mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d246654fa9 | |||
| 5d2fe19586 | |||
| ac8f1b403a | |||
| 023d9b57fe | |||
| eb13e174e9 | |||
| c2dd36d13b | |||
| be4d8d21c0 | |||
| 26b05aef7b | |||
| 687fd0867b | |||
| 733b556166 |
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>eu.endermite</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.4</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>CommandWhitelist</name>
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
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 eu.endermite.commandwhitelist.listeners.PlayerCommandPreProcessListener;
|
||||
import eu.endermite.commandwhitelist.listeners.PlayerCommandSendListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
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;
|
||||
@@ -16,19 +21,27 @@ public final class CommandWhitelist extends JavaPlugin {
|
||||
commandWhitelist = this;
|
||||
reloadPluginConfig();
|
||||
|
||||
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcess(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerCommandSend(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), 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());
|
||||
reloadConfig();
|
||||
configCache = new ConfigCache();
|
||||
}
|
||||
|
||||
public void reloadPluginConfig(CommandSender sender) {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||
reloadPluginConfig();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
p.updateCommands();
|
||||
}
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getConfigReloaded()));
|
||||
});
|
||||
}
|
||||
|
||||
public static CommandWhitelist getPlugin() {return commandWhitelist;}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
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);
|
||||
} 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,23 @@ 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 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() {
|
||||
|
||||
Configuration config = CommandWhitelist.getPlugin().getConfig();
|
||||
|
||||
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 +37,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
-6
@@ -6,13 +6,12 @@ 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;
|
||||
|
||||
public class PlayerCommandPreProcess implements Listener {
|
||||
public class PlayerCommandPreProcessListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
@@ -26,15 +25,16 @@ public class PlayerCommandPreProcess implements Listener {
|
||||
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
|
||||
for (String comm : s.getValue()) {
|
||||
comm = comm.toLowerCase();
|
||||
if (command.startsWith("/" + comm)) {
|
||||
if (command.equalsIgnoreCase("/"+comm))
|
||||
return;
|
||||
else if (command.startsWith("/" + comm + " ")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + " " + CommandWhitelist.getConfigCache().getCommandDenied()));
|
||||
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getCommandDenied()));
|
||||
}
|
||||
|
||||
}
|
||||
+5
-3
@@ -7,13 +7,13 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerCommandSend implements Listener {
|
||||
public class PlayerCommandSendListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
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
|
||||
@@ -9,7 +12,6 @@ commands:
|
||||
# commandwhitelist.commands.default
|
||||
# this will be automatically given to players by default
|
||||
default:
|
||||
- ?
|
||||
- help
|
||||
- spawn
|
||||
- bal
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
name: CommandWhitelist
|
||||
version: ${project.version}
|
||||
main: eu.endermite.commandwhitelist.CommandWhitelist
|
||||
api-version: 1.16
|
||||
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