From 667e441460fd89d47b8d2614cbfee4c839aa9316 Mon Sep 17 00:00:00 2001 From: ElFrod0 Date: Wed, 14 May 2025 01:49:35 +0200 Subject: [PATCH 1/4] bump PAPI --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 04c84bd..ca33ad6 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,7 @@ me.clip placeholderapi - 2.11.1 + 2.11.6 provided From b3d9ae720fba0254cc64417860b1fdca78cf33f2 Mon Sep 17 00:00:00 2001 From: ElFrod0 Date: Wed, 14 May 2025 02:01:03 +0200 Subject: [PATCH 2/4] Announce first then kill & adjust config --- .../youhavetrouble/preventstabby/config/ConfigCache.java | 9 +++++---- .../preventstabby/data/PlayerListener.java | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java b/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java index 19b3225..9448c8f 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java +++ b/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java @@ -16,7 +16,7 @@ public class ConfigCache { bucket_stopper_enabled, fire_stopper_enabled, block_stopper_enabled, - punish_for_combat_logout, + punish_for_combat_logout_kill, punish_for_combat_logout_announce, block_teleports_in_combat, allow_fishing_rod_pull; @@ -54,15 +54,16 @@ public class ConfigCache { 25, List.of("How long in seconds should combat last since the last hit") ); - this.punish_for_combat_logout = getBoolean( - "settings.punish_for_combat_logout.enabled", + + this.punish_for_combat_logout_kill = getBoolean( + "settings.punish_for_combat_logout.kill", true, List.of("Should players be killed if they log out during combat?") ); this.punish_for_combat_logout_announce = getBoolean( "settings.punish_for_combat_logout.announce", true, - List.of("Should killing of a player that logged out of combat be announced?") + List.of("Should we announce that player logged out of combat?") ); List commandsBlockedInCombat = getList( diff --git a/src/main/java/me/youhavetrouble/preventstabby/data/PlayerListener.java b/src/main/java/me/youhavetrouble/preventstabby/data/PlayerListener.java index 5557167..082e9eb 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/data/PlayerListener.java +++ b/src/main/java/me/youhavetrouble/preventstabby/data/PlayerListener.java @@ -44,13 +44,14 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerLeave(PlayerQuitEvent event) { Player player = event.getPlayer(); - if (!PreventStabby.getPlugin().getConfigCache().punish_for_combat_logout) return; + if (!PreventStabby.getPlugin().getConfigCache().punish_for_combat_logout_announce) { + PluginMessages.broadcastMessage(player, PreventStabby.getPlugin().getConfigCache().punish_for_combat_logout_message); + } + if (!PreventStabby.getPlugin().getConfigCache().punish_for_combat_logout_kill) return; PlayerData playerData = PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId()); if (playerData == null) return; if (!playerData.isInCombat()) return; player.setHealth(0); - if (!PreventStabby.getPlugin().getConfigCache().punish_for_combat_logout_announce) return; - PluginMessages.broadcastMessage(player, PreventStabby.getPlugin().getConfigCache().punish_for_combat_logout_message); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) From c1d0fcf5b380c910c2f7c769c41fa8eb6c3972f5 Mon Sep 17 00:00:00 2001 From: ElFrod0 Date: Wed, 14 May 2025 02:02:51 +0200 Subject: [PATCH 3/4] Old config migration --- .../preventstabby/config/ConfigCache.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java b/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java index 9448c8f..cca1ca4 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java +++ b/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java @@ -42,6 +42,10 @@ public class ConfigCache { plugin.reloadConfig(); config = plugin.getConfig(); + migrate("settings.punish_for_combat_logout.enabled", + "settings.punish_for_combat_logout.kill", + true); + // Settings this.pvp_enabled_by_default = getBoolean( "settings.pvp_enabled_by_default", @@ -238,5 +242,11 @@ public class ConfigCache { return getList(path, def, null); } - + private void migrate(String oldPath, String newPath, @Nullable Object defaultValue) { + if (config.isSet(oldPath) && !config.isSet(newPath)) { + Object value = config.get(oldPath); + config.set(newPath, value != null ? value : defaultValue); + config.set(oldPath, null); + } + } } From 138170c066f392aa4afdf52f5b5b6f3e59367d62 Mon Sep 17 00:00:00 2001 From: ElFrod0 Date: Wed, 14 May 2025 02:34:39 +0200 Subject: [PATCH 4/4] Comments always update --- .../preventstabby/config/ConfigCache.java | 55 ++++++++++++++----- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java b/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java index cca1ca4..e188dc8 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java +++ b/src/main/java/me/youhavetrouble/preventstabby/config/ConfigCache.java @@ -204,38 +204,63 @@ public class ConfigCache { } private String getString(String path, @NotNull String def, @Nullable List comments) { - if (config.isSet(path)) return config.getString(path, def); - config.set(path, def); + String value; + if (config.isSet(path)) { + value = config.getString(path, def); + } else { + config.set(path, def); + value = def; + } if (comments != null) config.setComments(path, comments); - return def; + return value; } private boolean getBoolean(String path, boolean def, @Nullable List comments) { - if (config.isSet(path)) return config.getBoolean(path, def); - config.set(path, def); + boolean value; + if (config.isSet(path)) { + value = config.getBoolean(path, def); + } else { + config.set(path, def); + value = def; + } if (comments != null) config.setComments(path, comments); - return def; + return value; } private double getDouble(String path, double def, @Nullable List comments) { - if (config.isSet(path)) return config.getDouble(path, def); - config.set(path, def); + double value; + if (config.isSet(path)) { + value = config.getDouble(path, def); + } else { + config.set(path, def); + value = def; + } if (comments != null) config.setComments(path, comments); - return def; + return value; } private long getLong(String path, long def, @Nullable List comments) { - if (config.isSet(path)) return config.getLong(path, def); - config.set(path, def); + long value; + if (config.isSet(path)) { + value = config.getLong(path, def); + } else { + config.set(path, def); + value = def; + } if (comments != null) config.setComments(path, comments); - return def; + return value; } private List getList(String path, List def, @Nullable List comments) { - if (config.isSet(path)) return config.getStringList(path); - config.set(path, def); + List value; + if (config.isSet(path)) { + value = config.getStringList(path); + } else { + config.set(path, def); + value = def; + } if (comments != null) config.setComments(path, comments); - return def; + return value; } private List getList(String path, List def) {