add folia support (not tested)

This commit is contained in:
Pyrbu 2023-04-29 19:42:04 +01:00
parent 4c160a44c4
commit ca49a605c0
80 changed files with 122 additions and 460 deletions

3
.gitignore vendored

@ -43,8 +43,7 @@ bin/
.DS_Store
/run/
/spigot/run/
/.idea/
gradle.properties
gradle.properties

@ -5,7 +5,7 @@ subprojects {
version "1.0.5"
compileJava {
options.release.set(16)
options.release.set(17)
}
repositories {
@ -16,5 +16,8 @@ subprojects {
maven {
url "https://repo.codemc.io/repository/maven-snapshots/"
}
maven {
url "https://repo.papermc.io/repository/maven-public/"
}
}
}

3
common/build.gradle Normal file

@ -0,0 +1,3 @@
dependencies {
compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT"
}

@ -0,0 +1,15 @@
package lol.pyr.znpcsplus.scheduling;
import org.bukkit.plugin.Plugin;
public abstract class TaskScheduler {
protected final Plugin plugin;
public TaskScheduler(Plugin plugin) {
this.plugin = plugin;
}
public abstract void runAsync(Runnable runnable);
public abstract void runLaterAsync(Runnable runnable, long ticks);
}

4
folia/build.gradle Normal file

@ -0,0 +1,4 @@
dependencies {
compileOnly "dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT"
compileOnly project(":common")
}

@ -0,0 +1,22 @@
package lol.pyr.znpcsplus.scheduling;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import java.util.concurrent.TimeUnit;
public class FoliaScheduler extends TaskScheduler {
public FoliaScheduler(Plugin plugin) {
super(plugin);
}
@Override
public void runAsync(Runnable runnable) {
Bukkit.getAsyncScheduler().runNow(plugin, task -> runnable.run());
}
@Override
public void runLaterAsync(Runnable runnable, long ticks) {
Bukkit.getAsyncScheduler().runDelayed(plugin, task -> runnable.run(), ticks * 50, TimeUnit.MILLISECONDS);
}
}

@ -0,0 +1,12 @@
package lol.pyr.znpcsplus.util;
public class FoliaUtil {
public static boolean isFolia() {
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}

@ -1,304 +0,0 @@
package io.github.znetworkw.znpcservers.gui;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import io.github.znetworkw.znpcservers.utility.inventory.ZInventory;
import io.github.znetworkw.znpcservers.utility.inventory.ZInventoryPage;
import org.bukkit.entity.Player;
public class ConversationGUI extends ZInventory {
private static final Splitter SPACE_SPLITTER = Splitter.on(" ");
private static final Joiner SPACE_JOINER = Joiner.on(" ");
public ConversationGUI(Player player) {
super(player);
this.setCurrentPage(new MainPage(this));
}
static class MainPage extends ZInventoryPage {
public MainPage(ZInventory inventory) {
super(inventory, "Conversations", 6);
}
@Override
public void update() {
}
/*
int pageID = 1;
public MainPage(ZInventory inventory) {
super(inventory, "Conversations", 6);
}
@Override
public void update() {
int size = ConfigurationConstants.NPC_CONVERSATIONS.size();
addItem(ItemStackBuilder.forMaterial(Material.BARRIER).setName(ChatColor.RED + "Close").build(), getRows() - 5, clickEvent -> this.getPlayer().closeInventory());
if (pageID > 1) {
addItem(ItemStackBuilder.forMaterial(Material.ARROW)
.setName(ChatColor.GRAY + "Previous page")
.build(),
getRows() - 6,
clickEvent -> {
pageID -= 1;
openInventory();
});
}
if (size > 45 * pageID) {
addItem(ItemStackBuilder.forMaterial(Material.ARROW)
.setName(ChatColor.GRAY + "Next page")
.build(),
getRows() - 4,
clickEvent -> {
pageID += 1;
openInventory();
});
}
int slots = (getRows() - 9) * pageID;
int min = Math.min(slots, size);
for (int i = slots - (getRows() - 9); i < min; ++i) {
Conversation conversation = ConfigurationConstants.NPC_CONVERSATIONS.get(i);
this.addItem(ItemStackBuilder.forMaterial(Material.PAPER).setName(ChatColor.GREEN + conversation.getName()).setLore("&7this conversation has &b" + conversation.getTexts().size() + " &7texts,", "&7it will activate when a player is on a &b" + conversation.getRadius() + "x" + conversation.getRadius() + " &7radius,", "&7or when a player interacts with an npc.", "&7when the conversation is finish, there is a &b" + conversation.getCooldown() + "s &7delay to start again.", "&f&lUSES", " &bLeft-click &7to manage texts.", " &bRight-click &7to add a new text.", " &bQ &7to change the radius.", " &bMiddle-click &7to change the cooldown.").build(), i - ((getRows() - 9) * (pageID - 1)), clickEvent -> {
if (clickEvent.getClick() == ClickType.DROP) {
Utils.sendTitle(this.getPlayer(), "&b&lCHANGE RADIUS", "&7Type the new radius...");
EventService.addService(User.get(this.getPlayer()), AsyncPlayerChatEvent.class).addConsumer(event -> {
if (!ConfigurationConstants.NPC_CONVERSATIONS.contains(conversation)) {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.NO_CONVERSATION_FOUND);
} else {
Integer radius = Ints.tryParse(event.getMessage());
if (radius == null) {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.INVALID_NUMBER);
} else if (radius < 0) {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.INVALID_NUMBER);
} else {
conversation.setRadius(radius);
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.SUCCESS);
}
}
}).addConsumer(event -> this.openInventory());
} else if (clickEvent.isRightClick()) {
Utils.sendTitle(this.getPlayer(), "&e&lADD LINE", "&7Type the new line...");
EventService.addService(User.get(this.getPlayer()), AsyncPlayerChatEvent.class).addConsumer(event -> {
if (!ConfigurationConstants.NPC_CONVERSATIONS.contains(conversation)) {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.NO_CONVERSATION_FOUND);
} else {
conversation.getTexts().add(new ConversationKey(event.getMessage()));
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.SUCCESS);
}
}).addConsumer(event -> this.openInventory());
} else if (clickEvent.isLeftClick()) {
new EditConversationPage(this.getInventory(), conversation).openInventory();
} else if (clickEvent.getClick() == ClickType.MIDDLE) {
Utils.sendTitle(this.getPlayer(), "&6&lCHANGE COOLDOWN", "&7Type the new cooldown...");
EventService.addService(User.get(this.getPlayer()), AsyncPlayerChatEvent.class).addConsumer(event -> {
if (!ConfigurationConstants.NPC_CONVERSATIONS.contains(conversation)) {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.NO_CONVERSATION_FOUND);
} else {
Integer cooldown = Ints.tryParse(event.getMessage());
if (cooldown == null) {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.INVALID_NUMBER);
} else if (cooldown < 0) {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.INVALID_NUMBER);
} else {
conversation.setDelay(cooldown);
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.SUCCESS);
}
}
}).addConsumer(event -> this.openInventory());
}
});
}
}
@Override
public String getPageName() {
return super.getPageName() + " - " + pageID + "/" + (int) (Math.ceil((double) ConfigurationConstants.NPC_CONVERSATIONS.size() / (double) 45));
}
static class ActionManagementPage extends ZInventoryPage {
private final Conversation conversation;
private final ConversationKey conversationKey;
int pageID = 1;
public ActionManagementPage(ZInventory inventory, Conversation conversation, ConversationKey conversationKey) {
super(inventory, "Editing " + conversationKey.getTextFormatted(), 6);
this.conversation = conversation;
this.conversationKey = conversationKey;
}
@Override
public void update() {
if (pageID > 1) {
addItem(ItemStackBuilder.forMaterial(Material.ARROW)
.setName(ChatColor.GRAY + "Previous page")
.build(),
getRows() - 6,
clickEvent -> {
pageID -= 1;
openInventory();
});
}
if (conversationKey.getActions().size() > 45 *pageID) {
addItem(ItemStackBuilder.forMaterial(Material.ARROW)
.setName(ChatColor.GRAY + "Next page")
.build(),
getRows() - 4,
clickEvent -> {
pageID += 1;
openInventory();
});
}
int slots = (getRows() - 9) * pageID;
int min = Math.min(slots, conversationKey.getActions().size());
for (int i = slots - (getRows() - 9); i < min; i++) {
NPCAction znpcAction = this.conversationKey.getActions().get(i);
this.addItem(ItemStackBuilder.forMaterial(Material.ANVIL).setName(ChatColor.AQUA + znpcAction.getAction().substring(0, Math.min(znpcAction.getAction().length(), 24)) + "....").setLore("&7this action type is &b" + znpcAction.getActionType(), "&f&lUSES", " &bRight-click &7to remove text.").build(), i - ((getRows() - 9) * (pageID - 1)), clickEvent -> {
if (clickEvent.isRightClick()) {
this.conversationKey.getActions().remove(znpcAction);
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.SUCCESS);
this.openInventory();
}
});
}
this.addItem(ItemStackBuilder.forMaterial(Material.EMERALD).setName(ChatColor.AQUA + "ADD A NEW ACTION").setLore("&7click here...").build(), this.getRows() - 5, clickEvent -> {
Utils.sendTitle(this.getPlayer(), "&d&lADD ACTION", "&7Type the new action...");
EventService.addService(User.get(this.getPlayer()), AsyncPlayerChatEvent.class).addConsumer(event -> {
if (ConfigurationConstants.NPC_CONVERSATIONS.contains(this.conversation) && this.conversation.getTexts().contains(this.conversationKey)) {
List<String> stringList = SPACE_SPLITTER.splitToList(event.getMessage());
if (stringList.size() < 2) {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.INCORRECT_USAGE);
} else {
this.conversationKey.getActions().add(new NPCAction(stringList.get(0).toUpperCase(), SPACE_JOINER.join(Iterables.skip(stringList, 1))));
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.SUCCESS);
}
} else {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.NO_CONVERSATION_FOUND);
}
}).addConsumer(event -> this.openInventory());
});
}
}
@SuppressWarnings({"UnstableApiUsage"})
static class EditConversationPage extends ZInventoryPage {
private final Conversation conversation;
int pageID = 1;
public EditConversationPage(ZInventory inventory, Conversation conversation) {
super(inventory, "Editing conversation " + conversation.getName(), 6);
this.conversation = conversation;
}
@Override
public void update() {
if (pageID > 1) {
addItem(ItemStackBuilder.forMaterial(Material.ARROW)
.setName(ChatColor.GRAY + "Previous page")
.build(),
getRows() - 6,
clickEvent -> {
pageID -= 1;
openInventory();
});
}
if (conversation.getTexts().size() > 45 * pageID) {
addItem(ItemStackBuilder.forMaterial(Material.ARROW)
.setName(ChatColor.GRAY + "Next page")
.build(),
getRows() - 4,
clickEvent -> {
pageID += 1;
openInventory();
});
}
int slots = (getRows() - 9) * pageID;
int min = Math.min(slots, conversation.getTexts().size());
for (int i = slots - (getRows() - 9); i < min; i++) {
ConversationKey conversationKey = this.conversation.getTexts().get(i);
this.addItem(ItemStackBuilder.forMaterial(Material.NAME_TAG).setName(ChatColor.AQUA + conversationKey.getTextFormatted() + "....").setLore("&7this conversation text has a delay of &b" + conversationKey.getCooldown() + "s &7to be executed,", "&7the sound for the text is &b" + (conversationKey.getSoundName() == null ? "NONE" : conversationKey.getSoundName()) + "&7,", "&7before sending the text there is a delay of &b" + conversationKey.getCooldown() + "s", "&7the index for the text is &b" + i + "&7,", "&7and the conversation has currently &b" + conversationKey.getActions().size() + " actions&7.", "&f&lUSES", " &bLeft-click &7to change the position.", " &bRight-click &7to remove text.", " &bLeft-Shift-click &7to change the sound.", " &bMiddle-click &7to change the delay.", " &bRight-Shift-click &7to edit the text.", " &bQ &7to manage actions.").build(), i, clickEvent -> {
if (clickEvent.getClick() == ClickType.SHIFT_LEFT) {
Utils.sendTitle(this.getPlayer(), "&c&lCHANGE SOUND", "&7Type the new sound...");
EventService.addService(User.get(this.getPlayer()), AsyncPlayerChatEvent.class).addConsumer(event -> {
if (ConfigurationConstants.NPC_CONVERSATIONS.contains(this.conversation) && this.conversation.getTexts().contains(conversationKey)) {
String sound = event.getMessage().trim();
conversationKey.setSoundName(sound);
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.SUCCESS);
} else {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.NO_CONVERSATION_FOUND);
}
}).addConsumer(event -> this.openInventory());
} else if (clickEvent.getClick() == ClickType.SHIFT_RIGHT) {
Utils.sendTitle(this.getPlayer(), "&a&lEDIT TEXT", "&7Type the new text...");
EventService.addService(User.get(this.getPlayer()), AsyncPlayerChatEvent.class).addConsumer(event -> {
if (ConfigurationConstants.NPC_CONVERSATIONS.contains(this.conversation) && this.conversation.getTexts().contains(conversationKey)) {
conversationKey.getLines().clear();
conversationKey.getLines().addAll(SPACE_SPLITTER.splitToList(event.getMessage()));
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.SUCCESS);
} else {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.NO_CONVERSATION_FOUND);
}
}).addConsumer(event -> this.openInventory());
} else if (clickEvent.isLeftClick()) {
Utils.sendTitle(this.getPlayer(), "&e&lCHANGE POSITION &a>=0&c<=" + this.conversation.getTexts().size(), "&7Type the new position...");
EventService.addService(User.get(this.getPlayer()), AsyncPlayerChatEvent.class).addConsumer(event -> {
if (ConfigurationConstants.NPC_CONVERSATIONS.contains(this.conversation) && this.conversation.getTexts().contains(conversationKey)) {
Integer position = Ints.tryParse(event.getMessage());
if (position == null) {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.INVALID_NUMBER);
} else if (position >= 0 && position <= this.conversation.getTexts().size() - 1) {
Collections.swap(this.conversation.getTexts(), this.conversation.getTexts().indexOf(conversationKey), position);
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.SUCCESS);
} else {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.INVALID_SIZE);
}
} else {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.NO_CONVERSATION_FOUND);
}
}).addConsumer(event -> this.openInventory());
} else if (clickEvent.isRightClick()) {
this.conversation.getTexts().remove(conversationKey);
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.SUCCESS);
this.openInventory();
} else if (clickEvent.getClick() == ClickType.MIDDLE) {
Utils.sendTitle(this.getPlayer(), "&d&lCHANGE DELAY", "&7Type the new delay...");
EventService.addService(User.get(this.getPlayer()), AsyncPlayerChatEvent.class).addConsumer(event -> {
if (ConfigurationConstants.NPC_CONVERSATIONS.contains(this.conversation) && this.conversation.getTexts().contains(conversationKey)) {
Integer delay = Ints.tryParse(event.getMessage());
if (delay == null) {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.INVALID_NUMBER);
} else if (delay < 0) {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.INVALID_NUMBER);
} else {
conversationKey.setDelay(delay);
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.SUCCESS);
}
} else {
Configuration.MESSAGES.sendMessage(this.getPlayer(), ConfigurationValue.NO_CONVERSATION_FOUND);
}
}).addConsumer(event -> this.openInventory());
} else if (clickEvent.getClick() == ClickType.DROP) {
new ActionManagementPage(this.getInventory(), this.conversation, conversationKey).openInventory();
}
});
}
}
@Override
public String getPageName() {
return super.getPageName() + " - " + pageID + "/" + (int) (Math.ceil((double) conversation.getTexts().size() / (double) 45));
}
}
*/
}
}

@ -1,55 +0,0 @@
package io.github.znetworkw.znpcservers.user;
import lol.pyr.znpcsplus.ZNPCsPlus;
import lol.pyr.znpcsplus.user.User;
import org.bukkit.event.Event;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
public class EventService<T extends Event> {
private final Class<T> eventClass;
private final List<Consumer<T>> eventConsumers;
protected EventService(Class<T> eventClass, List<Consumer<T>> eventConsumers) {
this.eventClass = eventClass;
this.eventConsumers = eventConsumers;
}
public Class<T> getEventClass() {
return this.eventClass;
}
public List<Consumer<T>> getEventConsumers() {
return this.eventConsumers;
}
public EventService<T> addConsumer(Consumer<T> consumer) {
this.getEventConsumers().add(consumer);
return this;
}
public void runAll(T event) {
ZNPCsPlus.SCHEDULER.runNextTick(() -> this.eventConsumers.forEach(consumer -> consumer.accept(event)));
}
public static <T extends Event> EventService<T> addService(User user, Class<T> eventClass) {
if (EventService.hasService(user, eventClass)) throw new IllegalStateException(eventClass.getSimpleName() + " is already register for " + user.getUuid().toString());
EventService<T> service = new EventService<>(eventClass, new ArrayList<>());
user.getEventServices().add(service);
user.getPlayer().closeInventory();
return service;
}
@SuppressWarnings("unchecked")
public static <T extends Event> EventService<T> findService(User user, Class<T> eventClass) {
Objects.requireNonNull(EventService.class);
return user.getEventServices().stream().filter(eventService -> eventService.getEventClass().isAssignableFrom(eventClass)).map(EventService.class::cast).findFirst().orElse(null);
}
public static boolean hasService(User user, Class<? extends Event> eventClass) {
return user.getEventServices().stream().anyMatch(eventService -> eventService.getEventClass() == eventClass);
}
}

@ -1,38 +0,0 @@
package io.github.znetworkw.znpcservers.utility;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
public class SchedulerUtils {
private final Plugin plugin;
public SchedulerUtils(Plugin plugin) {
this.plugin = plugin;
}
public BukkitTask runTaskTimer(BukkitRunnable bukkitRunnable, int delay) {
return runTaskTimer(bukkitRunnable, delay, delay);
}
public BukkitTask runTaskTimer(BukkitRunnable bukkitRunnable, int delay, int continuousDelay) {
return bukkitRunnable.runTaskTimer(this.plugin, delay, continuousDelay);
}
public BukkitTask runTaskTimerAsynchronously(Runnable runnable, int delay, int continuousDelay) {
return Bukkit.getScheduler().runTaskTimerAsynchronously(this.plugin, runnable, delay, continuousDelay);
}
public void runTaskLaterSync(Runnable runnable, int delay) {
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, runnable, delay);
}
public BukkitTask runNextTick(Runnable runnable) {
return Bukkit.getScheduler().runTask(this.plugin, runnable);
}
public void runAsync(Runnable runnable) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable);
}
}

@ -1,38 +0,0 @@
package lol.pyr.znpcsplus.user;
import io.github.znetworkw.znpcservers.user.EventService;
import lol.pyr.znpcsplus.ZNPCsPlus;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class UserListener implements Listener {
public UserListener(ZNPCsPlus plugin) {
Bukkit.getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
User.get(event.getPlayer());
}
@EventHandler
public void onQuit(PlayerQuitEvent event) {
User.remove(event.getPlayer().getUniqueId());
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onTalk(AsyncPlayerChatEvent event) {
User zUser = User.get(event.getPlayer());
if (EventService.hasService(zUser, AsyncPlayerChatEvent.class)) {
event.setCancelled(true);
EventService<AsyncPlayerChatEvent> eventService = EventService.findService(zUser, AsyncPlayerChatEvent.class);
eventService.runAll(event);
zUser.getEventServices().remove(eventService);
}
}
}

@ -1,3 +1,3 @@
rootProject.name = "ZNPCsPlus"
include "api", "plugin"
include "api", "spigot", "folia", "common"

@ -10,9 +10,6 @@ repositories {
maven {
url "https://jitpack.io/"
}
maven {
url "https://repo.papermc.io/repository/maven-public/"
}
}
dependencies {
@ -32,6 +29,8 @@ dependencies {
implementation "space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.1"
implementation project(":api")
implementation project(":common")
implementation project(":folia")
}
shadowJar {

@ -6,7 +6,6 @@ import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
import io.github.znetworkw.znpcservers.listeners.InventoryListener;
import io.github.znetworkw.znpcservers.utility.BungeeUtils;
import io.github.znetworkw.znpcservers.utility.SchedulerUtils;
import lol.pyr.znpcsplus.api.ZApiProvider;
import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.api.npc.NPCType;
@ -16,6 +15,9 @@ import lol.pyr.znpcsplus.interaction.types.ConsoleCommandAction;
import lol.pyr.znpcsplus.interaction.types.MessageAction;
import lol.pyr.znpcsplus.npc.NPC;
import lol.pyr.znpcsplus.npc.NPCRegistry;
import lol.pyr.znpcsplus.scheduling.FoliaScheduler;
import lol.pyr.znpcsplus.scheduling.SpigotScheduler;
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
import lol.pyr.znpcsplus.skin.cache.SkinCache;
import lol.pyr.znpcsplus.skin.cache.SkinCacheCleanTask;
import lol.pyr.znpcsplus.skin.descriptor.FetchingDescriptor;
@ -26,6 +28,7 @@ import lol.pyr.znpcsplus.updater.UpdateChecker;
import lol.pyr.znpcsplus.updater.UpdateNotificationListener;
import lol.pyr.znpcsplus.user.User;
import lol.pyr.znpcsplus.user.UserListener;
import lol.pyr.znpcsplus.util.FoliaUtil;
import lol.pyr.znpcsplus.util.ZLocation;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
@ -46,7 +49,7 @@ public class ZNPCsPlus extends JavaPlugin {
public static File PLUGIN_FOLDER;
public static File PATH_FOLDER;
private static final int PLUGIN_ID = 18244;
public static SchedulerUtils SCHEDULER;
public static TaskScheduler SCHEDULER;
public static BungeeUtils BUNGEE_UTILS;
public static BukkitAudiences ADVENTURE;
public static boolean PLACEHOLDERS_SUPPORTED;
@ -116,7 +119,7 @@ public class ZNPCsPlus extends JavaPlugin {
log(ChatColor.WHITE + " * Registering components...");
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
new Metrics(this, PLUGIN_ID);
SCHEDULER = new SchedulerUtils(this);
SCHEDULER = FoliaUtil.isFolia() ? new FoliaScheduler(this) : new SpigotScheduler(this);
BUNGEE_UTILS = new BungeeUtils(this);
Bukkit.getOnlinePlayers().forEach(User::get);

@ -4,7 +4,6 @@ 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.ZNPCsPlus;
import lol.pyr.znpcsplus.npc.NPC;
import lol.pyr.znpcsplus.npc.NPCRegistry;
import lol.pyr.znpcsplus.user.User;
@ -23,11 +22,9 @@ public class InteractionPacketListener implements PacketListener {
NPC npc = NPCRegistry.get().getByEntityId(packet.getEntityId());
if (npc == null) return;
ZNPCsPlus.SCHEDULER.runNextTick(() -> {
for (NPCAction action : npc.getActions()) {
if (action.getCooldown() > 0 && !user.actionCooldownCheck(action)) continue;
action.run(player);
}
});
}
}

@ -35,7 +35,7 @@ public class V1_8Factory implements PacketFactory {
sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(),
entity.getUuid(), location.toVector3d(), location.getYaw(), location.getPitch(), List.of()));
sendAllMetadata(player, entity, properties);
ZNPCsPlus.SCHEDULER.runTaskLaterSync(() -> removeTabPlayer(player, entity), 60);
ZNPCsPlus.SCHEDULER.runLaterAsync(() -> removeTabPlayer(player, entity), 60);
});
}

@ -0,0 +1,20 @@
package lol.pyr.znpcsplus.scheduling;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
public class SpigotScheduler extends TaskScheduler {
public SpigotScheduler(Plugin plugin) {
super(plugin);
}
@Override
public void runAsync(Runnable runnable) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable);
}
@Override
public void runLaterAsync(Runnable runnable, long ticks) {
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, runnable, ticks);
}
}

@ -1,11 +1,12 @@
package lol.pyr.znpcsplus.user;
import io.github.znetworkw.znpcservers.user.EventService;
import lol.pyr.znpcsplus.interaction.NPCAction;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class User {
private final static Map<UUID, User> USER_MAP = new HashMap<>();
@ -29,7 +30,6 @@ public class User {
private final UUID uuid;
private long lastNPCInteraction;
private final Map<UUID, Long> actionCooldownMap = new HashMap<>();
private final List<EventService<?>> eventServices = new ArrayList<>();
public User(UUID uuid) {
this.uuid = uuid;
@ -47,10 +47,6 @@ public class User {
return false;
}
public List<EventService<?>> getEventServices() {
return eventServices;
}
public UUID getUuid() {
return uuid;
}

@ -0,0 +1,24 @@
package lol.pyr.znpcsplus.user;
import lol.pyr.znpcsplus.ZNPCsPlus;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class UserListener implements Listener {
public UserListener(ZNPCsPlus plugin) {
Bukkit.getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
User.get(event.getPlayer());
}
@EventHandler
public void onQuit(PlayerQuitEvent event) {
User.remove(event.getPlayer().getUniqueId());
}
}