diff --git a/.idea/VulnerabilityPatcher.iml b/.idea/VulnerabilityPatcher.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/VulnerabilityPatcher.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..674a398
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace-SK54BF641F610A.xml b/.idea/workspace-SK54BF641F610A.xml
new file mode 100644
index 0000000..63c133c
--- /dev/null
+++ b/.idea/workspace-SK54BF641F610A.xml
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1548667472501
+
+
+ 1548667472501
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f40fcae..f2410db 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,31 +1,26 @@
-
+
+
+
-
-
+
-
+
-
-
-
-
-
-
@@ -40,52 +35,34 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
-
-
-
-
-
+
-
-
-
-
+
+
+
+
-
@@ -99,48 +76,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -148,9 +83,6 @@
-
-
-
@@ -168,241 +100,174 @@
-
- 1547829118400
+
+ 1549009858370
- 1547829118400
+ 1549009858370
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
+
+
+
+
+
+
-
+
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
-
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1.8
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index ced2689..b6b0961 100644
--- a/README.md
+++ b/README.md
@@ -4,8 +4,7 @@ VulnerabilityPatcher is a light weight Spigot plugin that runs on 1.13.2 servers
Its task is to prevent bugs in Spigot to cause issues for both the server and the players.
**Patches:**
-It currently prevents 4 server crash bugs, 2 client crash bugs, 2 disconnect bugs,
-2 bugs that kills creative users and 1 that causes commands to run when clicking in books.
+It currently prevents 15+ vulnerabilities from being executed.
**Planned:**
- More security patches.
diff --git a/bin/main/config.yml b/bin/main/config.yml
index 1c451c3..a96820d 100644
--- a/bin/main/config.yml
+++ b/bin/main/config.yml
@@ -1,6 +1,6 @@
# VulnerabilityPatcher by CoolJWB.
-# Patches: DeathPotions, DeathItems, CrashItems, Books, RougeEntity, Knockback, Riptide, FollowRange, DisconnectItems, CrashEgg, EntityTag.
+# Patches: DeathPotions, DeathItems, CrashItems, Books, RougeEntity, Arrows, Riptide, FollowRange, DisconnectItems, EntityTag.
# All patches added in the list below will be activated on server startup.
Patches:
- DeathPotions
@@ -8,11 +8,10 @@ Patches:
- CrashItems
- Books
- RougeEntity
- - Knockback
+ - Arrows
- Riptide
- FollowRange
- DisconnectItems
- - CrashEgg
- EntityTag
# All entities added below will be blocked to use in a spawn egg.
diff --git a/bin/main/plugin.yml b/bin/main/plugin.yml
index ea041a0..f454d76 100644
--- a/bin/main/plugin.yml
+++ b/bin/main/plugin.yml
@@ -1,5 +1,5 @@
name: VulnerabilityPatcher
-version: 0.1.2
+version: 0.2
main: me.cooljwb.vulnerabilitypatcher.VulnerabilityPatcher
api-version: 1.13
authors: [CoolJWB]
diff --git a/gradle.properties b/gradle.properties
index 45520f1..a9fb0f4 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,2 +1,2 @@
pluginGroup=me.CoolJWB.VulnerabilityPatcher
-pluginVersion=v0.2
+pluginVersion=v0.2.1
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/SMG.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/SMG.java
index 5989f17..95814e0 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/SMG.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/SMG.java
@@ -32,6 +32,7 @@ public enum SMG {
"&8 - &7/getnbt &aPrint the item in hands NBT."),
ITEM(SMG.VULNERABILITYPATCHER.msg + "&cThis item is not allowed."),
+ ITEMS(SMG.VULNERABILITYPATCHER.msg + "&cAn item in your inventory has been cleared for being potentially dangerous."),
ITEM_IN_CONTAINER(SMG.VULNERABILITYPATCHER.msg + "&cAn item in this container is not allowed."),
ITEM_NOTIFY(SMG.VULNERABILITYPATCHER.msg + "&c%s tried to %s a %s at x:%s y:%s z:%s"),
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/VulnerabilityPatcher.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/VulnerabilityPatcher.java
index eff1651..835647f 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/VulnerabilityPatcher.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/VulnerabilityPatcher.java
@@ -38,6 +38,10 @@ import java.util.logging.Logger;
public final class VulnerabilityPatcher extends JavaPlugin {
/*
+ * TODO: Fix that disconnect item shulkers return null in dispensers.
+ * TODO: Issues with potions?
+ * TODO: Fix command signs.
+ * TODO: Fix ReflectionToStringBuilder parse error in shulker.
* Patches: Books with commands, Invalid translations (crashes both client and server), Death Items, Death Potions, Rouge Entities, Arrow knockback, Trident speed,
* Large follow range, Disconnect Items, Crash Eggs, Knowledge Books, Negative Damage Arrows, much more.
*/
@@ -121,7 +125,28 @@ public final class VulnerabilityPatcher extends JavaPlugin {
String confstr = FileUtils.readFileToString(conf);
if(confstr.contains("ConfVersion")) {
- // Foundation of automatic update system.
+ // Check if this prints the real config version.
+ //switch(main.getConfig().getInt("ConfVersion")) { // Switch the versions, and try to update all versions forward.
+ // This won't be needed yet, since all versions before this will trigger the config.yml reset.
+ // This is now generating ConfVersion 0. Next version will need to update from ConfVersion 0 to 1.
+
+ /*
+ case 0:
+ if(confstr.contains("CrashSigns"))
+ confstr = confstr.replaceAll("CrashSigns", "CrashItems");
+
+ if(!confstr.contains("EntityTag"))
+
+ // Does this really work if you have changed the config.yml so it has no spacing/new lines or?
+ if(!confstr.contains("BlockedEntityTags")) {
+ confstr = new StringBuilder(confstr).insert((confstr.indexOf("Commands") - 2), "\n# All entity tags that are added here are blocked to use in a monster spawn egg.\n" +
+ "BlockedEntityTags:\n" +
+ " - lightning_bolt\n" +
+ " - falling_block\n").toString();
+ }
+ */
+ //}
+ //FileUtils.write(conf, confstr);
}
else {
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Arrows.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Arrows.java
index 20b224a..03aa7c5 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Arrows.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Arrows.java
@@ -41,7 +41,7 @@ public class Arrows extends Patches implements Listener {
if(event.getVelocity().getX() > 10 || event.getVelocity().getY() > 10 || event.getVelocity().getZ() > 10)
event.setCancelled(true);
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler
@@ -56,7 +56,7 @@ public class Arrows extends Patches implements Listener {
arrow.setDamage(0);
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -71,6 +71,6 @@ public class Arrows extends Patches implements Listener {
arrow.setDamage(0);
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
}
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Books.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Books.java
index 2d74475..4549754 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Books.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Books.java
@@ -60,7 +60,7 @@ public class Books extends Patches implements Listener {
}
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
public void writtenBook(Player player, EquipmentSlot hand) {
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Crash_Items.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Crash_Items.java
index 1b87472..121e0b4 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Crash_Items.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Crash_Items.java
@@ -80,7 +80,7 @@ public class Crash_Items extends Patches implements Listener {
notifyViolation(event.getBlock().getType().toString(), "drop", event.getItem().getType() + " with crash item in it", event.getBlock().getLocation());
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -96,7 +96,7 @@ public class Crash_Items extends Patches implements Listener {
notifyViolation(player, "interact with", "crash item", player.getLocation());
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -115,7 +115,7 @@ public class Crash_Items extends Patches implements Listener {
}
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -141,7 +141,7 @@ public class Crash_Items extends Patches implements Listener {
}, 0L);
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -157,7 +157,7 @@ public class Crash_Items extends Patches implements Listener {
notifyViolation(player, "drop", "crash item", player.getLocation());
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
public static boolean isCrashItem(ItemStack item) {
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Death_Items.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Death_Items.java
index ffdeaba..01c105d 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Death_Items.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Death_Items.java
@@ -62,7 +62,7 @@ public class Death_Items extends Patches implements Listener {
notifyViolation("Dispenser", "place", event.getItem().getType() + " with death item in it", event.getBlock().getLocation());
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -82,7 +82,7 @@ public class Death_Items extends Patches implements Listener {
}
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -108,7 +108,7 @@ public class Death_Items extends Patches implements Listener {
}, 0L);
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -124,22 +124,26 @@ public class Death_Items extends Patches implements Listener {
notifyViolation(player, "drop", "death item", player.getLocation());
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
public static boolean isDeathItem(ItemStack item) {
+ net.minecraft.server.v1_13_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item);
+
+ if(nmsItemStack != null && nmsItemStack.hasTag())
+ return isDeathItem(nmsItemStack.getTag());
+ return false;
+ }
+
+ public static boolean isDeathItem(NBTTagCompound item) {
if(item != null) {
- net.minecraft.server.v1_13_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item);
+ NBTTagList attrlist = item.getList("AttributeModifiers", 10);
- if(nmsItemStack.getTag() != null) {
- NBTTagList attrlist = nmsItemStack.getTag().getList("AttributeModifiers", 10);
-
- if(attrlist != null) {
- for(int i = 0; i < attrlist.size(); i++) {
- NBTTagCompound compound = (NBTTagCompound)attrlist.get(i);
- if((compound.getString("Name").equalsIgnoreCase("MAX_HEALTH") || compound.getString("AttributeName").equalsIgnoreCase("generic.maxHealth")) && compound.getDouble("Amount") <= 0)
- return true;
- }
+ if(attrlist != null) {
+ for(int i = 0; i < attrlist.size(); i++) {
+ NBTTagCompound compound = (NBTTagCompound)attrlist.get(i);
+ if((compound.getString("Name").equalsIgnoreCase("MAX_HEALTH") || compound.getString("AttributeName").equalsIgnoreCase("generic.maxHealth")) && compound.getDouble("Amount") <= 0)
+ return true;
}
}
}
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Death_Potions.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Death_Potions.java
index 58581d6..d35291b 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Death_Potions.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Death_Potions.java
@@ -57,7 +57,7 @@ public class Death_Potions extends Patches implements Listener {
}
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -74,7 +74,7 @@ public class Death_Potions extends Patches implements Listener {
notifyViolation(player, "splash", "death potion", player.getLocation());
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -91,7 +91,7 @@ public class Death_Potions extends Patches implements Listener {
notifyViolation(player, "splash", "death potion", player.getLocation());
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
public static boolean isDeathPotion(List effects) {
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Disconnect_Items.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Disconnect_Items.java
index d9d4ed6..6193f32 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Disconnect_Items.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Disconnect_Items.java
@@ -62,6 +62,8 @@ public class Disconnect_Items extends Patches implements Listener {
String invstr = "";
for (ItemStack item : container.getInventory().getContents()) {
+ if(isDisconnectItem(item))
+ clearItemMeta(item);
invstr = invstr + itemToString(item);
}
@@ -72,26 +74,33 @@ public class Disconnect_Items extends Patches implements Listener {
}
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockDispenseEvent(BlockDispenseEvent event) {
- if(containsDisconnectItem(event.getItem())) {
+ ItemStack item = event.getItem();
+
+ if(isDisconnectItem(item)) {
+ event.setCancelled(true);
+ clearItemMeta(item);
+ }
+
+ if(containsDisconnectItem(item)) {
event.setCancelled(true);
Container container = (Container) event.getBlock().getState();
for(int c = 0; c < container.getInventory().getSize(); c++) {
if(container.getInventory().getItem(c) != null) {
if (container.getInventory().getItem(c).isSimilar(event.getItem()))
- container.getInventory().getItem(c).setItemMeta(null);
+ clearItemMeta(container.getInventory().getItem(c));
}
}
notifyViolation("Dispenser", "place", event.getItem().getType() + " with disconnect item in it", event.getBlock().getLocation());
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -111,7 +120,7 @@ public class Disconnect_Items extends Patches implements Listener {
}
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -137,7 +146,7 @@ public class Disconnect_Items extends Patches implements Listener {
}, 0L);
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -153,17 +162,25 @@ public class Disconnect_Items extends Patches implements Listener {
notifyViolation(player, "drop", "disconnect item", player.getLocation());
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
public boolean isDisconnectItem(ItemStack item) {
- if(item != null) {
- net.minecraft.server.v1_13_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item);
+ net.minecraft.server.v1_13_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item);
- if(nmsItemStack != null && nmsItemStack.getTag() != null) {
- if((nmsItemStack.getTag().getInt("CustomPotionColor") < 0) || (nmsItemStack.getTag().getCompound("display").getInt("color") < 0) || (nmsItemStack.getTag().toString().length() > 50000) || isMovementDisconnectItem(nmsItemStack) || isInvalidAttributeName(nmsItemStack))
- return true;
- }
+ if(nmsItemStack != null && nmsItemStack.hasTag())
+ return isDisconnectItem(nmsItemStack.getTag());
+ return false;
+ }
+
+ public boolean isDisconnectItem(NBTTagCompound item) {
+ if(item != null) {
+ if(item.hasKey("CustomPotionColor") && item.getInt("CustomPotionColor") <= 0)
+ return true;
+ else if(item.getCompound("display").hasKey("color") && item.getCompound("display").getInt("color") <= 0)
+ return true;
+ else if(item.toString().length() > 50000 || isMovementDisconnectItem(item) || isInvalidAttributeName(item))
+ return true;
}
return false;
}
@@ -177,8 +194,8 @@ public class Disconnect_Items extends Patches implements Listener {
if(items != null) {
for (int a = 0; a <= items.size(); a++) {
- if((nmsItemStack.getTag().getInt("CustomPotionColor") < 0) || (nmsItemStack.getTag().getCompound("display").getInt("color") < 0) || (nmsItemStack.getTag().toString().length() > 50000) || isMovementDisconnectItem(nmsItemStack) || isInvalidAttributeName(nmsItemStack))
- return true;
+ NBTTagCompound nmsitem = items.getCompound(a);
+ return isDisconnectItem(nmsitem.getCompound("tag"));
}
}
}
@@ -186,9 +203,9 @@ public class Disconnect_Items extends Patches implements Listener {
return false;
}
- public boolean isMovementDisconnectItem(net.minecraft.server.v1_13_R2.ItemStack nmsItemStack) {
- if(nmsItemStack != null) {
- NBTTagList attrlist = nmsItemStack.getTag().getList("AttributeModifiers", 10);
+ public boolean isMovementDisconnectItem(NBTTagCompound tag) {
+ if(tag != null) {
+ NBTTagList attrlist = tag.getList("AttributeModifiers", 10);
if(attrlist != null) {
HashMap attributes = new HashMap<>();
@@ -204,13 +221,15 @@ public class Disconnect_Items extends Patches implements Listener {
}
return false;
}
+
+ public boolean isInvalidAttributeName(NBTTagCompound tag) {
+ if(tag != null) {
+ NBTTagList attrlist = tag.getList("AttributeModifiers", 10);
- public boolean isInvalidAttributeName(net.minecraft.server.v1_13_R2.ItemStack nmsItemStack) {
- if(nmsItemStack != null) {
- NBTTagList attrlist = nmsItemStack.getTag().getList("AttributeModifiers", 10);
if(attrlist != null) {
for(int a = 0; a <= attrlist.size(); a++) {
NBTTagCompound attribute = attrlist.getCompound(a);
+
if(attribute != null && attribute.getString("AttributeName").toLowerCase() != "") {
if(!Variables.Attributes.liststr.contains(attribute.getString("AttributeName").toLowerCase()))
return true;
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Entity_Tag.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Entity_Tag.java
index ce4ae06..203856a 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Entity_Tag.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Entity_Tag.java
@@ -26,7 +26,7 @@ public class Entity_Tag extends Patches implements Listener {
if(isDangerousEgg(item))
clearItemMeta(event.getItem());
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -49,7 +49,7 @@ public class Entity_Tag extends Patches implements Listener {
}
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
public boolean isDangerousEgg(ItemStack item) {
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Follow_Range.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Follow_Range.java
index d5c7a5d..680092c 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Follow_Range.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Follow_Range.java
@@ -46,6 +46,6 @@ public class Follow_Range extends Patches implements Listener {
}
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
}
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Patches.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Patches.java
index dba3744..f35b92c 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Patches.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Patches.java
@@ -4,20 +4,29 @@ import me.cooljwb.vulnerabilitypatcher.VulnerabilityPatcher;
import me.cooljwb.vulnerabilitypatcher.SMG;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.*;
+import net.minecraft.server.v1_13_R2.AttributeModifier;
+import net.minecraft.server.v1_13_R2.ChatMessageException;
import net.minecraft.server.v1_13_R2.NBTTagCompound;
+import net.minecraft.server.v1_13_R2.NBTTagList;
+
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Location;
+import org.bukkit.attribute.Attribute;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
+import org.bukkit.event.Event;
import org.bukkit.event.Listener;
+import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.PlayerInventory;
import org.bukkit.scheduler.BukkitScheduler;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -55,6 +64,7 @@ public class Patches implements Listener {
private Rouge_Entity rouge_entity;
private Logger log = Logger.getLogger("Minecraft");
+ private HashMap active_attributes = new HashMap<>();
public Patches() {}
public Patches(VulnerabilityPatcher main) {
@@ -81,31 +91,55 @@ public class Patches implements Listener {
public void run() {
for(Player player : Bukkit.getOnlinePlayers()) {
for(ItemStack item : player.getInventory()) {
+
+ if(listeners.contains("DisconnectItems") && itemInVisibleSlot(player.getInventory(), item)) {
+ NBTTagList item_attributes = getNBTAttributeList(item);
+
+ if(item_attributes != null) {
+ for(int a = 0; a <= item_attributes.size(); a++) {
+ NBTTagCompound attribute = item_attributes.getCompound(a);
+
+ if(attribute != null && !attribute.isEmpty()) {
+ String attr_name = attribute.getString("AttributeName").toLowerCase();
+ float attr_amount = attribute.getFloat("Amount");
+
+ if((active_attributes.containsKey("generic.movementspeed") && attr_name.equalsIgnoreCase("generic.movementspeed")) && (Float.isFinite(active_attributes.get("generic.movementspeed")) || Float.isInfinite(active_attributes.get("generic.movementspeed")) || active_attributes.get("generic.movementspeed") == Float.NEGATIVE_INFINITY) && (Float.isFinite(attr_amount) || Float.isInfinite(attr_amount) || attr_amount == Float.NEGATIVE_INFINITY)) {
+ msg(player, SMG.ITEMS.msg);
+ clearItemMeta(item);
+ }
+
+ active_attributes.put(attr_name, attr_amount);
+ }
+ }
+ }
+ }
+
for(String listener : listeners) {
switch(listener) {
case "DeathItems":
if(death_items.isDeathItem(item) || death_items.containsDeathItem(item)) {
clearItemMeta(item);
notifyViolation(player, "acquire", "death item", player.getLocation());
- msg(player, SMG.ITEM.msg);
- }
+ msg(player, SMG.ITEMS.msg);
+ } break;
case "DisconnectItems":
if(disconnect_items.isDisconnectItem(item) || disconnect_items.containsDisconnectItem(item)) {
clearItemMeta(item);
notifyViolation(player, "acquire", "disconnect item", player.getLocation());
- msg(player, SMG.ITEM.msg);
+ msg(player, SMG.ITEMS.msg);
} break;
case "CrashItems":
if(crash_items.isCrashItem(item) || crash_items.containsCrashItem(item)) {
clearItemMeta(item);
notifyViolation(player.getName(), "acquire", "crash item", player.getLocation());
- msg(player, SMG.ITEM.msg);
+ msg(player, SMG.ITEMS.msg);
} break;
}
}
}
+ active_attributes.clear();
}
}
}, 0L, 0);
@@ -170,9 +204,13 @@ public class Patches implements Listener {
notify(notification);
}
- public void debug(String event) {
- if(devmode)
- log.log(Level.INFO, String.format("[%s] Event in %s: %s", pluginName, getClass().getName(), event));
+ public void debug(Event event) {
+ try {
+ if (devmode)
+ log.log(Level.INFO, String.format("[%s] Event in %s: %s", pluginName, getClass().getName(), ReflectionToStringBuilder.toString(event)));
+ } catch(ChatMessageException e) {
+ log.log(Level.INFO, String.format("[%s] Could not debug event in %s.", pluginName, getClass().getName()));
+ }
}
public void clearItemMeta(ItemStack item) {
@@ -186,6 +224,30 @@ public class Patches implements Listener {
}
}
+ public NBTTagCompound getNBTItemTag(ItemStack item) {
+ if(item != null) {
+ net.minecraft.server.v1_13_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item);
+ if(nmsItemStack != null)
+ return nmsItemStack.getTag();
+ }
+ return null;
+ }
+
+ public NBTTagCompound getEntityNMS(Entity entity) {
+ net.minecraft.server.v1_13_R2.Entity nmsEntity = ((CraftEntity)entity).getHandle();
+ NBTTagCompound tag = new NBTTagCompound();
+ nmsEntity.save(tag);
+ return tag;
+ }
+
+ public NBTTagList getNBTAttributeList(ItemStack item) {
+ NBTTagCompound itemtag = getNBTItemTag(item);
+
+ if(item != null && itemtag != null && itemtag.hasKey("AttributeModifiers"))
+ return getNBTItemTag(item).getList("AttributeModifiers", 10);
+ return null;
+ }
+
public String itemToString(ItemStack item) {
if(item != null) {
net.minecraft.server.v1_13_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item);
@@ -195,11 +257,22 @@ public class Patches implements Listener {
}
return "";
}
+
+ public boolean itemInVisibleSlot(PlayerInventory inv, ItemStack item) {
+ ItemStack mainhand = inv.getItemInMainHand();
+ ItemStack offhand = inv.getItemInOffHand();
- public NBTTagCompound getEntityNMS(Entity entity) {
- net.minecraft.server.v1_13_R2.Entity nmsEntity = ((CraftEntity)entity).getHandle();
- NBTTagCompound tag = new NBTTagCompound();
- nmsEntity.save(tag);
- return tag;
+ if(item != null && inv != null && mainhand != null && offhand != null) {
+ if(inv.getItemInMainHand().isSimilar(item) || inv.getItemInOffHand().isSimilar(item))
+ return true;
+
+ else {
+ for(ItemStack items : inv.getArmorContents()) {
+ if(items != null && items.isSimilar(item))
+ return true;
+ }
+ }
+ }
+ return false;
}
}
diff --git a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Trident_Riptide.java b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Trident_Riptide.java
index 4c1dedc..d753dc5 100644
--- a/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Trident_Riptide.java
+++ b/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Trident_Riptide.java
@@ -57,7 +57,7 @@ public class Trident_Riptide extends Patches implements Listener {
}
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
@EventHandler
@@ -70,6 +70,6 @@ public class Trident_Riptide extends Patches implements Listener {
item.addUnsafeEnchantment(Enchantment.RIPTIDE, enchantlevel.get(player));
}
- debug(ReflectionToStringBuilder.toString(event));
+ debug(event);
}
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index f454d76..6f5bf50 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,5 +1,5 @@
name: VulnerabilityPatcher
-version: 0.2
+version: 0.2.1
main: me.cooljwb.vulnerabilitypatcher.VulnerabilityPatcher
api-version: 1.13
authors: [CoolJWB]