mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-11-30 20:39:53 -05:00
Add PAPIProxyBridge Support
This commit is contained in:
1 parent
66df008047
commit
21bd15e5f0
9 files changed
+93
-18
No files matched your search
@@ -28,7 +28,7 @@ public class Storage {
|
||||
public static String TOKEN = "", SERVER_NAME = null, CURRENT_VERSION = "", NEWER_VERSION = "";
|
||||
public static boolean OUTDATED = false, SEND_CONSOLE_NOTIFICATION = true;
|
||||
public static Object PLUGIN_OBJECT;
|
||||
public static boolean USE_LUCKPERMS = false, USE_PLACEHOLDERAPI = false, USE_VIAVERSION = false, USE_VELOCITY = false;
|
||||
public static boolean USE_LUCKPERMS = false, USE_PLACEHOLDERAPI = false, USE_PAPIPROXYBRIDGE = false, USE_VIAVERSION = false, USE_VELOCITY = false;
|
||||
|
||||
public static void loadAll(boolean loadBlacklist) {
|
||||
loadConfig();
|
||||
|
||||
@@ -70,6 +70,9 @@ public class BungeeLoader extends Plugin {
|
||||
|
||||
if (manager.getPlugin("LuckPerms") != null)
|
||||
LuckPermsAdapter.initialize();
|
||||
|
||||
Storage.USE_PAPIPROXYBRIDGE = manager.getPlugin("PAPIProxyBridge") != null;
|
||||
|
||||
BungeePacketAnalyzer.injectAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ version = "1.7.3",
|
||||
authors = "Rayzs_YT",
|
||||
description = "A simple structured AntiTab plugin to prevent specific commands from being executed and auto-tab-completed.",
|
||||
dependencies = {
|
||||
@Dependency(id = "luckperms", optional = true)
|
||||
@Dependency(id = "luckperms", optional = true),
|
||||
@Dependency(id = "papiproxybridge", optional = true)
|
||||
})
|
||||
public class VelocityLoader {
|
||||
|
||||
@@ -89,6 +90,8 @@ public class VelocityLoader {
|
||||
|
||||
if(server.getPluginManager().getPlugin("luckperms").isPresent())
|
||||
LuckPermsAdapter.initialize();
|
||||
|
||||
Storage.USE_PAPIPROXYBRIDGE = server.getPluginManager().getPlugin("papiproxybridge").isPresent();
|
||||
}
|
||||
|
||||
public void startUpdaterTask() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.configuration.helper.MultipleMessagesHelper;
|
||||
import de.rayzs.pat.utils.message.replacer.PlaceholderReplacer;
|
||||
import de.rayzs.pat.utils.message.replacer.impl.BukkitPlaceholderReplacer;
|
||||
import de.rayzs.pat.utils.message.translators.*;
|
||||
import java.util.*;
|
||||
|
||||
@@ -85,11 +86,13 @@ public class MessageTranslator {
|
||||
text = replaceMessageString(text, replacements);
|
||||
if(translator == null) {
|
||||
CommandSender sender = target instanceof CommandSender ? (CommandSender) target : new CommandSender(target);
|
||||
sender.sendMessage(text);
|
||||
if(!PlaceholderReplacer.process(sender, text, sender::sendMessage))
|
||||
sender.sendMessage(text);
|
||||
return;
|
||||
}
|
||||
|
||||
translator.send(target, text);
|
||||
if(!PlaceholderReplacer.process(target, text, result -> translator.send(target, result)))
|
||||
translator.send(target, text);
|
||||
}
|
||||
|
||||
public static String replaceMessage(String text) {
|
||||
@@ -99,7 +102,7 @@ public class MessageTranslator {
|
||||
public static String replaceMessage(Object playerObj, String text) {
|
||||
CommandSender sender = playerObj instanceof CommandSender ? (CommandSender) playerObj : new CommandSender(playerObj);
|
||||
text = text.replace("%executor%", sender.isPlayer() ? sender.getName() : "").replace("&", "§").replace("%prefix%", Storage.ConfigSections.Messages.PREFIX.PREFIX).replace("%current_version%", Storage.CURRENT_VERSION).replace("%newest_version%", Storage.NEWER_VERSION).replace("\\n", "\n");
|
||||
return !Storage.USE_PLACEHOLDERAPI ? text : PlaceholderReplacer.replace(playerObj, text);
|
||||
return PlaceholderReplacer.replace(playerObj, text);
|
||||
}
|
||||
|
||||
public static String replaceMessageString(String rawText, String... replacements) {
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
package de.rayzs.pat.utils.message.replacer;
|
||||
|
||||
import de.rayzs.pat.utils.CommandSender;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.message.replacer.impl.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PlaceholderReplacer {
|
||||
|
||||
public static String replace(Object playerObj, String text) {
|
||||
Player player = null;
|
||||
if(!Storage.USE_PLACEHOLDERAPI) return text;
|
||||
return BukkitPlaceholderReplacer.process(playerObj, text);
|
||||
}
|
||||
|
||||
if(playerObj != null)
|
||||
if(playerObj instanceof CommandSender) {
|
||||
CommandSender sender = (CommandSender) playerObj;
|
||||
player = sender.isPlayer() ? (Player) sender.getSenderObject() : null;
|
||||
} else if(playerObj instanceof Player)
|
||||
player = (Player) playerObj;
|
||||
|
||||
return PlaceholderAPI.setPlaceholders(player, text);
|
||||
public static boolean process(Object playerObj, String text, Consumer<String> consumer) {
|
||||
if(!Storage.USE_PAPIPROXYBRIDGE) return false;
|
||||
return ProxyPlaceholderReplacer.process(playerObj, text, consumer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package de.rayzs.pat.utils.message.replacer.impl;
|
||||
|
||||
import de.rayzs.pat.utils.CommandSender;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BukkitPlaceholderReplacer {
|
||||
|
||||
public static String process(Object playerObj, String text) {
|
||||
Player player = null;
|
||||
|
||||
if(playerObj != null)
|
||||
if(playerObj instanceof CommandSender) {
|
||||
CommandSender sender = (CommandSender) playerObj;
|
||||
player = sender.isPlayer() ? (Player) sender.getSenderObject() : null;
|
||||
} else if(playerObj instanceof Player)
|
||||
player = (Player) playerObj;
|
||||
|
||||
return PlaceholderAPI.setPlaceholders(player, text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package de.rayzs.pat.utils.message.replacer.impl;
|
||||
|
||||
import de.rayzs.pat.utils.CommandSender;
|
||||
import net.william278.papiproxybridge.api.PlaceholderAPI;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ProxyPlaceholderReplacer {
|
||||
|
||||
private static final PlaceholderAPI PLACEHOLDER_API;
|
||||
|
||||
static {
|
||||
PLACEHOLDER_API = PlaceholderAPI.createInstance();
|
||||
}
|
||||
|
||||
public static boolean process(Object playerObj, String text, Consumer<String> consumer) {
|
||||
UUID uuid = null;
|
||||
|
||||
if(playerObj != null)
|
||||
if(playerObj instanceof CommandSender)
|
||||
uuid = ((CommandSender) playerObj).getUniqueId();
|
||||
|
||||
else if(playerObj instanceof com.velocitypowered.api.proxy.Player)
|
||||
uuid = ((com.velocitypowered.api.proxy.Player) playerObj).getUniqueId();
|
||||
|
||||
else if(playerObj instanceof org.bukkit.entity.Player)
|
||||
uuid = ((org.bukkit.entity.Player) playerObj).getUniqueId();
|
||||
|
||||
if(uuid == null) return false;
|
||||
PLACEHOLDER_API.formatPlaceholders(text, uuid).thenAccept(consumer);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user