(patrickfreed) (bladedpenguin) (donington) Custom Event System - custom events are provided for other developers to hook into to create their own plugins based around Factions! Check the factions/event folder for the currently implemented events.
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
|
||||
@@ -52,6 +55,14 @@ public class CmdAdmin extends FCommand
|
||||
return;
|
||||
}
|
||||
|
||||
// only perform a FPlayerJoinEvent when newLeader isn't actually in the faction
|
||||
if (fyou.getFaction() != targetFaction)
|
||||
{
|
||||
FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.i.get(me),targetFaction,FPlayerJoinEvent.PlayerJoinReason.LEADER);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return;
|
||||
}
|
||||
|
||||
FPlayer admin = targetFaction.getFPlayerAdmin();
|
||||
|
||||
// if target player is currently admin, demote and replace him
|
||||
|
||||
@@ -2,12 +2,16 @@ package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
||||
import com.massivecraft.factions.event.FactionCreateEvent;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
|
||||
@@ -54,7 +58,12 @@ public class CmdCreate extends FCommand
|
||||
sendMessage(tagValidationErrors);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// trigger the faction creation event (cancellable)
|
||||
FactionCreateEvent createEvent = new FactionCreateEvent(me, tag);
|
||||
Bukkit.getServer().getPluginManager().callEvent(createEvent);
|
||||
if(createEvent.isCancelled()) return;
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if ( ! payForCommand(Conf.econCostCreate, "to create a new faction", "for creating a new faction")) return;
|
||||
|
||||
@@ -67,7 +76,15 @@ public class CmdCreate extends FCommand
|
||||
return;
|
||||
}
|
||||
|
||||
// finish setting up the Faction
|
||||
faction.setTag(tag);
|
||||
|
||||
// trigger the faction join event for the creator
|
||||
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.i.get(me),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE);
|
||||
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
|
||||
// join event cannot be cancelled or you'll have an empty faction
|
||||
|
||||
// finish setting up the FPlayer
|
||||
fme.setRole(Role.ADMIN);
|
||||
fme.setFaction(faction);
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.event.FPlayerLeaveEvent;
|
||||
import com.massivecraft.factions.event.FactionDisbandEvent;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
@@ -62,6 +66,16 @@ public class CmdDisband extends FCommand
|
||||
return;
|
||||
}
|
||||
|
||||
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(me, faction.getId());
|
||||
Bukkit.getServer().getPluginManager().callEvent(disbandEvent);
|
||||
if(disbandEvent.isCancelled()) return;
|
||||
|
||||
// Send FPlayerLeaveEvent for each player in the faction
|
||||
for ( FPlayer fplayer : faction.getFPlayers() )
|
||||
{
|
||||
Bukkit.getServer().getPluginManager().callEvent(new FPlayerLeaveEvent(fplayer, faction, FPlayerLeaveEvent.PlayerLeaveReason.DISBAND));
|
||||
}
|
||||
|
||||
// Inform all players
|
||||
for (FPlayer fplayer : FPlayers.i.getOnline())
|
||||
{
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdJoin extends FCommand
|
||||
@@ -81,7 +85,13 @@ public class CmdJoin extends FCommand
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (samePlayer && ! payForCommand(Conf.econCostJoin, "to join a faction", "for joining a faction")) return;
|
||||
|
||||
// trigger the join event (cancellable)
|
||||
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.i.get(me),faction,FPlayerJoinEvent.PlayerJoinReason.COMMAND);
|
||||
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
|
||||
if (joinEvent.isCancelled()) return;
|
||||
|
||||
fme.msg("<i>%s successfully joined %s.", fplayer.describeTo(fme, true), faction.getTag(fme));
|
||||
|
||||
if (!samePlayer)
|
||||
fplayer.msg("<i>%s moved you into the faction %s.", fme.describeTo(fplayer, true), faction.getTag(fplayer));
|
||||
faction.msg("<i>%s joined your faction.", fplayer.describeTo(faction, true));
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
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.FPlayerLeaveEvent;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
|
||||
@@ -69,6 +71,11 @@ public class CmdKick extends FCommand
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if ( ! payForCommand(Conf.econCostKick, "to kick someone from the faction", "for kicking someone from the faction")) return;
|
||||
|
||||
// trigger the leave event (cancellable) [reason:kicked]
|
||||
FPlayerLeaveEvent event = new FPlayerLeaveEvent(you, you.getFaction(), FPlayerLeaveEvent.PlayerLeaveReason.KICKED);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
yourFaction.msg("%s<i> kicked %s<i> from the faction! :O", fme.describeTo(yourFaction, true), you.describeTo(yourFaction, true));
|
||||
you.msg("%s<i> kicked you from %s<i>! :O", fme.describeTo(you, true), yourFaction.describeTo(you));
|
||||
if (yourFaction != myFaction)
|
||||
|
||||
@@ -2,9 +2,12 @@ package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.event.FactionRenameEvent;
|
||||
import com.massivecraft.factions.integration.SpoutFeatures;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
@@ -50,7 +53,12 @@ public class CmdTag extends FCommand
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if ( ! payForCommand(Conf.econCostTag, "to change the faction tag", "for changing the faction tag")) return;
|
||||
|
||||
|
||||
// trigger the faction rename event (cancellable)
|
||||
FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag);
|
||||
Bukkit.getServer().getPluginManager().callEvent(renameEvent);
|
||||
if(renameEvent.isCancelled()) return;
|
||||
|
||||
String oldtag = myFaction.getTag();
|
||||
myFaction.setTag(tag);
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.event.LandUnclaimEvent;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.integration.SpoutFeatures;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
@@ -101,7 +104,6 @@ public class CmdUnclaim extends FCommand
|
||||
return;
|
||||
}
|
||||
|
||||
//String moneyBack = "<i>";
|
||||
if (Econ.shouldBeUsed())
|
||||
{
|
||||
double refund = Econ.calculateClaimRefund(myFaction.getLandRounded());
|
||||
@@ -114,54 +116,12 @@ public class CmdUnclaim extends FCommand
|
||||
{
|
||||
if ( ! Econ.modifyMoney(fme , refund, "to unclaim this land", "for unclaiming this land")) return;
|
||||
}
|
||||
|
||||
/*
|
||||
// a real refund
|
||||
if (refund > 0.0)
|
||||
{
|
||||
if(Conf.bankFactionPaysLandCosts)
|
||||
{
|
||||
Faction faction = myFaction;
|
||||
faction.addMoney(refund);
|
||||
moneyBack = " "+faction.getTag()+"<i> received a refund of <h>"+Econ.moneyString(refund)+"<i>.";
|
||||
}
|
||||
else
|
||||
{
|
||||
Econ.addMoney(fme.getName(), refund);
|
||||
moneyBack = " They received a refund of <h>"+Econ.moneyString(refund)+"<i>.";
|
||||
}
|
||||
}
|
||||
// wait, you're charging people to unclaim land? outrageous
|
||||
else if (refund < 0.0)
|
||||
{
|
||||
if(Conf.bankFactionPaysLandCosts)
|
||||
{
|
||||
Faction faction = myFaction;
|
||||
if(!faction.removeMoney(-refund))
|
||||
{
|
||||
msg("<b>Unclaiming this land will cost <h>%s<b> which your faction can't currently afford.", Econ.moneyString(-refund));
|
||||
return;
|
||||
}
|
||||
moneyBack = " It cost "+faction.getTag()+" <h>"+Econ.moneyString(refund)+"<i>.";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Econ.deductMoney(fme.getName(), -refund))
|
||||
{
|
||||
msg("<b>Unclaiming this land will cost <h>%s<b> which you can't currently afford.", Econ.moneyString(-refund));
|
||||
return;
|
||||
}
|
||||
moneyBack = " It cost them <h>"+Econ.moneyString(refund)+"<i>.";
|
||||
}
|
||||
}
|
||||
// no refund
|
||||
else
|
||||
{
|
||||
moneyBack = "";
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(flocation, otherFaction, fme);
|
||||
Bukkit.getServer().getPluginManager().callEvent(unclaimEvent);
|
||||
if(unclaimEvent.isCancelled()) return;
|
||||
|
||||
Board.removeAt(flocation);
|
||||
SpoutFeatures.updateTerritoryDisplayLoc(flocation);
|
||||
myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true));
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.event.LandUnclaimAllEvent;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.integration.SpoutFeatures;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
@@ -42,6 +45,10 @@ public class CmdUnclaimall extends FCommand
|
||||
}
|
||||
}
|
||||
|
||||
LandUnclaimAllEvent unclaimAllEvent = new LandUnclaimAllEvent(myFaction, fme);
|
||||
Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent);
|
||||
// this event cannot be cancelled
|
||||
|
||||
Board.unclaimAll(myFaction.getId());
|
||||
myFaction.msg("%s<i> unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true));
|
||||
SpoutFeatures.updateTerritoryDisplayLoc(null);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.event.FactionRelationEvent;
|
||||
import com.massivecraft.factions.integration.SpoutFeatures;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Relation;
|
||||
@@ -48,14 +50,23 @@ public abstract class FRelationCommand extends FCommand
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if ( ! payForCommand(targetRelation.getRelationCost(), "to change a relation wish", "for changing a relation wish")) return;
|
||||
|
||||
// try to set the new relation
|
||||
Relation oldRelation = myFaction.getRelationTo(them, true);
|
||||
myFaction.setRelationWish(them, targetRelation);
|
||||
Relation currentRelation = myFaction.getRelationTo(them, true);
|
||||
ChatColor currentRelationColor = currentRelation.getColor();
|
||||
|
||||
// if the relation change was successful
|
||||
if (targetRelation.value == currentRelation.value)
|
||||
{
|
||||
// trigger the faction relation event
|
||||
FactionRelationEvent relationEvent = new FactionRelationEvent(myFaction, them, oldRelation, currentRelation);
|
||||
Bukkit.getServer().getPluginManager().callEvent(relationEvent);
|
||||
|
||||
them.msg("<i>Your faction is now "+currentRelationColor+targetRelation.toString()+"<i> to "+currentRelationColor+myFaction.getTag());
|
||||
myFaction.msg("<i>Your faction is now "+currentRelationColor+targetRelation.toString()+"<i> to "+currentRelationColor+them.getTag());
|
||||
}
|
||||
// inform the other faction of your request
|
||||
else
|
||||
{
|
||||
them.msg(currentRelationColor+myFaction.getTag()+"<i> wishes to be your "+targetRelation.getColor()+targetRelation.toString());
|
||||
|
||||
Reference in New Issue
Block a user