Merge pull request #197 from alkarinv/master
Added a new Factions event for power loss
This commit is contained in:
commit
0948800678
78
src/com/massivecraft/factions/event/PowerLossEvent.java
Normal file
78
src/com/massivecraft/factions/event/PowerLossEvent.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package com.massivecraft.factions.event;
|
||||||
|
|
||||||
|
import src.com.massivecraft.factions.FPlayer;
|
||||||
|
import src.com.massivecraft.factions.Faction;
|
||||||
|
|
||||||
|
public class PowerLossEvent extends Event implements Cancellable
|
||||||
|
{
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private boolean cancelled;
|
||||||
|
private Faction faction;
|
||||||
|
private FPlayer fplayer;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public PowerLossEvent(Faction f, FPlayer p)
|
||||||
|
{
|
||||||
|
cancelled = false;
|
||||||
|
faction = f;
|
||||||
|
fplayer = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Faction getFaction()
|
||||||
|
{
|
||||||
|
return faction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFactionId()
|
||||||
|
{
|
||||||
|
return faction.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFactionTag()
|
||||||
|
{
|
||||||
|
return faction.getTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FPlayer getFPlayer()
|
||||||
|
{
|
||||||
|
return fplayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer()
|
||||||
|
{
|
||||||
|
return fplayer.getPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled()
|
||||||
|
{
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean c)
|
||||||
|
{
|
||||||
|
this.cancelled = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
@ -57,6 +60,7 @@ public class FactionsEntityListener implements Listener
|
|||||||
this.p = p;
|
this.p = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onEntityDeath(EntityDeathEvent event)
|
public void onEntityDeath(EntityDeathEvent event)
|
||||||
{
|
{
|
||||||
@ -67,20 +71,35 @@ public class FactionsEntityListener implements Listener
|
|||||||
FPlayer fplayer = FPlayers.i.get(player);
|
FPlayer fplayer = FPlayers.i.get(player);
|
||||||
Faction faction = Board.getFactionAt(new FLocation(player.getLocation()));
|
Faction faction = Board.getFactionAt(new FLocation(player.getLocation()));
|
||||||
|
|
||||||
|
PowerLossEvent powerLossEvent = new PowerLossEvent(faction,fplayer);
|
||||||
|
// Check for no power loss conditions
|
||||||
if ( ! faction.getFlag(FFlag.POWERLOSS))
|
if ( ! faction.getFlag(FFlag.POWERLOSS))
|
||||||
{
|
{
|
||||||
fplayer.msg("<i>You didn't lose any power since the territory you died in works that way.");
|
powerLossEvent.setMessage("<i>You didn't lose any power since the territory you died in works that way.");
|
||||||
return;
|
powerLossEvent.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
else if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName()))
|
||||||
if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName()))
|
|
||||||
{
|
{
|
||||||
fplayer.msg("<i>You didn't lose any power due to the world you died in.");
|
powerLossEvent.setMessage("<i>You didn't lose any power due to the world you died in.");
|
||||||
return;
|
powerLossEvent.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
powerLossEvent.setMessage("<i>Your power is now <h>%d / %d");
|
||||||
|
}
|
||||||
|
// call Event
|
||||||
|
Bukkit.getPluginManager().callEvent(powerLossEvent);
|
||||||
|
|
||||||
|
// Call player onDeath if the event is not cancelled
|
||||||
|
if(!powerLossEvent.isCancelled())
|
||||||
|
{
|
||||||
fplayer.onDeath();
|
fplayer.onDeath();
|
||||||
fplayer.msg("<i>Your power is now <h>"+fplayer.getPowerRounded()+" / "+fplayer.getPowerMaxRounded());
|
}
|
||||||
|
// Send the message from the powerLossEvent
|
||||||
|
final String msg = powerLossEvent.getMessage();
|
||||||
|
if (msg != null && !msg.isEmpty())
|
||||||
|
{
|
||||||
|
fplayer.msg(msg,fplayer.getPowerRounded(),fplayer.getPowerMaxRounded());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
Loading…
Reference in New Issue
Block a user