Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/main/java/us/myles/sep/ItemPatcher.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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())) {
Expand Down
106 changes: 50 additions & 56 deletions src/main/java/us/myles/sep/SkullExploitPatch.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -105,7 +99,6 @@ public boolean isExploit(NbtCompound root) {
}
// Block
if (root.containsKey("Owner"))

{
NbtCompound skullOwner = root.getCompound("Owner");
if (skullOwner.containsKey("Properties")) {
Expand All @@ -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;
}
Expand All @@ -153,6 +138,7 @@ public boolean isExploit(NbtCompound root) {
}
}
}

return false;
}

Expand All @@ -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.
}
}

Expand Down