Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the new change off tellraw has a bug #127

Open
thiagogebrimm opened this issue Jan 31, 2025 · 9 comments
Open

the new change off tellraw has a bug #127

thiagogebrimm opened this issue Jan 31, 2025 · 9 comments
Labels
bug Something to be fixed! Compatibility Conflict with other plugin(s)

Comments

@thiagogebrimm
Copy link

It returns unique-id in the message, see image:

Image

@EvModder
Copy link
Owner

I am not sure that is a bug, the vanilla built in tellraw uses UUID to select entities, so the custom one needs to support this as well

@thiagogebrimm
Copy link
Author

my tellraw command:

package com.rederevo.commands;

import com.google.gson.JsonSyntaxException;
import com.rederevo.utils.ChatUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class TellRawCommand implements CommandExecutor {

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
        if (!sender.hasPermission("revo.admin")) {
            sender.sendMessage(ChatUtils.colorize("&cVocê não tem permissão para usar este comando."));
            return true;
        }

        if (args.length < 2) {
            sender.sendMessage(ChatUtils.colorize("&cUso correto: /tellraw <jogador> <mensagem JSON ou texto simples>"));
            return true;
        }

        String targetName = args[0];
        Player target = Bukkit.getPlayerExact(targetName);

        if (target == null || !target.isOnline()) {
            sender.sendMessage(ChatUtils.colorize("&cJogador não encontrado ou offline."));
            return true;
        }

        // Construir a mensagem
        StringBuilder messageBuilder = new StringBuilder();
        for (int i = 1; i < args.length; i++) {
            messageBuilder.append(args[i]).append(" ");
        }
        String rawMessage = messageBuilder.toString().trim();

        try {
            if (rawMessage.startsWith("[") && rawMessage.endsWith("]")) {
                // Trata como JSON
                Component message = GsonComponentSerializer.gson().deserialize(rawMessage);
                target.sendMessage(message);
            } else {
                // Trata como texto simples com formatação
                target.sendMessage(ChatUtils.colorize(rawMessage));
            }
        } catch (JsonSyntaxException e) {
            sender.sendMessage(ChatUtils.colorize("&cErro: o JSON fornecido é inválido."));
        }

        return true;
    }
}

@EvModder
Copy link
Owner

EvModder commented Feb 1, 2025

Hmm, your code looks correct, maybe verify the rawMessage might not always be wrapped in [ ].
I will test it later if I get some time

@EvModder
Copy link
Owner

EvModder commented Feb 4, 2025

I tried it, it worked correctly for me, with a very similar command implementation:

@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
	Player target = Bukkit.getPlayerExact(args[0]);
	if(target == null){
		try{target = Bukkit.getPlayer(UUID.fromString(args[0]));}
		catch(IllegalArgumentException e){}
	}

	if(target == null || !target.isOnline()){
		sender.sendMessage("Offline");
		return true;
	}

	String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
	try{
		Component c = JSONComponentSerializer.json().deserialize(message);
		target.sendMessage(c);
	}
	catch(JsonSyntaxException e){
		sender.sendMessage("Invalid");
	}
	return true;
}

@EvModder
Copy link
Owner

EvModder commented Feb 4, 2025

Maybe I can include this in the base jar, so it does not use /tellraw (except for in the older versions of Minecraft, which require it)

@EvModder
Copy link
Owner

EvModder commented Feb 4, 2025

I found a bug while testing it, certain weapons cause the Component to break, so I am fixing that as well

@EvModder
Copy link
Owner

EvModder commented Feb 6, 2025

I uploaded a new dev version of the plugin here on GitHub (3.9.11), it might fix the issue. It sends the message directly to players now instead of using /tellraw, and it uses Component library functions for the killed entity instead of a selector, since I think the issue was the server lost track of dead entities before the chat messages were sent (since it is in a different thread)

@thiagogebrimm
Copy link
Author

oks, thx

@EvModder
Copy link
Owner

Maybe try the latest version v3.9.11, it no longer uses /tellraw or any other command, instead it sends the messages directly.

@EvModder EvModder added bug Something to be fixed! Compatibility Conflict with other plugin(s) labels Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something to be fixed! Compatibility Conflict with other plugin(s)
Projects
None yet
Development

No branches or pull requests

2 participants