More econ event moves

This commit is contained in:
Olof Larsson 2013-04-19 14:08:45 +02:00
parent f22ea3300f
commit c6739c4aa9
10 changed files with 130 additions and 143 deletions

View File

@ -7,8 +7,9 @@ import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.massivecraft.factions.event.FactionsEventLeave;
import com.massivecraft.factions.event.FactionsEventLandClaim;
import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.integration.Econ;
@ -674,17 +675,10 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
public void leave(boolean makePay)
{
Faction myFaction = this.getFaction();
makePay = makePay && Econ.isEnabled() && ! this.isUsingAdminMode();
if (myFaction == null)
{
resetFactionData();
return;
}
boolean permanent = myFaction.getFlag(FFlag.PERMANENT);
boolean perm = myFaction.getFlag(FFlag.PERMANENT);
if (!perm && this.getRole() == Rel.LEADER && myFaction.getFPlayers().size() > 1)
if (!permanent && this.getRole() == Rel.LEADER && myFaction.getFPlayers().size() > 1)
{
msg("<b>You must give the admin role to someone else first.");
return;
@ -696,15 +690,10 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
return;
}
// if economy is enabled and they're not on the bypass list, make sure they can pay
if (makePay && ! Econ.hasAtLeast(this, ConfServer.econCostLeave, "to leave your faction.")) return;
FactionsEventLeave leaveEvent = new FactionsEventLeave(sender, this, myFaction, FactionsEventLeave.PlayerLeaveReason.LEAVE);
leaveEvent.run();
if (leaveEvent.isCancelled()) return;
// then make 'em pay (if applicable)
if (makePay && ! Econ.modifyMoney(this, -ConfServer.econCostLeave, "leave your faction")) return;
// Event
FactionsEventMembershipChange membershipChangeEvent = new FactionsEventMembershipChange(sender, this, myFaction, MembershipChangeReason.LEAVE);
membershipChangeEvent.run();
if (membershipChangeEvent.isCancelled()) return;
// Am I the last one in the faction?
if (myFaction.getFPlayers().size() == 1)
@ -727,7 +716,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
this.resetFactionData();
if (myFaction.isNormal() && !perm && myFaction.getFPlayers().isEmpty())
if (myFaction.isNormal() && !permanent && myFaction.getFPlayers().isEmpty())
{
// Remove this faction
for (FPlayer fplayer : FPlayerColl.get().getAllOnline())

View File

@ -10,8 +10,9 @@ import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.event.FactionsEventJoin;
import com.massivecraft.factions.event.FactionsEventCreate;
import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsCreate extends FCommand
@ -66,7 +67,7 @@ public class CmdFactionsCreate extends FCommand
fme.setRole(Rel.LEADER);
fme.setFaction(faction);
FactionsEventJoin joinEvent = new FactionsEventJoin(sender, fme, faction, FactionsEventJoin.PlayerJoinReason.CREATE);
FactionsEventMembershipChange joinEvent = new FactionsEventMembershipChange(sender, fme, faction, MembershipChangeReason.CREATE);
joinEvent.run();
// NOTE: join event cannot be cancelled or you'll have an empty faction

View File

@ -2,13 +2,15 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FactionsEventLeave;
import com.massivecraft.factions.event.FactionsEventDisband;
import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Perm;
@ -53,8 +55,8 @@ public class CmdFactionsDisband extends FCommand
// Send FPlayerLeaveEvent for each player in the faction
for (FPlayer fplayer : faction.getFPlayers())
{
FactionsEventLeave leaveEvent = new FactionsEventLeave(sender, fplayer, faction, FactionsEventLeave.PlayerLeaveReason.DISBAND);
leaveEvent.run();
FactionsEventMembershipChange membershipChangeEvent = new FactionsEventMembershipChange(sender, fplayer, FactionColl.get().getNone(), MembershipChangeReason.DISBAND);
membershipChangeEvent.run();
}
// Inform all players

View File

@ -1,16 +1,14 @@
package com.massivecraft.factions.cmd;
import org.bukkit.Bukkit;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FactionsEventJoin;
import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsJoin extends FCommand
@ -28,6 +26,7 @@ public class CmdFactionsJoin extends FCommand
@Override
public void perform()
{
// Args
Faction faction = this.arg(0, ARFaction.get());
if (faction == null) return;
@ -36,6 +35,7 @@ public class CmdFactionsJoin extends FCommand
boolean samePlayer = fplayer == fme;
// Validate
if (!samePlayer && ! Perm.JOIN_OTHERS.has(sender, false))
{
msg("<b>You do not have permission to move other players into a faction.");
@ -70,30 +70,33 @@ public class CmdFactionsJoin extends FCommand
{
msg("<i>This faction requires invitation.");
if (samePlayer)
{
faction.msg("%s<i> tried to join your faction.", fplayer.describeTo(faction, true));
}
return;
}
// trigger the join event (cancellable)
FactionsEventJoin joinEvent = new FactionsEventJoin(FPlayerColl.get().get(me),faction,FactionsEventJoin.PlayerJoinReason.JOIN);
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
if (joinEvent.isCancelled()) return;
// then make 'em pay (if applicable)
if (samePlayer && ! payForCommand(ConfServer.econCostJoin)) return;
// Event
FactionsEventMembershipChange membershipChangeEvent = new FactionsEventMembershipChange(sender, fme, faction, MembershipChangeReason.JOIN);
membershipChangeEvent.run();
if (membershipChangeEvent.isCancelled()) return;
// Inform
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));
fme.msg("<i>%s successfully joined %s.", fplayer.describeTo(fme, true), faction.getTag(fme));
// Apply
fplayer.resetFactionData();
fplayer.setFaction(faction);
fme.setRole(ConfServer.factionRankDefault); // They have just joined a faction, start them out on the lowest rank (default config).
faction.deinvite(fplayer);
faction.setInvited(fplayer, false);
// Derplog
if (ConfServer.logFactionJoin)
{
if (samePlayer)

View File

@ -1,16 +1,16 @@
package com.massivecraft.factions.cmd;
import org.bukkit.Bukkit;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.event.FactionsEventLeave;
import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsKick extends FCommand
@ -28,55 +28,59 @@ public class CmdFactionsKick extends FCommand
@Override
public void perform()
{
FPlayer you = this.arg(1, ARFPlayer.getStartAny());
if (you == null) return;
// Arg
FPlayer fplayer = this.arg(1, ARFPlayer.getStartAny());
if (fplayer == null) return;
if (fme == you)
// Validate
if (fme == fplayer)
{
msg("<b>You cannot kick yourself.");
msg("<i>You might want to: %s", Factions.get().getOuterCmdFactions().cmdFactionsLeave.getUseageTemplate(false));
return;
}
if (you.getRole() == Rel.LEADER && !(this.senderIsConsole || fme.isUsingAdminMode()))
if (fplayer.getRole() == Rel.LEADER && !(this.senderIsConsole || fme.isUsingAdminMode()))
{
msg("<b>The leader can not be kicked.");
return;
}
if ( ! ConfServer.canLeaveWithNegativePower && you.getPower() < 0)
if ( ! ConfServer.canLeaveWithNegativePower && fplayer.getPower() < 0)
{
msg("<b>You cannot kick that member until their power is positive.");
return;
}
Faction yourFaction = you.getFaction();
// FPerm
Faction fplayerFaction = fplayer.getFaction();
if (!FPerm.KICK.has(sender, fplayerFaction)) return;
if (fme != null && ! FPerm.KICK.has(fme, yourFaction)) return;
// trigger the leave event (cancellable) [reason:kicked]
FactionsEventLeave event = new FactionsEventLeave(you, you.getFaction(), FactionsEventLeave.PlayerLeaveReason.KICKED);
Bukkit.getServer().getPluginManager().callEvent(event);
// Event
FactionsEventMembershipChange event = new FactionsEventMembershipChange(sender, fplayer, FactionColl.get().getNone(), MembershipChangeReason.KICK);
event.run();
if (event.isCancelled()) return;
// then make 'em pay (if applicable)
if (!payForCommand(ConfServer.econCostKick)) 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)
// Inform
fplayerFaction.msg("%s<i> kicked %s<i> from the faction! :O", fme.describeTo(fplayerFaction, true), fplayer.describeTo(fplayerFaction, true));
fplayer.msg("%s<i> kicked you from %s<i>! :O", fme.describeTo(fplayer, true), fplayerFaction.describeTo(fplayer));
if (fplayerFaction != myFaction)
{
fme.msg("<i>You kicked %s<i> from the faction %s<i>!", you.describeTo(fme), yourFaction.describeTo(fme));
fme.msg("<i>You kicked %s<i> from the faction %s<i>!", fplayer.describeTo(fme), fplayerFaction.describeTo(fme));
}
if (ConfServer.logFactionKick)
Factions.get().log((senderIsConsole ? "A console command" : fme.getName())+" kicked "+you.getName()+" from the faction: "+yourFaction.getTag());
{
Factions.get().log((senderIsConsole ? "A console command" : fme.getName())+" kicked "+fplayer.getName()+" from the faction: "+fplayerFaction.getTag());
}
if (you.getRole() == Rel.LEADER)
yourFaction.promoteNewLeader();
yourFaction.deinvite(you);
you.resetFactionData();
// Apply
if (fplayer.getRole() == Rel.LEADER)
{
fplayerFaction.promoteNewLeader();
}
fplayerFaction.setInvited(fplayer, false);
fplayer.resetFactionData();
}
}

View File

@ -7,7 +7,8 @@ import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FactionsEventJoin;
import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt;
@ -65,7 +66,7 @@ public class CmdFactionsLeader extends FCommand
// only perform a FPlayerJoinEvent when newLeader isn't actually in the faction
if (newLeader.getFaction() != targetFaction)
{
FactionsEventJoin event = new FactionsEventJoin(sender, newLeader, targetFaction, FactionsEventJoin.PlayerJoinReason.LEADER);
FactionsEventMembershipChange event = new FactionsEventMembershipChange(sender, newLeader, targetFaction, MembershipChangeReason.LEADER);
event.run();
if (event.isCancelled()) return;
}

View File

@ -58,10 +58,4 @@ public abstract class FCommand extends MCommand
return false;
}
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost
/*public boolean payForCommand(double cost)
{
return Econ.payForAction(cost, sender, this.getDesc());
}*/
}

View File

@ -1,53 +0,0 @@
package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
public class FactionsEventJoin extends FactionsEventAbstractSender
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final FPlayer fplayer;
public FPlayer getFPlayer() { return this.fplayer; }
private final Faction faction;
public Faction getFaction() { return this.faction; }
private final PlayerJoinReason reason;
public PlayerJoinReason getReason() { return reason; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionsEventJoin(CommandSender sender, FPlayer fplayer, Faction faction, PlayerJoinReason reason)
{
super(sender);
this.fplayer = fplayer;
this.faction = faction;
this.reason = reason;
}
// -------------------------------------------- //
// INTERNAL ENUM
// -------------------------------------------- //
public enum PlayerJoinReason
{
CREATE, LEADER, JOIN
}
}

View File

@ -6,7 +6,7 @@ import org.bukkit.event.HandlerList;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
public class FactionsEventLeave extends FactionsEventAbstractSender
public class FactionsEventMembershipChange extends FactionsEventAbstractSender
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
@ -23,31 +23,28 @@ public class FactionsEventLeave extends FactionsEventAbstractSender
@Override
public void setCancelled(boolean cancelled)
{
if (this.reason == PlayerLeaveReason.DISBAND || this.reason == PlayerLeaveReason.RESET)
{
cancelled = false;
}
if (!this.reason.isCancellable()) cancelled = false;
super.setCancelled(cancelled);
}
private final FPlayer fplayer;
public FPlayer getFPlayer() { return this.fplayer; }
private final Faction faction;
public Faction getFaction() { return this.faction; }
private final Faction newFaction;
public Faction getNewFaction() { return this.newFaction; }
private final PlayerLeaveReason reason;
public PlayerLeaveReason getReason() { return this.reason; }
private final MembershipChangeReason reason;
public MembershipChangeReason getReason() { return this.reason; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionsEventLeave(CommandSender sender, FPlayer fplayer, Faction faction, PlayerLeaveReason reason)
public FactionsEventMembershipChange(CommandSender sender, FPlayer fplayer, Faction newFaction, MembershipChangeReason reason)
{
super(sender);
this.fplayer = fplayer;
this.faction = faction;
this.newFaction = newFaction;
this.reason = reason;
}
@ -55,9 +52,28 @@ public class FactionsEventLeave extends FactionsEventAbstractSender
// INTERNAL ENUM
// -------------------------------------------- //
public enum PlayerLeaveReason
public enum MembershipChangeReason
{
KICKED, DISBAND, RESET, JOINOTHER, LEAVE
// Join
JOIN (true),
CREATE (false),
LEADER (true),
// Leave
LEAVE (true),
//JOINOTHER (true),
KICK (true),
DISBAND (false),
//RESET (false),
;
private final boolean cancellable;
public boolean isCancellable() { return this.cancellable; }
private MembershipChangeReason(boolean cancellable)
{
this.cancellable = cancellable;
}
}
}

View File

@ -13,6 +13,8 @@ import com.massivecraft.factions.event.FactionsEventDescriptionChange;
import com.massivecraft.factions.event.FactionsEventHomeChange;
import com.massivecraft.factions.event.FactionsEventHomeTeleport;
import com.massivecraft.factions.event.FactionsEventInvitedChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.event.FactionsEventOpenChange;
import com.massivecraft.factions.event.FactionsEventRelationChange;
import com.massivecraft.factions.event.FactionsEventTagChange;
@ -110,4 +112,32 @@ public class FactionsListenerEcon implements Listener
payForCommand(event, ConfServer.econCostHome, Factions.get().getOuterCmdFactions().cmdFactionsHome);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(FactionsEventMembershipChange event)
{
Double cost = null;
MCommand command = null;
if (event.getReason() == MembershipChangeReason.JOIN)
{
cost = ConfServer.econCostJoin;
command = Factions.get().getOuterCmdFactions().cmdFactionsJoin;
}
else if (event.getReason() == MembershipChangeReason.LEAVE)
{
cost = ConfServer.econCostLeave;
command = Factions.get().getOuterCmdFactions().cmdFactionsLeave;
}
else if (event.getReason() == MembershipChangeReason.KICK)
{
cost = ConfServer.econCostKick;
command = Factions.get().getOuterCmdFactions().cmdFactionsKick;
}
else
{
return;
}
payForCommand(event, cost, command);
}
}