Compare commits

..

12 Commits

Author SHA1 Message Date
YouHaveTrouble af376437a0 bump version 2025-06-17 16:11:40 +02:00
YouHaveTrouble 636ccf516c fix broken pvp state check 2025-06-17 16:11:27 +02:00
YouHaveTrouble bd9ecc09ae do not announce combat quit when player is not in combat when quitting 2025-06-17 16:02:31 +02:00
YouHaveTrouble 9ba3bd1dc8 fix inverted config option for combat logout announce 2025-05-15 08:35:03 +02:00
YouHaveTrouble 624cc335f2 bump version 2025-05-14 17:12:30 +02:00
YouHaveTrouble 23fc50ac46 fix exception raised with no worldguard enabled 2025-05-14 17:11:40 +02:00
YouHaveTrouble 466091f1ea Merge pull request #23 from ElFrod0/master
Announce player's combat logging and then (maybe) kill afterwards
2025-05-14 17:00:19 +02:00
ElFrod0 138170c066 Comments always update 2025-05-14 02:34:39 +02:00
ElFrod0 c1d0fcf5b3 Old config migration 2025-05-14 02:33:42 +02:00
ElFrod0 b3d9ae720f Announce first then kill & adjust config 2025-05-14 02:29:00 +02:00
ElFrod0 667e441460 bump PAPI 2025-05-14 01:49:35 +02:00
YouHaveTrouble fb913d97ae 2.0.0 release 2025-05-11 12:17:52 +02:00
4 changed files with 65 additions and 28 deletions
+3 -3
View File
@@ -4,9 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.youhavetrouble</groupId>
<groupId>me.youhavetrouble.preventstabby</groupId>
<artifactId>PreventStabby</artifactId>
<version>2.0.0-rc-3</version>
<version>2.1.2</version>
<packaging>jar</packaging>
<name>PreventStabby</name>
@@ -104,7 +104,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.1</version>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
@@ -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;
@@ -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",
@@ -54,15 +58,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<String> commandsBlockedInCombat = getList(
@@ -199,43 +204,74 @@ public class ConfigCache {
}
private String getString(String path, @NotNull String def, @Nullable List<String> 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<String> 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<String> 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<String> 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<String> getList(String path, List<String> def, @Nullable List<String> comments) {
if (config.isSet(path)) return config.getStringList(path);
config.set(path, def);
List<String> 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<String> getList(String path, List<String> def) {
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);
}
}
}
@@ -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;
PlayerData playerData = PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
if (playerData == null) return;
if (!playerData.isInCombat()) 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;
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)
@@ -175,7 +175,7 @@ public class PlayerManager {
}
}
if (!attackerPlayerData.isPvpEnabled() && !WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(attackerId))) {
if (!attackerPlayerData.isPvpEnabled() || (PreventStabby.worldGuardHookEnabled() && !WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(attackerId)))) {
String message = switch (victimClassifier) {
case PLAYER -> plugin.getConfigCache().cannot_attack_attacker;
case PET -> plugin.getConfigCache().cannot_attack_pets_victim;
@@ -185,7 +185,7 @@ public class PlayerManager {
return new DamageCheckResult(false, attackerId, victimId, message, victimClassifier.equals(Target.EntityClassifier.PLAYER));
}
if (!victimPlayerData.isPvpEnabled() && !WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(victimId))) {
if (!victimPlayerData.isPvpEnabled() || (PreventStabby.worldGuardHookEnabled() && !WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(victimId)))) {
String message = switch (victimClassifier) {
case PLAYER -> plugin.getConfigCache().cannot_attack_victim;
case PET -> plugin.getConfigCache().cannot_attack_pets_attacker;