From 4d5278b079e1c049cb949f6c76acd8e5404d0a95 Mon Sep 17 00:00:00 2001 From: drtshock Date: Wed, 9 Jul 2014 14:00:16 -0500 Subject: [PATCH] Improve and document event system. Deprecate duplicate methods. --- .../factions/event/FPlayerJoinEvent.java | 24 +----------- .../factions/event/FPlayerLeaveEvent.java | 31 +++------------ .../factions/event/FactionCreateEvent.java | 1 + .../factions/event/FactionDisbandEvent.java | 21 ++-------- .../factions/event/FactionEvent.java | 27 +++++++++++++ .../factions/event/FactionPlayerEvent.java | 18 +++++++++ .../factions/event/FactionRelationEvent.java | 1 + .../factions/event/FactionRenameEvent.java | 35 ++++------------- .../factions/event/LandClaimEvent.java | 33 ++++------------ .../factions/event/LandUnclaimAllEvent.java | 34 ++++------------- .../factions/event/LandUnclaimEvent.java | 33 ++++------------ .../factions/event/PowerLossEvent.java | 38 +++++-------------- 12 files changed, 99 insertions(+), 197 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/event/FactionEvent.java create mode 100644 src/main/java/com/massivecraft/factions/event/FactionPlayerEvent.java diff --git a/src/main/java/com/massivecraft/factions/event/FPlayerJoinEvent.java b/src/main/java/com/massivecraft/factions/event/FPlayerJoinEvent.java index 433eb380..28376823 100644 --- a/src/main/java/com/massivecraft/factions/event/FPlayerJoinEvent.java +++ b/src/main/java/com/massivecraft/factions/event/FPlayerJoinEvent.java @@ -6,11 +6,8 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class FPlayerJoinEvent extends Event implements Cancellable { - private static final HandlerList handlers = new HandlerList(); +public class FPlayerJoinEvent extends FactionPlayerEvent implements Cancellable { - FPlayer fplayer; - Faction faction; PlayerJoinReason reason; boolean cancelled = false; @@ -19,31 +16,14 @@ public class FPlayerJoinEvent extends Event implements Cancellable { } public FPlayerJoinEvent(FPlayer fp, Faction f, PlayerJoinReason r) { - fplayer = fp; - faction = f; + super(f, fp); reason = r; } - public FPlayer getFPlayer() { - return fplayer; - } - - public Faction getFaction() { - return faction; - } - public PlayerJoinReason getReason() { return reason; } - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - @Override public boolean isCancelled() { return cancelled; diff --git a/src/main/java/com/massivecraft/factions/event/FPlayerLeaveEvent.java b/src/main/java/com/massivecraft/factions/event/FPlayerLeaveEvent.java index 805ec745..6ff0c195 100644 --- a/src/main/java/com/massivecraft/factions/event/FPlayerLeaveEvent.java +++ b/src/main/java/com/massivecraft/factions/event/FPlayerLeaveEvent.java @@ -6,11 +6,9 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class FPlayerLeaveEvent extends Event implements Cancellable { - private static final HandlerList handlers = new HandlerList(); +public class FPlayerLeaveEvent extends FactionPlayerEvent implements Cancellable { + private PlayerLeaveReason reason; - FPlayer FPlayer; - Faction Faction; boolean cancelled = false; public enum PlayerLeaveReason { @@ -18,31 +16,14 @@ public class FPlayerLeaveEvent extends Event implements Cancellable { } public FPlayerLeaveEvent(FPlayer p, Faction f, PlayerLeaveReason r) { - FPlayer = p; - Faction = f; + super(f, p); reason = r; } - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - public PlayerLeaveReason getReason() { return reason; } - public FPlayer getFPlayer() { - return FPlayer; - } - - public Faction getFaction() { - return Faction; - } - @Override public boolean isCancelled() { return cancelled; @@ -51,9 +32,9 @@ public class FPlayerLeaveEvent extends Event implements Cancellable { @Override public void setCancelled(boolean c) { if (reason == PlayerLeaveReason.DISBAND || reason == PlayerLeaveReason.RESET) { - cancelled = false; - return; - } + cancelled = false; // Don't let them cancel factions disbanding. + } else { cancelled = c; + } } } \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/event/FactionCreateEvent.java b/src/main/java/com/massivecraft/factions/event/FactionCreateEvent.java index 1f18d39a..671b3b9d 100644 --- a/src/main/java/com/massivecraft/factions/event/FactionCreateEvent.java +++ b/src/main/java/com/massivecraft/factions/event/FactionCreateEvent.java @@ -9,6 +9,7 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; public class FactionCreateEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); private String factionTag; diff --git a/src/main/java/com/massivecraft/factions/event/FactionDisbandEvent.java b/src/main/java/com/massivecraft/factions/event/FactionDisbandEvent.java index b7f767ae..eef61556 100644 --- a/src/main/java/com/massivecraft/factions/event/FactionDisbandEvent.java +++ b/src/main/java/com/massivecraft/factions/event/FactionDisbandEvent.java @@ -9,29 +9,14 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class FactionDisbandEvent extends Event implements Cancellable { - private static final HandlerList handlers = new HandlerList(); +public class FactionDisbandEvent extends FactionEvent implements Cancellable { - private boolean cancelled; - private String id; + private boolean cancelled = false; private Player sender; public FactionDisbandEvent(Player sender, String factionId) { - cancelled = false; + super(Factions.i.get(factionId)); this.sender = sender; - this.id = factionId; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - public Faction getFaction() { - return Factions.i.get(id); } public FPlayer getFPlayer() { diff --git a/src/main/java/com/massivecraft/factions/event/FactionEvent.java b/src/main/java/com/massivecraft/factions/event/FactionEvent.java new file mode 100644 index 00000000..a9037edc --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/FactionEvent.java @@ -0,0 +1,27 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.Faction; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class FactionEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + private final Faction faction; + + public FactionEvent(Faction faction) { + this.faction = faction; + } + + public Faction getFaction() { + return this.getFaction(); + } + + public HandlerList getHandlers() { + return handlers; + } + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/FactionPlayerEvent.java b/src/main/java/com/massivecraft/factions/event/FactionPlayerEvent.java new file mode 100644 index 00000000..da59473d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/FactionPlayerEvent.java @@ -0,0 +1,18 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; + +public class FactionPlayerEvent extends FactionEvent { + + private final FPlayer fPlayer; + + public FactionPlayerEvent(Faction faction, FPlayer fPlayer) { + super(faction); + this.fPlayer = fPlayer; + } + + public FPlayer getfPlayer() { + return this.fPlayer; + } +} diff --git a/src/main/java/com/massivecraft/factions/event/FactionRelationEvent.java b/src/main/java/com/massivecraft/factions/event/FactionRelationEvent.java index 05f0d344..601525a5 100644 --- a/src/main/java/com/massivecraft/factions/event/FactionRelationEvent.java +++ b/src/main/java/com/massivecraft/factions/event/FactionRelationEvent.java @@ -7,6 +7,7 @@ import org.bukkit.event.HandlerList; public class FactionRelationEvent extends Event { + private static final HandlerList handlers = new HandlerList(); private Faction fsender; diff --git a/src/main/java/com/massivecraft/factions/event/FactionRenameEvent.java b/src/main/java/com/massivecraft/factions/event/FactionRenameEvent.java index d8862526..146de1d0 100644 --- a/src/main/java/com/massivecraft/factions/event/FactionRenameEvent.java +++ b/src/main/java/com/massivecraft/factions/event/FactionRenameEvent.java @@ -7,47 +7,28 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class FactionRenameEvent extends Event implements Cancellable { - private static final HandlerList handlers = new HandlerList(); +public class FactionRenameEvent extends FactionPlayerEvent implements Cancellable { - private boolean cancelled; - private FPlayer fplayer; - private Faction faction; + private boolean cancelled = false; private String tag; public FactionRenameEvent(FPlayer sender, String newTag) { - fplayer = sender; - faction = sender.getFaction(); + super(sender.getFaction(), sender); tag = newTag; - this.cancelled = false; - } - - public Faction getFaction() { - return (faction); - } - - public FPlayer getFPlayer() { - return (fplayer); } + @Deprecated public Player getPlayer() { - return (fplayer.getPlayer()); + return getfPlayer().getPlayer(); } + @Deprecated public String getOldFactionTag() { - return (faction.getTag()); + return getFaction().getTag(); } public String getFactionTag() { - return (tag); - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; + return tag; } @Override diff --git a/src/main/java/com/massivecraft/factions/event/LandClaimEvent.java b/src/main/java/com/massivecraft/factions/event/LandClaimEvent.java index 55ff0eef..133cf10b 100644 --- a/src/main/java/com/massivecraft/factions/event/LandClaimEvent.java +++ b/src/main/java/com/massivecraft/factions/event/LandClaimEvent.java @@ -8,51 +8,34 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class LandClaimEvent extends Event implements Cancellable { - private static final HandlerList handlers = new HandlerList(); +public class LandClaimEvent extends FactionPlayerEvent implements Cancellable { private boolean cancelled; private FLocation location; - private Faction faction; - private FPlayer fplayer; public LandClaimEvent(FLocation loc, Faction f, FPlayer p) { + super(f, p); 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; - } - + @Deprecated public String getFactionId() { - return faction.getId(); + return getFaction().getId(); } + @Deprecated public String getFactionTag() { - return faction.getTag(); - } - - public FPlayer getFPlayer() { - return fplayer; + return getFaction().getTag(); } + @Deprecated public Player getPlayer() { - return fplayer.getPlayer(); + return getfPlayer().getPlayer(); } @Override diff --git a/src/main/java/com/massivecraft/factions/event/LandUnclaimAllEvent.java b/src/main/java/com/massivecraft/factions/event/LandUnclaimAllEvent.java index 0e705778..6d1264bf 100644 --- a/src/main/java/com/massivecraft/factions/event/LandUnclaimAllEvent.java +++ b/src/main/java/com/massivecraft/factions/event/LandUnclaimAllEvent.java @@ -6,42 +6,24 @@ import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class LandUnclaimAllEvent extends Event { - private static final HandlerList handlers = new HandlerList(); - - private Faction faction; - private FPlayer fplayer; +public class LandUnclaimAllEvent extends FactionPlayerEvent { public LandUnclaimAllEvent(Faction f, FPlayer p) { - faction = f; - fplayer = p; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - public Faction getFaction() { - return faction; + super(f, p); } + @Deprecated public String getFactionId() { - return faction.getId(); + return getFaction().getId(); } + @Deprecated public String getFactionTag() { - return faction.getTag(); - } - - public FPlayer getFPlayer() { - return fplayer; + return getFaction().getTag(); } + @Deprecated public Player getPlayer() { - return fplayer.getPlayer(); + return getfPlayer().getPlayer(); } } diff --git a/src/main/java/com/massivecraft/factions/event/LandUnclaimEvent.java b/src/main/java/com/massivecraft/factions/event/LandUnclaimEvent.java index 436f58cb..1c5f77c7 100644 --- a/src/main/java/com/massivecraft/factions/event/LandUnclaimEvent.java +++ b/src/main/java/com/massivecraft/factions/event/LandUnclaimEvent.java @@ -8,51 +8,34 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class LandUnclaimEvent extends Event implements Cancellable { - private static final HandlerList handlers = new HandlerList(); +public class LandUnclaimEvent extends FactionPlayerEvent implements Cancellable { private boolean cancelled; private FLocation location; - private Faction faction; - private FPlayer fplayer; public LandUnclaimEvent(FLocation loc, Faction f, FPlayer p) { + super(f, p); 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; - } - + @Deprecated public String getFactionId() { - return faction.getId(); + return getFaction().getId(); } + @Deprecated public String getFactionTag() { - return faction.getTag(); - } - - public FPlayer getFPlayer() { - return fplayer; + return getFaction().getTag(); } + @Deprecated public Player getPlayer() { - return fplayer.getPlayer(); + return getfPlayer().getPlayer(); } @Override diff --git a/src/main/java/com/massivecraft/factions/event/PowerLossEvent.java b/src/main/java/com/massivecraft/factions/event/PowerLossEvent.java index cd64dc0e..0f28cda1 100644 --- a/src/main/java/com/massivecraft/factions/event/PowerLossEvent.java +++ b/src/main/java/com/massivecraft/factions/event/PowerLossEvent.java @@ -7,48 +7,28 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +public class PowerLossEvent extends FactionPlayerEvent implements Cancellable { -public class PowerLossEvent extends Event implements Cancellable { - private static final HandlerList handlers = new HandlerList(); - - private boolean cancelled; - private Faction faction; - private FPlayer fplayer; + private boolean cancelled = false; private String message; public PowerLossEvent(Faction f, FPlayer p) { - cancelled = false; - faction = f; - fplayer = p; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - public Faction getFaction() { - return faction; + super(f, p); } + @Deprecated public String getFactionId() { - return faction.getId(); + return getFaction().getId(); } + @Deprecated public String getFactionTag() { - return faction.getTag(); - } - - public FPlayer getFPlayer() { - return fplayer; + return getFaction().getTag(); } + @Deprecated public Player getPlayer() { - return fplayer.getPlayer(); + return getfPlayer().getPlayer(); } public String getMessage() {