mirror of
https://github.com/songoda/EpicHoppers.git
synced 2025-02-16 11:51:54 +01:00
Merge branch 'development'
This commit is contained in:
commit
04586653ed
4
pom.xml
4
pom.xml
@ -2,7 +2,7 @@
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicHoppers</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>4.6.20</version>
|
||||
<version>4.6.21</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>EpicHoppers-${project.version}</finalName>
|
||||
@ -122,7 +122,7 @@
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateStacker</artifactId>
|
||||
<version>1.9.6</version>
|
||||
<version>2.1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -22,7 +22,7 @@ import com.songoda.epichoppers.commands.CommandReload;
|
||||
import com.songoda.epichoppers.commands.CommandSettings;
|
||||
import com.songoda.epichoppers.database.DataManager;
|
||||
import com.songoda.epichoppers.database.migrations._1_InitialMigration;
|
||||
import com.songoda.epichoppers.handlers.TeleportHandler;
|
||||
import com.songoda.epichoppers.hopper.teleport.TeleportHandler;
|
||||
import com.songoda.epichoppers.hopper.HopperManager;
|
||||
import com.songoda.epichoppers.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.hopper.levels.LevelManager;
|
||||
@ -58,7 +58,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class EpicHoppers extends SongodaPlugin {
|
||||
|
||||
private static EpicHoppers INSTANCE;
|
||||
@ -173,6 +172,8 @@ public class EpicHoppers extends SongodaPlugin {
|
||||
this.dataManager.getHoppers((hoppers) -> {
|
||||
this.hopperManager.addHoppers(hoppers.values());
|
||||
this.dataManager.getBoosts((boosts) -> this.boostManager.addBoosts(boosts));
|
||||
|
||||
this.hopperManager.setReady();
|
||||
});
|
||||
}
|
||||
|
||||
@ -229,7 +230,6 @@ public class EpicHoppers extends SongodaPlugin {
|
||||
} else if (key.equals("AutoSmelting")) {
|
||||
modules.add(new ModuleAutoSmelter(this, levels.getInt("AutoSmelting")));
|
||||
}
|
||||
|
||||
}
|
||||
levelManager.addLevel(level, costExperience, costEconomy, radius, amount, filter, teleport, linkAmount, modules);
|
||||
}
|
||||
@ -258,6 +258,7 @@ public class EpicHoppers extends SongodaPlugin {
|
||||
return nbtItem.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
@ -35,8 +35,7 @@ public class CommandBoost extends AbstractCommand {
|
||||
long duration = 0L;
|
||||
|
||||
if (args.length > 2) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String line = args[i];
|
||||
for (String line : args) {
|
||||
long time = Methods.parseTime(line);
|
||||
duration += time;
|
||||
|
||||
|
@ -9,7 +9,7 @@ import com.songoda.epichoppers.hopper.Hopper;
|
||||
import com.songoda.epichoppers.hopper.HopperBuilder;
|
||||
import com.songoda.epichoppers.hopper.ItemType;
|
||||
import com.songoda.epichoppers.hopper.LinkType;
|
||||
import com.songoda.epichoppers.utils.TeleportTrigger;
|
||||
import com.songoda.epichoppers.hopper.teleport.TeleportTrigger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
@ -14,7 +14,7 @@ import com.songoda.epichoppers.player.SyncType;
|
||||
import com.songoda.epichoppers.settings.Settings;
|
||||
import com.songoda.epichoppers.utils.CostType;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import com.songoda.epichoppers.utils.TeleportTrigger;
|
||||
import com.songoda.epichoppers.hopper.teleport.TeleportTrigger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -269,7 +269,7 @@ public class GUIOverview extends CustomizableGui {
|
||||
|
||||
private void runTask() {
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
if (inventory.getViewers().size() != 0)
|
||||
if (!inventory.getViewers().isEmpty())
|
||||
this.constructGUI();
|
||||
}, 5L, 5L);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class Filter {
|
||||
|
||||
|
||||
public List<ItemStack> getWhiteList() {
|
||||
return whiteList != null ? whiteList : Collections.EMPTY_LIST;
|
||||
return whiteList != null ? whiteList : Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ public class Filter {
|
||||
|
||||
|
||||
public List<ItemStack> getBlackList() {
|
||||
return blackList != null ? blackList : Collections.EMPTY_LIST;
|
||||
return blackList != null ? blackList : Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ public class Filter {
|
||||
|
||||
|
||||
public List<ItemStack> getVoidList() {
|
||||
return voidList != null ? voidList : Collections.EMPTY_LIST;
|
||||
return voidList != null ? voidList : Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ public class Filter {
|
||||
|
||||
|
||||
public List<ItemStack> getAutoSellWhiteList() {
|
||||
return autoSellWhiteList != null ? autoSellWhiteList : Collections.EMPTY_LIST;
|
||||
return autoSellWhiteList != null ? autoSellWhiteList : Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ public class Filter {
|
||||
|
||||
|
||||
public List<ItemStack> getAutoSellBlackList() {
|
||||
return autoSellBlackList != null ? autoSellBlackList : Collections.EMPTY_LIST;
|
||||
return autoSellBlackList != null ? autoSellBlackList : Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.songoda.epichoppers.hopper;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
@ -7,14 +9,14 @@ import com.songoda.epichoppers.EpicHoppers;
|
||||
import com.songoda.epichoppers.api.events.HopperAccessEvent;
|
||||
import com.songoda.epichoppers.gui.GUIOverview;
|
||||
import com.songoda.epichoppers.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.hopper.teleport.TeleportTrigger;
|
||||
import com.songoda.epichoppers.player.PlayerData;
|
||||
import com.songoda.epichoppers.settings.Settings;
|
||||
import com.songoda.epichoppers.utils.CostType;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import com.songoda.epichoppers.utils.TeleportTrigger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -92,7 +94,7 @@ public class Hopper {
|
||||
return;
|
||||
}
|
||||
if (!EconomyManager.hasBalance(player, cost)) {
|
||||
plugin.getInstance().getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||
plugin.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
EconomyManager.withdrawBalance(player, cost);
|
||||
@ -123,20 +125,16 @@ public class Hopper {
|
||||
}
|
||||
Location loc = location.clone().add(.5, .5, .5);
|
||||
|
||||
if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) return;
|
||||
|
||||
player.getWorld().spawnParticle(org.bukkit.Particle.valueOf(plugin.getConfig().getString("Main.Upgrade Particle Type")), loc, 200, .5, .5, .5);
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(Settings.UPGRADE_PARTICLE_TYPE.getString()),
|
||||
loc, 100, .5, .5, .5);
|
||||
|
||||
if (plugin.getLevelManager().getHighestLevel() != level) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F);
|
||||
player.playSound(player.getLocation(), CompatibleSound.ENTITY_PLAYER_LEVELUP.getSound(), 0.6F, 15.0F);
|
||||
} else {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 2F, 25.0F);
|
||||
|
||||
if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) return;
|
||||
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 2F, 25.0F);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1.2F, 35.0F), 5L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1.8F, 35.0F), 10L);
|
||||
player.playSound(player.getLocation(), CompatibleSound.ENTITY_PLAYER_LEVELUP.getSound(), 2F, 25.0F);
|
||||
player.playSound(player.getLocation(), CompatibleSound.BLOCK_NOTE_BLOCK_CHIME.getSound(), 2F, 25.0F);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> player.playSound(player.getLocation(), CompatibleSound.BLOCK_NOTE_BLOCK_CHIME.getSound(), 1.2F, 35.0F), 5L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> player.playSound(player.getLocation(), CompatibleSound.BLOCK_NOTE_BLOCK_CHIME.getSound(), 1.8F, 35.0F), 10L);
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +153,7 @@ public class Hopper {
|
||||
instance.getLocale().getMessage("event.hopper.synctimeout").sendPrefixedMessage(player);
|
||||
playerData.setSyncType(null);
|
||||
}
|
||||
}, instance.getConfig().getLong("Main.Timeout When Syncing Hoppers") * level.getLinkAmount());
|
||||
}, Settings.LINK_TIMEOUT.getLong() * level.getLinkAmount());
|
||||
}
|
||||
|
||||
public void link(Block toLink, boolean filtered, Player player) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.epichoppers.hopper;
|
||||
|
||||
import com.songoda.epichoppers.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.utils.TeleportTrigger;
|
||||
import com.songoda.epichoppers.hopper.teleport.TeleportTrigger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -13,9 +13,25 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HopperManager {
|
||||
protected boolean ready;
|
||||
|
||||
private final Map<Location, Hopper> registeredHoppers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Sets {@link #isReady()} to {@code true}.<br>
|
||||
* <b>Called by {@link EpicHoppers#onDataLoad()}</b>
|
||||
*/
|
||||
public void setReady() {
|
||||
this.ready = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true, if all the data has been loaded from the DB
|
||||
*/
|
||||
public boolean isReady() {
|
||||
return this.ready;
|
||||
}
|
||||
|
||||
public Hopper addHopper(Hopper hopper) {
|
||||
registeredHoppers.put(roundLocation(hopper.getLocation()), hopper);
|
||||
return hopper;
|
||||
@ -50,41 +66,47 @@ public class HopperManager {
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
||||
public Hopper getHopper(Location location) {
|
||||
if (!registeredHoppers.containsKey(location = roundLocation(location))) {
|
||||
if (!this.ready) {
|
||||
throw new IllegalStateException("Hoppers are still being loaded");
|
||||
}
|
||||
|
||||
Hopper hopper = addHopper(new Hopper(location));
|
||||
EpicHoppers.getInstance().getDataManager().createHopper(hopper);
|
||||
}
|
||||
return registeredHoppers.get(location);
|
||||
}
|
||||
|
||||
|
||||
public Hopper getHopper(Block block) {
|
||||
return getHopper(block.getLocation());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <em>Returns {@code false} if {@link #isReady()} is false too</em>
|
||||
*/
|
||||
public boolean isHopper(Location location) {
|
||||
return registeredHoppers.containsKey(roundLocation(location));
|
||||
}
|
||||
|
||||
|
||||
public Map<Location, Hopper> getHoppers() {
|
||||
return Collections.unmodifiableMap(registeredHoppers);
|
||||
}
|
||||
|
||||
|
||||
public Hopper getHopperFromPlayer(Player player) {
|
||||
if (!this.ready) {
|
||||
throw new IllegalStateException("Hoppers are still being loaded");
|
||||
}
|
||||
|
||||
for (Hopper hopper : registeredHoppers.values()) {
|
||||
if (hopper.getLastPlayerOpened() == player.getUniqueId()) {
|
||||
return hopper;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private Location roundLocation(Location location) {
|
||||
location = location.clone();
|
||||
location.setX(location.getBlockX());
|
||||
|
@ -36,7 +36,7 @@ public class LevelManager {
|
||||
|
||||
// Legacy trash.
|
||||
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]));
|
||||
}
|
||||
|
||||
|
@ -460,7 +460,7 @@ public class ModuleAutoCrafting extends Module {
|
||||
* Like {@link #equals(Object)} but ignores {@link #additionalAmount} and {@link ItemStack#getAmount()}
|
||||
*
|
||||
* @return If two {@link SimpleIngredient} objects are equal
|
||||
* while ignoring any item amounts, true otherwise false
|
||||
* while ignoring any item amounts, true otherwise false
|
||||
*/
|
||||
public boolean isSimilar(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -77,7 +77,7 @@ public class ModuleAutoSmelter extends Module {
|
||||
blockmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.smelttitle").getMessage());
|
||||
ArrayList<String> loreblock = new ArrayList<>();
|
||||
String[] parts = plugin.getLocale().getMessage("interface.hopper.smeltlore").processPlaceholder("timeleft",
|
||||
getTime(hopper) == -9999 ? "\u221E" : (int) Math.floor(getTime(hopper) / 20)).processPlaceholder("enabled",
|
||||
getTime(hopper) == -9999 ? "\u221E" : (int) Math.floor(getTime(hopper) / 20.0)).processPlaceholder("enabled",
|
||||
isEnabled(hopper) ? EpicHoppers.getInstance().getLocale().getMessage("general.word.enabled").getMessage()
|
||||
: EpicHoppers.getInstance().getLocale().getMessage("general.word.disabled").getMessage()).getMessage().split("\\|");
|
||||
for (String line : parts) {
|
||||
@ -99,7 +99,7 @@ public class ModuleAutoSmelter extends Module {
|
||||
@Override
|
||||
public List<Material> getBlockedItems(Hopper hopper) {
|
||||
if (getTime(hopper) == -9999)
|
||||
return Collections.EMPTY_LIST;
|
||||
return Collections.emptyList();
|
||||
|
||||
List<Material> blockedItems = new ArrayList<>();
|
||||
for (CompatibleMaterial material : CompatibleMaterial.values())
|
||||
@ -112,7 +112,7 @@ public class ModuleAutoSmelter extends Module {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return plugin.getLocale().getMessage("interface.hopper.autosmelt")
|
||||
.processPlaceholder("ticks", (int) Math.floor(timeOut / 20)).getMessage();
|
||||
.processPlaceholder("ticks", (int) Math.floor(timeOut / 20.0)).getMessage();
|
||||
}
|
||||
|
||||
private int getTime(Hopper hopper) {
|
||||
|
@ -10,6 +10,7 @@ import com.songoda.epichoppers.hopper.Hopper;
|
||||
import com.songoda.epichoppers.settings.Settings;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import com.songoda.epichoppers.utils.StorageContainerCache;
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -37,22 +38,8 @@ public class ModuleSuction extends Module {
|
||||
|
||||
private static List<UUID> blacklist = new ArrayList<>();
|
||||
|
||||
private final static boolean wildStacker = Bukkit.getPluginManager().isPluginEnabled("WildStacker");
|
||||
private final static boolean ultimateStacker = Bukkit.getPluginManager().isPluginEnabled("UltimateStacker");
|
||||
private static boolean oldUltimateStacker;
|
||||
private static Method oldUltimateStacker_updateItemAmount;
|
||||
|
||||
static {
|
||||
if (ultimateStacker) {
|
||||
try {
|
||||
oldUltimateStacker_updateItemAmount = com.songoda.ultimatestacker.utils.Methods.class.getDeclaredMethod("updateItemAmount", Item.class, int.class);
|
||||
oldUltimateStacker = true;
|
||||
} catch (NoSuchMethodException | SecurityException ex) {
|
||||
}
|
||||
} else {
|
||||
oldUltimateStacker = false;
|
||||
}
|
||||
}
|
||||
private static final boolean wildStacker = Bukkit.getPluginManager().isPluginEnabled("WildStacker");
|
||||
private static final boolean ultimateStacker = Bukkit.getPluginManager().isPluginEnabled("UltimateStacker");
|
||||
|
||||
public ModuleSuction(EpicHoppers plugin, int amount) {
|
||||
super(plugin);
|
||||
@ -76,7 +63,7 @@ public class ModuleSuction extends Module {
|
||||
&& !entity.isDead()
|
||||
&& entity.getTicksLived() >= ((Item) entity).getPickupDelay()
|
||||
&& entity.getLocation().getBlock().getType() != Material.HOPPER)
|
||||
.map(entity -> (Item) entity)
|
||||
.map(Item.class::cast)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if (itemsToSuck.isEmpty())
|
||||
@ -84,10 +71,9 @@ public class ModuleSuction extends Module {
|
||||
|
||||
boolean filterEndpoint = hopper.getFilter().getEndPoint() != null;
|
||||
|
||||
InventoryHolder inventoryHolder = null;
|
||||
Inventory hopperInventory = null;
|
||||
if (Settings.EMIT_INVENTORYPICKUPITEMEVENT.getBoolean()) {
|
||||
inventoryHolder = (InventoryHolder) hopper.getBlock().getState();
|
||||
InventoryHolder inventoryHolder = (InventoryHolder) hopper.getBlock().getState();
|
||||
hopperInventory = Bukkit.createInventory(inventoryHolder, InventoryType.HOPPER);
|
||||
}
|
||||
|
||||
@ -118,7 +104,7 @@ public class ModuleSuction extends Module {
|
||||
// whitelist has priority
|
||||
if (!hopper.getFilter().getWhiteList().isEmpty()) {
|
||||
// is this item on the whitelist?
|
||||
if (!hopper.getFilter().getWhiteList().stream().anyMatch(filterItem -> Methods.isSimilarMaterial(itemStack, filterItem))) {
|
||||
if (hopper.getFilter().getWhiteList().stream().noneMatch(filterItem -> Methods.isSimilarMaterial(itemStack, filterItem))) {
|
||||
// nope!
|
||||
continue;
|
||||
}
|
||||
@ -177,15 +163,7 @@ public class ModuleSuction extends Module {
|
||||
|
||||
private void updateAmount(Item item, int amount) {
|
||||
if (ultimateStacker) {
|
||||
if (oldUltimateStacker) {
|
||||
try {
|
||||
oldUltimateStacker_updateItemAmount.invoke(null, item, amount);
|
||||
} catch (Exception ex) {
|
||||
item.remove(); // not the best solution, but they should update, anyway..
|
||||
}
|
||||
} else {
|
||||
com.songoda.ultimatestacker.utils.Methods.updateItemAmount(item, item.getItemStack(), amount);
|
||||
}
|
||||
UltimateStacker.updateItemAmount(item, item.getItemStack(), amount);
|
||||
} else if (wildStacker)
|
||||
WildStackerAPI.getStackedItem(item).setStackAmount(amount, true);
|
||||
else
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.songoda.epichoppers.handlers;
|
||||
package com.songoda.epichoppers.hopper.teleport;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.epichoppers.EpicHoppers;
|
||||
import com.songoda.epichoppers.hopper.Hopper;
|
||||
import com.songoda.epichoppers.settings.Settings;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import com.songoda.epichoppers.utils.TeleportTrigger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -24,20 +24,24 @@ public class TeleportHandler {
|
||||
|
||||
private final Map<UUID, Long> lastTeleports = new HashMap<>();
|
||||
|
||||
private EpicHoppers plugin;
|
||||
private final EpicHoppers plugin;
|
||||
|
||||
public TeleportHandler(EpicHoppers plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::teleportRunner, 0, plugin.getConfig().getLong("Main.Amount of Ticks Between Teleport"));
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::teleportRunner, 0,
|
||||
Settings.TELEPORT_TICKS.getLong());
|
||||
}
|
||||
|
||||
private void teleportRunner() {
|
||||
if (!plugin.getHopperManager().isReady())
|
||||
return;
|
||||
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
for (Entity entity : world.getEntities()) {
|
||||
if (!(entity instanceof LivingEntity) || entity.getType() == EntityType.ARMOR_STAND)
|
||||
continue;
|
||||
|
||||
if (!this.plugin.getConfig().getBoolean("Main.Allow Players To Teleport Through Hoppers")
|
||||
if (!Settings.TELEPORT.getBoolean()
|
||||
|| (entity instanceof Player && !entity.hasPermission("EpicHoppers.Teleport")))
|
||||
continue;
|
||||
|
||||
@ -106,7 +110,6 @@ public class TeleportHandler {
|
||||
|
||||
entity.teleport(location);
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12))
|
||||
entity.getWorld().playSound(entity.getLocation(), ServerVersion.isServerVersion(ServerVersion.V1_12) ? Sound.valueOf("ENTITY_ENDERMEN_TELEPORT") : Sound.ENTITY_ENDERMAN_TELEPORT, 10, 10);
|
||||
CompatibleSound.ENTITY_ENDERMAN_TELEPORT.play(entity.getWorld(), entity.getLocation(), 10, 10);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.songoda.epichoppers.hopper.teleport;
|
||||
|
||||
public enum TeleportTrigger {
|
||||
|
||||
DISABLED, WALK_ON, SNEAK
|
||||
|
||||
}
|
@ -17,7 +17,6 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/14/2017.
|
||||
*/
|
||||
@ -54,6 +53,12 @@ public class BlockListeners implements Listener {
|
||||
if (Settings.ALLOW_NORMAL_HOPPERS.getBoolean() && !plugin.getLevelManager().isEpicHopper(item))
|
||||
return;
|
||||
|
||||
if (!plugin.getHopperManager().isReady()) {
|
||||
player.sendMessage(plugin.getLocale().getMessage("event.hopper.notready").getMessage());
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Hopper hopper = plugin.getHopperManager().addHopper(
|
||||
new HopperBuilder(e.getBlock())
|
||||
.setLevel(plugin.getLevelManager().getLevel(item))
|
||||
@ -70,7 +75,7 @@ public class BlockListeners implements Listener {
|
||||
if (num > limit)
|
||||
limit = num;
|
||||
}
|
||||
if (limit == -1) limit = plugin.getConfig().getInt("Main.Max Hoppers Per Chunk");
|
||||
if (limit == -1) limit = Settings.MAX_CHUNK.getInt();
|
||||
return limit;
|
||||
}
|
||||
|
||||
@ -93,6 +98,12 @@ public class BlockListeners implements Listener {
|
||||
|
||||
if (event.getBlock().getType() != Material.HOPPER) return;
|
||||
|
||||
if (!plugin.getHopperManager().isReady()) {
|
||||
player.sendMessage(plugin.getLocale().getMessage("event.hopper.notready").getMessage());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.ALLOW_NORMAL_HOPPERS.getBoolean() && !plugin.getHopperManager().isHopper(block.getLocation()))
|
||||
return;
|
||||
|
||||
|
@ -25,10 +25,10 @@ import org.bukkit.inventory.ItemStack;
|
||||
*/
|
||||
public class HopperListeners implements Listener {
|
||||
|
||||
private final EpicHoppers instance;
|
||||
private final EpicHoppers plugin;
|
||||
|
||||
public HopperListeners(EpicHoppers instance) {
|
||||
this.instance = instance;
|
||||
public HopperListeners(EpicHoppers plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
// todo: InventoryMoveItemEvent for filters
|
||||
@ -40,7 +40,7 @@ public class HopperListeners implements Listener {
|
||||
Location sourceLocation = source.getHolder() instanceof BlockState ? ((BlockState) source.getHolder()).getLocation() : null;
|
||||
Location destinationLocation = destination.getHolder() instanceof BlockState ? ((BlockState) destination.getHolder()).getLocation() : null;
|
||||
|
||||
if (sourceLocation != null && Settings.ALLOW_NORMAL_HOPPERS.getBoolean() && !instance.getHopperManager().isHopper(sourceLocation))
|
||||
if (sourceLocation != null && Settings.ALLOW_NORMAL_HOPPERS.getBoolean() && !plugin.getHopperManager().isHopper(sourceLocation))
|
||||
return;
|
||||
|
||||
// Hopper minecarts should be able to take care of themselves
|
||||
@ -66,10 +66,14 @@ public class HopperListeners implements Listener {
|
||||
|
||||
// Special cases when a hopper is picking up items
|
||||
if (destination.getHolder() instanceof org.bukkit.block.Hopper) {
|
||||
if (destinationLocation != null && Settings.ALLOW_NORMAL_HOPPERS.getBoolean() && !instance.getHopperManager().isHopper(destinationLocation))
|
||||
if (destinationLocation != null && Settings.ALLOW_NORMAL_HOPPERS.getBoolean() && !plugin.getHopperManager().isHopper(destinationLocation))
|
||||
return;
|
||||
|
||||
Hopper toHopper = instance.getHopperManager().getHopper(destinationLocation);
|
||||
// Calling HopperManager#getHopper() automatically creates a new Hopper and we don't need to iterate over default-valued hoppers
|
||||
if (!plugin.getHopperManager().isHopper(destinationLocation))
|
||||
return;
|
||||
|
||||
Hopper toHopper = plugin.getHopperManager().getHopper(destinationLocation);
|
||||
// minecraft 1.8 doesn't have a method to get the hopper's location from the inventory, so we use the holder instead
|
||||
final ItemStack toMove = event.getItem();
|
||||
|
||||
@ -89,7 +93,7 @@ public class HopperListeners implements Listener {
|
||||
if (toHopper != null
|
||||
&& toHopper.getFilter().getEndPoint() == null
|
||||
&& !(toHopper.getFilter().getWhiteList().isEmpty() && toHopper.getFilter().getBlackList().isEmpty())) {
|
||||
// this hopper has a filter with no rejection endpoint, so don't absorb disalowed items
|
||||
// this hopper has a filter with no rejection endpoint, so don't absorb disallowed items
|
||||
boolean allowItem;
|
||||
ItemStack moveInstead = null;
|
||||
// whitelist has priority
|
||||
@ -113,10 +117,9 @@ public class HopperListeners implements Listener {
|
||||
}
|
||||
} else {
|
||||
// check the blacklist
|
||||
allowItem = !toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilarMaterial(toMove, item));
|
||||
allowItem = toHopper.getFilter().getBlackList().stream().noneMatch(item -> Methods.isSimilarMaterial(toMove, item));
|
||||
if (!allowItem) {
|
||||
// can we change the item to something else?
|
||||
searchReplacement:
|
||||
for (ItemStack sourceItem : source.getContents()) {
|
||||
if (sourceItem != null && Methods.canMove(destination, sourceItem)) {
|
||||
boolean blacklisted = toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilarMaterial(sourceItem, item));
|
||||
|
@ -7,7 +7,7 @@ import com.songoda.epichoppers.hopper.Hopper;
|
||||
import com.songoda.epichoppers.player.PlayerData;
|
||||
import com.songoda.epichoppers.player.SyncType;
|
||||
import com.songoda.epichoppers.settings.Settings;
|
||||
import com.songoda.epichoppers.utils.TeleportTrigger;
|
||||
import com.songoda.epichoppers.hopper.teleport.TeleportTrigger;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -27,26 +27,26 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
*/
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private final EpicHoppers instance;
|
||||
private final EpicHoppers plugin;
|
||||
|
||||
public InteractListeners(EpicHoppers instance) {
|
||||
this.instance = instance;
|
||||
public InteractListeners(EpicHoppers plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleSneakEvent(PlayerToggleSneakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.isSneaking()) {
|
||||
if (player.isSneaking() && plugin.getHopperManager().isReady()) {
|
||||
Location location = player.getLocation().getBlock().getRelative(BlockFace.SELF).getLocation();
|
||||
Location down = location.getBlock().getRelative(BlockFace.DOWN).getLocation();
|
||||
if (instance.getHopperManager().isHopper(down)) {
|
||||
Hopper hopper = instance.getHopperManager().getHopper(down);
|
||||
if (plugin.getHopperManager().isHopper(down)) {
|
||||
Hopper hopper = plugin.getHopperManager().getHopper(down);
|
||||
if (hopper.getTeleportTrigger() == TeleportTrigger.SNEAK)
|
||||
instance.getTeleportHandler().tpEntity(player, hopper);
|
||||
} else if (instance.getHopperManager().isHopper(location)) {
|
||||
Hopper hopper = instance.getHopperManager().getHopper(location);
|
||||
plugin.getTeleportHandler().tpEntity(player, hopper);
|
||||
} else if (plugin.getHopperManager().isHopper(location)) {
|
||||
Hopper hopper = plugin.getHopperManager().getHopper(location);
|
||||
if (hopper.getTeleportTrigger() == TeleportTrigger.SNEAK)
|
||||
instance.getTeleportHandler().tpEntity(player, hopper);
|
||||
plugin.getTeleportHandler().tpEntity(player, hopper);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -66,7 +66,7 @@ public class InteractListeners implements Listener {
|
||||
return;
|
||||
|
||||
if (Settings.USE_PROTECTION_PLUGINS.getBoolean() && !ProtectionManager.canInteract(player, event.getClickedBlock().getLocation())) {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.general.protected").getPrefixedMessage());
|
||||
player.sendMessage(plugin.getLocale().getMessage("event.general.protected").getPrefixedMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -80,17 +80,22 @@ public class InteractListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player);
|
||||
|
||||
PlayerData playerData = plugin.getPlayerDataManager().getPlayerData(player);
|
||||
|
||||
if (playerData.getSyncType() == null) {
|
||||
if (event.getClickedBlock().getType() == Material.HOPPER) {
|
||||
if (Settings.ALLOW_NORMAL_HOPPERS.getBoolean() && !instance.getHopperManager().isHopper(event.getClickedBlock().getLocation()))
|
||||
if (!plugin.getHopperManager().isReady()) {
|
||||
player.sendMessage(plugin.getLocale().getMessage("event.hopper.notready").getMessage());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.ALLOW_NORMAL_HOPPERS.getBoolean() && !plugin.getHopperManager().isHopper(event.getClickedBlock().getLocation()))
|
||||
return;
|
||||
|
||||
Hopper hopper = instance.getHopperManager().getHopper(event.getClickedBlock());
|
||||
Hopper hopper = plugin.getHopperManager().getHopper(event.getClickedBlock());
|
||||
if (!player.getInventory().getItemInHand().getType().name().contains("PICKAXE")) {
|
||||
hopper.overview(instance.getGuiManager(), player);
|
||||
hopper.overview(plugin.getGuiManager(), player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -98,13 +103,15 @@ public class InteractListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getClickedBlock().getState() instanceof InventoryHolder || (event.getClickedBlock().getType().equals(Material.ENDER_CHEST) && instance.getConfig().getBoolean("Main.Support Enderchests"))) {
|
||||
if (event.getClickedBlock().getState() instanceof InventoryHolder
|
||||
|| (event.getClickedBlock().getType().equals(Material.ENDER_CHEST)
|
||||
&& Settings.ENDERCHESTS.getBoolean())) {
|
||||
Hopper hopper = playerData.getLastHopper();
|
||||
if (event.getClickedBlock().getLocation().equals(playerData.getLastHopper().getLocation())) {
|
||||
if (hopper.getLinkedBlocks().size() != 0)
|
||||
instance.getLocale().getMessage("event.hopper.syncfinish").sendPrefixedMessage(player);
|
||||
if (!hopper.getLinkedBlocks().isEmpty())
|
||||
plugin.getLocale().getMessage("event.hopper.syncfinish").sendPrefixedMessage(player);
|
||||
else
|
||||
instance.getLocale().getMessage("event.hopper.synccanceled").sendPrefixedMessage(player);
|
||||
plugin.getLocale().getMessage("event.hopper.synccanceled").sendPrefixedMessage(player);
|
||||
hopper.cancelSync(player);
|
||||
} else if (playerData.getSyncType() != null) {
|
||||
hopper.link(event.getClickedBlock(), playerData.getSyncType() == SyncType.FILTERED, player);
|
||||
|
@ -2,8 +2,6 @@ package com.songoda.epichoppers.player;
|
||||
|
||||
import com.songoda.epichoppers.hopper.Hopper;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerData {
|
||||
|
||||
private Hopper lastHopper = null;
|
||||
|
@ -13,9 +13,7 @@ public class PlayerDataManager {
|
||||
private final Map<UUID, PlayerData> registeredPlayers = new HashMap<>();
|
||||
|
||||
private PlayerData getPlayerData(UUID uuid) {
|
||||
if (!registeredPlayers.containsKey(uuid))
|
||||
registeredPlayers.put(uuid, new PlayerData());
|
||||
return registeredPlayers.get(uuid);
|
||||
return registeredPlayers.computeIfAbsent(uuid, u -> new PlayerData());
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData(Player player) {
|
||||
|
@ -36,7 +36,7 @@ public class Settings {
|
||||
public static final ConfigSetting ENDERCHESTS = new ConfigSetting(config, "Main.Support Enderchests", true,
|
||||
"Should hoppers dump items into a player enderchests?");
|
||||
|
||||
public static final ConfigSetting PARTICLE_TYPE = new ConfigSetting(config, "Main.Upgrade Particle Type", "SPELL_WITCH",
|
||||
public static final ConfigSetting UPGRADE_PARTICLE_TYPE = new ConfigSetting(config, "Main.Upgrade Particle Type", "SPELL_WITCH",
|
||||
"The type of particle shown when a hopper is upgraded.");
|
||||
|
||||
public static final ConfigSetting HOP_TICKS = new ConfigSetting(config, "Main.Amount of Ticks Between Hops", 8L,
|
||||
@ -52,7 +52,7 @@ public class Settings {
|
||||
"The cooldown between teleports. It prevents players",
|
||||
"from getting stuck in a teleport loop.");
|
||||
|
||||
public static final ConfigSetting SYNC_TIMEOUT = new ConfigSetting(config, "Main.Timeout When Syncing Hoppers", 300L,
|
||||
public static final ConfigSetting LINK_TIMEOUT = new ConfigSetting(config, "Main.Timeout When Syncing Hoppers", 300L,
|
||||
"The amount of time in ticks a player has between hitting the hopper",
|
||||
"Link button and performing the link. When the time is up the link event is canceled.");
|
||||
|
||||
|
@ -3,7 +3,6 @@ package com.songoda.epichoppers.tasks;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.epichoppers.EpicHoppers;
|
||||
import com.songoda.epichoppers.boost.BoostData;
|
||||
import com.songoda.epichoppers.hopper.HopperManager;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.Module;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.ModuleAutoCrafting;
|
||||
import com.songoda.epichoppers.settings.Settings;
|
||||
@ -29,10 +28,8 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
@ -44,14 +41,14 @@ public class HopTask extends BukkitRunnable {
|
||||
|
||||
// Hop to the bop to the be bop top.
|
||||
|
||||
private static EpicHoppers plugin;
|
||||
private EpicHoppers plugin;
|
||||
|
||||
private final int hopTicks;
|
||||
private final boolean hasFabledSkyBlock;
|
||||
private final Plugin fabledSkyblockPlugin;
|
||||
|
||||
public HopTask(EpicHoppers plugin) {
|
||||
HopTask.plugin = plugin;
|
||||
this.plugin = plugin;
|
||||
this.hopTicks = Math.max(1, Settings.HOP_TICKS.getInt() / 2); // Purposeful integer division. Don't go below 1.
|
||||
this.runTaskTimer(plugin, 0, 2);
|
||||
this.hasFabledSkyBlock = (fabledSkyblockPlugin = Bukkit.getPluginManager().getPlugin("FabledSkyBlock")) != null;
|
||||
@ -110,8 +107,8 @@ public class HopTask extends BukkitRunnable {
|
||||
List<Material> materials = module.getBlockedItems(hopper);
|
||||
if (materials != null && !materials.isEmpty())
|
||||
blockedMaterials.addAll(materials);
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
@ -174,7 +171,6 @@ public class HopTask extends BukkitRunnable {
|
||||
|
||||
// Move items into destination containers
|
||||
pushItemsIntoContainers(hopper, hopperCache, maxToMove, blockedMaterials, hopperDirection);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -386,7 +382,7 @@ public class HopTask extends BukkitRunnable {
|
||||
if (checkForMinecarts) {
|
||||
for (InventoryHolder minecartInventory : hopper.getWorld().getNearbyEntities(pointingLocation.clone().add(0.5, 0.5, 0.5), 0.5, 0.5, 0.5)
|
||||
.stream().filter(e -> e.getType() == EntityType.MINECART_CHEST || e.getType() == EntityType.MINECART_HOPPER)
|
||||
.map(e -> (InventoryHolder) e).collect(Collectors.toSet())) {
|
||||
.map(InventoryHolder.class::cast).collect(Collectors.toSet())) {
|
||||
StorageContainerCache.Cache cache = new StorageContainerCache.Cache(Material.CHEST, minecartInventory.getInventory().getContents());
|
||||
if (tryPush(hopper, hopperCache, cache, filterCache, maxToMove, blockedMaterials)) {
|
||||
if (cache.isDirty())
|
||||
|
@ -1,18 +1,7 @@
|
||||
package com.songoda.epichoppers.utils;
|
||||
|
||||
/**
|
||||
* Represents a cost type when making a purchase from EpicSpawners
|
||||
*/
|
||||
public enum CostType {
|
||||
|
||||
/**
|
||||
* A purchase made with an economy balance (generally an implementation of Vault)
|
||||
*/
|
||||
ECONOMY,
|
||||
|
||||
/**
|
||||
* A purchase made with a player's experience levels
|
||||
*/
|
||||
EXPERIENCE
|
||||
ECONOMY, EXPERIENCE
|
||||
|
||||
}
|
@ -11,12 +11,12 @@ public enum HopperDirection {
|
||||
WEST(4, 12, -1, 0, 0),
|
||||
EAST(5, 13, 1, 0, 0);
|
||||
|
||||
private int unpowered;
|
||||
private int powered;
|
||||
private final int unpowered;
|
||||
private final int powered;
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
HopperDirection(int unpowered, int powered, int x, int y, int z) {
|
||||
this.unpowered = unpowered;
|
||||
@ -28,10 +28,9 @@ public enum HopperDirection {
|
||||
}
|
||||
|
||||
public static HopperDirection getDirection(int value) {
|
||||
for (HopperDirection hopperDirection : HopperDirection.values()) {
|
||||
if (hopperDirection.getPowered() == value
|
||||
|| hopperDirection.getUnpowered() == value) return hopperDirection;
|
||||
}
|
||||
for (HopperDirection hopperDirection : HopperDirection.values())
|
||||
if (hopperDirection.getPowered() == value || hopperDirection.getUnpowered() == value)
|
||||
return hopperDirection;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -165,8 +165,9 @@ public class Methods {
|
||||
return value * 1000 * 60;
|
||||
case 's':
|
||||
return value * 1000;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,156 +0,0 @@
|
||||
package com.songoda.epichoppers.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Serializers {
|
||||
public static String serialize(ItemStack item) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(item.getType().toString());
|
||||
if (item.getDurability() != 0) builder.append(":" + item.getDurability());
|
||||
builder.append(" " + item.getAmount());
|
||||
for (Enchantment enchant : item.getEnchantments().keySet())
|
||||
builder.append(" " + enchant.getName() + ":" + item.getEnchantments().get(enchant));
|
||||
String name = getName(item);
|
||||
if (name != null) builder.append(" name:" + name);
|
||||
String lore = getLore(item);
|
||||
if (lore != null) builder.append(" lore:" + lore);
|
||||
Color color = getArmorColor(item);
|
||||
if (color != null) builder.append(" rgb:" + color.getRed() + "|" + color.getGreen() + "|" + color.getBlue());
|
||||
String owner = getOwner(item);
|
||||
if (owner != null) builder.append(" owner:" + owner);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static ItemStack deserialize(String serializedItem) {
|
||||
String[] strings = serializedItem.split(" ");
|
||||
Map<Enchantment, Integer> enchants = new HashMap<>();
|
||||
String[] args;
|
||||
ItemStack item = new ItemStack(Material.AIR);
|
||||
for (String str : strings) {
|
||||
args = str.split(":");
|
||||
if (Material.matchMaterial(args[0]) != null && item.getType() == Material.AIR) {
|
||||
item.setType(Material.matchMaterial(args[0]));
|
||||
if (args.length == 2) item.setDurability(Short.parseShort(args[1]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (item.getType() == Material.AIR) {
|
||||
Bukkit.getLogger().info("Could not find a valid material for the item in \"" + serializedItem + "\"");
|
||||
return null;
|
||||
}
|
||||
for (String str : strings) {
|
||||
args = str.split(":", 2);
|
||||
if (isNumber(args[0])) item.setAmount(Integer.parseInt(args[0]));
|
||||
if (args.length == 1) continue;
|
||||
if (args[0].equalsIgnoreCase("name")) {
|
||||
setName(item, ChatColor.translateAlternateColorCodes('&', args[1]));
|
||||
continue;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("lore")) {
|
||||
setLore(item, ChatColor.translateAlternateColorCodes('&', args[1]));
|
||||
continue;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("rgb")) {
|
||||
setArmorColor(item, args[1]);
|
||||
continue;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("owner")) {
|
||||
setOwner(item, args[1]);
|
||||
continue;
|
||||
}
|
||||
if (Enchantment.getByName(args[0].toUpperCase()) != null) {
|
||||
enchants.put(Enchantment.getByName(args[0].toUpperCase()), Integer.parseInt(args[1]));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
item.addUnsafeEnchantments(enchants);
|
||||
return item.getType().equals(Material.AIR) ? null : item;
|
||||
}
|
||||
|
||||
private static String getOwner(ItemStack item) {
|
||||
if (!(item.getItemMeta() instanceof SkullMeta)) return null;
|
||||
return ((SkullMeta) item.getItemMeta()).getOwner();
|
||||
}
|
||||
|
||||
private static void setOwner(ItemStack item, String owner) {
|
||||
try {
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setOwner(owner);
|
||||
item.setItemMeta(meta);
|
||||
} catch (Exception exception) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getName(ItemStack item) {
|
||||
if (!item.hasItemMeta()) return null;
|
||||
if (!item.getItemMeta().hasDisplayName()) return null;
|
||||
return item.getItemMeta().getDisplayName().replace(" ", "_").replace(ChatColor.COLOR_CHAR, '&');
|
||||
}
|
||||
|
||||
private static void setName(ItemStack item, String name) {
|
||||
name = name.replace("_", " ").replace('&', ChatColor.COLOR_CHAR);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
private static String getLore(ItemStack item) {
|
||||
if (!item.hasItemMeta()) return null;
|
||||
if (!item.getItemMeta().hasLore()) return null;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
List<String> lore = item.getItemMeta().getLore();
|
||||
for (int ind = 0; ind < lore.size(); ind++) {
|
||||
builder.append((ind > 0 ? "|" : "") + lore.get(ind).replace(" ", "_").replace(ChatColor.COLOR_CHAR, '&'));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static void setLore(ItemStack item, String lore) {
|
||||
lore = lore.replace("_", " ").replace('&', ChatColor.COLOR_CHAR);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setLore(Arrays.asList(lore.split("\\|")));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
private static Color getArmorColor(ItemStack item) {
|
||||
if (!(item.getItemMeta() instanceof LeatherArmorMeta)) return null;
|
||||
return ((LeatherArmorMeta) item.getItemMeta()).getColor();
|
||||
}
|
||||
|
||||
private static void setArmorColor(ItemStack item, String str) {
|
||||
try {
|
||||
String[] colors = str.split("\\|");
|
||||
int red = Integer.parseInt(colors[0]);
|
||||
int green = Integer.parseInt(colors[1]);
|
||||
int blue = Integer.parseInt(colors[2]);
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
|
||||
meta.setColor(Color.fromRGB(red, green, blue));
|
||||
item.setItemMeta(meta);
|
||||
} catch (Exception exception) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isNumber(String str) {
|
||||
try {
|
||||
Integer.parseInt(str);
|
||||
} catch (NumberFormatException exception) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class StorageContainerCache {
|
||||
|
||||
private final static Map<Block, Cache> inventoryCache = new HashMap<>();
|
||||
private static final Map<Block, Cache> inventoryCache = new HashMap<>();
|
||||
|
||||
// need to get the topmost inventory for a double chest, and save as that block
|
||||
public static Cache getCachedInventory(Block b) {
|
||||
@ -71,6 +71,9 @@ public class StorageContainerCache {
|
||||
break;
|
||||
case WEST:
|
||||
other = block.getRelative(c.getType() != Chest.Type.RIGHT ? BlockFace.NORTH : BlockFace.SOUTH);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// double-check
|
||||
if (other != null && other.getType() == block.getType()) {
|
||||
@ -81,7 +84,7 @@ public class StorageContainerCache {
|
||||
} else {
|
||||
// legacy check
|
||||
Material material = block.getType();
|
||||
BlockFace[] faces = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST};
|
||||
BlockFace[] faces = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST};
|
||||
for (BlockFace face : faces) {
|
||||
Block adjacentBlock = block.getRelative(face);
|
||||
|
||||
@ -291,7 +294,10 @@ public class StorageContainerCache {
|
||||
else
|
||||
check[0] = true;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// we can reduce calls to ItemStack.isSimilar() by caching what cells to look at
|
||||
|
@ -1,7 +0,0 @@
|
||||
package com.songoda.epichoppers.utils;
|
||||
|
||||
public enum TeleportTrigger {
|
||||
DISABLED,
|
||||
WALK_ON,
|
||||
SNEAK
|
||||
}
|
@ -106,3 +106,4 @@ event:
|
||||
syncchest: '&7You have linked your &9%name% &7with this chest.'
|
||||
desyncchest: '&7You have unlinked your &9%name% &7with this chest.'
|
||||
autosell: '&7Your hopper sold &6%items% &7item(s) worth &6$%amount%&7.'
|
||||
notready: '&cHoppers are still being loaded...'
|
||||
|
Loading…
Reference in New Issue
Block a user