mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-19 07:17:37 +01:00
Initial refactoring on hologram objects
This commit is contained in:
parent
c17de21313
commit
a295243019
@ -10,7 +10,7 @@ import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.internal.BackendAPI;
|
||||
import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.api.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.placeholder.Placeholder;
|
||||
import me.filoghost.holographicdisplays.placeholder.PlaceholdersRegister;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -29,11 +29,11 @@ import me.filoghost.holographicdisplays.listener.UpdateNotificationListener;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.object.APIHologram;
|
||||
import me.filoghost.holographicdisplays.object.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.api.APIHologram;
|
||||
import me.filoghost.holographicdisplays.object.api.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.placeholder.AnimationsRegister;
|
||||
import me.filoghost.holographicdisplays.placeholder.PlaceholdersManager;
|
||||
import me.filoghost.holographicdisplays.task.BungeeCleanupTask;
|
||||
@ -175,7 +175,7 @@ public class HolographicDisplays extends FCommonsPlugin implements PacketControl
|
||||
|
||||
// Then trigger a refresh for all of them
|
||||
for (BaseHologram hologram : internalHologramManager.getHolograms()) {
|
||||
hologram.refreshAll();
|
||||
hologram.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@ import me.filoghost.holographicdisplays.bridge.protocollib.packet.WrapperPlaySer
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.TextLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseTextLine;
|
||||
import me.filoghost.holographicdisplays.placeholder.RelativePlaceholder;
|
||||
import me.filoghost.holographicdisplays.util.NMSVersion;
|
||||
import org.bukkit.World;
|
||||
@ -67,7 +67,7 @@ class PacketListener extends PacketAdapter {
|
||||
// Spawn entity packet
|
||||
if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY_LIVING) {
|
||||
WrapperPlayServerSpawnEntityLiving spawnEntityPacket = new WrapperPlayServerSpawnEntityLiving(packet);
|
||||
HologramLineImpl hologramLine = getHologramLine(event, spawnEntityPacket);
|
||||
BaseHologramLine hologramLine = getHologramLine(event, spawnEntityPacket);
|
||||
|
||||
if (hologramLine == null) {
|
||||
return;
|
||||
@ -83,10 +83,10 @@ class PacketListener extends PacketAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(hologramLine instanceof TextLineImpl)) {
|
||||
if (!(hologramLine instanceof BaseTextLine)) {
|
||||
return;
|
||||
}
|
||||
TextLineImpl textLine = (TextLineImpl) hologramLine;
|
||||
BaseTextLine textLine = (BaseTextLine) hologramLine;
|
||||
|
||||
if (!hologramLine.getParent().isAllowPlaceholders() || !textLine.hasRelativePlaceholders()) {
|
||||
return;
|
||||
@ -104,7 +104,7 @@ class PacketListener extends PacketAdapter {
|
||||
|
||||
} else if (packet.getType() == PacketType.Play.Server.SPAWN_ENTITY) {
|
||||
WrapperPlayServerSpawnEntity spawnEntityPacket = new WrapperPlayServerSpawnEntity(packet);
|
||||
HologramLineImpl hologramLine = getHologramLine(event, spawnEntityPacket);
|
||||
BaseHologramLine hologramLine = getHologramLine(event, spawnEntityPacket);
|
||||
|
||||
if (hologramLine == null) {
|
||||
return;
|
||||
@ -117,7 +117,7 @@ class PacketListener extends PacketAdapter {
|
||||
|
||||
} else if (packet.getType() == PacketType.Play.Server.ENTITY_METADATA) {
|
||||
WrapperPlayServerEntityMetadata entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet);
|
||||
HologramLineImpl hologramLine = getHologramLine(event, entityMetadataPacket);
|
||||
BaseHologramLine hologramLine = getHologramLine(event, entityMetadataPacket);
|
||||
|
||||
if (hologramLine == null) {
|
||||
return;
|
||||
@ -128,10 +128,10 @@ class PacketListener extends PacketAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(hologramLine instanceof TextLineImpl)) {
|
||||
if (!(hologramLine instanceof BaseTextLine)) {
|
||||
return;
|
||||
}
|
||||
TextLineImpl textLine = (TextLineImpl) hologramLine;
|
||||
BaseTextLine textLine = (BaseTextLine) hologramLine;
|
||||
|
||||
if (!hologramLine.getParent().isAllowPlaceholders() || !textLine.hasRelativePlaceholders()) {
|
||||
return;
|
||||
@ -183,11 +183,11 @@ class PacketListener extends PacketAdapter {
|
||||
return true;
|
||||
}
|
||||
|
||||
private HologramLineImpl getHologramLine(PacketEvent packetEvent, EntityRelatedPacketWrapper packetWrapper) {
|
||||
private BaseHologramLine getHologramLine(PacketEvent packetEvent, EntityRelatedPacketWrapper packetWrapper) {
|
||||
return getHologramLine(packetEvent.getPlayer().getWorld(), packetWrapper.getEntityID());
|
||||
}
|
||||
|
||||
private HologramLineImpl getHologramLine(World world, int entityID) {
|
||||
private BaseHologramLine getHologramLine(World world, int entityID) {
|
||||
if (entityID < 0) {
|
||||
return null;
|
||||
}
|
||||
@ -197,7 +197,7 @@ class PacketListener extends PacketAdapter {
|
||||
return null; // Entity not existing or not related to holograms.
|
||||
}
|
||||
|
||||
return (HologramLineImpl) nmsEntity.getHologramLine();
|
||||
return (BaseHologramLine) nmsEntity.getHologramLine();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,12 +18,11 @@ import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.ItemLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.TextLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.TouchSlimeLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.TouchableLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseItemLine;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseTextLine;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseTouchableLine;
|
||||
import me.filoghost.holographicdisplays.object.base.SpawnableHologramLine;
|
||||
import me.filoghost.holographicdisplays.util.NMSVersion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -40,12 +39,8 @@ class PacketSender {
|
||||
|
||||
public void sendDestroyEntitiesPacket(Player player, BaseHologram hologram) {
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
for (HologramLineImpl line : hologram.getLinesUnsafe()) {
|
||||
if (line.isSpawned()) {
|
||||
for (int id : line.getEntitiesIDs()) {
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
for (SpawnableHologramLine line : hologram.getLinesUnsafe()) {
|
||||
line.collectEntityIDs(ids);
|
||||
}
|
||||
|
||||
if (!ids.isEmpty()) {
|
||||
@ -54,45 +49,39 @@ class PacketSender {
|
||||
}
|
||||
|
||||
public void sendCreateEntitiesPacket(Player player, BaseHologram hologram) {
|
||||
for (HologramLineImpl line : hologram.getLinesUnsafe()) {
|
||||
for (SpawnableHologramLine line : hologram.getLinesUnsafe()) {
|
||||
sendCreateEntitiesPacket(player, line);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendCreateEntitiesPacket(Player player, HologramLineImpl line) {
|
||||
if (!line.isSpawned()) {
|
||||
return;
|
||||
}
|
||||
private void sendCreateEntitiesPacket(Player player, SpawnableHologramLine line) {
|
||||
if (line instanceof BaseTextLine) {
|
||||
BaseTextLine textLine = (BaseTextLine) line;
|
||||
|
||||
TouchableLineImpl touchableLine;
|
||||
if (textLine.getNMSNameable() != null) {
|
||||
sendSpawnArmorStandPacket(player, textLine.getNMSNameable());
|
||||
}
|
||||
|
||||
if (line instanceof TextLineImpl) {
|
||||
TextLineImpl textLine = (TextLineImpl) line;
|
||||
touchableLine = textLine;
|
||||
|
||||
sendSpawnArmorStandPacket(player, (NMSArmorStand) textLine.getNmsNameable());
|
||||
|
||||
} else if (line instanceof ItemLineImpl) {
|
||||
ItemLineImpl itemLine = (ItemLineImpl) line;
|
||||
touchableLine = itemLine;
|
||||
|
||||
sendSpawnArmorStandPacket(player, (NMSArmorStand) itemLine.getNmsVehicle());
|
||||
sendSpawnItemPacket(player, itemLine.getNmsItem());
|
||||
sendVehicleAttachPacket(player, itemLine.getNmsVehicle(), itemLine.getNmsItem());
|
||||
sendItemMetadataPacket(player, itemLine.getNmsItem());
|
||||
} else if (line instanceof BaseItemLine) {
|
||||
BaseItemLine itemLine = (BaseItemLine) line;
|
||||
|
||||
if (itemLine.getNMSItem() != null && itemLine.getNMSVehicle() != null) {
|
||||
sendSpawnArmorStandPacket(player, itemLine.getNMSVehicle());
|
||||
sendSpawnItemPacket(player, itemLine.getNMSItem());
|
||||
sendVehicleAttachPacket(player, itemLine.getNMSVehicle(), itemLine.getNMSItem());
|
||||
sendItemMetadataPacket(player, itemLine.getNMSItem());
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected hologram line type: " + line.getClass().getName());
|
||||
}
|
||||
|
||||
if (touchableLine.getTouchSlime() != null) {
|
||||
TouchSlimeLineImpl touchSlime = touchableLine.getTouchSlime();
|
||||
// All sub-types of lines are touchable, no need to check instance type
|
||||
BaseTouchableLine touchableLine = (BaseTouchableLine) line;
|
||||
|
||||
if (touchSlime.isSpawned()) {
|
||||
sendSpawnArmorStandPacket(player, (NMSArmorStand) touchSlime.getNmsVehicle());
|
||||
sendSpawnSlimePacket(player, touchSlime.getNmsSlime());
|
||||
sendVehicleAttachPacket(player, touchSlime.getNmsVehicle(), touchSlime.getNmsSlime());
|
||||
}
|
||||
if (touchableLine.getNMSSlime() != null && touchableLine.getNMSVehicle() != null) {
|
||||
sendSpawnArmorStandPacket(player, touchableLine.getNMSVehicle());
|
||||
sendSpawnSlimePacket(player, touchableLine.getNMSSlime());
|
||||
sendVehicleAttachPacket(player, touchableLine.getNMSVehicle(), touchableLine.getNMSSlime());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ package me.filoghost.holographicdisplays.bridge.protocollib;
|
||||
import com.google.common.base.Preconditions;
|
||||
import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.util.VersionUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -35,8 +35,8 @@ import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
@ -10,9 +10,9 @@ import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.HologramLineParser;
|
||||
import me.filoghost.holographicdisplays.disk.HologramLoadException;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.util.FileUtils;
|
||||
|
||||
import java.nio.file.Files;
|
||||
@ -20,7 +20,7 @@ import java.nio.file.Path;
|
||||
|
||||
public class HologramCommandValidate {
|
||||
|
||||
public static HologramLineImpl parseHologramLine(InternalHologram hologram, String serializedLine, boolean validateMaterial) throws CommandException {
|
||||
public static InternalHologramLine parseHologramLine(InternalHologram hologram, String serializedLine, boolean validateMaterial) throws CommandException {
|
||||
try {
|
||||
return HologramLineParser.parseLine(hologram, serializedLine, validateMaterial);
|
||||
} catch (HologramLoadException e) {
|
||||
|
@ -13,9 +13,9 @@ import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -41,9 +41,9 @@ public class AddlineCommand extends LineEditingCommand implements QuickEditComma
|
||||
InternalHologram hologram = HologramCommandValidate.getNamedHologram(internalHologramManager, args[0]);
|
||||
String serializedLine = Utils.join(args, " ", 1, args.length);
|
||||
|
||||
HologramLineImpl line = HologramCommandValidate.parseHologramLine(hologram, serializedLine, true);
|
||||
InternalHologramLine line = HologramCommandValidate.parseHologramLine(hologram, serializedLine, true);
|
||||
hologram.getLinesUnsafe().add(line);
|
||||
hologram.refreshAll();
|
||||
hologram.refresh();
|
||||
|
||||
configManager.getHologramDatabase().addOrUpdate(hologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
@ -12,8 +12,8 @@ import me.filoghost.holographicdisplays.Colors;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -55,9 +55,7 @@ public class AlignCommand extends HologramSubCommand {
|
||||
throw new CommandException("You must specify either X, Y, Z or XZ, " + axis + " is not a valid axis.");
|
||||
}
|
||||
|
||||
hologram.teleport(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ());
|
||||
hologram.despawnEntities();
|
||||
hologram.refreshAll();
|
||||
hologram.teleport(loc);
|
||||
|
||||
configManager.getHologramDatabase().addOrUpdate(hologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
@ -11,9 +11,9 @@ import me.filoghost.holographicdisplays.Colors;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CopyCommand extends HologramSubCommand {
|
||||
@ -37,12 +37,12 @@ public class CopyCommand extends HologramSubCommand {
|
||||
InternalHologram toHologram = HologramCommandValidate.getNamedHologram(internalHologramManager, args[1]);
|
||||
|
||||
toHologram.clearLines();
|
||||
for (HologramLineImpl line : fromHologram.getLinesUnsafe()) {
|
||||
HologramLineImpl clonedLine = HologramCommandValidate.parseHologramLine(toHologram, line.getSerializedConfigValue(), false);
|
||||
for (InternalHologramLine line : fromHologram.getLinesUnsafe()) {
|
||||
InternalHologramLine clonedLine = HologramCommandValidate.parseHologramLine(toHologram, line.getSerializedConfigValue(), false);
|
||||
toHologram.getLinesUnsafe().add(clonedLine);
|
||||
}
|
||||
|
||||
toHologram.refreshAll();
|
||||
toHologram.refresh();
|
||||
|
||||
configManager.getHologramDatabase().addOrUpdate(toHologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
@ -13,9 +13,9 @@ import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -63,14 +63,14 @@ public class CreateCommand extends HologramSubCommand {
|
||||
String text = Utils.join(args, " ", 1, args.length);
|
||||
CommandValidate.check(!text.equalsIgnoreCase("{empty}"), "The first line should not be empty.");
|
||||
|
||||
HologramLineImpl line = HologramCommandValidate.parseHologramLine(hologram, text, true);
|
||||
InternalHologramLine line = HologramCommandValidate.parseHologramLine(hologram, text, true);
|
||||
hologram.getLinesUnsafe().add(line);
|
||||
player.sendMessage(Colors.SECONDARY_SHADOW + "(Change the lines with /" + context.getRootLabel() + " edit " + hologram.getName() + ")");
|
||||
} else {
|
||||
hologram.appendTextLine("Default hologram. Change it with " + Colors.PRIMARY + "/" + context.getRootLabel() + " edit " + hologram.getName());
|
||||
}
|
||||
|
||||
hologram.refreshAll();
|
||||
hologram.refresh();
|
||||
|
||||
configManager.getHologramDatabase().addOrUpdate(hologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
@ -11,8 +11,8 @@ import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.object.APIHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.api.APIHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
|
@ -11,8 +11,8 @@ import me.filoghost.holographicdisplays.Colors;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class DeleteCommand extends HologramSubCommand {
|
||||
@ -34,7 +34,7 @@ public class DeleteCommand extends HologramSubCommand {
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
InternalHologram hologram = HologramCommandValidate.getNamedHologram(internalHologramManager, args[0]);
|
||||
|
||||
hologram.delete();
|
||||
internalHologramManager.deleteHologram(hologram);
|
||||
|
||||
configManager.getHologramDatabase().removeHologram(hologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
@ -12,8 +12,8 @@ import me.filoghost.holographicdisplays.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.commands.Messages;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
@ -11,9 +11,9 @@ import me.filoghost.holographicdisplays.Colors;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.commands.Messages;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class InfoCommand extends LineEditingCommand implements QuickEditCommand {
|
||||
@ -39,7 +39,7 @@ public class InfoCommand extends LineEditingCommand implements QuickEditCommand
|
||||
Messages.sendTitle(sender, "Lines of the hologram '" + hologram.getName() + "'");
|
||||
int index = 0;
|
||||
|
||||
for (HologramLineImpl line : hologram.getLinesUnsafe()) {
|
||||
for (InternalHologramLine line : hologram.getLinesUnsafe()) {
|
||||
sender.sendMessage(Colors.SECONDARY + Colors.BOLD + (++index) + Colors.SECONDARY_SHADOW + ". " + Colors.SECONDARY + line.getSerializedConfigValue());
|
||||
}
|
||||
commandManager.sendQuickEditCommands(context, hologram);
|
||||
|
@ -15,9 +15,9 @@ import me.filoghost.holographicdisplays.commands.Messages;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -51,9 +51,9 @@ public class InsertlineCommand extends LineEditingCommand implements QuickEditCo
|
||||
|
||||
CommandValidate.check(insertAfter >= 0 && insertAfter <= oldLinesAmount, "The number must be between 0 and " + hologram.size() + "(amount of lines of the hologram).");
|
||||
|
||||
HologramLineImpl line = HologramCommandValidate.parseHologramLine(hologram, serializedLine, true);
|
||||
InternalHologramLine line = HologramCommandValidate.parseHologramLine(hologram, serializedLine, true);
|
||||
hologram.getLinesUnsafe().add(insertAfter, line);
|
||||
hologram.refreshAll();
|
||||
hologram.refresh();
|
||||
|
||||
configManager.getHologramDatabase().addOrUpdate(hologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
@ -11,8 +11,8 @@ import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||
import me.filoghost.holographicdisplays.Colors;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.commands.Messages;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -12,8 +12,8 @@ import me.filoghost.holographicdisplays.Colors;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -39,9 +39,7 @@ public class MovehereCommand extends HologramSubCommand {
|
||||
Player player = CommandValidate.getPlayerSender(sender);
|
||||
InternalHologram hologram = HologramCommandValidate.getNamedHologram(internalHologramManager, args[0]);
|
||||
|
||||
hologram.teleport(player.getWorld(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
|
||||
hologram.despawnEntities();
|
||||
hologram.refreshAll();
|
||||
hologram.teleport(player.getLocation());
|
||||
|
||||
configManager.getHologramDatabase().addOrUpdate(hologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
@ -11,8 +11,8 @@ import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||
import me.filoghost.holographicdisplays.Colors;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.commands.Messages;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -44,7 +44,7 @@ public class NearCommand extends HologramSubCommand {
|
||||
List<InternalHologram> nearHolograms = new ArrayList<>();
|
||||
|
||||
for (InternalHologram hologram : internalHologramManager.getHolograms()) {
|
||||
if (hologram.getLocation().getWorld().equals(world) && hologram.getLocation().distanceSquared(player.getLocation()) <= radiusSquared) {
|
||||
if (hologram.getWorld().equals(world) && hologram.getLocation().distanceSquared(player.getLocation()) <= radiusSquared) {
|
||||
nearHolograms.add(hologram);
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ import me.filoghost.holographicdisplays.image.ImageMessage;
|
||||
import me.filoghost.holographicdisplays.image.ImageReadException;
|
||||
import me.filoghost.holographicdisplays.image.ImageReader;
|
||||
import me.filoghost.holographicdisplays.image.ImageTooWideException;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.TextLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalTextLine;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -114,11 +114,10 @@ public class ReadimageCommand extends LineEditingCommand {
|
||||
hologram.clearLines();
|
||||
}
|
||||
for (String newLine : newLines) {
|
||||
TextLineImpl line = new TextLineImpl(hologram, newLine);
|
||||
line.setSerializedConfigValue(newLine);
|
||||
InternalTextLine line = new InternalTextLine(hologram, newLine, newLine);
|
||||
hologram.getLinesUnsafe().add(line);
|
||||
}
|
||||
hologram.refreshAll();
|
||||
hologram.refresh();
|
||||
|
||||
if (newLines.length < 5) {
|
||||
Messages.sendTip(sender, "The image has a very low height. You can increase it by increasing the width, it will scale automatically.");
|
||||
|
@ -15,9 +15,9 @@ import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.disk.HologramLineParser;
|
||||
import me.filoghost.holographicdisplays.disk.HologramLoadException;
|
||||
import me.filoghost.holographicdisplays.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.util.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -73,10 +73,10 @@ public class ReadtextCommand extends LineEditingCommand {
|
||||
linesAmount = 40;
|
||||
}
|
||||
|
||||
List<HologramLineImpl> linesToAdd = new ArrayList<>();
|
||||
List<InternalHologramLine> linesToAdd = new ArrayList<>();
|
||||
for (int i = 0; i < linesAmount; i++) {
|
||||
try {
|
||||
HologramLineImpl line = HologramLineParser.parseLine(hologram, serializedLines.get(i), true);
|
||||
InternalHologramLine line = HologramLineParser.parseLine(hologram, serializedLines.get(i), true);
|
||||
linesToAdd.add(line);
|
||||
} catch (HologramLoadException e) {
|
||||
throw new CommandException("Error at line " + (i + 1) + ": " + e.getMessage());
|
||||
@ -85,7 +85,7 @@ public class ReadtextCommand extends LineEditingCommand {
|
||||
|
||||
hologram.clearLines();
|
||||
hologram.getLinesUnsafe().addAll(linesToAdd);
|
||||
hologram.refreshAll();
|
||||
hologram.refresh();
|
||||
|
||||
configManager.getHologramDatabase().addOrUpdate(hologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
@ -13,8 +13,8 @@ import me.filoghost.holographicdisplays.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -47,7 +47,7 @@ public class RemovelineCommand extends LineEditingCommand implements QuickEditCo
|
||||
CommandValidate.check(hologram.size() > 1, "The hologram should have at least 1 line. If you want to delete it, use /" + context.getRootLabel() + " delete.");
|
||||
|
||||
hologram.removeLine(index);
|
||||
hologram.refreshAll();
|
||||
hologram.refresh();
|
||||
|
||||
configManager.getHologramDatabase().addOrUpdate(hologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
@ -14,9 +14,9 @@ import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -46,11 +46,11 @@ public class SetlineCommand extends LineEditingCommand implements QuickEditComma
|
||||
CommandValidate.check(lineNumber >= 1 && lineNumber <= hologram.size(), "The line number must be between 1 and " + hologram.size() + ".");
|
||||
int index = lineNumber - 1;
|
||||
|
||||
HologramLineImpl line = HologramCommandValidate.parseHologramLine(hologram, serializedLine, true);
|
||||
InternalHologramLine line = HologramCommandValidate.parseHologramLine(hologram, serializedLine, true);
|
||||
|
||||
hologram.getLinesUnsafe().get(index).despawn();
|
||||
hologram.getLinesUnsafe().set(index, line);
|
||||
hologram.refreshAll();
|
||||
InternalHologramLine prevLine = hologram.getLinesUnsafe().set(index, line);
|
||||
prevLine.despawn();
|
||||
hologram.refresh();
|
||||
|
||||
configManager.getHologramDatabase().addOrUpdate(hologram);
|
||||
configManager.saveHologramDatabase();
|
||||
|
@ -11,8 +11,8 @@ import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||
import me.filoghost.holographicdisplays.Colors;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -7,9 +7,9 @@ package me.filoghost.holographicdisplays.disk;
|
||||
|
||||
import me.filoghost.fcommons.Strings;
|
||||
import me.filoghost.fcommons.config.ConfigSection;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -38,7 +38,7 @@ public class HologramConfig {
|
||||
public HologramConfig(InternalHologram hologram) {
|
||||
this.name = hologram.getName();
|
||||
this.serializedLines = new ArrayList<>();
|
||||
for (HologramLineImpl line : hologram.getLinesUnsafe()) {
|
||||
for (InternalHologramLine line : hologram.getLinesUnsafe()) {
|
||||
serializedLines.add(line.getSerializedConfigValue());
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ public class HologramConfig {
|
||||
|
||||
for (String serializedLine : serializedLines) {
|
||||
try {
|
||||
HologramLineImpl line = HologramLineParser.parseLine(hologram, serializedLine, false);
|
||||
InternalHologramLine line = HologramLineParser.parseLine(hologram, serializedLine, false);
|
||||
hologram.getLinesUnsafe().add(line);
|
||||
} catch (HologramLoadException e) {
|
||||
// Rethrow with more details
|
||||
|
@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.disk;
|
||||
|
||||
import me.filoghost.fcommons.config.Config;
|
||||
import me.filoghost.fcommons.config.ConfigSection;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
|
@ -9,10 +9,10 @@ import me.filoghost.fcommons.MaterialsHelper;
|
||||
import me.filoghost.fcommons.Strings;
|
||||
import me.filoghost.holographicdisplays.nbt.parser.MojangsonParseException;
|
||||
import me.filoghost.holographicdisplays.nbt.parser.MojangsonParser;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.ItemLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.TextLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalItemLine;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalTextLine;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -21,23 +21,22 @@ public class HologramLineParser {
|
||||
|
||||
private static final String ICON_PREFIX = "icon:";
|
||||
|
||||
public static HologramLineImpl parseLine(InternalHologram hologram, String serializedLine, boolean checkMaterialValidity) throws HologramLoadException {
|
||||
HologramLineImpl hologramLine;
|
||||
public static InternalHologramLine parseLine(InternalHologram hologram, String serializedLine, boolean checkMaterialValidity) throws HologramLoadException {
|
||||
InternalHologramLine hologramLine;
|
||||
|
||||
if (serializedLine.toLowerCase().startsWith(ICON_PREFIX)) {
|
||||
String serializedIcon = serializedLine.substring(ICON_PREFIX.length());
|
||||
ItemStack icon = parseItemStack(serializedIcon, checkMaterialValidity);
|
||||
hologramLine = new ItemLineImpl(hologram, icon);
|
||||
hologramLine = new InternalItemLine(hologram, icon, serializedLine);
|
||||
|
||||
} else {
|
||||
if (serializedLine.trim().equalsIgnoreCase("{empty}")) {
|
||||
hologramLine = new TextLineImpl(hologram, "");
|
||||
hologramLine = new InternalTextLine(hologram, "", serializedLine);
|
||||
} else {
|
||||
hologramLine = new TextLineImpl(hologram, StringConverter.toReadableFormat(serializedLine));
|
||||
hologramLine = new InternalTextLine(hologram, StringConverter.toReadableFormat(serializedLine), serializedLine);
|
||||
}
|
||||
}
|
||||
|
||||
hologramLine.setSerializedConfigValue(serializedLine);
|
||||
return hologramLine;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.event;
|
||||
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
@ -2,9 +2,9 @@ package me.filoghost.holographicdisplays.listener;
|
||||
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.object.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.api.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.util.SchedulerUtils;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -9,8 +9,8 @@ import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.object.APIHologram;
|
||||
import me.filoghost.holographicdisplays.object.line.TouchSlimeLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.api.APIHologram;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseTouchableLine;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -46,12 +46,12 @@ public class MainListener implements Listener {
|
||||
}
|
||||
|
||||
NMSEntityBase entityBase = nmsManager.getNMSEntityBase(event.getRightClicked());
|
||||
if (entityBase == null || !(entityBase.getHologramLine() instanceof TouchSlimeLineImpl)) {
|
||||
if (entityBase == null || !(entityBase.getHologramLine() instanceof BaseTouchableLine)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TouchSlimeLineImpl touchSlime = (TouchSlimeLineImpl) entityBase.getHologramLine();
|
||||
if (touchSlime.getTouchablePiece().getTouchHandler() == null || !touchSlime.getParent().getVisibilityManager().isVisibleTo(clicker)) {
|
||||
BaseTouchableLine touchableLine = (BaseTouchableLine) entityBase.getHologramLine();
|
||||
if (touchableLine.getTouchHandler() == null || !touchableLine.getParent().getVisibilityManager().isVisibleTo(clicker)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -63,9 +63,9 @@ public class MainListener implements Listener {
|
||||
anticlickSpam.put(event.getPlayer(), System.currentTimeMillis());
|
||||
|
||||
try {
|
||||
touchSlime.getTouchablePiece().getTouchHandler().onTouch(event.getPlayer());
|
||||
touchableLine.getTouchHandler().onTouch(event.getPlayer());
|
||||
} catch (Throwable t) {
|
||||
Plugin plugin = touchSlime.getParent() instanceof APIHologram ? ((APIHologram) touchSlime.getParent()).getOwner() : HolographicDisplays.getInstance();
|
||||
Plugin plugin = touchableLine.getParent() instanceof APIHologram ? ((APIHologram) touchableLine.getParent()).getOwner() : HolographicDisplays.getInstance();
|
||||
Log.warning("The plugin " + plugin.getName() + " generated an exception when the player " + event.getPlayer().getName() + " touched a hologram.", t);
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class APIHologram extends BaseHologram {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final APIHologramManager apiHologramManager;
|
||||
|
||||
protected APIHologram(Location source, Plugin plugin, NMSManager nmsManager, APIHologramManager apiHologramManager) {
|
||||
super(source, nmsManager);
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
this.plugin = plugin;
|
||||
this.apiHologramManager = apiHologramManager;
|
||||
}
|
||||
|
||||
public Plugin getOwner() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
apiHologramManager.deleteHologram(this);
|
||||
}
|
||||
|
||||
}
|
@ -1,354 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.VisibilityManager;
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import me.filoghost.holographicdisplays.api.line.TextLine;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.line.HologramLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.ItemLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.line.TextLineImpl;
|
||||
import me.filoghost.holographicdisplays.placeholder.PlaceholdersManager;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseHologram implements Hologram {
|
||||
|
||||
private final NMSManager nmsManager;
|
||||
|
||||
// Position variables.
|
||||
private World world;
|
||||
private double x, y, z;
|
||||
private int chunkX, chunkZ;
|
||||
|
||||
// The entities that represent lines.
|
||||
private final List<HologramLineImpl> lines;
|
||||
|
||||
private final VisibilityManager visibilityManager;
|
||||
private boolean allowPlaceholders;
|
||||
private final long creationTimestamp;
|
||||
private boolean deleted;
|
||||
|
||||
public BaseHologram(Location location, NMSManager nmsManager) {
|
||||
Preconditions.notNull(location, "location");
|
||||
setLocation(location.getWorld(), location.getX(), location.getY(), location.getZ());
|
||||
|
||||
this.nmsManager = nmsManager;
|
||||
this.lines = new ArrayList<>();
|
||||
this.creationTimestamp = System.currentTimeMillis();
|
||||
this.visibilityManager = new VisibilityManagerImpl(this);
|
||||
|
||||
this.allowPlaceholders = false;
|
||||
}
|
||||
|
||||
public boolean isInChunk(Chunk chunk) {
|
||||
return chunk.getWorld() == world && chunk.getX() == chunkX && chunk.getZ() == chunkZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
private void setLocation(World world, double x, double y, double z) {
|
||||
Preconditions.notNull(world, "world");
|
||||
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
chunkX = Utils.floor(x) >> 4;
|
||||
chunkZ = Utils.floor(z) >> 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted() {
|
||||
if (!deleted) {
|
||||
deleted = true;
|
||||
clearLines();
|
||||
}
|
||||
}
|
||||
|
||||
public List<HologramLineImpl> getLinesUnsafe() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HologramLine getLine(int index) {
|
||||
return lines.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextLine appendTextLine(String text) {
|
||||
checkState();
|
||||
|
||||
TextLineImpl line = new TextLineImpl(this, text);
|
||||
lines.add(line);
|
||||
refreshSingleLines();
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLine appendItemLine(ItemStack itemStack) {
|
||||
checkState();
|
||||
Preconditions.notNull(itemStack, "itemStack");
|
||||
|
||||
ItemLineImpl line = new ItemLineImpl(this, itemStack);
|
||||
lines.add(line);
|
||||
refreshSingleLines();
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextLine insertTextLine(int index, String text) {
|
||||
checkState();
|
||||
|
||||
TextLineImpl line = new TextLineImpl(this, text);
|
||||
lines.add(index, line);
|
||||
refreshSingleLines();
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLine insertItemLine(int index, ItemStack itemStack) {
|
||||
checkState();
|
||||
Preconditions.notNull(itemStack, "itemStack");
|
||||
|
||||
ItemLineImpl line = new ItemLineImpl(this, itemStack);
|
||||
lines.add(index, line);
|
||||
refreshSingleLines();
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLine(int index) {
|
||||
checkState();
|
||||
|
||||
lines.remove(index).despawn();
|
||||
refreshSingleLines();
|
||||
}
|
||||
|
||||
public void removeLine(HologramLineImpl line) {
|
||||
checkState();
|
||||
|
||||
lines.remove(line);
|
||||
line.despawn();
|
||||
refreshSingleLines();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearLines() {
|
||||
for (HologramLineImpl line : lines) {
|
||||
line.despawn();
|
||||
}
|
||||
|
||||
lines.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return lines.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
if (lines.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double height = 0.0;
|
||||
|
||||
for (HologramLineImpl line : lines) {
|
||||
height += line.getHeight();
|
||||
}
|
||||
|
||||
height += Configuration.spaceBetweenLines * (lines.size() - 1);
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityManager getVisibilityManager() {
|
||||
return visibilityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCreationTimestamp() {
|
||||
return creationTimestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowPlaceholders() {
|
||||
return allowPlaceholders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowPlaceholders(boolean allowPlaceholders) {
|
||||
if (this.allowPlaceholders == allowPlaceholders) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.allowPlaceholders = allowPlaceholders;
|
||||
refreshAll();
|
||||
}
|
||||
|
||||
public NMSManager getNMSManager() {
|
||||
return nmsManager;
|
||||
}
|
||||
|
||||
public void refreshAll() {
|
||||
if (world.isChunkLoaded(chunkX, chunkZ)) {
|
||||
spawnEntities();
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshSingleLines() {
|
||||
if (world.isChunkLoaded(chunkX, chunkZ)) {
|
||||
double currentY = this.y;
|
||||
boolean first = true;
|
||||
|
||||
for (HologramLineImpl line : lines) {
|
||||
currentY -= line.getHeight();
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
currentY -= Configuration.spaceBetweenLines;
|
||||
}
|
||||
|
||||
if (line.isSpawned()) {
|
||||
line.teleport(x, currentY, z);
|
||||
} else {
|
||||
line.spawn(world, x, currentY, z);
|
||||
if (allowPlaceholders && line instanceof TextLineImpl) {
|
||||
PlaceholdersManager.trackIfNecessary((TextLineImpl) line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the entities to (re)spawn, without checking if the chunk is loaded.
|
||||
*/
|
||||
public void spawnEntities() {
|
||||
checkState();
|
||||
|
||||
despawnEntities();
|
||||
|
||||
double currentY = this.y;
|
||||
boolean first = true;
|
||||
|
||||
for (HologramLineImpl line : lines) {
|
||||
currentY -= line.getHeight();
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
currentY -= Configuration.spaceBetweenLines;
|
||||
}
|
||||
|
||||
line.spawn(world, x, currentY, z);
|
||||
if (allowPlaceholders && line instanceof TextLineImpl) {
|
||||
PlaceholdersManager.trackIfNecessary((TextLineImpl) line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void despawnEntities() {
|
||||
for (HologramLineImpl piece : lines) {
|
||||
piece.despawn();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(Location location) {
|
||||
Preconditions.notNull(location, "location");
|
||||
teleport(location.getWorld(), location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(World world, double x, double y, double z) {
|
||||
checkState();
|
||||
Preconditions.notNull(world, "world");
|
||||
|
||||
setLocation(world, x, y, z);
|
||||
|
||||
if (this.world != world) {
|
||||
despawnEntities();
|
||||
refreshAll();
|
||||
return;
|
||||
}
|
||||
|
||||
double currentY = y;
|
||||
boolean first = true;
|
||||
|
||||
for (HologramLineImpl line : lines) {
|
||||
if (!line.isSpawned()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
currentY -= line.getHeight();
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
currentY -= Configuration.spaceBetweenLines;
|
||||
}
|
||||
|
||||
line.teleport(x, currentY, z);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkState() {
|
||||
Preconditions.checkState(!deleted, "hologram already deleted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BaseHologram [world=" + world + ", x=" + x + ", y=" + y + ", z=" + z + ", lines=" + lines + ", deleted=" + deleted + "]";
|
||||
}
|
||||
|
||||
/*
|
||||
* Object.equals() and Object.hashCode() are not overridden:
|
||||
* two holograms are equal only if they are the same exact instance.
|
||||
*/
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
public abstract class HologramComponent {
|
||||
|
||||
private World world;
|
||||
private double x, y, z;
|
||||
private int chunkX, chunkZ;
|
||||
|
||||
public boolean isInChunk(Chunk chunk) {
|
||||
return world != null
|
||||
&& chunk.getWorld() == world
|
||||
&& chunk.getX() == chunkX
|
||||
&& chunk.getZ() == chunkZ;
|
||||
}
|
||||
|
||||
public boolean isInLoadedChunk() {
|
||||
return world.isChunkLoaded(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
protected void setLocation(Location location) {
|
||||
setLocation(location.getWorld(), location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
protected void setLocation(World world, double x, double y, double z) {
|
||||
Preconditions.notNull(world, "world");
|
||||
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.chunkX = Utils.floor(x) >> 4;
|
||||
this.chunkZ = Utils.floor(z) >> 4;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object;
|
||||
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class InternalHologram extends BaseHologram {
|
||||
|
||||
private final String name;
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
|
||||
protected InternalHologram(Location source, String name, NMSManager nmsManager, InternalHologramManager internalHologramManager) {
|
||||
super(source, nmsManager);
|
||||
this.name = name;
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
setAllowPlaceholders(true);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
internalHologramManager.deleteHologram(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InternalHologram [name=" + name + ", super=" + super.toString() + "]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.api;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import me.filoghost.holographicdisplays.api.line.TextLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologramLine;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseItemLine;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseTextLine;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class APIHologram extends BaseHologram implements Hologram {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final APIHologramManager apiHologramManager;
|
||||
private final List<BaseHologramLine> lines;
|
||||
|
||||
protected APIHologram(Location source, Plugin plugin, NMSManager nmsManager, APIHologramManager apiHologramManager) {
|
||||
super(source, nmsManager);
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
this.plugin = plugin;
|
||||
this.apiHologramManager = apiHologramManager;
|
||||
this.lines = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
||||
public Plugin getOwner() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BaseHologramLine> getLinesUnsafe() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextLine appendTextLine(String text) {
|
||||
checkState();
|
||||
|
||||
BaseTextLine line = new BaseTextLine(this, text);
|
||||
lines.add(line);
|
||||
refresh();
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLine appendItemLine(ItemStack itemStack) {
|
||||
checkState();
|
||||
Preconditions.notNull(itemStack, "itemStack");
|
||||
|
||||
BaseItemLine line = new BaseItemLine(this, itemStack);
|
||||
lines.add(line);
|
||||
refresh();
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextLine insertTextLine(int index, String text) {
|
||||
checkState();
|
||||
|
||||
BaseTextLine line = new BaseTextLine(this, text);
|
||||
lines.add(index, line);
|
||||
refresh();
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLine insertItemLine(int index, ItemStack itemStack) {
|
||||
checkState();
|
||||
Preconditions.notNull(itemStack, "itemStack");
|
||||
|
||||
BaseItemLine line = new BaseItemLine(this, itemStack);
|
||||
lines.add(index, line);
|
||||
refresh();
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
apiHologramManager.deleteHologram(this);
|
||||
}
|
||||
|
||||
}
|
@ -3,18 +3,20 @@
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object;
|
||||
package me.filoghost.holographicdisplays.object.api;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologramManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class APIHologramManager extends HologramManager<APIHologram> {
|
||||
public class APIHologramManager extends BaseHologramManager<APIHologram> {
|
||||
|
||||
private final NMSManager nmsManager;
|
||||
|
||||
@ -28,8 +30,8 @@ public class APIHologramManager extends HologramManager<APIHologram> {
|
||||
return hologram;
|
||||
}
|
||||
|
||||
public Set<Hologram> getHologramsByPlugin(Plugin plugin) {
|
||||
Set<Hologram> ownedHolograms = new HashSet<>();
|
||||
public Collection<Hologram> getHologramsByPlugin(Plugin plugin) {
|
||||
List<Hologram> ownedHolograms = new LinkedList<>();
|
||||
|
||||
for (APIHologram hologram : getHolograms()) {
|
||||
if (hologram.getOwner().equals(plugin)) {
|
||||
@ -37,7 +39,7 @@ public class APIHologramManager extends HologramManager<APIHologram> {
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.unmodifiableSet(ownedHolograms);
|
||||
return Collections.unmodifiableList(ownedHolograms);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.base;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.VisibilityManager;
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.HologramComponent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseHologram extends HologramComponent implements Hologram {
|
||||
|
||||
private final NMSManager nmsManager;
|
||||
private final VisibilityManager visibilityManager;
|
||||
private final long creationTimestamp;
|
||||
|
||||
private boolean allowPlaceholders;
|
||||
private boolean deleted;
|
||||
|
||||
public BaseHologram(Location location, NMSManager nmsManager) {
|
||||
Preconditions.notNull(location, "location");
|
||||
this.setLocation(location);
|
||||
this.nmsManager = nmsManager;
|
||||
this.visibilityManager = new DefaultVisibilityManager(this);
|
||||
this.creationTimestamp = System.currentTimeMillis();
|
||||
this.allowPlaceholders = false;
|
||||
}
|
||||
|
||||
public abstract List<? extends SpawnableHologramLine> getLinesUnsafe();
|
||||
|
||||
@Override
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted() {
|
||||
if (!deleted) {
|
||||
deleted = true;
|
||||
clearLines();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCreationTimestamp() {
|
||||
return creationTimestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowPlaceholders(boolean allowPlaceholders) {
|
||||
if (this.allowPlaceholders == allowPlaceholders) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.allowPlaceholders = allowPlaceholders;
|
||||
refresh(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowPlaceholders() {
|
||||
return allowPlaceholders;
|
||||
}
|
||||
|
||||
public NMSManager getNMSManager() {
|
||||
return nmsManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HologramLine getLine(int index) {
|
||||
return getLinesUnsafe().get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLine(int index) {
|
||||
checkState();
|
||||
|
||||
getLinesUnsafe().remove(index).despawn();
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void removeLine(SpawnableHologramLine line) {
|
||||
checkState();
|
||||
|
||||
getLinesUnsafe().remove(line);
|
||||
line.despawn();
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearLines() {
|
||||
for (SpawnableHologramLine line : getLinesUnsafe()) {
|
||||
line.despawn();
|
||||
}
|
||||
|
||||
getLinesUnsafe().clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return getLinesUnsafe().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(Location location) {
|
||||
Preconditions.notNull(location, "location");
|
||||
teleport(location.getWorld(), location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(World world, double x, double y, double z) {
|
||||
checkState();
|
||||
Preconditions.notNull(world, "world");
|
||||
|
||||
setLocation(world, x, y, z);
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
refresh(false);
|
||||
}
|
||||
|
||||
public void refresh(boolean forceRespawn) {
|
||||
refresh(forceRespawn, isInLoadedChunk());
|
||||
}
|
||||
|
||||
public void refresh(boolean forceRespawn, boolean isChunkLoaded) {
|
||||
checkState();
|
||||
|
||||
if (isChunkLoaded) {
|
||||
respawnEntities(forceRespawn);
|
||||
} else {
|
||||
despawnEntities();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
if (getLinesUnsafe().isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double height = 0.0;
|
||||
|
||||
for (SpawnableHologramLine line : getLinesUnsafe()) {
|
||||
height += line.getHeight();
|
||||
}
|
||||
|
||||
height += Configuration.spaceBetweenLines * (getLinesUnsafe().size() - 1);
|
||||
return height;
|
||||
}
|
||||
|
||||
/*
|
||||
* When spawning at a location, the top part of the first line should be exactly on that location.
|
||||
* The second line is below the first, and so on.
|
||||
*/
|
||||
private void respawnEntities(boolean forceRespawn) {
|
||||
double currentLineY = getY();
|
||||
|
||||
for (int i = 0; i < getLinesUnsafe().size(); i++) {
|
||||
SpawnableHologramLine line = getLinesUnsafe().get(i);
|
||||
|
||||
currentLineY -= line.getHeight();
|
||||
if (i > 0) {
|
||||
currentLineY -= Configuration.spaceBetweenLines;
|
||||
}
|
||||
|
||||
if (forceRespawn) {
|
||||
line.despawn();
|
||||
}
|
||||
line.respawn(getWorld(), getX(), currentLineY, getZ());
|
||||
}
|
||||
}
|
||||
|
||||
public void despawnEntities() {
|
||||
for (SpawnableHologramLine line : getLinesUnsafe()) {
|
||||
line.despawn();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityManager getVisibilityManager() {
|
||||
return visibilityManager;
|
||||
}
|
||||
|
||||
protected void checkState() {
|
||||
Preconditions.checkState(!deleted, "hologram already deleted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BaseHologram [location=" + getLocation() + ", lines=" + getLinesUnsafe() + ", deleted=" + deleted + "]";
|
||||
}
|
||||
|
||||
/*
|
||||
* Object.equals() and Object.hashCode() are not overridden:
|
||||
* two holograms are equal only if they are the same exact instance.
|
||||
*/
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.base;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.HologramComponent;
|
||||
import org.bukkit.World;
|
||||
|
||||
public abstract class BaseHologramLine extends HologramComponent implements SpawnableHologramLine {
|
||||
|
||||
private final BaseHologram parent;
|
||||
|
||||
private boolean isSpawned;
|
||||
|
||||
protected BaseHologramLine(BaseHologram parent) {
|
||||
Preconditions.notNull(parent, "parent hologram");
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public final BaseHologram getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
protected final NMSManager getNMSManager() {
|
||||
return parent.getNMSManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void removeLine() {
|
||||
parent.removeLine(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void respawn(World world, double x, double y, double z) {
|
||||
Preconditions.notNull(world, "world");
|
||||
|
||||
boolean changedWorld = world != getWorld();
|
||||
setLocation(world, x, y, z);
|
||||
|
||||
if (changedWorld) {
|
||||
// World has changed, entities must be fully respawned
|
||||
despawnEntities();
|
||||
spawnEntities(world, x, y, z);
|
||||
|
||||
} else if (isSpawned) {
|
||||
// Line is already spawned, respawn can be avoided
|
||||
teleportEntities(x, y, z);
|
||||
|
||||
} else {
|
||||
// Line is not spawned, entities must be spawned
|
||||
spawnEntities(world, x, y, z);
|
||||
}
|
||||
|
||||
isSpawned = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void despawn() {
|
||||
despawnEntities();
|
||||
isSpawned = false;
|
||||
}
|
||||
|
||||
protected boolean isSpawned() {
|
||||
return isSpawned;
|
||||
}
|
||||
|
||||
protected abstract void spawnEntities(World world, double x, double y, double z);
|
||||
|
||||
protected abstract void teleportEntities(double x, double y, double z);
|
||||
|
||||
protected abstract void despawnEntities();
|
||||
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object;
|
||||
package me.filoghost.holographicdisplays.object.base;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import org.bukkit.Chunk;
|
||||
@ -12,7 +12,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HologramManager<H extends BaseHologram> {
|
||||
public class BaseHologramManager<H extends BaseHologram> {
|
||||
|
||||
private final List<H> holograms = new ArrayList<>();
|
||||
private final List<H> unmodifiableHologramsView = Collections.unmodifiableList(holograms);
|
||||
@ -21,7 +21,7 @@ public class HologramManager<H extends BaseHologram> {
|
||||
holograms.add(hologram);
|
||||
}
|
||||
|
||||
protected void deleteHologram(H hologram) {
|
||||
public void deleteHologram(H hologram) {
|
||||
Preconditions.checkArgument(hologram.isDeleted(), "hologram must be deleted first");
|
||||
holograms.remove(hologram);
|
||||
hologram.setDeleted();
|
||||
@ -36,7 +36,7 @@ public class HologramManager<H extends BaseHologram> {
|
||||
holograms.clear();
|
||||
|
||||
for (H hologram : oldHolograms) {
|
||||
hologram.delete();
|
||||
hologram.setDeleted();
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public class HologramManager<H extends BaseHologram> {
|
||||
// Load the holograms in that chunk.
|
||||
for (H hologram : holograms) {
|
||||
if (hologram.isInChunk(chunk)) {
|
||||
hologram.spawnEntities();
|
||||
hologram.refresh(false, true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.base;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.api.handler.PickupHandler;
|
||||
import me.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class BaseItemLine extends BaseTouchableLine implements ItemLine {
|
||||
|
||||
private ItemStack itemStack;
|
||||
private PickupHandler pickupHandler;
|
||||
|
||||
private NMSItem itemEntity;
|
||||
private NMSArmorStand vehicleEntity;
|
||||
|
||||
public BaseItemLine(BaseHologram parent, ItemStack itemStack) {
|
||||
super(parent);
|
||||
setItemStack(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemStack(ItemStack itemStack) {
|
||||
Preconditions.notNull(itemStack, "itemStack");
|
||||
Preconditions.checkArgument(0 < itemStack.getAmount() && itemStack.getAmount() <= 64, "Item must have amount between 1 and 64");
|
||||
this.itemStack = itemStack;
|
||||
|
||||
if (itemEntity != null) {
|
||||
itemEntity.setItemStackNMS(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PickupHandler getPickupHandler() {
|
||||
return pickupHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPickupHandler(PickupHandler pickupHandler) {
|
||||
this.pickupHandler = pickupHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnEntities(World world, double x, double y, double z) {
|
||||
super.spawnEntities(world, x, y, z);
|
||||
|
||||
if (itemStack != null) {
|
||||
itemEntity = getNMSManager().spawnNMSItem(world, x, y + getItemSpawnOffset(), z, this, itemStack);
|
||||
vehicleEntity = getNMSManager().spawnNMSArmorStand(world, x, y + getItemSpawnOffset(), z, this);
|
||||
|
||||
itemEntity.setPassengerOfNMS(vehicleEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportEntities(double x, double y, double z) {
|
||||
super.teleportEntities(x, y, z);
|
||||
|
||||
if (vehicleEntity != null) {
|
||||
vehicleEntity.setLocationNMS(x, y + getItemSpawnOffset(), z);
|
||||
}
|
||||
if (itemEntity != null) {
|
||||
itemEntity.setLocationNMS(x, y + getItemSpawnOffset(), z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void despawnEntities() {
|
||||
super.despawnEntities();
|
||||
|
||||
if (vehicleEntity != null) {
|
||||
vehicleEntity.killEntityNMS();
|
||||
vehicleEntity = null;
|
||||
}
|
||||
|
||||
if (itemEntity != null) {
|
||||
itemEntity.killEntityNMS();
|
||||
itemEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
return 0.7;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectEntityIDs(Collection<Integer> collector) {
|
||||
super.collectEntityIDs(collector);
|
||||
|
||||
if (vehicleEntity != null) {
|
||||
collector.add(vehicleEntity.getIdNMS());
|
||||
}
|
||||
if (itemEntity != null) {
|
||||
collector.add(itemEntity.getIdNMS());
|
||||
}
|
||||
}
|
||||
|
||||
public NMSItem getNMSItem() {
|
||||
return itemEntity;
|
||||
}
|
||||
|
||||
public NMSArmorStand getNMSVehicle() {
|
||||
return vehicleEntity;
|
||||
}
|
||||
|
||||
private double getItemSpawnOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemLine [itemStack=" + itemStack + ", pickupHandler=" + pickupHandler + "]";
|
||||
}
|
||||
|
||||
}
|
@ -3,52 +3,45 @@
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.line;
|
||||
package me.filoghost.holographicdisplays.object.base;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.handler.TouchHandler;
|
||||
import me.filoghost.holographicdisplays.api.line.TextLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSNameable;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.placeholder.PlaceholdersManager;
|
||||
import me.filoghost.holographicdisplays.placeholder.RelativePlaceholder;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class TextLineImpl extends TouchableLineImpl implements TextLine {
|
||||
public class BaseTextLine extends BaseTouchableLine implements TextLine {
|
||||
|
||||
private String text;
|
||||
private List<RelativePlaceholder> relativePlaceholders;
|
||||
private NMSArmorStand nmsNameable;
|
||||
private NMSArmorStand nameableEntity;
|
||||
|
||||
|
||||
public TextLineImpl(BaseHologram parent, String text) {
|
||||
public BaseTextLine(BaseHologram parent, String text) {
|
||||
super(parent);
|
||||
setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
|
||||
if (nmsNameable != null) {
|
||||
if (nameableEntity != null) {
|
||||
if (text != null && !text.isEmpty()) {
|
||||
nmsNameable.setCustomNameNMS(text);
|
||||
nameableEntity.setCustomNameNMS(text);
|
||||
if (getParent().isAllowPlaceholders()) {
|
||||
PlaceholdersManager.trackIfNecessary(this);
|
||||
}
|
||||
} else {
|
||||
nmsNameable.setCustomNameNMS(""); // It will not appear
|
||||
nameableEntity.setCustomNameNMS(""); // It will not appear
|
||||
if (getParent().isAllowPlaceholders()) {
|
||||
PlaceholdersManager.untrack(this);
|
||||
}
|
||||
@ -73,34 +66,36 @@ public class TextLineImpl extends TouchableLineImpl implements TextLine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTouchHandler(TouchHandler touchHandler) {
|
||||
if (nmsNameable != null) {
|
||||
Location loc = nmsNameable.getBukkitEntityNMS().getLocation();
|
||||
super.setTouchHandler(touchHandler, loc.getWorld(), loc.getX(), loc.getY() - getTextOffset(), loc.getZ());
|
||||
} else {
|
||||
super.setTouchHandler(touchHandler, null, 0, 0, 0);
|
||||
public void spawnEntities(World world, double x, double y, double z) {
|
||||
super.spawnEntities(world, x, y, z);
|
||||
|
||||
nameableEntity = getNMSManager().spawnNMSArmorStand(world, x, y + getTextSpawnOffset(), z, this);
|
||||
|
||||
if (text != null && !text.isEmpty()) {
|
||||
nameableEntity.setCustomNameNMS(text);
|
||||
}
|
||||
|
||||
if (getParent().isAllowPlaceholders()) {
|
||||
PlaceholdersManager.trackIfNecessary(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnEntities(World world, double x, double y, double z) {
|
||||
super.spawnEntities(world, x, y, z);
|
||||
public void teleportEntities(double x, double y, double z) {
|
||||
super.teleportEntities(x, y, z);
|
||||
|
||||
nmsNameable = getNMSManager().spawnNMSArmorStand(world, x, y + getTextOffset(), z, this);
|
||||
|
||||
if (text != null && !text.isEmpty()) {
|
||||
nmsNameable.setCustomNameNMS(text);
|
||||
if (nameableEntity != null) {
|
||||
nameableEntity.setLocationNMS(x, y + getTextSpawnOffset(), z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void despawnEntities() {
|
||||
super.despawnEntities();
|
||||
|
||||
if (nmsNameable != null) {
|
||||
nmsNameable.killEntityNMS();
|
||||
nmsNameable = null;
|
||||
if (nameableEntity != null) {
|
||||
nameableEntity.killEntityNMS();
|
||||
nameableEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,33 +113,20 @@ public class TextLineImpl extends TouchableLineImpl implements TextLine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(double x, double y, double z) {
|
||||
super.teleport(x, y, z);
|
||||
public void collectEntityIDs(Collection<Integer> collector) {
|
||||
super.collectEntityIDs(collector);
|
||||
|
||||
if (nmsNameable != null) {
|
||||
nmsNameable.setLocationNMS(x, y + getTextOffset(), z);
|
||||
if (nameableEntity != null) {
|
||||
collector.add(nameableEntity.getIdNMS());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getEntitiesIDs() {
|
||||
if (isSpawned()) {
|
||||
if (touchSlime != null) {
|
||||
return ArrayUtils.add(touchSlime.getEntitiesIDs(), nmsNameable.getIdNMS());
|
||||
} else {
|
||||
return new int[] {nmsNameable.getIdNMS()};
|
||||
}
|
||||
} else {
|
||||
return new int[0];
|
||||
}
|
||||
public NMSArmorStand getNMSNameable() {
|
||||
return nameableEntity;
|
||||
}
|
||||
|
||||
public NMSNameable getNmsNameable() {
|
||||
return nmsNameable;
|
||||
}
|
||||
|
||||
private double getTextOffset() {
|
||||
return Offsets.ARMOR_STAND_ALONE;
|
||||
private double getTextSpawnOffset() {
|
||||
return -0.29;
|
||||
}
|
||||
|
||||
@Override
|
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.base;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.handler.TouchHandler;
|
||||
import me.filoghost.holographicdisplays.api.line.TouchableLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSSlime;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Useful class that implements TouchablePiece. The downside is that subclasses must extend this, and cannot extend other classes.
|
||||
* But all the current items are touchable.
|
||||
*/
|
||||
public abstract class BaseTouchableLine extends BaseHologramLine implements TouchableLine {
|
||||
|
||||
private static final double SLIME_HEIGHT = 0.5;
|
||||
|
||||
private TouchHandler touchHandler;
|
||||
|
||||
private NMSSlime slimeEntity;
|
||||
private NMSArmorStand vehicleEntity;
|
||||
|
||||
protected BaseTouchableLine(BaseHologram parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTouchHandler(TouchHandler touchHandler) {
|
||||
this.touchHandler = touchHandler;
|
||||
|
||||
if (touchHandler != null && slimeEntity == null && super.isSpawned()) {
|
||||
// If the touch handler was null before and no entity has been spawned, spawn it now.
|
||||
spawnSlime(getWorld(), getX(), getY(), getZ());
|
||||
|
||||
} else if (touchHandler == null) {
|
||||
// Opposite case, the touch handler was not null and an entity was spawned, but now it's useless.
|
||||
despawnSlime();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TouchHandler getTouchHandler() {
|
||||
return this.touchHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnEntities(World world, double x, double y, double z) {
|
||||
if (touchHandler != null) {
|
||||
spawnSlime(world, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportEntities(double x, double y, double z) {
|
||||
if (vehicleEntity != null) {
|
||||
vehicleEntity.setLocationNMS(x, getSlimeSpawnY(y), z);
|
||||
}
|
||||
if (slimeEntity != null) {
|
||||
slimeEntity.setLocationNMS(x, getSlimeSpawnY(y), z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void despawnEntities() {
|
||||
despawnSlime();
|
||||
}
|
||||
|
||||
private void spawnSlime(World world, double x, double y, double z) {
|
||||
despawnSlime();
|
||||
|
||||
if (world != null) {
|
||||
slimeEntity = getNMSManager().spawnNMSSlime(world, x, getSlimeSpawnY(y), z, this);
|
||||
vehicleEntity = getNMSManager().spawnNMSArmorStand(world, x, getSlimeSpawnY(y), z, this);
|
||||
|
||||
slimeEntity.setPassengerOfNMS(vehicleEntity);
|
||||
}
|
||||
}
|
||||
|
||||
private void despawnSlime() {
|
||||
if (slimeEntity != null) {
|
||||
slimeEntity.killEntityNMS();
|
||||
slimeEntity = null;
|
||||
}
|
||||
|
||||
if (vehicleEntity != null) {
|
||||
vehicleEntity.killEntityNMS();
|
||||
vehicleEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
private double getSlimeSpawnY(double y) {
|
||||
return y + ((getHeight() - SLIME_HEIGHT) / 2) + getSlimeSpawnOffset();
|
||||
}
|
||||
|
||||
private double getSlimeSpawnOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectEntityIDs(Collection<Integer> collector) {
|
||||
if (vehicleEntity != null) {
|
||||
collector.add(vehicleEntity.getIdNMS());
|
||||
}
|
||||
if (slimeEntity != null) {
|
||||
collector.add(slimeEntity.getIdNMS());
|
||||
}
|
||||
}
|
||||
|
||||
public NMSArmorStand getNMSVehicle() {
|
||||
return vehicleEntity;
|
||||
}
|
||||
|
||||
public NMSSlime getNMSSlime() {
|
||||
return slimeEntity;
|
||||
}
|
||||
|
||||
}
|
@ -3,10 +3,9 @@
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object;
|
||||
package me.filoghost.holographicdisplays.object.base;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.VisibilityManager;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.ProtocolLibHook;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -17,15 +16,15 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class VisibilityManagerImpl implements VisibilityManager {
|
||||
public class DefaultVisibilityManager implements VisibilityManager {
|
||||
|
||||
private static final int VISIBILITY_DISTANCE_SQUARED = 64 * 64;
|
||||
|
||||
private final BaseHologram hologram;
|
||||
private Map<String, Boolean> playersVisibilityMap;
|
||||
private boolean visibleByDefault;
|
||||
|
||||
private static final int VISIBILITY_DISTANCE_SQUARED = 64 * 64;
|
||||
|
||||
public VisibilityManagerImpl(BaseHologram hologram) {
|
||||
public DefaultVisibilityManager(BaseHologram hologram) {
|
||||
Preconditions.notNull(hologram, "hologram");
|
||||
this.hologram = hologram;
|
||||
this.visibleByDefault = true;
|
||||
@ -161,7 +160,7 @@ public class VisibilityManagerImpl implements VisibilityManager {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNear(Player player, Hologram hologram) {
|
||||
private boolean isNear(Player player, BaseHologram hologram) {
|
||||
return player.isOnline()
|
||||
&& player.getWorld().equals(hologram.getWorld())
|
||||
&& player.getLocation().distanceSquared(hologram.getLocation()) < VISIBILITY_DISTANCE_SQUARED;
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.base;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface SpawnableHologramLine extends HologramLine {
|
||||
|
||||
void respawn(World world, double x, double y, double z);
|
||||
|
||||
void despawn();
|
||||
|
||||
double getHeight();
|
||||
|
||||
void collectEntityIDs(Collection<Integer> collector);
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.internal;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import me.filoghost.holographicdisplays.api.line.TextLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologram;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InternalHologram extends BaseHologram {
|
||||
|
||||
private final String name;
|
||||
private final List<InternalHologramLine> lines;
|
||||
|
||||
protected InternalHologram(Location source, String name, NMSManager nmsManager) {
|
||||
super(source, nmsManager);
|
||||
super.setAllowPlaceholders(true);
|
||||
this.name = name;
|
||||
this.lines = new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InternalHologramLine> getLinesUnsafe() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InternalHologram [name=" + name + ", super=" + super.toString() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextLine appendTextLine(String text) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLine appendItemLine(ItemStack itemStack) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextLine insertTextLine(int index, String text) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLine insertItemLine(int index, ItemStack itemStack) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.internal;
|
||||
|
||||
import me.filoghost.holographicdisplays.object.base.SpawnableHologramLine;
|
||||
|
||||
public interface InternalHologramLine extends SpawnableHologramLine {
|
||||
|
||||
String getSerializedConfigValue();
|
||||
|
||||
}
|
@ -3,12 +3,13 @@
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object;
|
||||
package me.filoghost.holographicdisplays.object.internal;
|
||||
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologramManager;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class InternalHologramManager extends HologramManager<InternalHologram> {
|
||||
public class InternalHologramManager extends BaseHologramManager<InternalHologram> {
|
||||
|
||||
private final NMSManager nmsManager;
|
||||
|
||||
@ -17,7 +18,7 @@ public class InternalHologramManager extends HologramManager<InternalHologram> {
|
||||
}
|
||||
|
||||
public InternalHologram createHologram(Location source, String name) {
|
||||
InternalHologram hologram = new InternalHologram(source, name, nmsManager, this);
|
||||
InternalHologram hologram = new InternalHologram(source, name, nmsManager);
|
||||
super.addHologram(hologram);
|
||||
return hologram;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.internal;
|
||||
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseItemLine;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InternalItemLine extends BaseItemLine implements InternalHologramLine {
|
||||
|
||||
private final String serializedConfigValue;
|
||||
|
||||
public InternalItemLine(BaseHologram parent, ItemStack itemStack, String serializedConfigValue) {
|
||||
super(parent, itemStack);
|
||||
this.serializedConfigValue = serializedConfigValue;
|
||||
}
|
||||
|
||||
public String getSerializedConfigValue() {
|
||||
return serializedConfigValue;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.internal;
|
||||
|
||||
import me.filoghost.holographicdisplays.object.base.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseTextLine;
|
||||
|
||||
public class InternalTextLine extends BaseTextLine implements InternalHologramLine {
|
||||
|
||||
private final String serializedConfigValue;
|
||||
|
||||
public InternalTextLine(BaseHologram parent, String text, String serializedConfigValue) {
|
||||
super(parent, text);
|
||||
this.serializedConfigValue = serializedConfigValue;
|
||||
}
|
||||
|
||||
public String getSerializedConfigValue() {
|
||||
return serializedConfigValue;
|
||||
}
|
||||
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.line;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import org.bukkit.World;
|
||||
|
||||
public abstract class HologramLineImpl implements HologramLine {
|
||||
|
||||
private final BaseHologram parent;
|
||||
|
||||
// This field is necessary for teleport.
|
||||
private boolean isSpawned;
|
||||
|
||||
// Useful for saving to disk.
|
||||
private String serializedConfigValue;
|
||||
|
||||
protected HologramLineImpl(BaseHologram parent) {
|
||||
Preconditions.notNull(parent, "parent hologram");
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BaseHologram getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
protected final NMSManager getNMSManager() {
|
||||
return parent.getNMSManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLine() {
|
||||
parent.removeLine(this);
|
||||
}
|
||||
|
||||
public void spawn(World world, double x, double y, double z) {
|
||||
Preconditions.notNull(world, "world");
|
||||
|
||||
// Remove the old entities when spawning the new ones.
|
||||
despawn();
|
||||
isSpawned = true;
|
||||
|
||||
spawnEntities(world, x, y, z);
|
||||
}
|
||||
|
||||
public final void despawn() {
|
||||
isSpawned = false;
|
||||
despawnEntities();
|
||||
}
|
||||
|
||||
public String getSerializedConfigValue() {
|
||||
return serializedConfigValue;
|
||||
}
|
||||
|
||||
public void setSerializedConfigValue(String serializedConfigValue) {
|
||||
this.serializedConfigValue = serializedConfigValue;
|
||||
}
|
||||
|
||||
public final boolean isSpawned() {
|
||||
return isSpawned;
|
||||
}
|
||||
|
||||
protected abstract void spawnEntities(World world, double x, double y, double z);
|
||||
|
||||
protected abstract void despawnEntities();
|
||||
|
||||
public abstract void teleport(double x, double y, double z);
|
||||
|
||||
public abstract double getHeight();
|
||||
|
||||
public abstract int[] getEntitiesIDs();
|
||||
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.line;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.api.handler.PickupHandler;
|
||||
import me.filoghost.holographicdisplays.api.handler.TouchHandler;
|
||||
import me.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemLineImpl extends TouchableLineImpl implements ItemLine {
|
||||
|
||||
private ItemStack itemStack;
|
||||
private PickupHandler pickupHandler;
|
||||
|
||||
private NMSItem nmsItem;
|
||||
private NMSArmorStand nmsVehicle;
|
||||
|
||||
public ItemLineImpl(BaseHologram parent, ItemStack itemStack) {
|
||||
super(parent);
|
||||
setItemStack(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemStack(ItemStack itemStack) {
|
||||
Preconditions.notNull(itemStack, "itemStack");
|
||||
Preconditions.checkArgument(0 < itemStack.getAmount() && itemStack.getAmount() <= 64, "Item must have amount between 1 and 64");
|
||||
this.itemStack = itemStack;
|
||||
|
||||
if (nmsItem != null) {
|
||||
nmsItem.setItemStackNMS(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PickupHandler getPickupHandler() {
|
||||
return pickupHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPickupHandler(PickupHandler pickupHandler) {
|
||||
this.pickupHandler = pickupHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTouchHandler(TouchHandler touchHandler) {
|
||||
if (nmsVehicle != null) {
|
||||
Location loc = nmsVehicle.getBukkitEntityNMS().getLocation();
|
||||
super.setTouchHandler(touchHandler, loc.getWorld(), loc.getX(), loc.getY() - getItemOffset(), loc.getZ());
|
||||
} else {
|
||||
super.setTouchHandler(touchHandler, null, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnEntities(World world, double x, double y, double z) {
|
||||
super.spawnEntities(world, x, y, z);
|
||||
|
||||
if (itemStack != null) {
|
||||
nmsItem = getNMSManager().spawnNMSItem(world, x, y + getItemOffset(), z, this, itemStack);
|
||||
nmsVehicle = getNMSManager().spawnNMSArmorStand(world, x, y + getItemOffset(), z, this);
|
||||
|
||||
nmsItem.setPassengerOfNMS(nmsVehicle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void despawnEntities() {
|
||||
super.despawnEntities();
|
||||
|
||||
if (nmsVehicle != null) {
|
||||
nmsVehicle.killEntityNMS();
|
||||
nmsVehicle = null;
|
||||
}
|
||||
|
||||
if (nmsItem != null) {
|
||||
nmsItem.killEntityNMS();
|
||||
nmsItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
return 0.7;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(double x, double y, double z) {
|
||||
super.teleport(x, y, z);
|
||||
|
||||
if (nmsVehicle != null) {
|
||||
nmsVehicle.setLocationNMS(x, y + getItemOffset(), z);
|
||||
}
|
||||
if (nmsItem != null) {
|
||||
nmsItem.setLocationNMS(x, y + getItemOffset(), z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getEntitiesIDs() {
|
||||
if (isSpawned()) {
|
||||
if (touchSlime != null) {
|
||||
return ArrayUtils.addAll(new int[] {nmsVehicle.getIdNMS(), nmsItem.getIdNMS()}, touchSlime.getEntitiesIDs());
|
||||
} else {
|
||||
return new int[] {nmsVehicle.getIdNMS(), nmsItem.getIdNMS()};
|
||||
}
|
||||
} else {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
public NMSItem getNmsItem() {
|
||||
return nmsItem;
|
||||
}
|
||||
|
||||
public NMSEntityBase getNmsVehicle() {
|
||||
return nmsVehicle;
|
||||
}
|
||||
|
||||
private double getItemOffset() {
|
||||
return Offsets.ARMOR_STAND_WITH_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemLine [itemStack=" + itemStack + ", pickupHandler=" + pickupHandler + "]";
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.line;
|
||||
|
||||
/**
|
||||
* When spawning a hologram at a location, the top part of the first line should be exactly on that location.
|
||||
* The second line is below the first, and so on.
|
||||
*/
|
||||
public class Offsets {
|
||||
|
||||
// A single armor stand.
|
||||
public static final double ARMOR_STAND_ALONE = -0.29;
|
||||
|
||||
// An armor stand holding an item.
|
||||
public static final double ARMOR_STAND_WITH_ITEM = 0;
|
||||
|
||||
// An armor stand holding a slime.
|
||||
public static final double ARMOR_STAND_WITH_SLIME = 0;
|
||||
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.line;
|
||||
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSSlime;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import org.bukkit.World;
|
||||
|
||||
/**
|
||||
* A touch slime that can be applied to a line.
|
||||
*/
|
||||
public class TouchSlimeLineImpl extends HologramLineImpl {
|
||||
|
||||
// The touchable piece associated with this piece
|
||||
private final TouchableLineImpl touchablePiece;
|
||||
|
||||
private NMSSlime nmsSlime;
|
||||
private NMSArmorStand nmsVehicle;
|
||||
|
||||
|
||||
protected TouchSlimeLineImpl(BaseHologram parent, TouchableLineImpl touchablePiece) {
|
||||
super(parent);
|
||||
this.touchablePiece = touchablePiece;
|
||||
}
|
||||
|
||||
public TouchableLineImpl getTouchablePiece() {
|
||||
return touchablePiece;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void spawnEntities(World world, double x, double y, double z) {
|
||||
nmsSlime = getNMSManager().spawnNMSSlime(world, x, y + getSlimeOffset(), z, this);
|
||||
nmsVehicle = getNMSManager().spawnNMSArmorStand(world, x, y + getSlimeOffset(), z, this);
|
||||
|
||||
nmsSlime.setPassengerOfNMS(nmsVehicle);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void despawnEntities() {
|
||||
if (nmsSlime != null) {
|
||||
nmsSlime.killEntityNMS();
|
||||
nmsSlime = null;
|
||||
}
|
||||
|
||||
if (nmsVehicle != null) {
|
||||
nmsVehicle.killEntityNMS();
|
||||
nmsVehicle = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(double x, double y, double z) {
|
||||
if (nmsVehicle != null) {
|
||||
nmsVehicle.setLocationNMS(x, y + getSlimeOffset(), z);
|
||||
}
|
||||
if (nmsSlime != null) {
|
||||
nmsSlime.setLocationNMS(x, y + getSlimeOffset(), z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getEntitiesIDs() {
|
||||
if (isSpawned()) {
|
||||
return new int[] {nmsVehicle.getIdNMS(), nmsSlime.getIdNMS()};
|
||||
} else {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
public NMSSlime getNmsSlime() {
|
||||
return nmsSlime;
|
||||
}
|
||||
|
||||
public NMSEntityBase getNmsVehicle() {
|
||||
return nmsVehicle;
|
||||
}
|
||||
|
||||
private double getSlimeOffset() {
|
||||
return Offsets.ARMOR_STAND_WITH_SLIME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TouchSlimeLine [touchablePiece=" + touchablePiece + "]";
|
||||
}
|
||||
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.object.line;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.handler.TouchHandler;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import org.bukkit.World;
|
||||
|
||||
/**
|
||||
* Useful class that implements TouchablePiece. The downside is that subclasses must extend this, and cannot extend other classes.
|
||||
* But all the current items are touchable.
|
||||
*/
|
||||
public abstract class TouchableLineImpl extends HologramLineImpl {
|
||||
|
||||
protected TouchSlimeLineImpl touchSlime;
|
||||
private TouchHandler touchHandler;
|
||||
|
||||
|
||||
protected TouchableLineImpl(BaseHologram parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
protected void setTouchHandler(TouchHandler touchHandler, World world, double x, double y, double z) {
|
||||
this.touchHandler = touchHandler;
|
||||
|
||||
if (touchHandler != null && touchSlime == null && world != null) {
|
||||
// If the touch handler was null before and no entity has been spawned, spawn it now.
|
||||
touchSlime = new TouchSlimeLineImpl(getParent(), this);
|
||||
touchSlime.spawn(world, x, y + (getHeight() / 2.0 - touchSlime.getHeight() / 2.0), z);
|
||||
|
||||
} else if (touchHandler == null && touchSlime != null) {
|
||||
// Opposite case, the touch handler was not null and an entity was spawned, but now it's useless.
|
||||
touchSlime.despawn();
|
||||
touchSlime = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public TouchHandler getTouchHandler() {
|
||||
return this.touchHandler;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void spawnEntities(World world, double x, double y, double z) {
|
||||
if (touchHandler != null) {
|
||||
touchSlime = new TouchSlimeLineImpl(getParent(), this);
|
||||
touchSlime.spawn(world, x, y + (getHeight() / 2.0 - touchSlime.getHeight() / 2.0), z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void despawnEntities() {
|
||||
if (touchSlime != null) {
|
||||
touchSlime.despawn();
|
||||
touchSlime = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void teleport(double x, double y, double z) {
|
||||
if (touchSlime != null) {
|
||||
touchSlime.teleport(x, y + (getHeight() / 2.0 - touchSlime.getHeight() / 2.0), z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public TouchSlimeLineImpl getTouchSlime() {
|
||||
return touchSlime;
|
||||
}
|
||||
|
||||
}
|
@ -10,7 +10,7 @@ import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
|
||||
import me.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerTracker;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSNameable;
|
||||
import me.filoghost.holographicdisplays.object.line.TextLineImpl;
|
||||
import me.filoghost.holographicdisplays.object.base.BaseTextLine;
|
||||
import me.filoghost.holographicdisplays.task.WorldPlayerCounterTask;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -88,33 +88,29 @@ public class PlaceholdersManager {
|
||||
linesToUpdate.clear();
|
||||
}
|
||||
|
||||
public static void untrack(TextLineImpl line) {
|
||||
if (line == null || !line.isSpawned()) {
|
||||
return;
|
||||
}
|
||||
|
||||
public static void untrack(BaseTextLine line) {
|
||||
Iterator<DynamicLineData> iter = linesToUpdate.iterator();
|
||||
while (iter.hasNext()) {
|
||||
DynamicLineData data = iter.next();
|
||||
if (data.getEntity() == line.getNmsNameable()) {
|
||||
if (data.getEntity() == line.getNMSNameable()) {
|
||||
iter.remove();
|
||||
data.getEntity().setCustomNameNMS(data.getOriginalName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void trackIfNecessary(TextLineImpl line) {
|
||||
NMSNameable nameableEntity = line.getNmsNameable();
|
||||
public static void trackIfNecessary(BaseTextLine line) {
|
||||
String text = line.getText();
|
||||
if (text == null || text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
NMSNameable nameableEntity = line.getNMSNameable();
|
||||
if (nameableEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String name = line.getText();
|
||||
if (name == null || name.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean updateName = false;
|
||||
boolean updateText = false;
|
||||
|
||||
// Lazy initialization.
|
||||
Set<Placeholder> normalPlaceholders = null;
|
||||
@ -125,7 +121,7 @@ public class PlaceholdersManager {
|
||||
Matcher matcher;
|
||||
|
||||
for (Placeholder placeholder : PlaceholdersRegister.getPlaceholders()) {
|
||||
if (name.contains(placeholder.getTextPlaceholder())) {
|
||||
if (text.contains(placeholder.getTextPlaceholder())) {
|
||||
if (normalPlaceholders == null) {
|
||||
normalPlaceholders = new HashSet<>();
|
||||
}
|
||||
@ -135,7 +131,7 @@ public class PlaceholdersManager {
|
||||
|
||||
|
||||
// Players in a world count pattern.
|
||||
matcher = WORLD_PATTERN.matcher(name);
|
||||
matcher = WORLD_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
if (worldsOnlinePlayersReplacers == null) {
|
||||
worldsOnlinePlayersReplacers = new HashMap<>();
|
||||
@ -164,7 +160,7 @@ public class PlaceholdersManager {
|
||||
}
|
||||
|
||||
// BungeeCord online pattern.
|
||||
matcher = BUNGEE_ONLINE_PATTERN.matcher(name);
|
||||
matcher = BUNGEE_ONLINE_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
if (bungeeReplacers == null) {
|
||||
bungeeReplacers = new HashMap<>();
|
||||
@ -198,7 +194,7 @@ public class PlaceholdersManager {
|
||||
}
|
||||
|
||||
// BungeeCord max players pattern.
|
||||
matcher = BUNGEE_MAX_PATTERN.matcher(name);
|
||||
matcher = BUNGEE_MAX_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
if (bungeeReplacers == null) {
|
||||
bungeeReplacers = new HashMap<>();
|
||||
@ -214,7 +210,7 @@ public class PlaceholdersManager {
|
||||
}
|
||||
|
||||
// BungeeCord motd pattern.
|
||||
matcher = BUNGEE_MOTD_PATTERN.matcher(name);
|
||||
matcher = BUNGEE_MOTD_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
if (bungeeReplacers == null) {
|
||||
bungeeReplacers = new HashMap<>();
|
||||
@ -230,7 +226,7 @@ public class PlaceholdersManager {
|
||||
}
|
||||
|
||||
// BungeeCord motd (line 2) pattern.
|
||||
matcher = BUNGEE_MOTD_2_PATTERN.matcher(name);
|
||||
matcher = BUNGEE_MOTD_2_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
if (bungeeReplacers == null) {
|
||||
bungeeReplacers = new HashMap<>();
|
||||
@ -246,7 +242,7 @@ public class PlaceholdersManager {
|
||||
}
|
||||
|
||||
// BungeeCord status pattern.
|
||||
matcher = BUNGEE_STATUS_PATTERN.matcher(name);
|
||||
matcher = BUNGEE_STATUS_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
if (bungeeReplacers == null) {
|
||||
bungeeReplacers = new HashMap<>();
|
||||
@ -263,7 +259,7 @@ public class PlaceholdersManager {
|
||||
|
||||
|
||||
// Animation pattern.
|
||||
matcher = ANIMATION_PATTERN.matcher(name);
|
||||
matcher = ANIMATION_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
String fileName = extractArgumentFromPlaceholder(matcher);
|
||||
Placeholder animation = AnimationsRegister.getAnimation(fileName);
|
||||
@ -277,13 +273,13 @@ public class PlaceholdersManager {
|
||||
animationsPlaceholders.put(matcher.group(), animation);
|
||||
|
||||
} else {
|
||||
name = name.replace(matcher.group(), "[Animation not found: " + fileName + "]");
|
||||
updateName = true;
|
||||
text = text.replace(matcher.group(), "[Animation not found: " + fileName + "]");
|
||||
updateText = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (Utils.isThereNonNull(normalPlaceholders, bungeeReplacers, worldsOnlinePlayersReplacers, animationsPlaceholders)) {
|
||||
DynamicLineData lineData = new DynamicLineData(nameableEntity, name);
|
||||
DynamicLineData lineData = new DynamicLineData(nameableEntity, text);
|
||||
|
||||
if (normalPlaceholders != null) {
|
||||
lineData.setPlaceholders(normalPlaceholders);
|
||||
@ -312,8 +308,8 @@ public class PlaceholdersManager {
|
||||
} else {
|
||||
|
||||
// The name needs to be updated anyways.
|
||||
if (updateName) {
|
||||
nameableEntity.setCustomNameNMS(name);
|
||||
if (updateText) {
|
||||
nameableEntity.setCustomNameNMS(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.HologramConfig;
|
||||
import me.filoghost.holographicdisplays.disk.HologramLoadException;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@ -29,7 +29,7 @@ public class StartupLoadHologramsTask implements Runnable {
|
||||
for (HologramConfig hologramConfig : hologramConfigsToLoad) {
|
||||
try {
|
||||
InternalHologram hologram = hologramConfig.createHologram(internalHologramManager);
|
||||
hologram.refreshAll();
|
||||
hologram.refresh();
|
||||
} catch (HologramLoadException e) {
|
||||
Log.warning(Utils.formatExceptionMessage(e));
|
||||
} catch (Exception e) {
|
||||
|
Loading…
Reference in New Issue
Block a user