-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added optional usage of protocollib for command filter
- Loading branch information
1 parent
eb0f53f
commit e823aa9
Showing
5 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/eu/endermite/commandwhitelist/spigot/listeners/PacketCommandSendListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package eu.endermite.commandwhitelist.spigot.listeners; | ||
|
||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.ProtocolLibrary; | ||
import com.comphenix.protocol.ProtocolManager; | ||
import com.comphenix.protocol.events.ListenerPriority; | ||
import com.comphenix.protocol.events.PacketAdapter; | ||
import com.comphenix.protocol.events.PacketContainer; | ||
import com.comphenix.protocol.events.PacketEvent; | ||
import eu.endermite.commandwhitelist.api.CommandsList; | ||
import eu.endermite.commandwhitelist.api.RandomStuff; | ||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist; | ||
import eu.endermite.commandwhitelist.spigot.config.ConfigCache; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class PacketCommandSendListener { | ||
|
||
public static void protocol(CommandWhitelist plugin) { | ||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); | ||
commandExecListener(protocolManager, plugin); | ||
} | ||
|
||
public static void commandExecListener(ProtocolManager protocolManager, Plugin plugin) { | ||
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CHAT) { | ||
@Override | ||
public void onPacketReceiving(PacketEvent event) { | ||
PacketContainer packet = event.getPacket(); | ||
String string = packet.getStrings().read(0); | ||
if (!string.startsWith("/")) | ||
return; | ||
Player player = event.getPlayer(); | ||
if (player.hasPermission("commandwhitelist.bypass")) | ||
return; | ||
String cmd = string.replace("/", ""); | ||
String[] split = cmd.split("\\s+"); | ||
String command = split[0].toLowerCase(); | ||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) { | ||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey())) | ||
continue; | ||
for (String comm : s.getValue()) { | ||
comm = comm.toLowerCase(); | ||
if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) { | ||
List<String> bannedSubCommands = CommandsList.getSuggestions(player); | ||
for (String bannedSubCommand : bannedSubCommands) { | ||
if (cmd.startsWith(bannedSubCommand)) { | ||
event.setCancelled(true); | ||
ConfigCache config = CommandWhitelist.getConfigCache(); | ||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied()))); | ||
return; | ||
} | ||
} | ||
return; | ||
} | ||
} | ||
} | ||
|
||
event.setCancelled(true); | ||
ConfigCache config = CommandWhitelist.getConfigCache(); | ||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getCommandDenied()))); | ||
|
||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters