Skip to content

Commit

Permalink
Add check for pvp in spawn region
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhydium committed Nov 16, 2024
1 parent 66151ef commit 1b44dcc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/mythicamc/listeners/PvPListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 1b44dcc

Please sign in to comment.