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;
import lol.pyr.znpcsplus.api.npc.NPCRegistry;
import lol.pyr.znpcsplus.api.npc.NpcRegistry;
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.entity.PropertyHolder;
public interface NPC extends PropertyHolder {
public interface Npc extends PropertyHolder {
Hologram getHologram();
}

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

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

@ -8,14 +8,14 @@ import lol.pyr.znpcsplus.api.entity.EntityProperty;
import java.util.*;
public class NPCType {
private final static Map<String, NPCType> BY_NAME = new HashMap<>();
public class NpcType {
private final static Map<String, NpcType> BY_NAME = new HashMap<>();
public static Collection<NPCType> values() {
public static Collection<NpcType> values() {
return BY_NAME.values();
}
public static NPCType byName(String name) {
public static NpcType byName(String name) {
return BY_NAME.get(name.toUpperCase());
}
@ -24,7 +24,7 @@ public class NPCType {
private final String name;
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.type = type;
this.hologramOffset = hologramOffset;
@ -47,29 +47,29 @@ public class NPCType {
return allowedProperties;
}
private static NPCType define(Builder builder) {
private static NpcType define(Builder builder) {
return define(builder.build());
}
private static NPCType define(NPCType type) {
private static NpcType define(NpcType type) {
BY_NAME.put(type.getName(), type);
return type;
}
public static final NPCType PLAYER = define(
public static final NpcType PLAYER = define(
new Builder("player", EntityTypes.PLAYER)
.addProperties(EntityProperty.SKIN, EntityProperty.SKIN_LAYERS)
.setHologramOffset(-0.45D));
public static final NPCType CREEPER = define(
public static final NpcType CREEPER = define(
new Builder("creeper", EntityTypes.CREEPER)
.setHologramOffset(-0.6D));
public static final NPCType ZOMBIE = define(
public static final NpcType ZOMBIE = define(
new Builder("zombie", EntityTypes.ZOMBIE)
.setHologramOffset(-0.3D));
public static final NPCType SKELETON = define(
public static final NpcType SKELETON = define(
new Builder("skeleton", EntityTypes.SKELETON)
.setHologramOffset(-0.3D));
@ -100,7 +100,7 @@ public class NPCType {
return this;
}
public NPCType build() {
public NpcType build() {
if (globalProperties) {
allowedProperties.add(EntityProperty.FIRE);
allowedProperties.add(EntityProperty.INVISIBLE);
@ -108,7 +108,7 @@ public class NPCType {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9))
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.znpcsplus.api.ZApiProvider;
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.interaction.InteractionPacketListener;
import lol.pyr.znpcsplus.interaction.types.ConsoleCommandAction;
import lol.pyr.znpcsplus.interaction.types.MessageAction;
import lol.pyr.znpcsplus.npc.NPCEntryImpl;
import lol.pyr.znpcsplus.npc.NPCImpl;
import lol.pyr.znpcsplus.npc.NPCRegistryImpl;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.scheduling.FoliaScheduler;
import lol.pyr.znpcsplus.scheduling.SpigotScheduler;
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.MirrorDescriptor;
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.UpdateNotificationListener;
import lol.pyr.znpcsplus.user.User;
@ -46,7 +46,7 @@ import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
public class ZNPCsPlus extends JavaPlugin {
public class ZNpcsPlus extends JavaPlugin {
public static Logger LOGGER;
public static File PLUGIN_FOLDER;
public static File PATH_FOLDER;
@ -127,12 +127,12 @@ public class ZNPCsPlus extends JavaPlugin {
registerCommands();
log(ChatColor.WHITE + " * Starting tasks...");
new NPCVisibilityTask();
new NpcVisibilityTask();
new SkinCacheCleanTask();
new UserListener(this);
if (Configs.config().checkForUpdates()) new UpdateNotificationListener(this, new UpdateChecker(this));
ZApiProvider.register(new ZNPCsApi());
ZApiProvider.register(new ZNpcsApi());
enabled = true;
log(ChatColor.WHITE + " * Loading complete! (" + (System.currentTimeMillis() - before) + "ms)");
log("");
@ -143,10 +143,10 @@ public class ZNPCsPlus extends JavaPlugin {
int z = 0;
World world = Bukkit.getWorld("world");
if (world == null) world = Bukkit.getWorlds().get(0);
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));
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));
entry.setProcessed(true);
NPCImpl npc = entry.getNpc();
NpcImpl npc = entry.getNpc();
if (type.getType() == EntityTypes.PLAYER) {
SkinCache.fetchByName("Notch").thenAccept(skin -> npc.setProperty(EntityProperty.SKIN, new PrefetchedDescriptor(skin)));
npc.setProperty(EntityProperty.INVISIBLE, true);
@ -159,13 +159,13 @@ public class ZNPCsPlus extends JavaPlugin {
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);
NPCImpl npc = entry.getNpc();
NpcImpl npc = entry.getNpc();
npc.setProperty(EntityProperty.SKIN, new FetchingDescriptor("jeb_"));
npc.addAction(new MessageAction(1000L, "<red>Hi, I'm jeb!"));
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);
npc = entry.getNpc();
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.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.npc.NPCRegistryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
public class CreateCommand implements CommandHandler {
@Override
public void run(CommandContext context) throws CommandExecutionException {
String id = context.popString();
NPCRegistryImpl.get().get(id);
NpcRegistryImpl.get().get(id);
}
}

@ -1,6 +1,6 @@
package lol.pyr.znpcsplus.config;
import lol.pyr.znpcsplus.ZNPCsPlus;
import lol.pyr.znpcsplus.ZNpcsPlus;
import space.arim.dazzleconf.ConfigurationFactory;
import space.arim.dazzleconf.ConfigurationOptions;
import space.arim.dazzleconf.error.ConfigFormatSyntaxException;
@ -40,13 +40,13 @@ public class Configs {
config = configHelper.reloadConfigData();
messages = messagesHelper.reloadConfigData();
} catch (IOException e) {
ZNPCsPlus.LOGGER.severe("Couldn't open config file!");
ZNpcsPlus.LOGGER.severe("Couldn't open config file!");
e.printStackTrace();
} catch (ConfigFormatSyntaxException e) {
ZNPCsPlus.LOGGER.severe("Invalid config syntax!");
ZNpcsPlus.LOGGER.severe("Invalid config syntax!");
e.printStackTrace();
} catch (InvalidConfigException e) {
ZNPCsPlus.LOGGER.severe("Invalid config value!");
ZNpcsPlus.LOGGER.severe("Invalid config value!");
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.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;
import lol.pyr.znpcsplus.npc.NPCEntryImpl;
import lol.pyr.znpcsplus.npc.NPCImpl;
import lol.pyr.znpcsplus.npc.NPCRegistryImpl;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.user.User;
import org.bukkit.entity.Player;
@ -20,11 +20,11 @@ public class InteractionPacketListener implements PacketListener {
User user = User.get(player);
if (!user.canInteract()) return;
NPCEntryImpl entry = NPCRegistryImpl.get().getByEntityId(packet.getEntityId());
NpcEntryImpl entry = NpcRegistryImpl.get().getByEntityId(packet.getEntityId());
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;
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;
public abstract class NPCAction {
public abstract class NpcAction {
private final UUID id;
private final long delay;
protected final String argument;
protected NPCAction(long delay, String argument) {
protected NpcAction(long delay, String argument) {
this.id = UUID.randomUUID();
this.delay = delay;
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.*;
public enum NPCActionType implements NPCActionDeserializer {
public enum NpcActionType implements NpcActionDeserializer {
CONSOLE_CMD(ConsoleCommandAction::new),
MESSAGE(MessageAction::new),
PLAYER_CMD(PlayerCommandAction::new),
SERVER(SwitchServerAction::new);
private final NPCActionDeserializer deserializer;
private final NpcActionDeserializer deserializer;
NPCActionType(NPCActionDeserializer deserializer) {
NpcActionType(NpcActionDeserializer deserializer) {
this.deserializer = deserializer;
}
@Override
public NPCAction deserialize(long delay, String str) {
public NpcAction deserialize(long delay, String str) {
return deserializer.deserialize(delay, str);
}
}

@ -1,12 +1,12 @@
package lol.pyr.znpcsplus.interaction.types;
import lol.pyr.znpcsplus.ZNPCsPlus;
import lol.pyr.znpcsplus.interaction.NPCAction;
import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.interaction.NpcAction;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class ConsoleCommandAction extends NPCAction {
public class ConsoleCommandAction extends NpcAction {
public ConsoleCommandAction(long delay, String argument) {
super(delay, argument);
}
@ -14,6 +14,6 @@ public class ConsoleCommandAction extends NPCAction {
@Override
public void run(Player player) {
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;
import lol.pyr.znpcsplus.ZNPCsPlus;
import lol.pyr.znpcsplus.interaction.NPCAction;
import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.interaction.NpcAction;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.entity.Player;
public class MessageAction extends NPCAction {
public class MessageAction extends NpcAction {
private final Component message;
public MessageAction(long delay, String argument) {
@ -16,6 +16,6 @@ public class MessageAction extends NPCAction {
@Override
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;
import lol.pyr.znpcsplus.ZNPCsPlus;
import lol.pyr.znpcsplus.interaction.NPCAction;
import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.interaction.NpcAction;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class PlayerCommandAction extends NPCAction {
public class PlayerCommandAction extends NpcAction {
public PlayerCommandAction(long delay, String argument) {
super(delay, argument);
}
@ -14,6 +14,6 @@ public class PlayerCommandAction extends NPCAction {
@Override
public void run(Player player) {
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;
import lol.pyr.znpcsplus.ZNPCsPlus;
import lol.pyr.znpcsplus.interaction.NPCAction;
import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.interaction.NpcAction;
import org.bukkit.entity.Player;
public class SwitchServerAction extends NPCAction {
public class SwitchServerAction extends NpcAction {
public SwitchServerAction(long delay, String argument) {
super(delay, argument);
}
@Override
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.manager.server.ServerVersion;
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 net.kyori.adventure.text.Component;
@ -42,7 +42,7 @@ public interface MetadataFactory {
if (v.isNewerThan(version)) continue;
if (!factories.containsKey(v)) continue;
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;
}
throw new RuntimeException("Unsupported version!");

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

@ -1,10 +1,11 @@
package lol.pyr.znpcsplus.npc;
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.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.ZLocation;
import org.bukkit.Bukkit;
@ -13,18 +14,18 @@ import org.bukkit.entity.Player;
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 String worldName;
private PacketEntity entity;
private ZLocation location;
private NPCType type;
private NpcType type;
private final HologramImpl hologram;
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.type = type;
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()));
}
public void setType(NPCType type) {
public void setType(NpcType type) {
UNSAFE_hideAll();
this.type = type;
entity = new PacketEntity(this, type.getType(), entity.getLocation());
UNSAFE_showAll();
}
public NPCType getType() {
public NpcType getType() {
return type;
}
@ -103,11 +104,11 @@ public class NPCImpl extends Viewable implements lol.pyr.znpcsplus.api.npc.NPC {
_refreshMeta();
}
public Collection<NPCAction> getActions() {
public Collection<NpcAction> getActions() {
return Collections.unmodifiableSet(actions);
}
public void addAction(NPCAction action) {
public void addAction(NpcAction action) {
actions.add(action);
}
}

@ -1,7 +1,7 @@
package lol.pyr.znpcsplus.npc;
import lol.pyr.znpcsplus.api.npc.NPCRegistry;
import lol.pyr.znpcsplus.api.npc.NPCType;
import lol.pyr.znpcsplus.api.npc.NpcRegistry;
import lol.pyr.znpcsplus.api.npc.NpcType;
import lol.pyr.znpcsplus.util.ZLocation;
import org.bukkit.World;
@ -10,28 +10,28 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class NPCRegistryImpl implements NPCRegistry {
private final static NPCRegistryImpl registry = new NPCRegistryImpl();
public class NpcRegistryImpl implements NpcRegistry {
private final static NpcRegistryImpl registry = new NpcRegistryImpl();
public static NPCRegistryImpl get() {
public static NpcRegistryImpl get() {
return registry;
}
private NPCRegistryImpl() {
private NpcRegistryImpl() {
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());
}
public Collection<NPCEntryImpl> all() {
public Collection<NpcEntryImpl> all() {
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);
}
@ -40,11 +40,11 @@ public class NPCRegistryImpl implements NPCRegistry {
}
@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();
if (npcMap.containsKey(id)) throw new IllegalArgumentException("An npc with the id " + id + " already exists!");
NPCImpl npc = new NPCImpl(world, type, location);
NPCEntryImpl entry = new NPCEntryImpl(npc);
NpcImpl npc = new NpcImpl(world, type, location);
NpcEntryImpl entry = new NpcEntryImpl(npc);
npcMap.put(id, entry);
return entry;
}

@ -3,7 +3,7 @@ package lol.pyr.znpcsplus.packets;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
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.api.entity.PropertyHolder;
import lol.pyr.znpcsplus.util.LazyLoader;
@ -37,7 +37,7 @@ public interface PacketFactory {
if (v.isNewerThan(version)) continue;
if (!factories.containsKey(v)) continue;
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;
}
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.wrapper.PacketWrapper;
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.EntityProperty;
import lol.pyr.znpcsplus.entity.PacketEntity;
@ -36,7 +36,7 @@ public class V1_8Factory implements PacketFactory {
sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(),
entity.getUuid(), location.toVector3d(), location.getYaw(), location.getPitch(), Collections.emptyList()));
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;
import lol.pyr.znpcsplus.util.VersionUtil;
import lol.pyr.znpcsplus.ZNPCsPlus;
import lol.pyr.znpcsplus.ZNpcsPlus;
import java.util.ArrayList;
import java.util.List;
@ -50,9 +50,9 @@ public abstract class ReflectionLazyLoader<T> {
}
private void warn(String message) {
ZNPCsPlus.LOGGER.warning("[Reflection] " + message);
ZNpcsPlus.LOGGER.warning("[Reflection] " + message);
}
protected abstract T load() throws Exception;
protected void printDebugInfo(Consumer<String> logger) {}
}
}

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

@ -1,6 +1,6 @@
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.skin.BaseSkinDescriptor;
import lol.pyr.znpcsplus.skin.Skin;
@ -33,7 +33,7 @@ public class FetchingDescriptor implements BaseSkinDescriptor, SkinDescriptor {
}
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;
}
}

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

@ -1,6 +1,6 @@
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.SpigotResourcesAPI;
import org.bukkit.scheduler.BukkitRunnable;
@ -12,13 +12,13 @@ public class UpdateChecker extends BukkitRunnable {
public final static int RESOURCE_ID = 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 String newestVersion = "N/A";
public UpdateChecker(ZNPCsPlus plugin) {
public UpdateChecker(ZNpcsPlus plugin) {
this.plugin = plugin;
ZNPCsPlus.SCHEDULER.runDelayedTimerAsync(this, 5L, 6000L);
ZNpcsPlus.SCHEDULER.runDelayedTimerAsync(this, 5L, 6000L);
}
public void run() {
@ -34,8 +34,8 @@ public class UpdateChecker extends BukkitRunnable {
}
private void notifyConsole() {
ZNPCsPlus.LOGGER.warning("Version " + getLatestVersion() + " of " + plugin.getDescription().getName() + " is available now!");
ZNPCsPlus.LOGGER.warning("Download it at " + UpdateChecker.DOWNLOAD_LINK);
ZNpcsPlus.LOGGER.warning("Version " + getLatestVersion() + " of " + plugin.getDescription().getName() + " is available now!");
ZNpcsPlus.LOGGER.warning("Download it at " + UpdateChecker.DOWNLOAD_LINK);
}
private int versionToNumber(String version) {

@ -1,6 +1,6 @@
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.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
@ -10,10 +10,10 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class UpdateNotificationListener implements Listener {
private final ZNPCsPlus plugin;
private final ZNpcsPlus plugin;
private final UpdateChecker updateChecker;
public UpdateNotificationListener(ZNPCsPlus plugin, UpdateChecker updateChecker) {
public UpdateNotificationListener(ZNpcsPlus plugin, UpdateChecker updateChecker) {
this.plugin = plugin;
this.updateChecker = updateChecker;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
@ -25,7 +25,7 @@ public class UpdateNotificationListener implements Listener {
if (updateChecker.getStatus() != UpdateChecker.Status.UPDATE_NEEDED) return;
Bukkit.getScheduler().runTaskLater(plugin, () -> {
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()
.append(Component.text("Click this message to open the Spigot page (CLICK)", NamedTextColor.YELLOW)).clickEvent(ClickEvent.openUrl(UpdateChecker.DOWNLOAD_LINK)));
}, 100L);

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

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

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