Make naming conventions consistent

This commit is contained in:
Sparky983 2023-05-04 17:25:05 +10:00
parent fbe54b0a3c
commit 106129d39e
34 changed files with 159 additions and 158 deletions

@ -1,7 +1,7 @@
package lol.pyr.znpcsplus.api; package lol.pyr.znpcsplus.api;
import lol.pyr.znpcsplus.api.npc.NPCRegistry; import lol.pyr.znpcsplus.api.npc.NpcRegistry;
public interface ZApi { public interface ZApi {
NPCRegistry getNPCRegistry(); NpcRegistry getNpcRegistry();
} }

@ -3,6 +3,6 @@ package lol.pyr.znpcsplus.api.npc;
import lol.pyr.znpcsplus.api.hologram.Hologram; import lol.pyr.znpcsplus.api.hologram.Hologram;
import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.api.entity.PropertyHolder;
public interface NPC extends PropertyHolder { public interface Npc extends PropertyHolder {
Hologram getHologram(); Hologram getHologram();
} }

@ -1,7 +1,7 @@
package lol.pyr.znpcsplus.api.npc; package lol.pyr.znpcsplus.api.npc;
public interface NPCEntry { public interface NpcEntry {
NPC getNpc(); Npc getNpc();
boolean isProcessed(); boolean isProcessed();
void setProcessed(boolean value); void setProcessed(boolean value);

@ -5,10 +5,10 @@ import org.bukkit.World;
import java.util.Collection; import java.util.Collection;
public interface NPCRegistry { public interface NpcRegistry {
Collection<? extends NPCEntry> all(); Collection<? extends NpcEntry> all();
Collection<String> ids(); Collection<String> ids();
NPCEntry create(String id, World world, NPCType type, ZLocation location); NpcEntry create(String id, World world, NpcType type, ZLocation location);
NPCEntry get(String id); NpcEntry get(String id);
void delete(String id); void delete(String id);
} }

@ -8,14 +8,14 @@ import lol.pyr.znpcsplus.api.entity.EntityProperty;
import java.util.*; import java.util.*;
public class NPCType { public class NpcType {
private final static Map<String, NPCType> BY_NAME = new HashMap<>(); private final static Map<String, NpcType> BY_NAME = new HashMap<>();
public static Collection<NPCType> values() { public static Collection<NpcType> values() {
return BY_NAME.values(); return BY_NAME.values();
} }
public static NPCType byName(String name) { public static NpcType byName(String name) {
return BY_NAME.get(name.toUpperCase()); return BY_NAME.get(name.toUpperCase());
} }
@ -24,7 +24,7 @@ public class NPCType {
private final String name; private final String name;
private final double hologramOffset; private final double hologramOffset;
private NPCType(String name, EntityType type, double hologramOffset, Set<EntityProperty<?>> allowedProperties) { private NpcType(String name, EntityType type, double hologramOffset, Set<EntityProperty<?>> allowedProperties) {
this.name = name.toUpperCase(); this.name = name.toUpperCase();
this.type = type; this.type = type;
this.hologramOffset = hologramOffset; this.hologramOffset = hologramOffset;
@ -47,29 +47,29 @@ public class NPCType {
return allowedProperties; return allowedProperties;
} }
private static NPCType define(Builder builder) { private static NpcType define(Builder builder) {
return define(builder.build()); return define(builder.build());
} }
private static NPCType define(NPCType type) { private static NpcType define(NpcType type) {
BY_NAME.put(type.getName(), type); BY_NAME.put(type.getName(), type);
return type; return type;
} }
public static final NPCType PLAYER = define( public static final NpcType PLAYER = define(
new Builder("player", EntityTypes.PLAYER) new Builder("player", EntityTypes.PLAYER)
.addProperties(EntityProperty.SKIN, EntityProperty.SKIN_LAYERS) .addProperties(EntityProperty.SKIN, EntityProperty.SKIN_LAYERS)
.setHologramOffset(-0.45D)); .setHologramOffset(-0.45D));
public static final NPCType CREEPER = define( public static final NpcType CREEPER = define(
new Builder("creeper", EntityTypes.CREEPER) new Builder("creeper", EntityTypes.CREEPER)
.setHologramOffset(-0.6D)); .setHologramOffset(-0.6D));
public static final NPCType ZOMBIE = define( public static final NpcType ZOMBIE = define(
new Builder("zombie", EntityTypes.ZOMBIE) new Builder("zombie", EntityTypes.ZOMBIE)
.setHologramOffset(-0.3D)); .setHologramOffset(-0.3D));
public static final NPCType SKELETON = define( public static final NpcType SKELETON = define(
new Builder("skeleton", EntityTypes.SKELETON) new Builder("skeleton", EntityTypes.SKELETON)
.setHologramOffset(-0.3D)); .setHologramOffset(-0.3D));
@ -100,7 +100,7 @@ public class NPCType {
return this; return this;
} }
public NPCType build() { public NpcType build() {
if (globalProperties) { if (globalProperties) {
allowedProperties.add(EntityProperty.FIRE); allowedProperties.add(EntityProperty.FIRE);
allowedProperties.add(EntityProperty.INVISIBLE); allowedProperties.add(EntityProperty.INVISIBLE);
@ -108,7 +108,7 @@ public class NPCType {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9))
allowedProperties.add(EntityProperty.GLOW); allowedProperties.add(EntityProperty.GLOW);
} }
return new NPCType(name, type, hologramOffset, new HashSet<>(allowedProperties)); return new NpcType(name, type, hologramOffset, new HashSet<>(allowedProperties));
} }
} }
} }

@ -1,12 +0,0 @@
package lol.pyr.znpcsplus;
import lol.pyr.znpcsplus.api.ZApi;
import lol.pyr.znpcsplus.api.npc.NPCRegistry;
import lol.pyr.znpcsplus.npc.NPCRegistryImpl;
public class ZNPCsApi implements ZApi {
@Override
public NPCRegistry getNPCRegistry() {
return NPCRegistryImpl.get();
}
}

@ -0,0 +1,12 @@
package lol.pyr.znpcsplus;
import lol.pyr.znpcsplus.api.ZApi;
import lol.pyr.znpcsplus.api.npc.NpcRegistry;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
public class ZNpcsApi implements ZApi {
@Override
public NpcRegistry getNpcRegistry() {
return NpcRegistryImpl.get();
}
}

@ -8,14 +8,14 @@ import lol.pyr.director.adventure.command.CommandManager;
import lol.pyr.director.adventure.command.MultiCommand; import lol.pyr.director.adventure.command.MultiCommand;
import lol.pyr.znpcsplus.api.ZApiProvider; import lol.pyr.znpcsplus.api.ZApiProvider;
import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.api.npc.NPCType; import lol.pyr.znpcsplus.api.npc.NpcType;
import lol.pyr.znpcsplus.config.Configs; import lol.pyr.znpcsplus.config.Configs;
import lol.pyr.znpcsplus.interaction.InteractionPacketListener; import lol.pyr.znpcsplus.interaction.InteractionPacketListener;
import lol.pyr.znpcsplus.interaction.types.ConsoleCommandAction; import lol.pyr.znpcsplus.interaction.types.ConsoleCommandAction;
import lol.pyr.znpcsplus.interaction.types.MessageAction; import lol.pyr.znpcsplus.interaction.types.MessageAction;
import lol.pyr.znpcsplus.npc.NPCEntryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NPCImpl; import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NPCRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.scheduling.FoliaScheduler; import lol.pyr.znpcsplus.scheduling.FoliaScheduler;
import lol.pyr.znpcsplus.scheduling.SpigotScheduler; import lol.pyr.znpcsplus.scheduling.SpigotScheduler;
import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.scheduling.TaskScheduler;
@ -24,7 +24,7 @@ import lol.pyr.znpcsplus.skin.cache.SkinCacheCleanTask;
import lol.pyr.znpcsplus.skin.descriptor.FetchingDescriptor; import lol.pyr.znpcsplus.skin.descriptor.FetchingDescriptor;
import lol.pyr.znpcsplus.skin.descriptor.MirrorDescriptor; import lol.pyr.znpcsplus.skin.descriptor.MirrorDescriptor;
import lol.pyr.znpcsplus.skin.descriptor.PrefetchedDescriptor; import lol.pyr.znpcsplus.skin.descriptor.PrefetchedDescriptor;
import lol.pyr.znpcsplus.tasks.NPCVisibilityTask; import lol.pyr.znpcsplus.tasks.NpcVisibilityTask;
import lol.pyr.znpcsplus.updater.UpdateChecker; import lol.pyr.znpcsplus.updater.UpdateChecker;
import lol.pyr.znpcsplus.updater.UpdateNotificationListener; import lol.pyr.znpcsplus.updater.UpdateNotificationListener;
import lol.pyr.znpcsplus.user.User; import lol.pyr.znpcsplus.user.User;
@ -46,7 +46,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Logger; import java.util.logging.Logger;
public class ZNPCsPlus extends JavaPlugin { public class ZNpcsPlus extends JavaPlugin {
public static Logger LOGGER; public static Logger LOGGER;
public static File PLUGIN_FOLDER; public static File PLUGIN_FOLDER;
public static File PATH_FOLDER; public static File PATH_FOLDER;
@ -127,12 +127,12 @@ public class ZNPCsPlus extends JavaPlugin {
registerCommands(); registerCommands();
log(ChatColor.WHITE + " * Starting tasks..."); log(ChatColor.WHITE + " * Starting tasks...");
new NPCVisibilityTask(); new NpcVisibilityTask();
new SkinCacheCleanTask(); new SkinCacheCleanTask();
new UserListener(this); new UserListener(this);
if (Configs.config().checkForUpdates()) new UpdateNotificationListener(this, new UpdateChecker(this)); if (Configs.config().checkForUpdates()) new UpdateNotificationListener(this, new UpdateChecker(this));
ZApiProvider.register(new ZNPCsApi()); ZApiProvider.register(new ZNpcsApi());
enabled = true; enabled = true;
log(ChatColor.WHITE + " * Loading complete! (" + (System.currentTimeMillis() - before) + "ms)"); log(ChatColor.WHITE + " * Loading complete! (" + (System.currentTimeMillis() - before) + "ms)");
log(""); log("");
@ -143,10 +143,10 @@ public class ZNPCsPlus extends JavaPlugin {
int z = 0; int z = 0;
World world = Bukkit.getWorld("world"); World world = Bukkit.getWorld("world");
if (world == null) world = Bukkit.getWorlds().get(0); if (world == null) world = Bukkit.getWorlds().get(0);
for (NPCType type : NPCType.values()) { for (NpcType type : NpcType.values()) {
NPCEntryImpl entry = NPCRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, type, new ZLocation(x * 3, 200, z * 3, 0, 0)); NpcEntryImpl entry = NpcRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, type, new ZLocation(x * 3, 200, z * 3, 0, 0));
entry.setProcessed(true); entry.setProcessed(true);
NPCImpl npc = entry.getNpc(); NpcImpl npc = entry.getNpc();
if (type.getType() == EntityTypes.PLAYER) { if (type.getType() == EntityTypes.PLAYER) {
SkinCache.fetchByName("Notch").thenAccept(skin -> npc.setProperty(EntityProperty.SKIN, new PrefetchedDescriptor(skin))); SkinCache.fetchByName("Notch").thenAccept(skin -> npc.setProperty(EntityProperty.SKIN, new PrefetchedDescriptor(skin)));
npc.setProperty(EntityProperty.INVISIBLE, true); npc.setProperty(EntityProperty.INVISIBLE, true);
@ -159,13 +159,13 @@ public class ZNPCsPlus extends JavaPlugin {
z++; z++;
} }
} }
NPCEntryImpl entry = NPCRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, NPCType.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0)); NpcEntryImpl entry = NpcRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, NpcType.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0));
entry.setProcessed(true); entry.setProcessed(true);
NPCImpl npc = entry.getNpc(); NpcImpl npc = entry.getNpc();
npc.setProperty(EntityProperty.SKIN, new FetchingDescriptor("jeb_")); npc.setProperty(EntityProperty.SKIN, new FetchingDescriptor("jeb_"));
npc.addAction(new MessageAction(1000L, "<red>Hi, I'm jeb!")); npc.addAction(new MessageAction(1000L, "<red>Hi, I'm jeb!"));
x++; x++;
entry = NPCRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, NPCType.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0)); entry = NpcRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, NpcType.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0));
entry.setProcessed(true); entry.setProcessed(true);
npc = entry.getNpc(); npc = entry.getNpc();
npc.setProperty(EntityProperty.SKIN, new MirrorDescriptor()); npc.setProperty(EntityProperty.SKIN, new MirrorDescriptor());

@ -3,12 +3,12 @@ package lol.pyr.znpcsplus.command;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.npc.NPCRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
public class CreateCommand implements CommandHandler { public class CreateCommand implements CommandHandler {
@Override @Override
public void run(CommandContext context) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
String id = context.popString(); String id = context.popString();
NPCRegistryImpl.get().get(id); NpcRegistryImpl.get().get(id);
} }
} }

@ -1,6 +1,6 @@
package lol.pyr.znpcsplus.config; package lol.pyr.znpcsplus.config;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import space.arim.dazzleconf.ConfigurationFactory; import space.arim.dazzleconf.ConfigurationFactory;
import space.arim.dazzleconf.ConfigurationOptions; import space.arim.dazzleconf.ConfigurationOptions;
import space.arim.dazzleconf.error.ConfigFormatSyntaxException; import space.arim.dazzleconf.error.ConfigFormatSyntaxException;
@ -40,13 +40,13 @@ public class Configs {
config = configHelper.reloadConfigData(); config = configHelper.reloadConfigData();
messages = messagesHelper.reloadConfigData(); messages = messagesHelper.reloadConfigData();
} catch (IOException e) { } catch (IOException e) {
ZNPCsPlus.LOGGER.severe("Couldn't open config file!"); ZNpcsPlus.LOGGER.severe("Couldn't open config file!");
e.printStackTrace(); e.printStackTrace();
} catch (ConfigFormatSyntaxException e) { } catch (ConfigFormatSyntaxException e) {
ZNPCsPlus.LOGGER.severe("Invalid config syntax!"); ZNpcsPlus.LOGGER.severe("Invalid config syntax!");
e.printStackTrace(); e.printStackTrace();
} catch (InvalidConfigException e) { } catch (InvalidConfigException e) {
ZNPCsPlus.LOGGER.severe("Invalid config value!"); ZNpcsPlus.LOGGER.severe("Invalid config value!");
e.printStackTrace(); e.printStackTrace();
} }
} }

@ -4,9 +4,9 @@ import com.github.retrooper.packetevents.event.PacketListener;
import com.github.retrooper.packetevents.event.PacketReceiveEvent; import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType; import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity; import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;
import lol.pyr.znpcsplus.npc.NPCEntryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NPCImpl; import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NPCRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.user.User; import lol.pyr.znpcsplus.user.User;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -20,11 +20,11 @@ public class InteractionPacketListener implements PacketListener {
User user = User.get(player); User user = User.get(player);
if (!user.canInteract()) return; if (!user.canInteract()) return;
NPCEntryImpl entry = NPCRegistryImpl.get().getByEntityId(packet.getEntityId()); NpcEntryImpl entry = NpcRegistryImpl.get().getByEntityId(packet.getEntityId());
if (entry == null || !entry.isProcessed()) return; if (entry == null || !entry.isProcessed()) return;
NPCImpl npc = entry.getNpc(); NpcImpl npc = entry.getNpc();
for (NPCAction action : npc.getActions()) { for (NpcAction action : npc.getActions()) {
if (action.getCooldown() > 0 && !user.actionCooldownCheck(action)) continue; if (action.getCooldown() > 0 && !user.actionCooldownCheck(action)) continue;
action.run(player); action.run(player);
} }

@ -1,6 +0,0 @@
package lol.pyr.znpcsplus.interaction;
@FunctionalInterface
interface NPCActionDeserializer {
NPCAction deserialize(long delay, String argument);
}

@ -4,12 +4,12 @@ import org.bukkit.entity.Player;
import java.util.UUID; import java.util.UUID;
public abstract class NPCAction { public abstract class NpcAction {
private final UUID id; private final UUID id;
private final long delay; private final long delay;
protected final String argument; protected final String argument;
protected NPCAction(long delay, String argument) { protected NpcAction(long delay, String argument) {
this.id = UUID.randomUUID(); this.id = UUID.randomUUID();
this.delay = delay; this.delay = delay;
this.argument = argument; this.argument = argument;

@ -0,0 +1,6 @@
package lol.pyr.znpcsplus.interaction;
@FunctionalInterface
interface NpcActionDeserializer {
NpcAction deserialize(long delay, String argument);
}

@ -2,20 +2,20 @@ package lol.pyr.znpcsplus.interaction;
import lol.pyr.znpcsplus.interaction.types.*; import lol.pyr.znpcsplus.interaction.types.*;
public enum NPCActionType implements NPCActionDeserializer { public enum NpcActionType implements NpcActionDeserializer {
CONSOLE_CMD(ConsoleCommandAction::new), CONSOLE_CMD(ConsoleCommandAction::new),
MESSAGE(MessageAction::new), MESSAGE(MessageAction::new),
PLAYER_CMD(PlayerCommandAction::new), PLAYER_CMD(PlayerCommandAction::new),
SERVER(SwitchServerAction::new); SERVER(SwitchServerAction::new);
private final NPCActionDeserializer deserializer; private final NpcActionDeserializer deserializer;
NPCActionType(NPCActionDeserializer deserializer) { NpcActionType(NpcActionDeserializer deserializer) {
this.deserializer = deserializer; this.deserializer = deserializer;
} }
@Override @Override
public NPCAction deserialize(long delay, String str) { public NpcAction deserialize(long delay, String str) {
return deserializer.deserialize(delay, str); return deserializer.deserialize(delay, str);
} }
} }

@ -1,12 +1,12 @@
package lol.pyr.znpcsplus.interaction.types; package lol.pyr.znpcsplus.interaction.types;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.interaction.NPCAction; import lol.pyr.znpcsplus.interaction.NpcAction;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class ConsoleCommandAction extends NPCAction { public class ConsoleCommandAction extends NpcAction {
public ConsoleCommandAction(long delay, String argument) { public ConsoleCommandAction(long delay, String argument) {
super(delay, argument); super(delay, argument);
} }
@ -14,6 +14,6 @@ public class ConsoleCommandAction extends NPCAction {
@Override @Override
public void run(Player player) { public void run(Player player) {
String cmd = argument.replace("{player}", player.getName()).replace("{uuid}", player.getUniqueId().toString()); String cmd = argument.replace("{player}", player.getName()).replace("{uuid}", player.getUniqueId().toString());
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), ZNPCsPlus.PLACEHOLDERS_SUPPORTED ? PlaceholderAPI.setPlaceholders(player, cmd) : cmd); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), ZNpcsPlus.PLACEHOLDERS_SUPPORTED ? PlaceholderAPI.setPlaceholders(player, cmd) : cmd);
} }
} }

@ -1,12 +1,12 @@
package lol.pyr.znpcsplus.interaction.types; package lol.pyr.znpcsplus.interaction.types;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.interaction.NPCAction; import lol.pyr.znpcsplus.interaction.NpcAction;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class MessageAction extends NPCAction { public class MessageAction extends NpcAction {
private final Component message; private final Component message;
public MessageAction(long delay, String argument) { public MessageAction(long delay, String argument) {
@ -16,6 +16,6 @@ public class MessageAction extends NPCAction {
@Override @Override
public void run(Player player) { public void run(Player player) {
ZNPCsPlus.ADVENTURE.player(player).sendMessage(message); ZNpcsPlus.ADVENTURE.player(player).sendMessage(message);
} }
} }

@ -1,12 +1,12 @@
package lol.pyr.znpcsplus.interaction.types; package lol.pyr.znpcsplus.interaction.types;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.interaction.NPCAction; import lol.pyr.znpcsplus.interaction.NpcAction;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class PlayerCommandAction extends NPCAction { public class PlayerCommandAction extends NpcAction {
public PlayerCommandAction(long delay, String argument) { public PlayerCommandAction(long delay, String argument) {
super(delay, argument); super(delay, argument);
} }
@ -14,6 +14,6 @@ public class PlayerCommandAction extends NPCAction {
@Override @Override
public void run(Player player) { public void run(Player player) {
String cmd = argument.replace("{player}", player.getName()).replace("{uuid}", player.getUniqueId().toString()); String cmd = argument.replace("{player}", player.getName()).replace("{uuid}", player.getUniqueId().toString());
Bukkit.dispatchCommand(player, ZNPCsPlus.PLACEHOLDERS_SUPPORTED ? PlaceholderAPI.setPlaceholders(player, cmd) : cmd); Bukkit.dispatchCommand(player, ZNpcsPlus.PLACEHOLDERS_SUPPORTED ? PlaceholderAPI.setPlaceholders(player, cmd) : cmd);
} }
} }

@ -1,16 +1,16 @@
package lol.pyr.znpcsplus.interaction.types; package lol.pyr.znpcsplus.interaction.types;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.interaction.NPCAction; import lol.pyr.znpcsplus.interaction.NpcAction;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class SwitchServerAction extends NPCAction { public class SwitchServerAction extends NpcAction {
public SwitchServerAction(long delay, String argument) { public SwitchServerAction(long delay, String argument) {
super(delay, argument); super(delay, argument);
} }
@Override @Override
public void run(Player player) { public void run(Player player) {
ZNPCsPlus.BUNGEE_UTILS.sendPlayerToServer(player, argument); ZNpcsPlus.BUNGEE_UTILS.sendPlayerToServer(player, argument);
} }
} }

@ -3,7 +3,7 @@ package lol.pyr.znpcsplus.metadata;
import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.util.LazyLoader; import lol.pyr.znpcsplus.util.LazyLoader;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -42,7 +42,7 @@ public interface MetadataFactory {
if (v.isNewerThan(version)) continue; if (v.isNewerThan(version)) continue;
if (!factories.containsKey(v)) continue; if (!factories.containsKey(v)) continue;
MetadataFactory f = factories.get(v).get(); MetadataFactory f = factories.get(v).get();
ZNPCsPlus.debug("Using MetadataFactory Version " + v.name() + " (" + f.getClass().getName() + ")"); ZNpcsPlus.debug("Using MetadataFactory Version " + v.name() + " (" + f.getClass().getName() + ")");
return f; return f;
} }
throw new RuntimeException("Unsupported version!"); throw new RuntimeException("Unsupported version!");

@ -1,20 +1,20 @@
package lol.pyr.znpcsplus.npc; package lol.pyr.znpcsplus.npc;
import lol.pyr.znpcsplus.api.npc.NPCEntry; import lol.pyr.znpcsplus.api.npc.NpcEntry;
public class NPCEntryImpl implements NPCEntry { public class NpcEntryImpl implements NpcEntry {
private final NPCImpl npc; private final NpcImpl npc;
private boolean process = false; private boolean process = false;
private boolean save = false; private boolean save = false;
private boolean modify = false; private boolean modify = false;
public NPCEntryImpl(NPCImpl npc) { public NpcEntryImpl(NpcImpl npc) {
this.npc = npc; this.npc = npc;
} }
@Override @Override
public NPCImpl getNpc() { public NpcImpl getNpc() {
return npc; return npc;
} }

@ -1,10 +1,11 @@
package lol.pyr.znpcsplus.npc; package lol.pyr.znpcsplus.npc;
import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.api.npc.NPCType; import lol.pyr.znpcsplus.api.npc.NpcType;
import lol.pyr.znpcsplus.api.npc.Npc;
import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.entity.PacketEntity;
import lol.pyr.znpcsplus.hologram.HologramImpl; import lol.pyr.znpcsplus.hologram.HologramImpl;
import lol.pyr.znpcsplus.interaction.NPCAction; import lol.pyr.znpcsplus.interaction.NpcAction;
import lol.pyr.znpcsplus.util.Viewable; import lol.pyr.znpcsplus.util.Viewable;
import lol.pyr.znpcsplus.util.ZLocation; import lol.pyr.znpcsplus.util.ZLocation;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -13,18 +14,18 @@ import org.bukkit.entity.Player;
import java.util.*; import java.util.*;
public class NPCImpl extends Viewable implements lol.pyr.znpcsplus.api.npc.NPC { public class NpcImpl extends Viewable implements Npc {
private final Set<Player> viewers = new HashSet<>(); private final Set<Player> viewers = new HashSet<>();
private final String worldName; private final String worldName;
private PacketEntity entity; private PacketEntity entity;
private ZLocation location; private ZLocation location;
private NPCType type; private NpcType type;
private final HologramImpl hologram; private final HologramImpl hologram;
private final Map<EntityProperty<?>, Object> propertyMap = new HashMap<>(); private final Map<EntityProperty<?>, Object> propertyMap = new HashMap<>();
private final Set<NPCAction> actions = new HashSet<>(); private final Set<NpcAction> actions = new HashSet<>();
protected NPCImpl(World world, NPCType type, ZLocation location) { protected NpcImpl(World world, NpcType type, ZLocation location) {
this.worldName = world.getName(); this.worldName = world.getName();
this.type = type; this.type = type;
this.location = location; this.location = location;
@ -32,14 +33,14 @@ public class NPCImpl extends Viewable implements lol.pyr.znpcsplus.api.npc.NPC {
hologram = new HologramImpl(location.withY(location.getY() + type.getHologramOffset())); hologram = new HologramImpl(location.withY(location.getY() + type.getHologramOffset()));
} }
public void setType(NPCType type) { public void setType(NpcType type) {
UNSAFE_hideAll(); UNSAFE_hideAll();
this.type = type; this.type = type;
entity = new PacketEntity(this, type.getType(), entity.getLocation()); entity = new PacketEntity(this, type.getType(), entity.getLocation());
UNSAFE_showAll(); UNSAFE_showAll();
} }
public NPCType getType() { public NpcType getType() {
return type; return type;
} }
@ -103,11 +104,11 @@ public class NPCImpl extends Viewable implements lol.pyr.znpcsplus.api.npc.NPC {
_refreshMeta(); _refreshMeta();
} }
public Collection<NPCAction> getActions() { public Collection<NpcAction> getActions() {
return Collections.unmodifiableSet(actions); return Collections.unmodifiableSet(actions);
} }
public void addAction(NPCAction action) { public void addAction(NpcAction action) {
actions.add(action); actions.add(action);
} }
} }

@ -1,7 +1,7 @@
package lol.pyr.znpcsplus.npc; package lol.pyr.znpcsplus.npc;
import lol.pyr.znpcsplus.api.npc.NPCRegistry; import lol.pyr.znpcsplus.api.npc.NpcRegistry;
import lol.pyr.znpcsplus.api.npc.NPCType; import lol.pyr.znpcsplus.api.npc.NpcType;
import lol.pyr.znpcsplus.util.ZLocation; import lol.pyr.znpcsplus.util.ZLocation;
import org.bukkit.World; import org.bukkit.World;
@ -10,28 +10,28 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class NPCRegistryImpl implements NPCRegistry { public class NpcRegistryImpl implements NpcRegistry {
private final static NPCRegistryImpl registry = new NPCRegistryImpl(); private final static NpcRegistryImpl registry = new NpcRegistryImpl();
public static NPCRegistryImpl get() { public static NpcRegistryImpl get() {
return registry; return registry;
} }
private NPCRegistryImpl() { private NpcRegistryImpl() {
if (registry != null) throw new UnsupportedOperationException("This class can only be instanciated once!"); if (registry != null) throw new UnsupportedOperationException("This class can only be instanciated once!");
} }
private final Map<String, NPCEntryImpl> npcMap = new HashMap<>(); private final Map<String, NpcEntryImpl> npcMap = new HashMap<>();
public NPCEntryImpl get(String id) { public NpcEntryImpl get(String id) {
return npcMap.get(id.toUpperCase()); return npcMap.get(id.toUpperCase());
} }
public Collection<NPCEntryImpl> all() { public Collection<NpcEntryImpl> all() {
return Collections.unmodifiableCollection(npcMap.values()); return Collections.unmodifiableCollection(npcMap.values());
} }
public NPCEntryImpl getByEntityId(int id) { public NpcEntryImpl getByEntityId(int id) {
return all().stream().filter(entry -> entry.getNpc().getEntity().getEntityId() == id).findFirst().orElse(null); return all().stream().filter(entry -> entry.getNpc().getEntity().getEntityId() == id).findFirst().orElse(null);
} }
@ -40,11 +40,11 @@ public class NPCRegistryImpl implements NPCRegistry {
} }
@Override @Override
public NPCEntryImpl create(String id, World world, NPCType type, ZLocation location) { public NpcEntryImpl create(String id, World world, NpcType type, ZLocation location) {
id = id.toUpperCase(); id = id.toUpperCase();
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(world, type, location); NpcImpl npc = new NpcImpl(world, type, location);
NPCEntryImpl entry = new NPCEntryImpl(npc); NpcEntryImpl entry = new NpcEntryImpl(npc);
npcMap.put(id, entry); npcMap.put(id, entry);
return entry; return entry;
} }

@ -3,7 +3,7 @@ package lol.pyr.znpcsplus.packets;
import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.entity.PacketEntity;
import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.api.entity.PropertyHolder;
import lol.pyr.znpcsplus.util.LazyLoader; import lol.pyr.znpcsplus.util.LazyLoader;
@ -37,7 +37,7 @@ public interface PacketFactory {
if (v.isNewerThan(version)) continue; if (v.isNewerThan(version)) continue;
if (!factories.containsKey(v)) continue; if (!factories.containsKey(v)) continue;
PacketFactory f = factories.get(v).get(); PacketFactory f = factories.get(v).get();
ZNPCsPlus.debug("Using PacketFactory Version " + v.name() + " (" + f.getClass().getName() + ")"); ZNpcsPlus.debug("Using PacketFactory Version " + v.name() + " (" + f.getClass().getName() + ")");
return f; return f;
} }
throw new RuntimeException("Unsupported version!"); throw new RuntimeException("Unsupported version!");

@ -10,7 +10,7 @@ import com.github.retrooper.packetevents.protocol.player.UserProfile;
import com.github.retrooper.packetevents.util.Vector3d; import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.wrapper.PacketWrapper; import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.github.retrooper.packetevents.wrapper.play.server.*; import com.github.retrooper.packetevents.wrapper.play.server.*;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.api.entity.PropertyHolder;
import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.entity.PacketEntity;
@ -36,7 +36,7 @@ public class V1_8Factory implements PacketFactory {
sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(), sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(),
entity.getUuid(), location.toVector3d(), location.getYaw(), location.getPitch(), Collections.emptyList())); entity.getUuid(), location.toVector3d(), location.getYaw(), location.getPitch(), Collections.emptyList()));
sendAllMetadata(player, entity, properties); sendAllMetadata(player, entity, properties);
ZNPCsPlus.SCHEDULER.runLaterAsync(() -> removeTabPlayer(player, entity), 60); ZNpcsPlus.SCHEDULER.runLaterAsync(() -> removeTabPlayer(player, entity), 60);
}); });
} }

@ -1,7 +1,7 @@
package lol.pyr.znpcsplus.reflection; package lol.pyr.znpcsplus.reflection;
import lol.pyr.znpcsplus.util.VersionUtil; import lol.pyr.znpcsplus.util.VersionUtil;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -50,9 +50,9 @@ public abstract class ReflectionLazyLoader<T> {
} }
private void warn(String message) { private void warn(String message) {
ZNPCsPlus.LOGGER.warning("[Reflection] " + message); ZNpcsPlus.LOGGER.warning("[Reflection] " + message);
} }
protected abstract T load() throws Exception; protected abstract T load() throws Exception;
protected void printDebugInfo(Consumer<String> logger) {} protected void printDebugInfo(Consumer<String> logger) {}
} }

@ -1,11 +1,11 @@
package lol.pyr.znpcsplus.skin.cache; package lol.pyr.znpcsplus.skin.cache;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class SkinCacheCleanTask extends BukkitRunnable { public class SkinCacheCleanTask extends BukkitRunnable {
public SkinCacheCleanTask() { public SkinCacheCleanTask() {
ZNPCsPlus.SCHEDULER.runDelayedTimerAsync(this, 1200, 1200); ZNpcsPlus.SCHEDULER.runDelayedTimerAsync(this, 1200, 1200);
} }
@Override @Override

@ -1,6 +1,6 @@
package lol.pyr.znpcsplus.skin.descriptor; package lol.pyr.znpcsplus.skin.descriptor;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.api.skin.SkinDescriptor; import lol.pyr.znpcsplus.api.skin.SkinDescriptor;
import lol.pyr.znpcsplus.skin.BaseSkinDescriptor; import lol.pyr.znpcsplus.skin.BaseSkinDescriptor;
import lol.pyr.znpcsplus.skin.Skin; import lol.pyr.znpcsplus.skin.Skin;
@ -33,7 +33,7 @@ public class FetchingDescriptor implements BaseSkinDescriptor, SkinDescriptor {
} }
private String papi(Player player) { private String papi(Player player) {
if (ZNPCsPlus.PLACEHOLDERS_SUPPORTED) return PlaceholderAPI.setPlaceholders(player, name); if (ZNpcsPlus.PLACEHOLDERS_SUPPORTED) return PlaceholderAPI.setPlaceholders(player, name);
return name; return name;
} }
} }

@ -1,25 +1,25 @@
package lol.pyr.znpcsplus.tasks; package lol.pyr.znpcsplus.tasks;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.config.Configs; import lol.pyr.znpcsplus.config.Configs;
import lol.pyr.znpcsplus.npc.NPCEntryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NPCImpl; import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NPCRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.NumberConversions; import org.bukkit.util.NumberConversions;
public class NPCVisibilityTask extends BukkitRunnable { public class NpcVisibilityTask extends BukkitRunnable {
public NPCVisibilityTask() { public NpcVisibilityTask() {
ZNPCsPlus.SCHEDULER.runDelayedTimerAsync(this, 60L, 10L); ZNpcsPlus.SCHEDULER.runDelayedTimerAsync(this, 60L, 10L);
} }
public void run() { public void run() {
double distSq = NumberConversions.square(Configs.config().viewDistance()); double distSq = NumberConversions.square(Configs.config().viewDistance());
for (NPCEntryImpl entry : NPCRegistryImpl.get().all()) { for (NpcEntryImpl entry : NpcRegistryImpl.get().all()) {
if (!entry.isProcessed()) continue; if (!entry.isProcessed()) continue;
NPCImpl npc = entry.getNpc(); NpcImpl npc = entry.getNpc();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
boolean inRange = (player.getWorld() == npc.getWorld() && player.getLocation().distanceSquared(npc.getLocation().toBukkitLocation(npc.getWorld())) <= distSq); boolean inRange = (player.getWorld() == npc.getWorld() && player.getLocation().distanceSquared(npc.getLocation().toBukkitLocation(npc.getWorld())) <= distSq);
if (!inRange && npc.isShown(player)) npc.hide(player); if (!inRange && npc.isShown(player)) npc.hide(player);

@ -1,6 +1,6 @@
package lol.pyr.znpcsplus.updater; package lol.pyr.znpcsplus.updater;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import me.robertlit.spigotresources.api.Resource; import me.robertlit.spigotresources.api.Resource;
import me.robertlit.spigotresources.api.SpigotResourcesAPI; import me.robertlit.spigotresources.api.SpigotResourcesAPI;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -12,13 +12,13 @@ public class UpdateChecker extends BukkitRunnable {
public final static int RESOURCE_ID = 109380; public final static int RESOURCE_ID = 109380;
public final static String DOWNLOAD_LINK = "https://www.spigotmc.org/resources/znpcsplus.109380/"; public final static String DOWNLOAD_LINK = "https://www.spigotmc.org/resources/znpcsplus.109380/";
private final ZNPCsPlus plugin; private final ZNpcsPlus plugin;
private Status status = Status.UNKNOWN; private Status status = Status.UNKNOWN;
private String newestVersion = "N/A"; private String newestVersion = "N/A";
public UpdateChecker(ZNPCsPlus plugin) { public UpdateChecker(ZNpcsPlus plugin) {
this.plugin = plugin; this.plugin = plugin;
ZNPCsPlus.SCHEDULER.runDelayedTimerAsync(this, 5L, 6000L); ZNpcsPlus.SCHEDULER.runDelayedTimerAsync(this, 5L, 6000L);
} }
public void run() { public void run() {
@ -34,8 +34,8 @@ public class UpdateChecker extends BukkitRunnable {
} }
private void notifyConsole() { private void notifyConsole() {
ZNPCsPlus.LOGGER.warning("Version " + getLatestVersion() + " of " + plugin.getDescription().getName() + " is available now!"); ZNpcsPlus.LOGGER.warning("Version " + getLatestVersion() + " of " + plugin.getDescription().getName() + " is available now!");
ZNPCsPlus.LOGGER.warning("Download it at " + UpdateChecker.DOWNLOAD_LINK); ZNpcsPlus.LOGGER.warning("Download it at " + UpdateChecker.DOWNLOAD_LINK);
} }
private int versionToNumber(String version) { private int versionToNumber(String version) {

@ -1,6 +1,6 @@
package lol.pyr.znpcsplus.updater; package lol.pyr.znpcsplus.updater;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
@ -10,10 +10,10 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
public class UpdateNotificationListener implements Listener { public class UpdateNotificationListener implements Listener {
private final ZNPCsPlus plugin; private final ZNpcsPlus plugin;
private final UpdateChecker updateChecker; private final UpdateChecker updateChecker;
public UpdateNotificationListener(ZNPCsPlus plugin, UpdateChecker updateChecker) { public UpdateNotificationListener(ZNpcsPlus plugin, UpdateChecker updateChecker) {
this.plugin = plugin; this.plugin = plugin;
this.updateChecker = updateChecker; this.updateChecker = updateChecker;
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getServer().getPluginManager().registerEvents(this, plugin);
@ -25,7 +25,7 @@ public class UpdateNotificationListener implements Listener {
if (updateChecker.getStatus() != UpdateChecker.Status.UPDATE_NEEDED) return; if (updateChecker.getStatus() != UpdateChecker.Status.UPDATE_NEEDED) return;
Bukkit.getScheduler().runTaskLater(plugin, () -> { Bukkit.getScheduler().runTaskLater(plugin, () -> {
if (!event.getPlayer().isOnline()) return; if (!event.getPlayer().isOnline()) return;
ZNPCsPlus.ADVENTURE.player(event.getPlayer()) ZNpcsPlus.ADVENTURE.player(event.getPlayer())
.sendMessage(Component.text(plugin.getDescription().getName() + " v" + updateChecker.getLatestVersion() + " is available now!", NamedTextColor.GOLD).appendNewline() .sendMessage(Component.text(plugin.getDescription().getName() + " v" + updateChecker.getLatestVersion() + " is available now!", NamedTextColor.GOLD).appendNewline()
.append(Component.text("Click this message to open the Spigot page (CLICK)", NamedTextColor.YELLOW)).clickEvent(ClickEvent.openUrl(UpdateChecker.DOWNLOAD_LINK))); .append(Component.text("Click this message to open the Spigot page (CLICK)", NamedTextColor.YELLOW)).clickEvent(ClickEvent.openUrl(UpdateChecker.DOWNLOAD_LINK)));
}, 100L); }, 100L);

@ -1,6 +1,6 @@
package lol.pyr.znpcsplus.user; package lol.pyr.znpcsplus.user;
import lol.pyr.znpcsplus.interaction.NPCAction; import lol.pyr.znpcsplus.interaction.NpcAction;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -28,7 +28,7 @@ public class User {
} }
private final UUID uuid; private final UUID uuid;
private long lastNPCInteraction; private long lastNpcInteraction;
private final Map<UUID, Long> actionCooldownMap = new HashMap<>(); private final Map<UUID, Long> actionCooldownMap = new HashMap<>();
public User(UUID uuid) { public User(UUID uuid) {
@ -40,8 +40,8 @@ public class User {
} }
public boolean canInteract() { public boolean canInteract() {
if (System.currentTimeMillis() - lastNPCInteraction > 100L) { if (System.currentTimeMillis() - lastNpcInteraction > 100L) {
lastNPCInteraction = System.currentTimeMillis(); lastNpcInteraction = System.currentTimeMillis();
return true; return true;
} }
return false; return false;
@ -51,7 +51,7 @@ public class User {
return uuid; return uuid;
} }
public boolean actionCooldownCheck(NPCAction action) { public boolean actionCooldownCheck(NpcAction action) {
UUID id = action.getUuid(); UUID id = action.getUuid();
if (System.currentTimeMillis() - actionCooldownMap.getOrDefault(id, 0L) >= action.getCooldown()) { if (System.currentTimeMillis() - actionCooldownMap.getOrDefault(id, 0L) >= action.getCooldown()) {
actionCooldownMap.put(id, System.currentTimeMillis()); actionCooldownMap.put(id, System.currentTimeMillis());

@ -1,6 +1,6 @@
package lol.pyr.znpcsplus.user; package lol.pyr.znpcsplus.user;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNpcsPlus;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -8,7 +8,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
public class UserListener implements Listener { public class UserListener implements Listener {
public UserListener(ZNPCsPlus plugin) { public UserListener(ZNpcsPlus plugin) {
Bukkit.getPluginManager().registerEvents(this, plugin); Bukkit.getPluginManager().registerEvents(this, plugin);
} }

@ -1,8 +1,8 @@
name: ZNPCsPlus name: ZNpcsPlus
authors: authors:
- Pyr (Pyr#6969) - Pyr (Pyr#6969)
main: lol.pyr.znpcsplus.ZNPCsPlus main: lol.pyr.znpcsplus.ZNpcsPlus
load: POSTWORLD load: POSTWORLD
version: ${version} version: ${version}