mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-11 21:06:55 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dbf7595c07 | |||
| 263190daa9 | |||
| fccd413cf8 | |||
| af376437a0 | |||
| 636ccf516c | |||
| bd9ecc09ae | |||
| 9ba3bd1dc8 | |||
| 624cc335f2 | |||
| 23fc50ac46 | |||
| 466091f1ea | |||
| 138170c066 | |||
| c1d0fcf5b3 | |||
| b3d9ae720f | |||
| 667e441460 |
@@ -4,9 +4,9 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>me.youhavetrouble</groupId>
|
<groupId>me.youhavetrouble.preventstabby</groupId>
|
||||||
<artifactId>PreventStabby</artifactId>
|
<artifactId>PreventStabby</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.1.4</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>PreventStabby</name>
|
<name>PreventStabby</name>
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc.paper</groupId>
|
<groupId>io.papermc.paper</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.21-R0.1-SNAPSHOT</version>
|
<version>1.21.11-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
<artifactId>placeholderapi</artifactId>
|
<artifactId>placeholderapi</artifactId>
|
||||||
<version>2.11.1</version>
|
<version>2.11.6</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class ConfigCache {
|
|||||||
bucket_stopper_enabled,
|
bucket_stopper_enabled,
|
||||||
fire_stopper_enabled,
|
fire_stopper_enabled,
|
||||||
block_stopper_enabled,
|
block_stopper_enabled,
|
||||||
punish_for_combat_logout,
|
punish_for_combat_logout_kill,
|
||||||
punish_for_combat_logout_announce,
|
punish_for_combat_logout_announce,
|
||||||
block_teleports_in_combat,
|
block_teleports_in_combat,
|
||||||
allow_fishing_rod_pull;
|
allow_fishing_rod_pull;
|
||||||
@@ -42,6 +42,10 @@ public class ConfigCache {
|
|||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
config = plugin.getConfig();
|
config = plugin.getConfig();
|
||||||
|
|
||||||
|
migrate("settings.punish_for_combat_logout.enabled",
|
||||||
|
"settings.punish_for_combat_logout.kill",
|
||||||
|
true);
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
this.pvp_enabled_by_default = getBoolean(
|
this.pvp_enabled_by_default = getBoolean(
|
||||||
"settings.pvp_enabled_by_default",
|
"settings.pvp_enabled_by_default",
|
||||||
@@ -54,15 +58,16 @@ public class ConfigCache {
|
|||||||
25,
|
25,
|
||||||
List.of("How long in seconds should combat last since the last hit")
|
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,
|
true,
|
||||||
List.of("Should players be killed if they log out during combat?")
|
List.of("Should players be killed if they log out during combat?")
|
||||||
);
|
);
|
||||||
this.punish_for_combat_logout_announce = getBoolean(
|
this.punish_for_combat_logout_announce = getBoolean(
|
||||||
"settings.punish_for_combat_logout.announce",
|
"settings.punish_for_combat_logout.announce",
|
||||||
true,
|
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(
|
List<String> commandsBlockedInCombat = getList(
|
||||||
@@ -199,43 +204,74 @@ public class ConfigCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getString(String path, @NotNull String def, @Nullable List<String> comments) {
|
private String getString(String path, @NotNull String def, @Nullable List<String> comments) {
|
||||||
if (config.isSet(path)) return config.getString(path, def);
|
String value;
|
||||||
config.set(path, def);
|
if (config.isSet(path)) {
|
||||||
|
value = config.getString(path, def);
|
||||||
|
} else {
|
||||||
|
config.set(path, def);
|
||||||
|
value = def;
|
||||||
|
}
|
||||||
if (comments != null) config.setComments(path, comments);
|
if (comments != null) config.setComments(path, comments);
|
||||||
return def;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getBoolean(String path, boolean def, @Nullable List<String> comments) {
|
private boolean getBoolean(String path, boolean def, @Nullable List<String> comments) {
|
||||||
if (config.isSet(path)) return config.getBoolean(path, def);
|
boolean value;
|
||||||
config.set(path, def);
|
if (config.isSet(path)) {
|
||||||
|
value = config.getBoolean(path, def);
|
||||||
|
} else {
|
||||||
|
config.set(path, def);
|
||||||
|
value = def;
|
||||||
|
}
|
||||||
if (comments != null) config.setComments(path, comments);
|
if (comments != null) config.setComments(path, comments);
|
||||||
return def;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getDouble(String path, double def, @Nullable List<String> comments) {
|
private double getDouble(String path, double def, @Nullable List<String> comments) {
|
||||||
if (config.isSet(path)) return config.getDouble(path, def);
|
double value;
|
||||||
config.set(path, def);
|
if (config.isSet(path)) {
|
||||||
|
value = config.getDouble(path, def);
|
||||||
|
} else {
|
||||||
|
config.set(path, def);
|
||||||
|
value = def;
|
||||||
|
}
|
||||||
if (comments != null) config.setComments(path, comments);
|
if (comments != null) config.setComments(path, comments);
|
||||||
return def;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getLong(String path, long def, @Nullable List<String> comments) {
|
private long getLong(String path, long def, @Nullable List<String> comments) {
|
||||||
if (config.isSet(path)) return config.getLong(path, def);
|
long value;
|
||||||
config.set(path, def);
|
if (config.isSet(path)) {
|
||||||
|
value = config.getLong(path, def);
|
||||||
|
} else {
|
||||||
|
config.set(path, def);
|
||||||
|
value = def;
|
||||||
|
}
|
||||||
if (comments != null) config.setComments(path, comments);
|
if (comments != null) config.setComments(path, comments);
|
||||||
return def;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getList(String path, List<String> def, @Nullable List<String> comments) {
|
private List<String> getList(String path, List<String> def, @Nullable List<String> comments) {
|
||||||
if (config.isSet(path)) return config.getStringList(path);
|
List<String> value;
|
||||||
config.set(path, def);
|
if (config.isSet(path)) {
|
||||||
|
value = config.getStringList(path);
|
||||||
|
} else {
|
||||||
|
config.set(path, def);
|
||||||
|
value = def;
|
||||||
|
}
|
||||||
if (comments != null) config.setComments(path, comments);
|
if (comments != null) config.setComments(path, comments);
|
||||||
return def;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getList(String path, List<String> def) {
|
private List<String> getList(String path, List<String> def) {
|
||||||
return getList(path, def, null);
|
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)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (!PreventStabby.getPlugin().getConfigCache().punish_for_combat_logout) return;
|
|
||||||
PlayerData playerData = PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
|
PlayerData playerData = PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
|
||||||
if (playerData == null) return;
|
if (playerData == null) return;
|
||||||
if (!playerData.isInCombat()) 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);
|
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)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
|||||||
@@ -46,15 +46,16 @@ public class PlayerManager {
|
|||||||
for (PlayerData playerData : playerList.values()) {
|
for (PlayerData playerData : playerList.values()) {
|
||||||
if (playerData == null) continue;
|
if (playerData == null) continue;
|
||||||
Player player = Bukkit.getPlayer(playerData.getPlayerUuid());
|
Player player = Bukkit.getPlayer(playerData.getPlayerUuid());
|
||||||
|
playerData.getRelatedEntities().removeIf( uuid -> {
|
||||||
|
Entity entity = Bukkit.getEntity(uuid);
|
||||||
|
return entity == null;
|
||||||
|
});
|
||||||
if (player == null || !player.isOnline()) {
|
if (player == null || !player.isOnline()) {
|
||||||
// player not online, so check for related entities
|
// player not online, so check for related entities
|
||||||
playerData.getRelatedEntities().removeIf( uuid -> {
|
|
||||||
Entity entity = Bukkit.getEntity(uuid);
|
|
||||||
return entity == null;
|
|
||||||
});
|
|
||||||
if (playerData.getRelatedEntities().isEmpty()) continue;
|
if (playerData.getRelatedEntities().isEmpty()) continue;
|
||||||
}
|
}
|
||||||
playerData.refreshCacheTime(); // Refresh cache timer if player is online
|
playerData.refreshCacheTime();
|
||||||
|
if (player == null || !player.isOnline()) continue; // If player is offline, skip the rest of the logic
|
||||||
// leaving combat logic
|
// leaving combat logic
|
||||||
if (playerData.getLastCombatCheckState() && !playerData.isInCombat()) {
|
if (playerData.getLastCombatCheckState() && !playerData.isInCombat()) {
|
||||||
PlayerLeaveCombatEvent leaveCombatEvent = null;
|
PlayerLeaveCombatEvent leaveCombatEvent = null;
|
||||||
@@ -175,7 +176,14 @@ public class PlayerManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!attackerPlayerData.isPvpEnabled() && !WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(attackerId))) {
|
Boolean attackerForcedPvpState = null;
|
||||||
|
Boolean victimForcedPvpState = null;
|
||||||
|
if (PreventStabby.worldGuardHookEnabled()) {
|
||||||
|
attackerForcedPvpState = WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(attackerId));
|
||||||
|
victimForcedPvpState = WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(victimId));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!attackerPlayerData.isPvpEnabled() || Boolean.FALSE.equals(attackerForcedPvpState)) {
|
||||||
String message = switch (victimClassifier) {
|
String message = switch (victimClassifier) {
|
||||||
case PLAYER -> plugin.getConfigCache().cannot_attack_attacker;
|
case PLAYER -> plugin.getConfigCache().cannot_attack_attacker;
|
||||||
case PET -> plugin.getConfigCache().cannot_attack_pets_victim;
|
case PET -> plugin.getConfigCache().cannot_attack_pets_victim;
|
||||||
@@ -185,7 +193,7 @@ public class PlayerManager {
|
|||||||
return new DamageCheckResult(false, attackerId, victimId, message, victimClassifier.equals(Target.EntityClassifier.PLAYER));
|
return new DamageCheckResult(false, attackerId, victimId, message, victimClassifier.equals(Target.EntityClassifier.PLAYER));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!victimPlayerData.isPvpEnabled() && !WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(victimId))) {
|
if (!victimPlayerData.isPvpEnabled() || Boolean.FALSE.equals(victimForcedPvpState)) {
|
||||||
String message = switch (victimClassifier) {
|
String message = switch (victimClassifier) {
|
||||||
case PLAYER -> plugin.getConfigCache().cannot_attack_victim;
|
case PLAYER -> plugin.getConfigCache().cannot_attack_victim;
|
||||||
case PET -> plugin.getConfigCache().cannot_attack_pets_attacker;
|
case PET -> plugin.getConfigCache().cannot_attack_pets_attacker;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class WorldGuardHook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPlayerForcedToPvp(Player player) {
|
public static Boolean isPlayerForcedToPvp(Player player) {
|
||||||
if (player == null) return false;
|
if (player == null) return false;
|
||||||
if (!PreventStabby.worldGuardHookEnabled()) return false;
|
if (!PreventStabby.worldGuardHookEnabled()) return false;
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
@@ -60,7 +60,11 @@ public class WorldGuardHook {
|
|||||||
if (loc.getWorld() == null) return false;
|
if (loc.getWorld() == null) return false;
|
||||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||||
ApplicableRegionSet set = query.getApplicableRegions(new Location(BukkitAdapter.adapt(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
|
ApplicableRegionSet set = query.getApplicableRegions(new Location(BukkitAdapter.adapt(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
|
||||||
return set.testState(localPlayer, FORCE_PVP_FLAG);
|
return switch (set.queryState(localPlayer, FORCE_PVP_FLAG)) {
|
||||||
|
case ALLOW -> true;
|
||||||
|
case DENY -> false;
|
||||||
|
case null-> null;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -33,12 +34,12 @@ public class PluginMessages {
|
|||||||
return PreventStabby.getPlugin().getServer().getPluginManager().getPlugin("PlaceholderAPI") != null;
|
return PreventStabby.getPlugin().getServer().getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(CommandSender sender, String message) {
|
public static void sendMessage(@NotNull CommandSender sender, String message) {
|
||||||
if ("".equals(message)) return;
|
if ("".equals(message)) return;
|
||||||
sender.sendMessage(parseMessage(sender, message));
|
sender.sendMessage(parseMessage(sender, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendActionBar(Player player, String message) {
|
public static void sendActionBar(@NotNull Player player, String message) {
|
||||||
if ("".equals(message)) return;
|
if ("".equals(message)) return;
|
||||||
Component parsedMessage = parseMessage(player, message);
|
Component parsedMessage = parseMessage(player, message);
|
||||||
player.sendActionBar(parsedMessage);
|
player.sendActionBar(parsedMessage);
|
||||||
|
|||||||
Reference in New Issue
Block a user