Skip to content

Commit

Permalink
2.0.10 - fixed chat commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanguygab committed May 6, 2024
1 parent 0bafae0 commit 1627409
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'io.github.tanguygab'
version = '2.0.9'
version = '2.0.10'

compileJava.options.encoding = 'UTF-8'

Expand Down Expand Up @@ -52,19 +52,19 @@ 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'
compileOnly 'com.loohp:InteractiveChat:4.2.9.0'
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ public BungeeAudiences getKyori() {
}

@Override
@SuppressWarnings("UnstableApiUsage")
public void sendToDiscord(TabPlayer player, String msg, String channel, List<String> plugins) {
public void sendToDiscord(TabPlayer player, String msg, String channel, List<String> plugins) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(String.join(",",plugins));
out.writeUTF(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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<String>) cmds.get(tab.getFeatureManager())).addAll(List.of("/ignore", "/clearchat",
"/togglemsg", "/socialspy", "/togglementions", "/toggleemojis", "/emojis"));
} catch (Exception e) {
e.printStackTrace();
}
}

private void loadProperties(TabPlayer player) {
Expand Down Expand Up @@ -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)))
Expand All @@ -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<UUID> ignored = this.ignored.computeIfAbsent(p.getUniqueId(), uuid->new ArrayList<>());
if (ignored.contains(playerUUID))
ignored.remove(playerUUID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public CommandManager(Chat chat, Map<String,Map<String,Object>> commands) {
ChatUtils.componentsToMM(display),
save,
prefix));
plugin.getPlatform().registerCommand(name);
});

Map<String,String> data = plugin.getPlayerData().getConfigurationSection("chat-commands-formats");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
}
Expand Down

0 comments on commit 1627409

Please sign in to comment.