mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-12-02 05:19:52 -05:00
Add Placeholders
This commit is contained in:
1 parent
f1eb4c089c
commit
80385ae694
14 files changed
+438
-8
No files matched your search
@@ -1,18 +1,19 @@
|
||||
package de.rayzs.pat.api.storage;
|
||||
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
|
||||
import de.rayzs.pat.api.storage.blacklist.BlacklistCreator;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GroupBlacklist;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.*;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.general.*;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.group.*;
|
||||
import de.rayzs.pat.api.storage.placeholders.groups.*;
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.api.storage.config.messages.*;
|
||||
import de.rayzs.pat.api.storage.config.settings.*;
|
||||
import de.rayzs.pat.plugin.BungeeLoader;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.plugin.*;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.*;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -39,6 +40,7 @@ public class Storage {
|
||||
ConfigSections.Settings.initialize();
|
||||
ConfigSections.Messages.initialize();
|
||||
ConfigSections.SECTIONS.forEach(ConfigStorage::load);
|
||||
ConfigSections.PLACEHOLDERS.forEach(PlaceholderStorage::load);
|
||||
}
|
||||
|
||||
public static List<String> getServers() {
|
||||
@@ -83,6 +85,7 @@ public class Storage {
|
||||
public static final ConfigurationBuilder
|
||||
CONFIGURATION = Configurator.get("config"),
|
||||
STORAGE = Configurator.get("storage"),
|
||||
PLACEHOLDERS = Configurator.get("placeholders"),
|
||||
TOKEN = Configurator.get("token");
|
||||
|
||||
public static void initialize() {}
|
||||
@@ -91,6 +94,7 @@ public class Storage {
|
||||
public static class ConfigSections {
|
||||
|
||||
public static List<ConfigStorage> SECTIONS = new ArrayList<>();
|
||||
public static List<PlaceholderStorage> PLACEHOLDERS = new ArrayList<>();
|
||||
|
||||
public static class Settings {
|
||||
|
||||
@@ -122,6 +126,41 @@ public class Storage {
|
||||
|
||||
public static void initialize() {}
|
||||
}
|
||||
|
||||
public static class Placeholders {
|
||||
|
||||
public static ListGroupsPlaceholder LIST_GROUP = new ListGroupsPlaceholder();
|
||||
public static ListGroupsReversedPlaceholder LIST_GROUP_REVERSED = new ListGroupsReversedPlaceholder();
|
||||
public static ListGroupsSortedPlaceholder LIST_GROUP_SORTED = new ListGroupsSortedPlaceholder();
|
||||
|
||||
public static ListGroupCommandsPlaceholder LIST_GROUP_COMMANDS = new ListGroupCommandsPlaceholder();
|
||||
public static ListGroupReversedCommandsPlaceholder LIST_GROUP_REVERSED_COMMANDS = new ListGroupReversedCommandsPlaceholder();
|
||||
public static ListGroupSortedCommandsPlaceholder LIST_GROUP_SORTED_COMMANDS = new ListGroupSortedCommandsPlaceholder();
|
||||
|
||||
public static ListCommandsPlaceholder LIST_COMMANDS = new ListCommandsPlaceholder();
|
||||
public static ListReversedCommandsPlaceholder LIST_REVERSED_COMMANDS = new ListReversedCommandsPlaceholder();
|
||||
public static ListSortedCommandsPlaceholder LIST_SORTED_COMMANDS = new ListSortedCommandsPlaceholder();
|
||||
|
||||
public static void initialize() {}
|
||||
|
||||
public static String findAndReplace(String request) {
|
||||
String result, param = "";
|
||||
|
||||
for (PlaceholderStorage storage : PLACEHOLDERS) {
|
||||
if(!storage.getRequest().startsWith(request)) continue;
|
||||
|
||||
if(storage.getRequest().endsWith("group_") && request.contains("group_"))
|
||||
param = request.split("group_")[1];
|
||||
|
||||
result = storage.onRequest(param);
|
||||
if(result == null) continue;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Blacklist {
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package de.rayzs.pat.api.storage.placeholders.commands.general;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
|
||||
public class ListCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListCommandsPlaceholder() { super("list_commands"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(String param) {
|
||||
return StringUtils.buildStringList(
|
||||
Storage.Blacklist.getBlacklist().getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package de.rayzs.pat.api.storage.placeholders.commands.general;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
|
||||
public class ListReversedCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListReversedCommandsPlaceholder() { super("list_reversed_commands"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(String param) {
|
||||
return StringUtils.buildSortedStringList(
|
||||
Storage.Blacklist.getBlacklist().getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%",
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package de.rayzs.pat.api.storage.placeholders.commands.general;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
|
||||
public class ListSortedCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListSortedCommandsPlaceholder() { super("list_sorted_commands"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(String param) {
|
||||
return StringUtils.buildSortedStringList(
|
||||
Storage.Blacklist.getBlacklist().getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%",
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package de.rayzs.pat.api.storage.placeholders.commands.group;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
public class ListGroupCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupCommandsPlaceholder() { super("list_commands_group_"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildStringList(
|
||||
group.getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package de.rayzs.pat.api.storage.placeholders.commands.group;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
public class ListGroupReversedCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupReversedCommandsPlaceholder() { super("list_reversed_commands_group_"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildSortedStringList(
|
||||
group.getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%",
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package de.rayzs.pat.api.storage.placeholders.commands.group;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
public class ListGroupSortedCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupSortedCommandsPlaceholder() { super("list_sorted_group_"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildSortedStringList(
|
||||
group.getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%",
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package de.rayzs.pat.api.storage.placeholders.groups;
|
||||
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
|
||||
public class ListGroupsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupsPlaceholder() { super("list_groups"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildStringList(
|
||||
GroupManager.getGroupNames(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%group%"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "group", "&f%group%\\n").getOrSet();
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package de.rayzs.pat.api.storage.placeholders.groups;
|
||||
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
|
||||
public class ListGroupsReversedPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupsReversedPlaceholder() { super("list_reversed_groups"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildSortedStringList(
|
||||
GroupManager.getGroupNames(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%group%",
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "group", "&f%group%\\n").getOrSet();
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package de.rayzs.pat.api.storage.placeholders.groups;
|
||||
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
|
||||
public class ListGroupsSortedPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupsSortedPlaceholder() { super("list_sorted_groups"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildSortedStringList(
|
||||
GroupManager.getGroupNames(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%",
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "group", "&f%group%\\n").getOrSet();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package de.rayzs.pat.api.storage.storages;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.StorageTemplate;
|
||||
|
||||
public abstract class PlaceholderStorage extends StorageTemplate {
|
||||
|
||||
private String request;
|
||||
|
||||
public PlaceholderStorage(String request) {
|
||||
super(Storage.Files.PLACEHOLDERS, "placeholders." + request);
|
||||
this.request = request;
|
||||
Storage.ConfigSections.PLACEHOLDERS.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() { getConfig().save(); }
|
||||
|
||||
@Override
|
||||
public void load() { getConfig().reload(); }
|
||||
|
||||
public String getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public abstract String onRequest(String param);
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import de.rayzs.pat.plugin.metrics.bStats;
|
||||
import de.rayzs.pat.api.netty.bukkit.BukkitPacketAnalyzer;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.utils.adapter.PlaceholderAdapter;
|
||||
import de.rayzs.pat.utils.adapter.ViaVersionAdapter;
|
||||
import de.rayzs.pat.utils.configuration.Configurator;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
@@ -79,9 +80,12 @@ public class BukkitLoader extends JavaPlugin {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> PermissionUtil.setPlayerPermissions(player.getUniqueId()));
|
||||
}
|
||||
|
||||
if(getServer().getPluginManager().getPlugin("ViaVersion") != null) {
|
||||
if(getServer().getPluginManager().getPlugin("ViaVersion") != null)
|
||||
ViaVersionAdapter.initialize();
|
||||
}
|
||||
|
||||
if(getServer().getPluginManager().getPlugin("PlaceholderAPI") != null)
|
||||
new PlaceholderAdapter().register();
|
||||
|
||||
|
||||
try {
|
||||
if (Bukkit.getPluginManager() instanceof SimplePluginManager) {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package de.rayzs.pat.utils.adapter;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
public class PlaceholderAdapter extends PlaceholderExpansion {
|
||||
|
||||
public PlaceholderAdapter() {
|
||||
Storage.ConfigSections.Placeholders.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register() {
|
||||
return super.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return super.persist();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "proantitab";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return BukkitLoader.getPlugin().getDescription().getAuthors().get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return BukkitLoader.getPlugin().getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String onPlaceholderRequest(Player player, @NotNull String request) {
|
||||
String result = null;
|
||||
request = request.toLowerCase();
|
||||
|
||||
if(request.startsWith("pat_")) {
|
||||
request = StringUtils.replaceFirst(request,"pat_", "");
|
||||
result = Storage.ConfigSections.Placeholders.findAndReplace(request);
|
||||
}
|
||||
|
||||
return result != null ? result : super.onPlaceholderRequest(player, request);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.rayzs.pat.utils.configuration.helper;
|
||||
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.utils.configuration.ConfigurationBuilder;
|
||||
|
||||
public class ConfigSectionHelper<T> {
|
||||
@@ -15,6 +16,12 @@ public class ConfigSectionHelper<T> {
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
public ConfigSectionHelper(PlaceholderStorage config, String path, Object obj) {
|
||||
this.configuration = config.getConfig();
|
||||
this.path = config.getNavigatePath() + (path != null ? "." + path : ""); ;
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
public boolean exist() {
|
||||
return get() != null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user