diff --git a/src/main/java/com/danifoldi/protogui/main/GuiHandler.java b/src/main/java/com/danifoldi/protogui/main/GuiHandler.java index a4bde49..58744ab 100644 --- a/src/main/java/com/danifoldi/protogui/main/GuiHandler.java +++ b/src/main/java/com/danifoldi/protogui/main/GuiHandler.java @@ -368,7 +368,7 @@ void open(final @NotNull GuiGrid gui, final @NotNull UUID uuid, final @NotNull S return; } - runCommand(uuid,openGui, slot, target, event.clickType()); + runCommand(uuid, openGui, slot, target, event.clickType()); close(uuid, true); }); inventory.onClose(event -> close(event.player().uniqueId(), false)); diff --git a/src/main/java/com/danifoldi/protogui/main/ProtoGuiAPI.java b/src/main/java/com/danifoldi/protogui/main/ProtoGuiAPI.java index b253099..b04c35e 100644 --- a/src/main/java/com/danifoldi/protogui/main/ProtoGuiAPI.java +++ b/src/main/java/com/danifoldi/protogui/main/ProtoGuiAPI.java @@ -147,8 +147,8 @@ public void removeGui(final @NotNull String name) { public long reloadGuis() { final @NotNull Instant loadStart = Instant.now(); - loader.unload(); - loader.load(); + loader.unload(true); + loader.load(true); final @NotNull Instant loadEnd = Instant.now(); return Duration.between(loadStart, loadEnd).toMillis(); diff --git a/src/main/java/com/danifoldi/protogui/main/ProtoGuiLoader.java b/src/main/java/com/danifoldi/protogui/main/ProtoGuiLoader.java index f505949..461ff66 100644 --- a/src/main/java/com/danifoldi/protogui/main/ProtoGuiLoader.java +++ b/src/main/java/com/danifoldi/protogui/main/ProtoGuiLoader.java @@ -56,8 +56,12 @@ public ProtoGuiLoader(final @NotNull GuiHandler guiHandler, this.threadPool = threadPool; } - public void load() { - StringUtil.blockPrint(logger::info, "Loading %s version %s".formatted(platform.pluginName(), platform.pluginVersion())); + public void load(boolean reload) { + if (reload) { + StringUtil.blockPrint(logger::info, "Reloading %s version %s".formatted(platform.pluginName(), platform.pluginVersion())); + } else { + StringUtil.blockPrint(logger::info, "Loading %s version %s".formatted(platform.pluginName(), platform.pluginVersion())); + } ProtoGuiAPI.setInstance(new ProtoGuiAPI(guiHandler, this, placeholderHandler)); commandManager.setup(); @@ -91,10 +95,12 @@ public void load() { logger.setFilter(record -> newConfig.getEnumOrElse("logLevel", LogLevel.ALL, EnumGetMethod.NAME_IGNORECASE).level.intValue() <= record.getLevel().intValue()); if (newInstall) { - FileUtil.ensureConfigFile(datafolder.resolve("guis").resolve("authors.yml"), "authors.yml"); - FileUtil.ensureConfigFile(datafolder.resolve("guis").resolve("servermenu.yml"), "servermenu.yml"); - FileUtil.ensureConfigFile(datafolder.resolve("guis").resolve("sounds.yml"), "sounds.yml"); - FileUtil.ensureConfigFile(datafolder.resolve("guis").resolve("stats.yml"), "stats.yml"); + logger.info("Fresh install, copying example files"); + FileUtil.ensureConfigFile(datafolder.resolve("guis"), "authors.yml"); + FileUtil.ensureConfigFile(datafolder.resolve("guis"), "servermenu.yml"); + FileUtil.ensureConfigFile(datafolder.resolve("guis"), "sounds.yml"); + FileUtil.ensureConfigFile(datafolder.resolve("guis"), "stats.yml"); + FileUtil.ensureConfigFile(datafolder.resolve("templates"), "test.yml"); } guiHandler.load(datafolder); @@ -116,8 +122,10 @@ public void load() { }); } - public void unload() { - StringUtil.blockPrint(logger::info, "Unloading %s version %s".formatted(platform.pluginName(), platform.pluginVersion())); + public void unload(boolean reload) { + if (!reload) { + StringUtil.blockPrint(logger::info, "Unloading %s version %s".formatted(platform.pluginName(), platform.pluginVersion())); + } guiHandler.unload(); placeholderHandler.unregisterAll(); diff --git a/src/main/java/com/danifoldi/protogui/platform/bungee/ProtoGui.java b/src/main/java/com/danifoldi/protogui/platform/bungee/ProtoGui.java index 3bb69c3..88a30b8 100644 --- a/src/main/java/com/danifoldi/protogui/platform/bungee/ProtoGui.java +++ b/src/main/java/com/danifoldi/protogui/platform/bungee/ProtoGui.java @@ -16,6 +16,7 @@ import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PlayerDisconnectEvent; +import net.md_5.bungee.api.event.ProxyReloadEvent; import net.md_5.bungee.api.event.ServerSwitchEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Plugin; @@ -97,7 +98,7 @@ public void onEnable() { .build(); this.loader = component.loader(); - this.loader.load(); + this.loader.load(false); } @Override @@ -110,7 +111,7 @@ public void onDisable() { if (this.loader == null) { return; } - this.loader.unload(); + this.loader.unload(false); } final @NotNull Function senderGenerator = commandSender -> new PlatformInteraction.ProtoSender() { @@ -425,6 +426,16 @@ public Map getServers() { } }; + @EventHandler + @SuppressWarnings("unused") + public void onReload(final @NotNull ProxyReloadEvent event) { + if (this.loader == null) { + return; + } + this.loader.unload(true); + this.loader.load(true); + } + @EventHandler @SuppressWarnings("unused") public void onServerSwitch(final @NotNull ServerSwitchEvent event) { diff --git a/src/main/java/com/danifoldi/protogui/platform/velocity/ProtoGui.java b/src/main/java/com/danifoldi/protogui/platform/velocity/ProtoGui.java index 62f3980..03f5e57 100644 --- a/src/main/java/com/danifoldi/protogui/platform/velocity/ProtoGui.java +++ b/src/main/java/com/danifoldi/protogui/platform/velocity/ProtoGui.java @@ -12,6 +12,7 @@ import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.event.proxy.ProxyReloadEvent; import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; import com.velocitypowered.api.plugin.Dependency; import com.velocitypowered.api.plugin.Plugin; @@ -90,7 +91,16 @@ public void onInitialize(ProxyInitializeEvent event) { .build(); this.loader = component.loader(); - this.loader.load(); + this.loader.load(false); + } + + @Subscribe + public void onShutdown(ProxyReloadEvent event) { + if (this.loader == null) { + return; + } + this.loader.unload(true); + this.loader.load(true); } @Subscribe @@ -98,7 +108,7 @@ public void onShutdown(ProxyShutdownEvent event) { if (this.loader == null) { return; } - this.loader.unload(); + this.loader.unload(false); } final @NotNull Function senderGenerator = commandSource -> new PlatformInteraction.ProtoSender() { diff --git a/src/main/java/com/danifoldi/protogui/util/ConditionUtil.java b/src/main/java/com/danifoldi/protogui/util/ConditionUtil.java index 42c178c..58fa4cc 100644 --- a/src/main/java/com/danifoldi/protogui/util/ConditionUtil.java +++ b/src/main/java/com/danifoldi/protogui/util/ConditionUtil.java @@ -8,8 +8,8 @@ public class ConditionUtil { - private static final Pattern permissionPattern = Pattern.compile("^(?(no)?perm)<(?[\\w.]+)>"); - private static final Pattern relationPattern = Pattern.compile("^(?le|lq|eq|ne|ge|gq):(?[\\w\\d.]+):(?[\\w\\d.]+)"); + private static final Pattern permissionPattern = Pattern.compile("^(?(no)?perm):(?[\\w.]+)"); + private static final Pattern relationPattern = Pattern.compile("^(?[\\w\\d.]+):(?le|lq|eq|ne|ge|gq):(?[\\w\\d.]+)"); @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean holds(String condition, PlatformInteraction.ProtoSender sender) { @@ -30,15 +30,23 @@ public static boolean holds(String condition, PlatformInteraction.ProtoSender se Matcher relationMatcher = relationPattern.matcher(condition); if (relationMatcher.matches()) { - String mode = permissionMatcher.group("mode"); + String mode = permissionMatcher.group("relation"); String left = permissionMatcher.group("left"); String right = permissionMatcher.group("right"); try { switch (mode) { case "le": return Integer.parseInt(left) <= Integer.parseInt(right); case "lq": return Integer.parseInt(left) < Integer.parseInt(right); - case "eq": return left.equalsIgnoreCase(right); - case "ne": return !left.equalsIgnoreCase(right); + case "eq": try { + return Integer.parseInt(left) == Integer.parseInt(right); + } catch (NumberFormatException ignored) { + return left.equalsIgnoreCase(right); + } + case "ne": try { + return Integer.parseInt(left) != Integer.parseInt(right); + } catch (NumberFormatException ignored) { + return !left.equalsIgnoreCase(right); + } case "ge": return Integer.parseInt(left) >= Integer.parseInt(right); case "gq": return Integer.parseInt(left) > Integer.parseInt(right); } diff --git a/src/main/resources/authors.yml b/src/main/resources/authors.yml index 75bbc6e..683e8e7 100644 --- a/src/main/resources/authors.yml +++ b/src/main/resources/authors.yml @@ -3,7 +3,7 @@ aliases: size: 45 title: '&6BungeeGui Authors' items: - '0,8,36,44': + '0+8+36+44': type: nether_star '21': type: player_head diff --git a/src/main/resources/servermenu.yml b/src/main/resources/servermenu.yml index 1c4904b..8c5ed39 100644 --- a/src/main/resources/servermenu.yml +++ b/src/main/resources/servermenu.yml @@ -4,7 +4,7 @@ aliases: size: 54 title: '&d&lExampleCraft &dserver menu' items: - 'row0,row5,column0,column8': + 'row0+row5+column0+column8': type: white_stained_glass_pane '20': type: player_head diff --git a/src/main/resources/stats.yml b/src/main/resources/stats.yml index aeffcd6..4da4441 100644 --- a/src/main/resources/stats.yml +++ b/src/main/resources/stats.yml @@ -1,17 +1,8 @@ +template: test aliases: - stats -size: 45 title: '&4&lStatistics' -openSound: - sound: block_beacon_activate - volume: 0.4 -closeable: false items: - row0,row4,column0,column8: - type: red_stained_glass_pane - enchanted: true - clickSound: - sound: entity_villager_no '13': type: player_head data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzI3NDA3NjFkYmQ0MmY3NmU0ZjEyYzQ4ZWMwOTlhY2RjMWM2OTI3MmFiNTc2MzU3OWJiZTkxYzVmNTg2NTZkNyJ9fX0= @@ -53,12 +44,4 @@ items: lore: - 'MOTD: %motd@%servername%%' - 'Players: %online_visible@%servername%% / %max@%servername%%' - - 'Version: %version@%servername%%' - '16': - type: barrier - clickSound: - sound: block_beacon_deactivate - volume: 0.4 - name: '&cClose' - commands: - - '' \ No newline at end of file + - 'Version: %version@%servername%%' \ No newline at end of file diff --git a/src/main/resources/test.yml b/src/main/resources/test.yml new file mode 100644 index 0000000..624e0a0 --- /dev/null +++ b/src/main/resources/test.yml @@ -0,0 +1,19 @@ +size: 45 +openSound: + sound: block_beacon_activate + volume: 0.4 +closeable: false +items: + row0+row4+column0+column8: + type: red_stained_glass_pane + enchanted: true + clickSound: + sound: entity_villager_no + '16': + type: barrier + clickSound: + sound: block_beacon_deactivate + volume: 0.4 + name: '&cClose' + commands: + - '' \ No newline at end of file