Allowing other plugins to disable PvP protections.
Now plugins that want to can selectively disable GP's PvP protections.
This commit is contained in:
parent
0298ca2aa8
commit
b95c34b6f2
|
|
@ -26,6 +26,9 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import me.ryanhamshire.GriefPrevention.events.PreventPvPEvent;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
@ -81,7 +84,7 @@ import org.bukkit.projectiles.ProjectileSource;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
//handles events related to entities
|
//handles events related to entities
|
||||||
class EntityEventHandler implements Listener
|
public class EntityEventHandler implements Listener
|
||||||
{
|
{
|
||||||
//convenience reference for the singleton datastore
|
//convenience reference for the singleton datastore
|
||||||
private DataStore dataStore;
|
private DataStore dataStore;
|
||||||
|
|
@ -626,9 +629,14 @@ class EntityEventHandler implements Listener
|
||||||
!attackerClaim.isAdminClaim() && GriefPrevention.instance.config_pvp_noCombatInPlayerLandClaims))
|
!attackerClaim.isAdminClaim() && GriefPrevention.instance.config_pvp_noCombatInPlayerLandClaims))
|
||||||
{
|
{
|
||||||
attackerData.lastClaim = attackerClaim;
|
attackerData.lastClaim = attackerClaim;
|
||||||
event.setCancelled(true);
|
PreventPvPEvent pvpEvent = new PreventPvPEvent(attackerClaim);
|
||||||
GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.CantFightWhileImmune);
|
Bukkit.getPluginManager().callEvent(pvpEvent);
|
||||||
return;
|
if(!pvpEvent.isCancelled())
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.CantFightWhileImmune);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Claim defenderClaim = this.dataStore.getClaimAt(defender.getLocation(), false, defenderData.lastClaim);
|
Claim defenderClaim = this.dataStore.getClaimAt(defender.getLocation(), false, defenderData.lastClaim);
|
||||||
|
|
@ -639,9 +647,14 @@ class EntityEventHandler implements Listener
|
||||||
!defenderClaim.isAdminClaim() && GriefPrevention.instance.config_pvp_noCombatInPlayerLandClaims))
|
!defenderClaim.isAdminClaim() && GriefPrevention.instance.config_pvp_noCombatInPlayerLandClaims))
|
||||||
{
|
{
|
||||||
defenderData.lastClaim = defenderClaim;
|
defenderData.lastClaim = defenderClaim;
|
||||||
event.setCancelled(true);
|
PreventPvPEvent pvpEvent = new PreventPvPEvent(defenderClaim);
|
||||||
GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.PlayerInPvPSafeZone);
|
Bukkit.getPluginManager().callEvent(pvpEvent);
|
||||||
return;
|
if(!pvpEvent.isCancelled())
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.PlayerInPvPSafeZone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1026,9 +1039,14 @@ class EntityEventHandler implements Listener
|
||||||
!attackerClaim.isAdminClaim() && GriefPrevention.instance.config_pvp_noCombatInPlayerLandClaims))
|
!attackerClaim.isAdminClaim() && GriefPrevention.instance.config_pvp_noCombatInPlayerLandClaims))
|
||||||
{
|
{
|
||||||
attackerData.lastClaim = attackerClaim;
|
attackerData.lastClaim = attackerClaim;
|
||||||
event.setIntensity(effected, 0);
|
PreventPvPEvent pvpEvent = new PreventPvPEvent(attackerClaim);
|
||||||
GriefPrevention.sendMessage(thrower, TextMode.Err, Messages.CantFightWhileImmune);
|
Bukkit.getPluginManager().callEvent(pvpEvent);
|
||||||
continue;
|
if(!pvpEvent.isCancelled())
|
||||||
|
{
|
||||||
|
event.setIntensity(effected, 0);
|
||||||
|
GriefPrevention.sendMessage(thrower, TextMode.Err, Messages.CantFightWhileImmune);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Claim defenderClaim = this.dataStore.getClaimAt(effectedPlayer.getLocation(), false, defenderData.lastClaim);
|
Claim defenderClaim = this.dataStore.getClaimAt(effectedPlayer.getLocation(), false, defenderData.lastClaim);
|
||||||
|
|
@ -1038,16 +1056,21 @@ class EntityEventHandler implements Listener
|
||||||
!defenderClaim.isAdminClaim() && GriefPrevention.instance.config_pvp_noCombatInPlayerLandClaims))
|
!defenderClaim.isAdminClaim() && GriefPrevention.instance.config_pvp_noCombatInPlayerLandClaims))
|
||||||
{
|
{
|
||||||
defenderData.lastClaim = defenderClaim;
|
defenderData.lastClaim = defenderClaim;
|
||||||
event.setIntensity(effected, 0);
|
PreventPvPEvent pvpEvent = new PreventPvPEvent(defenderClaim);
|
||||||
GriefPrevention.sendMessage(thrower, TextMode.Err, Messages.PlayerInPvPSafeZone);
|
Bukkit.getPluginManager().callEvent(pvpEvent);
|
||||||
continue;
|
if(!pvpEvent.isCancelled())
|
||||||
|
{
|
||||||
|
event.setIntensity(effected, 0);
|
||||||
|
GriefPrevention.sendMessage(thrower, TextMode.Err, Messages.PlayerInPvPSafeZone);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HashSet<PotionEffectType> positiveEffects = new HashSet<PotionEffectType>(Arrays.asList
|
public static final HashSet<PotionEffectType> positiveEffects = new HashSet<PotionEffectType>(Arrays.asList
|
||||||
(
|
(
|
||||||
PotionEffectType.ABSORPTION,
|
PotionEffectType.ABSORPTION,
|
||||||
PotionEffectType.DAMAGE_RESISTANCE,
|
PotionEffectType.DAMAGE_RESISTANCE,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package me.ryanhamshire.GriefPrevention.events;
|
||||||
|
|
||||||
|
import me.ryanhamshire.GriefPrevention.Claim;
|
||||||
|
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
//if cancelled, GriefPrevention will not cancel the PvP event it's processing.
|
||||||
|
public class PreventPvPEvent extends Event implements Cancellable
|
||||||
|
{
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
Claim claim;
|
||||||
|
|
||||||
|
public PreventPvPEvent(Claim claim)
|
||||||
|
{
|
||||||
|
this.claim = claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Claim getClaim()
|
||||||
|
{
|
||||||
|
return this.claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled()
|
||||||
|
{
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancelled)
|
||||||
|
{
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user