From 69d318c4b0ab3c13cacf1c2e0dc390201c67da4d Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Sat, 23 Nov 2024 20:35:19 -0600 Subject: [PATCH] feat: add Nexo support --- build.gradle.kts | 2 +- .../hmccosmetics/HMCCosmeticsPlugin.java | 2 + .../hmccosmetics/config/Settings.java | 7 ++++ .../listener/PlayerGameListener.java | 21 +--------- .../hmccosmetics/listener/ServerListener.java | 41 +++++++++++++++++++ common/src/main/resources/config.yml | 3 ++ 6 files changed, 56 insertions(+), 20 deletions(-) create mode 100644 common/src/main/java/com/hibiscusmc/hmccosmetics/listener/ServerListener.java diff --git a/build.gradle.kts b/build.gradle.kts index 2bb53d49..47f97aaa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -80,7 +80,7 @@ allprojects { compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.12") //compileOnly("it.unimi.dsi:fastutil:8.5.14") compileOnly("org.projectlombok:lombok:1.18.34") - compileOnly("me.lojosho:HibiscusCommons:0.5.0") + compileOnly("me.lojosho:HibiscusCommons:0.5.1") // Handled by Spigot Library Loader compileOnly("net.kyori:adventure-api:4.17.0") diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java index 5a8500c1..7bf20df9 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java @@ -20,6 +20,7 @@ import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGListener; import com.hibiscusmc.hmccosmetics.listener.PaperPlayerGameListener; import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener; import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener; +import com.hibiscusmc.hmccosmetics.listener.ServerListener; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUsers; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; @@ -94,6 +95,7 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin { // Listener getServer().getPluginManager().registerEvents(new PlayerConnectionListener(), this); getServer().getPluginManager().registerEvents(new PlayerGameListener(), this); + getServer().getPluginManager().registerEvents(new ServerListener(), this); // Taken from PaperLib if (HibiscusCommonsPlugin.isOnPaper()) { getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java index 0410ced6..c7100a16 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java @@ -38,6 +38,7 @@ public class Settings { private static final String EMOTE_DISTANCE_PATH = "emote-distance"; private static final String HOOK_SETTING_PATH = "hook-settings"; private static final String HOOK_ITEMADDER_PATH = "itemsadder"; + private static final String HOOK_NEXO_PATH = "nexo"; private static final String HOOK_RELOAD_CHANGE_PATH = "reload-on-change"; private static final String HOOK_WORLDGUARD_PATH = "worldguard"; private static final String HOOK_WG_MOVE_CHECK_PATH = "player-move-check"; @@ -97,6 +98,8 @@ public class Settings { @Getter private static boolean itemsAdderChangeReload; @Getter + private static boolean nexoChangeReload; + @Getter private static boolean worldGuardMoveCheck; @Getter private static boolean cosmeticEmoteBlockCheck; @@ -257,9 +260,13 @@ public class Settings { dyeMenuOutputSlot = dyeMenuSettings.node(DYE_MENU_OUTPUT_SLOT).getInt(25); ConfigurationNode hookSettings = source.node(HOOK_SETTING_PATH); + ConfigurationNode itemsAdderSettings = hookSettings.node(HOOK_ITEMADDER_PATH); itemsAdderChangeReload = itemsAdderSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(false); + ConfigurationNode nexoSettings = hookSettings.node(HOOK_NEXO_PATH); + nexoChangeReload = nexoSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(true); + ConfigurationNode worldGuardSettings = hookSettings.node(HOOK_WORLDGUARD_PATH); worldGuardMoveCheck = worldGuardSettings.node(HOOK_WG_MOVE_CHECK_PATH).getBoolean(true); // I messed up in release 2.2.6 and forgot to change player_move_check to player-move-check. diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java index 5113d521..647b7ff1 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java @@ -29,7 +29,9 @@ import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager; import me.lojosho.hibiscuscommons.api.events.*; +import me.lojosho.hibiscuscommons.hooks.Hook; import me.lojosho.hibiscuscommons.hooks.items.HookItemAdder; +import me.lojosho.hibiscuscommons.hooks.items.HookNexo; import me.lojosho.hibiscuscommons.util.packets.PacketManager; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -431,21 +433,6 @@ public class PlayerGameListener implements Listener { user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN); } - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onHookReload(HibiscusHookReload event) { - if (event.getHook() instanceof HookItemAdder hook) { - switch (event.getReloadType()) { - case INITIAL -> { - HMCCosmeticsPlugin.setup(); - } - case RELOAD -> { - if (!Settings.isItemsAdderChangeReload()) return; - HMCCosmeticsPlugin.setup(); - } - } - } - } - // These emote mostly handles emotes from other plugins, such as ItemsAdder @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerPlayEmote(HibiscusPlayerEmotePlayEvent event) { @@ -771,10 +758,6 @@ public class PlayerGameListener implements Listener { }); } - - - - @Nullable private EquipmentSlot getArmorSlot(final Material material) { for (final EquipmentSlot slot : EquipmentSlot.values()) { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/ServerListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/ServerListener.java new file mode 100644 index 00000000..953ca0da --- /dev/null +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/ServerListener.java @@ -0,0 +1,41 @@ +package com.hibiscusmc.hmccosmetics.listener; + +import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; +import com.hibiscusmc.hmccosmetics.config.Settings; +import me.lojosho.hibiscuscommons.api.events.HibiscusHookReload; +import me.lojosho.hibiscuscommons.hooks.Hook; +import me.lojosho.hibiscuscommons.hooks.items.HookItemAdder; +import me.lojosho.hibiscuscommons.hooks.items.HookNexo; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; + +public class ServerListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onHookReload(HibiscusHookReload event) { + Hook hook = event.getHook(); + if (hook instanceof HookItemAdder) { + switch (event.getReloadType()) { + case INITIAL -> { + HMCCosmeticsPlugin.setup(); + } + case RELOAD -> { + if (!Settings.isItemsAdderChangeReload()) return; + HMCCosmeticsPlugin.setup(); + } + } + } + if (hook instanceof HookNexo) { + switch (event.getReloadType()) { + case INITIAL -> { + HMCCosmeticsPlugin.setup(); + } + case RELOAD -> { + if (!Settings.isNexoChangeReload()) return; + HMCCosmeticsPlugin.setup(); + } + } + } + } +} diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 4768a7bf..f009c3df 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -129,6 +129,9 @@ hook-settings: # This causes the plugin to reload itself after any ItemsAdder change. This keeps the plugin fully up to date with IA, but # could cause console spam as HMCCosmetics has to reload itself as well. reload-on-change: false + nexo: + # This causes the plugin to reload itself after any Nexo change. This keeps the plugin fully up to date with Nexo + reload-on-change: true worldguard: # Checks worldguard regions for HMCC flags. If set to false, flags will not work properly. # Requires restart to apply changes.