mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-25 19:56:20 +01:00
Merge branch 'development'
This commit is contained in:
commit
e9dc2ee4fb
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
|||||||
<groupId>com.songoda</groupId>
|
<groupId>com.songoda</groupId>
|
||||||
<artifactId>EpicHoppers</artifactId>
|
<artifactId>EpicHoppers</artifactId>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<version>4.6.1</version>
|
<version>4.6.2</version>
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>clean install</defaultGoal>
|
<defaultGoal>clean install</defaultGoal>
|
||||||
<finalName>EpicHoppers-${project.version}</finalName>
|
<finalName>EpicHoppers-${project.version}</finalName>
|
||||||
|
@ -11,6 +11,8 @@ import com.songoda.core.database.SQLiteConnector;
|
|||||||
import com.songoda.core.gui.GuiManager;
|
import com.songoda.core.gui.GuiManager;
|
||||||
import com.songoda.core.hooks.EconomyManager;
|
import com.songoda.core.hooks.EconomyManager;
|
||||||
import com.songoda.core.locale.Locale;
|
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.BoostData;
|
||||||
import com.songoda.epichoppers.boost.BoostManager;
|
import com.songoda.epichoppers.boost.BoostManager;
|
||||||
import com.songoda.epichoppers.commands.*;
|
import com.songoda.epichoppers.commands.*;
|
||||||
@ -305,13 +307,16 @@ public class EpicHoppers extends SongodaPlugin {
|
|||||||
public ItemStack newHopperItem(Level level) {
|
public ItemStack newHopperItem(Level level) {
|
||||||
ItemStack item = new ItemStack(Material.HOPPER, 1);
|
ItemStack item = new ItemStack(Material.HOPPER, 1);
|
||||||
ItemMeta itemmeta = item.getItemMeta();
|
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();
|
String line = getLocale().getMessage("general.nametag.lore").getMessage();
|
||||||
if (!line.equals("")) {
|
if (!line.equals("")) {
|
||||||
itemmeta.setLore(Arrays.asList(line.split("\n")));
|
itemmeta.setLore(Arrays.asList(line.split("\n")));
|
||||||
}
|
}
|
||||||
item.setItemMeta(itemmeta);
|
item.setItemMeta(itemmeta);
|
||||||
return item;
|
|
||||||
|
NBTItem nbtItem = NmsManager.getNbt().of(item);
|
||||||
|
nbtItem.set("level", level.getLevel());
|
||||||
|
return nbtItem.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
|
@ -30,7 +30,7 @@ public class GUIAutoSellFilter extends Gui {
|
|||||||
this.hopper = hopper;
|
this.hopper = hopper;
|
||||||
|
|
||||||
setRows(6);
|
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);
|
setDefaultItem(null);
|
||||||
setAcceptsItems(true);
|
setAcceptsItems(true);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ public class GUICrafting extends Gui {
|
|||||||
|
|
||||||
public GUICrafting(ModuleAutoCrafting module, Hopper hopper, Player player) {
|
public GUICrafting(ModuleAutoCrafting module, Hopper hopper, Player player) {
|
||||||
setRows(3);
|
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)));
|
setOnClose((event) -> module.setAutoCrafting(hopper, player, inventory.getItem(13)));
|
||||||
setAcceptsItems(true);
|
setAcceptsItems(true);
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public class GUIFilter extends Gui {
|
|||||||
this.hopper = hopper;
|
this.hopper = hopper;
|
||||||
|
|
||||||
setRows(6);
|
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);
|
setDefaultItem(null);
|
||||||
setAcceptsItems(true);
|
setAcceptsItems(true);
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public class GUIOverview extends Gui {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
setRows(3);
|
setRows(3);
|
||||||
setTitle(Methods.formatName(hopper.getLevel().getLevel(), false));
|
setTitle(Methods.formatName(hopper.getLevel().getLevel()));
|
||||||
runTask();
|
runTask();
|
||||||
constructGUI();
|
constructGUI();
|
||||||
this.setOnClose(action -> Bukkit.getScheduler().cancelTask(task));
|
this.setOnClose(action -> Bukkit.getScheduler().cancelTask(task));
|
||||||
|
@ -126,7 +126,7 @@ public class Hopper {
|
|||||||
private void syncName() {
|
private void syncName() {
|
||||||
org.bukkit.block.Hopper hopper = (org.bukkit.block.Hopper) location.getBlock().getState();
|
org.bukkit.block.Hopper hopper = (org.bukkit.block.Hopper) location.getBlock().getState();
|
||||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10))
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10))
|
||||||
hopper.setCustomName(Methods.formatName(level.getLevel(), false));
|
hopper.setCustomName(Methods.formatName(level.getLevel()));
|
||||||
hopper.update(true);
|
hopper.update(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.songoda.epichoppers.hopper.levels;
|
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 com.songoda.epichoppers.hopper.levels.modules.Module;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -10,7 +13,7 @@ public class LevelManager {
|
|||||||
|
|
||||||
private final NavigableMap<Integer, Level> registeredLevels = new TreeMap<>();
|
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) {
|
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));
|
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) {
|
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(":")) {
|
if (item.hasItemMeta() && item.getItemMeta().getDisplayName().contains(":")) {
|
||||||
String arr[] = item.getItemMeta().getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "").split(":");
|
String arr[] = item.getItemMeta().getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "").split(":");
|
||||||
return getLevel(Integer.parseInt(arr[0]));
|
return getLevel(Integer.parseInt(arr[0]));
|
||||||
} else {
|
|
||||||
return getLowestLevel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return getLowestLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEpicHopper(ItemStack item) {
|
public boolean isEpicHopper(ItemStack item) {
|
||||||
if (item.hasItemMeta() && item.getItemMeta().getDisplayName().contains(":")) {
|
NBTCore nbt = NmsManager.getNbt();
|
||||||
|
|
||||||
|
if (nbt.of(item).has("level"))
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
return item.hasItemMeta()
|
||||||
}
|
// Legacy Trash.
|
||||||
|
&& item.getItemMeta().getDisplayName().contains(":");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Level getLowestLevel() {
|
public Level getLowestLevel() {
|
||||||
return registeredLevels.firstEntry().getValue();
|
return registeredLevels.firstEntry().getValue();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.songoda.epichoppers.listeners;
|
package com.songoda.epichoppers.listeners;
|
||||||
|
|
||||||
import com.songoda.core.compatibility.ServerVersion;
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
|
import com.songoda.core.utils.BlockUtils;
|
||||||
import com.songoda.epichoppers.EpicHoppers;
|
import com.songoda.epichoppers.EpicHoppers;
|
||||||
import com.songoda.epichoppers.hopper.Hopper;
|
import com.songoda.epichoppers.hopper.Hopper;
|
||||||
import com.songoda.epichoppers.hopper.levels.modules.Module;
|
import com.songoda.epichoppers.hopper.levels.modules.Module;
|
||||||
@ -138,10 +139,10 @@ public class HopperListeners implements Listener {
|
|||||||
//event.setItem(moveInstead);
|
//event.setItem(moveInstead);
|
||||||
// we need to instead cancel and manually remove the item to move
|
// we need to instead cancel and manually remove the item to move
|
||||||
source.removeItem(moveInstead);
|
source.removeItem(moveInstead);
|
||||||
Methods.updateAdjacentComparators(sourceLocation);
|
BlockUtils.updateAdjacentComparators(sourceLocation);
|
||||||
// now add it to the hopper
|
// now add it to the hopper
|
||||||
destination.addItem(moveInstead);
|
destination.addItem(moveInstead);
|
||||||
Methods.updateAdjacentComparators(destinationLocation);
|
BlockUtils.updateAdjacentComparators(destinationLocation);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -61,8 +61,7 @@ public class InteractListeners implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean flag;
|
if (WorldGuardHook.isInteractAllowed(event.getClickedBlock().getLocation()))
|
||||||
if ((flag = WorldGuardHook.getBooleanFlag(event.getClickedBlock().getLocation(), "use")) != null && !flag)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event.getClickedBlock().getType() == Material.CHEST && Methods.isSync(player)) {
|
if (event.getClickedBlock().getType() == Material.CHEST && Methods.isSync(player)) {
|
||||||
|
@ -115,17 +115,13 @@ public class Methods {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatName(int level, boolean full) {
|
public static String formatName(int level) {
|
||||||
EpicHoppers instance = EpicHoppers.getInstance();
|
EpicHoppers instance = EpicHoppers.getInstance();
|
||||||
String name = instance.getLocale().getMessage("general.nametag.nameformat")
|
String name = instance.getLocale().getMessage("general.nametag.nameformat")
|
||||||
.processPlaceholder("level", level).getMessage();
|
.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) {
|
public static void doParticles(Entity entity, Location location) {
|
||||||
@ -188,47 +184,6 @@ public class Methods {
|
|||||||
serializeCache.put(cacheKey, location.clone());
|
serializeCache.put(cacheKey, location.clone());
|
||||||
return location;
|
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) {
|
public static String convertToInvisibleString(String s) {
|
||||||
if (s == null || s.equals(""))
|
if (s == null || s.equals(""))
|
||||||
return "";
|
return "";
|
||||||
|
@ -2,6 +2,7 @@ package com.songoda.epichoppers.utils;
|
|||||||
|
|
||||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
import com.songoda.core.compatibility.ServerVersion;
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
|
import com.songoda.core.utils.BlockUtils;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -108,7 +109,7 @@ public class StorageContainerCache {
|
|||||||
inventory.setItem(i, cachedInventory[i]);
|
inventory.setItem(i, cachedInventory[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Methods.updateAdjacentComparators(e.getKey().getLocation());
|
BlockUtils.updateAdjacentComparators(e.getKey().getLocation());
|
||||||
});
|
});
|
||||||
inventoryCache.clear();
|
inventoryCache.clear();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user