2020-08-25 01:01:11 +02:00
|
|
|
package com.songoda.ultimatestacker.stackable.block;
|
|
|
|
|
|
|
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
2021-03-05 15:09:00 +01:00
|
|
|
import com.songoda.core.utils.TextUtils;
|
2020-08-25 01:01:11 +02:00
|
|
|
import com.songoda.ultimatestacker.UltimateStacker;
|
|
|
|
import com.songoda.ultimatestacker.settings.Settings;
|
|
|
|
import com.songoda.ultimatestacker.stackable.Hologramable;
|
2020-09-01 20:13:53 +02:00
|
|
|
import com.songoda.ultimatestacker.utils.Stackable;
|
2020-08-25 01:01:11 +02:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.World;
|
|
|
|
|
2021-12-22 23:11:16 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2020-08-25 01:01:11 +02:00
|
|
|
public class BlockStack implements Stackable, Hologramable {
|
|
|
|
|
2021-12-22 23:11:16 +01:00
|
|
|
// This is the unique identifier for this stack.
|
|
|
|
// It is reset on every plugin load.
|
|
|
|
// Used for holograms.
|
|
|
|
private final UUID uniqueId = UUID.randomUUID();
|
|
|
|
|
2020-08-25 01:01:11 +02:00
|
|
|
// The id that identifies this stack in the database.
|
|
|
|
private int id;
|
|
|
|
|
2023-04-07 18:58:21 +02:00
|
|
|
private int amount = 1;
|
2020-08-25 01:01:11 +02:00
|
|
|
private final CompatibleMaterial material;
|
|
|
|
private final Location location;
|
|
|
|
|
|
|
|
public BlockStack(CompatibleMaterial material, Location location) {
|
|
|
|
this.material = material;
|
|
|
|
this.location = location;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockStack(CompatibleMaterial material, Location location, int amount) {
|
|
|
|
this.amount = amount;
|
|
|
|
this.material = material;
|
|
|
|
this.location = location;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getAmount() {
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
2020-08-26 15:40:51 +02:00
|
|
|
@Override
|
|
|
|
public boolean isValid() {
|
|
|
|
return CompatibleMaterial.getMaterial(location.getBlock()) == material;
|
|
|
|
}
|
|
|
|
|
2020-08-25 01:01:11 +02:00
|
|
|
public void add(int amount) {
|
|
|
|
this.amount = this.amount + amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void take(int amount) {
|
|
|
|
this.amount = this.amount - amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getX() {
|
|
|
|
return location.getBlockX();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getY() {
|
|
|
|
return location.getBlockY();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getZ() {
|
|
|
|
return location.getBlockZ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public World getWorld() {
|
|
|
|
return location.getWorld();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void destroy() {
|
|
|
|
amount = 0;
|
|
|
|
UltimateStacker plugin = UltimateStacker.getInstance();
|
|
|
|
plugin.getBlockStackManager().removeBlock(location);
|
|
|
|
plugin.removeHologram(this);
|
|
|
|
plugin.getDataManager().deleteBlock(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Location getLocation() {
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CompatibleMaterial getMaterial() {
|
|
|
|
return material;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHologramName() {
|
|
|
|
String nameFormat = Settings.NAME_FORMAT_BLOCK.getString();
|
2021-03-05 15:09:00 +01:00
|
|
|
String displayName = TextUtils.formatText(material.name().toLowerCase().replace("_", " "), true);
|
2020-08-25 01:01:11 +02:00
|
|
|
|
|
|
|
nameFormat = nameFormat.replace("{TYPE}", displayName);
|
|
|
|
nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount));
|
|
|
|
|
2021-03-05 15:09:00 +01:00
|
|
|
return TextUtils.formatText(nameFormat).trim();
|
2020-08-25 01:01:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areHologramsEnabled() {
|
|
|
|
return Settings.BLOCK_HOLOGRAMS.getBoolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setId(int id) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
2021-12-22 23:11:16 +01:00
|
|
|
@Override
|
|
|
|
public String getHologramId() {
|
|
|
|
return "UltimateStacker-" + uniqueId;
|
|
|
|
}
|
|
|
|
|
2020-08-25 01:01:11 +02:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "BlockStack{" +
|
|
|
|
"id=" + id +
|
|
|
|
", amount=" + amount +
|
|
|
|
", material=" + material +
|
|
|
|
", location=" + location +
|
|
|
|
'}';
|
|
|
|
}
|
|
|
|
}
|