From 1b44dcc3a4e424b0bc40985f2982b563e3f8ced5 Mon Sep 17 00:00:00 2001 From: Rhydium Date: Sat, 16 Nov 2024 23:29:27 +0100 Subject: [PATCH] Add check for pvp in spawn region --- .../java/com/mythicamc/listeners/PvPListener.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/mythicamc/listeners/PvPListener.java b/src/main/java/com/mythicamc/listeners/PvPListener.java index 5b2e733..b982cad 100644 --- a/src/main/java/com/mythicamc/listeners/PvPListener.java +++ b/src/main/java/com/mythicamc/listeners/PvPListener.java @@ -3,6 +3,7 @@ import com.mythicamc.KitPvP; import com.mythicamc.managers.CombatManager; import com.mythicamc.utils.KitSelectorGUI; +import com.mythicamc.utils.WorldGuardUtils; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.ChatColor; @@ -15,6 +16,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; @@ -48,6 +50,13 @@ else if (damagerEntity instanceof Projectile projectile) { } } + // Check if event happens in spawn + if (WorldGuardUtils.isInRegion(damager, "spawn") || WorldGuardUtils.isInRegion(damaged, "spawn")) { + event.setCancelled(true); + damager.sendMessage("PvP is not allowed in the spawn area."); + return; + } + // Tag both players only if the damager is a player if (damager != null) { boolean damagedWasTagged = combatManager.tagPlayer(damaged); @@ -95,6 +104,11 @@ public void onEntityDamage(EntityDamageEvent e) { } } + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + // TO DO: Check if player tries to leave spawn area without a kit selected. + } + private void startRespawnCountdown(Player player) { int countdownTime = plugin.getConfig().getInt("respawn.countdown", 3);