mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
Compare commits
13 Commits
v1.9.0-pre1
...
v1.11.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ae6e9212c | |||
| fec1dd2ab6 | |||
| fba2f03aab | |||
| e30437694c | |||
| 8fcf34e310 | |||
| aac1f99374 | |||
| 7f1da79444 | |||
| 244ceb4dcc | |||
| ac1cafe0d9 | |||
| b3ce1913fd | |||
| 9a707b34a3 | |||
| d52648b4ff | |||
| 7d2c41646e |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>me.youhavetrouble</groupId>
|
<groupId>me.youhavetrouble</groupId>
|
||||||
<artifactId>PreventStabby</artifactId>
|
<artifactId>PreventStabby</artifactId>
|
||||||
<version>1.8.0</version>
|
<version>1.11.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>PreventStabby</name>
|
<name>PreventStabby</name>
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.24</version>
|
<version>1.18.26</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -76,13 +76,6 @@ public final class PreventStabby extends JavaPlugin {
|
|||||||
pvpCommand.setExecutor(mainCommand);
|
pvpCommand.setExecutor(mainCommand);
|
||||||
pvpCommand.setTabCompleter(mainCommand);
|
pvpCommand.setTabCompleter(mainCommand);
|
||||||
|
|
||||||
try {
|
|
||||||
WorldGuardHook.init();
|
|
||||||
worldGuardHook = true;
|
|
||||||
} catch (NoClassDefFoundError e) {
|
|
||||||
worldGuardHook = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
new PlacoholderApiHook(this).register();
|
new PlacoholderApiHook(this).register();
|
||||||
}
|
}
|
||||||
@@ -90,6 +83,18 @@ public final class PreventStabby extends JavaPlugin {
|
|||||||
Metrics metrics = new Metrics(this, 14074);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean worldGuardHookEnabled() {
|
public static boolean worldGuardHookEnabled() {
|
||||||
return worldGuardHook;
|
return worldGuardHook;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ public class ConfigCache {
|
|||||||
cannot_attack_pets_victim, cannot_attack_pets_attacker, no_permission, no_such_command, pvp_enabled_other,
|
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,
|
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,
|
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 double lava_and_fire_stopper_radius;
|
||||||
@Getter private final long cache_time, combat_time, login_protection_time, teleport_protection_time;
|
@Getter private final long cache_time, combat_time, login_protection_time, teleport_protection_time;
|
||||||
@Getter private final Set<String> combatBlockedCommands = new HashSet<>();
|
@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("messages.force_pvp_none", "PvP state is not forced now");
|
||||||
addDefault("placeholder.placeholder_combat_time", "Combat time: %time%");
|
addDefault("placeholder.placeholder_combat_time", "Combat time: %time%");
|
||||||
addDefault("placeholder.not_in_combat", "Not in combat");
|
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_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_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.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -46,6 +47,15 @@ public class PlacoholderApiHook extends PlaceholderExpansion {
|
|||||||
case "in_combat":
|
case "in_combat":
|
||||||
if (!player.isOnline()) return String.valueOf(false);
|
if (!player.isOnline()) return String.valueOf(false);
|
||||||
return String.valueOf(plugin.getPlayerManager().getPlayer(player.getUniqueId()).isInCombat());
|
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:
|
default:
|
||||||
return null;
|
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.flags.registry.FlagRegistry;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class WorldGuardHook {
|
public class WorldGuardHook {
|
||||||
|
|
||||||
@@ -22,19 +21,18 @@ public class WorldGuardHook {
|
|||||||
public static StateFlag FORCE_PVP_FLAG;
|
public static StateFlag FORCE_PVP_FLAG;
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
PreventStabby plugin = PreventStabby.getPlugin();
|
|
||||||
try {
|
try {
|
||||||
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagRegistry");
|
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagRegistry");
|
||||||
WorldGuardPlugin 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");
|
Bukkit.getLogger().info("[PreventStabby] Hooking into WorldGuard");
|
||||||
flagRegistry = WorldGuard.getInstance().getFlagRegistry();
|
flagRegistry = WorldGuard.getInstance().getFlagRegistry();
|
||||||
createForcePvpFlag(plugin);
|
createForcePvpFlag();
|
||||||
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createForcePvpFlag(Plugin plugin) {
|
private static void createForcePvpFlag() {
|
||||||
if (flagRegistry == null) return;
|
if (flagRegistry == null) return;
|
||||||
String flagName = "preventstabby-force-pvp";
|
String flagName = "preventstabby-force-pvp";
|
||||||
try {
|
try {
|
||||||
@@ -46,7 +44,7 @@ public class WorldGuardHook {
|
|||||||
if (existing instanceof StateFlag) {
|
if (existing instanceof StateFlag) {
|
||||||
FORCE_PVP_FLAG = (StateFlag) existing;
|
FORCE_PVP_FLAG = (StateFlag) existing;
|
||||||
} else {
|
} else {
|
||||||
plugin.getLogger().severe("There is a conflict between flag names!");
|
Bukkit.getLogger().severe("[PreventStabby] There is a conflict between flag names!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -3,6 +3,7 @@ package me.youhavetrouble.preventstabby.listeners.pets;
|
|||||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||||
|
import me.youhavetrouble.preventstabby.util.PvpState;
|
||||||
import me.youhavetrouble.preventstabby.util.Util;
|
import me.youhavetrouble.preventstabby.util.Util;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
@@ -14,8 +15,12 @@ import org.bukkit.event.Listener;
|
|||||||
@PreventStabbyListener
|
@PreventStabbyListener
|
||||||
public class PetTargettingMountListener implements Listener {
|
public class PetTargettingMountListener implements Listener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO - this needs to pass canDamage() in the future, for now it just checks forced pvp state directly
|
||||||
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onWolfAttackMount(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
public void onWolfAttackMount(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||||
|
if (PreventStabby.getPlugin().getPlayerManager().getForcedPvpState() == PvpState.ENABLED) return;
|
||||||
if (!(event.getDamager() instanceof Tameable) || event.getEntity().getPassengers().isEmpty()) return;
|
if (!(event.getDamager() instanceof Tameable) || event.getEntity().getPassengers().isEmpty()) return;
|
||||||
Tameable damager = (Tameable) event.getDamager();
|
Tameable damager = (Tameable) event.getDamager();
|
||||||
Entity victim = event.getEntity();
|
Entity victim = event.getEntity();
|
||||||
|
|||||||
+15
-15
@@ -1,7 +1,9 @@
|
|||||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||||
|
|
||||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||||
|
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||||
|
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
@@ -14,23 +16,21 @@ public class PetTargettingPetListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onWolfAttackWolf(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
public void onWolfAttackWolf(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||||
if (event.getDamager() instanceof Tameable && event.getEntity() instanceof Tameable) {
|
if (!(event.getDamager() instanceof Tameable) || !(event.getEntity() instanceof Tameable)) return;
|
||||||
Tameable damager = (Tameable) event.getDamager();
|
Tameable damager = (Tameable) event.getDamager();
|
||||||
Tameable victim = (Tameable) event.getEntity();
|
Tameable victim = (Tameable) event.getEntity();
|
||||||
if (damager.getOwner() == null || victim.getOwner() == null) return;
|
if (damager.getOwner() == null || victim.getOwner() == null) return;
|
||||||
|
|
||||||
|
if (!PreventStabby.getPlugin().getPlayerManager()
|
||||||
|
.canDamage(
|
||||||
|
damager.getUniqueId(),
|
||||||
|
victim.getUniqueId(),
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
))
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
|
||||||
boolean damagerPvpEnabled = smartCache.getPlayerData(damager.getOwner().getUniqueId()).isPvpEnabled();
|
|
||||||
boolean victimPvpEnabled = smartCache.getPlayerData(victim.getOwner().getUniqueId()).isPvpEnabled();
|
|
||||||
|
|
||||||
if (!victimPvpEnabled || !damagerPvpEnabled) {
|
|
||||||
if (damager instanceof Wolf) {
|
|
||||||
Wolf wolf = (Wolf) damager;
|
|
||||||
wolf.setAngry(false);
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -8,6 +8,7 @@ import org.bukkit.entity.Tameable;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityTargetEvent;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ public class PetTargettingPlayerListener implements Listener {
|
|||||||
* Stops pets with owners targetting players with pvp off
|
* Stops pets with owners targetting players with pvp off
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPetTargetPlayer(org.bukkit.event.entity.EntityTargetEvent event) {
|
public void onPetTargetPlayer(EntityTargetEvent event) {
|
||||||
if (!(event.getEntity() instanceof Tameable)) return;
|
if (!(event.getEntity() instanceof Tameable)) return;
|
||||||
Tameable entity = (Tameable) event.getEntity();
|
Tameable entity = (Tameable) event.getEntity();
|
||||||
if (!(entity.getOwner() instanceof Player)) return;
|
if (!(entity.getOwner() instanceof Player)) return;
|
||||||
@@ -26,8 +27,15 @@ public class PetTargettingPlayerListener implements Listener {
|
|||||||
UUID damager = entity.getOwner().getUniqueId();
|
UUID damager = entity.getOwner().getUniqueId();
|
||||||
UUID victim = event.getTarget().getUniqueId();
|
UUID victim = event.getTarget().getUniqueId();
|
||||||
|
|
||||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true, false))
|
boolean tempting = event.getReason().equals(EntityTargetEvent.TargetReason.TEMPT);
|
||||||
|
|
||||||
|
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, !tempting, false)) {
|
||||||
|
if (tempting) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
|||||||
+21
-23
@@ -2,15 +2,14 @@ package me.youhavetrouble.preventstabby.listeners.pets;
|
|||||||
|
|
||||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
|
||||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
|
||||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -18,32 +17,31 @@ import java.util.UUID;
|
|||||||
public class PlayerAttackPetListener implements Listener {
|
public class PlayerAttackPetListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerAttackPet(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
public void onPlayerAttackPet(EntityDamageByEntityEvent event) {
|
||||||
|
|
||||||
if (event.getDamager() instanceof Player && event.getEntity() instanceof Tameable) {
|
if (!(event.getDamager() instanceof Player) || !(event.getEntity() instanceof Tameable)) return;
|
||||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
|
||||||
Tameable tameable = (Tameable) event.getEntity();
|
|
||||||
if (tameable.getOwner() == null) return;
|
|
||||||
|
|
||||||
UUID damager = event.getDamager().getUniqueId();
|
Tameable tameable = (Tameable) event.getEntity();
|
||||||
UUID victim = tameable.getOwner().getUniqueId();
|
if (tameable.getOwner() == null) return;
|
||||||
|
|
||||||
if (damager.equals(victim)) return;
|
UUID damager = event.getDamager().getUniqueId();
|
||||||
|
UUID victim = tameable.getOwner().getUniqueId();
|
||||||
|
|
||||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
if (damager.equals(victim)) return;
|
||||||
boolean damagerPvpState = PreventStabby.getPlugin().getPlayerManager().getPlayerPvPState(damager);
|
|
||||||
if (!damagerPvpState) {
|
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker());
|
|
||||||
event.setCancelled(true);
|
if (PreventStabby.getPlugin().getPlayerManager()
|
||||||
return;
|
.canDamage(
|
||||||
}
|
damager,
|
||||||
if (!smartCache.getPlayerData(victim).isPvpEnabled()) {
|
victim,
|
||||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_victim());
|
config.getCannot_attack_pets_attacker(),
|
||||||
event.setCancelled(true);
|
config.getCannot_attack_pets_victim(),
|
||||||
return;
|
false
|
||||||
}
|
))
|
||||||
CombatTimer.refreshPlayersCombatTime(damager);
|
CombatTimer.refreshPlayersCombatTime(damager);
|
||||||
|
else
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-22
@@ -18,37 +18,36 @@ import java.util.UUID;
|
|||||||
@PreventStabbyListener
|
@PreventStabbyListener
|
||||||
public class PlayerHitPetWithProjectileListener implements Listener {
|
public class PlayerHitPetWithProjectileListener implements Listener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels damage done by projectiles to pets of players with pvp off
|
* Cancels damage done by projectiles to pets of players with pvp off
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerHitPetWithProjectile(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
public void onPlayerHitPetWithProjectile(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||||
if (event.getEntity() instanceof Tameable && event.getDamager() instanceof Projectile) {
|
if (!(event.getEntity() instanceof Tameable) || !(event.getDamager() instanceof Projectile)) return;
|
||||||
Projectile projectile = (Projectile) event.getDamager();
|
Projectile projectile = (Projectile) event.getDamager();
|
||||||
if (!(projectile.getShooter() instanceof Player)) return;
|
if (!(projectile.getShooter() instanceof Player)) return;
|
||||||
Tameable tameable = (Tameable) event.getEntity();
|
Tameable tameable = (Tameable) event.getEntity();
|
||||||
if (tameable.getOwner() == null) return;
|
if (tameable.getOwner() == null) return;
|
||||||
|
|
||||||
UUID damager = ((Player) projectile.getShooter()).getUniqueId();
|
UUID damager = ((Player) projectile.getShooter()).getUniqueId();
|
||||||
UUID victim = tameable.getOwner().getUniqueId();
|
UUID victim = tameable.getOwner().getUniqueId();
|
||||||
|
|
||||||
if (damager.equals(victim)) return;
|
if (damager.equals(victim)) return;
|
||||||
|
|
||||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
|
||||||
|
|
||||||
if (!smartCache.getPlayerData(damager).isPvpEnabled()) {
|
if (PreventStabby.getPlugin().getPlayerManager()
|
||||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker());
|
.canDamage(
|
||||||
event.setCancelled(true);
|
damager,
|
||||||
return;
|
victim,
|
||||||
}
|
config.getCannot_attack_pets_attacker(),
|
||||||
if (!smartCache.getPlayerData(victim).isPvpEnabled()) {
|
config.getCannot_attack_pets_victim(),
|
||||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_victim());
|
false
|
||||||
event.setCancelled(true);
|
))
|
||||||
return;
|
|
||||||
}
|
|
||||||
CombatTimer.refreshPlayersCombatTime(damager);
|
CombatTimer.refreshPlayersCombatTime(damager);
|
||||||
|
else
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -142,6 +143,22 @@ public class PlayerManager {
|
|||||||
* @return Whenever attacker can harm the victim.
|
* @return Whenever attacker can harm the victim.
|
||||||
*/
|
*/
|
||||||
public boolean canDamage(UUID attacker, UUID victim, boolean sendDenyMessage, boolean checkVictimSpawnProtection) {
|
public boolean canDamage(UUID attacker, UUID victim, boolean sendDenyMessage, boolean checkVictimSpawnProtection) {
|
||||||
|
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||||
|
String attackerMessage = sendDenyMessage ? config.getCannot_attack_attacker() : null;
|
||||||
|
String victimMessage = sendDenyMessage ? config.getCannot_attack_victim() : null;
|
||||||
|
return canDamage(attacker, victim, attackerMessage, victimMessage, checkVictimSpawnProtection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if attacker can harm the victim.
|
||||||
|
* @param attacker Atacker's UUID.
|
||||||
|
* @param victim Victim's UUID.
|
||||||
|
* @param attackerDenyMessage Message that action was denied to the attacker.
|
||||||
|
* @param victimDenyMessage Message that action was denied to the victim.
|
||||||
|
* @param checkVictimSpawnProtection Should teleport and spawn protections be taken into account?
|
||||||
|
* @return Whenever attacker can harm the victim.
|
||||||
|
*/
|
||||||
|
public boolean canDamage(UUID attacker, UUID victim, @Nullable String attackerDenyMessage, @Nullable String victimDenyMessage, 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;
|
||||||
@@ -165,9 +182,8 @@ public class PlayerManager {
|
|||||||
if (PreventStabby.worldGuardHookEnabled() && attackerPlayer != null && WorldGuardHook.isPlayerForcedToPvp(attackerPlayer))
|
if (PreventStabby.worldGuardHookEnabled() && attackerPlayer != null && WorldGuardHook.isPlayerForcedToPvp(attackerPlayer))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (sendDenyMessage) {
|
if (attackerDenyMessage != null) {
|
||||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
PluginMessages.sendActionBar(attacker, attackerDenyMessage);
|
||||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_attacker());
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -176,7 +192,7 @@ public class PlayerManager {
|
|||||||
if (PreventStabby.worldGuardHookEnabled() && victimPlayer != null && WorldGuardHook.isPlayerForcedToPvp(victimPlayer))
|
if (PreventStabby.worldGuardHookEnabled() && victimPlayer != null && WorldGuardHook.isPlayerForcedToPvp(victimPlayer))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (sendDenyMessage) {
|
if (victimDenyMessage != null) {
|
||||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_victim());
|
PluginMessages.sendActionBar(attacker, config.getCannot_attack_victim());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ public class PluginMessages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Component parseMessage(CommandSender sender,String message) {
|
public static Component parseMessage(CommandSender sender,String message) {
|
||||||
|
|
||||||
if (sender instanceof Player && isPlaceholderApiEnabled()) {
|
if (sender instanceof Player && isPlaceholderApiEnabled()) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
message = PlaceholderAPI.setPlaceholders(player, message);
|
message = PlaceholderAPI.setPlaceholders(player, message);
|
||||||
@@ -37,15 +36,18 @@ public class PluginMessages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(CommandSender sender, String message) {
|
public static void sendMessage(CommandSender sender, String message) {
|
||||||
|
if ("".equals(message)) return;
|
||||||
audiences.sender(sender).sendMessage(parseMessage(sender, message));
|
audiences.sender(sender).sendMessage(parseMessage(sender, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendActionBar(Player player, String message) {
|
public static void sendActionBar(Player player, String message) {
|
||||||
|
if ("".equals(message)) return;
|
||||||
Component parsedMessage = parseMessage(player, message);
|
Component parsedMessage = parseMessage(player, message);
|
||||||
audiences.player(player).sendActionBar(parsedMessage);
|
audiences.player(player).sendActionBar(parsedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendActionBar(UUID uuid, String message) {
|
public static void sendActionBar(UUID uuid, String message) {
|
||||||
|
if ("".equals(message)) return;
|
||||||
Player player = Bukkit.getPlayer(uuid);
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
sendActionBar(player, message);
|
sendActionBar(player, message);
|
||||||
@@ -57,6 +59,7 @@ public class PluginMessages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void broadcastMessage(Player player, String message) {
|
public static void broadcastMessage(Player player, String message) {
|
||||||
|
if ("".equals(message)) return;
|
||||||
message = parsePlayerName(player, message);
|
message = parsePlayerName(player, message);
|
||||||
if (PreventStabby.getPlugin().getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
if (PreventStabby.getPlugin().getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
message = PlaceholderAPI.setPlaceholders(player, message);
|
message = PlaceholderAPI.setPlaceholders(player, message);
|
||||||
@@ -65,6 +68,7 @@ public class PluginMessages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void broadcastMessage(String message) {
|
public static void broadcastMessage(String message) {
|
||||||
|
if ("".equals(message)) return;
|
||||||
audiences.all().sendMessage(parseMessage(message));
|
audiences.all().sendMessage(parseMessage(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user