mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e7adf398a | |||
| c0ca85c44d | |||
| a86485a089 |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>me.youhavetrouble</groupId>
|
<groupId>me.youhavetrouble</groupId>
|
||||||
<artifactId>PreventStabby</artifactId>
|
<artifactId>PreventStabby</artifactId>
|
||||||
<version>1.3-pre4</version>
|
<version>1.3-pre5</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>PreventStabby</name>
|
<name>PreventStabby</name>
|
||||||
@@ -47,7 +47,6 @@
|
|||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.bstats</pattern>
|
<pattern>org.bstats</pattern>
|
||||||
<!-- Replace this with your package! -->
|
|
||||||
<shadedPattern>bstats</shadedPattern>
|
<shadedPattern>bstats</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public final class PreventStabby extends JavaPlugin {
|
|||||||
private PlayerManager playerManager;
|
private PlayerManager playerManager;
|
||||||
private DatabaseSQLite sqLite;
|
private DatabaseSQLite sqLite;
|
||||||
private SmartCache smartCache;
|
private SmartCache smartCache;
|
||||||
|
private static boolean worldGuardHook;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -45,7 +46,7 @@ public final class PreventStabby extends JavaPlugin {
|
|||||||
smartCache.runSmartCache();
|
smartCache.runSmartCache();
|
||||||
|
|
||||||
// Register listeners
|
// Register listeners
|
||||||
Reflections reflections = new Reflections(new String[]{"me.youhavetrouble.preventstabby"});
|
Reflections reflections = new Reflections((Object[]) new String[]{"me.youhavetrouble.preventstabby"});
|
||||||
Set<Class<?>> listenerClasses = reflections.getTypesAnnotatedWith(PreventStabbyListener.class);
|
Set<Class<?>> listenerClasses = reflections.getTypesAnnotatedWith(PreventStabbyListener.class);
|
||||||
listenerClasses.forEach((listener)-> {
|
listenerClasses.forEach((listener)-> {
|
||||||
try {
|
try {
|
||||||
@@ -71,11 +72,18 @@ public final class PreventStabby extends JavaPlugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
WorldGuardHook.init();
|
WorldGuardHook.init();
|
||||||
} catch (NoClassDefFoundError ignored) {}
|
worldGuardHook = true;
|
||||||
|
} catch (NoClassDefFoundError e) {
|
||||||
|
worldGuardHook = false;
|
||||||
|
}
|
||||||
|
|
||||||
Metrics metrics = new Metrics(this, 10597);
|
Metrics metrics = new Metrics(this, 10597);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean worldGuardHookEnabled() {
|
||||||
|
return worldGuardHook;
|
||||||
|
}
|
||||||
|
|
||||||
public void reloadPluginConfig() {
|
public void reloadPluginConfig() {
|
||||||
configCache = new ConfigCache();
|
configCache = new ConfigCache();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,27 +18,23 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
public class WorldGuardHook {
|
public class WorldGuardHook {
|
||||||
|
|
||||||
private static WorldGuardPlugin worldGuardPlugin;
|
|
||||||
private static FlagRegistry flagRegistry;
|
private static FlagRegistry flagRegistry;
|
||||||
public static StateFlag FORCE_PVP_FLAG;
|
public static StateFlag FORCE_PVP_FLAG;
|
||||||
|
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
PreventStabby plugin = PreventStabby.getPlugin();
|
PreventStabby plugin = PreventStabby.getPlugin();
|
||||||
try {
|
try {
|
||||||
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagConflictException");
|
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagConflictException");
|
||||||
worldGuardPlugin = WorldGuardPlugin.inst();
|
WorldGuardPlugin worldGuardPlugin = WorldGuardPlugin.inst();
|
||||||
if (WorldGuard.getInstance() == null || worldGuardPlugin == null) return;
|
if (WorldGuard.getInstance() == null || worldGuardPlugin == null) return;
|
||||||
plugin.getLogger().info("Hooking into WorldGuard");
|
plugin.getLogger().info("Hooking into WorldGuard");
|
||||||
flagRegistry = WorldGuard.getInstance().getFlagRegistry();
|
flagRegistry = WorldGuard.getInstance().getFlagRegistry();
|
||||||
createForcePvpFlag(plugin);
|
createForcePvpFlag(plugin);
|
||||||
} catch (NoClassDefFoundError | ClassNotFoundException e) {
|
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createForcePvpFlag(Plugin plugin) {
|
private static void createForcePvpFlag(Plugin plugin) {
|
||||||
if (!isHooked()) return;
|
|
||||||
if (flagRegistry == null) return;
|
if (flagRegistry == null) return;
|
||||||
String flagName = "preventstabby-force-pvp";
|
String flagName = "preventstabby-force-pvp";
|
||||||
try {
|
try {
|
||||||
@@ -56,7 +52,6 @@ public class WorldGuardHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPlayerForcedToPvp(Player player) {
|
public static boolean isPlayerForcedToPvp(Player player) {
|
||||||
if (!isHooked()) return false;
|
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
RegionQuery query = container.createQuery();
|
RegionQuery query = container.createQuery();
|
||||||
org.bukkit.Location loc = player.getLocation();
|
org.bukkit.Location loc = player.getLocation();
|
||||||
@@ -65,10 +60,4 @@ public class WorldGuardHook {
|
|||||||
return set.testState(localPlayer, FORCE_PVP_FLAG);
|
return set.testState(localPlayer, FORCE_PVP_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isHooked() {
|
|
||||||
return worldGuardPlugin != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,24 +112,25 @@ public class PlayerManager {
|
|||||||
public boolean canDamage(UUID attacker, UUID victim, boolean sendDenyMessage, boolean checkVictimSpawnProtection) {
|
public boolean canDamage(UUID attacker, UUID victim, boolean sendDenyMessage, boolean checkVictimSpawnProtection) {
|
||||||
|
|
||||||
if (hasLoginProtection(attacker) || hasTeleportProtection(attacker)) return false;
|
if (hasLoginProtection(attacker) || hasTeleportProtection(attacker)) return false;
|
||||||
|
|
||||||
if (checkVictimSpawnProtection && hasLoginProtection(victim)) return false;
|
if (checkVictimSpawnProtection && hasLoginProtection(victim)) return false;
|
||||||
|
|
||||||
if (checkVictimSpawnProtection && hasTeleportProtection(victim)) return false;
|
if (checkVictimSpawnProtection && hasTeleportProtection(victim)) return false;
|
||||||
|
|
||||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||||
|
|
||||||
Player attackerPlayer = Bukkit.getPlayer(attacker);
|
if (!smartCache.getPlayerData(attacker).isPvpEnabled()) {
|
||||||
Player victimPlayer = Bukkit.getPlayer(victim);
|
Player attackerPlayer = Bukkit.getPlayer(attacker);
|
||||||
|
if (PreventStabby.worldGuardHookEnabled() && WorldGuardHook.isPlayerForcedToPvp(attackerPlayer)) return true;
|
||||||
|
|
||||||
if (!smartCache.getPlayerData(attacker).isPvpEnabled() && (attackerPlayer != null && !isInForcedPvpRegion(attackerPlayer))) {
|
|
||||||
if (sendDenyMessage) {
|
if (sendDenyMessage) {
|
||||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_attacker());
|
PluginMessages.sendActionBar(attacker, config.getCannot_attack_attacker());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!smartCache.getPlayerData(victim).isPvpEnabled() && (victimPlayer != null && !isInForcedPvpRegion(victimPlayer))) {
|
if (!smartCache.getPlayerData(victim).isPvpEnabled()) {
|
||||||
|
Player victimPlayer = Bukkit.getPlayer(victim);
|
||||||
|
if (PreventStabby.worldGuardHookEnabled() && WorldGuardHook.isPlayerForcedToPvp(victimPlayer)) return true;
|
||||||
|
|
||||||
if (sendDenyMessage) {
|
if (sendDenyMessage) {
|
||||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_victim());
|
PluginMessages.sendActionBar(attacker, config.getCannot_attack_victim());
|
||||||
@@ -157,9 +158,4 @@ public class PlayerManager {
|
|||||||
return Instant.now().getEpochSecond() < smartCache.getPlayerData(uuid).getTeleportTimestamp();
|
return Instant.now().getEpochSecond() < smartCache.getPlayerData(uuid).getTeleportTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInForcedPvpRegion(Player player) {
|
|
||||||
if (!WorldGuardHook.isHooked()) return false;
|
|
||||||
return WorldGuardHook.isPlayerForcedToPvp(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user