full recode
This commit is contained in:
1 parent
43a3e3cbaa
commit
0fe49b396c
51 files changed
+1014
-1154
No files matched your search
@@ -15,9 +15,9 @@ Clone this repository, then run the following command:
|
||||
|
||||
## Minecraft Versions Supported
|
||||
|
||||
[Spigot](https://www.spigotmc.org/) - [Paper](https://papermc.io/software/paper) - [Bungeecord/WaterFall](https://papermc.io/software/waterfall)
|
||||
[Spigot](https://www.spigotmc.org/) - [Paper](https://papermc.io/software/paper)
|
||||
|
||||
`1.13.x|1.14.x|1.16.x|1.17.x|1.18.x|1.19.x|1.20.x`
|
||||
`1.13.x|1.14.x|1.16.x|1.17.x|1.18.x|1.19.x|1.20.x|1.21.x`
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'lee.code.tcf'
|
||||
version = '1.2.5'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "paper-repo"
|
||||
url = "https://repo.papermc.io/repository/maven-public/"
|
||||
}
|
||||
maven {
|
||||
name = 'waterfall-repo'
|
||||
url = 'https://repo.papermc.io/repository/maven-public/'
|
||||
}
|
||||
maven {
|
||||
name = "spigotmc-repo"
|
||||
url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.projectlombok:lombok:1.18.28'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.28'
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.28'
|
||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.28'
|
||||
|
||||
compileOnly 'org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT'
|
||||
compileOnly 'io.github.waterfallmc:waterfall-api:1.20-R0.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
def targetJavaVersion = 16
|
||||
|
||||
java {
|
||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||
sourceCompatibility = javaVersion
|
||||
targetCompatibility = javaVersion
|
||||
if (JavaVersion.current() < javaVersion) {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||
options.release = targetJavaVersion
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property("version", project.version)
|
||||
outputs.dir(destinationDir)
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'plugin.yml'
|
||||
include 'bungee.yml'
|
||||
expand 'version': project.version
|
||||
}
|
||||
duplicatesStrategy = 'warn'
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
plugins {
|
||||
id("java")
|
||||
}
|
||||
|
||||
group = "dev.lee.tcf"
|
||||
version = "1.3.0"
|
||||
|
||||
tasks.compileJava {
|
||||
options.release.set(16)
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
val props = mapOf("version" to project.version)
|
||||
inputs.properties(props)
|
||||
filesMatching("plugin.yml") {
|
||||
expand(props)
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
|
||||
maven("https://libraries.minecraft.net")
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Spigot
|
||||
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
|
||||
compileOnly("com.mojang:authlib:3.13.56")
|
||||
|
||||
// Lombok
|
||||
compileOnly("org.projectlombok:lombok:1.18.38")
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.38")
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
rootProject.name = "TabCompleteFilter"
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package dev.lee.tcf;
|
||||
|
||||
import dev.lee.tcf.data.CustomArgData;
|
||||
import dev.lee.tcf.files.FileData;
|
||||
import dev.lee.tcf.files.files.Lang;
|
||||
import dev.lee.tcf.commands.CommandManager;
|
||||
import dev.lee.tcf.commands.CustomTabCompletion;
|
||||
import dev.lee.tcf.commands.TabCompletion;
|
||||
import dev.lee.tcf.files.FileManager;
|
||||
import dev.lee.tcf.listeners.FilterListener;
|
||||
import dev.lee.tcf.listeners.ServerLoadListener;
|
||||
import dev.lee.tcf.manager.TabManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TabCompleteFilter extends JavaPlugin {
|
||||
@Getter private static TabCompleteFilter instance;
|
||||
@Getter private TabManager tabManager;
|
||||
@Getter private FileManager fileManager;
|
||||
@Getter private FileData fileData;
|
||||
@Getter private CommandManager commandManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
this.tabManager = new TabManager();
|
||||
this.fileManager = new FileManager();
|
||||
this.fileData = new FileData();
|
||||
this.commandManager = new CommandManager();
|
||||
|
||||
registerListeners();
|
||||
registerCommands();
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
getCommand("tcf").setExecutor(commandManager);
|
||||
getCommand("tcf").setTabCompleter(new TabCompletion());
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
getServer().getPluginManager().registerEvents(new FilterListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new ServerLoadListener(), this);
|
||||
}
|
||||
|
||||
public void registerCustomTabCompletes() {
|
||||
for (Map.Entry<String, CustomArgData> argData : tabManager.getCustomArgDataMap().entrySet()) {
|
||||
PluginCommand pluginCommand = Bukkit.getServer().getPluginCommand(argData.getKey());
|
||||
if (pluginCommand == null) {
|
||||
getLogger().log(Level.WARNING, Lang.ERROR_CUSTOM_TAB_COMPLETE_NOT_REGISTERED.getString(new String[]{argData.getKey()}));
|
||||
continue;
|
||||
}
|
||||
pluginCommand.setTabCompleter(new CustomTabCompletion(argData.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -1,8 +1,7 @@
|
||||
package lee.code.tcf.spigot.commands;
|
||||
package dev.lee.tcf.commands;
|
||||
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lee.code.tcf.spigot.commands.subcommands.*;
|
||||
import lee.code.tcf.spigot.files.files.FileLang;
|
||||
import dev.lee.tcf.commands.subcommands.*;
|
||||
import dev.lee.tcf.files.files.Lang;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@@ -13,15 +12,16 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class CommandManager implements CommandExecutor {
|
||||
@Getter private final HashMap<String, SubCommand> subCommands = new HashMap<>();
|
||||
private final HashMap<String, SubCommand> subCommands = new HashMap<>();
|
||||
|
||||
public CommandManager(TabCompleteFilter tabCompleteFilter) {
|
||||
storeSubCommand(new ReloadCMD(tabCompleteFilter));
|
||||
storeSubCommand(new AddCMD(tabCompleteFilter));
|
||||
storeSubCommand(new RemoveCMD(tabCompleteFilter));
|
||||
storeSubCommand(new ListCMD(tabCompleteFilter));
|
||||
storeSubCommand(new HelpCMD(tabCompleteFilter));
|
||||
public CommandManager() {
|
||||
storeSubCommand(new ReloadCMD());
|
||||
storeSubCommand(new AddCMD());
|
||||
storeSubCommand(new RemoveCMD());
|
||||
storeSubCommand(new ListCMD());
|
||||
storeSubCommand(new HelpCMD());
|
||||
}
|
||||
|
||||
private void storeSubCommand(SubCommand subCommand) {
|
||||
@@ -41,9 +41,9 @@ public class CommandManager implements CommandExecutor {
|
||||
if (args.length > 0) {
|
||||
if (sender instanceof Player player) {
|
||||
if (subCommands.containsKey(args[0].toLowerCase())) {
|
||||
final SubCommand subCommand = getSubCommand(args[0].toLowerCase());
|
||||
SubCommand subCommand = getSubCommand(args[0].toLowerCase());
|
||||
if (!player.hasPermission(subCommand.getPermission())) {
|
||||
player.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_NO_PERMISSION.getString(null));
|
||||
player.sendMessage(Lang.PREFIX.getString(null) + Lang.ERROR_NO_PERMISSION.getString(null));
|
||||
return true;
|
||||
}
|
||||
subCommand.perform(player, args);
|
||||
@@ -57,7 +57,7 @@ public class CommandManager implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
getSubCommand("help").performSender(sender, args);
|
||||
getSubCommand("help").performConsole(sender, args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,8 +1,8 @@
|
||||
package lee.code.tcf.spigot.commands;
|
||||
package dev.lee.tcf.commands;
|
||||
|
||||
import lee.code.tcf.spigot.data.PlaceHolders;
|
||||
import lee.code.tcf.spigot.util.CoreUtil;
|
||||
import lee.code.tcf.spigot.data.CustomArgData;
|
||||
import dev.lee.tcf.data.CustomArgData;
|
||||
import dev.lee.tcf.data.Placeholders;
|
||||
import dev.lee.tcf.util.CoreUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@@ -21,15 +21,15 @@ public class CustomTabCompletion implements TabCompleter {
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (customArgData.isPermissionCheck()) {
|
||||
if (customArgData.getArgs().containsKey(args.length)) {
|
||||
final List<String> filteredList = new ArrayList<>();
|
||||
List<String> filteredList = new ArrayList<>();
|
||||
for (String commandArg : customArgData.getArgs().get(args.length)) {
|
||||
if (sender.hasPermission(customArgData.getPermission() + commandArg)) filteredList.add(commandArg);
|
||||
}
|
||||
return filteredList;
|
||||
}
|
||||
} else if (customArgData.getArgs().containsKey(args.length)) {
|
||||
final List<String> listArgs = customArgData.getArgs().get(args.length);
|
||||
if (listArgs.contains(PlaceHolders.ONLINE_PLAYERS.getPlaceholder())) return CoreUtil.getOnlinePlayers();
|
||||
List<String> listArgs = customArgData.getArgs().get(args.length);
|
||||
if (listArgs.contains(Placeholders.ONLINE_PLAYERS.getPlaceholder())) return CoreUtil.getOnlinePlayers();
|
||||
else return listArgs;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
+7
-4
@@ -1,17 +1,20 @@
|
||||
package lee.code.tcf.spigot.commands;
|
||||
package dev.lee.tcf.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class SubCommand {
|
||||
public abstract String getName();
|
||||
public abstract String getDescription();
|
||||
public abstract String getSyntax();
|
||||
public abstract String getUsage();
|
||||
public abstract String getPermission();
|
||||
public abstract void perform(Player player, String[] args);
|
||||
public abstract void performConsole(CommandSender console, String[] args);
|
||||
public abstract void performSender(CommandSender sender, String[] args);
|
||||
public abstract List<String> onTabComplete(CommandSender sender, String[] args);
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
+5
-9
@@ -1,28 +1,24 @@
|
||||
package lee.code.tcf.spigot.commands;
|
||||
package dev.lee.tcf.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
public class TabCompletion implements TabCompleter {
|
||||
private final CommandManager commandManager;
|
||||
|
||||
public TabCompletion(CommandManager commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
if (args.length == 1) {
|
||||
final ArrayList<String> hasCommand = new ArrayList<>();
|
||||
for (SubCommand subCommand : commandManager.getSubCommandList()) if (sender.hasPermission(subCommand.getPermission())) hasCommand.add(subCommand.getName());
|
||||
ArrayList<String> hasCommand = new ArrayList<>();
|
||||
for (SubCommand subCommand : TabCompleteFilter.getInstance().getCommandManager().getSubCommandList()) if (sender.hasPermission(subCommand.getPermission())) hasCommand.add(subCommand.getName());
|
||||
return StringUtil.copyPartialMatches(args[0], hasCommand, new ArrayList<>());
|
||||
} else {
|
||||
final SubCommand subCommand = commandManager.getSubCommand(args[0].toLowerCase());
|
||||
SubCommand subCommand = TabCompleteFilter.getInstance().getCommandManager().getSubCommand(args[0].toLowerCase());
|
||||
if (sender.hasPermission(subCommand.getPermission())) return subCommand.onTabComplete(sender, args);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
@@ -0,0 +1,79 @@
|
||||
package dev.lee.tcf.commands.subcommands;
|
||||
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import dev.lee.tcf.commands.SubCommand;
|
||||
import dev.lee.tcf.files.files.Lang;
|
||||
import dev.lee.tcf.manager.TabManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AddCMD extends SubCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "add";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return Lang.CMD_ADD_DESCRIPTION.getString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "/tcf add &f<group> <command>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "tcf.command.add";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Player player, String[] args) {
|
||||
if (args.length < 3) {
|
||||
player.sendMessage(Lang.USAGE.getString(new String[]{getUsage()}));
|
||||
return;
|
||||
}
|
||||
addGroupCommand(player, args[1], args[2].toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performConsole(CommandSender console, String[] args) {
|
||||
if (args.length < 3) {
|
||||
console.sendMessage(Lang.USAGE.getString(new String[]{getUsage()}));
|
||||
return;
|
||||
}
|
||||
addGroupCommand(console, args[1], args[2].toLowerCase());
|
||||
}
|
||||
|
||||
private void addGroupCommand(CommandSender sender, String group, String command) {
|
||||
TabManager tabManager = TabCompleteFilter.getInstance().getTabManager();
|
||||
if (!tabManager.hasGroupData(group)) {
|
||||
sender.sendMessage(Lang.PREFIX.getString() + Lang.ERROR_GROUP_DOES_NOT_EXIST.getString(new String[]{group}));
|
||||
return;
|
||||
}
|
||||
if (!command.contains("/")) {
|
||||
sender.sendMessage(Lang.PREFIX.getString() + Lang.ERROR_COMMAND_NOT_A_COMMAND.getString(new String[]{command}));
|
||||
return;
|
||||
}
|
||||
if (tabManager.hasGroupCommand(group, command)) {
|
||||
sender.sendMessage(Lang.PREFIX.getString() + Lang.ERROR_COMMAND_ADD_DUPE.getString(new String[]{command, group}));
|
||||
return;
|
||||
}
|
||||
tabManager.addGroupCommand(group, command);
|
||||
TabCompleteFilter.getInstance().getFileManager().setGroupCommands(group, tabManager.getGroupCommands(group));
|
||||
sender.sendMessage(Lang.PREFIX.getString() + Lang.CMD_ADD_SUCCESSFUL.getString(new String[]{command, group}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
if (args.length == 2) return StringUtil.copyPartialMatches(args[1], TabCompleteFilter.getInstance().getTabManager().getGroups(), new ArrayList<>());
|
||||
else return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package dev.lee.tcf.commands.subcommands;
|
||||
|
||||
import dev.lee.tcf.files.files.Lang;
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import dev.lee.tcf.commands.SubCommand;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class HelpCMD extends SubCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return Lang.CMD_HELP_DESCRIPTION.getString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "/tcf help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "tcf.command.help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Player player, String[] args) {
|
||||
help(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performConsole(CommandSender console, String[] args) {
|
||||
help(console);
|
||||
}
|
||||
|
||||
private void help(CommandSender sender) {
|
||||
int number = 1;
|
||||
List<TextComponent> lines = new LinkedList<>();
|
||||
lines.add(Lang.CMD_HELP_DIVIDER.getTextComponent());
|
||||
lines.add(new TextComponent(""));
|
||||
lines.add(Lang.CMD_HELP_TITLE.getTextComponent());
|
||||
lines.add(new TextComponent(""));
|
||||
|
||||
List<SubCommand> subCommands = TabCompleteFilter.getInstance().getCommandManager().getSubCommandList();
|
||||
subCommands.sort(Comparator.comparing(SubCommand::getName, String.CASE_INSENSITIVE_ORDER));
|
||||
|
||||
for (SubCommand subCommand : subCommands) {
|
||||
if (!sender.hasPermission(subCommand.getPermission())) continue;
|
||||
TextComponent helpSubCommand = Lang.CMD_HELP_SUB_COMMAND.getTextComponent(new String[]{String.valueOf(number), subCommand.getUsage()});
|
||||
helpSubCommand.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tcf " + subCommand.getName()));
|
||||
helpSubCommand.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Lang.CMD_HELP_SUB_COMMAND_HOVER.getString(new String[]{subCommand.getDescription()})).create()));
|
||||
lines.add(helpSubCommand);
|
||||
number++;
|
||||
}
|
||||
lines.add(new TextComponent(""));
|
||||
lines.add(Lang.CMD_HELP_DIVIDER.getTextComponent());
|
||||
for (TextComponent line : lines) sender.spigot().sendMessage(line);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package dev.lee.tcf.commands.subcommands;
|
||||
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import dev.lee.tcf.commands.SubCommand;
|
||||
import dev.lee.tcf.files.files.Lang;
|
||||
import dev.lee.tcf.manager.TabManager;
|
||||
import dev.lee.tcf.util.CoreUtil;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ListCMD extends SubCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "list";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return Lang.CMD_LIST_DESCRIPTION.getString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "/tcf list &f<group> <page>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "tcf.command.list";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Player player, String[] args) {
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(Lang.USAGE.getString(new String[]{getUsage()}));
|
||||
return;
|
||||
}
|
||||
if (args.length > 2) listGroupCommands(player, args[1], args[2]);
|
||||
else listGroupCommands(player, args[1], null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performConsole(CommandSender console, String[] args) {
|
||||
if (args.length < 2) {
|
||||
console.sendMessage(Lang.USAGE.getString(new String[]{getUsage()}));
|
||||
return;
|
||||
}
|
||||
if (args.length > 2) listGroupCommands(console, args[1], args[2]);
|
||||
else listGroupCommands(console, args[1], null);
|
||||
}
|
||||
|
||||
private void listGroupCommands(CommandSender sender, String group, String pageString) {
|
||||
TabManager tabManager = TabCompleteFilter.getInstance().getTabManager();
|
||||
if (!tabManager.hasGroupData(group)) {
|
||||
sender.sendMessage(Lang.PREFIX.getString() + Lang.ERROR_GROUP_DOES_NOT_EXIST.getString(new String[]{group}));
|
||||
return;
|
||||
}
|
||||
|
||||
int index;
|
||||
int page = 0;
|
||||
int maxDisplayed = 10;
|
||||
if (CoreUtil.isPositiveInt(pageString)) page = Integer.parseInt(pageString);
|
||||
int position = page * maxDisplayed + 1;
|
||||
|
||||
List<String> commandList = tabManager.getGroupCommands(group);
|
||||
commandList.sort(String::compareToIgnoreCase);
|
||||
|
||||
List<TextComponent> lines = new LinkedList<>();
|
||||
lines.add(Lang.CMD_LIST_HEADER_SPLITTER.getTextComponent());
|
||||
lines.add(new TextComponent(""));
|
||||
lines.add(Lang.CMD_LIST_HEADER_GROUP.getTextComponent(new String[]{group}));
|
||||
lines.add(new TextComponent(""));
|
||||
|
||||
for (int i = 0; i < maxDisplayed; i++) {
|
||||
index = maxDisplayed * page + i;
|
||||
if (index >= commandList.size()) break;
|
||||
String command = commandList.get(index);
|
||||
lines.add(Lang.CMD_LIST_LINE.getTextComponent(new String[]{String.valueOf(position), command}));
|
||||
position++;
|
||||
}
|
||||
|
||||
if (lines.size() == 4) return;
|
||||
lines.add(new TextComponent(""));
|
||||
lines.add(CoreUtil.createPageSelectionMessage("/tcf list " + group, page));
|
||||
for (TextComponent line : lines) sender.spigot().sendMessage(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
if (args.length == 2) return StringUtil.copyPartialMatches(args[1], TabCompleteFilter.getInstance().getTabManager().getGroups(), new ArrayList<>());
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package dev.lee.tcf.commands.subcommands;
|
||||
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import dev.lee.tcf.commands.SubCommand;
|
||||
import dev.lee.tcf.files.files.Args;
|
||||
import dev.lee.tcf.files.files.Lang;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ReloadCMD extends SubCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return Lang.CMD_RELOAD_DESCRIPTION.getString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "/tcf reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "tcf.command.reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Player player, String[] args) {
|
||||
reload(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performConsole(CommandSender console, String[] args) {
|
||||
reload(console);
|
||||
}
|
||||
|
||||
private void reload(CommandSender sender) {
|
||||
TabCompleteFilter.getInstance().getFileData().loadFiles();
|
||||
if (Args.ENABLED.getBoolean()) TabCompleteFilter.getInstance().registerCustomTabCompletes();
|
||||
sender.sendMessage(Lang.PREFIX.getString() + Lang.CMD_RELOAD_SUCCESSFUL.getString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package dev.lee.tcf.commands.subcommands;
|
||||
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import dev.lee.tcf.commands.SubCommand;
|
||||
import dev.lee.tcf.files.files.Lang;
|
||||
import dev.lee.tcf.manager.TabManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RemoveCMD extends SubCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "remove";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return Lang.CMD_REMOVE_DESCRIPTION.getString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "/tcf remove &f<group> <command>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "tcf.command.remove";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Player player, String[] args) {
|
||||
if (args.length < 3) {
|
||||
player.sendMessage(Lang.USAGE.getString(new String[]{getUsage()}));
|
||||
return;
|
||||
}
|
||||
removeGroupCommand(player, args[1], args[2].toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performConsole(CommandSender console, String[] args) {
|
||||
if (args.length < 3) {
|
||||
console.sendMessage(Lang.USAGE.getString(new String[]{getUsage()}));
|
||||
return;
|
||||
}
|
||||
removeGroupCommand(console, args[1], args[2].toLowerCase());
|
||||
}
|
||||
|
||||
private void removeGroupCommand(CommandSender sender, String group, String command) {
|
||||
TabManager tabManager = TabCompleteFilter.getInstance().getTabManager();
|
||||
if (!tabManager.hasGroupData(group)) {
|
||||
sender.sendMessage(Lang.PREFIX.getString() + Lang.ERROR_GROUP_DOES_NOT_EXIST.getString(new String[]{group}));
|
||||
return;
|
||||
}
|
||||
if (!command.contains("/")) {
|
||||
sender.sendMessage(Lang.PREFIX.getString() + Lang.ERROR_COMMAND_NOT_A_COMMAND.getString(new String[]{command}));
|
||||
return;
|
||||
}
|
||||
if (!tabManager.hasGroupCommand(group, command)) {
|
||||
sender.sendMessage(Lang.PREFIX.getString() + Lang.ERROR_COMMAND_REMOVE_DOES_NOT_EXIST.getString(new String[]{command, group}));
|
||||
return;
|
||||
}
|
||||
tabManager.removeGroupCommand(group, command);
|
||||
TabCompleteFilter.getInstance().getFileManager().setGroupCommands(group, tabManager.getGroupCommands(group));
|
||||
sender.sendMessage(Lang.PREFIX.getString() + Lang.CMD_REMOVE_SUCCESSFUL.getString(new String[]{command, group}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
if (args.length == 2) return StringUtil.copyPartialMatches(args[1], TabCompleteFilter.getInstance().getTabManager().getGroups(), new ArrayList<>());
|
||||
else if (args.length == 3) return StringUtil.copyPartialMatches(args[2], TabCompleteFilter.getInstance().getTabManager().getGroupCommands(args[1]), new ArrayList<>());
|
||||
else return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.lee.tcf.data;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class CustomArgData {
|
||||
private final String command;
|
||||
private final boolean permissionCheck;
|
||||
private final String permission;
|
||||
private final Map<Integer, List<String>> args;
|
||||
}
|
||||
+4
-3
@@ -1,11 +1,12 @@
|
||||
package lee.code.tcf.spigot.data;
|
||||
package dev.lee.tcf.data;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum PlaceHolders {
|
||||
public enum Placeholders {
|
||||
ONLINE_PLAYERS("%online_players%"),
|
||||
;
|
||||
@Getter private final String placeholder;
|
||||
private final String placeholder;
|
||||
}
|
||||
+9
-12
@@ -1,10 +1,8 @@
|
||||
package lee.code.tcf.spigot.files;
|
||||
package dev.lee.tcf.files;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import org.bukkit.Bukkit;
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class CustomYML extends FileManager {
|
||||
@@ -12,10 +10,9 @@ public class CustomYML extends FileManager {
|
||||
private final File path;
|
||||
private YamlConfiguration yamlConfiguration;
|
||||
|
||||
public CustomYML(TabCompleteFilter tabCompleteFilter, String name, String path) {
|
||||
super(tabCompleteFilter);
|
||||
this.file = new File(tabCompleteFilter.getDataFolder(), name);
|
||||
this.path = new File(tabCompleteFilter.getDataFolder(), path);
|
||||
public CustomYML(String name, String path) {
|
||||
this.file = new File(TabCompleteFilter.getInstance().getDataFolder(), name);
|
||||
this.path = new File(TabCompleteFilter.getInstance().getDataFolder(), path);
|
||||
createFile();
|
||||
}
|
||||
|
||||
@@ -31,7 +28,7 @@ public class CustomYML extends FileManager {
|
||||
try {
|
||||
yamlConfiguration.save(file);
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to save file: " + file.getName());
|
||||
TabCompleteFilter.getInstance().getLogger().log(Level.WARNING, "Failed to save file: " + file.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,14 +37,14 @@ public class CustomYML extends FileManager {
|
||||
try {
|
||||
boolean createdDir = path.mkdir();
|
||||
} catch (SecurityException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to create directory for file: " + file.getName());
|
||||
TabCompleteFilter.getInstance().getLogger().log(Level.WARNING, "Failed to create directory for file: " + file.getName());
|
||||
}
|
||||
}
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
tabCompleteFilter.saveResource(file.getName(), false);
|
||||
TabCompleteFilter.getInstance().saveResource(file.getName(), false);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to create file: " + file.getName());
|
||||
TabCompleteFilter.getInstance().getLogger().log(Level.WARNING, "Failed to create file: " + file.getName());
|
||||
}
|
||||
}
|
||||
reloadFile();
|
||||
@@ -0,0 +1,73 @@
|
||||
package dev.lee.tcf.files;
|
||||
|
||||
import dev.lee.tcf.files.files.Args;
|
||||
import dev.lee.tcf.files.files.Config;
|
||||
import dev.lee.tcf.files.files.Lang;
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import dev.lee.tcf.data.CustomArgData;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FileData {
|
||||
|
||||
public FileData() {
|
||||
loadFiles();
|
||||
}
|
||||
|
||||
public void loadFiles() {
|
||||
loadConfig();
|
||||
loadLang();
|
||||
loadArgs();
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
FileManager fileManager = TabCompleteFilter.getInstance().getFileManager();
|
||||
fileManager.createYML("config");
|
||||
CustomYML customYML = fileManager.getYML("config");
|
||||
YamlConfiguration yaml = customYML.getFile();
|
||||
|
||||
for (Config config : Config.values()) {
|
||||
if (yaml.contains(config.getPath())) continue;
|
||||
yaml.set(config.getPath(), config.getObject());
|
||||
}
|
||||
customYML.saveFile();
|
||||
TabCompleteFilter.getInstance().getTabManager().getGroupDataMap().clear();
|
||||
|
||||
for (Map.Entry<String, List<String>> groupData : fileManager.getAllGroupData().entrySet()) {
|
||||
TabCompleteFilter.getInstance().getTabManager().addGroupData(groupData.getKey(), groupData.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void loadLang() {
|
||||
FileManager fileManager = TabCompleteFilter.getInstance().getFileManager();
|
||||
fileManager.createYML("lang");
|
||||
CustomYML customYML = fileManager.getYML("lang");
|
||||
YamlConfiguration yaml = customYML.getFile();
|
||||
|
||||
for (Lang lang : Lang.values()) {
|
||||
if (yaml.contains(lang.getPath())) continue;
|
||||
yaml.set(lang.getPath(), lang.getObject());
|
||||
}
|
||||
customYML.saveFile();
|
||||
}
|
||||
|
||||
private void loadArgs() {
|
||||
FileManager fileManager = TabCompleteFilter.getInstance().getFileManager();
|
||||
fileManager.createYML("args");
|
||||
CustomYML customYML = fileManager.getYML("args");
|
||||
YamlConfiguration yaml = customYML.getFile();
|
||||
|
||||
for (Args args : Args.values()) {
|
||||
if (yaml.contains(args.getPath())) continue;
|
||||
yaml.set(args.getPath(), args.getObject());
|
||||
}
|
||||
customYML.saveFile();
|
||||
TabCompleteFilter.getInstance().getTabManager().getCustomArgDataMap().clear();
|
||||
|
||||
for (Map.Entry<String, CustomArgData> argData : fileManager.getAllCustomArgData().entrySet()) {
|
||||
TabCompleteFilter.getInstance().getTabManager().addCustomArgData(argData.getKey(), argData.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package dev.lee.tcf.files;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import dev.lee.tcf.data.CustomArgData;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class FileManager {
|
||||
protected final HashMap<String, CustomYML> ymlFiles = new HashMap<>();
|
||||
|
||||
public FileManager() {
|
||||
Locale.setDefault(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public void createYML(String name) {
|
||||
ymlFiles.put(name, new CustomYML(name + ".yml", ""));
|
||||
}
|
||||
|
||||
public CustomYML getYML(String name) {
|
||||
return ymlFiles.get(name);
|
||||
}
|
||||
|
||||
public String getString(String file, String path) {
|
||||
return ymlFiles.get(file).getFile().getString(path);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String config, String path) {
|
||||
return ymlFiles.get(config).getFile().getBoolean(path);
|
||||
}
|
||||
|
||||
public int getInt(String config, String path) {
|
||||
return ymlFiles.get(config).getFile().getInt(path);
|
||||
}
|
||||
|
||||
public void setInt(String config, String path, int value) {
|
||||
CustomYML yml = ymlFiles.get(config);
|
||||
FileConfiguration fileConfig = yml.getFile();
|
||||
fileConfig.set(path, value);
|
||||
yml.saveFile();
|
||||
}
|
||||
|
||||
public void setString(String config, String path, String string) {
|
||||
CustomYML yml = ymlFiles.get(config);
|
||||
FileConfiguration fileConfig = yml.getFile();
|
||||
fileConfig.set(path, string);
|
||||
yml.saveFile();
|
||||
}
|
||||
|
||||
public void setGroupCommands(String group, List<String> commands) {
|
||||
CustomYML yml = getYML("config");
|
||||
YamlConfiguration yaml = yml.getFile();
|
||||
yaml.set("groups." + group, commands);
|
||||
yml.saveFile();
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getAllGroupData() {
|
||||
Map<String, List<String>> groupData = new HashMap<>();
|
||||
CustomYML customYML = getYML("config");
|
||||
YamlConfiguration yaml = customYML.getFile();
|
||||
|
||||
for (String key : yaml.getConfigurationSection("groups").getKeys(false)) {
|
||||
try {
|
||||
groupData.put(key, yaml.getStringList("groups." + key));
|
||||
} catch (Exception e) {
|
||||
TabCompleteFilter.getInstance().getLogger().log(Level.WARNING, "Failed to load group " + key + ": ", e);
|
||||
}
|
||||
}
|
||||
return groupData;
|
||||
}
|
||||
|
||||
public Map<String, CustomArgData> getAllCustomArgData() {
|
||||
Map<String, CustomArgData> argData = new HashMap<>();
|
||||
CustomYML customYML = getYML("args");
|
||||
YamlConfiguration yaml = customYML.getFile();
|
||||
|
||||
for (String key : yaml.getConfigurationSection("custom-args").getKeys(false)) {
|
||||
try {
|
||||
String base = "custom-args." + key;
|
||||
boolean permissionCheck = yaml.getBoolean(base + ".permission-check");
|
||||
String permission = yaml.getString(base + ".permission");
|
||||
String command = yaml.getString(base + ".command");
|
||||
Map<Integer, List<String>> args = new HashMap<>();
|
||||
for (String argKey : yaml.getConfigurationSection(base + ".args").getKeys(false)) {
|
||||
int number = Integer.parseInt(argKey);
|
||||
List<String> numberArgs = yaml.getStringList(base + ".args." + argKey);
|
||||
args.put(number, numberArgs);
|
||||
}
|
||||
|
||||
CustomArgData customArgData = CustomArgData.builder()
|
||||
.permissionCheck(permissionCheck)
|
||||
.permission(permission)
|
||||
.command(command)
|
||||
.args(args)
|
||||
.build();
|
||||
|
||||
argData.put(command, customArgData);
|
||||
} catch (Exception e) {
|
||||
TabCompleteFilter.getInstance().getLogger().log(Level.WARNING, "Failed to load custom arg " + key + ": ", e);
|
||||
}
|
||||
}
|
||||
return argData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package dev.lee.tcf.files.files;
|
||||
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum Args {
|
||||
ENABLED("enabled", false),
|
||||
;
|
||||
|
||||
private final String path;
|
||||
private final Object object;
|
||||
|
||||
public boolean getBoolean() {
|
||||
return TabCompleteFilter.getInstance().getFileManager().getBoolean("args", path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package dev.lee.tcf.files.files;
|
||||
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum Config {
|
||||
OP_BYPASS("op-player-filter-bypass", false),
|
||||
;
|
||||
|
||||
private final String path;
|
||||
private final Object object;
|
||||
|
||||
public boolean getBoolean() {
|
||||
return TabCompleteFilter.getInstance().getFileManager().getBoolean("config", path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package dev.lee.tcf.files.files;
|
||||
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import dev.lee.tcf.util.CoreUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum Lang {
|
||||
PREFIX("&6&lTCF &e➔ &r"),
|
||||
USAGE("&6&lUsage&7: &e{0}"),
|
||||
NEXT_PAGE_TEXT("&2&lNext &a&l>>&a---------"),
|
||||
PREVIOUS_PAGE_TEXT("&a---------&a&l<< &2&lPrev"),
|
||||
PAGE_SPACER_TEXT(" &e| "),
|
||||
NEXT_PAGE_HOVER("&6&lNext Page"),
|
||||
PREVIOUS_PAGE_HOVER("&6&lPrevious Page"),
|
||||
|
||||
CMD_HELP_DIVIDER("&a▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"),
|
||||
CMD_HELP_TITLE(" &2-== &6&l&nTabCompleteFilter Help&r &2==-"),
|
||||
CMD_HELP_SUB_COMMAND("&3{0}&b. &e{1}"),
|
||||
CMD_HELP_SUB_COMMAND_HOVER("&6{0}"),
|
||||
CMD_RELOAD_SUCCESSFUL("&aThe plugin has been reloaded."),
|
||||
CMD_LIST_HEADER_SPLITTER("&a&l------------------------------"),
|
||||
CMD_LIST_HEADER_GROUP("&6&lGroup&7: &9{0}"),
|
||||
CMD_LIST_LINE("&3{0}&b. &e{1}"),
|
||||
CMD_ADD_SUCCESSFUL("&aYou successfully added the command &3{0} &ato the group &3{1}&a!"),
|
||||
CMD_REMOVE_SUCCESSFUL("&aYou successfully removed the command &3{0} &afrom the group &3{1}&a!"),
|
||||
CMD_REMOVE_DESCRIPTION("Remove an existing group command."),
|
||||
CMD_RELOAD_DESCRIPTION("Reloads the plugin yml files."),
|
||||
CMD_HELP_DESCRIPTION("A list of all plugin commands."),
|
||||
CMD_LIST_DESCRIPTION("List of all group commands."),
|
||||
CMD_ADD_DESCRIPTION("Add a command to a group."),
|
||||
|
||||
ERROR_NO_PERMISSION("&cYou sadly do not have permission for this."),
|
||||
ERROR_COMMAND_REMOVE_DOES_NOT_EXIST("&cThe command &3{0} &ccould not be found in the group &3{1}&c."),
|
||||
ERROR_GROUP_DOES_NOT_EXIST("&cThe group &3{0} &cdoes not exist."),
|
||||
ERROR_NOT_A_CONSOLE_COMMAND("&cThis is not a console command."),
|
||||
ERROR_COMMAND_NOT_A_COMMAND("&cThe input &3{0} &cis not a command. You need to add a slash."),
|
||||
ERROR_COMMAND_ADD_DUPE("&cThe command &3{0} &cis already set for the group &3{1}&c."),
|
||||
ERROR_CUSTOM_TAB_COMPLETE_NOT_REGISTERED("The command ({0}) is not registered so a custom tab-complete handler could not be registered for this command."),
|
||||
;
|
||||
|
||||
private final Object object;
|
||||
|
||||
public String getPath() {
|
||||
return name();
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return CoreUtil.parseColor(TabCompleteFilter.getInstance().getFileManager().getString("lang", getPath()));
|
||||
}
|
||||
|
||||
public String getString(String[] variables) {
|
||||
String text = getString();
|
||||
if (variables == null || variables.length == 0) return text;
|
||||
for (int i = 0; i < variables.length; i++) text = text.replace("{" + i + "}", variables[i]);
|
||||
return CoreUtil.parseColor(text);
|
||||
}
|
||||
|
||||
public TextComponent getTextComponent() {
|
||||
return new TextComponent(getString());
|
||||
}
|
||||
|
||||
public TextComponent getTextComponent(String[] variables) {
|
||||
return new TextComponent(getString(variables));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package dev.lee.tcf.listeners;
|
||||
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import dev.lee.tcf.files.files.Config;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandSendEvent;
|
||||
import java.util.List;
|
||||
|
||||
public class FilterListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onCommandTabShow(PlayerCommandSendEvent e) {
|
||||
if (Config.OP_BYPASS.getBoolean() && e.getPlayer().isOp()) return;
|
||||
if (!e.getPlayer().isOp() && e.getPlayer().hasPermission("tcf.bypass")) return;
|
||||
e.getCommands().clear();
|
||||
List<String> groups = TabCompleteFilter.getInstance().getTabManager().getPlayerGroups(e.getPlayer());
|
||||
if (groups.isEmpty()) return;
|
||||
for (String group : groups) {
|
||||
for (String command : TabCompleteFilter.getInstance().getTabManager().getGroupCommands(group)) e.getCommands().add(command.replaceFirst("/", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.lee.tcf.listeners;
|
||||
|
||||
import dev.lee.tcf.TabCompleteFilter;
|
||||
import dev.lee.tcf.files.files.Args;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerLoadEvent;
|
||||
|
||||
public class ServerLoadListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onServerLoad(ServerLoadEvent event) {
|
||||
if (Args.ENABLED.getBoolean()) TabCompleteFilter.getInstance().registerCustomTabCompletes();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package dev.lee.tcf.manager;
|
||||
|
||||
import dev.lee.tcf.data.CustomArgData;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Getter
|
||||
public class TabManager {
|
||||
private final Map<String, List<String>> groupDataMap = new HashMap<>();
|
||||
private final Map<String, CustomArgData> customArgDataMap = new HashMap<>();
|
||||
|
||||
public void addGroupData(String group, List<String> commands) {
|
||||
groupDataMap.put(group, commands);
|
||||
}
|
||||
|
||||
public void addGroupCommand(String group, String command) {
|
||||
groupDataMap.get(group).add(command);
|
||||
}
|
||||
|
||||
public void removeGroupCommand(String group, String command) {
|
||||
groupDataMap.get(group).remove(command);
|
||||
}
|
||||
|
||||
public boolean hasGroupData(String group) {
|
||||
return groupDataMap.containsKey(group);
|
||||
}
|
||||
|
||||
public boolean hasGroupCommand(String group, String command) {
|
||||
return groupDataMap.get(group).contains(command);
|
||||
}
|
||||
|
||||
public List<String> getGroupCommands(String group) {
|
||||
if (!groupDataMap.containsKey(group)) return new ArrayList<>();
|
||||
return groupDataMap.get(group);
|
||||
}
|
||||
|
||||
public Set<String> getGroups() {
|
||||
return groupDataMap.keySet();
|
||||
}
|
||||
|
||||
public List<String> getPlayerGroups(Player player) {
|
||||
List<String> groups = new ArrayList<>();
|
||||
for (String group : getGroups()) {
|
||||
if (player.hasPermission("tcf." + group)) groups.add(group);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void addCustomArgData(String command, CustomArgData customArgData) {
|
||||
customArgDataMap.put(command, customArgData);
|
||||
}
|
||||
|
||||
public CustomArgData getCustomArgData(String command) {
|
||||
return customArgDataMap.get(command);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package dev.lee.tcf.util;
|
||||
|
||||
import dev.lee.tcf.files.files.Lang;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CoreUtil {
|
||||
private final static int mcVersion = Integer.parseInt(getMajorVersion(Bukkit.getVersion()).substring(2));
|
||||
private final static Pattern hexPattern = Pattern.compile("\\&#[a-fA-F0-9]{6}");
|
||||
|
||||
public static String parseColor(String text) {
|
||||
if (text == null) return "";
|
||||
if (isSupported(16)) {
|
||||
Matcher matcher = hexPattern.matcher(text);
|
||||
while (matcher.find()) {
|
||||
String color = text.substring(matcher.start(), matcher.end()).replaceAll("&", "");
|
||||
text = text.replace("&" + color, net.md_5.bungee.api.ChatColor.of(color) + "");
|
||||
matcher = hexPattern.matcher(text);
|
||||
}
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
|
||||
private static String getMajorVersion(String version) {
|
||||
if (version == null) return null;
|
||||
int index = version.lastIndexOf("MC:");
|
||||
if (index != -1) {
|
||||
version = version.substring(index + 4, version.length() - 1);
|
||||
} else if (version.endsWith("SNAPSHOT")) {
|
||||
index = version.indexOf('-');
|
||||
version = version.substring(0, index);
|
||||
}
|
||||
int lastDot = version.lastIndexOf('.');
|
||||
if (version.indexOf('.') != lastDot) version = version.substring(0, lastDot);
|
||||
return version;
|
||||
}
|
||||
|
||||
public static boolean isSupported(int version) {
|
||||
return mcVersion >= version;
|
||||
}
|
||||
|
||||
public static boolean isPositiveInt(String input) {
|
||||
if (input == null || input.isEmpty()) return false;
|
||||
try {
|
||||
int value = Integer.parseInt(input);
|
||||
return value > 0;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getOnlinePlayers() {
|
||||
List<String> players = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!player.getGameMode().equals(GameMode.SPECTATOR)) players.add(player.getName());
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
public static TextComponent createHoverMessage(String message, String hoverText) {
|
||||
TextComponent messageComponent = new TextComponent(parseColor(message));
|
||||
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(parseColor(hoverText)).create());
|
||||
messageComponent.setHoverEvent(hoverEvent);
|
||||
return messageComponent;
|
||||
}
|
||||
|
||||
public static TextComponent createHoverClickMessage(String message, String hoverText, String command) {
|
||||
TextComponent messageComponent = createHoverMessage(message, hoverText);
|
||||
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, command);
|
||||
messageComponent.setClickEvent(clickEvent);
|
||||
return messageComponent;
|
||||
}
|
||||
|
||||
public static TextComponent createPageSelectionMessage(String command, int page) {
|
||||
TextComponent prev = createHoverClickMessage(Lang.PREVIOUS_PAGE_TEXT.getString(), Lang.PREVIOUS_PAGE_HOVER.getString(), command + " " + (page - 1));
|
||||
TextComponent split = createHoverMessage(Lang.PAGE_SPACER_TEXT.getString(), "");
|
||||
TextComponent next = createHoverClickMessage(Lang.NEXT_PAGE_TEXT.getString(), Lang.NEXT_PAGE_HOVER.getString(), command + " " + (page + 1));
|
||||
prev.addExtra(split);
|
||||
prev.addExtra(next);
|
||||
return prev;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package lee.code.tcf.spigot;
|
||||
|
||||
import lee.code.tcf.spigot.data.CustomArgData;
|
||||
import lee.code.tcf.spigot.data.Data;
|
||||
import lee.code.tcf.spigot.commands.CommandManager;
|
||||
import lee.code.tcf.spigot.commands.CustomTabCompletion;
|
||||
import lee.code.tcf.spigot.commands.TabCompletion;
|
||||
import lee.code.tcf.spigot.files.FileManager;
|
||||
import lee.code.tcf.spigot.files.files.FileLang;
|
||||
import lee.code.tcf.spigot.listeners.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TabCompleteFilter extends JavaPlugin {
|
||||
@Getter private static TabCompleteFilter instance;
|
||||
@Getter private FileManager fileManager;
|
||||
@Getter private CommandManager commandManager;
|
||||
@Getter private Data data;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
this.fileManager = new FileManager(this);
|
||||
this.data = new Data(this);
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
registerListeners();
|
||||
registerCommands();
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
getCommand("tcf").setExecutor(commandManager);
|
||||
getCommand("tcf").setTabCompleter(new TabCompletion(commandManager));
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
getServer().getPluginManager().registerEvents(new FilterListener(this), this);
|
||||
getServer().getPluginManager().registerEvents(new ServerLoadListener(this), this);
|
||||
}
|
||||
|
||||
public void registerCustomTabCompletes() {
|
||||
final HashMap<String, CustomArgData> customArgData = getData().getCustomArgData();
|
||||
if (customArgData.isEmpty()) return;
|
||||
|
||||
for (String command : customArgData.keySet()) {
|
||||
final PluginCommand pluginCommand = Bukkit.getServer().getPluginCommand(command);
|
||||
if (pluginCommand == null) {
|
||||
Bukkit.getLogger().log(Level.WARNING, FileLang.ERROR_CUSTOM_TAB_COMPLETE_NOT_REGISTERED.getString(new String[]{command}));
|
||||
continue;
|
||||
}
|
||||
pluginCommand.setTabCompleter(new CustomTabCompletion(customArgData.get(command)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package lee.code.tcf.spigot.commands.subcommands;
|
||||
|
||||
import lee.code.tcf.spigot.data.Data;
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lee.code.tcf.spigot.commands.SubCommand;
|
||||
import lee.code.tcf.spigot.files.FileManager;
|
||||
import lee.code.tcf.spigot.files.files.FileLang;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AddCMD extends SubCommand {
|
||||
private final TabCompleteFilter tabCompleteFilter;
|
||||
|
||||
public AddCMD(TabCompleteFilter tabCompleteFilter) {
|
||||
this.tabCompleteFilter = tabCompleteFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "add";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return FileLang.COMMAND_ADD_DESCRIPTION.getString(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/tcf add &f<group> <command>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "tcf.command.add";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Player player, String[] args) {
|
||||
performSender(player, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performConsole(CommandSender console, String[] args) {
|
||||
performSender(console, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performSender(CommandSender sender, String[] args) {
|
||||
final FileManager fileManager = tabCompleteFilter.getFileManager();
|
||||
final Data data = tabCompleteFilter.getData();
|
||||
if (args.length > 1) {
|
||||
if (args.length > 2) {
|
||||
if (!data.getAllGroups().contains(args[1])) {
|
||||
sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_GROUP_DOES_NOT_EXIST.getString(new String[]{args[1]}));
|
||||
return;
|
||||
}
|
||||
final String group = args[1];
|
||||
if (!args[2].contains("/")) {
|
||||
sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_COMMAND_NOT_A_COMMAND.getString(new String[]{args[2]}));
|
||||
return;
|
||||
}
|
||||
final String command = args[2].toLowerCase();
|
||||
if (data.getGroupCommands(group).contains(command)) {
|
||||
sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_COMMAND_ADD_DUPE.getString(new String[]{command, group}));
|
||||
return;
|
||||
}
|
||||
data.addGroupCommand(group, command);
|
||||
fileManager.setGroupCommands(group);
|
||||
sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.COMMAND_ADD_SUCCESSFUL.getString(new String[]{command, group}));
|
||||
} else sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_COMMAND_ADD_ARG_2.getString(null));
|
||||
} else sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_COMMAND_ADD_ARG_1.getString(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
if (args.length == 2) return StringUtil.copyPartialMatches(args[1], tabCompleteFilter.getData().getAllGroups(), new ArrayList<>());
|
||||
else return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package lee.code.tcf.spigot.commands.subcommands;
|
||||
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lee.code.tcf.spigot.commands.SubCommand;
|
||||
import lee.code.tcf.spigot.files.files.FileLang;
|
||||
import lee.code.tcf.spigot.util.CoreUtil;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HelpCMD extends SubCommand {
|
||||
private final TabCompleteFilter tabCompleteFilter;
|
||||
|
||||
public HelpCMD(TabCompleteFilter tabCompleteFilter) {
|
||||
this.tabCompleteFilter = tabCompleteFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return FileLang.COMMAND_HELP_DESCRIPTION.getString(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/tcf help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "shop.command.help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Player player, String[] args) {
|
||||
performSender(player, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performConsole(CommandSender console, String[] args) {
|
||||
performSender(console, args);
|
||||
}
|
||||
|
||||
@Override @SuppressWarnings("deprecation")
|
||||
public void performSender(CommandSender sender, String[] args) {
|
||||
int number = 1;
|
||||
final List<TextComponent> lines = new ArrayList<>();
|
||||
lines.add(FileLang.COMMAND_HELP_DIVIDER.getTextComponent(null));
|
||||
lines.add(FileLang.COMMAND_HELP_TITLE.getTextComponent(null));
|
||||
lines.add(new TextComponent(""));
|
||||
|
||||
for (SubCommand subCommand : tabCompleteFilter.getCommandManager().getSubCommandList()) {
|
||||
if (sender.hasPermission(subCommand.getPermission())) {
|
||||
final String suggestCommand = CoreUtil.getTextBeforeCharacter(subCommand.getSyntax(), '&');
|
||||
final TextComponent helpSubCommand = FileLang.COMMAND_HELP_SUB_COMMAND.getTextComponent(new String[]{String.valueOf(number), subCommand.getSyntax()});
|
||||
helpSubCommand.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggestCommand));
|
||||
helpSubCommand.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(FileLang.COMMAND_HELP_SUB_COMMAND_HOVER.getString(new String[]{subCommand.getDescription()})).create()));
|
||||
lines.add(helpSubCommand);
|
||||
number++;
|
||||
}
|
||||
}
|
||||
lines.add(new TextComponent(""));
|
||||
lines.add(FileLang.COMMAND_HELP_DIVIDER.getTextComponent(null));
|
||||
for (TextComponent line : lines) sender.spigot().sendMessage(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package lee.code.tcf.spigot.commands.subcommands;
|
||||
|
||||
import lee.code.tcf.spigot.util.CoreUtil;
|
||||
import lee.code.tcf.spigot.data.Data;
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lee.code.tcf.spigot.commands.SubCommand;
|
||||
import lee.code.tcf.spigot.files.files.FileLang;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListCMD extends SubCommand {
|
||||
private final TabCompleteFilter tabCompleteFilter;
|
||||
|
||||
public ListCMD(TabCompleteFilter tabCompleteFilter) {
|
||||
this.tabCompleteFilter = tabCompleteFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "list";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return FileLang.COMMAND_LIST_DESCRIPTION.getString(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/tcf list &f<group>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "tcf.command.list";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void perform(Player player, String[] args) {
|
||||
final Data data = tabCompleteFilter.getData();
|
||||
if (args.length > 1) {
|
||||
if (!data.getAllGroups().contains(args[1])) {
|
||||
player.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_GROUP_DOES_NOT_EXIST.getString(new String[]{args[1]}));
|
||||
return;
|
||||
}
|
||||
final String group = args[1];
|
||||
final int maxDisplayed = 10;
|
||||
int index;
|
||||
int page = 0;
|
||||
if (args.length > 2) {
|
||||
if (CoreUtil.isPositiveIntNumber(args[2])) page = Integer.parseInt(args[2]);
|
||||
}
|
||||
final List<TextComponent> lines = new ArrayList<>();
|
||||
final List<String> commands = data.getGroupCommands(group);
|
||||
if (commands != null && !commands.isEmpty()) {
|
||||
lines.add(FileLang.COMMAND_LIST_HEADER_SPLITTER.getTextComponent(null));
|
||||
lines.add(new TextComponent(""));
|
||||
lines.add(FileLang.COMMAND_LIST_HEADER_GROUP.getTextComponent(new String[]{group}));
|
||||
lines.add(new TextComponent(""));
|
||||
for (int i = 0; i < maxDisplayed; i++) {
|
||||
index = maxDisplayed * page + i;
|
||||
if (index >= commands.size()) break;
|
||||
if (commands.get(index) != null) {
|
||||
final int commandNumber = index + 1;
|
||||
final String command = commands.get(index);
|
||||
lines.add(FileLang.COMMAND_LIST_LINE.getTextComponent(new String[]{String.valueOf(commandNumber), command}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lines.size() == 4) return;
|
||||
lines.add(new TextComponent(""));
|
||||
|
||||
final TextComponent next = FileLang.COMMAND_LIST_NEXT_PAGE.getTextComponent(null);
|
||||
next.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(FileLang.COMMAND_LIST_NEXT_PAGE_HOVER.getString(null)).create()));
|
||||
next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tcf list " + group + " " + (page + 1)));
|
||||
|
||||
final TextComponent split = FileLang.COMMAND_LIST_PAGE_SPACER.getTextComponent(null);
|
||||
|
||||
final TextComponent prev = FileLang.COMMAND_LIST_PREVIOUS_PAGE.getTextComponent(null);
|
||||
prev.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(FileLang.COMMAND_LIST_PREVIOUS_PAGE_HOVER.getString(null)).create()));
|
||||
prev.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tcf list " + group + " " + (page - 1)));
|
||||
|
||||
prev.addExtra(split);
|
||||
prev.addExtra(next);
|
||||
lines.add(prev);
|
||||
|
||||
for (TextComponent line : lines) player.spigot().sendMessage(line);
|
||||
} else player.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_COMMAND_LIST_ARG_1.getString(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performConsole(CommandSender console, String[] args) {
|
||||
console.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_NOT_A_CONSOLE_COMMAND.getString(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performSender(CommandSender sender, String[] args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
if (args.length == 2) return StringUtil.copyPartialMatches(args[1], tabCompleteFilter.getData().getAllGroups(), new ArrayList<>());
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package lee.code.tcf.spigot.commands.subcommands;
|
||||
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lee.code.tcf.spigot.commands.SubCommand;
|
||||
import lee.code.tcf.spigot.files.files.FileArgs;
|
||||
import lee.code.tcf.spigot.files.files.FileLang;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ReloadCMD extends SubCommand {
|
||||
private final TabCompleteFilter tabCompleteFilter;
|
||||
|
||||
public ReloadCMD(TabCompleteFilter tabCompleteFilter) {
|
||||
this.tabCompleteFilter = tabCompleteFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return FileLang.COMMAND_RELOAD_DESCRIPTION.getString(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/tcf reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "tcf.command.reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Player player, String[] args) {
|
||||
performSender(player, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performConsole(CommandSender console, String[] args) {
|
||||
performSender(console, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performSender(CommandSender sender, String[] args) {
|
||||
tabCompleteFilter.getData().load();
|
||||
if (FileArgs.ENABLED.getBoolean()) tabCompleteFilter.registerCustomTabCompletes();
|
||||
sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.COMMAND_RELOAD_SUCCESSFUL.getString(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package lee.code.tcf.spigot.commands.subcommands;
|
||||
|
||||
import lee.code.tcf.spigot.data.Data;
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lee.code.tcf.spigot.commands.SubCommand;
|
||||
import lee.code.tcf.spigot.files.FileManager;
|
||||
import lee.code.tcf.spigot.files.files.FileLang;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class RemoveCMD extends SubCommand {
|
||||
private final TabCompleteFilter tabCompleteFilter;
|
||||
|
||||
public RemoveCMD(TabCompleteFilter tabCompleteFilter) {
|
||||
this.tabCompleteFilter = tabCompleteFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "remove";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return FileLang.COMMAND_REMOVE_DESCRIPTION.getString(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/tcf remove &f<group> <command>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "tcf.command.remove";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Player player, String[] args) {
|
||||
performSender(player, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performConsole(CommandSender console, String[] args) {
|
||||
performSender(console, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performSender(CommandSender sender, String[] args) {
|
||||
final FileManager fileManager = tabCompleteFilter.getFileManager();
|
||||
final Data data = tabCompleteFilter.getData();
|
||||
if (args.length > 1) {
|
||||
if (args.length > 2) {
|
||||
if (!data.getAllGroups().contains(args[1])) {
|
||||
sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_GROUP_DOES_NOT_EXIST.getString(new String[]{args[1]}));
|
||||
return;
|
||||
}
|
||||
final String group = args[1];
|
||||
if (!args[2].contains("/")) {
|
||||
sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_COMMAND_NOT_A_COMMAND.getString(new String[]{args[2]}));
|
||||
return;
|
||||
}
|
||||
final String command = args[2].toLowerCase();
|
||||
if (!data.getGroupCommands(group).contains(command)) {
|
||||
sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_COMMAND_REMOVE_DOES_NOT_EXIST.getString(new String[]{command, group}));
|
||||
return;
|
||||
}
|
||||
data.removeGroupCommand(group, command);
|
||||
fileManager.setGroupCommands(group);
|
||||
sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.COMMAND_REMOVE_SUCCESSFUL.getString(new String[]{command, group}));
|
||||
} else sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_COMMAND_REMOVE_ARG_2.getString(null));
|
||||
} else sender.sendMessage(FileLang.PREFIX.getString(null) + FileLang.ERROR_COMMAND_REMOVE_ARG_1.getString(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
if (args.length == 2) return StringUtil.copyPartialMatches(args[1], tabCompleteFilter.getData().getAllGroups(), new ArrayList<>());
|
||||
else if (args.length == 3) return StringUtil.copyPartialMatches(args[2], Collections.singletonList("<command>"), new ArrayList<>());
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package lee.code.tcf.spigot.data;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class CustomArgData {
|
||||
@Getter private final boolean permissionCheck;
|
||||
@Getter private final String permission;
|
||||
@Getter private final HashMap<Integer, List<String>> args;
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
package lee.code.tcf.spigot.data;
|
||||
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lee.code.tcf.spigot.files.CustomYML;
|
||||
import lee.code.tcf.spigot.files.FileManager;
|
||||
import lee.code.tcf.spigot.files.files.File;
|
||||
import lee.code.tcf.spigot.files.files.FileArgs;
|
||||
import lee.code.tcf.spigot.files.files.FileConfig;
|
||||
import lee.code.tcf.spigot.files.files.FileLang;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Data {
|
||||
private final TabCompleteFilter tabCompleteFilter;
|
||||
@Getter private final HashMap<String, List<String>> groupData = new HashMap<>();
|
||||
@Getter private final HashMap<String, CustomArgData> customArgData = new HashMap<>();
|
||||
|
||||
public Data(TabCompleteFilter tabCompleteFilter) {
|
||||
this.tabCompleteFilter = tabCompleteFilter;
|
||||
load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
getGroupData().clear();
|
||||
getCustomArgData().clear();
|
||||
loadFiles();
|
||||
}
|
||||
|
||||
public List<String> getGroupCommands(String group) {
|
||||
return getGroupData().get(group);
|
||||
}
|
||||
|
||||
public List<String> getAllGroups() {
|
||||
return List.copyOf(getGroupData().keySet());
|
||||
}
|
||||
|
||||
public void addGroupCommand(String group, String command) {
|
||||
getGroupData().get(group).add(command);
|
||||
}
|
||||
|
||||
public void removeGroupCommand(String group, String command) {
|
||||
getGroupData().get(group).remove(command);
|
||||
}
|
||||
|
||||
public ArrayList<String> getPlayerGroup(Player player) {
|
||||
return getAllGroups().stream()
|
||||
.filter(group -> player.hasPermission("tcf." + group))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
|
||||
private void loadFiles() {
|
||||
loadFile(File.LANG.name().toLowerCase(), File.LANG);
|
||||
loadFile(File.CONFIG.name().toLowerCase(), File.CONFIG);
|
||||
loadFile(File.ARGS.name().toLowerCase(), File.ARGS);
|
||||
}
|
||||
|
||||
private void loadFile(String config, File file) {
|
||||
final FileManager fileManager = tabCompleteFilter.getFileManager();
|
||||
fileManager.createYML(config);
|
||||
final CustomYML customYML = fileManager.getYML(config);
|
||||
final YamlConfiguration yaml = customYML.getFile();
|
||||
|
||||
switch (file) {
|
||||
case CONFIG -> {
|
||||
for (FileConfig value : FileConfig.values()) {
|
||||
if (!yaml.contains(value.getPath())) {
|
||||
switch (value.getFileDataType()) {
|
||||
case BOOLEAN -> yaml.set(value.getPath(), Boolean.parseBoolean(value.getString()));
|
||||
case DOUBLE -> yaml.set(value.getPath(), Double.parseDouble(value.getString()));
|
||||
case INT -> yaml.set(value.getPath(), Integer.parseInt(value.getString()));
|
||||
case STRING -> yaml.set(value.getPath(), value.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
final ConfigurationSection groups = yaml.getConfigurationSection("groups");
|
||||
if (groups == null) return;
|
||||
groups.getKeys(false).forEach(group -> getGroupData().put(group, new ArrayList<>(groups.getStringList(group))));
|
||||
}
|
||||
case LANG -> {
|
||||
for (FileLang value : FileLang.values()) {
|
||||
if (!yaml.contains(value.getPath())) yaml.set(value.getPath(), value.getString());
|
||||
}
|
||||
}
|
||||
case ARGS -> {
|
||||
for (FileArgs value : FileArgs.values()) {
|
||||
if (!yaml.contains(value.getPath())) {
|
||||
switch (value.getFileDataType()) {
|
||||
case BOOLEAN -> yaml.set(value.getPath(), Boolean.parseBoolean(value.getString()));
|
||||
case DOUBLE -> yaml.set(value.getPath(), Double.parseDouble(value.getString()));
|
||||
case INT -> yaml.set(value.getPath(), Integer.parseInt(value.getString()));
|
||||
case STRING -> yaml.set(value.getPath(), value.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final ConfigurationSection commands = yaml.getConfigurationSection("custom-args");
|
||||
if (commands == null) return;
|
||||
commands.getKeys(false).forEach(commandID -> {
|
||||
final ConfigurationSection id = commands.getConfigurationSection(commandID);
|
||||
if (id == null) return;
|
||||
final String command = id.getString("command");
|
||||
if (command == null) return;
|
||||
final boolean permissionCheck = id.getBoolean("permission-check");
|
||||
final String permission = id.getString("permission");
|
||||
|
||||
final ConfigurationSection args = id.getConfigurationSection("args");
|
||||
if (args == null) return;
|
||||
final HashMap<Integer, List<String>> commandArgs = new HashMap<>();
|
||||
args.getKeys(false).forEach(argNumber -> {
|
||||
final List<String> argList = args.getStringList(argNumber);
|
||||
commandArgs.put(Integer.parseInt(argNumber), argList);
|
||||
});
|
||||
getCustomArgData().put(command, new CustomArgData(permissionCheck, permission, commandArgs));
|
||||
});
|
||||
}
|
||||
}
|
||||
customYML.saveFile();
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package lee.code.tcf.spigot.files;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import lee.code.tcf.spigot.util.CoreUtil;
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lee.code.tcf.spigot.files.files.File;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class FileManager {
|
||||
protected TabCompleteFilter tabCompleteFilter;
|
||||
protected final HashMap<String, CustomYML> ymlFiles = new HashMap<>();
|
||||
|
||||
public FileManager(TabCompleteFilter tabCompleteFilter) {
|
||||
this.tabCompleteFilter = tabCompleteFilter;
|
||||
Locale.setDefault(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public void createYML(String name) {
|
||||
ymlFiles.put(name, new CustomYML(tabCompleteFilter, name + ".yml", ""));
|
||||
}
|
||||
|
||||
public CustomYML getYML(String name) {
|
||||
return ymlFiles.get(name);
|
||||
}
|
||||
|
||||
public String getStringFromFile(String config, String path, String[] variables) {
|
||||
final FileConfiguration fileConfig = ymlFiles.get(config).getFile();
|
||||
String value = fileConfig.getString(path);
|
||||
value = value != null ? value : "";
|
||||
if (variables == null || variables.length == 0) return CoreUtil.parseColorString(value);
|
||||
for (int i = 0; i < variables.length; i++) value = value.replace("{" + i + "}", variables[i]);
|
||||
return CoreUtil.parseColorString(value);
|
||||
}
|
||||
|
||||
public boolean getBooleanFromFile(String config, String path) {
|
||||
return ymlFiles.get(config).getFile().getBoolean(path);
|
||||
}
|
||||
|
||||
public int getValueFromFile(String config, String path) {
|
||||
final FileConfiguration fileConfig = ymlFiles.get(config).getFile();
|
||||
final String value = fileConfig.getString(path);
|
||||
return value != null ? Integer.parseInt(value) : 0;
|
||||
}
|
||||
|
||||
public void setValueInFile(String config, String path, int value) {
|
||||
final CustomYML yml = ymlFiles.get(config);
|
||||
final FileConfiguration fileConfig = yml.getFile();
|
||||
fileConfig.set(path, value);
|
||||
yml.saveFile();
|
||||
}
|
||||
|
||||
public void setStringInFile(String config, String path, String string) {
|
||||
final CustomYML yml = ymlFiles.get(config);
|
||||
final FileConfiguration fileConfig = yml.getFile();
|
||||
fileConfig.set(path, string);
|
||||
yml.saveFile();
|
||||
}
|
||||
|
||||
public void setGroupCommands(String group) {
|
||||
final CustomYML yml = ymlFiles.get(File.CONFIG.name().toLowerCase());
|
||||
final FileConfiguration fileConfig = yml.getFile();
|
||||
fileConfig.set("groups." + group, tabCompleteFilter.getData().getGroupCommands(group));
|
||||
yml.saveFile();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package lee.code.tcf.spigot.files.files;
|
||||
|
||||
public enum File {
|
||||
CONFIG, LANG, ARGS
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package lee.code.tcf.spigot.files.files;
|
||||
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum FileArgs {
|
||||
ENABLED("enabled", "false", FileDataType.BOOLEAN),
|
||||
;
|
||||
|
||||
@Getter private final String path;
|
||||
@Getter private final String string;
|
||||
@Getter private final FileDataType fileDataType;
|
||||
|
||||
public boolean getBoolean() {
|
||||
return TabCompleteFilter.getInstance().getFileManager().getBooleanFromFile(File.ARGS.name().toLowerCase(), path);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package lee.code.tcf.spigot.files.files;
|
||||
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum FileConfig {
|
||||
OP_BYPASS("op-player-filter-bypass", "false", FileDataType.BOOLEAN),
|
||||
;
|
||||
@Getter private final String path;
|
||||
@Getter private final String string;
|
||||
@Getter private final FileDataType fileDataType;
|
||||
|
||||
public boolean getBoolean() {
|
||||
return TabCompleteFilter.getInstance().getFileManager().getBooleanFromFile(File.CONFIG.name().toLowerCase(), path);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package lee.code.tcf.spigot.files.files;
|
||||
|
||||
public enum FileDataType {
|
||||
BOOLEAN, INT, DOUBLE, STRING, LIST
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package lee.code.tcf.spigot.files.files;
|
||||
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum FileLang {
|
||||
PREFIX("prefix", "&6&lTCF &e➔ &r"),
|
||||
COMMAND_HELP_DIVIDER("command_help_divider", "&a▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"),
|
||||
COMMAND_HELP_TITLE("command_help_title", " &2-== &6&l&nTabCompleteFilter Help&r &2==-"),
|
||||
COMMAND_HELP_SUB_COMMAND("command_help_sub_command", "&3{0}&b. &e{1}"),
|
||||
COMMAND_HELP_SUB_COMMAND_HOVER("command_help_sub_command_hover", "&6{0}"),
|
||||
COMMAND_RELOAD_SUCCESSFUL("command_reload_successful", "&aThe plugin has been reloaded."),
|
||||
COMMAND_LIST_HEADER_SPLITTER("command_list_header_splitter", "&a&l------------------------------"),
|
||||
COMMAND_LIST_HEADER_GROUP("command_list_header_group", "&e&lGroup&7: &9{0}"),
|
||||
COMMAND_LIST_LINE("command_list_line", "&3{0}&b. &6{1}"),
|
||||
COMMAND_LIST_NEXT_PAGE("command_list_next_page", "&2&lNext &a&l>>--------"),
|
||||
COMMAND_LIST_NEXT_PAGE_HOVER("command_list_next_page_hover", "&6&lNext Page"),
|
||||
COMMAND_LIST_PAGE_SPACER("command_list_page_spacer", " &e| "),
|
||||
COMMAND_LIST_PREVIOUS_PAGE("command_list_previous_page", "&a&l--------<< &2&lPrev"),
|
||||
COMMAND_LIST_PREVIOUS_PAGE_HOVER("command_list_previous_page_hover", "&6&lPrevious Page"),
|
||||
COMMAND_ADD_SUCCESSFUL("command_add_successful", "&aYou successfully added the command &6{0} &ato the group &6{1}&a!"),
|
||||
COMMAND_REMOVE_SUCCESSFUL("command_remove_successful", "&aYou successfully removed the command &6{0} &afrom the group &6{1}&a!"),
|
||||
COMMAND_REMOVE_DESCRIPTION("command_remove_description", "Remove an existing group."),
|
||||
COMMAND_RELOAD_DESCRIPTION("command_reload_description", "Reloads the TabCompleteFilter plugin, this will read all yml files again and apply changes if any."),
|
||||
COMMAND_HELP_DESCRIPTION("command_help_description", "A list of commands you can use with this plugin."),
|
||||
COMMAND_LIST_DESCRIPTION("command_list_description", "List of all groups and permissions."),
|
||||
COMMAND_ADD_DESCRIPTION("command_add_description", "Add commands to groups."),
|
||||
ERROR_NO_PERMISSION("error_no_permission", "&cYou sadly do not have permission for this."),
|
||||
ERROR_COMMAND_REMOVE_ARG_1("error_command_remove_arg_1", "&cYou need to select a group and input a command to remove."),
|
||||
ERROR_COMMAND_REMOVE_ARG_2("error_command_remove_arg_2", "&cYou need to input a command to remove."),
|
||||
ERROR_COMMAND_REMOVE_DOES_NOT_EXIST("error_command_remove_does_not_exist", "&cThe command &6{0} &ccould not be found in the group &6{1}&c."),
|
||||
ERROR_COMMAND_ADD_ARG_1("error_command_add_arg_1", "&cYou need to select a group and input a command to add."),
|
||||
ERROR_COMMAND_ADD_ARG_2("error_command_add_arg_2", "&cYou need to input a command to add."),
|
||||
ERROR_GROUP_DOES_NOT_EXIST("error_group_does_not_exist", "&cThe group &6{0} &cdoes not exist."),
|
||||
ERROR_COMMAND_LIST_ARG_1("error_command_list_arg_1", "&cYou need to select a group."),
|
||||
ERROR_NOT_A_CONSOLE_COMMAND("error_not_a_console_command", "&cThis is not a console command."),
|
||||
ERROR_COMMAND_NOT_A_COMMAND("error_command_not_a_command", "&cThe input &6{0} &cis not a command. You need to add a slash."),
|
||||
ERROR_COMMAND_ADD_DUPE("error_command_add_dupe", "&cThe command &6{0} &cis already set for the group &6{1}&c."),
|
||||
ERROR_CUSTOM_TAB_COMPLETE_NOT_REGISTERED("error_custom_tab_complete_not_registered", "The command ({0}) is not registered so a custom tab-complete handler could not be set for this command. Make sure it's the command registered to the server, not the alias."),
|
||||
;
|
||||
|
||||
@Getter private final String path;
|
||||
@Getter private final String string;
|
||||
|
||||
public String getString(String[] variables) {
|
||||
return TabCompleteFilter.getInstance().getFileManager().getStringFromFile(File.LANG.name().toLowerCase(), getPath(), variables);
|
||||
}
|
||||
|
||||
public TextComponent getTextComponent(String[] variables) {
|
||||
return new TextComponent(TabCompleteFilter.getInstance().getFileManager().getStringFromFile(File.LANG.name().toLowerCase(), getPath(), variables));
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package lee.code.tcf.spigot.listeners;
|
||||
|
||||
import lee.code.tcf.spigot.data.Data;
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lee.code.tcf.spigot.files.files.FileConfig;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandSendEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FilterListener implements Listener {
|
||||
private final TabCompleteFilter tabCompleteFilter;
|
||||
|
||||
public FilterListener(TabCompleteFilter tabCompleteFilter) {
|
||||
this.tabCompleteFilter = tabCompleteFilter;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onCommandTabShow(PlayerCommandSendEvent e) {
|
||||
final Player player = e.getPlayer();
|
||||
if (FileConfig.OP_BYPASS.getBoolean() && player.isOp()) return;
|
||||
if (!player.isOp() && player.hasPermission("tcf.bypass")) return;
|
||||
e.getCommands().clear();
|
||||
final Data data = tabCompleteFilter.getData();
|
||||
final ArrayList<String> groups = data.getPlayerGroup(player);
|
||||
if (groups.isEmpty()) return;
|
||||
for (String group : groups) {
|
||||
for (String command : data.getGroupCommands(group)) e.getCommands().add(command.replaceFirst("/", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package lee.code.tcf.spigot.listeners;
|
||||
|
||||
import lee.code.tcf.spigot.TabCompleteFilter;
|
||||
import lee.code.tcf.spigot.files.files.FileArgs;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerLoadEvent;
|
||||
|
||||
public class ServerLoadListener implements Listener {
|
||||
private final TabCompleteFilter tabCompleteFilter;
|
||||
|
||||
public ServerLoadListener(TabCompleteFilter tabCompleteFilter) {
|
||||
this.tabCompleteFilter = tabCompleteFilter;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerLoad(ServerLoadEvent event) {
|
||||
if (FileArgs.ENABLED.getBoolean()) tabCompleteFilter.registerCustomTabCompletes();
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package lee.code.tcf.spigot.util;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CoreUtil {
|
||||
private final static int mcVersion = Integer.parseInt(getMajorVersion(Bukkit.getVersion()).substring(2));
|
||||
private final static Pattern hexPattern = Pattern.compile("\\&#[a-fA-F0-9]{6}");
|
||||
private final static Pattern numberIntPattern = Pattern.compile("^[1-9]\\d*$");
|
||||
|
||||
public static String parseColorString(String text) {
|
||||
if (text == null) return "";
|
||||
if (isSupported(16)) {
|
||||
Matcher matcher = hexPattern.matcher(text);
|
||||
while (matcher.find()) {
|
||||
final String color = text.substring(matcher.start(), matcher.end()).replaceAll("&", "");
|
||||
text = text.replace("&" + color, net.md_5.bungee.api.ChatColor.of(color) + "");
|
||||
matcher = hexPattern.matcher(text);
|
||||
}
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
|
||||
private static String getMajorVersion(String version) {
|
||||
if (version == null) return null;
|
||||
int index = version.lastIndexOf("MC:");
|
||||
if (index != -1) {
|
||||
version = version.substring(index + 4, version.length() - 1);
|
||||
} else if (version.endsWith("SNAPSHOT")) {
|
||||
index = version.indexOf('-');
|
||||
version = version.substring(0, index);
|
||||
}
|
||||
final int lastDot = version.lastIndexOf('.');
|
||||
if (version.indexOf('.') != lastDot) version = version.substring(0, lastDot);
|
||||
return version;
|
||||
}
|
||||
|
||||
public static boolean isSupported(int version) {
|
||||
return mcVersion >= version;
|
||||
}
|
||||
|
||||
public static boolean isPositiveIntNumber(String numbers) {
|
||||
final String intMax = String.valueOf(Integer.MAX_VALUE);
|
||||
if (numbers.length() > intMax.length() || (numbers.length() == intMax.length() && numbers.compareTo(intMax) > 0)) return false;
|
||||
return numberIntPattern.matcher(numbers).matches();
|
||||
}
|
||||
|
||||
public static String getTextBeforeCharacter(String input, char character) {
|
||||
final int index = input.indexOf(character);
|
||||
if (index == -1) return input;
|
||||
else return input.substring(0, index);
|
||||
}
|
||||
|
||||
public static List<String> getOnlinePlayers() {
|
||||
final List<String> players = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!player.getGameMode().equals(GameMode.SPECTATOR)) players.add(player.getName());
|
||||
}
|
||||
return players;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package lee.code.tcf.waterfall;
|
||||
|
||||
import lee.code.tcf.waterfall.files.ConfigManager;
|
||||
import lee.code.tcf.waterfall.listeners.FilterListener;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
public class TabCompleteFilter extends Plugin {
|
||||
@Getter private ConfigManager configManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.configManager = new ConfigManager(this);
|
||||
|
||||
getConfigManager().loadConfig();
|
||||
getProxy().getPluginManager().registerListener(this, new FilterListener(this));
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package lee.code.tcf.waterfall.files;
|
||||
|
||||
import lee.code.tcf.waterfall.TabCompleteFilter;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigManager {
|
||||
private final TabCompleteFilter tabCompleteFilter;
|
||||
private Configuration configuration;
|
||||
private File configFile;
|
||||
|
||||
public ConfigManager(TabCompleteFilter tabCompleteFilter) {
|
||||
this.tabCompleteFilter = tabCompleteFilter;
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
configFile = new File(tabCompleteFilter.getDataFolder(), "bungee-config.yml");
|
||||
|
||||
if (!configFile.exists()) {
|
||||
tabCompleteFilter.getDataFolder().mkdirs();
|
||||
try (InputStream inputStream = tabCompleteFilter.getResourceAsStream("bungee-config.yml")) {
|
||||
Files.copy(inputStream, configFile.toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
try {
|
||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, configFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getWhiteList() {
|
||||
return configuration.getStringList("whitelist");
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package lee.code.tcf.waterfall.listeners;
|
||||
|
||||
import io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent;
|
||||
import lee.code.tcf.waterfall.TabCompleteFilter;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FilterListener implements Listener {
|
||||
private final TabCompleteFilter tabCompleteFilter;
|
||||
|
||||
public FilterListener(TabCompleteFilter tabCompleteFilter) {
|
||||
this.tabCompleteFilter = tabCompleteFilter;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onTabCompleteResponse(ProxyDefineCommandsEvent e) {
|
||||
if (e.getReceiver() instanceof ProxiedPlayer proxiedPlayer) {
|
||||
if (proxiedPlayer.hasPermission("tcf.bypass")) return;
|
||||
final Set<String> whitelist = new HashSet<>(tabCompleteFilter.getConfigManager().getWhiteList());
|
||||
final Map<String, Command> filteredCommands = new HashMap<>();
|
||||
|
||||
for (Command command : e.getCommands().values()) {
|
||||
if (whitelist.contains("/" + command.getName())) {
|
||||
filteredCommands.put(command.getName(), command);
|
||||
}
|
||||
}
|
||||
|
||||
e.getCommands().clear();
|
||||
e.getCommands().putAll(filteredCommands);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ enabled: false
|
||||
custom-args:
|
||||
'1':
|
||||
permission-check: true
|
||||
permission: 'essentials.warp.'
|
||||
permission: 'essentials.warps.'
|
||||
command: 'warp'
|
||||
args:
|
||||
'1':
|
||||
@@ -24,4 +24,4 @@ custom-args:
|
||||
'4':
|
||||
- a
|
||||
'5':
|
||||
- example!
|
||||
- example!
|
||||
@@ -1,5 +0,0 @@
|
||||
# Input all the commands you want to allow users to see that are registered to the proxy
|
||||
# To filter spigot server commands, you need to install this plugin on each server and give the user the correct group perm
|
||||
# This ONLY works on Waterfall, Bungeecord by itself does not have an event listener for doing this
|
||||
whitelist:
|
||||
- /server
|
||||
@@ -1,5 +0,0 @@
|
||||
name: TabCompleteFilter
|
||||
main: lee.code.tcf.waterfall.TabCompleteFilter
|
||||
version: ${version}
|
||||
api-version: 1.13
|
||||
author: Lee
|
||||
@@ -1 +0,0 @@
|
||||
#lang
|
||||
@@ -1,5 +1,5 @@
|
||||
name: TabCompleteFilter
|
||||
main: lee.code.tcf.spigot.TabCompleteFilter
|
||||
main: dev.lee.tcf.TabCompleteFilter
|
||||
version: ${version}
|
||||
api-version: 1.13
|
||||
folia-supported: true
|
||||
|
||||
Reference in new issue
Block a user