Added hologram offset
This commit is contained in:
parent
8129405de8
commit
329f9fe86c
4 changed files with 56 additions and 5 deletions
|
@ -8,6 +8,7 @@ import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder
|
|||
import lol.pyr.director.adventure.command.CommandManager;
|
||||
import lol.pyr.director.adventure.command.MultiCommand;
|
||||
import lol.pyr.director.adventure.parse.primitive.BooleanParser;
|
||||
import lol.pyr.director.adventure.parse.primitive.DoubleParser;
|
||||
import lol.pyr.director.adventure.parse.primitive.IntegerParser;
|
||||
import lol.pyr.znpcsplus.api.ZApi;
|
||||
import lol.pyr.znpcsplus.api.ZApiProvider;
|
||||
|
@ -231,6 +232,7 @@ public class ZNpcsPlus extends JavaPlugin implements ZApi {
|
|||
manager.registerParser(NpcEntryImpl.class, new NpcEntryParser(npcRegistry, context -> {}));
|
||||
manager.registerParser(EntityPropertyImpl.class, new EntityPropertyParser(context -> {}));
|
||||
manager.registerParser(Integer.class, new IntegerParser(context -> {}));
|
||||
manager.registerParser(Double.class, new DoubleParser(context -> {}));
|
||||
manager.registerParser(Boolean.class, new BooleanParser(context -> {}));
|
||||
manager.registerParser(NamedTextColor.class, new NamedTextColorParser(context -> {}));
|
||||
|
||||
|
@ -254,7 +256,7 @@ public class ZNpcsPlus extends JavaPlugin implements ZApi {
|
|||
.addSubcommand("info", new HoloInfoCommand(npcRegistry))
|
||||
.addSubcommand("insert", new HoloInsertCommand(npcRegistry, textSerializer))
|
||||
.addSubcommand("set", new HoloSetCommand(npcRegistry, textSerializer))
|
||||
)
|
||||
.addSubcommand("offset", new HoloOffsetCommand(npcRegistry)))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package lol.pyr.znpcsplus.commands.hologram;
|
||||
|
||||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.hologram.HologramImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HoloOffsetCommand implements CommandHandler {
|
||||
private final NpcRegistryImpl npcRegistry;
|
||||
|
||||
public HoloOffsetCommand(NpcRegistryImpl npcRegistry) {
|
||||
this.npcRegistry = npcRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.setUsage(context.getLabel() + " holo offset <id> <offset>");
|
||||
HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram();
|
||||
double offset = context.parse(Double.class);
|
||||
hologram.setOffset(offset);
|
||||
context.send("NPC hologram offset set!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.modifiableIds());
|
||||
if (context.argSize() == 2) {
|
||||
HologramImpl hologram = context.suggestionParse(0, NpcEntryImpl.class).getNpc().getHologram();
|
||||
return context.suggestLiteral(String.valueOf(hologram.getOffset()));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ public class HologramImpl extends Viewable implements Hologram {
|
|||
private final ConfigManager configManager;
|
||||
private final PacketFactory packetFactory;
|
||||
|
||||
private double offset = 0.0;
|
||||
private ZLocation location;
|
||||
private final List<HologramLine> lines = new ArrayList<>();
|
||||
|
||||
|
@ -79,10 +80,19 @@ public class HologramImpl extends Viewable implements Hologram {
|
|||
|
||||
private void relocateLines(HologramLine newLine) {
|
||||
final double lineSpacing = configManager.getConfig().lineSpacing();
|
||||
double height = location.getY() + (lines.size() - 1) * lineSpacing;
|
||||
double height = location.getY() + (lines.size() - 1) * lineSpacing + getOffset();
|
||||
for (HologramLine line : lines) {
|
||||
line.setLocation(location.withY(height), line == newLine ? Collections.emptySet() : getViewers());
|
||||
height -= lineSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
public void setOffset(double offset) {
|
||||
this.offset = offset;
|
||||
relocateLines();
|
||||
}
|
||||
|
||||
public double getOffset() {
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ public class YamlStorage implements NpcStorage {
|
|||
npc.UNSAFE_setProperty(property, property.deserialize(properties.getString(key)));
|
||||
}
|
||||
}
|
||||
|
||||
for (String line : config.getStringList("hologram")) npc.getHologram().addLine(MiniMessage.miniMessage().deserialize(line));
|
||||
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 s : config.getStringList("actions")) npc.addAction(actionRegistry.deserialize(s));
|
||||
|
||||
NpcEntryImpl entry = new NpcEntryImpl(config.getString("id"), npc);
|
||||
|
@ -84,11 +84,12 @@ public class YamlStorage implements NpcStorage {
|
|||
config.set("properties." + property.getName(), property.serialize(npc));
|
||||
}
|
||||
|
||||
if (npc.getHologram().getOffset() != 0.0) config.set("hologram.offset", npc.getHologram().getOffset());
|
||||
List<String> lines = new ArrayList<>();
|
||||
for (HologramLine line : npc.getHologram().getLines()) {
|
||||
lines.add(MiniMessage.miniMessage().serialize(line.getText()));
|
||||
}
|
||||
config.set("hologram", lines);
|
||||
config.set("hologram.lines", lines);
|
||||
config.set("actions", npc.getActions().stream()
|
||||
.map(actionRegistry::serialize)
|
||||
.filter(Objects::nonNull)
|
||||
|
|
Loading…
Reference in a new issue