mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-12-28 11:27:58 +01:00
Added validation for stackables.
This commit is contained in:
parent
b6046820bf
commit
ccd9b68d1f
@ -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
|
||||
|
@ -9,4 +9,6 @@ public interface Hologramable {
|
||||
String getHologramName();
|
||||
|
||||
boolean areHologramsEnabled();
|
||||
|
||||
boolean isValid();
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
package com.songoda.ultimatestacker.stackable;
|
||||
|
||||
|
||||
public interface Stackable {
|
||||
|
||||
int getAmount();
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.songoda.ultimatestacker.utils;
|
||||
|
||||
|
||||
public interface Stackable {
|
||||
|
||||
int getAmount();
|
||||
|
||||
boolean isValid();
|
||||
}
|
Loading…
Reference in New Issue
Block a user