diff --git a/build.gradle b/build.gradle index 0bf85bc..4dab700 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'io.github.tanguygab' -version = '2.0.9' +version = '2.0.10' compileJava.options.encoding = 'UTF-8' @@ -52,8 +52,8 @@ dependencies { compileOnly 'net.md-5:bungeecord-api:1.20-R0.1-SNAPSHOT' compileOnly 'org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT' compileOnly files('../../dependencies/TAB-4.1.3-SNAPSHOT.jar') - compileOnly 'org.projectlombok:lombok:1.18.20' - annotationProcessor 'org.projectlombok:lombok:1.18.20' + compileOnly 'org.projectlombok:lombok:1.18.32' + annotationProcessor 'org.projectlombok:lombok:1.18.32' compileOnly 'com.discordsrv:discordsrv:1.27.0' compileOnly 'net.essentialsx:EssentialsXDiscord:2.20.1' @@ -61,10 +61,10 @@ dependencies { compileOnly 'com.github.DevLeoko:AdvancedBan:2.3.0' compileOnly 'dev.simplix:protocolize-api:2.2.6' - implementation "net.kyori:adventure-platform-bukkit:4.3.2" - implementation "net.kyori:adventure-platform-bungeecord:4.3.2" - implementation "net.kyori:adventure-text-minimessage:4.15.0" - implementation("net.kyori:adventure-text-serializer-plain:4.15.0") + implementation "net.kyori:adventure-platform-bukkit:4.3.3-SNAPSHOT" + implementation "net.kyori:adventure-platform-bungeecord:4.3.3-SNAPSHOT" + implementation 'net.kyori:adventure-text-minimessage:4.17.0-SNAPSHOT' + implementation 'net.kyori:adventure-text-serializer-plain:4.17.0-SNAPSHOT' } shadowJar { diff --git a/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeeListener.java b/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeeListener.java index 9a7f7f6..686746b 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeeListener.java +++ b/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeeListener.java @@ -19,15 +19,20 @@ public class BungeeListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onChat(ChatEvent e) { - if (e.isCommand() || e.isCancelled()) return; + if (e.isCancelled()) return; Chat chat = tab.getFeatureManager().getFeature("Chat"); - if (chat == null || chat.isBukkitBridgeChatEnabled()) return; + if (chat == null) return; + TabPlayer player = getPlayer(e.getSender()); + if (e.isCommand() && chat.onCommand(player,e.getMessage())) { + e.setCancelled(true); + return; + } + if (chat.isBukkitBridgeChatEnabled()) return; e.setCancelled(true); - chat.onChat(getPlayer(e.getSender()),e.getMessage()); + chat.onChat(player,e.getMessage()); } @EventHandler - @SuppressWarnings("UnstableApiUsage") public void onMessageReceived(PluginMessageEvent e) { if (!e.getTag().equalsIgnoreCase("tabadditions:channel")) return; ByteArrayDataInput in = ByteStreams.newDataInput(e.getData()); diff --git a/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeePlatform.java b/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeePlatform.java index 11275e5..d3f192e 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeePlatform.java +++ b/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeePlatform.java @@ -93,8 +93,7 @@ public BungeeAudiences getKyori() { } @Override - @SuppressWarnings("UnstableApiUsage") - public void sendToDiscord(TabPlayer player, String msg, String channel, List plugins) { + public void sendToDiscord(TabPlayer player, String msg, String channel, List plugins) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF(String.join(",",plugins)); out.writeUTF(msg); diff --git a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/Chat.java b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/Chat.java index bd08347..4caf5b9 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/Chat.java +++ b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/Chat.java @@ -25,7 +25,6 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Field; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.*; @@ -174,15 +173,6 @@ public Chat(ConfigurationFile config) { bukkitBridgeChatEnabled = plugin.getPlatform().isProxy() && config.getBoolean("chat-from-bukkit-bridge",false); for (TabPlayer player : tab.getOnlinePlayers()) loadProperties(player); - - try { - Field cmds = tab.getFeatureManager().getClass().getDeclaredField("listeningCommands"); - cmds.setAccessible(true); - ((List) cmds.get(tab.getFeatureManager())).addAll(List.of("/ignore", "/clearchat", - "/togglemsg", "/socialspy", "/togglementions", "/toggleemojis", "/emojis")); - } catch (Exception e) { - e.printStackTrace(); - } } private void loadProperties(TabPlayer player) { @@ -221,7 +211,7 @@ public void onJoin(@NotNull TabPlayer player) { } @Override - public boolean onCommand(@NotNull TabPlayer p, String cmd) { + public boolean onCommand(@NotNull TabPlayer p, @NotNull String cmd) { if (cmd.startsWith("/emojis") || cmd.equals("/toggleemojis")) return emojiManager != null && emojiManager.onCommand(p,cmd); if (cmd.equals("/togglementions")) return mentionManager != null && mentionManager.onCommand(p,cmd); if (msgManager != null && (cmd.equals("/togglemsg") || msgManager.isReplyCmd(cmd,false) || msgManager.isMsgCmd(cmd,false))) @@ -245,12 +235,17 @@ public boolean onCommand(@NotNull TabPlayer p, String cmd) { p.sendMessage(msgs.providePlayer, true); return true; } - String player = cmd.substring(cmd.indexOf(8)).toLowerCase(); + String player = cmd.substring(8).toLowerCase(); if (p.getName().equalsIgnoreCase(player)) { p.sendMessage(msgs.cantIgnoreSelf,true); return true; } - UUID playerUUID = plugin.getPlayer(player).getUniqueId(); + TabPlayer tabPlayer = plugin.getPlayer(player); + if (tabPlayer == null) { + p.sendMessage(msgs.getPlayerNotFound(player),true); + return true; + } + UUID playerUUID = tabPlayer.getUniqueId(); List ignored = this.ignored.computeIfAbsent(p.getUniqueId(), uuid->new ArrayList<>()); if (ignored.contains(playerUUID)) ignored.remove(playerUUID); diff --git a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/commands/CommandManager.java b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/commands/CommandManager.java index 8e43a21..5eea747 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/commands/CommandManager.java +++ b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/commands/CommandManager.java @@ -35,6 +35,7 @@ public CommandManager(Chat chat, Map> commands) { ChatUtils.componentsToMM(display), save, prefix)); + plugin.getPlatform().registerCommand(name); }); Map data = plugin.getPlayerData().getConfigurationSection("chat-commands-formats"); diff --git a/src/main/java/io/github/tanguygab/tabadditions/spigot/SpigotListener.java b/src/main/java/io/github/tanguygab/tabadditions/spigot/SpigotListener.java index d6162c5..fa6d84e 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/spigot/SpigotListener.java +++ b/src/main/java/io/github/tanguygab/tabadditions/spigot/SpigotListener.java @@ -8,6 +8,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; @@ -28,6 +29,13 @@ public void onChat(AsyncPlayerChatEvent e) { ((Chat)tab.getFeatureManager().getFeature("Chat")).onChat(getPlayer(e),e.getMessage()); } + @EventHandler + public void onCommand(PlayerCommandPreprocessEvent e) { + if (!tab.getFeatureManager().isFeatureEnabled("Chat")) return; + if (((Chat)tab.getFeatureManager().getFeature("Chat")).onCommand(getPlayer(e),e.getMessage())) + e.setCancelled(true); + } + private TabPlayer getPlayer(PlayerEvent e) { return tab.getPlayer(e.getPlayer().getUniqueId()); }