Skip to content

Commit

Permalink
RELEASE VERSION 3.6.1
Browse files Browse the repository at this point in the history
Prevents exploit with glowing items and grindstones

Closes #112
  • Loading branch information
JustBru00 committed Jul 22, 2019
1 parent 473a30a commit c772680
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="C:/Users/justb/Desktop/EpicRealm_Minigames_Server/Test_Server_1.13/spigot-1.13.2.jar">
<classpathentry kind="lib" path="C:/Users/justb/OneDrive/Coding/Test_Server_1.12/plugins/Vault.jar"/>
<classpathentry kind="lib" path="C:/Users/justb/Desktop/Test_Server_1.14/spigot-1.14.4.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/C:/Users/justb/Desktop/Coding/Downloaded%20Java%20Docs%20for%20Spigot/spigot-api-1.13-R0.1-20180722.042426-1-javadoc.jar!/"/>
<attribute name="javadoc_location" value="jar:file:/C:/Users/justb/Desktop/Coding/Downloaded%20Java%20Docs%20for%20Spigot/spigot-api-1.14-R0.1-20190425.033315-1-javadoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/Users/justb/OneDrive/Coding/Test_Server_1.12/plugins/Vault.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
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);
}
}
}
}
}
}
}
}

}
10 changes: 7 additions & 3 deletions src/com/gmail/justbru00/epic/rename/main/v3/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -27,6 +28,7 @@
import com.gmail.justbru00.epic.rename.commands.v3.Rename;
import com.gmail.justbru00.epic.rename.commands.v3.SetLoreLine;
import com.gmail.justbru00.epic.rename.enums.v3.MCVersion;
import com.gmail.justbru00.epic.rename.exploit_prevention.ExploitPreventionListener;
import com.gmail.justbru00.epic.rename.listeners.v3.OnJoin;
import com.gmail.justbru00.epic.rename.main.v3.Metrics.Graph;
import com.gmail.justbru00.epic.rename.main.v3.bstats.BStats;
Expand Down Expand Up @@ -59,8 +61,8 @@ public class Main extends JavaPlugin {
public static Economy econ = null;
public static boolean USE_ECO = false;

public static final int CONFIG_VERSION = 6;
public static final int MESSAGES_VERSION = 9;
public static final int CONFIG_VERSION = 7;
public static final int MESSAGES_VERSION = 10;
public static ConsoleCommandSender clogger = Bukkit.getServer().getConsoleSender();
public static Logger log = Bukkit.getLogger();

Expand Down Expand Up @@ -103,7 +105,9 @@ public void onEnable() {
}

// Register Listeners
Bukkit.getServer().getPluginManager().registerEvents(new OnJoin(), this);
PluginManager pm = Bukkit.getServer().getPluginManager();
pm.registerEvents(new OnJoin(), this);
pm.registerEvents(new ExploitPreventionListener(), this);

// Command Executors
getCommand("rename").setExecutor(new Rename());
Expand Down
9 changes: 6 additions & 3 deletions src/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#EpicRename by Justin Brubaker. https://www.spigotmc.org/resources/epicrename.4341/
#Version 3.6+
#Version 3.6.1+

#DO NOT CHANGE THIS PLEASE
config_version: 6
config_version: 7

#Plugin Prefix
prefix: '&8[&bEpic&fRename&8] &f'
Expand Down Expand Up @@ -73,4 +73,7 @@ enabled_worlds:
- 'world_the_end'

#Disables bypass messages from being sent to all players.
disable_bypass_messages: false
disable_bypass_messages: false

# Exploit Prevention
disable_grindstone_for_glowing_items: true
5 changes: 4 additions & 1 deletion src/messages.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#EpicRename messages.yml generated by version 3.6+
messages_yml_version: 9
messages_yml_version: 10

epicrename:
no_permission: '&cSorry you don''t have permission to perform that command.'
Expand Down Expand Up @@ -158,4 +158,7 @@ economy:
bypass: '&aYou just bypassed the economy requirement.'
transaction_success: '&aJust took {cost} from your balance.'
transaction_error: '&cThere was a problem taking money from your balance: {error}'

exploit_prevention:
no_grindstone_with_glowing_items: '&cYou cannot use a grindstone while having a glowing item in your inventory. Please remove the glowing item from your inventory in order to use the grindstone.'

2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: EpicRename
main: com.gmail.justbru00.epic.rename.main.v3.Main
version: 3.6
version: 3.6.1
description: Performs different item modifications with easy to use commands.
authors: [Justin Brubaker, JustBru00]
softdepend: [Vault]
Expand Down

0 comments on commit c772680

Please sign in to comment.