From b643366e9ef7d8eea4958214284c83541349d034 Mon Sep 17 00:00:00 2001 From: RayzsYT <51991564+RayzsYT@users.noreply.github.com> Date: Mon, 10 Jun 2024 19:35:59 +0200 Subject: [PATCH] Add Player To Command --- .../de/rayzs/pat/plugin/commands/BukkitCommand.java | 9 ++++++++- .../de/rayzs/pat/plugin/commands/BungeeCommand.java | 7 +++++++ .../rayzs/pat/plugin/commands/VelocityCommand.java | 7 +++++++ .../replacer/impl/ProxyPlaceholderReplacer.java | 13 ++++++++++--- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/rayzs/pat/plugin/commands/BukkitCommand.java b/src/main/java/de/rayzs/pat/plugin/commands/BukkitCommand.java index 4a2f1f79..f71e1a0b 100644 --- a/src/main/java/de/rayzs/pat/plugin/commands/BukkitCommand.java +++ b/src/main/java/de/rayzs/pat/plugin/commands/BukkitCommand.java @@ -2,6 +2,7 @@ package de.rayzs.pat.plugin.commands; import de.rayzs.pat.plugin.process.CommandProcess; import org.bukkit.command.*; +import org.bukkit.entity.Player; import java.util.List; @@ -9,8 +10,14 @@ public class BukkitCommand implements CommandExecutor, TabCompleter { @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + if(commandSender instanceof Player) { + Player player = (Player) commandSender; + CommandProcess.handleCommand(player, strings, s); + return true; + } + CommandProcess.handleCommand(commandSender, strings, s); - return false; + return true; } @Override diff --git a/src/main/java/de/rayzs/pat/plugin/commands/BungeeCommand.java b/src/main/java/de/rayzs/pat/plugin/commands/BungeeCommand.java index 6c785394..6f6e51e7 100644 --- a/src/main/java/de/rayzs/pat/plugin/commands/BungeeCommand.java +++ b/src/main/java/de/rayzs/pat/plugin/commands/BungeeCommand.java @@ -2,6 +2,7 @@ package de.rayzs.pat.plugin.commands; import de.rayzs.pat.plugin.process.CommandProcess; import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.*; public class BungeeCommand extends Command implements TabExecutor { @@ -12,6 +13,12 @@ public class BungeeCommand extends Command implements TabExecutor { @Override public void execute(CommandSender commandSender, String[] strings) { + if(commandSender instanceof ProxiedPlayer) { + ProxiedPlayer proxiedPlayer = (ProxiedPlayer) commandSender; + CommandProcess.handleCommand(proxiedPlayer, strings, "bpat"); + return; + } + CommandProcess.handleCommand(commandSender, strings, "bpat"); } diff --git a/src/main/java/de/rayzs/pat/plugin/commands/VelocityCommand.java b/src/main/java/de/rayzs/pat/plugin/commands/VelocityCommand.java index 87da87f2..bff19c23 100644 --- a/src/main/java/de/rayzs/pat/plugin/commands/VelocityCommand.java +++ b/src/main/java/de/rayzs/pat/plugin/commands/VelocityCommand.java @@ -1,6 +1,7 @@ package de.rayzs.pat.plugin.commands; import com.velocitypowered.api.command.SimpleCommand; +import com.velocitypowered.api.proxy.Player; import de.rayzs.pat.plugin.process.CommandProcess; import java.util.List; @@ -8,6 +9,12 @@ public class VelocityCommand implements SimpleCommand { @Override public void execute(Invocation invocation) { + if(invocation.source() instanceof Player) { + Player player = (Player) invocation.source(); + CommandProcess.handleCommand(player, invocation.arguments(), "bpat"); + return; + } + CommandProcess.handleCommand(invocation.source(), invocation.arguments(), "bpat"); } diff --git a/src/main/java/de/rayzs/pat/utils/message/replacer/impl/ProxyPlaceholderReplacer.java b/src/main/java/de/rayzs/pat/utils/message/replacer/impl/ProxyPlaceholderReplacer.java index 0b817af6..057f1e59 100644 --- a/src/main/java/de/rayzs/pat/utils/message/replacer/impl/ProxyPlaceholderReplacer.java +++ b/src/main/java/de/rayzs/pat/utils/message/replacer/impl/ProxyPlaceholderReplacer.java @@ -27,15 +27,22 @@ public class ProxyPlaceholderReplacer { uuid = ((com.velocitypowered.api.proxy.Player) playerObj).getUniqueId(); } else if(Reflection.isProxyServer()) { - if (playerObj instanceof net.md_5.bungee.api.connection.ProxiedPlayer) + System.out.println("Checking through proxy"); + if (playerObj instanceof net.md_5.bungee.api.connection.ProxiedPlayer) { + System.out.println("Is ProxiedPlayer"); uuid = ((net.md_5.bungee.api.connection.ProxiedPlayer) playerObj).getUniqueId(); - + } else System.out.println("No proxied player ;C -> " + playerObj); } else { if(playerObj instanceof org.bukkit.entity.Player) uuid = ((org.bukkit.entity.Player) playerObj).getUniqueId(); } - if(uuid == null) return false; + if(uuid == null) { + System.out.println("Ignore translation: " + text); + return false; + } + + System.out.println("Translated: " + text); PLACEHOLDER_API.formatPlaceholders(text, uuid).thenAccept(consumer); return true;