mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-26 01:51:19 +01:00
A cancellable event is now fired if WorldGuard disallows PvP.
This commit is contained in:
parent
0dc65d083f
commit
c4f6267921
@ -70,6 +70,7 @@
|
|||||||
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
|
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
|
||||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
|
import com.sk89q.worldguard.protection.events.DisallowedPVPEvent;
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
|
|
||||||
@ -241,8 +242,7 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
|||||||
|
|
||||||
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)
|
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)
|
||||||
|| !mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
|
|| !mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
|
||||||
((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
tryCancelPVPEvent((Player) attacker, player, event);
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -278,8 +278,7 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
|||||||
Vector pt2 = toVector(fireball.getShooter().getLocation());
|
Vector pt2 = toVector(fireball.getShooter().getLocation());
|
||||||
if (!set.allows(DefaultFlag.PVP, localPlayer)
|
if (!set.allows(DefaultFlag.PVP, localPlayer)
|
||||||
|| !mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) fireball.getShooter()))) {
|
|| !mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) fireball.getShooter()))) {
|
||||||
((Player) fireball.getShooter()).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
tryCancelPVPEvent((Player) fireball.getShooter(), player, event);
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -350,8 +349,7 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
|
|||||||
|
|
||||||
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)
|
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)
|
||||||
|| !mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
|
|| !mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
|
||||||
((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
tryCancelPVPEvent((Player) attacker, player, event);
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -822,4 +820,23 @@ private boolean isInvincible(Player player) {
|
|||||||
return god;
|
return god;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Using a DisallowedPVPEvent, notifies other plugins that WorldGuard
|
||||||
|
* wants to cancel a PvP damage event.<br />
|
||||||
|
* If this event is not cancelled, the attacking player is notified that
|
||||||
|
* PvP is disabled and WorldGuard cancels the damage event.
|
||||||
|
*
|
||||||
|
* @param attackingPlayer The attacker
|
||||||
|
* @param defendingPlayer The defender
|
||||||
|
* @param event The event that caused WorldGuard to act
|
||||||
|
*/
|
||||||
|
public void tryCancelPVPEvent(final Player attackingPlayer, final Player defendingPlayer, EntityDamageByEntityEvent event) {
|
||||||
|
final DisallowedPVPEvent disallowedPVPEvent = new DisallowedPVPEvent(attackingPlayer, defendingPlayer, event);
|
||||||
|
plugin.getServer().getPluginManager().callEvent(disallowedPVPEvent);
|
||||||
|
if (!disallowedPVPEvent.isCancelled()) {
|
||||||
|
attackingPlayer.sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldGuard
|
||||||
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldguard.protection.events;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is fired when PVP is disallowed between players due to a "pvp deny" flag.
|
||||||
|
* Cancelling this event allows the PVP in spite of this.
|
||||||
|
*
|
||||||
|
* @author Score_Under
|
||||||
|
*/
|
||||||
|
public class DisallowedPVPEvent extends Event implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private final Player attacker;
|
||||||
|
private final Player defender;
|
||||||
|
private final EntityDamageByEntityEvent event;
|
||||||
|
|
||||||
|
public DisallowedPVPEvent(final Player attacker, final Player defender, EntityDamageByEntityEvent event) {
|
||||||
|
this.attacker = attacker;
|
||||||
|
this.defender = defender;
|
||||||
|
this.event = event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the attacking player.
|
||||||
|
*/
|
||||||
|
public Player getAttacker() {
|
||||||
|
return attacker;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the defending player.
|
||||||
|
*/
|
||||||
|
public Player getDefender() {
|
||||||
|
return defender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityDamageByEntityEvent getCause() {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user