Major messaround with the internal events and payForCommand logic. Not done just yet though.

This commit is contained in:
Olof Larsson 2013-04-19 12:27:39 +02:00
parent d3488311de
commit 61baf70ed1
46 changed files with 638 additions and 626 deletions

View File

@ -26,7 +26,6 @@ permissions:
factions.claim.radius: {description: claim land in a large radius} factions.claim.radius: {description: claim land in a large radius}
factions.config: {description: change a conf.json setting} factions.config: {description: change a conf.json setting}
factions.create: {description: create a new faction} factions.create: {description: create a new faction}
factions.deinvite: {description: remove a pending invitation}
factions.demote: {description: demote lesser members in your faction} factions.demote: {description: demote lesser members in your faction}
factions.description: {description: change the faction description} factions.description: {description: change the faction description}
factions.disband: {description: disband a faction} factions.disband: {description: disband a faction}
@ -34,7 +33,7 @@ permissions:
factions.flag.set: {description: set faction flags} factions.flag.set: {description: set faction flags}
factions.help: {description: display a help page} factions.help: {description: display a help page}
factions.home: {description: teleport to the faction home} factions.home: {description: teleport to the faction home}
factions.invite: {description: invite a player to your faction} factions.invite: {description: set if a player is invited}
factions.join: {description: join a faction} factions.join: {description: join a faction}
factions.join.any: {description: join any faction, bypassing invitation process for closed factions} factions.join.any: {description: join any faction, bypassing invitation process for closed factions}
factions.join.others: {description: specify another player in the join command, to move them to the specified faction} factions.join.others: {description: specify another player in the join command, to move them to the specified faction}
@ -134,7 +133,6 @@ permissions:
factions.cape.*: true factions.cape.*: true
factions.claim: true factions.claim: true
factions.claim.radius: true factions.claim.radius: true
factions.deinvite: true
factions.demote: true factions.demote: true
factions.description: true factions.description: true
factions.disband: true factions.disband: true

View File

@ -283,9 +283,10 @@ public class ConfServer extends SimpleConfig
public static double econCostLeave = 0.0; public static double econCostLeave = 0.0;
public static double econCostKick = 0.0; public static double econCostKick = 0.0;
public static double econCostInvite = 0.0; public static double econCostInvite = 0.0;
public static double econCostDeinvite = 0.0;
public static double econCostHome = 0.0; public static double econCostHome = 0.0;
public static double econCostTag = 0.0; public static double econCostTag = 0.0;
public static double econCostDesc = 0.0; public static double econCostDescription = 0.0;
public static double econCostTitle = 0.0; public static double econCostTitle = 0.0;
public static double econCostOpen = 0.0; public static double econCostOpen = 0.0;
public static double econCostAlly = 0.0; public static double econCostAlly = 0.0;

View File

@ -3,13 +3,12 @@ package com.massivecraft.factions;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.event.FactionsEventLeave;
import com.massivecraft.factions.event.LandClaimEvent; import com.massivecraft.factions.event.FactionsEventLandClaim;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
@ -700,8 +699,8 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
// if economy is enabled and they're not on the bypass list, make sure they can pay // 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; if (makePay && ! Econ.hasAtLeast(this, ConfServer.econCostLeave, "to leave your faction.")) return;
FPlayerLeaveEvent leaveEvent = new FPlayerLeaveEvent(this,myFaction,FPlayerLeaveEvent.PlayerLeaveReason.LEAVE); FactionsEventLeave leaveEvent = new FactionsEventLeave(sender, this, myFaction, FactionsEventLeave.PlayerLeaveReason.LEAVE);
Bukkit.getServer().getPluginManager().callEvent(leaveEvent); leaveEvent.run();
if (leaveEvent.isCancelled()) return; if (leaveEvent.isCancelled()) return;
// then make 'em pay (if applicable) // then make 'em pay (if applicable)
@ -858,8 +857,8 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
if ( ! Econ.hasAtLeast(payee, cost, "to claim this land")) return false; if ( ! Econ.hasAtLeast(payee, cost, "to claim this land")) return false;
} }
LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this); FactionsEventLandClaim claimEvent = new FactionsEventLandClaim(sender, forFaction, flocation);
Bukkit.getServer().getPluginManager().callEvent(claimEvent); claimEvent.run();
if (claimEvent.isCancelled()) return false; if (claimEvent.isCancelled()) return false;
// then make 'em pay (if applicable) // then make 'em pay (if applicable)

View File

@ -354,39 +354,28 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
return this.isInvited(fplayer.getId()); return this.isInvited(fplayer.getId());
} }
public boolean invite(String playerId) public boolean setInvited(String playerId, boolean invited)
{ {
TreeSet<String> invitedPlayerIds = this.getInvitedPlayerIds(); TreeSet<String> invitedPlayerIds = this.getInvitedPlayerIds();
if (invitedPlayerIds.add(playerId.toLowerCase())) boolean ret;
if (invited)
{ {
this.setInvitedPlayerIds(invitedPlayerIds); ret = invitedPlayerIds.add(playerId.toLowerCase());
return true;
} }
return false; else
}
public void invite(FPlayer fplayer)
{
this.invite(fplayer.getId());
}
public boolean deinvite(String playerId)
{
TreeSet<String> invitedPlayerIds = this.getInvitedPlayerIds();
if (invitedPlayerIds.remove(playerId.toLowerCase()))
{ {
this.setInvitedPlayerIds(invitedPlayerIds); ret = invitedPlayerIds.remove(playerId.toLowerCase());
return true;
} }
return false; this.setInvitedPlayerIds(invitedPlayerIds);
return ret;
} }
public void deinvite(FPlayer fplayer) public void setInvited(FPlayer fplayer, boolean invited)
{ {
this.deinvite(fplayer.getId()); this.setInvited(fplayer.getId(), invited);
} }
// -------------------------------------------- // // -------------------------------------------- //
// FIELD: relationWish // FIELD: relationWish
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -26,7 +26,6 @@ import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.integration.herochat.HerochatFeatures; import com.massivecraft.factions.integration.herochat.HerochatFeatures;
import com.massivecraft.factions.listeners.FactionsListenerChat; import com.massivecraft.factions.listeners.FactionsListenerChat;
import com.massivecraft.factions.listeners.FactionsListenerEcon; import com.massivecraft.factions.listeners.FactionsListenerEcon;
import com.massivecraft.factions.listeners.TodoFactionsEntityListener;
import com.massivecraft.factions.listeners.FactionsListenerExploit; import com.massivecraft.factions.listeners.FactionsListenerExploit;
import com.massivecraft.factions.listeners.FactionsListenerMain; import com.massivecraft.factions.listeners.FactionsListenerMain;
import com.massivecraft.factions.listeners.TodoFactionsPlayerListener; import com.massivecraft.factions.listeners.TodoFactionsPlayerListener;
@ -57,7 +56,6 @@ public class Factions extends MPlugin
// Listeners // Listeners
public TodoFactionsPlayerListener playerListener; public TodoFactionsPlayerListener playerListener;
public TodoFactionsEntityListener entityListener;
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
@ -90,13 +88,10 @@ public class Factions extends MPlugin
// Right now only a few situations are handled through this listener. // Right now only a few situations are handled through this listener.
FactionsListenerEcon.get().setup(); FactionsListenerEcon.get().setup();
// TODO: Get rid of these // TODO: Get rid of this one
this.playerListener = new TodoFactionsPlayerListener(); this.playerListener = new TodoFactionsPlayerListener();
getServer().getPluginManager().registerEvents(this.playerListener, this); getServer().getPluginManager().registerEvents(this.playerListener, this);
this.entityListener = new TodoFactionsEntityListener();
getServer().getPluginManager().registerEvents(this.entityListener, this);
// Schedule recurring non-tps-dependent tasks // Schedule recurring non-tps-dependent tasks
AutoLeaveTask.get().schedule(this); AutoLeaveTask.get().schedule(this);
EconLandRewardTask.get().schedule(this); EconLandRewardTask.get().schedule(this);

View File

@ -23,7 +23,6 @@ public enum Perm
CLAIM_RADIUS("claim.radius"), CLAIM_RADIUS("claim.radius"),
CONFIG("config"), CONFIG("config"),
CREATE("create"), CREATE("create"),
DEINVITE("deinvite"),
DEMOTE("demote"), DEMOTE("demote"),
DESCRIPTION("description"), DESCRIPTION("description"),
DISBAND("disband"), DISBAND("disband"),

View File

@ -17,7 +17,6 @@ public class CmdFactions extends FCommand
public CmdFactionsCape cmdFactionsCape = new CmdFactionsCape(); public CmdFactionsCape cmdFactionsCape = new CmdFactionsCape();
public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim();
public CmdFactionsCreate cmdFactionsCreate = new CmdFactionsCreate(); public CmdFactionsCreate cmdFactionsCreate = new CmdFactionsCreate();
public CmdFactionsDeinvite cmdFactionsDeinvite = new CmdFactionsDeinvite();
public CmdFactionsDemote cmdFactionsDemote = new CmdFactionsDemote(); public CmdFactionsDemote cmdFactionsDemote = new CmdFactionsDemote();
public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription(); public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription();
public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband(); public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband();
@ -77,7 +76,6 @@ public class CmdFactions extends FCommand
this.addSubCommand(this.cmdFactionsPerm); this.addSubCommand(this.cmdFactionsPerm);
this.addSubCommand(this.cmdFactionsFlag); this.addSubCommand(this.cmdFactionsFlag);
this.addSubCommand(this.cmdFactionsInvite); this.addSubCommand(this.cmdFactionsInvite);
this.addSubCommand(this.cmdFactionsDeinvite);
this.addSubCommand(this.cmdFactionsOpen); this.addSubCommand(this.cmdFactionsOpen);
this.addSubCommand(this.cmdFactionsMoney); this.addSubCommand(this.cmdFactionsMoney);
this.addSubCommand(this.cmdFactionsClaim); this.addSubCommand(this.cmdFactionsClaim);

View File

@ -12,8 +12,8 @@ import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.event.FactionsEventJoin;
import com.massivecraft.factions.event.FactionCreateEvent; import com.massivecraft.factions.event.FactionsEventCreate;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsCreate extends FCommand public class CmdFactionsCreate extends FCommand
@ -54,29 +54,19 @@ public class CmdFactionsCreate extends FCommand
// trigger the faction creation event (cancellable) // trigger the faction creation event (cancellable)
String factionId = FactionColl.get().getIdStrategy().generate(FactionColl.get()); String factionId = FactionColl.get().getIdStrategy().generate(FactionColl.get());
FactionCreateEvent createEvent = new FactionCreateEvent(sender, tag, factionId); FactionsEventCreate createEvent = new FactionsEventCreate(sender, tag, factionId);
Bukkit.getServer().getPluginManager().callEvent(createEvent); Bukkit.getServer().getPluginManager().callEvent(createEvent);
if(createEvent.isCancelled()) return; if (createEvent.isCancelled()) return;
// then make 'em pay (if applicable)
if (!payForCommand(ConfServer.econCostCreate)) return;
Faction faction = FactionColl.get().create(factionId); Faction faction = FactionColl.get().create(factionId);
// TODO: Why would this even happen??? Auto increment clash??
if (faction == null)
{
msg("<b>There was an internal error while trying to create your faction. Please try again.");
return;
}
// finish setting up the Faction // finish setting up the Faction
faction.setTag(tag); faction.setTag(tag);
// trigger the faction join event for the creator // trigger the faction join event for the creator
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.get().get(sender),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE); FactionsEventJoin joinEvent = new FactionsEventJoin(sender, fme, faction, FactionsEventJoin.PlayerJoinReason.CREATE);
Bukkit.getServer().getPluginManager().callEvent(joinEvent); joinEvent.run();
// join event cannot be cancelled or you'll have an empty faction // NOTE: join event cannot be cancelled or you'll have an empty faction
// finish setting up the FPlayer // finish setting up the FPlayer
fme.setRole(Rel.LEADER); fme.setRole(Rel.LEADER);

View File

@ -1,44 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsDeinvite extends FCommand
{
public CmdFactionsDeinvite()
{
this.addAliases("deinvite", "deinv");
this.addRequiredArg("player");
this.addRequirements(ReqHasPerm.get(Perm.DEINVITE.node));
}
@Override
public void perform()
{
if ( ! FPerm.INVITE.has(sender, myFaction, true)) return;
FPlayer you = this.arg(0, ARFPlayer.getStartAny());
if (you == null) return;
if (you.getFaction() == myFaction)
{
msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag());
msg("<i>You might want to: %s", Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false));
return;
}
myFaction.deinvite(you);
you.msg("%s<i> revoked your invitation to <h>%s<i>.", fme.describeTo(you), myFaction.describeTo(you));
myFaction.msg("%s<i> revoked %s's<i> invitation.", fme.describeTo(myFaction), you.describeTo(myFaction));
}
}

View File

@ -1,9 +1,9 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.factions.event.FactionsEventDescriptionChange;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.mixin.Mixin;
@ -23,11 +23,19 @@ public class CmdFactionsDescription extends FCommand
@Override @Override
public void perform() public void perform()
{ {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // Args
if (!payForCommand(ConfServer.econCostDesc)) return; String newDescription = this.argConcatFrom(1);
// Event
FactionsEventDescriptionChange event = new FactionsEventDescriptionChange(sender, myFaction, newDescription);
event.run();
if (event.isCancelled()) return;
newDescription = event.getNewDescription();
// Apply
myFaction.setDescription(this.argConcatFrom(1)); myFaction.setDescription(this.argConcatFrom(1));
// Inform
myFaction.msg("<i>%s <i>set your faction description to:\n%s", Mixin.getDisplayName(sender), myFaction.getDescription()); myFaction.msg("<i>%s <i>set your faction description to:\n%s", Mixin.getDisplayName(sender), myFaction.getDescription());
} }

View File

@ -4,8 +4,8 @@ import org.bukkit.Bukkit;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.event.FactionsEventLeave;
import com.massivecraft.factions.event.FactionDisbandEvent; import com.massivecraft.factions.event.FactionsEventDisband;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
@ -42,14 +42,15 @@ public class CmdFactionsDisband extends FCommand
return; return;
} }
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(me, faction.getId()); FactionsEventDisband disbandEvent = new FactionsEventDisband(me, faction);
Bukkit.getServer().getPluginManager().callEvent(disbandEvent); Bukkit.getServer().getPluginManager().callEvent(disbandEvent);
if(disbandEvent.isCancelled()) return; if(disbandEvent.isCancelled()) return;
// Send FPlayerLeaveEvent for each player in the faction // Send FPlayerLeaveEvent for each player in the faction
for ( FPlayer fplayer : faction.getFPlayers() ) for ( FPlayer fplayer : faction.getFPlayers() )
{ {
Bukkit.getServer().getPluginManager().callEvent(new FPlayerLeaveEvent(fplayer, faction, FPlayerLeaveEvent.PlayerLeaveReason.DISBAND)); FactionsEventLeave leaveEvent = new FactionsEventLeave(sender, fplayer, faction, FactionsEventLeave.PlayerLeaveReason.DISBAND);
leaveEvent.run();
} }
// Inform all players // Inform all players

View File

@ -1,11 +1,12 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.event.FactionsEventInvitedChange;
import com.massivecraft.mcore.cmd.arg.ARBoolean;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
@ -16,6 +17,7 @@ public class CmdFactionsInvite extends FCommand
this.addAliases("inv", "invite"); this.addAliases("inv", "invite");
this.addRequiredArg("player"); this.addRequiredArg("player");
this.addOptionalArg("yes/no", "toggle");
this.addRequirements(ReqHasPerm.get(Perm.INVITE.node)); this.addRequirements(ReqHasPerm.get(Perm.INVITE.node));
this.addRequirements(ReqIsPlayer.get()); this.addRequirements(ReqIsPlayer.get());
@ -24,27 +26,44 @@ public class CmdFactionsInvite extends FCommand
@Override @Override
public void perform() public void perform()
{ {
if ( ! FPerm.INVITE.has(sender, myFaction, true)) return; // Args
FPlayer fplayer = this.arg(0, ARFPlayer.getStartAny());
if (fplayer == null) return;
FPlayer you = this.arg(0, ARFPlayer.getStartAny()); Boolean newInvited = this.arg(1, ARBoolean.get(), !myFaction.isInvited(fplayer));
if (you == null) return; if (newInvited == null) return;
if (you.getFaction() == myFaction) // Allready member?
if (fplayer.getFaction() == myFaction)
{ {
msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag()); msg("%s<i> is already a member of %s", fplayer.getName(), myFaction.getTag());
msg("<i>You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false)); msg("<i>You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false));
return; return;
} }
if (fme != null && ! FPerm.INVITE.has(fme, myFaction)) return; // FPerm
if ( ! FPerm.INVITE.has(sender, myFaction, true)) return;
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // Event
if (!payForCommand(ConfServer.econCostInvite)) return; FactionsEventInvitedChange event = new FactionsEventInvitedChange(sender, fplayer, myFaction, newInvited);
event.run();
if (event.isCancelled()) return;
newInvited = event.isNewInvited();
myFaction.invite(you); // Apply
myFaction.setInvited(fplayer, newInvited);
you.msg("%s<i> invited you to %s", fme.describeTo(you, true), myFaction.describeTo(you)); // Inform
myFaction.msg("%s<i> invited %s<i> to your faction.", fme.describeTo(myFaction, true), you.describeTo(myFaction)); if (newInvited)
{
fplayer.msg("%s<i> invited you to %s", fme.describeTo(fplayer, true), myFaction.describeTo(fplayer));
myFaction.msg("%s<i> invited %s<i> to your faction.", fme.describeTo(myFaction, true), fplayer.describeTo(myFaction));
}
else
{
fplayer.msg("%s<i> revoked your invitation to <h>%s<i>.", fme.describeTo(fplayer), myFaction.describeTo(fplayer));
myFaction.msg("%s<i> revoked %s's<i> invitation.", fme.describeTo(myFaction), fplayer.describeTo(myFaction));
}
} }
} }

View File

@ -10,7 +10,7 @@ import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.event.FactionsEventJoin;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsJoin extends FCommand public class CmdFactionsJoin extends FCommand
@ -75,7 +75,7 @@ public class CmdFactionsJoin extends FCommand
} }
// trigger the join event (cancellable) // trigger the join event (cancellable)
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.get().get(me),faction,FPlayerJoinEvent.PlayerJoinReason.COMMAND); FactionsEventJoin joinEvent = new FactionsEventJoin(FPlayerColl.get().get(me),faction,FactionsEventJoin.PlayerJoinReason.JOIN);
Bukkit.getServer().getPluginManager().callEvent(joinEvent); Bukkit.getServer().getPluginManager().callEvent(joinEvent);
if (joinEvent.isCancelled()) return; if (joinEvent.isCancelled()) return;

View File

@ -10,7 +10,7 @@ import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.event.FactionsEventLeave;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
public class CmdFactionsKick extends FCommand public class CmdFactionsKick extends FCommand
@ -55,7 +55,7 @@ public class CmdFactionsKick extends FCommand
if (fme != null && ! FPerm.KICK.has(fme, yourFaction)) return; if (fme != null && ! FPerm.KICK.has(fme, yourFaction)) return;
// trigger the leave event (cancellable) [reason:kicked] // trigger the leave event (cancellable) [reason:kicked]
FPlayerLeaveEvent event = new FPlayerLeaveEvent(you, you.getFaction(), FPlayerLeaveEvent.PlayerLeaveReason.KICKED); FactionsEventLeave event = new FactionsEventLeave(you, you.getFaction(), FactionsEventLeave.PlayerLeaveReason.KICKED);
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return; if (event.isCancelled()) return;

View File

@ -1,7 +1,5 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import org.bukkit.Bukkit;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
@ -9,7 +7,7 @@ import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.event.FactionsEventJoin;
import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -67,8 +65,8 @@ public class CmdFactionsLeader extends FCommand
// only perform a FPlayerJoinEvent when newLeader isn't actually in the faction // only perform a FPlayerJoinEvent when newLeader isn't actually in the faction
if (newLeader.getFaction() != targetFaction) if (newLeader.getFaction() != targetFaction)
{ {
FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayerColl.get().get(me),targetFaction,FPlayerJoinEvent.PlayerJoinReason.LEADER); FactionsEventJoin event = new FactionsEventJoin(sender, newLeader, targetFaction, FactionsEventJoin.PlayerJoinReason.LEADER);
Bukkit.getServer().getPluginManager().callEvent(event); event.run();
if (event.isCancelled()) return; if (event.isCancelled()) return;
} }

View File

@ -1,11 +1,11 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionColl; import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.factions.event.FactionsEventOpenChange;
import com.massivecraft.mcore.cmd.arg.ARBoolean; import com.massivecraft.mcore.cmd.arg.ARBoolean;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
@ -24,17 +24,21 @@ public class CmdFactionsOpen extends FCommand
@Override @Override
public void perform() public void perform()
{ {
Boolean target = this.arg(0, ARBoolean.get(), !myFaction.isOpen()); // Args
if (target == null) return; Boolean newOpen = this.arg(0, ARBoolean.get(), !myFaction.isOpen());
if (newOpen == null) return;
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // Event
if (!payForCommand(ConfServer.econCostOpen)) return; FactionsEventOpenChange event = new FactionsEventOpenChange(sender, myFaction, newOpen);
event.run();
if (event.isCancelled()) return;
newOpen = event.isNewOpen();
myFaction.setOpen(target); // Apply
myFaction.setOpen(newOpen);
String descTarget = myFaction.isOpen() ? "open" : "closed";
// Inform // Inform
String descTarget = myFaction.isOpen() ? "open" : "closed";
myFaction.msg("%s<i> changed the faction to <h>%s<i>.", fme.describeTo(myFaction, true), descTarget); myFaction.msg("%s<i> changed the faction to <h>%s<i>.", fme.describeTo(myFaction, true), descTarget);
for (Faction faction : FactionColl.get().getAll()) for (Faction faction : FactionColl.get().getAll())
{ {

View File

@ -1,7 +1,5 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import org.bukkit.Bukkit;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
@ -9,7 +7,7 @@ import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.factions.event.FactionRelationEvent; import com.massivecraft.factions.event.FactionsEventRelationChange;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
@ -28,8 +26,11 @@ public abstract class CmdFactionsRelationAbstract extends FCommand
@Override @Override
public void perform() public void perform()
{ {
Faction them = this.arg(0, ARFaction.get()); // Args
if (them == null) return; Faction otherFaction = this.arg(0, ARFaction.get());
if (otherFaction == null) return;
Rel newRelation = targetRelation;
/*if ( ! them.isNormal()) /*if ( ! them.isNormal())
{ {
@ -37,60 +38,60 @@ public abstract class CmdFactionsRelationAbstract extends FCommand
return; return;
}*/ }*/
if (them == myFaction) // Verify
if (otherFaction == myFaction)
{ {
msg("<b>Nope! You can't declare a relation to yourself :)"); msg("<b>Nope! You can't declare a relation to yourself :)");
return; return;
} }
if (myFaction.getRelationWish(them) == targetRelation) if (myFaction.getRelationWish(otherFaction) == newRelation)
{ {
msg("<b>You already have that relation wish set with %s.", them.getTag()); msg("<b>You already have that relation wish set with %s.", otherFaction.getTag());
return; return;
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // Event
if (!payForCommand(targetRelation.getRelationCost())) return; FactionsEventRelationChange event = new FactionsEventRelationChange(sender, myFaction, otherFaction, newRelation);
event.run();
if (event.isCancelled()) return;
newRelation = event.getNewRelation();
// try to set the new relation // try to set the new relation
Rel oldRelation = myFaction.getRelationTo(them, true); myFaction.setRelationWish(otherFaction, newRelation);
myFaction.setRelationWish(them, targetRelation); Rel currentRelation = myFaction.getRelationTo(otherFaction, true);
Rel currentRelation = myFaction.getRelationTo(them, true);
// if the relation change was successful // if the relation change was successful
if (targetRelation == currentRelation) if (newRelation == currentRelation)
{ {
// trigger the faction relation event otherFaction.msg("%s<i> is now %s.", myFaction.describeTo(otherFaction, true), newRelation.getDescFactionOne());
FactionRelationEvent relationEvent = new FactionRelationEvent(myFaction, them, oldRelation, currentRelation); myFaction.msg("%s<i> is now %s.", otherFaction.describeTo(myFaction, true), newRelation.getDescFactionOne());
Bukkit.getServer().getPluginManager().callEvent(relationEvent);
them.msg("%s<i> is now %s.", myFaction.describeTo(them, true), targetRelation.getDescFactionOne());
myFaction.msg("%s<i> is now %s.", them.describeTo(myFaction, true), targetRelation.getDescFactionOne());
} }
// inform the other faction of your request // inform the other faction of your request
else else
{ {
them.msg("%s<i> wishes to be %s.", myFaction.describeTo(them, true), targetRelation.getColor()+targetRelation.getDescFactionOne()); otherFaction.msg("%s<i> wishes to be %s.", myFaction.describeTo(otherFaction, true), newRelation.getColor()+newRelation.getDescFactionOne());
them.msg("<i>Type <c>/"+ConfServer.baseCommandAliases.get(0)+" "+targetRelation+" "+myFaction.getTag()+"<i> to accept."); otherFaction.msg("<i>Type <c>/"+ConfServer.baseCommandAliases.get(0)+" "+newRelation+" "+myFaction.getTag()+"<i> to accept.");
myFaction.msg("%s<i> were informed that you wish to be %s<i>.", them.describeTo(myFaction, true), targetRelation.getColor()+targetRelation.getDescFactionOne()); myFaction.msg("%s<i> were informed that you wish to be %s<i>.", otherFaction.describeTo(myFaction, true), newRelation.getColor()+newRelation.getDescFactionOne());
} }
// TODO: The ally case should work!! // TODO: The ally case should work!!
// * this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only // * this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only
if ( targetRelation != Rel.TRUCE && them.getFlag(FFlag.PEACEFUL)) if ( newRelation != Rel.TRUCE && otherFaction.getFlag(FFlag.PEACEFUL))
{ {
them.msg("<i>This will have no effect while your faction is peaceful."); otherFaction.msg("<i>This will have no effect while your faction is peaceful.");
myFaction.msg("<i>This will have no effect while their faction is peaceful."); myFaction.msg("<i>This will have no effect while their faction is peaceful.");
} }
if ( targetRelation != Rel.TRUCE && myFaction.getFlag(FFlag.PEACEFUL)) if ( newRelation != Rel.TRUCE && myFaction.getFlag(FFlag.PEACEFUL))
{ {
them.msg("<i>This will have no effect while their faction is peaceful."); otherFaction.msg("<i>This will have no effect while their faction is peaceful.");
myFaction.msg("<i>This will have no effect while your faction is peaceful."); myFaction.msg("<i>This will have no effect while your faction is peaceful.");
} }
SpoutFeatures.updateTitle(myFaction, them); SpoutFeatures.updateTitle(myFaction, otherFaction);
SpoutFeatures.updateTitle(them, myFaction); SpoutFeatures.updateTitle(otherFaction, myFaction);
SpoutFeatures.updateTerritoryDisplayLoc(null); SpoutFeatures.updateTerritoryDisplayLoc(null);
} }
} }

View File

@ -6,7 +6,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FactionsHomeChangeEvent; import com.massivecraft.factions.event.FactionsEventHomeChange;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
@ -48,14 +48,11 @@ public class CmdFactionsSethome extends FCommand
return; return;
} }
FactionsHomeChangeEvent event = new FactionsHomeChangeEvent(sender, FactionsHomeChangeEvent.REASON_COMMAND_SETHOME, faction, newHome); FactionsEventHomeChange event = new FactionsEventHomeChange(sender, faction, newHome);
event.run(); event.run();
if (event.isCancelled()) return; if (event.isCancelled()) return;
newHome = event.getNewHome(); newHome = event.getNewHome();
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(ConfServer.econCostSethome)) return;
faction.setHome(newHome); faction.setHome(newHome);
faction.msg("%s<i> set the home for your faction. You can now use:", fme.describeTo(myFaction, true)); faction.msg("%s<i> set the home for your faction. You can now use:", fme.describeTo(myFaction, true));

View File

@ -10,7 +10,7 @@ import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.factions.event.FactionRenameEvent; import com.massivecraft.factions.event.FactionsEventTagChange;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
@ -31,33 +31,33 @@ public class CmdFactionsTag extends FCommand
@Override @Override
public void perform() public void perform()
{ {
String tag = this.arg(0); // Arg
String newTag = this.arg(0);
// TODO does not first test cover selfcase? // TODO does not first test cover selfcase?
if (FactionColl.get().isTagTaken(tag) && ! MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) if (FactionColl.get().isTagTaken(newTag) && ! MiscUtil.getComparisonString(newTag).equals(myFaction.getComparisonTag()))
{ {
msg("<b>That tag is already taken"); msg("<b>That tag is already taken");
return; return;
} }
ArrayList<String> errors = new ArrayList<String>(); ArrayList<String> errors = new ArrayList<String>();
errors.addAll(FactionColl.validateTag(tag)); errors.addAll(FactionColl.validateTag(newTag));
if (errors.size() > 0) if (errors.size() > 0)
{ {
sendMessage(errors); sendMessage(errors);
return; return;
} }
// trigger the faction rename event (cancellable) // Event
FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag); FactionsEventTagChange renameEvent = new FactionsEventTagChange(sender, myFaction, newTag);
Bukkit.getServer().getPluginManager().callEvent(renameEvent); Bukkit.getServer().getPluginManager().callEvent(renameEvent);
if(renameEvent.isCancelled()) return; if (renameEvent.isCancelled()) return;
newTag = renameEvent.getNewTag();
// then make 'em pay (if applicable)
if (!payForCommand(ConfServer.econCostTag)) return;
// Apply
String oldtag = myFaction.getTag(); String oldtag = myFaction.getTag();
myFaction.setTag(tag); myFaction.setTag(newTag);
// Inform // Inform
myFaction.msg("%s<i> changed your faction tag to %s", fme.describeTo(myFaction, true), myFaction.getTag(myFaction)); myFaction.msg("%s<i> changed your faction tag to %s", fme.describeTo(myFaction, true), myFaction.getTag(myFaction));

View File

@ -6,6 +6,7 @@ import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.factions.event.FactionsEventTitleChange;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.mcore.cmd.arg.ARString; import com.massivecraft.mcore.cmd.arg.ARString;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
@ -26,18 +27,24 @@ public class CmdFactionsTitle extends FCommand
@Override @Override
public void perform() public void perform()
{ {
// Args
FPlayer you = this.arg(0, ARFPlayer.getStartAny()); FPlayer you = this.arg(0, ARFPlayer.getStartAny());
if (you == null) return; if (you == null) return;
String title = this.argConcatFrom(1, ARString.get(), ""); String newTitle = this.argConcatFrom(1, ARString.get(), "");
if (title == null) return; if (newTitle == null) return;
// Verify
if ( ! canIAdministerYou(fme, you)) return; if ( ! canIAdministerYou(fme, you)) return;
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // Event
if (!payForCommand(ConfServer.econCostTitle)) return; FactionsEventTitleChange event = new FactionsEventTitleChange(sender, you, newTitle);
event.run();
if (event.isCancelled()) return;
newTitle = event.getNewTitle();
you.setTitle(title); // Apply
you.setTitle(newTitle);
// Inform // Inform
myFaction.msg("%s<i> changed a title: %s", fme.describeTo(myFaction, true), you.describeTo(myFaction, true)); myFaction.msg("%s<i> changed a title: %s", fme.describeTo(myFaction, true), you.describeTo(myFaction, true));

View File

@ -3,7 +3,7 @@ package com.massivecraft.factions.cmd;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.event.LandUnclaimEvent; import com.massivecraft.factions.event.FactionsEventLandUnclaim;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.BoardColl; import com.massivecraft.factions.BoardColl;
@ -33,7 +33,7 @@ public class CmdFactionsUnclaim extends FCommand
if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return; if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return;
LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(chunk, otherFaction, fme); FactionsEventLandUnclaim unclaimEvent = new FactionsEventLandUnclaim(sender, otherFaction, chunk);
Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); Bukkit.getServer().getPluginManager().callEvent(unclaimEvent);
if(unclaimEvent.isCancelled()) return; if(unclaimEvent.isCancelled()) return;

View File

@ -8,7 +8,7 @@ import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.factions.event.LandUnclaimAllEvent; import com.massivecraft.factions.event.FactionsEventLandUnclaimAll;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
@ -39,7 +39,7 @@ public class CmdFactionsUnclaimall extends FCommand
} }
} }
LandUnclaimAllEvent unclaimAllEvent = new LandUnclaimAllEvent(myFaction, fme); FactionsEventLandUnclaimAll unclaimAllEvent = new FactionsEventLandUnclaimAll(sender, myFaction);
Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent); Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent);
// this event cannot be cancelled // this event cannot be cancelled

View File

@ -4,7 +4,6 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.cmd.MCommand; import com.massivecraft.mcore.cmd.MCommand;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -61,8 +60,8 @@ public abstract class FCommand extends MCommand
} }
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost // 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) /*public boolean payForCommand(double cost)
{ {
return Econ.payForAction(cost, sender, this.getDesc()); return Econ.payForAction(cost, sender, this.getDesc());
} }*/
} }

View File

@ -1,68 +0,0 @@
package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionColl;
public class FactionDisbandEvent extends Event implements Cancellable
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private boolean cancelled;
@Override public boolean isCancelled() { return this.cancelled; }
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
// TODO: Could the fields be reorganized to achieve symmetry?
private String id;
private CommandSender sender;
public Faction getFaction()
{
return FactionColl.get().get(id);
}
public FPlayer getFPlayer()
{
return FPlayer.get(sender);
}
public CommandSender getPlayer()
{
return this.sender;
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionDisbandEvent(CommandSender sender, String factionId)
{
this.cancelled = false;
this.sender = sender;
this.id = factionId;
}
// -------------------------------------------- //
// ASSORTED
// -------------------------------------------- //
}

View File

@ -1,60 +0,0 @@
package com.massivecraft.factions.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
public class FactionRenameEvent extends Event implements Cancellable
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private boolean cancelled;
@Override public boolean isCancelled() { return this.cancelled; }
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
private final FPlayer fplayer;
public FPlayer getFPlayer() { return this.fplayer; }
private final Faction faction;
public Faction getFaction() { return this.faction; }
private String tag;
// TODO: fix these
public Player getPlayer() { return this.fplayer.getPlayer(); }
public String getOldFactionTag() { return this.faction.getTag(); }
public String getFactionTag() { return this.tag; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionRenameEvent(FPlayer sender, String newTag)
{
this.cancelled = false;
this.fplayer = sender;
this.faction = sender.getFaction(); // TODO: Players can only rename their own faction? A field and constructor rewrite is probably pending for this class...
this.tag = newTag;
}
}

View File

@ -0,0 +1,8 @@
package com.massivecraft.factions.event;
import com.massivecraft.mcore.event.MCoreEvent;
public abstract class FactionsEventAbstract extends MCoreEvent
{
}

View File

@ -0,0 +1,26 @@
package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.mcore.event.MCoreEvent;
public abstract class FactionsEventAbstractSender extends MCoreEvent
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final CommandSender sender;
public CommandSender getSender() { return this.sender; }
public FPlayer getFSender() { return FPlayer.get(this.sender); }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionsEventAbstractSender(CommandSender sender)
{
this.sender = sender;
}
}

View File

@ -1,11 +1,9 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class FactionCreateEvent extends Event implements Cancellable public class FactionsEventCreate extends FactionsEventAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
@ -19,13 +17,6 @@ public class FactionCreateEvent extends Event implements Cancellable
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private boolean cancelled = false;
@Override public boolean isCancelled() { return this.cancelled; }
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
private final CommandSender sender;
public CommandSender getSender() { return this.sender; }
// TODO: How do we know what universe? Should we perhaps actually create the faction? // TODO: How do we know what universe? Should we perhaps actually create the faction?
private String factionTag; private String factionTag;
@ -38,9 +29,9 @@ public class FactionCreateEvent extends Event implements Cancellable
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public FactionCreateEvent(CommandSender sender, String factionTag, String factionId) public FactionsEventCreate(CommandSender sender, String factionTag, String factionId)
{ {
this.sender = sender; super(sender);
this.factionTag = factionTag; this.factionTag = factionTag;
this.factionId = factionId; this.factionId = factionId;
} }

View File

@ -0,0 +1,40 @@
package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.Faction;
public class FactionsEventDescriptionChange 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 Faction faction;
public Faction getFaction() { return this.faction; }
private String newDescription;
public String getNewDescription() { return this.newDescription; }
public void setNewDescription(String newDescription) { this.newDescription = newDescription; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionsEventDescriptionChange(CommandSender sender, Faction faction, String newDescription)
{
super(sender);
this.faction = faction;
this.newDescription = newDescription;
}
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.Faction;
public class FactionsEventDisband 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 Faction faction;
public Faction getFaction() { return this.faction; }
private final String factionId;
public String getFactionId() { return this.factionId; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionsEventDisband(CommandSender sender, Faction faction)
{
super(sender);
this.faction = faction;
this.factionId = faction.getId();
}
// -------------------------------------------- //
// ASSORTED
// -------------------------------------------- //
}

View File

@ -4,19 +4,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.mcore.event.MCoreCancellableEvent;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
public class FactionsHomeChangeEvent extends MCoreCancellableEvent public class FactionsEventHomeChange extends FactionsEventAbstractSender
{ {
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
public final static String REASON_COMMAND_SETHOME = "FACTIONS_COMMAND_SETHOME";
public final static String REASON_VERIFY_FAILED = "FACTIONS_VERIFY_FAILED";
public final static String REASON_UNDEFINED = "FACTIONS_UNDEFINED";
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
// -------------------------------------------- // // -------------------------------------------- //
@ -29,12 +20,6 @@ public class FactionsHomeChangeEvent extends MCoreCancellableEvent
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final CommandSender sender;
public CommandSender getSender() { return this.sender; }
private final String reason;
public String getReason() { return this.reason; }
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
@ -46,10 +31,9 @@ public class FactionsHomeChangeEvent extends MCoreCancellableEvent
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public FactionsHomeChangeEvent(CommandSender sender, String reason, Faction faction, PS newHome) public FactionsEventHomeChange(CommandSender sender, Faction faction, PS newHome)
{ {
this.sender = sender; super(sender);
this.reason = reason;
this.faction = faction; this.faction = faction;
this.newHome = newHome; this.newHome = newHome;
} }

View File

@ -1,13 +1,12 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import org.bukkit.event.Event; import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import org.bukkit.entity.Player; import com.massivecraft.factions.Faction;
public class LandUnclaimAllEvent extends Event public class FactionsEventInvitedChange extends FactionsEventAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
@ -21,25 +20,26 @@ public class LandUnclaimAllEvent extends Event
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final Faction faction;
public Faction getFaction() { return this.faction; }
private final FPlayer fplayer; private final FPlayer fplayer;
public FPlayer getFPlayer() { return this.fplayer; } public FPlayer getFPlayer() { return this.fplayer; }
// TODO: These methods seem redundant? Why were they added? Can I remove them? private final Faction faction;
public String getFactionId() { return this.faction.getId(); } public Faction getFaction() { return this.faction; }
public String getFactionTag() { return this.faction.getTag(); }
public Player getPlayer() { return this.fplayer.getPlayer(); } private boolean newInvited;
public boolean isNewInvited() { return this.newInvited; }
public void setNewInvited(boolean newInvited) { this.newInvited = newInvited; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public LandUnclaimAllEvent(Faction faction, FPlayer fplayer) public FactionsEventInvitedChange(CommandSender sender, FPlayer fplayer, Faction faction, boolean newInvited)
{ {
this.faction = faction; super(sender);
this.fplayer = fplayer; this.fplayer = fplayer;
this.faction = faction;
this.newInvited = newInvited;
} }
} }

View File

@ -1,13 +1,12 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import org.bukkit.event.Cancellable; import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
public class FPlayerJoinEvent extends Event implements Cancellable public class FactionsEventJoin extends FactionsEventAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
@ -21,45 +20,34 @@ public class FPlayerJoinEvent extends Event implements Cancellable
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private FPlayer fplayer; private final FPlayer fplayer;
private Faction faction; public FPlayer getFPlayer() { return this.fplayer; }
private PlayerJoinReason reason;
private boolean cancelled = false; private final Faction faction;
@Override public boolean isCancelled() { return this.cancelled; } public Faction getFaction() { return this.faction; }
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
private final PlayerJoinReason reason;
public PlayerJoinReason getReason() { return reason; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public FPlayerJoinEvent(FPlayer fplayer, Faction faction, PlayerJoinReason reason) public FactionsEventJoin(CommandSender sender, FPlayer fplayer, Faction faction, PlayerJoinReason reason)
{ {
super(sender);
this.fplayer = fplayer; this.fplayer = fplayer;
this.faction = faction; this.faction = faction;
this.reason = reason; this.reason = reason;
} }
public FPlayer getFPlayer()
{
return fplayer;
}
public Faction getFaction()
{
return faction;
}
public PlayerJoinReason getReason()
{
return reason;
}
// -------------------------------------------- // // -------------------------------------------- //
// INTERNAL ENUM // INTERNAL ENUM
// -------------------------------------------- // // -------------------------------------------- //
public enum PlayerJoinReason public enum PlayerJoinReason
{ {
CREATE, LEADER, COMMAND CREATE, LEADER, JOIN
} }
} }

View File

@ -1,16 +1,12 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import org.bukkit.event.Cancellable; import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import org.bukkit.entity.Player; public class FactionsEventLandClaim extends FactionsEventAbstractSender
public class LandUnclaimEvent extends Event implements Cancellable
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
@ -24,34 +20,21 @@ public class LandUnclaimEvent extends Event implements Cancellable
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private boolean cancelled;
@Override public boolean isCancelled() { return this.cancelled; }
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
private final PS chunk;
public PS getChunk() { return this.chunk; }
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
private final FPlayer fplayer; private final PS chunk;
public FPlayer getFPlayer() { return this.fplayer; } public PS getChunk() { return this.chunk; }
// TODO: These methods seem redundant? Why were they added? Can I remove them?
public String getFactionId() { return this.faction.getId(); }
public String getFactionTag() { return this.faction.getTag(); }
public Player getPlayer() { return this.fplayer.getPlayer(); }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public LandUnclaimEvent(PS chunk, Faction faction, FPlayer fplayer) public FactionsEventLandClaim(CommandSender sender, Faction faction, PS chunk)
{ {
this.cancelled = false; super(sender);
this.chunk = chunk.getChunk(true);
this.faction = faction; this.faction = faction;
this.fplayer = fplayer; this.chunk = chunk.getChunk(true);
} }
} }

View File

@ -1,16 +1,12 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import org.bukkit.event.Cancellable; import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import org.bukkit.entity.Player; public class FactionsEventLandUnclaim extends FactionsEventAbstractSender
public class LandClaimEvent extends Event implements Cancellable
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
@ -24,34 +20,21 @@ public class LandClaimEvent extends Event implements Cancellable
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private boolean cancelled = false;
@Override public boolean isCancelled() { return this.cancelled; }
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
private final PS chunk;
public PS getChunk() { return this.chunk; }
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
private final FPlayer fplayer; private final PS chunk;
public FPlayer getFPlayer() { return this.fplayer; } public PS getChunk() { return this.chunk; }
// TODO: These methods seem redundant? Why were they added? Can I remove them?
public String getFactionId() { return faction.getId(); }
public String getFactionTag() { return this.faction.getTag(); }
public Player getPlayer() { return this.fplayer.getPlayer(); }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public LandClaimEvent(PS chunk, Faction faction, FPlayer fplayer) public FactionsEventLandUnclaim(CommandSender sender, Faction faction, PS chunk)
{ {
this.cancelled = false; super(sender);
this.chunk = chunk.getChunk(true); this.chunk = chunk.getChunk(true);
this.faction = faction; this.faction = faction;
this.fplayer = fplayer;
} }
} }

View File

@ -0,0 +1,35 @@
package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.Faction;
public class FactionsEventLandUnclaimAll 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 Faction faction;
public Faction getFaction() { return this.faction; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionsEventLandUnclaimAll(CommandSender sender, Faction faction)
{
super(sender);
this.faction = faction;
}
}

View File

@ -1,13 +1,12 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import org.bukkit.event.Cancellable; import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
public class FPlayerLeaveEvent extends Event implements Cancellable public class FactionsEventLeave extends FactionsEventAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
@ -21,35 +20,32 @@ public class FPlayerLeaveEvent extends Event implements Cancellable
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private boolean cancelled;
@Override public boolean isCancelled() { return this.cancelled; }
@Override @Override
public void setCancelled(boolean c) public void setCancelled(boolean cancelled)
{ {
if (reason == PlayerLeaveReason.DISBAND || reason == PlayerLeaveReason.RESET) if (this.reason == PlayerLeaveReason.DISBAND || this.reason == PlayerLeaveReason.RESET)
{ {
cancelled = false; cancelled = false;
return;
} }
cancelled = c; super.setCancelled(cancelled);
} }
private final PlayerLeaveReason reason;
public PlayerLeaveReason getReason() { return this.reason; }
private final FPlayer fplayer; private final FPlayer fplayer;
public FPlayer getFPlayer() { return this.fplayer; } public FPlayer getFPlayer() { return this.fplayer; }
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
private final PlayerLeaveReason reason;
public PlayerLeaveReason getReason() { return this.reason; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public FPlayerLeaveEvent(FPlayer fplayer, Faction faction, PlayerLeaveReason reason) public FactionsEventLeave(CommandSender sender, FPlayer fplayer, Faction faction, PlayerLeaveReason reason)
{ {
this.cancelled = false; super(sender);
this.fplayer = fplayer; this.fplayer = fplayer;
this.faction = faction; this.faction = faction;
this.reason = reason; this.reason = reason;

View File

@ -0,0 +1,40 @@
package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.Faction;
public class FactionsEventOpenChange 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 Faction faction;
public Faction getFaction() { return this.faction; }
private boolean newOpen;
public boolean isNewOpen() { return this.newOpen; }
public void setNewOpen(boolean newOpen) { this.newOpen = newOpen; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionsEventOpenChange(CommandSender sender, Faction faction, boolean newOpen)
{
super(sender);
this.faction = faction;
this.newOpen = newOpen;
}
}

View File

@ -0,0 +1,27 @@
package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
public class FactionsEventPowerLoss extends FactionsEventAbstractSender
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
// TODO: Replace this event with a power change event?
public FactionsEventPowerLoss(CommandSender sender)
{
super(sender);
}
}

View File

@ -1,13 +1,13 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import org.bukkit.event.Event; import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
public class FactionRelationEvent extends Event public class FactionsEventRelationChange extends FactionsEventAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
@ -21,32 +21,26 @@ public class FactionRelationEvent extends Event
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
// TODO: Should this one be informative only?
// TODO: How about making it Cancellable?
// TODO: How about making the target relation non-final?
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
private final Faction targetFaction; private final Faction otherFaction;
public Faction getTargetFaction() { return this.targetFaction; } public Faction getOtherFaction() { return this.otherFaction; }
private final Rel oldRel; private Rel newRelation;
public Rel getOldRel() { return this.oldRel; } public Rel getNewRelation() { return this.newRelation; }
public void setNewRelation(Rel newRelation) { this.newRelation = newRelation; }
private final Rel newRel;
public Rel getNewRel() { return this.newRel; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public FactionRelationEvent(Faction faction, Faction targetFaction, Rel oldRel, Rel newRel) public FactionsEventRelationChange(CommandSender sender, Faction faction, Faction otherFaction, Rel newRelation)
{ {
super(sender);
this.faction = faction; this.faction = faction;
this.targetFaction = targetFaction; this.otherFaction = otherFaction;
this.oldRel = oldRel; this.newRelation = newRelation;
this.newRel = newRel;
} }
} }

View File

@ -0,0 +1,40 @@
package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.Faction;
public class FactionsEventTagChange 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 Faction faction;
public Faction getFaction() { return this.faction; }
private String newTag;
public String getNewTag() { return this.newTag; }
public void setNewTag(String newTag) { this.newTag = newTag; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionsEventTagChange(CommandSender sender, Faction faction, String newTag)
{
super(sender);
this.faction = faction;
this.newTag = newTag;
}
}

View File

@ -0,0 +1,40 @@
package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.FPlayer;
public class FactionsEventTitleChange 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 String newTitle;
public String getNewTitle() { return this.newTitle; }
public void setNewTitle(String newTitle) { this.newTitle = newTitle; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionsEventTitleChange(CommandSender sender, FPlayer fplayer, String newTitle)
{
super(sender);
this.fplayer = fplayer;
this.newTitle = newTitle;
}
}

View File

@ -1,58 +0,0 @@
package com.massivecraft.factions.event;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import org.bukkit.entity.Player;
public class PowerLossEvent extends Event implements Cancellable
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private boolean cancelled;
@Override public boolean isCancelled() { return this.cancelled; }
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
private final Faction faction;
public Faction getFaction() { return this.faction; }
private final FPlayer fplayer;
public FPlayer getFPlayer() { return this.fplayer; }
// TODO: Should message really be set here? Or should it be sent by the plugin that cancells directly?
private String message;
public String getMessage() { return this.message; }
public void setMessage(String message) { this.message = message; }
// TODO: These methods seem redundant? Why were they added? Can I remove them?
public String getFactionId() { return this.faction.getId(); }
public String getFactionTag() { return this.faction.getTag(); }
public Player getPlayer() { return this.fplayer.getPlayer(); }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public PowerLossEvent(Faction faction, FPlayer fplayer)
{
this.cancelled = false;
this.faction = faction;
this.fplayer = fplayer;
}
}

View File

@ -7,8 +7,17 @@ import org.bukkit.event.Listener;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.event.FactionsHomeChangeEvent; import com.massivecraft.factions.event.FactionsEventAbstractSender;
import com.massivecraft.factions.event.FactionsEventCreate;
import com.massivecraft.factions.event.FactionsEventDescriptionChange;
import com.massivecraft.factions.event.FactionsEventHomeChange;
import com.massivecraft.factions.event.FactionsEventInvitedChange;
import com.massivecraft.factions.event.FactionsEventOpenChange;
import com.massivecraft.factions.event.FactionsEventRelationChange;
import com.massivecraft.factions.event.FactionsEventTagChange;
import com.massivecraft.factions.event.FactionsEventTitleChange;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.cmd.MCommand;
public class FactionsListenerEcon implements Listener public class FactionsListenerEcon implements Listener
{ {
@ -30,20 +39,67 @@ public class FactionsListenerEcon implements Listener
} }
// -------------------------------------------- // // -------------------------------------------- //
// LISTENER // PAY FOR COMMAND
// -------------------------------------------- // // -------------------------------------------- //
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void payForCommand(FactionsEventAbstractSender event, double cost, MCommand command)
public void onFactionsHomeChangeEvent(FactionsHomeChangeEvent event)
{ {
// If the faction home is being changed through a command ... // If there is a sender ...
if (!event.getReason().equals(FactionsHomeChangeEvent.REASON_COMMAND_SETHOME)) return; if (event.getSender() == null) return;
// ... and the sender can not afford the command ... // ... and the sender can't afford ...
if (Econ.payForAction(ConfServer.econCostSethome, event.getSender(), Factions.get().getOuterCmdFactions().cmdFactionsSethome.getDesc())) return; if (Econ.payForAction(cost, event.getSender(), command.getDesc())) return;
// ... then cancel the change. // ... then cancel.
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(FactionsEventHomeChange event)
{
payForCommand(event, ConfServer.econCostSethome, Factions.get().getOuterCmdFactions().cmdFactionsSethome);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(FactionsEventCreate event)
{
payForCommand(event, ConfServer.econCostCreate, Factions.get().getOuterCmdFactions().cmdFactionsCreate);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(FactionsEventDescriptionChange event)
{
payForCommand(event, ConfServer.econCostDescription, Factions.get().getOuterCmdFactions().cmdFactionsDescription);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(FactionsEventTagChange event)
{
payForCommand(event, ConfServer.econCostTag, Factions.get().getOuterCmdFactions().cmdFactionsTag);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(FactionsEventTitleChange event)
{
payForCommand(event, ConfServer.econCostTitle, Factions.get().getOuterCmdFactions().cmdFactionsTitle);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(FactionsEventRelationChange event)
{
payForCommand(event, event.getNewRelation().getRelationCost(), Factions.get().getOuterCmdFactions().cmdFactionsRelationNeutral);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(FactionsEventOpenChange event)
{
payForCommand(event, ConfServer.econCostOpen, Factions.get().getOuterCmdFactions().cmdFactionsOpen);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(FactionsEventInvitedChange event)
{
double cost = event.isNewInvited() ? ConfServer.econCostInvite : ConfServer.econCostDeinvite;
payForCommand(event, cost, Factions.get().getOuterCmdFactions().cmdFactionsInvite);
}
} }

View File

@ -35,6 +35,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingBreakEvent;
@ -59,6 +60,7 @@ import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.event.FactionsEventPowerLoss;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
@ -84,6 +86,44 @@ public class FactionsListenerMain implements Listener
Bukkit.getPluginManager().registerEvents(this, Factions.get()); Bukkit.getPluginManager().registerEvents(this, Factions.get());
} }
// -------------------------------------------- //
// POWER LOSS ON DEATH
// -------------------------------------------- //
@EventHandler(priority = EventPriority.NORMAL)
public void powerLossOnDeath(PlayerDeathEvent event)
{
// If a player dies ...
Player player = event.getEntity();
FPlayer fplayer = FPlayerColl.get().get(player);
// ... and powerloss can happen here ...
Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player));
if (!faction.getFlag(FFlag.POWERLOSS))
{
fplayer.msg("<i>You didn't lose any power since the territory you died in works that way.");
return;
}
if (ConfServer.worldsNoPowerLoss.contains(player.getWorld().getName()))
{
fplayer.msg("<i>You didn't lose any power due to the world you died in.");
return;
}
// ... and our special event doesn't get cancelled ...
FactionsEventPowerLoss powerLossEvent = new FactionsEventPowerLoss(player);
powerLossEvent.run();
if (powerLossEvent.isCancelled()) return;
// ... alter the power ...
fplayer.setPower(fplayer.getPower() + ConfServer.powerPerDeath);
// ... and inform the player.
fplayer.msg("<i>Your power is now <h>%d / %d", fplayer.getPowerRounded(), fplayer.getPowerMaxRounded());
}
// -------------------------------------------- // // -------------------------------------------- //
// CAN COMBAT DAMAGE HAPPEN // CAN COMBAT DAMAGE HAPPEN
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -1,78 +0,0 @@
package com.massivecraft.factions.listeners;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.event.PowerLossEvent;
import com.massivecraft.mcore.ps.PS;
public class TodoFactionsEntityListener implements Listener
{
// -------------------------------------------- //
// POWER LOSS ON DEATH
// -------------------------------------------- //
@EventHandler(priority = EventPriority.NORMAL)
public void powerLossOnDeath(PlayerDeathEvent event)
{
// If a player dies ...
Player player = event.getEntity();
FPlayer fplayer = FPlayerColl.get().get(player);
// ... TODO: Sending the message through the event is not the best way of doing it.
// TODO: We should listen to our own events and send message from there if we cancel.
//
Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player));
PowerLossEvent powerLossEvent = new PowerLossEvent(faction, fplayer);
// Check for no power loss conditions
if ( ! faction.getFlag(FFlag.POWERLOSS))
{
powerLossEvent.setMessage("<i>You didn't lose any power since the territory you died in works that way.");
powerLossEvent.setCancelled(true);
}
else if (ConfServer.worldsNoPowerLoss.contains(player.getWorld().getName()))
{
powerLossEvent.setMessage("<i>You didn't lose any power due to the world you died in.");
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.setPower(fplayer.getPower() + ConfServer.powerPerDeath);
}
// Send the message from the powerLossEvent
final String msg = powerLossEvent.getMessage();
if (msg != null && !msg.isEmpty())
{
fplayer.msg(msg, fplayer.getPowerRounded(), fplayer.getPowerMaxRounded());
}
}
}