Added Activate/Deactivate events

This commit is contained in:
Steven Scott 2011-08-18 22:00:35 -07:00
parent f174d9003b
commit e4c945449a
8 changed files with 110 additions and 26 deletions

View File

@ -9,7 +9,9 @@ import java.util.Iterator;
import java.util.Scanner; import java.util.Scanner;
import java.util.logging.Level; import java.util.logging.Level;
import net.TheDgtl.Stargate.event.StargateActivateEvent;
import net.TheDgtl.Stargate.event.StargateCloseEvent; import net.TheDgtl.Stargate.event.StargateCloseEvent;
import net.TheDgtl.Stargate.event.StargateDeactivateEvent;
import net.TheDgtl.Stargate.event.StargateOpenEvent; import net.TheDgtl.Stargate.event.StargateOpenEvent;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -415,6 +417,10 @@ public class Portal {
} }
public void activate(Player player) { public void activate(Player player) {
StargateActivateEvent event = new StargateActivateEvent(this);
Stargate.server.getPluginManager().callEvent(event);
if (event.isCancelled()) return;
destinations.clear(); destinations.clear();
destination = ""; destination = "";
drawSign(); drawSign();
@ -439,6 +445,10 @@ public class Portal {
} }
public void deactivate() { public void deactivate() {
StargateDeactivateEvent event = new StargateDeactivateEvent(this);
Stargate.server.getPluginManager().callEvent(event);
if (event.isCancelled()) return;
Stargate.activeList.remove(this); Stargate.activeList.remove(this);
if (isFixed()) { if (isFixed()) {
return; return;
@ -1032,23 +1042,32 @@ public class Portal {
@Override @Override
public int hashCode() { public int hashCode() {
return getName().hashCode(); final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((network == null) ? 0 : network.hashCode());
return result;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj)
return true; return true;
} if (obj == null)
if (obj == null) {
return false; return false;
} if (getClass() != obj.getClass())
if (getClass() != obj.getClass()) {
return false; return false;
} Portal other = (Portal) obj;
if (name == null) {
Portal portal = (Portal) obj; if (other.name != null)
return (this.getNetwork().equalsIgnoreCase(portal.getNetwork()) && return false;
this.getName().equalsIgnoreCase(portal.getName())); } else if (!name.equalsIgnoreCase(other.name))
return false;
if (network == null) {
if (other.network != null)
return false;
} else if (!network.equalsIgnoreCase(other.network))
return false;
return true;
} }
} }

View File

@ -270,6 +270,25 @@ public class Stargate extends JavaPlugin {
return defNetwork; return defNetwork;
} }
public static String getTeleMsg() {
return teleMsg;
}
public static String getRegMsg() {
return regMsg;
}
public static String getDmgMsg() {
return dmgMsg;
}
public static String getDenyMsg() {
return denyMsg;
}
public static String getInvMsg() {
return invMsg;
}
public static String getBlockMsg() {
return blockMsg;
}
private void onButtonPressed(Player player, Portal portal) { private void onButtonPressed(Player player, Portal portal) {
Portal destination = portal.getDestination(); Portal destination = portal.getDestination();

View File

@ -0,0 +1,12 @@
package net.TheDgtl.Stargate.event;
import net.TheDgtl.Stargate.Portal;
public class StargateActivateEvent extends StargateEvent {
private static final long serialVersionUID = -8058490029263773684L;
public StargateActivateEvent(Portal portal) {
super("StargatActivateEvent", portal);
}
}

View File

@ -4,8 +4,19 @@ import net.TheDgtl.Stargate.Portal;
public class StargateCloseEvent extends StargateEvent { public class StargateCloseEvent extends StargateEvent {
private static final long serialVersionUID = -4382967941863636023L; private static final long serialVersionUID = -4382967941863636023L;
private boolean force;
public StargateCloseEvent(Portal portal, boolean force) { public StargateCloseEvent(Portal portal, boolean force) {
super("StargateCloseEvent", portal, force); super("StargateCloseEvent", portal);
this.force = force;
}
public boolean getForce() {
return force;
}
public void setForce(boolean force) {
this.force = force;
} }
} }

View File

@ -0,0 +1,12 @@
package net.TheDgtl.Stargate.event;
import net.TheDgtl.Stargate.Portal;
public class StargateDeactivateEvent extends StargateEvent {
private static final long serialVersionUID = -1863190375834892100L;
public StargateDeactivateEvent(Portal portal) {
super("StargatDeactivateEvent", portal);
}
}

View File

@ -9,27 +9,17 @@ public class StargateEvent extends Event implements Cancellable {
private static final long serialVersionUID = -5079274654178040431L; private static final long serialVersionUID = -5079274654178040431L;
protected Portal portal; protected Portal portal;
protected boolean cancelled; protected boolean cancelled;
protected boolean force;
public StargateEvent(String event, Portal portal, boolean force) { public StargateEvent(String event, Portal portal) {
super (event); super (event);
this.portal = portal; this.portal = portal;
this.cancelled = false; this.cancelled = false;
this.force = force;
} }
public Portal getPortal() { public Portal getPortal() {
return portal; return portal;
} }
public boolean getForce() {
return force;
}
public void setForce(boolean force) {
this.force = force;
}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return this.cancelled; return this.cancelled;

View File

@ -17,12 +17,24 @@ public class StargateListener extends CustomEventListener implements Listener {
} }
public void onStargateActivate(StargateActivateEvent event) {
}
public void onStargateDeactivate(StargateDeactivateEvent event) {
}
@Override @Override
public void onCustomEvent(Event event) { public void onCustomEvent(Event event) {
if (event instanceof StargateOpenEvent) { if (event instanceof StargateOpenEvent) {
onStargateOpen((StargateOpenEvent)event); onStargateOpen((StargateOpenEvent)event);
} else if (event instanceof StargateCloseEvent) { } else if (event instanceof StargateCloseEvent) {
onStargateClose((StargateCloseEvent)event); onStargateClose((StargateCloseEvent)event);
} else if (event instanceof StargateActivateEvent) {
onStargateActivate((StargateActivateEvent)event);
} else if (event instanceof StargateDeactivateEvent) {
onStargateDeactivate((StargateDeactivateEvent)event);
} }
} }
} }

View File

@ -6,13 +6,14 @@ import org.bukkit.entity.Player;
public class StargateOpenEvent extends StargateEvent { public class StargateOpenEvent extends StargateEvent {
private static final long serialVersionUID = -2804865767733660648L; private static final long serialVersionUID = -2804865767733660648L;
Player player; private Player player;
private boolean force;
public StargateOpenEvent(Player player, Portal portal, boolean force) { public StargateOpenEvent(Player player, Portal portal, boolean force) {
super ("StargateOpenEvent", portal, force); super ("StargateOpenEvent", portal);
this.player = player; this.player = player;
this.portal = portal; this.force = force;
} }
/** /**
@ -22,4 +23,12 @@ public class StargateOpenEvent extends StargateEvent {
public Player getPlayer() { public Player getPlayer() {
return player; return player;
} }
public boolean getForce() {
return force;
}
public void setForce(boolean force) {
this.force = force;
}
} }