Merge branch 'development'

This commit is contained in:
Brianna 2020-04-22 10:35:20 -04:00
commit e9dc2ee4fb
12 changed files with 42 additions and 68 deletions

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId>
<artifactId>EpicHoppers</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>4.6.1</version>
<version>4.6.2</version>
<build>
<defaultGoal>clean install</defaultGoal>
<finalName>EpicHoppers-${project.version}</finalName>

View File

@ -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() {

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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));

View File

@ -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);
}

View File

@ -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<Integer, Level> registeredLevels = new TreeMap<>();
public void addLevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, int linkAmount, ArrayList<Module> 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();
}

View File

@ -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;
}

View File

@ -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)) {

View File

@ -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 "";

View File

@ -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();
}