Compare commits

...

10 Commits

Author SHA1 Message Date
youhavetrouble 86faeb8aeb version bump 2020-07-27 22:15:07 +02:00
youhavetrouble d246654fa9 ????? 2020-07-27 22:03:29 +02:00
youhavetrouble 5d2fe19586 reload command 2020-07-27 18:00:00 +02:00
youhavetrouble ac8f1b403a f 2020-07-27 17:23:12 +02:00
youhavetrouble 023d9b57fe downgraded to 1.13 api version 2020-07-26 17:22:46 +02:00
youhavetrouble eb13e174e9 Merge remote-tracking branch 'origin/master' 2020-07-22 19:46:16 +02:00
youhavetrouble c2dd36d13b Merge remote-tracking branch 'origin/master' 2020-07-22 19:46:09 +02:00
youhavetrouble be4d8d21c0 Merge remote-tracking branch 'origin/master' 2020-07-22 19:45:36 +02:00
youhavetrouble 26b05aef7b improved command execution check 2020-07-22 19:45:27 +02:00
youhavetrouble 687fd0867b improved command execution check 2020-07-22 19:44:55 +02:00
8 changed files with 113 additions and 31 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite</groupId> <groupId>eu.endermite</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>1.0.1</version> <version>1.1.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>CommandWhitelist</name> <name>CommandWhitelist</name>
@@ -1,11 +1,16 @@
package eu.endermite.commandwhitelist; package eu.endermite.commandwhitelist;
import eu.endermite.commandwhitelist.command.MainCommand;
import eu.endermite.commandwhitelist.config.ConfigCache; import eu.endermite.commandwhitelist.config.ConfigCache;
import eu.endermite.commandwhitelist.listeners.PlayerCommandPreProcess; import eu.endermite.commandwhitelist.listeners.PlayerCommandPreProcessListener;
import eu.endermite.commandwhitelist.listeners.PlayerCommandSend; 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; import org.bukkit.plugin.java.JavaPlugin;
public final class CommandWhitelist extends JavaPlugin { public class CommandWhitelist extends JavaPlugin {
private static CommandWhitelist commandWhitelist; private static CommandWhitelist commandWhitelist;
private static ConfigCache configCache; private static ConfigCache configCache;
@@ -16,19 +21,27 @@ public final class CommandWhitelist extends JavaPlugin {
commandWhitelist = this; commandWhitelist = this;
reloadPluginConfig(); reloadPluginConfig();
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcess(), this); getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
getServer().getPluginManager().registerEvents(new PlayerCommandSend(), 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() { public void reloadPluginConfig() {
saveDefaultConfig(); 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;} 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; package eu.endermite.commandwhitelist.config;
import eu.endermite.commandwhitelist.CommandWhitelist; import eu.endermite.commandwhitelist.CommandWhitelist;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.Configuration;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -9,18 +9,23 @@ import java.util.Set;
public class ConfigCache { public class ConfigCache {
private final HashMap<String, List<String>> permList = new HashMap<>(); private HashMap<String, List<String>> permList = new HashMap<>();
private final String prefix; private String prefix, commandDenied, noPermission, noSubCommand, configReloaded;
private final String commandDenied;
public ConfigCache(FileConfiguration yamlConfiguration) { public ConfigCache() {
Set<String> perms = yamlConfiguration.getConfigurationSection("commands").getKeys(false);
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) { 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() { public HashMap<String, List<String>> getPermList() {
@@ -32,4 +37,7 @@ public class ConfigCache {
} }
public String getPrefix() {return prefix;} public String getPrefix() {return prefix;}
public String getCommandDenied() {return commandDenied;} public String getCommandDenied() {return commandDenied;}
public String getNoPermission() {return noPermission;}
public String getNoSubCommand() {return noSubCommand;}
public String getConfigReloaded() {return configReloaded;}
} }
@@ -6,11 +6,10 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class PlayerCommandPreProcess implements Listener { public class PlayerCommandPreProcessListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) { public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
@@ -26,14 +25,16 @@ public class PlayerCommandPreProcess implements Listener {
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) { if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
for (String comm : s.getValue()) { for (String comm : s.getValue()) {
comm = comm.toLowerCase(); comm = comm.toLowerCase();
if (command.startsWith("/" + comm)) { if (command.equalsIgnoreCase("/"+comm))
return;
else if (command.startsWith("/" + comm + " ")) {
return; return;
} }
} }
} }
} }
event.setCancelled(true); event.setCancelled(true);
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + " " + CommandWhitelist.getConfigCache().getCommandDenied())); player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getCommandDenied()));
} }
} }
@@ -7,13 +7,13 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import java.util.*; import java.util.*;
public class PlayerCommandSend implements Listener { public class PlayerCommandSendListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) { public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasPermission("commandwhitelist.bypass:")) { if (player.hasPermission("commandwhitelist.bypass")) {
return; return;
} }
@@ -29,4 +29,6 @@ public class PlayerCommandSend implements Listener {
} }
} }
+3 -1
View File
@@ -1,6 +1,9 @@
messages: messages:
prefix: "CommandWhitelist > " prefix: "CommandWhitelist > "
command-denied: "No such command." 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: commands:
# Permissions that control what commands players can use # Permissions that control what commands players can use
@@ -9,7 +12,6 @@ commands:
# commandwhitelist.commands.default # commandwhitelist.commands.default
# this will be automatically given to players by default # this will be automatically given to players by default
default: default:
- ?
- help - help
- spawn - spawn
- bal - bal
+8 -1
View File
@@ -1,10 +1,17 @@
name: CommandWhitelist name: CommandWhitelist
version: ${project.version} version: ${project.version}
main: eu.endermite.commandwhitelist.CommandWhitelist main: eu.endermite.commandwhitelist.CommandWhitelist
api-version: 1.16 api-version: 1.13
authors: [YouHaveTrouble] authors: [YouHaveTrouble]
description: Control what commands players can use description: Control what commands players can use
commands:
commandwhitelist:
aliases:
- cw
usage: /commandwhitelist [args]
permissions: permissions:
commandwhitelist.reload:
default: OP
commandwhitelist.bypass: commandwhitelist.bypass:
default: OP default: OP
commandwhitelist.commands.default: commandwhitelist.commands.default: