mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-11 22:16:57 +00:00
f
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package eu.endermite.commandwhitelist;
|
||||
|
||||
import eu.endermite.commandwhitelist.command.MainCommand;
|
||||
import eu.endermite.commandwhitelist.config.ConfigCache;
|
||||
import eu.endermite.commandwhitelist.listeners.PlayerCommandPreProcess;
|
||||
import eu.endermite.commandwhitelist.listeners.PlayerCommandSend;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class CommandWhitelist extends JavaPlugin {
|
||||
public class CommandWhitelist extends JavaPlugin {
|
||||
|
||||
private static CommandWhitelist commandWhitelist;
|
||||
private static ConfigCache configCache;
|
||||
@@ -18,19 +19,20 @@ public final class CommandWhitelist extends JavaPlugin {
|
||||
|
||||
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcess(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerCommandSend(), this);
|
||||
getCommand("commandwhitelist").setExecutor(new MainCommand());
|
||||
getCommand("commandwhitelist").setTabCompleter(new MainCommand());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
|
||||
public void reloadPluginConfig() {
|
||||
saveDefaultConfig();
|
||||
configCache = new ConfigCache(this.getConfig());
|
||||
configCache = new ConfigCache();
|
||||
}
|
||||
|
||||
public static CommandWhitelist getPlugin() {return commandWhitelist;}
|
||||
public static ConfigCache getConfigCache() {return configCache;}
|
||||
|
||||
public static <T> T TODO(final String reason) {
|
||||
throw new RuntimeException(reason);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package eu.endermite.commandwhitelist.command;
|
||||
|
||||
import eu.endermite.commandwhitelist.CommandWhitelist;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MainCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (sender.hasPermission("commandwhitelist.reload")) {
|
||||
CommandWhitelist.getPlugin().reloadPluginConfig();
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getConfigReloaded()));
|
||||
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getNoPermission()));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getNoSubCommand()));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bCommand Whitelist by YouHaveTrouble"));
|
||||
if (sender.hasPermission("commandwhitelist.reload")) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/cw reload &b- Reload plugin configuration"));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
if(args.length == 1) {
|
||||
if ("restart".startsWith(args[0]) && sender.hasPermission("commandwhitelist.reload")) {
|
||||
list.add("reload");
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package eu.endermite.commandwhitelist.config;
|
||||
|
||||
import eu.endermite.commandwhitelist.CommandWhitelist;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -9,18 +9,24 @@ import java.util.Set;
|
||||
|
||||
public class ConfigCache {
|
||||
|
||||
private final HashMap<String, List<String>> permList = new HashMap<>();
|
||||
private final String prefix;
|
||||
private final String commandDenied;
|
||||
private Configuration config = CommandWhitelist.getPlugin().getConfig();
|
||||
private HashMap<String, List<String>> permList = new HashMap<>();
|
||||
private String prefix, commandDenied, noPermission, noSubCommand, configReloaded;
|
||||
|
||||
public ConfigCache(FileConfiguration yamlConfiguration) {
|
||||
Set<String> perms = yamlConfiguration.getConfigurationSection("commands").getKeys(false);
|
||||
public ConfigCache() {
|
||||
|
||||
CommandWhitelist.getPlugin().reloadConfig();
|
||||
|
||||
prefix = config.getString("messages.prefix");
|
||||
commandDenied = config.getString("messages.command-denied");
|
||||
noPermission = config.getString("messages.no-permission");
|
||||
noSubCommand = config.getString("messages.no-such-subcommand");
|
||||
configReloaded = config.getString("messages.config-reloaded");
|
||||
|
||||
Set<String> perms = config.getConfigurationSection("commands").getKeys(false);
|
||||
for (String s : perms) {
|
||||
this.permList.put(s, CommandWhitelist.getPlugin().getConfig().getStringList("commands."+s));
|
||||
this.permList.put(s, config.getStringList("commands."+s));
|
||||
}
|
||||
|
||||
this.prefix = CommandWhitelist.getPlugin().getConfig().getString("messages.prefix");
|
||||
this.commandDenied = CommandWhitelist.getPlugin().getConfig().getString("messages.command-denied");
|
||||
}
|
||||
|
||||
public HashMap<String, List<String>> getPermList() {
|
||||
@@ -32,4 +38,7 @@ public class ConfigCache {
|
||||
}
|
||||
public String getPrefix() {return prefix;}
|
||||
public String getCommandDenied() {return commandDenied;}
|
||||
public String getNoPermission() {return noPermission;}
|
||||
public String getNoSubCommand() {return noSubCommand;}
|
||||
public String getConfigReloaded() {return configReloaded;}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -35,7 +34,7 @@ public class PlayerCommandPreProcess implements Listener {
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + " " + CommandWhitelist.getConfigCache().getCommandDenied()));
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getCommandDenied()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class PlayerCommandSend implements Listener {
|
||||
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player.hasPermission("commandwhitelist.bypass:")) {
|
||||
if (player.hasPermission("commandwhitelist.bypass")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -29,4 +29,6 @@ public class PlayerCommandSend implements Listener {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
messages:
|
||||
prefix: "CommandWhitelist >"
|
||||
prefix: "CommandWhitelist > "
|
||||
command-denied: "No such command."
|
||||
no-permission: "&cYou don't have permission to do this."
|
||||
no-such-subcommand: "&cNo subcommand by that name."
|
||||
config-reloaded: "&eConfiguration reloaded."
|
||||
|
||||
commands:
|
||||
# Permissions that control what commands players can use
|
||||
|
||||
@@ -4,7 +4,14 @@ main: eu.endermite.commandwhitelist.CommandWhitelist
|
||||
api-version: 1.13
|
||||
authors: [YouHaveTrouble]
|
||||
description: Control what commands players can use
|
||||
commands:
|
||||
commandwhitelist:
|
||||
aliases:
|
||||
- cw
|
||||
usage: /commandwhitelist [args]
|
||||
permissions:
|
||||
commandwhitelist.reload:
|
||||
default: OP
|
||||
commandwhitelist.bypass:
|
||||
default: OP
|
||||
commandwhitelist.commands.default:
|
||||
|
||||
Reference in New Issue
Block a user