mirror of
https://github.com/CarmJos/cn2b2t-project.git
synced 2026-06-04 18:17:19 +08:00
添加指令黑名单
This commit is contained in:
@@ -8,66 +8,69 @@ import com.comphenix.protocol.events.PacketAdapter;
|
|||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||||
import org.cn2b2t.core.Main;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.cn2b2t.core.Main;
|
||||||
|
|
||||||
public final class TabCompleteListener implements Listener {
|
public final class TabCompleteListener implements Listener {
|
||||||
|
|
||||||
private final ProtocolManager pm;
|
private final ProtocolManager pm;
|
||||||
|
|
||||||
public TabCompleteListener() {
|
public TabCompleteListener() {
|
||||||
this.pm = ProtocolLibrary.getProtocolManager();
|
this.pm = ProtocolLibrary.getProtocolManager();
|
||||||
setupPackets();
|
setupPackets();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupPackets() {
|
private void setupPackets() {
|
||||||
this.pm.addPacketListener(new PacketAdapter(Main.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.TAB_COMPLETE) {
|
this.pm.addPacketListener(new PacketAdapter(Main.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.TAB_COMPLETE) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
if (!event.getPlayer().isOp()) {
|
if (!event.getPlayer().isOp()) {
|
||||||
if (event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) {
|
if (event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
PacketContainer packet = event.getPacket();
|
PacketContainer packet = event.getPacket();
|
||||||
|
|
||||||
String message = packet.getSpecificModifier(String.class).read(0).toLowerCase();
|
String message = packet.getSpecificModifier(String.class).read(0).toLowerCase();
|
||||||
if (message.equalsIgnoreCase("/")
|
if (message.equalsIgnoreCase("/")
|
||||||
|| shouldCancel(message, "//")
|
|| shouldCancel(message, "//")
|
||||||
|| shouldCancel(message, "/cmi")
|
|| shouldCancel(message, "/cmi")
|
||||||
|| shouldCancel(message, "/mcpay")
|
|| shouldCancel(message, "/mcpay")
|
||||||
|| shouldCancel(message, "/help")
|
|| shouldCancel(message, "/version")
|
||||||
|| shouldCancel(message, "/bukkit:")
|
|| shouldCancel(message, "/help")
|
||||||
|| shouldCancel(message, "/minecraft:")) {
|
|| shouldCancel(message, "/bukkit:")
|
||||||
event.setCancelled(true);
|
|| shouldCancel(message, "/minecraft:")) {
|
||||||
}
|
event.setCancelled(true);
|
||||||
} catch (FieldAccessException ignored) {
|
}
|
||||||
}
|
} catch (FieldAccessException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onAtTab(PlayerCommandPreprocessEvent e) {
|
public void onAtTab(PlayerCommandPreprocessEvent e) {
|
||||||
if (!e.getPlayer().isOp()) {
|
if (!e.getPlayer().isOp()) {
|
||||||
String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
if (message.equalsIgnoreCase("/")
|
if (message.equalsIgnoreCase("/")
|
||||||
|| shouldCancel(message, "//")
|
|| shouldCancel(message, "//")
|
||||||
|| message.startsWith("/minecraft:")
|
|| message.startsWith("/minecraft:")
|
||||||
|| message.startsWith("/bukkit:")
|
|| message.startsWith("/version")
|
||||||
|| message.startsWith("/help")) {
|
|| message.startsWith("/ver")
|
||||||
e.setCancelled(true);
|
|| message.startsWith("/bukkit:")
|
||||||
}
|
|| message.startsWith("/help")) {
|
||||||
}
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean shouldCancel(String message, String command) {
|
public static boolean shouldCancel(String message, String command) {
|
||||||
return message.startsWith(command) || command.startsWith(message);
|
return message.startsWith(command) || command.startsWith(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @EventHandler
|
// @EventHandler
|
||||||
// public void onAtTab(PlayerChatTabCompleteEvent e) {
|
// public void onAtTab(PlayerChatTabCompleteEvent e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user