Added validation for stackables.

This commit is contained in:
Brianna 2020-08-26 08:40:51 -05:00
parent b6046820bf
commit ccd9b68d1f
7 changed files with 36 additions and 10 deletions

View File

@ -360,6 +360,12 @@ public class UltimateStacker extends SongodaPlugin {
public void updateHologram(Hologramable stack) {
// Is this stack invalid?
if (!stack.isValid())
if (stack instanceof BlockStack)
blockStackManager.removeBlock(stack.getLocation());
else if (stack instanceof SpawnerStack)
spawnerStackManager.removeSpawner(stack.getLocation());
// are holograms enabled?
if (!stack.areHologramsEnabled() && !HologramManager.getManager().isEnabled()) return;
// create the hologram

View File

@ -9,4 +9,6 @@ public interface Hologramable {
String getHologramName();
boolean areHologramsEnabled();
boolean isValid();
}

View File

@ -1,7 +0,0 @@
package com.songoda.ultimatestacker.stackable;
public interface Stackable {
int getAmount();
}

View File

@ -4,7 +4,7 @@ import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.settings.Settings;
import com.songoda.ultimatestacker.stackable.Hologramable;
import com.songoda.ultimatestacker.stackable.Stackable;
import com.songoda.ultimatestacker.utils.Stackable;
import com.songoda.ultimatestacker.utils.Methods;
import org.bukkit.Location;
import org.bukkit.World;
@ -34,6 +34,11 @@ public class BlockStack implements Stackable, Hologramable {
return amount;
}
@Override
public boolean isValid() {
return CompatibleMaterial.getMaterial(location.getBlock()) == material;
}
public void add(int amount) {
this.amount = this.amount + amount;
}

View File

@ -3,7 +3,7 @@ package com.songoda.ultimatestacker.stackable.entity;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.nbt.NBTEntity;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.stackable.Stackable;
import com.songoda.ultimatestacker.utils.Stackable;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@ -97,6 +97,11 @@ public class ColdEntityStack implements Stackable {
return stackedEntities.size() + 1;
}
@Override
public boolean isValid() {
return true;
}
public void createDuplicates(int duplicates) {
this.createDuplicates = duplicates;
}

View File

@ -1,10 +1,11 @@
package com.songoda.ultimatestacker.stackable.spawner;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.settings.Settings;
import com.songoda.ultimatestacker.stackable.Hologramable;
import com.songoda.ultimatestacker.stackable.Stackable;
import com.songoda.ultimatestacker.utils.Stackable;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.Reflection;
import org.bukkit.Bukkit;
@ -34,6 +35,11 @@ public class SpawnerStack implements Stackable, Hologramable {
return amount;
}
@Override
public boolean isValid() {
return CompatibleMaterial.getMaterial(location.getBlock()) == CompatibleMaterial.SPAWNER;
}
public void setAmount(int amount) {
this.amount = amount;
plugin.getDataManager().updateSpawner(this);

View File

@ -0,0 +1,9 @@
package com.songoda.ultimatestacker.utils;
public interface Stackable {
int getAmount();
boolean isValid();
}