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:
parent
a3160c4040
commit
792a127bdd
3 changed files with 12 additions and 23 deletions
|
@ -97,11 +97,12 @@ public class PlayerListener implements Listener {
|
||||||
return;
|
return;
|
||||||
if (!MainPlugin.Instance.isChatHandlerEnabled()) return;
|
if (!MainPlugin.Instance.isChatHandlerEnabled()) return;
|
||||||
if (event.getOrigin().equals("Minecraft")) return; //Let other plugins handle MC messages
|
if (event.getOrigin().equals("Minecraft")) return; //Let other plugins handle MC messages
|
||||||
|
var channel = event.getChannel();
|
||||||
String msg = MainPlugin.Instance.chatFormat().get()
|
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("{origin}", event.getOrigin().substring(0, 1))
|
||||||
.replace("{name}", ChromaUtils.getDisplayName(event.getSender()))
|
.replace("{name}", ChromaUtils.getDisplayName(event.getSender()))
|
||||||
.replace("{message}", event.getMessage());
|
.replace("{message}", "§" + channel.Color().get().ordinal() + event.getMessage());
|
||||||
for (Player player : Bukkit.getOnlinePlayers())
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
if (event.shouldSendTo(player))
|
if (event.shouldSendTo(player))
|
||||||
player.sendMessage(msg);
|
player.sendMessage(msg);
|
||||||
|
|
|
@ -5,7 +5,6 @@ import buttondevteam.lib.architecture.Component;
|
||||||
import buttondevteam.lib.chat.*;
|
import buttondevteam.lib.chat.*;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase;
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,19 +42,21 @@ public class ChannelComponent extends Component {
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
private static class ChannelCommand extends ICommand2MC {
|
private static class ChannelCommand extends ICommand2MC {
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCommandPath() {
|
public String getCommandPath() {
|
||||||
return channel.ID; //TODO: IDs
|
return channel.ID; //TODO: IDs
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command2.Subcommand
|
@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);
|
var user = ChromaGamerBase.getFromSender(sender);
|
||||||
if(user==null) {
|
if (user == null) {
|
||||||
sender.sendMessage("§cYou can't use channels from this platform.");
|
sender.sendMessage("§cYou can't use channels from this platform.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(message==null) {
|
if (message == null) {
|
||||||
Channel oldch = user.channel().get();
|
Channel oldch = user.channel().get();
|
||||||
if (oldch instanceof ChatRoom)
|
if (oldch instanceof ChatRoom)
|
||||||
((ChatRoom) oldch).leaveRoom(sender);
|
((ChatRoom) oldch).leaveRoom(sender);
|
||||||
|
@ -67,9 +68,9 @@ public class ChannelComponent extends Component {
|
||||||
((ChatRoom) channel).joinRoom(sender);
|
((ChatRoom) channel).joinRoom(sender);
|
||||||
}
|
}
|
||||||
sender.sendMessage("§6You are now talking in: §b" + user.channel().get().DisplayName().get());
|
sender.sendMessage("§6You are now talking in: §b" + user.channel().get().DisplayName().get());
|
||||||
}
|
} else
|
||||||
else
|
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender, user, message).fromCommand(true)
|
||||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender, user, message).build(), channel);
|
.permCheck(senderMC.getPermCheck()).build(), channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,21 +202,13 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
|
||||||
private static Commodore commodore;
|
private static Commodore commodore;
|
||||||
|
|
||||||
private static void registerTabcomplete(ICommand2MC command2MC, List<SubcommandData<ICommand2MC>> subcmds, Command bukkitCommand) {
|
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
|
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(" ");
|
String[] path = command2MC.getCommandPath().split(" ");
|
||||||
var maincmd = LiteralArgumentBuilder.literal(path[0]).build();
|
var maincmd = LiteralArgumentBuilder.literal(path[0]).build();
|
||||||
var cmd = maincmd;
|
var cmd = maincmd;
|
||||||
for (int i = 1; i < path.length; i++) {
|
for (int i = 1; i < path.length; i++) {
|
||||||
var subcmd = LiteralArgumentBuilder.literal(path[i]).build();
|
var subcmd = LiteralArgumentBuilder.literal(path[i]).build();
|
||||||
System.out.println(cmd + " -> " + subcmd);
|
|
||||||
cmd.addChild(subcmd);
|
cmd.addChild(subcmd);
|
||||||
cmd = subcmd; //Add each part of the path as a child of the previous one
|
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
|
if (subpath[0].length() > 0) { //If the method is def, it will contain one empty string
|
||||||
for (String s : subpath) {
|
for (String s : subpath) {
|
||||||
var subsubcmd = LiteralArgumentBuilder.literal(s).build();
|
var subsubcmd = LiteralArgumentBuilder.literal(s).build();
|
||||||
System.out.println(scmd + " -> " + subsubcmd);
|
|
||||||
scmd.addChild(subsubcmd);
|
scmd.addChild(subsubcmd);
|
||||||
scmd = subsubcmd; //Add method name part of the path (could_be_multiple())
|
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
|
else //TODO: Custom parameter types
|
||||||
type = StringArgumentType.word();
|
type = StringArgumentType.word();
|
||||||
var arg = RequiredArgumentBuilder.argument(parameter.getName(), type).build();
|
var arg = RequiredArgumentBuilder.argument(parameter.getName(), type).build();
|
||||||
System.out.println("Adding arg: " + arg + " to " + scmd);
|
|
||||||
scmd.addChild(arg);
|
scmd.addChild(arg);
|
||||||
scmd = arg;
|
scmd = arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("maincmd: " + maincmd);
|
|
||||||
System.out.println("Children:");
|
|
||||||
maincmd.getChildren().forEach(System.out::println);
|
|
||||||
commodore.register(maincmd);
|
commodore.register(maincmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue