Added Activate/Deactivate events
This commit is contained in:
		@@ -9,7 +9,9 @@ import java.util.Iterator;
 | 
			
		||||
import java.util.Scanner;
 | 
			
		||||
import java.util.logging.Level;
 | 
			
		||||
 | 
			
		||||
import net.TheDgtl.Stargate.event.StargateActivateEvent;
 | 
			
		||||
import net.TheDgtl.Stargate.event.StargateCloseEvent;
 | 
			
		||||
import net.TheDgtl.Stargate.event.StargateDeactivateEvent;
 | 
			
		||||
import net.TheDgtl.Stargate.event.StargateOpenEvent;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
@@ -415,6 +417,10 @@ public class Portal {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void activate(Player player) {
 | 
			
		||||
		StargateActivateEvent event = new StargateActivateEvent(this);
 | 
			
		||||
		Stargate.server.getPluginManager().callEvent(event);
 | 
			
		||||
		if (event.isCancelled()) return;
 | 
			
		||||
		
 | 
			
		||||
		destinations.clear();
 | 
			
		||||
		destination = "";
 | 
			
		||||
		drawSign();
 | 
			
		||||
@@ -439,6 +445,10 @@ public class Portal {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void deactivate() {
 | 
			
		||||
		StargateDeactivateEvent event = new StargateDeactivateEvent(this);
 | 
			
		||||
		Stargate.server.getPluginManager().callEvent(event);
 | 
			
		||||
		if (event.isCancelled()) return;
 | 
			
		||||
		
 | 
			
		||||
		Stargate.activeList.remove(this);
 | 
			
		||||
		if (isFixed()) {
 | 
			
		||||
			return;
 | 
			
		||||
@@ -1032,23 +1042,32 @@ public class Portal {
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	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
 | 
			
		||||
	public boolean equals(Object obj) {
 | 
			
		||||
		if (this == obj) {
 | 
			
		||||
		if (this == obj)
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		if (obj == null) {
 | 
			
		||||
		if (obj == null)
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		if (getClass() != obj.getClass()) {
 | 
			
		||||
		if (getClass() != obj.getClass())
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Portal portal = (Portal) obj;
 | 
			
		||||
		return (this.getNetwork().equalsIgnoreCase(portal.getNetwork()) && 
 | 
			
		||||
				this.getName().equalsIgnoreCase(portal.getName()));
 | 
			
		||||
		Portal other = (Portal) obj;
 | 
			
		||||
		if (name == null) {
 | 
			
		||||
			if (other.name != null)
 | 
			
		||||
				return false;
 | 
			
		||||
		} 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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -270,6 +270,25 @@ public class Stargate extends JavaPlugin {
 | 
			
		||||
		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) {
 | 
			
		||||
		Portal destination = portal.getDestination();
 | 
			
		||||
		
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								src/net/TheDgtl/Stargate/event/StargateActivateEvent.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/net/TheDgtl/Stargate/event/StargateActivateEvent.java
									
									
									
									
									
										Normal 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);
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -4,8 +4,19 @@ import net.TheDgtl.Stargate.Portal;
 | 
			
		||||
 | 
			
		||||
public class StargateCloseEvent extends StargateEvent {
 | 
			
		||||
	private static final long serialVersionUID = -4382967941863636023L;
 | 
			
		||||
	private 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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								src/net/TheDgtl/Stargate/event/StargateDeactivateEvent.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/net/TheDgtl/Stargate/event/StargateDeactivateEvent.java
									
									
									
									
									
										Normal 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);
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -9,27 +9,17 @@ public class StargateEvent extends Event implements Cancellable {
 | 
			
		||||
	private static final long serialVersionUID = -5079274654178040431L;
 | 
			
		||||
	protected Portal portal;
 | 
			
		||||
	protected boolean cancelled;
 | 
			
		||||
	protected boolean force;
 | 
			
		||||
	
 | 
			
		||||
	public StargateEvent(String event, Portal portal, boolean force) {
 | 
			
		||||
	public StargateEvent(String event, Portal portal) {
 | 
			
		||||
		super (event);
 | 
			
		||||
		this.portal = portal;
 | 
			
		||||
		this.cancelled = false;
 | 
			
		||||
		this.force = force;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public Portal getPortal() {
 | 
			
		||||
		return portal;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public boolean getForce() {
 | 
			
		||||
		return force;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void setForce(boolean force) {
 | 
			
		||||
		this.force = force;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean isCancelled() {
 | 
			
		||||
		return this.cancelled;
 | 
			
		||||
 
 | 
			
		||||
@@ -17,12 +17,24 @@ public class StargateListener extends CustomEventListener implements Listener {
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void onStargateActivate(StargateActivateEvent event) {
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void onStargateDeactivate(StargateDeactivateEvent event) {
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onCustomEvent(Event event) {
 | 
			
		||||
		if (event instanceof StargateOpenEvent) {
 | 
			
		||||
			onStargateOpen((StargateOpenEvent)event);
 | 
			
		||||
		} else if (event instanceof StargateCloseEvent) {
 | 
			
		||||
			onStargateClose((StargateCloseEvent)event);
 | 
			
		||||
		} else if (event instanceof StargateActivateEvent) {
 | 
			
		||||
			onStargateActivate((StargateActivateEvent)event);
 | 
			
		||||
		} else if (event instanceof StargateDeactivateEvent) {
 | 
			
		||||
			onStargateDeactivate((StargateDeactivateEvent)event);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,13 +6,14 @@ import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
public class StargateOpenEvent extends StargateEvent {
 | 
			
		||||
	private static final long serialVersionUID = -2804865767733660648L;
 | 
			
		||||
	Player player;
 | 
			
		||||
	private Player player;
 | 
			
		||||
	private boolean force;
 | 
			
		||||
	
 | 
			
		||||
	public StargateOpenEvent(Player player, Portal portal, boolean force) {
 | 
			
		||||
		super ("StargateOpenEvent", portal, force);
 | 
			
		||||
		super ("StargateOpenEvent", portal);
 | 
			
		||||
		
 | 
			
		||||
		this.player = player;
 | 
			
		||||
		this.portal = portal;
 | 
			
		||||
		this.force = force;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
@@ -22,4 +23,12 @@ public class StargateOpenEvent extends StargateEvent {
 | 
			
		||||
	public Player getPlayer() {
 | 
			
		||||
		return player;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public boolean getForce() {
 | 
			
		||||
		return force;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void setForce(boolean force) {
 | 
			
		||||
		this.force = force;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user