-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevents exploit with glowing items and grindstones Closes #112
- Loading branch information
Showing
6 changed files
with
103 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/com/gmail/justbru00/epic/rename/exploit_prevention/ExploitPreventionListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.gmail.justbru00.epic.rename.exploit_prevention; | ||
|
||
import java.util.Map.Entry; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.enchantments.Enchantment; | ||
import org.bukkit.entity.HumanEntity; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.inventory.InventoryOpenEvent; | ||
import org.bukkit.event.inventory.InventoryType; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import com.gmail.justbru00.epic.rename.main.v3.Main; | ||
import com.gmail.justbru00.epic.rename.utils.v3.Debug; | ||
import com.gmail.justbru00.epic.rename.utils.v3.Messager; | ||
|
||
public class ExploitPreventionListener implements Listener { | ||
|
||
@EventHandler(priority=EventPriority.HIGHEST) | ||
public void onInventoryOpenEvent(InventoryOpenEvent e) { | ||
// 1.14 or higher versions with grindstone | ||
if (Bukkit.getVersion().contains("1.14")) { | ||
if (Main.getBooleanFromConfig("disable_grindstone_for_glowing_items")) { | ||
if (e.getInventory().getType() == InventoryType.GRINDSTONE) { | ||
Debug.send("[ExploitPreventionListener] Grindstone prevention is enabled and a grindstone inventory was opened."); | ||
|
||
final HumanEntity eventPlayer = e.getPlayer(); | ||
|
||
// Check all inventory items | ||
// Grindstone | ||
for (ItemStack is : e.getInventory().getStorageContents()) { | ||
if (is == null) { | ||
continue; | ||
} | ||
for (Entry<Enchantment,Integer> enchantment : is.getEnchantments().entrySet()) { | ||
if (enchantment.getKey().equals(Enchantment.LURE) || enchantment.getKey().equals(Enchantment.ARROW_INFINITE)) { | ||
if (enchantment.getValue() == 4341) { | ||
// Is a glowing item | ||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() { | ||
@Override | ||
public void run() { | ||
Debug.send("[ExploitPreventionListener] Item has glowing! Closing Inventory."); | ||
eventPlayer.closeInventory(); | ||
Messager.msgSenderWithConfigMsg("exploit_prevention.no_grindstone_with_glowing_items", eventPlayer); | ||
Messager.msgConsole("[ExploitPreventionListener] Player: " + eventPlayer.getName() + "'s inventory was closed because they tried to use a grindstone with a glowing item in their inventory. "); | ||
} | ||
}, 1); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Player Inventory | ||
for (ItemStack is : e.getPlayer().getInventory().getStorageContents()) { | ||
if (is == null) { | ||
continue; | ||
} | ||
for (Entry<Enchantment,Integer> enchantment : is.getEnchantments().entrySet()) { | ||
if (enchantment.getKey().equals(Enchantment.LURE) || enchantment.getKey().equals(Enchantment.ARROW_INFINITE)) { | ||
if (enchantment.getValue() == 4341) { | ||
// Is a glowing item | ||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() { | ||
@Override | ||
public void run() { | ||
Debug.send("[ExploitPreventionListener] Item has glowing! Closing Inventory."); | ||
eventPlayer.closeInventory(); | ||
Messager.msgSenderWithConfigMsg("exploit_prevention.no_grindstone_with_glowing_items", eventPlayer); | ||
Messager.msgConsole("[ExploitPreventionListener] Player: " + eventPlayer.getName() + "'s inventory was closed because they tried to use a grindstone with a glowing item in their inventory. "); | ||
} | ||
}, 1); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters