mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b3ce1913fd | |||
| 9a707b34a3 | |||
| d52648b4ff | |||
| 7d2c41646e |
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.youhavetrouble</groupId>
|
||||
<artifactId>PreventStabby</artifactId>
|
||||
<version>1.8.0</version>
|
||||
<version>1.10.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>PreventStabby</name>
|
||||
@@ -100,7 +100,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
<version>1.18.26</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -76,18 +76,23 @@ public final class PreventStabby extends JavaPlugin {
|
||||
pvpCommand.setExecutor(mainCommand);
|
||||
pvpCommand.setTabCompleter(mainCommand);
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new PlacoholderApiHook(this).register();
|
||||
}
|
||||
|
||||
Metrics metrics = new Metrics(this, 14074);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
|
||||
try {
|
||||
WorldGuardHook.init();
|
||||
worldGuardHook = true;
|
||||
} catch (NoClassDefFoundError e) {
|
||||
worldGuardHook = false;
|
||||
}
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new PlacoholderApiHook(this).register();
|
||||
}
|
||||
|
||||
Metrics metrics = new Metrics(this, 14074);
|
||||
}
|
||||
|
||||
public static boolean worldGuardHookEnabled() {
|
||||
|
||||
@@ -21,7 +21,8 @@ public class ConfigCache {
|
||||
cannot_attack_pets_victim, cannot_attack_pets_attacker, no_permission, no_such_command, pvp_enabled_other,
|
||||
pvp_disabled_other, punish_for_combat_logout_message, entering_combat, leaving_combat,
|
||||
cant_do_that_during_combat, cannot_attack_mounts_attacker, cannot_attack_mounts_victim, force_pvp_on,
|
||||
force_pvp_off, force_pvp_none, placeholder_combat_time, placeholder_not_in_combat, cannot_attack_pvp_force_off;
|
||||
force_pvp_off, force_pvp_none, placeholder_combat_time, placeholder_not_in_combat, cannot_attack_pvp_force_off,
|
||||
placeholder_pvp_forced_true, placeholder_pvp_forced_false, placeholder_pvp_forced_none;
|
||||
@Getter private final double lava_and_fire_stopper_radius;
|
||||
@Getter private final long cache_time, combat_time, login_protection_time, teleport_protection_time;
|
||||
@Getter private final Set<String> combatBlockedCommands = new HashSet<>();
|
||||
@@ -91,6 +92,9 @@ public class ConfigCache {
|
||||
addDefault("messages.force_pvp_none", "PvP state is not forced now");
|
||||
addDefault("placeholder.placeholder_combat_time", "Combat time: %time%");
|
||||
addDefault("placeholder.not_in_combat", "Not in combat");
|
||||
addDefault("placeholder.pvp_forced_true", "PvP is forced on");
|
||||
addDefault("placeholder.pvp_forced_false", "PvP is forced off");
|
||||
addDefault("placeholder.pvp_forced_none", "PvP is not forced");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -152,6 +156,10 @@ public class ConfigCache {
|
||||
|
||||
this.placeholder_combat_time = config.getString("placeholder.placeholder_combat_time", "Combat time: %time%");
|
||||
this.placeholder_not_in_combat = config.getString("placeholder.not_in_combat", "Not in combat");
|
||||
|
||||
this.placeholder_pvp_forced_true = config.getString("placeholder.pvp_forced_true", "PvP is forced on");
|
||||
this.placeholder_pvp_forced_false = config.getString("placeholder.pvp_forced_false", "PvP is forced off");
|
||||
this.placeholder_pvp_forced_none = config.getString("placeholder.pvp_forced_none", "PvP is not forced");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package me.youhavetrouble.preventstabby.hooks;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -46,6 +47,15 @@ public class PlacoholderApiHook extends PlaceholderExpansion {
|
||||
case "in_combat":
|
||||
if (!player.isOnline()) return String.valueOf(false);
|
||||
return String.valueOf(plugin.getPlayerManager().getPlayer(player.getUniqueId()).isInCombat());
|
||||
case "pvp_forced":
|
||||
switch (PreventStabby.getPlugin().getPlayerManager().getForcedPvpState()) {
|
||||
case NONE:
|
||||
return legacyComponentSerializer.serialize(PluginMessages.parseMessage(plugin.getConfigCache().getPlaceholder_pvp_forced_none()));
|
||||
case ENABLED:
|
||||
return legacyComponentSerializer.serialize(PluginMessages.parseMessage(plugin.getConfigCache().getPlaceholder_pvp_forced_true()));
|
||||
case DISABLED:
|
||||
return legacyComponentSerializer.serialize(PluginMessages.parseMessage(plugin.getConfigCache().getPlaceholder_pvp_forced_false()));
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,8 @@ import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class WorldGuardHook {
|
||||
|
||||
@@ -22,19 +21,18 @@ public class WorldGuardHook {
|
||||
public static StateFlag FORCE_PVP_FLAG;
|
||||
|
||||
public static void init() {
|
||||
PreventStabby plugin = PreventStabby.getPlugin();
|
||||
try {
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagRegistry");
|
||||
WorldGuardPlugin worldGuardPlugin = WorldGuardPlugin.inst();
|
||||
if (WorldGuard.getInstance() == null || worldGuardPlugin == null) return;
|
||||
plugin.getLogger().info("Hooking into WorldGuard");
|
||||
Bukkit.getLogger().info("[PreventStabby] Hooking into WorldGuard");
|
||||
flagRegistry = WorldGuard.getInstance().getFlagRegistry();
|
||||
createForcePvpFlag(plugin);
|
||||
createForcePvpFlag();
|
||||
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void createForcePvpFlag(Plugin plugin) {
|
||||
private static void createForcePvpFlag() {
|
||||
if (flagRegistry == null) return;
|
||||
String flagName = "preventstabby-force-pvp";
|
||||
try {
|
||||
@@ -46,7 +44,7 @@ public class WorldGuardHook {
|
||||
if (existing instanceof StateFlag) {
|
||||
FORCE_PVP_FLAG = (StateFlag) existing;
|
||||
} else {
|
||||
plugin.getLogger().severe("There is a conflict between flag names!");
|
||||
Bukkit.getLogger().severe("[PreventStabby] There is a conflict between flag names!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user