mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-11 22:16:57 +00:00
improved code quality
This commit is contained in:
+34
-26
@@ -5,6 +5,7 @@ import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -13,34 +14,41 @@ public class BungeeChatEventListener implements Listener {
|
||||
@EventHandler
|
||||
public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) {
|
||||
|
||||
if (!event.isCancelled() && event.getSender() instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
if (event.isProxyCommand()) {
|
||||
if (player.hasPermission("commandwhitelist.bypass")) {
|
||||
return;
|
||||
}
|
||||
String command = event.getMessage().toLowerCase();
|
||||
boolean found = false;
|
||||
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
||||
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
|
||||
for (String comm : s.getValue()) {
|
||||
comm = comm.toLowerCase();
|
||||
if (command.equalsIgnoreCase("/"+comm)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
else if (command.startsWith("/" + comm + " ")) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getCommandDenied()));
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
if (!(event.getSender() instanceof ProxiedPlayer))
|
||||
return;
|
||||
|
||||
if (!event.isProxyCommand())
|
||||
return;
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
|
||||
if (player.hasPermission("commandwhitelist.bypass")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String command = event.getMessage().toLowerCase();
|
||||
boolean found = false;
|
||||
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
||||
continue;
|
||||
|
||||
for (String comm : s.getValue()) {
|
||||
comm = comm.toLowerCase();
|
||||
if (command.equalsIgnoreCase("/" + comm)) {
|
||||
found = true;
|
||||
break;
|
||||
} else if (command.startsWith("/" + comm + " ")) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getCommandDenied()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-11
@@ -59,7 +59,6 @@ public class LegacyPlayerTabChatCompleteListener {
|
||||
packet.getSpecificModifier(String[].class).write(0, toWrite);
|
||||
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -78,14 +77,14 @@ public class LegacyPlayerTabChatCompleteListener {
|
||||
System.out.println(command);
|
||||
|
||||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
||||
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
|
||||
for (String comm : s.getValue()) {
|
||||
comm = comm.toLowerCase();
|
||||
if (command.equalsIgnoreCase("/"+comm))
|
||||
return;
|
||||
else if (command.startsWith("/" + comm + " ")) {
|
||||
return;
|
||||
}
|
||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
||||
continue;
|
||||
for (String comm : s.getValue()) {
|
||||
comm = comm.toLowerCase();
|
||||
if (command.equalsIgnoreCase("/" + comm))
|
||||
return;
|
||||
else if (command.startsWith("/" + comm + " ")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,9 +92,7 @@ public class LegacyPlayerTabChatCompleteListener {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-10
@@ -6,6 +6,7 @@ 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;
|
||||
|
||||
@@ -15,21 +16,21 @@ public class PlayerCommandPreProcessListener implements Listener {
|
||||
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player.hasPermission("commandwhitelist.bypass")) {
|
||||
if (player.hasPermission("commandwhitelist.bypass"))
|
||||
return;
|
||||
}
|
||||
|
||||
String command = event.getMessage().toLowerCase();
|
||||
|
||||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
|
||||
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) {
|
||||
for (String comm : s.getValue()) {
|
||||
comm = comm.toLowerCase();
|
||||
if (command.equalsIgnoreCase("/"+comm))
|
||||
return;
|
||||
else if (command.startsWith("/" + comm + " ")) {
|
||||
return;
|
||||
}
|
||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
||||
continue;
|
||||
|
||||
for (String comm : s.getValue()) {
|
||||
comm = comm.toLowerCase();
|
||||
if (command.equalsIgnoreCase("/" + comm))
|
||||
return;
|
||||
else if (command.startsWith("/" + comm + " ")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user