mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-11 21:06:55 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ae6e9212c | |||
| fec1dd2ab6 | |||
| fba2f03aab | |||
| e30437694c | |||
| 8fcf34e310 | |||
| aac1f99374 |
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.youhavetrouble</groupId>
|
||||
<artifactId>PreventStabby</artifactId>
|
||||
<version>1.10.1</version>
|
||||
<version>1.11.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>PreventStabby</name>
|
||||
|
||||
+5
@@ -3,6 +3,7 @@ package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import me.youhavetrouble.preventstabby.util.PvpState;
|
||||
import me.youhavetrouble.preventstabby.util.Util;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Tameable;
|
||||
@@ -14,8 +15,12 @@ import org.bukkit.event.Listener;
|
||||
@PreventStabbyListener
|
||||
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)
|
||||
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;
|
||||
Tameable damager = (Tameable) event.getDamager();
|
||||
Entity victim = event.getEntity();
|
||||
|
||||
+15
-15
@@ -1,7 +1,9 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Wolf;
|
||||
@@ -14,23 +16,21 @@ public class PetTargettingPetListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onWolfAttackWolf(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager() instanceof Tameable && event.getEntity() instanceof Tameable) {
|
||||
Tameable damager = (Tameable) event.getDamager();
|
||||
Tameable victim = (Tameable) event.getEntity();
|
||||
if (damager.getOwner() == null || victim.getOwner() == null) return;
|
||||
if (!(event.getDamager() instanceof Tameable) || !(event.getEntity() instanceof Tameable)) return;
|
||||
Tameable damager = (Tameable) event.getDamager();
|
||||
Tameable victim = (Tameable) event.getEntity();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+21
-23
@@ -2,15 +2,14 @@ package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -18,32 +17,31 @@ import java.util.UUID;
|
||||
public class PlayerAttackPetListener implements Listener {
|
||||
|
||||
@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) {
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
Tameable tameable = (Tameable) event.getEntity();
|
||||
if (tameable.getOwner() == null) return;
|
||||
if (!(event.getDamager() instanceof Player) || !(event.getEntity() instanceof Tameable)) return;
|
||||
|
||||
UUID damager = event.getDamager().getUniqueId();
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
Tameable tameable = (Tameable) event.getEntity();
|
||||
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();
|
||||
boolean damagerPvpState = PreventStabby.getPlugin().getPlayerManager().getPlayerPvPState(damager);
|
||||
if (!damagerPvpState) {
|
||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!smartCache.getPlayerData(victim).isPvpEnabled()) {
|
||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_victim());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (damager.equals(victim)) return;
|
||||
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager()
|
||||
.canDamage(
|
||||
damager,
|
||||
victim,
|
||||
config.getCannot_attack_pets_attacker(),
|
||||
config.getCannot_attack_pets_victim(),
|
||||
false
|
||||
))
|
||||
CombatTimer.refreshPlayersCombatTime(damager);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-22
@@ -18,37 +18,36 @@ import java.util.UUID;
|
||||
@PreventStabbyListener
|
||||
public class PlayerHitPetWithProjectileListener implements Listener {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Cancels damage done by projectiles to pets of players with pvp off
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerHitPetWithProjectile(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (event.getEntity() instanceof Tameable && event.getDamager() instanceof Projectile) {
|
||||
Projectile projectile = (Projectile) event.getDamager();
|
||||
if (!(projectile.getShooter() instanceof Player)) return;
|
||||
Tameable tameable = (Tameable) event.getEntity();
|
||||
if (tameable.getOwner() == null) return;
|
||||
if (!(event.getEntity() instanceof Tameable) || !(event.getDamager() instanceof Projectile)) return;
|
||||
Projectile projectile = (Projectile) event.getDamager();
|
||||
if (!(projectile.getShooter() instanceof Player)) return;
|
||||
Tameable tameable = (Tameable) event.getEntity();
|
||||
if (tameable.getOwner() == null) return;
|
||||
|
||||
UUID damager = ((Player) projectile.getShooter()).getUniqueId();
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
UUID damager = ((Player) projectile.getShooter()).getUniqueId();
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
|
||||
if (damager.equals(victim)) return;
|
||||
if (damager.equals(victim)) return;
|
||||
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
|
||||
if (!smartCache.getPlayerData(damager).isPvpEnabled()) {
|
||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!smartCache.getPlayerData(victim).isPvpEnabled()) {
|
||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_victim());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (PreventStabby.getPlugin().getPlayerManager()
|
||||
.canDamage(
|
||||
damager,
|
||||
victim,
|
||||
config.getCannot_attack_pets_attacker(),
|
||||
config.getCannot_attack_pets_victim(),
|
||||
false
|
||||
))
|
||||
CombatTimer.refreshPlayersCombatTime(damager);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -142,6 +143,22 @@ public class PlayerManager {
|
||||
* @return Whenever attacker can harm the victim.
|
||||
*/
|
||||
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 (checkVictimSpawnProtection && hasLoginProtection(victim)) return false;
|
||||
@@ -165,9 +182,8 @@ public class PlayerManager {
|
||||
if (PreventStabby.worldGuardHookEnabled() && attackerPlayer != null && WorldGuardHook.isPlayerForcedToPvp(attackerPlayer))
|
||||
return true;
|
||||
|
||||
if (sendDenyMessage) {
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_attacker());
|
||||
if (attackerDenyMessage != null) {
|
||||
PluginMessages.sendActionBar(attacker, attackerDenyMessage);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -176,7 +192,7 @@ public class PlayerManager {
|
||||
if (PreventStabby.worldGuardHookEnabled() && victimPlayer != null && WorldGuardHook.isPlayerForcedToPvp(victimPlayer))
|
||||
return true;
|
||||
|
||||
if (sendDenyMessage) {
|
||||
if (victimDenyMessage != null) {
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_victim());
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ public class PluginMessages {
|
||||
}
|
||||
|
||||
public static Component parseMessage(CommandSender sender,String message) {
|
||||
|
||||
if (sender instanceof Player && isPlaceholderApiEnabled()) {
|
||||
Player player = (Player) sender;
|
||||
message = PlaceholderAPI.setPlaceholders(player, message);
|
||||
@@ -37,15 +36,18 @@ public class PluginMessages {
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String message) {
|
||||
if ("".equals(message)) return;
|
||||
audiences.sender(sender).sendMessage(parseMessage(sender, message));
|
||||
}
|
||||
|
||||
public static void sendActionBar(Player player, String message) {
|
||||
if ("".equals(message)) return;
|
||||
Component parsedMessage = parseMessage(player, message);
|
||||
audiences.player(player).sendActionBar(parsedMessage);
|
||||
}
|
||||
|
||||
public static void sendActionBar(UUID uuid, String message) {
|
||||
if ("".equals(message)) return;
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) return;
|
||||
sendActionBar(player, message);
|
||||
@@ -57,6 +59,7 @@ public class PluginMessages {
|
||||
}
|
||||
|
||||
public static void broadcastMessage(Player player, String message) {
|
||||
if ("".equals(message)) return;
|
||||
message = parsePlayerName(player, message);
|
||||
if (PreventStabby.getPlugin().getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(player, message);
|
||||
@@ -65,6 +68,7 @@ public class PluginMessages {
|
||||
}
|
||||
|
||||
public static void broadcastMessage(String message) {
|
||||
if ("".equals(message)) return;
|
||||
audiences.all().sendMessage(parseMessage(message));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user