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