diff --git a/UltimateStacker-API/src/main/java/com/craftaro/ultimatestacker/api/stack/spawner/SpawnerStackManager.java b/UltimateStacker-API/src/main/java/com/craftaro/ultimatestacker/api/stack/spawner/SpawnerStackManager.java index 5de4fd4..0004e35 100644 --- a/UltimateStacker-API/src/main/java/com/craftaro/ultimatestacker/api/stack/spawner/SpawnerStackManager.java +++ b/UltimateStacker-API/src/main/java/com/craftaro/ultimatestacker/api/stack/spawner/SpawnerStackManager.java @@ -32,14 +32,14 @@ public interface SpawnerStackManager { * @param block The block to get the spawner for * @return The spawner for the given block */ - SpawnerStack getSpawner(Block block); + @Nullable SpawnerStack getSpawner(Block block); /** * Get the spawner for the given location * @param location The location to get the spawner for * @return The spawner for the given location */ - SpawnerStack getSpawner(Location location); + @Nullable SpawnerStack getSpawner(Location location); /** * Check if the given block is a SpawnerStack diff --git a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/UltimateStacker.java b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/UltimateStacker.java index ec7991a..0bae565 100644 --- a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/UltimateStacker.java +++ b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/UltimateStacker.java @@ -9,8 +9,10 @@ import com.craftaro.core.database.DataManager; import com.craftaro.core.gui.GuiManager; import com.craftaro.core.hooks.EntityStackerManager; import com.craftaro.core.hooks.HologramManager; +import com.craftaro.core.hooks.HookManager; import com.craftaro.core.hooks.ProtectionManager; import com.craftaro.core.hooks.WorldGuardHook; +import com.craftaro.core.hooks.holograms.DecentHologramsHolograms; import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial; import com.craftaro.core.utils.TextUtils; import com.craftaro.ultimatestacker.api.UltimateStackerApi; @@ -359,20 +361,33 @@ public class UltimateStacker extends SongodaPlugin { if (!stack.isValid()) { if (stack instanceof BlockStackImpl) { blockStackManager.removeBlock(stack.getLocation()); + BlockStackImpl blockStack = (BlockStackImpl) stack; + dataManager.delete(blockStack); } else if (stack instanceof SpawnerStackImpl) { spawnerStackManager.removeSpawner(stack.getLocation()); + SpawnerStackImpl spawnerStack = (SpawnerStackImpl) stack; + dataManager.delete(spawnerStack); } - return; + } else { + // are holograms enabled? + if (!stack.areHologramsEnabled() && !HologramManager.getManager().isEnabled()) return; + // update the hologram + if (stack.getHologramName() == null) { + if (stack instanceof BlockStackImpl) { + BlockStackImpl blockStack = (BlockStackImpl) stack; + getLogger().warning("Hologram name is null for BlocStack at " + blockStack.getLocation()); + } else { + SpawnerStackImpl spawnerStack = (SpawnerStackImpl) stack; + getLogger().warning("Hologram name is null for SpawnerStack at " + spawnerStack.getLocation()); + } + return; + } + if (!HologramManager.isHologramLoaded(stack.getHologramId())) { + HologramManager.createHologram(stack.getHologramId(), stack.getLocation(), stack.getHologramName()); + return; + } + HologramManager.updateHologram(stack.getHologramId(), stack.getHologramName()); } - // are holograms enabled? - if (!stack.areHologramsEnabled() && !HologramManager.getManager().isEnabled()) return; - // update the hologram - if (!HologramManager.isHologramLoaded(stack.getHologramId())) { - HologramManager.createHologram(stack.getHologramId(), stack.getLocation(), stack.getHologramName()); - return; - } - - HologramManager.updateHologram(stack.getHologramId(), stack.getHologramName()); } public void removeHologram(Hologramable stack) { diff --git a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java index 2f5c933..77f8cb3 100644 --- a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java +++ b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java @@ -180,6 +180,7 @@ public class BlockListeners implements Listener { if (itemType == blockType) { SpawnerStack stack = UltimateStackerApi.getSpawnerStackManager().getSpawner(block); + if (stack == null) return; if (player.isSneaking()) return; if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (stack.getAmount() == maxStackSize) return; @@ -206,6 +207,7 @@ public class BlockListeners implements Listener { stack.setAmount(stack.getAmount() + itemAmount); plugin.updateHologram(stack); + plugin.getDataManager().save(stack); if (player.getGameMode() != GameMode.CREATIVE) hand.takeItem(player); } @@ -235,6 +237,7 @@ public class BlockListeners implements Listener { } SpawnerStack stack = UltimateStackerApi.getSpawnerStackManager().addSpawner(new SpawnerStackImpl(block.getLocation(), amount)); + plugin.getSpawnerStackManager().addSpawner(stack); plugin.getPluginDataManager().save(stack); cs.setSpawnedType(cs2.getSpawnedType()); @@ -285,6 +288,7 @@ public class BlockListeners implements Listener { plugin.getPluginDataManager().delete(spawnerStack); } else { stack.setAmount(stack.getAmount() - 1); + plugin.getDataManager().save(stack); plugin.updateHologram(stack); } diff --git a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackImpl.java b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackImpl.java index 0ef0f67..30f8225 100644 --- a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackImpl.java +++ b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackImpl.java @@ -35,6 +35,7 @@ public class SpawnerStackImpl implements SpawnerStack { } public SpawnerStackImpl(Location location, int amount) { + this.id = UltimateStacker.getInstance().getDataManager().getNextId("spawners"); this.location = location; this.amount = amount; @@ -54,7 +55,6 @@ public class SpawnerStackImpl implements SpawnerStack { @Override public void setAmount(int amount) { this.amount = amount; - UltimateStacker.getInstance().getPluginDataManager().save(this); } @Override diff --git a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackManagerImpl.java b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackManagerImpl.java index 2cc05d1..cdad915 100644 --- a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackManagerImpl.java +++ b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackManagerImpl.java @@ -5,6 +5,7 @@ import com.craftaro.ultimatestacker.UltimateStacker; import com.craftaro.ultimatestacker.api.stack.spawner.SpawnerStack; import com.craftaro.ultimatestacker.api.stack.spawner.SpawnerStackManager; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,27 +40,22 @@ public class SpawnerStackManagerImpl implements SpawnerStackManager { @Override public SpawnerStack getSpawner(Location location) { - if (!this.registeredSpawners.containsKey(roundLocation(location))) { - SpawnerStack spawnerStack = addSpawner(new SpawnerStackImpl(roundLocation(location), 1)); - UltimateStacker.getInstance().getPluginDataManager().save(spawnerStack); - return spawnerStack; - } - return this.registeredSpawners.get(location); + return this.registeredSpawners.get(roundLocation(location)); } @Override public boolean isSpawner(Block block) { - return isSpawner(block.getLocation()); + return isSpawner(roundLocation(block.getLocation())); } @Override public SpawnerStack getSpawner(Block block) { - return this.getSpawner(block.getLocation()); + return this.getSpawner(roundLocation(block.getLocation())); } @Override public boolean isSpawner(Location location) { - return this.registeredSpawners.get(location) != null; + return this.registeredSpawners.get(roundLocation(location)) != null; } @Override