From 476e0c99ead48e4b217be792e90d87b3ddbcb3fd Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 19 Aug 2024 16:55:39 +0100 Subject: [PATCH] Patched grindstone xp exploit --- .../mechanics/GrindstoneSupport.kt | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/GrindstoneSupport.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/GrindstoneSupport.kt index 7f96a1f6..e52adc86 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/GrindstoneSupport.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/GrindstoneSupport.kt @@ -2,8 +2,10 @@ package com.willfp.ecoenchants.mechanics import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.fast.fast +import com.willfp.eco.core.gui.player import com.willfp.ecoenchants.enchant.wrap import org.bukkit.enchantments.Enchantment +import org.bukkit.entity.ExperienceOrb import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.inventory.InventoryClickEvent @@ -17,7 +19,7 @@ class GrindstoneSupport( private val plugin: EcoPlugin ) : Listener { @EventHandler - fun onGrindstone(event: InventoryClickEvent) { + fun preGrindstone(event: InventoryClickEvent) { val inventory = event.view.topInventory as? GrindstoneInventory ?: return // Run everything later to await event completion @@ -77,4 +79,31 @@ class GrindstoneSupport( result.itemMeta = meta } } + + @EventHandler + fun postGrindstone(event: InventoryClickEvent) { + val inventory = event.clickedInventory as? GrindstoneInventory ?: return + + if (event.slot != 2) { + return + } + + val item = inventory.result ?: return + + if (item.fast().getEnchants(true).isEmpty()) { + return + } + + // Force remove XP + plugin.scheduler.runLater(1) { + val loc = inventory.location + + val orbs = loc?.getNearbyEntities(3.0, 3.0, 3.0) + ?: emptyList() + + for (orb in orbs.filterIsInstance()) { + orb.remove() + } + } + } }