remove api dependencies

This commit is contained in:
Pyrbu 2023-05-22 17:10:03 +01:00
parent fc87323d10
commit bc12f79e85
15 changed files with 60 additions and 43 deletions

@ -5,9 +5,6 @@ plugins {
dependencies { dependencies {
compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT" compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT"
compileOnly "net.kyori:adventure-platform-bukkit:4.3.0"
compileOnly "net.kyori:adventure-text-minimessage:4.13.1"
compileOnly "com.github.retrooper.packetevents:spigot:2.0.0-SNAPSHOT"
} }
publishing { publishing {

@ -1,11 +1,9 @@
package lol.pyr.znpcsplus.api.hologram; package lol.pyr.znpcsplus.api.hologram;
import net.kyori.adventure.text.Component;
public interface Hologram { public interface Hologram {
void addLine(Component line); void addLine(String line);
Component getLine(int index); String getLine(int index);
void removeLine(int index); void removeLine(int index);
void clearLines(); void clearLines();
void insertLine(int index, Component line); void insertLine(int index, String line);
} }

@ -1,6 +1,5 @@
package lol.pyr.znpcsplus.util; package lol.pyr.znpcsplus.util;
import com.github.retrooper.packetevents.util.Vector3d;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.util.NumberConversions; import org.bukkit.util.NumberConversions;
@ -64,10 +63,6 @@ public class NpcLocation {
return new NpcLocation(x, y, z, yaw, pitch); return new NpcLocation(x, y, z, yaw, pitch);
} }
public Vector3d toVector3d() {
return new Vector3d(x, y, z);
}
private static final double _2PI = 2 * Math.PI; private static final double _2PI = 2 * Math.PI;
public Location lookingAt(Location loc) { public Location lookingAt(Location loc) {

@ -114,7 +114,7 @@ public class ZNpcsPlus extends JavaPlugin {
BungeeConnector bungeeConnector = new BungeeConnector(this); BungeeConnector bungeeConnector = new BungeeConnector(this);
ActionRegistry actionRegistry = new ActionRegistry(); ActionRegistry actionRegistry = new ActionRegistry();
NpcTypeRegistryImpl typeRegistry = new NpcTypeRegistryImpl(); NpcTypeRegistryImpl typeRegistry = new NpcTypeRegistryImpl();
NpcRegistryImpl npcRegistry = new NpcRegistryImpl(configManager, this, packetFactory, actionRegistry, scheduler, typeRegistry, propertyRegistry); NpcRegistryImpl npcRegistry = new NpcRegistryImpl(configManager, this, packetFactory, actionRegistry, scheduler, typeRegistry, propertyRegistry, textSerializer);
UserManager userManager = new UserManager(); UserManager userManager = new UserManager();
log(ChatColor.WHITE + " * Registerring components..."); log(ChatColor.WHITE + " * Registerring components...");
@ -157,7 +157,7 @@ public class ZNpcsPlus extends JavaPlugin {
NpcEntryImpl entry = npcRegistry.create("debug_npc_" + i, world, type, new NpcLocation(i * 3, 200, 0, 0, 0)); NpcEntryImpl entry = npcRegistry.create("debug_npc_" + i, world, type, new NpcLocation(i * 3, 200, 0, 0, 0));
entry.setProcessed(true); entry.setProcessed(true);
NpcImpl npc = entry.getNpc(); NpcImpl npc = entry.getNpc();
npc.getHologram().addLine(Component.text("Hello, World!")); npc.getHologram().addLineComponent(Component.text("Hello, World!"));
i++; i++;
} }
} }

@ -30,7 +30,7 @@ public class ListCommand implements CommandHandler {
.append(Component.text(npc.getType().getName(), NamedTextColor.GREEN)) .append(Component.text(npc.getType().getName(), NamedTextColor.GREEN))
.append(Component.text(" | ", NamedTextColor.GRAY)) .append(Component.text(" | ", NamedTextColor.GRAY))
.append(Component.text("Name: ", NamedTextColor.GREEN)) .append(Component.text("Name: ", NamedTextColor.GREEN))
.append(npc.getHologram().getLine(0).color(NamedTextColor.GREEN)) .append(npc.getHologram().getLineComponent(0).color(NamedTextColor.GREEN))
.append(Component.text(" | ", NamedTextColor.GRAY)) .append(Component.text(" | ", NamedTextColor.GRAY))
.append(Component.text("Location: " + npc.getWorldName() + " X:" + location.getBlockX() + " Y:" + location.getBlockY() + " Z:" + location.getBlockZ(), NamedTextColor.GREEN)) .append(Component.text("Location: " + npc.getWorldName() + " X:" + location.getBlockX() + " Y:" + location.getBlockY() + " Z:" + location.getBlockZ(), NamedTextColor.GREEN))
.append(Component.text(" | ", NamedTextColor.GRAY)) .append(Component.text(" | ", NamedTextColor.GRAY))

@ -27,7 +27,7 @@ public class HoloAddCommand implements CommandHandler {
context.setUsage(context.getLabel() + " holo add <id> <text>"); context.setUsage(context.getLabel() + " holo add <id> <text>");
HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram(); HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram();
context.ensureArgsNotEmpty(); context.ensureArgsNotEmpty();
hologram.addLine(textSerializer.deserialize(context.dumpAllArgs())); hologram.addLineComponent(textSerializer.deserialize(context.dumpAllArgs()));
context.send(Component.text("NPC line added!", NamedTextColor.GREEN)); context.send(Component.text("NPC line added!", NamedTextColor.GREEN));
} }

@ -30,7 +30,7 @@ public class HoloInsertCommand implements CommandHandler {
int line = context.parse(Integer.class); int line = context.parse(Integer.class);
if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED)); if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED));
context.ensureArgsNotEmpty(); context.ensureArgsNotEmpty();
hologram.insertLine(line, componentSerializer.deserialize(context.dumpAllArgs())); hologram.insertLineComponent(line, componentSerializer.deserialize(context.dumpAllArgs()));
context.send(Component.text("NPC line inserted!", NamedTextColor.GREEN)); context.send(Component.text("NPC line inserted!", NamedTextColor.GREEN));
} }

@ -31,7 +31,7 @@ public class HoloSetCommand implements CommandHandler {
if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED)); if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED));
context.ensureArgsNotEmpty(); context.ensureArgsNotEmpty();
hologram.removeLine(line); hologram.removeLine(line);
hologram.insertLine(line, componentSerializer.deserialize(context.dumpAllArgs())); hologram.insertLineComponent(line, componentSerializer.deserialize(context.dumpAllArgs()));
context.send(Component.text("NPC line set!", NamedTextColor.GREEN)); context.send(Component.text("NPC line set!", NamedTextColor.GREEN));
} }
@ -43,7 +43,7 @@ public class HoloSetCommand implements CommandHandler {
if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1) if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1)
.limit(hologram.getLines().size()).map(String::valueOf)); .limit(hologram.getLines().size()).map(String::valueOf));
if (context.argSize() == 3) return context.suggestLiteral(componentSerializer.serialize( if (context.argSize() == 3) return context.suggestLiteral(componentSerializer.serialize(
hologram.getLine(context.suggestionParse(1, Integer.class)))); hologram.getLineComponent(context.suggestionParse(1, Integer.class))));
} }
return Collections.emptyList(); return Collections.emptyList();
} }

@ -6,6 +6,7 @@ import lol.pyr.znpcsplus.packets.PacketFactory;
import lol.pyr.znpcsplus.util.Viewable; import lol.pyr.znpcsplus.util.Viewable;
import lol.pyr.znpcsplus.util.NpcLocation; import lol.pyr.znpcsplus.util.NpcLocation;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -15,28 +16,38 @@ import java.util.List;
public class HologramImpl extends Viewable implements Hologram { public class HologramImpl extends Viewable implements Hologram {
private final ConfigManager configManager; private final ConfigManager configManager;
private final PacketFactory packetFactory; private final PacketFactory packetFactory;
private final LegacyComponentSerializer textSerializer;
private double offset = 0.0; private double offset = 0.0;
private NpcLocation location; private NpcLocation location;
private final List<HologramLine> lines = new ArrayList<>(); private final List<HologramLine> lines = new ArrayList<>();
public HologramImpl(ConfigManager configManager, PacketFactory packetFactory, NpcLocation location) { public HologramImpl(ConfigManager configManager, PacketFactory packetFactory, LegacyComponentSerializer textSerializer, NpcLocation location) {
this.configManager = configManager; this.configManager = configManager;
this.packetFactory = packetFactory; this.packetFactory = packetFactory;
this.textSerializer = textSerializer;
this.location = location; this.location = location;
} }
public void addLine(Component line) { public void addLineComponent(Component line) {
HologramLine newLine = new HologramLine(packetFactory, null, line); HologramLine newLine = new HologramLine(packetFactory, null, line);
lines.add(newLine); lines.add(newLine);
relocateLines(); relocateLines();
for (Player viewer : getViewers()) newLine.show(viewer.getPlayer()); for (Player viewer : getViewers()) newLine.show(viewer.getPlayer());
} }
public Component getLine(int index) { public void addLine(String line) {
addLineComponent(textSerializer.deserialize(line));
}
public Component getLineComponent(int index) {
return lines.get(index).getText(); return lines.get(index).getText();
} }
public String getLine(int index) {
return textSerializer.serialize(getLineComponent(index));
}
public void removeLine(int index) { public void removeLine(int index) {
HologramLine line = lines.remove(index); HologramLine line = lines.remove(index);
for (Player viewer : getViewers()) line.hide(viewer); for (Player viewer : getViewers()) line.hide(viewer);
@ -52,13 +63,17 @@ public class HologramImpl extends Viewable implements Hologram {
lines.clear(); lines.clear();
} }
public void insertLine(int index, Component line) { public void insertLineComponent(int index, Component line) {
HologramLine newLine = new HologramLine(packetFactory, null, line); HologramLine newLine = new HologramLine(packetFactory, null, line);
lines.add(index, newLine); lines.add(index, newLine);
relocateLines(); relocateLines();
for (Player viewer : getViewers()) newLine.show(viewer.getPlayer()); for (Player viewer : getViewers()) newLine.show(viewer.getPlayer());
} }
public void insertLine(int index, String line) {
insertLineComponent(index, textSerializer.deserialize(line));
}
@Override @Override
protected void UNSAFE_show(Player player) { protected void UNSAFE_show(Player player) {
for (HologramLine line : lines) line.show(player); for (HologramLine line : lines) line.show(player);

@ -10,6 +10,7 @@ import lol.pyr.znpcsplus.interaction.InteractionAction;
import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.packets.PacketFactory;
import lol.pyr.znpcsplus.util.NpcLocation; import lol.pyr.znpcsplus.util.NpcLocation;
import lol.pyr.znpcsplus.util.Viewable; import lol.pyr.znpcsplus.util.Viewable;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -28,17 +29,17 @@ public class NpcImpl extends Viewable implements Npc {
private final Map<EntityPropertyImpl<?>, Object> propertyMap = new HashMap<>(); private final Map<EntityPropertyImpl<?>, Object> propertyMap = new HashMap<>();
private final List<InteractionAction> actions = new ArrayList<>(); private final List<InteractionAction> actions = new ArrayList<>();
protected NpcImpl(ConfigManager configManager, World world, NpcTypeImpl type, NpcLocation location, PacketFactory packetFactory) { protected NpcImpl(ConfigManager configManager, LegacyComponentSerializer textSerializer, World world, NpcTypeImpl type, NpcLocation location, PacketFactory packetFactory) {
this(configManager, packetFactory, world.getName(), type, location); this(configManager, packetFactory, textSerializer, world.getName(), type, location);
} }
public NpcImpl(ConfigManager configManager, PacketFactory packetFactory, String world, NpcTypeImpl type, NpcLocation location) { public NpcImpl(ConfigManager configManager, PacketFactory packetFactory, LegacyComponentSerializer textSerializer, String world, NpcTypeImpl type, NpcLocation location) {
this.packetFactory = packetFactory; this.packetFactory = packetFactory;
this.worldName = world; this.worldName = world;
this.type = type; this.type = type;
this.location = location; this.location = location;
entity = new PacketEntity(packetFactory, this, type.getType(), location); entity = new PacketEntity(packetFactory, this, type.getType(), location);
hologram = new HologramImpl(configManager, packetFactory, location.withY(location.getY() + type.getHologramOffset())); hologram = new HologramImpl(configManager, packetFactory, textSerializer, location.withY(location.getY() + type.getHologramOffset()));
} }

@ -10,6 +10,7 @@ import lol.pyr.znpcsplus.packets.PacketFactory;
import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.scheduling.TaskScheduler;
import lol.pyr.znpcsplus.storage.NpcStorage; import lol.pyr.znpcsplus.storage.NpcStorage;
import lol.pyr.znpcsplus.util.NpcLocation; import lol.pyr.znpcsplus.util.NpcLocation;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.World; import org.bukkit.World;
import java.util.Collection; import java.util.Collection;
@ -22,9 +23,11 @@ public class NpcRegistryImpl implements NpcRegistry {
private final NpcStorage storage; private final NpcStorage storage;
private final PacketFactory packetFactory; private final PacketFactory packetFactory;
private final ConfigManager configManager; private final ConfigManager configManager;
private final LegacyComponentSerializer textSerializer;
public NpcRegistryImpl(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, TaskScheduler scheduler, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry) { public NpcRegistryImpl(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, TaskScheduler scheduler, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) {
storage = configManager.getConfig().storageType().create(configManager, plugin, packetFactory, actionRegistry, typeRegistry, propertyRegistry); this.textSerializer = textSerializer;
storage = configManager.getConfig().storageType().create(configManager, plugin, packetFactory, actionRegistry, typeRegistry, propertyRegistry, textSerializer);
this.packetFactory = packetFactory; this.packetFactory = packetFactory;
this.configManager = configManager; this.configManager = configManager;
@ -81,7 +84,7 @@ public class NpcRegistryImpl implements NpcRegistry {
public NpcEntryImpl create(String id, World world, NpcTypeImpl type, NpcLocation location) { public NpcEntryImpl create(String id, World world, NpcTypeImpl type, NpcLocation location) {
id = id.toLowerCase(); id = id.toLowerCase();
if (npcMap.containsKey(id)) throw new IllegalArgumentException("An npc with the id " + id + " already exists!"); if (npcMap.containsKey(id)) throw new IllegalArgumentException("An npc with the id " + id + " already exists!");
NpcImpl npc = new NpcImpl(configManager, world, type, location, packetFactory); NpcImpl npc = new NpcImpl(configManager, textSerializer, world, type, location, packetFactory);
NpcEntryImpl entry = new NpcEntryImpl(id, npc); NpcEntryImpl entry = new NpcEntryImpl(id, npc);
npcMap.put(id, entry); npcMap.put(id, entry);
return entry; return entry;

@ -23,7 +23,7 @@ public class V1_14PacketFactory extends V1_10PacketFactory {
public void spawnEntity(Player player, PacketEntity entity, PropertyHolder properties) { public void spawnEntity(Player player, PacketEntity entity, PropertyHolder properties) {
NpcLocation location = entity.getLocation(); NpcLocation location = entity.getLocation();
sendPacket(player, new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), sendPacket(player, new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(),
location.toVector3d(), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.of(new Vector3d()))); npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.of(new Vector3d())));
sendAllMetadata(player, entity, properties); sendAllMetadata(player, entity, properties);
createTeam(player, entity, properties); createTeam(player, entity, properties);
} }

@ -45,7 +45,7 @@ public class V1_8PacketFactory implements PacketFactory {
createTeam(player, entity, properties); createTeam(player, entity, properties);
NpcLocation location = entity.getLocation(); NpcLocation location = entity.getLocation();
sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(), sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(),
entity.getUuid(), location.toVector3d(), location.getYaw(), location.getPitch(), Collections.emptyList())); entity.getUuid(), npcLocationToVector(location), location.getYaw(), location.getPitch(), Collections.emptyList()));
sendPacket(player, new WrapperPlayServerEntityHeadLook(entity.getEntityId(), location.getYaw())); sendPacket(player, new WrapperPlayServerEntityHeadLook(entity.getEntityId(), location.getYaw()));
sendAllMetadata(player, entity, properties); sendAllMetadata(player, entity, properties);
scheduler.runLaterAsync(() -> removeTabPlayer(player, entity), 60); scheduler.runLaterAsync(() -> removeTabPlayer(player, entity), 60);
@ -58,14 +58,18 @@ public class V1_8PacketFactory implements PacketFactory {
EntityType type = entity.getType(); EntityType type = entity.getType();
ClientVersion clientVersion = packetEvents.getServerManager().getVersion().toClientVersion(); ClientVersion clientVersion = packetEvents.getServerManager().getVersion().toClientVersion();
sendPacket(player, type.getLegacyId(clientVersion) == -1 ? sendPacket(player, type.getLegacyId(clientVersion) == -1 ?
new WrapperPlayServerSpawnLivingEntity(entity.getEntityId(), entity.getUuid(), type, location.toVector3d(), new WrapperPlayServerSpawnLivingEntity(entity.getEntityId(), entity.getUuid(), type, npcLocationToVector(location),
location.getYaw(), location.getPitch(), location.getPitch(), new Vector3d(), Collections.emptyList()) : location.getYaw(), location.getPitch(), location.getPitch(), new Vector3d(), Collections.emptyList()) :
new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), location.toVector3d(), new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), npcLocationToVector(location),
location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty())); location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty()));
sendAllMetadata(player, entity, properties); sendAllMetadata(player, entity, properties);
createTeam(player, entity, properties); createTeam(player, entity, properties);
} }
protected Vector3d npcLocationToVector(NpcLocation location) {
return new Vector3d(location.getX(), location.getY(), location.getZ());
}
@Override @Override
public void destroyEntity(Player player, PacketEntity entity, PropertyHolder properties) { public void destroyEntity(Player player, PacketEntity entity, PropertyHolder properties) {
sendPacket(player, new WrapperPlayServerDestroyEntities(entity.getEntityId())); sendPacket(player, new WrapperPlayServerDestroyEntities(entity.getEntityId()));
@ -75,7 +79,7 @@ public class V1_8PacketFactory implements PacketFactory {
@Override @Override
public void teleportEntity(Player player, PacketEntity entity) { public void teleportEntity(Player player, PacketEntity entity) {
NpcLocation location = entity.getLocation(); NpcLocation location = entity.getLocation();
sendPacket(player, new WrapperPlayServerEntityTeleport(entity.getEntityId(), location.toVector3d(), location.getYaw(), location.getPitch(), true)); sendPacket(player, new WrapperPlayServerEntityTeleport(entity.getEntityId(), npcLocationToVector(location), location.getYaw(), location.getPitch(), true));
if (entity.getType() == EntityTypes.PLAYER) sendPacket(player, new WrapperPlayServerEntityHeadLook(entity.getEntityId(), location.getYaw())); if (entity.getType() == EntityTypes.PLAYER) sendPacket(player, new WrapperPlayServerEntityHeadLook(entity.getEntityId(), location.getYaw()));
} }

@ -7,16 +7,17 @@ import lol.pyr.znpcsplus.interaction.ActionRegistry;
import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl;
import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.packets.PacketFactory;
import lol.pyr.znpcsplus.storage.yaml.YamlStorage; import lol.pyr.znpcsplus.storage.yaml.YamlStorage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import java.io.File; import java.io.File;
public enum NpcStorageType { public enum NpcStorageType {
YAML { YAML {
@Override @Override
public NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry) { public NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) {
return new YamlStorage(packetFactory, configManager, actionRegistry, typeRegistry, propertyRegistry, new File(plugin.getDataFolder(), "data")); return new YamlStorage(packetFactory, configManager, actionRegistry, typeRegistry, propertyRegistry, textSerializer, new File(plugin.getDataFolder(), "data"));
} }
}; };
public abstract NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry); public abstract NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer);
} }

@ -12,6 +12,7 @@ import lol.pyr.znpcsplus.packets.PacketFactory;
import lol.pyr.znpcsplus.storage.NpcStorage; import lol.pyr.znpcsplus.storage.NpcStorage;
import lol.pyr.znpcsplus.util.NpcLocation; import lol.pyr.znpcsplus.util.NpcLocation;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -26,14 +27,16 @@ public class YamlStorage implements NpcStorage {
private final ActionRegistry actionRegistry; private final ActionRegistry actionRegistry;
private final NpcTypeRegistryImpl typeRegistry; private final NpcTypeRegistryImpl typeRegistry;
private final EntityPropertyRegistryImpl propertyRegistry; private final EntityPropertyRegistryImpl propertyRegistry;
private final LegacyComponentSerializer textSerializer;
private final File folder; private final File folder;
public YamlStorage(PacketFactory packetFactory, ConfigManager configManager, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, File folder) { public YamlStorage(PacketFactory packetFactory, ConfigManager configManager, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer, File folder) {
this.packetFactory = packetFactory; this.packetFactory = packetFactory;
this.configManager = configManager; this.configManager = configManager;
this.actionRegistry = actionRegistry; this.actionRegistry = actionRegistry;
this.typeRegistry = typeRegistry; this.typeRegistry = typeRegistry;
this.propertyRegistry = propertyRegistry; this.propertyRegistry = propertyRegistry;
this.textSerializer = textSerializer;
this.folder = folder; this.folder = folder;
if (!this.folder.exists()) this.folder.mkdirs(); if (!this.folder.exists()) this.folder.mkdirs();
} }
@ -46,8 +49,8 @@ public class YamlStorage implements NpcStorage {
List<NpcEntryImpl> npcs = new ArrayList<>(); List<NpcEntryImpl> npcs = new ArrayList<>();
for (File file : files) if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) { for (File file : files) if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file); YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
NpcImpl npc = new NpcImpl(configManager, packetFactory, config.getString("world"), typeRegistry.getByName(config.getString("type")), NpcImpl npc = new NpcImpl(configManager, packetFactory, textSerializer, config.getString("world"),
deserializeLocation(config.getConfigurationSection("location"))); typeRegistry.getByName(config.getString("type")), deserializeLocation(config.getConfigurationSection("location")));
ConfigurationSection properties = config.getConfigurationSection("properties"); ConfigurationSection properties = config.getConfigurationSection("properties");
if (properties != null) { if (properties != null) {
@ -57,7 +60,7 @@ public class YamlStorage implements NpcStorage {
} }
} }
npc.getHologram().setOffset(config.getDouble("hologram.offset", 0.0)); npc.getHologram().setOffset(config.getDouble("hologram.offset", 0.0));
for (String line : config.getStringList("hologram.lines")) npc.getHologram().addLine(MiniMessage.miniMessage().deserialize(line)); for (String line : config.getStringList("hologram.lines")) npc.getHologram().addLineComponent(MiniMessage.miniMessage().deserialize(line));
for (String s : config.getStringList("actions")) npc.addAction(actionRegistry.deserialize(s)); for (String s : config.getStringList("actions")) npc.addAction(actionRegistry.deserialize(s));
NpcEntryImpl entry = new NpcEntryImpl(config.getString("id"), npc); NpcEntryImpl entry = new NpcEntryImpl(config.getString("id"), npc);