diff --git a/src/main/java/us/myles/sep/ItemPatcher.java b/src/main/java/us/myles/sep/ItemPatcher.java index 082fd4d..f166f86 100644 --- a/src/main/java/us/myles/sep/ItemPatcher.java +++ b/src/main/java/us/myles/sep/ItemPatcher.java @@ -1,10 +1,10 @@ package us.myles.sep; -import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -35,7 +35,18 @@ public void onJoin(PlayerJoinEvent e) { } } } - + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerDeath(PlayerDeathEvent e) { + if (e.getEntity() == null) { + return; + } + for (ItemStack it : e.getDrops()) { + if (plugin.isExploit(it)) { + e.getDrops().remove(it); + plugin.getLogger().warning("Removing exploit from inventory, " + e.getEntity().getName()); + } + } + } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onItemDrop(PlayerDropItemEvent e) { if (plugin.isExploit(e.getItemDrop().getItemStack())) { diff --git a/src/main/java/us/myles/sep/SkullExploitPatch.java b/src/main/java/us/myles/sep/SkullExploitPatch.java index 65157c5..9a4ee16 100644 --- a/src/main/java/us/myles/sep/SkullExploitPatch.java +++ b/src/main/java/us/myles/sep/SkullExploitPatch.java @@ -1,29 +1,31 @@ package us.myles.sep; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.wrappers.nbt.NbtBase; -import com.comphenix.protocol.wrappers.nbt.NbtCompound; -import com.comphenix.protocol.wrappers.nbt.NbtFactory; -import com.comphenix.protocol.wrappers.nbt.NbtList; -import com.google.common.io.BaseEncoding; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockState; +import org.bukkit.block.Skull; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.wrappers.nbt.NbtBase; +import com.comphenix.protocol.wrappers.nbt.NbtCompound; +import com.comphenix.protocol.wrappers.nbt.NbtFactory; +import com.comphenix.protocol.wrappers.nbt.NbtList; +import com.google.common.io.BaseEncoding; public class SkullExploitPatch extends JavaPlugin { + Boolean mc10; public void onEnable() { + mc10 = this.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3].startsWith("v1_10_R"); // Packet Listener ProtocolLibrary.getProtocolManager().addPacketListener(new SkullExploitListener(this)); // Chunk Load Listener @@ -66,27 +68,19 @@ public boolean isExploit(NbtCompound root) { // Check for value if (((NbtCompound) texture).containsKey("Value")) { if (((NbtCompound) texture).getString("Value").trim().length() > 0) { - // Check json - try { - String decoded = new String(BaseEncoding.base64().decode(((NbtCompound) texture).getString("Value"))); - JSONObject object = (JSONObject) new JSONParser().parse(decoded); - if (object.containsKey("textures")) { - object = (JSONObject) object.get("textures"); - } - if (object.containsKey("SKIN")) { - object = (JSONObject) object.get("SKIN"); - } - if (!object.containsKey("url")) { - root.remove("SkullOwner"); - return true; - } - if (((String) object.get("url")).trim().length() == 0) { + String decoded = new String(BaseEncoding.base64().decode(((NbtCompound) texture).getString("Value"))); + if (decoded.contains("textures") && decoded.contains("SKIN")) { + if (decoded.contains("url")) { + String Url = decoded.split("url")[1].replace("\"", "").replace(":", "").replace("{", "").replace("}", ""); + if (Url.trim().length() == 0) { + root.remove("SkullOwner"); + return true; + } + } else { root.remove("SkullOwner"); return true; } - return false; - } catch (Exception e) { - // Decode failed + } else { root.remove("SkullOwner"); return true; } @@ -105,7 +99,6 @@ public boolean isExploit(NbtCompound root) { } // Block if (root.containsKey("Owner")) - { NbtCompound skullOwner = root.getCompound("Owner"); if (skullOwner.containsKey("Properties")) { @@ -116,27 +109,19 @@ public boolean isExploit(NbtCompound root) { if (texture instanceof NbtCompound) { if (((NbtCompound) texture).containsKey("Value")) { if (((NbtCompound) texture).getString("Value").trim().length() > 0) { - // Check json - try { - String decoded = new String(BaseEncoding.base64().decode(((NbtCompound) texture).getString("Value"))); - JSONObject object = (JSONObject) new JSONParser().parse(decoded); - if (object.containsKey("textures")) { - object = (JSONObject) object.get("textures"); - } - if (object.containsKey("SKIN")) { - object = (JSONObject) object.get("SKIN"); - } - if (!object.containsKey("url")) { - root.remove("Owner"); - return true; - } - if (((String) object.get("url")).trim().length() == 0) { + String decoded = new String(BaseEncoding.base64().decode(((NbtCompound) texture).getString("Value"))); + if (decoded.contains("textures") && decoded.contains("SKIN")) { + if (decoded.contains("url")) { + String Url = decoded.split("url")[1].replace("\"", "").replace(":", "").replace("{", "").replace("}", ""); + if (Url.trim().length() == 0) { + root.remove("Owner"); + return true; + } + } else { root.remove("Owner"); return true; } - return false; - } catch (Exception e) { - // Decode failed + } else { root.remove("Owner"); return true; } @@ -153,6 +138,7 @@ public boolean isExploit(NbtCompound root) { } } } + return false; } @@ -169,15 +155,23 @@ public void cleanChunk(Chunk chunk) { } for (Block head : heads) { - try { - //Dont skip loop if error - NbtCompound root = NbtFactory.readBlockState(head); - if (isExploit(root)) { - getLogger().warning("Removing exploit block, " + head.getLocation()); - head.setType(Material.AIR); + if (mc10) { + Skull meta = (Skull) head.getState(); + if (meta.hasOwner()) { + meta.setOwningPlayer(meta.getOwningPlayer()); + meta.update(); + } + } else { + try { + //Dont skip loop if error + NbtCompound root = NbtFactory.readBlockState(head); + if (isExploit(root)) { + getLogger().warning("Removing exploit block, " + head.getLocation()); + head.setType(Material.AIR); + } + } catch (Exception e) { + // Failed to read chunk data, probably odd version and need to update protocol lib. } - } catch (Exception e) { - // Failed to read chunk data, probably odd version and need to update protocol lib. } }