Channel command and message colors fix

Fixed channel 'from command' and 'perm check'
Fixed message colors when the chat plugin isn't present (TBMCPlugins/Chroma-Chat#107)
This commit is contained in:
Norbi Peti 2020-03-15 23:53:10 +01:00
parent a3160c4040
commit 792a127bdd
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 12 additions and 23 deletions

View file

@ -97,11 +97,12 @@ public class PlayerListener implements Listener {
return;
if (!MainPlugin.Instance.isChatHandlerEnabled()) return;
if (event.getOrigin().equals("Minecraft")) return; //Let other plugins handle MC messages
var channel = event.getChannel();
String msg = MainPlugin.Instance.chatFormat().get()
.replace("{channel}", event.getChannel().DisplayName().get())
.replace("{channel}", channel.DisplayName().get())
.replace("{origin}", event.getOrigin().substring(0, 1))
.replace("{name}", ChromaUtils.getDisplayName(event.getSender()))
.replace("{message}", event.getMessage());
.replace("{message}", "§" + channel.Color().get().ordinal() + event.getMessage());
for (Player player : Bukkit.getOnlinePlayers())
if (event.shouldSendTo(player))
player.sendMessage(msg);

View file

@ -5,7 +5,6 @@ import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.chat.*;
import buttondevteam.lib.player.ChromaGamerBase;
import lombok.RequiredArgsConstructor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
/**
@ -43,13 +42,15 @@ public class ChannelComponent extends Component {
@RequiredArgsConstructor
private static class ChannelCommand extends ICommand2MC {
private final Channel channel;
@Override
public String getCommandPath() {
return channel.ID; //TODO: IDs
}
@Command2.Subcommand
public void def(CommandSender sender, @Command2.OptionalArg @Command2.TextArg String message) {
public void def(Command2MCSender senderMC, @Command2.OptionalArg @Command2.TextArg String message) {
var sender = senderMC.getSender();
var user = ChromaGamerBase.getFromSender(sender);
if (user == null) {
sender.sendMessage("§cYou can't use channels from this platform.");
@ -67,9 +68,9 @@ public class ChannelComponent extends Component {
((ChatRoom) channel).joinRoom(sender);
}
sender.sendMessage("§6You are now talking in: §b" + user.channel().get().DisplayName().get());
}
else
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender, user, message).build(), channel);
} else
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender, user, message).fromCommand(true)
.permCheck(senderMC.getPermCheck()).build(), channel);
}
}
}

View file

@ -202,21 +202,13 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
private static Commodore commodore;
private static void registerTabcomplete(ICommand2MC command2MC, List<SubcommandData<ICommand2MC>> subcmds, Command bukkitCommand) {
if (commodore == null) {
if (commodore == null)
commodore = CommodoreProvider.getCommodore(MainPlugin.Instance); //Register all to the Core, it's easier
System.out.println("Registering test tabcomplete");
commodore.register(LiteralArgumentBuilder.literal("test")
.then(LiteralArgumentBuilder.literal("asd")
.then(RequiredArgumentBuilder.argument("dsa", StringArgumentType.word())))
.then(RequiredArgumentBuilder.argument("lol", StringArgumentType.word())));
}
System.out.println("Registering tabcomplete for path: " + command2MC.getCommandPath());
String[] path = command2MC.getCommandPath().split(" ");
var maincmd = LiteralArgumentBuilder.literal(path[0]).build();
var cmd = maincmd;
for (int i = 1; i < path.length; i++) {
var subcmd = LiteralArgumentBuilder.literal(path[i]).build();
System.out.println(cmd + " -> " + subcmd);
cmd.addChild(subcmd);
cmd = subcmd; //Add each part of the path as a child of the previous one
}
@ -226,7 +218,6 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
if (subpath[0].length() > 0) { //If the method is def, it will contain one empty string
for (String s : subpath) {
var subsubcmd = LiteralArgumentBuilder.literal(s).build();
System.out.println(scmd + " -> " + subsubcmd);
scmd.addChild(subsubcmd);
scmd = subsubcmd; //Add method name part of the path (could_be_multiple())
}
@ -258,14 +249,10 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
else //TODO: Custom parameter types
type = StringArgumentType.word();
var arg = RequiredArgumentBuilder.argument(parameter.getName(), type).build();
System.out.println("Adding arg: " + arg + " to " + scmd);
scmd.addChild(arg);
scmd = arg;
}
}
System.out.println("maincmd: " + maincmd);
System.out.println("Children:");
maincmd.getChildren().forEach(System.out::println);
commodore.register(maincmd);
}
}