diff --git a/pom.xml b/pom.xml
index 5447d2d..772da48 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
com.songoda
EpicHoppers
4.0.0
- 4.6.1
+ 4.6.2
clean install
EpicHoppers-${project.version}
diff --git a/src/main/java/com/songoda/epichoppers/EpicHoppers.java b/src/main/java/com/songoda/epichoppers/EpicHoppers.java
index 6275e79..30cad91 100644
--- a/src/main/java/com/songoda/epichoppers/EpicHoppers.java
+++ b/src/main/java/com/songoda/epichoppers/EpicHoppers.java
@@ -11,6 +11,8 @@ import com.songoda.core.database.SQLiteConnector;
import com.songoda.core.gui.GuiManager;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.core.locale.Locale;
+import com.songoda.core.nms.NmsManager;
+import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.epichoppers.boost.BoostData;
import com.songoda.epichoppers.boost.BoostManager;
import com.songoda.epichoppers.commands.*;
@@ -305,13 +307,16 @@ public class EpicHoppers extends SongodaPlugin {
public ItemStack newHopperItem(Level level) {
ItemStack item = new ItemStack(Material.HOPPER, 1);
ItemMeta itemmeta = item.getItemMeta();
- itemmeta.setDisplayName(Methods.formatText(Methods.formatName(level.getLevel(), true)));
+ itemmeta.setDisplayName(Methods.formatText(Methods.formatName(level.getLevel())));
String line = getLocale().getMessage("general.nametag.lore").getMessage();
if (!line.equals("")) {
itemmeta.setLore(Arrays.asList(line.split("\n")));
}
item.setItemMeta(itemmeta);
- return item;
+
+ NBTItem nbtItem = NmsManager.getNbt().of(item);
+ nbtItem.set("level", level.getLevel());
+ return nbtItem.finish();
}
public Locale getLocale() {
diff --git a/src/main/java/com/songoda/epichoppers/gui/GUIAutoSellFilter.java b/src/main/java/com/songoda/epichoppers/gui/GUIAutoSellFilter.java
index 9aaab05..b764575 100644
--- a/src/main/java/com/songoda/epichoppers/gui/GUIAutoSellFilter.java
+++ b/src/main/java/com/songoda/epichoppers/gui/GUIAutoSellFilter.java
@@ -30,7 +30,7 @@ public class GUIAutoSellFilter extends Gui {
this.hopper = hopper;
setRows(6);
- setTitle(Methods.formatText(Methods.formatName(hopper.getLevel().getLevel(), false) + " &8-&f AutoSell Filter"));
+ setTitle(Methods.formatText(Methods.formatName(hopper.getLevel().getLevel()) + " &8-&f AutoSell Filter"));
setDefaultItem(null);
setAcceptsItems(true);
diff --git a/src/main/java/com/songoda/epichoppers/gui/GUICrafting.java b/src/main/java/com/songoda/epichoppers/gui/GUICrafting.java
index 695747c..e57dad5 100644
--- a/src/main/java/com/songoda/epichoppers/gui/GUICrafting.java
+++ b/src/main/java/com/songoda/epichoppers/gui/GUICrafting.java
@@ -15,7 +15,7 @@ public class GUICrafting extends Gui {
public GUICrafting(ModuleAutoCrafting module, Hopper hopper, Player player) {
setRows(3);
- setTitle(Methods.formatName(hopper.getLevel().getLevel(), false) + Methods.formatText(" &8-&f Crafting"));
+ setTitle(Methods.formatName(hopper.getLevel().getLevel()) + Methods.formatText(" &8-&f Crafting"));
setOnClose((event) -> module.setAutoCrafting(hopper, player, inventory.getItem(13)));
setAcceptsItems(true);
diff --git a/src/main/java/com/songoda/epichoppers/gui/GUIFilter.java b/src/main/java/com/songoda/epichoppers/gui/GUIFilter.java
index 8e90d25..7cce91e 100644
--- a/src/main/java/com/songoda/epichoppers/gui/GUIFilter.java
+++ b/src/main/java/com/songoda/epichoppers/gui/GUIFilter.java
@@ -31,7 +31,7 @@ public class GUIFilter extends Gui {
this.hopper = hopper;
setRows(6);
- setTitle(Methods.formatText(Methods.formatName(hopper.getLevel().getLevel(), false) + " &8-&f Filter"));
+ setTitle(Methods.formatText(Methods.formatName(hopper.getLevel().getLevel()) + " &8-&f Filter"));
setDefaultItem(null);
setAcceptsItems(true);
diff --git a/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java b/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java
index e0e9dc6..4ea822b 100644
--- a/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java
+++ b/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java
@@ -41,7 +41,7 @@ public class GUIOverview extends Gui {
this.player = player;
setRows(3);
- setTitle(Methods.formatName(hopper.getLevel().getLevel(), false));
+ setTitle(Methods.formatName(hopper.getLevel().getLevel()));
runTask();
constructGUI();
this.setOnClose(action -> Bukkit.getScheduler().cancelTask(task));
diff --git a/src/main/java/com/songoda/epichoppers/hopper/Hopper.java b/src/main/java/com/songoda/epichoppers/hopper/Hopper.java
index 11a9f89..34f89a4 100644
--- a/src/main/java/com/songoda/epichoppers/hopper/Hopper.java
+++ b/src/main/java/com/songoda/epichoppers/hopper/Hopper.java
@@ -126,7 +126,7 @@ public class Hopper {
private void syncName() {
org.bukkit.block.Hopper hopper = (org.bukkit.block.Hopper) location.getBlock().getState();
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10))
- hopper.setCustomName(Methods.formatName(level.getLevel(), false));
+ hopper.setCustomName(Methods.formatName(level.getLevel()));
hopper.update(true);
}
diff --git a/src/main/java/com/songoda/epichoppers/hopper/levels/LevelManager.java b/src/main/java/com/songoda/epichoppers/hopper/levels/LevelManager.java
index 409ba7a..b5adc5a 100644
--- a/src/main/java/com/songoda/epichoppers/hopper/levels/LevelManager.java
+++ b/src/main/java/com/songoda/epichoppers/hopper/levels/LevelManager.java
@@ -1,5 +1,8 @@
package com.songoda.epichoppers.hopper.levels;
+import com.songoda.core.nms.NmsManager;
+import com.songoda.core.nms.nbt.NBTCore;
+import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.epichoppers.hopper.levels.modules.Module;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
@@ -10,7 +13,7 @@ public class LevelManager {
private final NavigableMap registeredLevels = new TreeMap<>();
-
+
public void addLevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, int linkAmount, ArrayList modules) {
registeredLevels.put(level, new Level(level, costExperience, costEconomy, range, amount, filter, teleport, linkAmount, modules));
}
@@ -21,23 +24,33 @@ public class LevelManager {
}
public Level getLevel(ItemStack item) {
+ NBTCore nbt = NmsManager.getNbt();
+ NBTItem nbtItem = nbt.of(item);
+
+ if (nbtItem.has("level"))
+ return getLevel(nbtItem.getNBTObject("level").asInt());
+
+ // Legacy trash.
if (item.hasItemMeta() && item.getItemMeta().getDisplayName().contains(":")) {
String arr[] = item.getItemMeta().getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "").split(":");
return getLevel(Integer.parseInt(arr[0]));
- } else {
- return getLowestLevel();
}
+
+ return getLowestLevel();
}
public boolean isEpicHopper(ItemStack item) {
- if (item.hasItemMeta() && item.getItemMeta().getDisplayName().contains(":")) {
+ NBTCore nbt = NmsManager.getNbt();
+
+ if (nbt.of(item).has("level"))
return true;
- } else {
- return false;
- }
+
+ return item.hasItemMeta()
+ // Legacy Trash.
+ && item.getItemMeta().getDisplayName().contains(":");
}
-
+
public Level getLowestLevel() {
return registeredLevels.firstEntry().getValue();
}
diff --git a/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java b/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java
index de4bdac..dc1762f 100644
--- a/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java
+++ b/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java
@@ -1,6 +1,7 @@
package com.songoda.epichoppers.listeners;
import com.songoda.core.compatibility.ServerVersion;
+import com.songoda.core.utils.BlockUtils;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.hopper.Hopper;
import com.songoda.epichoppers.hopper.levels.modules.Module;
@@ -138,10 +139,10 @@ public class HopperListeners implements Listener {
//event.setItem(moveInstead);
// we need to instead cancel and manually remove the item to move
source.removeItem(moveInstead);
- Methods.updateAdjacentComparators(sourceLocation);
+ BlockUtils.updateAdjacentComparators(sourceLocation);
// now add it to the hopper
destination.addItem(moveInstead);
- Methods.updateAdjacentComparators(destinationLocation);
+ BlockUtils.updateAdjacentComparators(destinationLocation);
}
return;
}
diff --git a/src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java b/src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java
index a49e5d4..67dc852 100644
--- a/src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java
+++ b/src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java
@@ -61,8 +61,7 @@ public class InteractListeners implements Listener {
return;
}
- Boolean flag;
- if ((flag = WorldGuardHook.getBooleanFlag(event.getClickedBlock().getLocation(), "use")) != null && !flag)
+ if (WorldGuardHook.isInteractAllowed(event.getClickedBlock().getLocation()))
return;
if (event.getClickedBlock().getType() == Material.CHEST && Methods.isSync(player)) {
diff --git a/src/main/java/com/songoda/epichoppers/utils/Methods.java b/src/main/java/com/songoda/epichoppers/utils/Methods.java
index 72242aa..ccc5558 100644
--- a/src/main/java/com/songoda/epichoppers/utils/Methods.java
+++ b/src/main/java/com/songoda/epichoppers/utils/Methods.java
@@ -115,17 +115,13 @@ public class Methods {
return false;
}
- public static String formatName(int level, boolean full) {
+ public static String formatName(int level) {
EpicHoppers instance = EpicHoppers.getInstance();
String name = instance.getLocale().getMessage("general.nametag.nameformat")
.processPlaceholder("level", level).getMessage();
- String info = "";
- if (full) {
- info += Methods.convertToInvisibleString(level + ":");
- }
- return info + Methods.formatText(name);
+ return Methods.formatText(name);
}
public static void doParticles(Entity entity, Location location) {
@@ -188,47 +184,6 @@ public class Methods {
serializeCache.put(cacheKey, location.clone());
return location;
}
-
- private static Class> clazzCraftWorld, clazzCraftBlock, clazzBlockPosition;
- private static Method getHandle, updateAdjacentComparators, getNMSBlock;
-
- public static void updateAdjacentComparators(Location location) {
- if(location == null || location.getWorld() == null) {
- return;
- }
- try {
- // Cache reflection.
- if (clazzCraftWorld == null) {
- String serverPackagePath = Bukkit.getServer().getClass().getPackage().getName();
- String ver = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1);
- clazzCraftWorld = Class.forName("org.bukkit.craftbukkit." + ver + ".CraftWorld");
- clazzCraftBlock = Class.forName("org.bukkit.craftbukkit." + ver + ".block.CraftBlock");
- clazzBlockPosition = Class.forName("net.minecraft.server." + ver + ".BlockPosition");
- Class> clazzWorld = Class.forName("net.minecraft.server." + ver + ".World");
- Class> clazzBlock = Class.forName("net.minecraft.server." + ver + ".Block");
-
- getHandle = clazzCraftWorld.getMethod("getHandle");
- updateAdjacentComparators = clazzWorld.getMethod("updateAdjacentComparators", clazzBlockPosition, clazzBlock);
- getNMSBlock = clazzCraftBlock.getDeclaredMethod("getNMSBlock");
- getNMSBlock.setAccessible(true);
- }
-
- // invoke and cast objects.
- Object craftWorld = clazzCraftWorld.cast(location.getWorld());
- Object world = getHandle.invoke(craftWorld);
- Object craftBlock = clazzCraftBlock.cast(location.getBlock());
-
- // Invoke final method.
- updateAdjacentComparators
- .invoke(world, clazzBlockPosition.getConstructor(double.class, double.class, double.class)
- .newInstance(location.getX(), location.getY(), location.getZ()),
- getNMSBlock.invoke(craftBlock));
-
- } catch (ReflectiveOperationException e) {
- e.printStackTrace();
- }
- }
-
public static String convertToInvisibleString(String s) {
if (s == null || s.equals(""))
return "";
diff --git a/src/main/java/com/songoda/epichoppers/utils/StorageContainerCache.java b/src/main/java/com/songoda/epichoppers/utils/StorageContainerCache.java
index 3f9f673..2a6b619 100644
--- a/src/main/java/com/songoda/epichoppers/utils/StorageContainerCache.java
+++ b/src/main/java/com/songoda/epichoppers/utils/StorageContainerCache.java
@@ -2,6 +2,7 @@ package com.songoda.epichoppers.utils;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
+import com.songoda.core.utils.BlockUtils;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -108,7 +109,7 @@ public class StorageContainerCache {
inventory.setItem(i, cachedInventory[i]);
}
}
- Methods.updateAdjacentComparators(e.getKey().getLocation());
+ BlockUtils.updateAdjacentComparators(e.getKey().getLocation());
});
inventoryCache.clear();
}