Compare commits

...

7 Commits

Author SHA1 Message Date
YouHaveTrouble 1e7adf398a fix worldguard hook errors 2021-09-18 01:40:11 +02:00
YouHaveTrouble c0ca85c44d add isHooked() back 2021-09-18 00:23:41 +02:00
YouHaveTrouble a86485a089 fix issues with servers not having worldguard 2021-09-18 00:21:19 +02:00
YouHaveTrouble bea0d9c7df make sure mount has player rider before checking for attack cancel 2021-09-17 15:28:34 +02:00
YouHaveTrouble 0eccf1b1af fix unable to attack mounts with no player on them 2021-09-17 15:26:40 +02:00
YouHaveTrouble 2669c538cd remove debug 2 electric boogaloo 2021-08-03 17:45:30 +02:00
YouHaveTrouble 36861084cc remove debug 2021-08-03 17:31:35 +02:00
5 changed files with 30 additions and 46 deletions
+5 -7
View File
@@ -6,7 +6,7 @@
<groupId>me.youhavetrouble</groupId>
<artifactId>PreventStabby</artifactId>
<version>1.3-pre3</version>
<version>1.3-pre5</version>
<packaging>jar</packaging>
<name>PreventStabby</name>
@@ -47,7 +47,6 @@
</relocation>
<relocation>
<pattern>org.bstats</pattern>
<!-- Replace this with your package! -->
<shadedPattern>bstats</shadedPattern>
</relocation>
</relocations>
@@ -74,8 +73,8 @@
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
<id>bs-repo</id>
<url>https://ci.pluginwiki.us/plugin/repository/everything/</url>
</repository>
<repository>
<id>sk89q-repo</id>
@@ -102,10 +101,9 @@
<version>0.9.12</version>
</dependency>
<dependency>
<groupId>com.github.Thatsmusic99</groupId>
<groupId>com.github.thatsmusic99</groupId>
<artifactId>ConfigurationMaster</artifactId>
<version>v1.0-RC-2</version>
<scope>compile</scope>
<version>v1.0.3</version>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
@@ -22,9 +22,10 @@ public final class PreventStabby extends JavaPlugin {
@Getter private static PreventStabby plugin;
private ConfigCache configCache;
protected PlayerManager playerManager;
protected DatabaseSQLite sqLite;
protected SmartCache smartCache;
private PlayerManager playerManager;
private DatabaseSQLite sqLite;
private SmartCache smartCache;
private static boolean worldGuardHook;
@Override
public void onEnable() {
@@ -45,7 +46,7 @@ public final class PreventStabby extends JavaPlugin {
smartCache.runSmartCache();
// 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);
listenerClasses.forEach((listener)-> {
try {
@@ -71,11 +72,18 @@ public final class PreventStabby extends JavaPlugin {
try {
WorldGuardHook.init();
} catch (NoClassDefFoundError ignored) {}
worldGuardHook = true;
} catch (NoClassDefFoundError e) {
worldGuardHook = false;
}
Metrics metrics = new Metrics(this, 10597);
}
public static boolean worldGuardHookEnabled() {
return worldGuardHook;
}
public void reloadPluginConfig() {
configCache = new ConfigCache();
}
@@ -18,31 +18,23 @@ import org.bukkit.plugin.Plugin;
public class WorldGuardHook {
private static WorldGuardPlugin worldGuardPlugin;
private static FlagRegistry flagRegistry;
public static StateFlag FORCE_PVP_FLAG;
public static void init() {
PreventStabby plugin = PreventStabby.getPlugin();
try {
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagConflictException");
System.out.println("what");
worldGuardPlugin = WorldGuardPlugin.inst();
System.out.println("the");
WorldGuardPlugin worldGuardPlugin = WorldGuardPlugin.inst();
if (WorldGuard.getInstance() == null || worldGuardPlugin == null) return;
System.out.println("actual");
plugin.getLogger().info("Hooking into WorldGuard");
flagRegistry = WorldGuard.getInstance().getFlagRegistry();
System.out.println("fuck");
createForcePvpFlag(plugin);
} catch (NoClassDefFoundError | ClassNotFoundException e) {
return;
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
}
}
private static void createForcePvpFlag(Plugin plugin) {
if (!isHooked()) return;
if (flagRegistry == null) return;
String flagName = "preventstabby-force-pvp";
try {
@@ -60,7 +52,6 @@ public class WorldGuardHook {
}
public static boolean isPlayerForcedToPvp(Player player) {
if (!isHooked()) return false;
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
org.bukkit.Location loc = player.getLocation();
@@ -69,10 +60,4 @@ public class WorldGuardHook {
return set.testState(localPlayer, FORCE_PVP_FLAG);
}
public static boolean isHooked() {
return worldGuardPlugin != null;
}
}
@@ -33,12 +33,7 @@ public class PlayerManager {
Iterator<PlayerData> iterator = playerList.values().iterator();
while (iterator.hasNext()) {
PlayerData playerData = iterator.next();
System.out.println(playerData);
UUID uuid = playerData.getPlayerUuid();
System.out.println("----------------------");
System.out.println(uuid.toString());
System.out.println("In combat: "+CombatTimer.isInCombat(uuid));
System.out.println("Last check: "+playerData.getLastCombatCheck());
if (!CombatTimer.isInCombat(uuid)) {
if (playerData.getLastCombatCheck()) {
Player player = Bukkit.getPlayer(uuid);
@@ -117,24 +112,25 @@ public class PlayerManager {
public boolean canDamage(UUID attacker, UUID victim, boolean sendDenyMessage, boolean checkVictimSpawnProtection) {
if (hasLoginProtection(attacker) || hasTeleportProtection(attacker)) return false;
if (checkVictimSpawnProtection && hasLoginProtection(victim)) return false;
if (checkVictimSpawnProtection && hasTeleportProtection(victim)) return false;
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
Player attackerPlayer = Bukkit.getPlayer(attacker);
Player victimPlayer = Bukkit.getPlayer(victim);
if (!smartCache.getPlayerData(attacker).isPvpEnabled()) {
Player attackerPlayer = Bukkit.getPlayer(attacker);
if (PreventStabby.worldGuardHookEnabled() && WorldGuardHook.isPlayerForcedToPvp(attackerPlayer)) return true;
if (!smartCache.getPlayerData(attacker).isPvpEnabled() && (attackerPlayer != null && !isInForcedPvpRegion(attackerPlayer))) {
if (sendDenyMessage) {
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
PluginMessages.sendActionBar(attacker, config.getCannot_attack_attacker());
}
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) {
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
PluginMessages.sendActionBar(attacker, config.getCannot_attack_victim());
@@ -162,9 +158,4 @@ public class PlayerManager {
return Instant.now().getEpochSecond() < smartCache.getPlayerData(uuid).getTeleportTimestamp();
}
public boolean isInForcedPvpRegion(Player player) {
if (!WorldGuardHook.isHooked()) return false;
return WorldGuardHook.isPlayerForcedToPvp(player);
}
}
@@ -45,14 +45,16 @@ public class Util {
Set<UUID> playerPassengersWithPvpEnabled = new HashSet<>();
boolean hasPlayerPassengers = false;
for (Entity passenger : mount.getPassengers()) {
if (!(passenger instanceof Player)) continue;
Player player = (Player) passenger;
hasPlayerPassengers = true;
if (PreventStabby.getPlugin().getPlayerManager().getPlayerPvPState(player.getUniqueId()))
playerPassengersWithPvpEnabled.add(player.getUniqueId());
}
if (playerPassengersWithPvpEnabled.isEmpty()) {
if (hasPlayerPassengers && playerPassengersWithPvpEnabled.isEmpty()) {
PluginMessages.sendActionBar(attacker, config.getCannot_attack_mounts_victim());
return true;
}