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