Merge pull request #55 from D3v1s0m/2.0.0

Added Action Edit command
This commit is contained in:
Pyr 2023-05-29 15:35:29 +01:00 committed by GitHub
commit a7863c9fe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 237 additions and 85 deletions

@ -13,9 +13,11 @@ import lol.pyr.director.adventure.parse.primitive.DoubleParser;
import lol.pyr.director.adventure.parse.primitive.IntegerParser;
import lol.pyr.director.common.message.Message;
import lol.pyr.znpcsplus.api.NpcApiProvider;
import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.commands.*;
import lol.pyr.znpcsplus.commands.action.ActionAddCommand;
import lol.pyr.znpcsplus.commands.action.ActionDeleteCommand;
import lol.pyr.znpcsplus.commands.action.ActionEditCommand;
import lol.pyr.znpcsplus.commands.action.ActionListCommand;
import lol.pyr.znpcsplus.commands.hologram.*;
import lol.pyr.znpcsplus.commands.storage.LoadAllCommand;
@ -25,7 +27,6 @@ import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
import lol.pyr.znpcsplus.interaction.ActionRegistry;
import lol.pyr.znpcsplus.interaction.InteractionPacketListener;
import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.metadata.*;
import lol.pyr.znpcsplus.npc.*;
import lol.pyr.znpcsplus.packets.*;
@ -117,7 +118,7 @@ public class ZNpcsPlus extends JavaPlugin {
log(ChatColor.WHITE + " * Registerring components...");
typeRegistry.registerDefault(packetEvents, propertyRegistry);
actionRegistry.registerTypes(npcRegistry, scheduler, adventure, bungeeConnector, textSerializer);
actionRegistry.registerTypes(scheduler, adventure, bungeeConnector, textSerializer);
packetEvents.getEventManager().registerListener(new InteractionPacketListener(userManager, npcRegistry), PacketListenerPriority.MONITOR);
new Metrics(this, PLUGIN_ID);
pluginManager.registerEvents(new UserListener(userManager), this);
@ -243,8 +244,9 @@ public class ZNpcsPlus extends JavaPlugin {
.addSubcommand("set", new HoloSetCommand(npcRegistry, textSerializer))
.addSubcommand("offset", new HoloOffsetCommand(npcRegistry)))
.addSubcommand("action", new MultiCommand()
.addSubcommand("add", new ActionAddCommand(actionRegistry))
.addSubcommand("add", new ActionAddCommand(npcRegistry, actionRegistry))
.addSubcommand("delete", new ActionDeleteCommand(npcRegistry))
.addSubcommand("edit", new ActionEditCommand(npcRegistry, actionRegistry))
.addSubcommand("list", new ActionListCommand()))
);
}

@ -44,8 +44,12 @@ public class PropertiesCommand implements CommandHandler {
valueName = bukkitStack.toString();
}
}
else if (type == NamedTextColor.class && context.argSize() < 1 && npc.getProperty(property) != null) {
value = null;
valueName = "NONE";
}
else {
value = context.parse(property.getType());
value = context.parse(type);
valueName = String.valueOf(value);
}

@ -51,7 +51,7 @@ public class SkinCommand implements CommandHandler {
String name = context.dumpAllArgs();
context.send(Component.text("Fetching skin \"" + name + "\"...", NamedTextColor.GREEN));
PrefetchedDescriptor.forPlayer(skinCache, name).thenAccept(skin -> {
if (skin == null) {
if (skin.getSkin() == null) {
context.send(Component.text("Failed to fetch skin, are you sure the player name is valid?", NamedTextColor.RED));
return;
}

@ -5,6 +5,9 @@ import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.interaction.ActionRegistry;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -13,19 +16,22 @@ import java.util.List;
import java.util.stream.Collectors;
public class ActionAddCommand implements CommandHandler {
private final NpcRegistryImpl npcRegistry;
private final ActionRegistry actionRegistry;
public ActionAddCommand(ActionRegistry actionRegistry) {
public ActionAddCommand(NpcRegistryImpl npcRegistry, ActionRegistry actionRegistry) {
this.npcRegistry = npcRegistry;
this.actionRegistry = actionRegistry;
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
List<InteractionCommandHandler> commands = actionRegistry.getCommands();
context.setUsage(context.getLabel() + " action add <action type>");
context.setUsage(context.getLabel() + " action add <id> <action type> ...");
NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc();
String sub = context.popString();
for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) {
command.run(context);
command.parse(context, npc);
return;
}
context.send(Component.text("Invalid action type, available action types:\n" +
@ -34,8 +40,10 @@ public class ActionAddCommand implements CommandHandler {
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
List<InteractionCommandHandler> commands = actionRegistry.getCommands();
if (context.argSize() == 1) return context.suggestStream(commands.stream().map(InteractionCommandHandler::getSubcommandName));
if (context.argSize() == 2) return context.suggestStream(commands.stream().map(InteractionCommandHandler::getSubcommandName));
context.popString();
String sub = context.popString();
for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) return command.suggest(context);
return Collections.emptyList();

@ -0,0 +1,64 @@
package lol.pyr.znpcsplus.commands.action;
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.interaction.ActionRegistry;
import lol.pyr.znpcsplus.interaction.InteractionAction;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ActionEditCommand implements CommandHandler {
private final NpcRegistryImpl npcRegistry;
private final ActionRegistry actionRegistry;
private InteractionCommandHandler commandHandler = null;
public ActionEditCommand(NpcRegistryImpl npcRegistry, ActionRegistry actionRegistry) {
this.npcRegistry = npcRegistry;
this.actionRegistry = actionRegistry;
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getLabel() + " action edit <id> <action id> <action type> ...");
NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
int index = context.parse(Integer.class);
if (index >= entry.getNpc().getActions().size() || index < 0) context.halt(Component.text("That npc doesn't have any action with the index " + index, NamedTextColor.RED));
List<InteractionCommandHandler> commands = actionRegistry.getCommands();
String sub = context.popString();
for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) {
this.commandHandler = command;
}
if (this.commandHandler == null) {
context.send(Component.text("Invalid action type, available action types:\n" +
commands.stream().map(InteractionCommandHandler::getSubcommandName).collect(Collectors.joining(", ")), NamedTextColor.RED));
}
InteractionAction newAction = this.commandHandler.parse(context, null);
entry.getNpc().editAction(index, newAction);
context.send(Component.text("Edited action with index " + index + " of Npc " + entry.getId(), NamedTextColor.GREEN));
}
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1)
.limit(context.suggestionParse(0, NpcEntryImpl.class).getNpc().getActions().size())
.map(String::valueOf));
List<InteractionCommandHandler> commands = actionRegistry.getCommands();
if (context.argSize() == 3) return context.suggestStream(commands.stream().map(InteractionCommandHandler::getSubcommandName));
context.popString();
context.popString();
String sub = context.popString();
for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) return command.suggest(context);
return Collections.emptyList();
}
}

@ -31,6 +31,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
registerType("skin", SkinDescriptor.class);
registerType("name", Component.class);
registerType("look", false);
registerType("cape", true);
registerType("helmet", ItemStack.class);
registerType("chestplate", ItemStack.class);

@ -4,7 +4,6 @@ import lol.pyr.znpcsplus.interaction.consolecommand.ConsoleCommandActionType;
import lol.pyr.znpcsplus.interaction.message.MessageActionType;
import lol.pyr.znpcsplus.interaction.playercommand.PlayerCommandActionType;
import lol.pyr.znpcsplus.interaction.switchserver.SwitchServerActionType;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
import lol.pyr.znpcsplus.util.BungeeConnector;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
@ -22,11 +21,11 @@ public class ActionRegistry {
public ActionRegistry() {
}
public void registerTypes(NpcRegistryImpl npcRegistry, TaskScheduler taskScheduler, BukkitAudiences adventure, BungeeConnector bungeeConnector, LegacyComponentSerializer textSerializer) {
register(new ConsoleCommandActionType(taskScheduler, npcRegistry));
register(new PlayerCommandActionType(taskScheduler, npcRegistry));
register(new SwitchServerActionType(bungeeConnector, npcRegistry));
register(new MessageActionType(adventure, textSerializer, npcRegistry));
public void registerTypes(TaskScheduler taskScheduler, BukkitAudiences adventure, BungeeConnector bungeeConnector, LegacyComponentSerializer textSerializer) {
register(new ConsoleCommandActionType(taskScheduler));
register(new PlayerCommandActionType(taskScheduler));
register(new SwitchServerActionType(bungeeConnector));
register(new MessageActionType(adventure, textSerializer));
}
public void register(InteractionActionType<?> type) {

@ -1,7 +1,12 @@
package lol.pyr.znpcsplus.interaction;
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.npc.NpcImpl;
public interface InteractionCommandHandler extends CommandHandler {
String getSubcommandName();
InteractionAction parse(CommandContext context, NpcImpl npc) throws CommandExecutionException;
}

@ -2,11 +2,11 @@ package lol.pyr.znpcsplus.interaction.consolecommand;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.interaction.InteractionAction;
import lol.pyr.znpcsplus.interaction.InteractionActionType;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -18,11 +18,9 @@ import java.util.List;
public class ConsoleCommandActionType implements InteractionActionType<ConsoleCommandAction>, InteractionCommandHandler {
private final TaskScheduler scheduler;
private final NpcRegistryImpl npcRegistry;
public ConsoleCommandActionType(TaskScheduler scheduler, NpcRegistryImpl npcRegistry) {
public ConsoleCommandActionType(TaskScheduler scheduler) {
this.scheduler = scheduler;
this.npcRegistry = npcRegistry;
}
@Override
@ -48,21 +46,28 @@ public class ConsoleCommandActionType implements InteractionActionType<ConsoleCo
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getUsage() + " consolecommand <id> <type> <cooldown seconds> <command>");
NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
public InteractionAction parse(CommandContext context, NpcImpl npc) throws CommandExecutionException {
context.setUsage(context.getUsage() + getSubcommandName() + " <type> <cooldown seconds> <command>");
InteractionType type = context.parse(InteractionType.class);
long cooldown = (long) (context.parse(Double.class) * 1000D);
String command = context.dumpAllArgs();
entry.getNpc().addAction(new ConsoleCommandAction(scheduler, command, type, cooldown));
context.send(Component.text("Added a console command action to the npc with the command " + command, NamedTextColor.GREEN));
ConsoleCommandAction action = new ConsoleCommandAction(scheduler, command, type, cooldown);
if (npc != null) {
npc.addAction(action);
context.send(Component.text("Added a console command action to the npc with the command " + action.getCommand(), NamedTextColor.GREEN));
}
return action;
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
}
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
if (context.argSize() == 2) return context.suggestEnum(InteractionType.values());
if (context.argSize() == 3) return context.suggestLiteral("1");
if (context.argSize() == 1) return context.suggestEnum(InteractionType.values());
if (context.argSize() == 2) return context.suggestLiteral("1");
return Collections.emptyList();
}
}

@ -3,10 +3,10 @@ package lol.pyr.znpcsplus.interaction.message;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.interaction.InteractionAction;
import lol.pyr.znpcsplus.interaction.InteractionActionType;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -20,12 +20,10 @@ import java.util.List;
public class MessageActionType implements InteractionActionType<MessageAction>, InteractionCommandHandler {
private final BukkitAudiences adventure;
private final LegacyComponentSerializer textSerializer;
private final NpcRegistryImpl npcRegistry;
public MessageActionType(BukkitAudiences adventure, LegacyComponentSerializer textSerializer, NpcRegistryImpl npcRegistry) {
public MessageActionType(BukkitAudiences adventure, LegacyComponentSerializer textSerializer) {
this.adventure = adventure;
this.textSerializer = textSerializer;
this.npcRegistry = npcRegistry;
}
@Override
@ -51,21 +49,28 @@ public class MessageActionType implements InteractionActionType<MessageAction>,
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getUsage() + " message <id> <type> <cooldown seconds> <message>");
NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
public InteractionAction parse(CommandContext context, NpcImpl npc) throws CommandExecutionException {
context.setUsage(context.getUsage() + " <type> <cooldown seconds> <message>");
InteractionType type = context.parse(InteractionType.class);
long cooldown = (long) (context.parse(Double.class) * 1000D);
String message = context.dumpAllArgs();
entry.getNpc().addAction(new MessageAction(adventure, message, type, textSerializer, cooldown));
MessageAction action = new MessageAction(adventure, message, type, textSerializer, cooldown);
if (npc != null) {
npc.addAction(action);
context.send(Component.text("Added a message action to the npc with the message ", NamedTextColor.GREEN).append(Component.text(message)));
}
return action;
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
}
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
if (context.argSize() == 2) return context.suggestEnum(InteractionType.values());
if (context.argSize() == 3) return context.suggestLiteral("1");
if (context.argSize() == 1) return context.suggestEnum(InteractionType.values());
if (context.argSize() == 2) return context.suggestLiteral("1");
return Collections.emptyList();
}
}

@ -2,11 +2,11 @@ package lol.pyr.znpcsplus.interaction.playercommand;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.interaction.InteractionAction;
import lol.pyr.znpcsplus.interaction.InteractionActionType;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -18,11 +18,9 @@ import java.util.List;
public class PlayerCommandActionType implements InteractionActionType<PlayerCommandAction>, InteractionCommandHandler {
private final TaskScheduler scheduler;
private final NpcRegistryImpl npcRegistry;
public PlayerCommandActionType(TaskScheduler scheduler, NpcRegistryImpl npcRegistry) {
public PlayerCommandActionType(TaskScheduler scheduler) {
this.scheduler = scheduler;
this.npcRegistry = npcRegistry;
}
@Override
@ -48,21 +46,28 @@ public class PlayerCommandActionType implements InteractionActionType<PlayerComm
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getUsage() + " playercommand <id> <type> <cooldown seconds> <command>");
NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
public InteractionAction parse(CommandContext context, NpcImpl npc) throws CommandExecutionException {
context.setUsage(context.getUsage() + getSubcommandName() + " <type> <cooldown seconds> <command>");
InteractionType type = context.parse(InteractionType.class);
long cooldown = (long) (context.parse(Double.class) * 1000D);
String command = context.dumpAllArgs();
entry.getNpc().addAction(new PlayerCommandAction(scheduler, command, type, cooldown));
context.send(Component.text("Added a player command action to the npc with the command " + command, NamedTextColor.GREEN));
PlayerCommandAction action = new PlayerCommandAction(scheduler, command, type, cooldown);
if (npc != null) {
npc.addAction(action);
context.send(Component.text("Added a player command action to the npc with the command " + action.getCommand(), NamedTextColor.GREEN));
}
return action;
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
}
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
if (context.argSize() == 2) return context.suggestEnum(InteractionType.values());
if (context.argSize() == 3) return context.suggestLiteral("1");
if (context.argSize() == 1) return context.suggestEnum(InteractionType.values());
if (context.argSize() == 2) return context.suggestLiteral("1");
return Collections.emptyList();
}
}

@ -2,11 +2,11 @@ package lol.pyr.znpcsplus.interaction.switchserver;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.interaction.InteractionAction;
import lol.pyr.znpcsplus.interaction.InteractionActionType;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.util.BungeeConnector;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -18,11 +18,9 @@ import java.util.List;
public class SwitchServerActionType implements InteractionActionType<SwitchServerAction>, InteractionCommandHandler {
private final BungeeConnector bungeeConnector;
private final NpcRegistryImpl npcRegistry;
public SwitchServerActionType(BungeeConnector bungeeConnector, NpcRegistryImpl npcRegistry) {
public SwitchServerActionType(BungeeConnector bungeeConnector) {
this.bungeeConnector = bungeeConnector;
this.npcRegistry = npcRegistry;
}
@Override
@ -48,21 +46,28 @@ public class SwitchServerActionType implements InteractionActionType<SwitchServe
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getUsage() + " switchserver <id> <type> <cooldown seconds> <server>");
NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
public InteractionAction parse(CommandContext context, NpcImpl npc) throws CommandExecutionException {
context.setUsage(context.getUsage() +getSubcommandName() + " <type> <cooldown seconds> <server>");
InteractionType type = context.parse(InteractionType.class);
long cooldown = (long) (context.parse(Double.class) * 1000D);
String server = context.dumpAllArgs();
entry.getNpc().addAction(new SwitchServerAction(bungeeConnector, server, type, cooldown));
context.send(Component.text("Added a switch server action to the npc with the server " + server, NamedTextColor.GREEN));
SwitchServerAction action = new SwitchServerAction(bungeeConnector, server, type, cooldown);
if (npc != null) {
npc.addAction(action);
context.send(Component.text("Added a switch server action to the npc with the server " + action.getServer(), NamedTextColor.GREEN));
}
return action;
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
}
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
if (context.argSize() == 2) return context.suggestEnum(InteractionType.values());
if (context.argSize() == 3) return context.suggestLiteral("1");
if (context.argSize() == 1) return context.suggestEnum(InteractionType.values());
if (context.argSize() == 2) return context.suggestLiteral("1");
return Collections.emptyList();
}
}

@ -6,21 +6,21 @@ import net.kyori.adventure.text.Component;
import java.util.Collection;
/**
* 1.8 https://wiki.vg/index.php?title=Entity_metadata&oldid=7415
* 1.9 https://wiki.vg/index.php?title=Entity_metadata&oldid=7968
* 1.10 https://wiki.vg/index.php?title=Entity_metadata&oldid=8241
* 1.11 https://wiki.vg/index.php?title=Entity_metadata&oldid=8534
* 1.12 https://wiki.vg/index.php?title=Entity_metadata&oldid=14048
* 1.13 https://wiki.vg/index.php?title=Entity_metadata&oldid=14800
* 1.14 https://wiki.vg/index.php?title=Entity_metadata&oldid=15240
* 1.15 https://wiki.vg/index.php?title=Entity_metadata&oldid=15991
* 1.16 https://wiki.vg/index.php?title=Entity_metadata&oldid=16539
* 1.17 https://wiki.vg/index.php?title=Entity_metadata&oldid=17521
* 1.18 NOTHING CHANGED
* 1.19 https://wiki.vg/index.php?title=Entity_metadata
* 1.8 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=7415">...</a>
* 1.9 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=7968">...</a>
* 1.10 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=8241">...</a>
* 1.11 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=8534">...</a>
* 1.12 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=14048">...</a>
* 1.13 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=14800">...</a>
* 1.14 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=15240">...</a>
* 1.15 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=15991">...</a>
* 1.16 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=16539">...</a>
* 1.17 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=17521">...</a>
* 1.18-1.19 <a href="https://wiki.vg/index.php?title=Entity_metadata">...</a>
*/
public interface MetadataFactory {
EntityData skinLayers(boolean enabled);
EntityData cape(boolean enabled);
EntityData effects(boolean onFire, boolean glowing, boolean invisible);
EntityData silent(boolean enabled);
Collection<EntityData> name(Component name);

@ -4,6 +4,11 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
public class V1_10MetadataFactory extends V1_9MetadataFactory {
@Override
public EntityData cape(boolean enabled) {
return createCape(13, enabled);
}
@Override
public EntityData noGravity() {
return new EntityData(5, EntityDataTypes.BOOLEAN, true);

@ -7,4 +7,9 @@ public class V1_14MetadataFactory extends V1_13MetadataFactory {
public EntityData skinLayers(boolean enabled) {
return createSkinLayers(15, enabled);
}
@Override
public EntityData cape(boolean enabled) {
return createCape(15, enabled);
}
}

@ -0,0 +1,12 @@
package lol.pyr.znpcsplus.metadata;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
public class V1_15MetadataFactory extends V1_14MetadataFactory {
@Override
public EntityData cape(boolean enabled) {
return createCape(16, enabled);
}
}

@ -2,7 +2,7 @@ package lol.pyr.znpcsplus.metadata;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
public class V1_16MetadataFactory extends V1_14MetadataFactory {
public class V1_16MetadataFactory extends V1_15MetadataFactory {
@Override
public EntityData skinLayers(boolean enabled) {
return createSkinLayers(16, enabled);

@ -7,4 +7,9 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory {
public EntityData skinLayers(boolean enabled) {
return createSkinLayers(17, enabled);
}
@Override
public EntityData cape(boolean enabled) {
return createCape(17, enabled);
}
}

@ -14,6 +14,11 @@ public class V1_8MetadataFactory implements MetadataFactory {
return createSkinLayers(12, enabled);
}
@Override
public EntityData cape(boolean enabled) {
return createCape(10, enabled);
}
@Override
public EntityData effects(boolean onFire, boolean glowing, boolean invisible) {
return new EntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0)));
@ -40,4 +45,8 @@ public class V1_8MetadataFactory implements MetadataFactory {
protected EntityData createSkinLayers(int index, boolean enabled) {
return new EntityData(index, EntityDataTypes.BYTE, enabled ? Byte.MAX_VALUE : 0);
}
protected EntityData createCape(int index, boolean enabled) {
return new EntityData(index, EntityDataTypes.BYTE, (byte) (enabled ? 0x01 : 0));
}
}

@ -14,6 +14,11 @@ public class V1_9MetadataFactory extends V1_8MetadataFactory {
return createSkinLayers(13, enabled);
}
@Override
public EntityData cape(boolean enabled) {
return createCape(12, enabled);
}
@Override
public EntityData effects(boolean onFire, boolean glowing, boolean invisible) {
return new EntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0) | (glowing ? 0x40 : 0)));

@ -146,4 +146,8 @@ public class NpcImpl extends Viewable implements Npc {
public void addAction(InteractionAction action) {
actions.add(action);
}
public void editAction(int index, InteractionAction action) {
actions.set(index, action);
}
}

@ -76,6 +76,7 @@ public class NpcTypeImpl implements NpcType {
allowedProperties.add(propertyRegistry.getByName("invisible"));
allowedProperties.add(propertyRegistry.getByName("silent"));
allowedProperties.add(propertyRegistry.getByName("look"));
allowedProperties.add(propertyRegistry.getByName("cape"));
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9))
allowedProperties.add(propertyRegistry.getByName("glow"));
return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties));

@ -126,7 +126,10 @@ public class V1_8PacketFactory implements PacketFactory {
@Override
public Map<Integer, EntityData> generateMetadata(Player player, PacketEntity entity, PropertyHolder properties) {
HashMap<Integer, EntityData> data = new HashMap<>();
if (entity.getType() == EntityTypes.PLAYER) add(data, metadataFactory.skinLayers(properties.getProperty(propertyRegistry.getByName("skin_layers", Boolean.class))));
if (entity.getType() == EntityTypes.PLAYER) {
add(data, metadataFactory.skinLayers(properties.getProperty(propertyRegistry.getByName("skin_layers", Boolean.class))));
add(data, metadataFactory.cape(properties.getProperty(propertyRegistry.getByName("cape", Boolean.class))));
}
add(data, metadataFactory.effects(properties.getProperty(propertyRegistry.getByName("fire", Boolean.class)), false, properties.getProperty(propertyRegistry.getByName("fire", Boolean.class))));
add(data, metadataFactory.silent(properties.getProperty(propertyRegistry.getByName("silent", Boolean.class))));
if (properties.hasProperty(propertyRegistry.getByName("name"))) addAll(data, metadataFactory.name(properties.getProperty(propertyRegistry.getByName("name", Component.class))));

@ -61,7 +61,7 @@ public class SkinCache {
}
} catch (IOException exception) {
if (!configManager.getConfig().disableSkinFetcherWarnings()) {
logger.warning("Failed to uuid from player name:");
logger.warning("Failed to get uuid from player name:");
exception.printStackTrace();
}
} finally {