mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-11 22:16:57 +00:00
improved code readability
This commit is contained in:
@@ -24,7 +24,6 @@ public final class CommandWhitelistBungee extends Plugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
plugin = this;
|
plugin = this;
|
||||||
getLogger().info("Running on "+ ChatColor.DARK_AQUA+getProxy().getName());
|
getLogger().info("Running on "+ ChatColor.DARK_AQUA+getProxy().getName());
|
||||||
loadConfig();
|
loadConfig();
|
||||||
@@ -40,18 +39,15 @@ public final class CommandWhitelistBungee extends Plugin {
|
|||||||
|
|
||||||
int pluginId = 8704;
|
int pluginId = 8704;
|
||||||
new BungeeMetrics(this, pluginId);
|
new BungeeMetrics(this, pluginId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommandWhitelistBungee getPlugin() {
|
public static CommandWhitelistBungee getPlugin() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BungeeConfigCache getConfigCache() {
|
public static BungeeConfigCache getConfigCache() {
|
||||||
return configCache;
|
return configCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
try {
|
try {
|
||||||
if (!getDataFolder().exists()) {
|
if (!getDataFolder().exists()) {
|
||||||
@@ -81,5 +77,4 @@ public final class CommandWhitelistBungee extends Plugin {
|
|||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getConfigReloaded()));
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getConfigReloaded()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class BungeeMainCommand extends Command implements TabExecutor {
|
public class BungeeMainCommand extends Command implements TabExecutor {
|
||||||
|
|
||||||
public BungeeMainCommand(String name) {
|
public BungeeMainCommand(String name) {
|
||||||
|
|||||||
+1
-9
@@ -14,28 +14,20 @@ public class BungeeChatEventListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) {
|
public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) {
|
||||||
|
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!(event.getSender() instanceof ProxiedPlayer))
|
if (!(event.getSender() instanceof ProxiedPlayer))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!event.isProxyCommand())
|
if (!event.isProxyCommand())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||||
|
if (player.hasPermission("commandwhitelist.bypass"))
|
||||||
if (player.hasPermission("commandwhitelist.bypass")) {
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
String command = event.getMessage().toLowerCase();
|
String command = event.getMessage().toLowerCase();
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
||||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (String comm : s.getValue()) {
|
for (String comm : s.getValue()) {
|
||||||
comm = comm.toLowerCase();
|
comm = comm.toLowerCase();
|
||||||
if (command.equalsIgnoreCase("/" + comm)) {
|
if (command.equalsIgnoreCase("/" + comm)) {
|
||||||
|
|||||||
+1
-9
@@ -13,25 +13,17 @@ public class WaterfallDefineCommandsListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onProxyDefineCommandsEvent(io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent event) {
|
public void onProxyDefineCommandsEvent(io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent event) {
|
||||||
|
|
||||||
if (event.getReceiver() instanceof ProxiedPlayer) {
|
if (event.getReceiver() instanceof ProxiedPlayer) {
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||||
|
if (player.hasPermission("commandwhitelist.bypass"))
|
||||||
if (player.hasPermission("commandwhitelist.bypass")) {
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<String, Command> commandHashMap = new HashMap<>();
|
HashMap<String, Command> commandHashMap = new HashMap<>();
|
||||||
CommandsList.getCommands(player).forEach(cmdName ->
|
CommandsList.getCommands(player).forEach(cmdName ->
|
||||||
CommandWhitelistBungee.getPlugin().getProxy().getPluginManager().getCommands()
|
CommandWhitelistBungee.getPlugin().getProxy().getPluginManager().getCommands()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(commandEntry -> cmdName.equalsIgnoreCase(commandEntry.getValue().getName()))
|
.filter(commandEntry -> cmdName.equalsIgnoreCase(commandEntry.getValue().getName()))
|
||||||
.forEach(commandEntry -> commandHashMap.put(commandEntry.getKey(), commandEntry.getValue())));
|
.forEach(commandEntry -> commandHashMap.put(commandEntry.getKey(), commandEntry.getValue())));
|
||||||
|
|
||||||
event.getCommands().values().removeIf((cmd) -> !commandHashMap.containsValue(cmd));
|
event.getCommands().values().removeIf((cmd) -> !commandHashMap.containsValue(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ public class MainCommand implements TabExecutor {
|
|||||||
} else {
|
} else {
|
||||||
sender.sendMessage("/cw remove <group> <command>");
|
sender.sendMessage("/cw remove <group> <command>");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getNoSubCommand()));
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getNoSubCommand()));
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-6
@@ -27,9 +27,8 @@ public class LegacyPlayerTabChatCompleteListener {
|
|||||||
public void onPacketSending(PacketEvent event) {
|
public void onPacketSending(PacketEvent event) {
|
||||||
try {
|
try {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.hasPermission("commandwhitelist.bypass")) {
|
if (player.hasPermission("commandwhitelist.bypass"))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
PacketContainer packet = event.getPacket();
|
PacketContainer packet = event.getPacket();
|
||||||
String[] message = packet.getSpecificModifier(String[].class).read(0);
|
String[] message = packet.getSpecificModifier(String[].class).read(0);
|
||||||
List<String> commandList = CommandsList.getCommands(player);
|
List<String> commandList = CommandsList.getCommands(player);
|
||||||
@@ -43,18 +42,14 @@ public class LegacyPlayerTabChatCompleteListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] toWrite = new String[components];
|
String[] toWrite = new String[components];
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (String cmd : finalList) {
|
for (String cmd : finalList) {
|
||||||
toWrite[counter++] = cmd;
|
toWrite[counter++] = cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
packet.getSpecificModifier(String[].class).write(0, toWrite);
|
packet.getSpecificModifier(String[].class).write(0, toWrite);
|
||||||
|
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-5
@@ -9,12 +9,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 PlayerCommandPreProcessListener 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) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
@@ -39,13 +37,10 @@ public class PlayerCommandPreProcessListener implements Listener {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
ConfigCache config = CommandWhitelist.getConfigCache();
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getCommandDenied())));
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getCommandDenied())));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-10
@@ -8,21 +8,12 @@ import org.bukkit.event.Listener;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class PlayerCommandSendListener 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;
|
||||||
}
|
|
||||||
|
|
||||||
List<String> commandList = CommandsList.getCommands(player);
|
List<String> commandList = CommandsList.getCommands(player);
|
||||||
|
|
||||||
event.getCommands().removeIf((cmd) -> !commandList.contains(cmd));
|
event.getCommands().removeIf((cmd) -> !commandList.contains(cmd));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -8,7 +8,6 @@ import org.bukkit.event.Listener;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TabCompleteBlockerListener implements Listener {
|
public class TabCompleteBlockerListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onCommandTabComplete(org.bukkit.event.server.TabCompleteEvent event) {
|
public void onCommandTabComplete(org.bukkit.event.server.TabCompleteEvent event) {
|
||||||
if (!(event.getSender() instanceof Player))
|
if (!(event.getSender() instanceof Player))
|
||||||
|
|||||||
Reference in New Issue
Block a user