Improve and document event system. Deprecate duplicate methods.

This commit is contained in:
drtshock 2014-07-09 14:00:16 -05:00
parent 7604b4455b
commit 4d5278b079
12 changed files with 99 additions and 197 deletions

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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() {

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -7,6 +7,7 @@ import org.bukkit.event.HandlerList;
public class FactionRelationEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Faction fsender;

View File

@ -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

View File

@ -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

View File

@ -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();
}
}

View File

@ -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

View File

@ -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() {