Avoid NPE that could arrise due to NPC plugins etc.
This commit is contained in:
parent
9f5753a682
commit
9aaa6de945
@ -587,14 +587,16 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
|
|||||||
|
|
||||||
public boolean isInOwnTerritory()
|
public boolean isInOwnTerritory()
|
||||||
{
|
{
|
||||||
// TODO: Use Mixin to get this PS instead
|
PS ps = Mixin.getSenderPs(this.getId());
|
||||||
return BoardColls.get().getFactionAt(Mixin.getSenderPs(this.getId())) == this.getFaction();
|
if (ps == null) return false;
|
||||||
|
return BoardColls.get().getFactionAt(ps) == this.getFaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInEnemyTerritory()
|
public boolean isInEnemyTerritory()
|
||||||
{
|
{
|
||||||
// TODO: Use Mixin to get this PS instead
|
PS ps = Mixin.getSenderPs(this.getId());
|
||||||
return BoardColls.get().getFactionAt(Mixin.getSenderPs(this.getId())).getRelationTo(this) == Rel.ENEMY;
|
if (ps == null) return false;
|
||||||
|
return BoardColls.get().getFactionAt(ps).getRelationTo(this) == Rel.ENEMY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -271,7 +271,7 @@ public class FactionsListenerMain implements Listener
|
|||||||
Entity edefender = event.getEntity();
|
Entity edefender = event.getEntity();
|
||||||
if (!(edefender instanceof Player)) return true;
|
if (!(edefender instanceof Player)) return true;
|
||||||
Player defender = (Player)edefender;
|
Player defender = (Player)edefender;
|
||||||
UPlayer fdefender = UPlayer.get(edefender);
|
UPlayer udefender = UPlayer.get(edefender);
|
||||||
|
|
||||||
// Check Disabled
|
// Check Disabled
|
||||||
if (UConf.isDisabled(defender)) return true;
|
if (UConf.isDisabled(defender)) return true;
|
||||||
@ -306,7 +306,7 @@ public class FactionsListenerMain implements Listener
|
|||||||
// ... and if the attacker is a player ...
|
// ... and if the attacker is a player ...
|
||||||
if (!(eattacker instanceof Player)) return true;
|
if (!(eattacker instanceof Player)) return true;
|
||||||
Player attacker = (Player)eattacker;
|
Player attacker = (Player)eattacker;
|
||||||
UPlayer fattacker = UPlayer.get(attacker);
|
UPlayer uattacker = UPlayer.get(attacker);
|
||||||
|
|
||||||
// ... does this player bypass all protection? ...
|
// ... does this player bypass all protection? ...
|
||||||
if (MConf.get().playersWhoBypassAllProtection.contains(attacker.getName())) return true;
|
if (MConf.get().playersWhoBypassAllProtection.contains(attacker.getName())) return true;
|
||||||
@ -320,20 +320,20 @@ public class FactionsListenerMain implements Listener
|
|||||||
// NOTE: This check is probably not that important but we could keep it anyways.
|
// NOTE: This check is probably not that important but we could keep it anyways.
|
||||||
if (attackerPsFaction.getFlag(FFlag.PVP) == false)
|
if (attackerPsFaction.getFlag(FFlag.PVP) == false)
|
||||||
{
|
{
|
||||||
if (notify) fattacker.msg("<i>PVP is disabled in %s.", attackerPsFaction.describeTo(fattacker));
|
if (notify) uattacker.msg("<i>PVP is disabled in %s.", attackerPsFaction.describeTo(uattacker));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... are PVP rules completely ignored in this world? ...
|
// ... are PVP rules completely ignored in this world? ...
|
||||||
if (MConf.get().worldsIgnorePvP.contains(defenderPs.getWorld())) return true;
|
if (MConf.get().worldsIgnorePvP.contains(defenderPs.getWorld())) return true;
|
||||||
|
|
||||||
Faction defendFaction = fdefender.getFaction();
|
Faction defendFaction = udefender.getFaction();
|
||||||
Faction attackFaction = fattacker.getFaction();
|
Faction attackFaction = uattacker.getFaction();
|
||||||
UConf uconf = UConf.get(attackFaction);
|
UConf uconf = UConf.get(attackFaction);
|
||||||
|
|
||||||
if (attackFaction.isNone() && uconf.disablePVPForFactionlessPlayers)
|
if (attackFaction.isNone() && uconf.disablePVPForFactionlessPlayers)
|
||||||
{
|
{
|
||||||
if (notify) fattacker.msg("<i>You can't hurt other players until you join a faction.");
|
if (notify) uattacker.msg("<i>You can't hurt other players until you join a faction.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (defendFaction.isNone())
|
else if (defendFaction.isNone())
|
||||||
@ -345,7 +345,7 @@ public class FactionsListenerMain implements Listener
|
|||||||
}
|
}
|
||||||
else if (uconf.disablePVPForFactionlessPlayers)
|
else if (uconf.disablePVPForFactionlessPlayers)
|
||||||
{
|
{
|
||||||
if (notify) fattacker.msg("<i>You can't hurt players who are not currently in a faction.");
|
if (notify) uattacker.msg("<i>You can't hurt players who are not currently in a faction.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -353,27 +353,28 @@ public class FactionsListenerMain implements Listener
|
|||||||
Rel relation = defendFaction.getRelationTo(attackFaction);
|
Rel relation = defendFaction.getRelationTo(attackFaction);
|
||||||
|
|
||||||
// Check the relation
|
// Check the relation
|
||||||
if (fdefender.hasFaction() && relation.isFriend() && defenderPsFaction.getFlag(FFlag.FRIENDLYFIRE) == false)
|
if (udefender.hasFaction() && relation.isFriend() && defenderPsFaction.getFlag(FFlag.FRIENDLYFIRE) == false)
|
||||||
{
|
{
|
||||||
if (notify) fattacker.msg("<i>You can't hurt %s<i>.", relation.getDescPlayerMany());
|
if (notify) uattacker.msg("<i>You can't hurt %s<i>.", relation.getDescPlayerMany());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// You can not hurt neutrals in their own territory.
|
// You can not hurt neutrals in their own territory.
|
||||||
boolean ownTerritory = fdefender.isInOwnTerritory();
|
boolean ownTerritory = udefender.isInOwnTerritory();
|
||||||
if (fdefender.hasFaction() && ownTerritory && relation == Rel.NEUTRAL)
|
|
||||||
|
if (udefender.hasFaction() && ownTerritory && relation == Rel.NEUTRAL)
|
||||||
{
|
{
|
||||||
if (notify)
|
if (notify)
|
||||||
{
|
{
|
||||||
fattacker.msg("<i>You can't hurt %s<i> in their own territory unless you declare them as an enemy.", fdefender.describeTo(fattacker));
|
uattacker.msg("<i>You can't hurt %s<i> in their own territory unless you declare them as an enemy.", udefender.describeTo(uattacker));
|
||||||
fdefender.msg("%s<i> tried to hurt you.", fattacker.describeTo(fdefender, true));
|
udefender.msg("%s<i> tried to hurt you.", uattacker.describeTo(udefender, true));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Damage will be dealt. However check if the damage should be reduced.
|
// Damage will be dealt. However check if the damage should be reduced.
|
||||||
double damage = event.getDamage();
|
double damage = event.getDamage();
|
||||||
if (damage > 0.0 && fdefender.hasFaction() && ownTerritory && uconf.territoryShieldFactor > 0)
|
if (damage > 0.0 && udefender.hasFaction() && ownTerritory && uconf.territoryShieldFactor > 0)
|
||||||
{
|
{
|
||||||
int newDamage = (int)Math.ceil(damage * (1D - uconf.territoryShieldFactor));
|
int newDamage = (int)Math.ceil(damage * (1D - uconf.territoryShieldFactor));
|
||||||
event.setDamage(newDamage);
|
event.setDamage(newDamage);
|
||||||
@ -382,7 +383,7 @@ public class FactionsListenerMain implements Listener
|
|||||||
if (notify)
|
if (notify)
|
||||||
{
|
{
|
||||||
String perc = MessageFormat.format("{0,number,#%}", (uconf.territoryShieldFactor)); // TODO does this display correctly??
|
String perc = MessageFormat.format("{0,number,#%}", (uconf.territoryShieldFactor)); // TODO does this display correctly??
|
||||||
fdefender.msg("<i>Enemy damage reduced by <rose>%s<i>.", perc);
|
udefender.msg("<i>Enemy damage reduced by <rose>%s<i>.", perc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user