From 439b0aa7cac506a1e1295bb2428c1643f3e6a63f Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sun, 11 Jun 2023 13:32:13 +0200 Subject: [PATCH] Refactors SpawnerStackImpl to not extend SSpawner I don't think thats a good idea as SSpawner is part of the NMS system, even if the import does not hint at that. It will probably change gratly again in the near future anyway (hopefully before CraftaroCore v3.0.0 releases). --- .../stackable/spawner/SpawnerStackImpl.java | 82 +++++++++---------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/UltimateStacker/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackImpl.java b/UltimateStacker/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackImpl.java index ef562bc..d1f6c60 100644 --- a/UltimateStacker/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackImpl.java +++ b/UltimateStacker/src/main/java/com.craftaro.ultimatestacker/stackable/spawner/SpawnerStackImpl.java @@ -1,15 +1,15 @@ package com.craftaro.ultimatestacker.stackable.spawner; -import com.craftaro.ultimatestacker.UltimateStacker; -import com.craftaro.ultimatestacker.api.UltimateStackerAPI; -import com.craftaro.ultimatestacker.api.stack.spawner.SpawnerStack; -import com.craftaro.ultimatestacker.settings.Settings; -import com.craftaro.ultimatestacker.utils.Methods; import com.craftaro.core.compatibility.CompatibleMaterial; import com.craftaro.core.database.Data; import com.craftaro.core.database.SerializedLocation; import com.craftaro.core.nms.world.SpawnedEntity; import com.craftaro.core.world.SSpawner; +import com.craftaro.ultimatestacker.UltimateStacker; +import com.craftaro.ultimatestacker.api.UltimateStackerAPI; +import com.craftaro.ultimatestacker.api.stack.spawner.SpawnerStack; +import com.craftaro.ultimatestacker.settings.Settings; +import com.craftaro.ultimatestacker.utils.Methods; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; @@ -21,38 +21,36 @@ import java.util.Random; import java.util.Set; import java.util.UUID; -public class SpawnerStackImpl extends SSpawner implements SpawnerStack { +public class SpawnerStackImpl implements SpawnerStack { + private final UUID uniqueHologramId = UUID.randomUUID(); - // This is the unique identifier for this spawner. - // It is reset on every plugin load. - // Used for holograms. - private final UUID uniqueId = UUID.randomUUID(); - private int id; - + private Location location; private int amount; - private static final UltimateStacker plugin = UltimateStacker.getInstance(); + private SSpawner sSpawner; public SpawnerStackImpl(Location location, int amount) { - super(location); + this.location = location; this.amount = amount; + + this.sSpawner = new SSpawner(this.location); } @Override public int getAmount() { - return amount; + return this.amount; } @Override public boolean isValid() { - return CompatibleMaterial.getMaterial(location.getBlock()) == CompatibleMaterial.SPAWNER; + return CompatibleMaterial.getMaterial(this.location.getBlock()) == CompatibleMaterial.SPAWNER; } @Override public void setAmount(int amount) { this.amount = amount; - plugin.getPluginDataManager().save(this); + UltimateStacker.getInstance().getPluginDataManager().save(this); } @Override @@ -72,18 +70,18 @@ public class SpawnerStackImpl extends SSpawner implements SpawnerStack { Random random = new Random(); int count = 0; - for (int i = 0; i < getAmount(); i++) { + for (int i = 0; i < getAmount(); ++i) { count += random.nextInt(3) + 1; } return count; } public int spawn(int amountToSpawn, EntityType... types) { - return super.spawn(amountToSpawn, types); + return this.sSpawner.spawn(amountToSpawn, types); } public int spawn(int amountToSpawn, String particle, Set canSpawnOn, SpawnedEntity spawned, EntityType... types) { - return super.spawn(amountToSpawn, particle, canSpawnOn, spawned, types); + return this.sSpawner.spawn(amountToSpawn, particle, canSpawnOn, spawned, types); } public int getId() { @@ -93,9 +91,9 @@ public class SpawnerStackImpl extends SSpawner implements SpawnerStack { @Override public Map serialize() { Map map = new HashMap<>(); - map.put("id", id); - map.put("amount", amount); - map.putAll(new SerializedLocation(location).asMap()); + map.put("id", this.id); + map.put("amount", this.amount); + map.putAll(new SerializedLocation(this.location).asMap()); return map; } @@ -103,7 +101,8 @@ public class SpawnerStackImpl extends SSpawner implements SpawnerStack { public Data deserialize(Map map) { this.id = (int) map.get("id"); this.amount = (int) map.get("amount"); - this.initFromData(map); + this.location = SerializedLocation.of(map); + this.sSpawner = new SSpawner(this.location); return this; } @@ -117,17 +116,17 @@ public class SpawnerStackImpl extends SSpawner implements SpawnerStack { } public Location getLocation() { - return location.clone(); + return this.location.clone(); } @Override public String getHologramName() { - if (!(location.getBlock().getState() instanceof CreatureSpawner)) { - UltimateStackerAPI.getSpawnerStackManager().removeSpawner(location); + if (!(this.location.getBlock().getState() instanceof CreatureSpawner)) { + UltimateStackerAPI.getSpawnerStackManager().removeSpawner(this.location); return null; } - CreatureSpawner creatureSpawner = (CreatureSpawner) location.getBlock().getState(); - return Methods.compileSpawnerName(creatureSpawner.getSpawnedType(), amount); + CreatureSpawner creatureSpawner = (CreatureSpawner) this.location.getBlock().getState(); + return Methods.compileSpawnerName(creatureSpawner.getSpawnedType(), this.amount); } @Override @@ -136,36 +135,33 @@ public class SpawnerStackImpl extends SSpawner implements SpawnerStack { } public int getX() { - return location.getBlockX(); + return this.location.getBlockX(); } public int getY() { - return location.getBlockY(); + return this.location.getBlockY(); } public int getZ() { - return location.getBlockZ(); + return this.location.getBlockZ(); } public World getWorld() { - return location.getWorld(); + return this.location.getWorld(); } @Override public String getHologramId() { - return "UltimateStacker-" + uniqueId; + return "UltimateStacker-" + this.uniqueHologramId; } @Override public String toString() { - return "SpawnerStackImpl:{" - + "Amount:\"" + amount + "\"," - + "Location:{" - + "World:\"" + location.getWorld().getName() + "\"," - + "X:" + location.getBlockX() + "," - + "Y:" + location.getBlockY() + "," - + "Z:" + location.getBlockZ() - + "}" - + "}"; + return "SpawnerStackImpl{" + + "uniqueHologramId=" + this.uniqueHologramId + + ", id=" + this.id + + ", location=" + this.location + + ", amount=" + this.amount + + '}'; } }