mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-05 18:22:14 +01:00
Fix for PowerLossEvent Messages
This commit is contained in:
parent
1f5dc830be
commit
6eb23a200e
@ -1,14 +1,15 @@
|
||||
package com.massivecraft.factions.listeners;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Enderman;
|
||||
@ -44,6 +45,8 @@ import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.event.PowerLossEvent;
|
||||
import com.massivecraft.factions.listeners.FactionsBlockListener;
|
||||
import com.massivecraft.factions.struct.FFlag;
|
||||
import com.massivecraft.factions.struct.Rel;
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
@ -81,7 +84,7 @@ public class FactionsEntityListener implements Listener
|
||||
powerLossEvent.setCancelled(true);
|
||||
}
|
||||
else {
|
||||
powerLossEvent.setMessage("<i>Your power is now <h>"+fplayer.getPowerRounded()+" / "+fplayer.getPowerMaxRounded());
|
||||
powerLossEvent.setMessage("<i>Your power is now <h>%d / %d");
|
||||
}
|
||||
// call Event
|
||||
Bukkit.getPluginManager().callEvent(powerLossEvent);
|
||||
@ -90,7 +93,7 @@ public class FactionsEntityListener implements Listener
|
||||
final String msg = powerLossEvent.getMessage();
|
||||
if (msg != null && !msg.isEmpty())
|
||||
{
|
||||
fplayer.msg(msg);
|
||||
fplayer.msg(msg,fplayer.getPowerRounded(),fplayer.getPowerMaxRounded());
|
||||
}
|
||||
// Call player onDeath if the event is not cancelled
|
||||
if(!powerLossEvent.isCancelled())
|
||||
@ -98,12 +101,12 @@ public class FactionsEntityListener implements Listener
|
||||
fplayer.onDeath();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEntityDamage(EntityDamageEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
|
||||
if (event instanceof EntityDamageByEntityEvent)
|
||||
{
|
||||
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent)event;
|
||||
@ -170,7 +173,7 @@ public class FactionsEntityListener implements Listener
|
||||
public void onEntityCombustByEntity(EntityCombustByEntityEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
|
||||
EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE, 0);
|
||||
if ( ! this.canDamagerHurtDamagee(sub, false))
|
||||
event.setCancelled(true);
|
||||
@ -224,14 +227,14 @@ public class FactionsEntityListener implements Listener
|
||||
Entity damager = sub.getDamager();
|
||||
Entity damagee = sub.getEntity();
|
||||
int damage = sub.getDamage();
|
||||
|
||||
|
||||
if ( ! (damagee instanceof Player)) return true;
|
||||
|
||||
|
||||
FPlayer defender = FPlayers.i.get((Player)damagee);
|
||||
|
||||
|
||||
if (defender == null || defender.getPlayer() == null)
|
||||
return true;
|
||||
|
||||
|
||||
Location defenderLoc = defender.getPlayer().getLocation();
|
||||
|
||||
Faction defLocFaction = Board.getFactionAt(new FLocation(defenderLoc));
|
||||
@ -244,7 +247,7 @@ public class FactionsEntityListener implements Listener
|
||||
return true;
|
||||
|
||||
// Players can not take attack damage in a SafeZone, or possibly peaceful territory
|
||||
|
||||
|
||||
if (defLocFaction.getFlag(FFlag.PVP) == false)
|
||||
{
|
||||
if (damager instanceof Player)
|
||||
@ -258,12 +261,12 @@ public class FactionsEntityListener implements Listener
|
||||
}
|
||||
return defLocFaction.getFlag(FFlag.MONSTERS);
|
||||
}
|
||||
|
||||
|
||||
if ( ! (damager instanceof Player))
|
||||
return true;
|
||||
|
||||
|
||||
FPlayer attacker = FPlayers.i.get((Player)damager);
|
||||
|
||||
|
||||
if (attacker == null || attacker.getPlayer() == null)
|
||||
return true;
|
||||
|
||||
@ -274,9 +277,9 @@ public class FactionsEntityListener implements Listener
|
||||
if (notify) attacker.msg("<i>You can't hurt other players for " + Conf.noPVPDamageToOthersForXSecondsAfterLogin + " seconds after logging in.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Faction locFaction = Board.getFactionAt(new FLocation(attacker));
|
||||
|
||||
|
||||
// so we know from above that the defender isn't in a safezone... what about the attacker, sneaky dog that he might be?
|
||||
if (locFaction.getFlag(FFlag.PVP) == false)
|
||||
{
|
||||
@ -289,7 +292,7 @@ public class FactionsEntityListener implements Listener
|
||||
|
||||
Faction defendFaction = defender.getFaction();
|
||||
Faction attackFaction = attacker.getFaction();
|
||||
|
||||
|
||||
if (attackFaction.isNone() && Conf.disablePVPForFactionlessPlayers)
|
||||
{
|
||||
if (notify) attacker.msg("<i>You can't hurt other players until you join a faction.");
|
||||
@ -308,16 +311,16 @@ public class FactionsEntityListener implements Listener
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Rel relation = defendFaction.getRelationTo(attackFaction);
|
||||
|
||||
|
||||
// Check the relation
|
||||
if (defender.hasFaction() && relation.isAtLeast(Conf.friendlyFireFromRel) && defLocFaction.getFlag(FFlag.FRIENDLYFIRE) == false)
|
||||
{
|
||||
if (notify) attacker.msg("<i>You can't hurt %s<i>.", relation.getDescPlayerMany());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// You can not hurt neutrals in their own territory.
|
||||
boolean ownTerritory = defender.isInOwnTerritory();
|
||||
if (defender.hasFaction() && ownTerritory && relation == Rel.NEUTRAL)
|
||||
@ -329,13 +332,13 @@ public class FactionsEntityListener implements Listener
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Damage will be dealt. However check if the damage should be reduced.
|
||||
if (damage > 0.0 && defender.hasFaction() && ownTerritory && Conf.territoryShieldFactor > 0)
|
||||
{
|
||||
int newDamage = (int)Math.ceil(damage * (1D - Conf.territoryShieldFactor));
|
||||
sub.setDamage(newDamage);
|
||||
|
||||
|
||||
// Send message
|
||||
if (notify)
|
||||
{
|
||||
@ -343,42 +346,42 @@ public class FactionsEntityListener implements Listener
|
||||
defender.msg("<i>Enemy damage reduced by <rose>%s<i>.", perc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
if (event.getLocation() == null) return;
|
||||
|
||||
|
||||
FLocation floc = new FLocation(event.getLocation());
|
||||
Faction faction = Board.getFactionAt(floc);
|
||||
|
||||
|
||||
if (faction.getFlag(FFlag.MONSTERS)) return;
|
||||
if ( ! Conf.monsters.contains(event.getEntityType())) return;
|
||||
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEntityTarget(EntityTargetEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
|
||||
// if there is a target
|
||||
Entity target = event.getTarget();
|
||||
if (target == null) return;
|
||||
|
||||
|
||||
// We are interested in blocking targeting for certain mobs:
|
||||
if ( ! Conf.monsters.contains(MiscUtil.creatureTypeFromEntity(event.getEntity()))) return;
|
||||
|
||||
|
||||
FLocation floc = new FLocation(target.getLocation());
|
||||
Faction faction = Board.getFactionAt(floc);
|
||||
|
||||
|
||||
if (faction.getFlag(FFlag.MONSTERS)) return;
|
||||
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -437,7 +440,7 @@ public class FactionsEntityListener implements Listener
|
||||
|
||||
FLocation floc = new FLocation(event.getBlock());
|
||||
Faction faction = Board.getFactionAt(floc);
|
||||
|
||||
|
||||
if (entity instanceof Enderman)
|
||||
{
|
||||
if ( ! faction.getFlag(FFlag.ENDERGRIEF))
|
||||
|
Loading…
Reference in New Issue
Block a user