From 27cee7d6f791a22fb4ebd023116d1a536f41b612 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 10 Apr 2013 09:34:14 +0200 Subject: [PATCH] Event cleanup pass 1. --- .../factions/event/FPlayerJoinEvent.java | 65 ++++++------ .../factions/event/FPlayerLeaveEvent.java | 88 ++++++++------- .../factions/event/FactionCreateEvent.java | 65 ++++++------ .../factions/event/FactionDisbandEvent.java | 61 ++++++----- .../factions/event/FactionRelationEvent.java | 76 +++++++------ .../factions/event/FactionRenameEvent.java | 84 ++++++--------- .../factions/event/LandClaimEvent.java | 100 +++++++----------- .../factions/event/LandUnclaimAllEvent.java | 68 +++++------- .../factions/event/LandUnclaimEvent.java | 97 +++++++---------- .../factions/event/PowerLossEvent.java | 97 ++++++----------- 10 files changed, 349 insertions(+), 452 deletions(-) diff --git a/src/com/massivecraft/factions/event/FPlayerJoinEvent.java b/src/com/massivecraft/factions/event/FPlayerJoinEvent.java index 8510d00c..12e34089 100644 --- a/src/com/massivecraft/factions/event/FPlayerJoinEvent.java +++ b/src/com/massivecraft/factions/event/FPlayerJoinEvent.java @@ -9,21 +9,35 @@ import com.massivecraft.factions.Faction; public class FPlayerJoinEvent extends Event implements Cancellable { + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + private static final HandlerList handlers = new HandlerList(); - - FPlayer fplayer; - Faction faction; - PlayerJoinReason reason; - boolean cancelled = false; - public enum PlayerJoinReason + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private FPlayer fplayer; + private Faction faction; + private PlayerJoinReason reason; + + private boolean cancelled = false; + @Override public boolean isCancelled() { return this.cancelled; } + @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FPlayerJoinEvent(FPlayer fplayer, Faction faction, PlayerJoinReason reason) { - CREATE, LEADER, COMMAND - } - public FPlayerJoinEvent(FPlayer fp, Faction f, PlayerJoinReason r) - { - fplayer = fp; - faction = f; - reason = r; + this.fplayer = fplayer; + this.faction = faction; + this.reason = reason; } public FPlayer getFPlayer() @@ -38,23 +52,14 @@ public class FPlayerJoinEvent extends Event implements Cancellable { return reason; } - public HandlerList getHandlers() + + // -------------------------------------------- // + // INTERNAL ENUM + // -------------------------------------------- // + + public enum PlayerJoinReason { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } - @Override - public boolean isCancelled() - { - return cancelled; - } - @Override - public void setCancelled(boolean c) - { - cancelled = c; + CREATE, LEADER, COMMAND } + } \ No newline at end of file diff --git a/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java b/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java index 12e951bb..ef35958a 100644 --- a/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java +++ b/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java @@ -9,55 +9,20 @@ import com.massivecraft.factions.Faction; public class FPlayerLeaveEvent extends Event implements Cancellable { + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + private static final HandlerList handlers = new HandlerList(); - private PlayerLeaveReason reason; - FPlayer FPlayer; - Faction Faction; - boolean cancelled = false; - - public enum PlayerLeaveReason - { - KICKED, DISBAND, RESET, JOINOTHER, LEAVE - } - - public FPlayerLeaveEvent(FPlayer p, Faction f, PlayerLeaveReason r) - { - FPlayer = p; - Faction = f; - reason = r; - } - - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } - public PlayerLeaveReason getReason() - { - return reason; - } + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // - public FPlayer getFPlayer() - { - return FPlayer; - } - - public Faction getFaction() - { - return Faction; - } - - @Override - public boolean isCancelled() - { - return cancelled; - } - + private boolean cancelled; + @Override public boolean isCancelled() { return this.cancelled; } @Override public void setCancelled(boolean c) { @@ -68,4 +33,35 @@ public class FPlayerLeaveEvent extends Event implements Cancellable } cancelled = c; } + + private final PlayerLeaveReason reason; + public PlayerLeaveReason getReason() { return this.reason; } + + private final FPlayer fplayer; + public FPlayer getFPlayer() { return this.fplayer; } + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FPlayerLeaveEvent(FPlayer fplayer, Faction faction, PlayerLeaveReason reason) + { + this.cancelled = false; + this.fplayer = fplayer; + this.faction = faction; + this.reason = reason; + } + + // -------------------------------------------- // + // INTERNAL ENUM + // -------------------------------------------- // + + public enum PlayerLeaveReason + { + KICKED, DISBAND, RESET, JOINOTHER, LEAVE + } + } \ No newline at end of file diff --git a/src/com/massivecraft/factions/event/FactionCreateEvent.java b/src/com/massivecraft/factions/event/FactionCreateEvent.java index 55fab873..1260e5f9 100644 --- a/src/com/massivecraft/factions/event/FactionCreateEvent.java +++ b/src/com/massivecraft/factions/event/FactionCreateEvent.java @@ -11,19 +11,29 @@ import com.massivecraft.factions.FactionColl; public class FactionCreateEvent extends Event implements Cancellable { - private static final HandlerList handlers = new HandlerList(); - - private String factionTag; - private Player sender; - private boolean cancelled; + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // - public FactionCreateEvent(Player sender, String tag) - { - this.factionTag = tag; - this.sender = sender; - this.cancelled = false; - } + 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 factionTag; + public String getFactionTag() { return this.factionTag; } + + private Player sender; + public FPlayer getFPlayer() { return FPlayerColl.i.get(sender); @@ -33,31 +43,16 @@ public class FactionCreateEvent extends Event implements Cancellable { return FactionColl.i.getNextId(); } - - public String getFactionTag() + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionCreateEvent(Player sender, String tag) { - return factionTag; + this.cancelled = false; + this.factionTag = tag; + this.sender = sender; } - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } - - @Override - public boolean isCancelled() - { - return cancelled; - } - - @Override - public void setCancelled(boolean c) - { - this.cancelled = c; - } } \ No newline at end of file diff --git a/src/com/massivecraft/factions/event/FactionDisbandEvent.java b/src/com/massivecraft/factions/event/FactionDisbandEvent.java index f8bef414..bd2baf37 100644 --- a/src/com/massivecraft/factions/event/FactionDisbandEvent.java +++ b/src/com/massivecraft/factions/event/FactionDisbandEvent.java @@ -12,29 +12,27 @@ 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 Player sender; - public FactionDisbandEvent(Player sender, String factionId) - { - cancelled = false; - this.sender = sender; - this.id = factionId; - } - - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } - public Faction getFaction() { return FactionColl.i.get(id); @@ -47,18 +45,25 @@ public class FactionDisbandEvent extends Event implements Cancellable public Player getPlayer() { - return sender; + return this.sender; } - - @Override - public boolean isCancelled() + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionDisbandEvent(Player sender, String factionId) { - return cancelled; + this.cancelled = false; + this.sender = sender; + this.id = factionId; } + + // -------------------------------------------- // + // ASSORTED + // -------------------------------------------- // - @Override - public void setCancelled(boolean c) - { - cancelled = c; - } + + + } diff --git a/src/com/massivecraft/factions/event/FactionRelationEvent.java b/src/com/massivecraft/factions/event/FactionRelationEvent.java index d07e5fb5..6256eb08 100644 --- a/src/com/massivecraft/factions/event/FactionRelationEvent.java +++ b/src/com/massivecraft/factions/event/FactionRelationEvent.java @@ -9,48 +9,44 @@ import com.massivecraft.factions.Rel; public class FactionRelationEvent extends Event { + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // 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; + public Faction getFaction() { return this.faction; } + + private final Faction targetFaction; + public Faction getTargetFaction() { return this.targetFaction; } + + private final Rel oldRel; + public Rel getOldRel() { return this.oldRel; } + + private final Rel newRel; + public Rel getNewRel() { return this.newRel; } - private Faction fsender; - private Faction ftarget; - private Rel foldrel; - private Rel frel; - - public FactionRelationEvent(Faction sender, Faction target, Rel oldrel, Rel rel) + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionRelationEvent(Faction faction, Faction targetFaction, Rel oldRel, Rel newRel) { - fsender = sender; - ftarget = target; - foldrel = oldrel; - frel = rel; - } - - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } - - public Rel getOldRelation() - { - return foldrel; - } - - public Rel getRelation() - { - return frel; - } - - public Faction getFaction() - { - return fsender; - } - - public Faction getTargetFaction() - { - return ftarget; + this.faction = faction; + this.targetFaction = targetFaction; + this.oldRel = oldRel; + this.newRel = newRel; } + } diff --git a/src/com/massivecraft/factions/event/FactionRenameEvent.java b/src/com/massivecraft/factions/event/FactionRenameEvent.java index 4454f8f8..2839d738 100644 --- a/src/com/massivecraft/factions/event/FactionRenameEvent.java +++ b/src/com/massivecraft/factions/event/FactionRenameEvent.java @@ -10,65 +10,51 @@ 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; - private FPlayer fplayer; - private Faction faction; + @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) { - fplayer = sender; - faction = sender.getFaction(); - tag = 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; } - public Faction getFaction() - { - return(faction); - } + - public FPlayer getFPlayer() - { - return(fplayer); - } + - public Player getPlayer() - { - return(fplayer.getPlayer()); - } - public String getOldFactionTag() - { - return(faction.getTag()); - } - - public String getFactionTag() - { - return(tag); - } - - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } - - @Override - public boolean isCancelled() - { - return cancelled; - } - - @Override - public void setCancelled(boolean c) - { - this.cancelled = c; - } } diff --git a/src/com/massivecraft/factions/event/LandClaimEvent.java b/src/com/massivecraft/factions/event/LandClaimEvent.java index abc08e1b..cc3d1c5c 100644 --- a/src/com/massivecraft/factions/event/LandClaimEvent.java +++ b/src/com/massivecraft/factions/event/LandClaimEvent.java @@ -11,70 +11,46 @@ import org.bukkit.entity.Player; public class LandClaimEvent 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 = false; + @Override public boolean isCancelled() { return this.cancelled; } + @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } + + private final FLocation location; + public FLocation getLocation() { return this.location; } + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private final FPlayer fplayer; + public FPlayer getFPlayer() { return this.fplayer; } + + // 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(); } - private boolean cancelled; - private FLocation location; - private Faction faction; - private FPlayer fplayer; - - public LandClaimEvent(FLocation loc, Faction f, FPlayer p) + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public LandClaimEvent(FLocation location, Faction faction, FPlayer fplayer) { - cancelled = false; - location = loc; - faction = f; - fplayer = p; - } - - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } - - public FLocation getLocation() - { - return this.location; - } - - public Faction getFaction() - { - return faction; - } - - public String getFactionId() - { - return faction.getId(); - } - - public String getFactionTag() - { - return faction.getTag(); - } - - public FPlayer getFPlayer() - { - return fplayer; - } - - public Player getPlayer() - { - return fplayer.getPlayer(); - } - - @Override - public boolean isCancelled() - { - return cancelled; - } - - @Override - public void setCancelled(boolean c) - { - this.cancelled = c; + this.cancelled = false; + this.location = location; + this.faction = faction; + this.fplayer = fplayer; } + } diff --git a/src/com/massivecraft/factions/event/LandUnclaimAllEvent.java b/src/com/massivecraft/factions/event/LandUnclaimAllEvent.java index d93d510f..54b2b46f 100755 --- a/src/com/massivecraft/factions/event/LandUnclaimAllEvent.java +++ b/src/com/massivecraft/factions/event/LandUnclaimAllEvent.java @@ -9,49 +9,37 @@ import org.bukkit.entity.Player; public class LandUnclaimAllEvent extends Event { + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } - private Faction faction; - private FPlayer fplayer; + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // - public LandUnclaimAllEvent(Faction f, FPlayer p) + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private final FPlayer fplayer; + public FPlayer getFPlayer() { return this.fplayer; } + + // 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 LandUnclaimAllEvent(Faction faction, FPlayer fplayer) { - faction = f; - fplayer = p; - } - - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } - - public Faction getFaction() - { - return faction; - } - - public String getFactionId() - { - return faction.getId(); - } - - public String getFactionTag() - { - return faction.getTag(); - } - - public FPlayer getFPlayer() - { - return fplayer; - } - - public Player getPlayer() - { - return fplayer.getPlayer(); + this.faction = faction; + this.fplayer = fplayer; } + } diff --git a/src/com/massivecraft/factions/event/LandUnclaimEvent.java b/src/com/massivecraft/factions/event/LandUnclaimEvent.java index 53d1b052..18cccef0 100644 --- a/src/com/massivecraft/factions/event/LandUnclaimEvent.java +++ b/src/com/massivecraft/factions/event/LandUnclaimEvent.java @@ -10,70 +10,47 @@ import com.massivecraft.factions.FPlayer; import org.bukkit.entity.Player; public class LandUnclaimEvent 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; - private FLocation location; - private Faction faction; - private FPlayer fplayer; + @Override public boolean isCancelled() { return this.cancelled; } + @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } + + private final FLocation location; + public FLocation getLocation() { return this.location; } + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private final FPlayer fplayer; + public FPlayer getFPlayer() { return this.fplayer; } - public LandUnclaimEvent(FLocation loc, Faction f, FPlayer p) + // 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 LandUnclaimEvent(FLocation location, Faction faction, FPlayer fplayer) { - cancelled = false; - location = loc; - faction = f; - fplayer = p; - } - - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } - - public FLocation getLocation() - { - return this.location; - } - - public Faction getFaction() - { - return faction; - } - - public String getFactionId() - { - return faction.getId(); - } - - public String getFactionTag() - { - return faction.getTag(); - } - - public FPlayer getFPlayer() - { - return fplayer; - } - - public Player getPlayer() - { - return fplayer.getPlayer(); - } - - @Override - public boolean isCancelled() - { - return cancelled; - } - - @Override - public void setCancelled(boolean c) { - cancelled = c; + this.cancelled = false; + this.location = location; + this.faction = faction; + this.fplayer = fplayer; } + } diff --git a/src/com/massivecraft/factions/event/PowerLossEvent.java b/src/com/massivecraft/factions/event/PowerLossEvent.java index 76eeb8d1..5f0570df 100644 --- a/src/com/massivecraft/factions/event/PowerLossEvent.java +++ b/src/com/massivecraft/factions/event/PowerLossEvent.java @@ -12,74 +12,47 @@ 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; - private Faction faction; - private FPlayer fplayer; + @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(); } - public PowerLossEvent(Faction f, FPlayer p) + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public PowerLossEvent(Faction faction, FPlayer fplayer) { - cancelled = false; - faction = f; - fplayer = p; - } - - @Override - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } - - public Faction getFaction() - { - return faction; - } - - public String getFactionId() - { - return faction.getId(); - } - - public String getFactionTag() - { - return faction.getTag(); - } - - public FPlayer getFPlayer() - { - return fplayer; - } - - public Player getPlayer() - { - return fplayer.getPlayer(); - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - @Override - public boolean isCancelled() - { - return cancelled; - } - - @Override - public void setCancelled(boolean c) - { - this.cancelled = c; + this.cancelled = false; + this.faction = faction; + this.fplayer = fplayer; } }