[Version 0.7.5.0]

- Refactored creation code a bit
 - Added StargateCreateEvent, see Stargate-API for usage.
 - Added StargateDestroyEvent, see Stargate-API for usage.
 - Updated Event API to the new standard, please see:
http://wiki.bukkit.org/Introduction_to_the_New_Event_System
 - Added handleVehicles option.
 - Added 'N'o Network option (Hides the network from the sign)
This commit is contained in:
Steven Scott 2012-02-02 22:00:30 -08:00
parent bf92401ea9
commit 218484f445
15 changed files with 409 additions and 180 deletions

10
README
View File

@ -27,6 +27,7 @@ stargate.option -- Allow use of all options
stargate.option.free -- Allow use of 'F'ree stargate.option.free -- Allow use of 'F'ree
stargate.option.backwards -- Allow use of 'B'ackwards stargate.option.backwards -- Allow use of 'B'ackwards
stargate.option.show -- Allow use of 'S'how stargate.option.show -- Allow use of 'S'how
stargate.option.nonetwork -- Allow use of 'N'oNetwork
stargate.create -- Allow creating gates on any network (Override all create permissions) stargate.create -- Allow creating gates on any network (Override all create permissions)
stargate.create.personal -- Allow creating gates on network {playername} stargate.create.personal -- Allow creating gates on network {playername}
@ -80,6 +81,7 @@ Sign Layout:
'F' for a free gate 'F' for a free gate
'B' is for a backwards facing gate (You will exit the back) 'B' is for a backwards facing gate (You will exit the back)
'S' is for showing an always-on gate in the network list 'S' is for showing an always-on gate in the network list
'N' is for hiding the network name
Options: Options:
The options are the single letter, not the word. So to make a private hidden gate, your 4th line would be 'PH'. The options are the single letter, not the word. So to make a private hidden gate, your 4th line would be 'PH'.
@ -156,6 +158,7 @@ maxgates - If non-zero, will define the maximum amount of gates allowed on any n
lang - The language to use (Included languages: en, de) lang - The language to use (Included languages: en, de)
destMemory - Whether to set the first destination as the last used destination for all gates destMemory - Whether to set the first destination as the last used destination for all gates
ignoreEntrance - Set this option to true to not check the entrance of a gate on startup. This is a workaround for snowmen breaking gates. ignoreEntrance - Set this option to true to not check the entrance of a gate on startup. This is a workaround for snowmen breaking gates.
handleVehicles - Whether or not to handle vehicles going through gates. Set to false to disallow vehicles (Manned or not) going through gates.
debug - Whether to show massive debug output debug - Whether to show massive debug output
permdebug - Whether to show massive permission debug output permdebug - Whether to show massive permission debug output
@ -198,6 +201,13 @@ createConflict=Gate conflicts with existing gate
============= =============
Changes Changes
============= =============
[Version 0.7.5.0]
- Refactored creation code a bit
- Added StargateCreateEvent, see Stargate-API for usage.
- Added StargateDestroyEvent, see Stargate-API for usage.
- Updated Event API to the new standard, please see: http://wiki.bukkit.org/Introduction_to_the_New_Event_System
- Added handleVehicles option.
- Added 'N'o Network option (Hides the network from the sign)
[Version 0.7.4.4] [Version 0.7.4.4]
- Changed the implementation of StargateAccessEvent. - Changed the implementation of StargateAccessEvent.
- Disable Permissions if version is 2.7.2 (Common version used between bridges) - Disable Permissions if version is 2.7.2 (Common version used between bridges)

View File

@ -17,6 +17,8 @@ lang: en
destMemory: false destMemory: false
# Ignore the entrance blocks of a gate when checking. Used to work around snowmen # Ignore the entrance blocks of a gate when checking. Used to work around snowmen
ignoreEntrance: false ignoreEntrance: false
# Whether to allow vehicles through gates
handleVehicles: true
# Stargate economy options # Stargate economy options

View File

@ -11,6 +11,7 @@ import java.util.logging.Level;
import net.TheDgtl.Stargate.event.StargateActivateEvent; import net.TheDgtl.Stargate.event.StargateActivateEvent;
import net.TheDgtl.Stargate.event.StargateCloseEvent; import net.TheDgtl.Stargate.event.StargateCloseEvent;
import net.TheDgtl.Stargate.event.StargateCreateEvent;
import net.TheDgtl.Stargate.event.StargateDeactivateEvent; import net.TheDgtl.Stargate.event.StargateDeactivateEvent;
import net.TheDgtl.Stargate.event.StargateOpenEvent; import net.TheDgtl.Stargate.event.StargateOpenEvent;
import net.TheDgtl.Stargate.event.StargatePortalEvent; import net.TheDgtl.Stargate.event.StargatePortalEvent;
@ -76,6 +77,7 @@ public class Portal {
private boolean free = false; private boolean free = false;
private boolean backwards = false; private boolean backwards = false;
private boolean show = false; private boolean show = false;
private boolean noNetwork = false;
// In-use information // In-use information
private Player player; private Player player;
@ -88,7 +90,7 @@ public class Portal {
float rotX, SignPost id, Blox button, float rotX, SignPost id, Blox button,
String dest, String name, String dest, String name,
boolean verified, String network, Gate gate, String owner, boolean verified, String network, Gate gate, String owner,
boolean hidden, boolean alwaysOn, boolean priv, boolean free, boolean backwards, boolean show) { boolean hidden, boolean alwaysOn, boolean priv, boolean free, boolean backwards, boolean show, boolean noNetwork) {
this.topLeft = topLeft; this.topLeft = topLeft;
this.modX = modX; this.modX = modX;
this.modZ = modZ; this.modZ = modZ;
@ -107,6 +109,7 @@ public class Portal {
this.free = free; this.free = free;
this.backwards = backwards; this.backwards = backwards;
this.show = show; this.show = show;
this.noNetwork = noNetwork;
this.world = topLeft.getWorld(); this.world = topLeft.getWorld();
this.fixed = dest.length() > 0; this.fixed = dest.length() > 0;
@ -115,7 +118,6 @@ public class Portal {
Stargate.debug("Portal", "Can not create a non-fixed always-on gate. Setting AlwaysOn = false"); Stargate.debug("Portal", "Can not create a non-fixed always-on gate. Setting AlwaysOn = false");
} }
this.register();
if (verified) { if (verified) {
this.drawSign(); this.drawSign();
} }
@ -152,6 +154,38 @@ public class Portal {
return show; return show;
} }
public boolean isNoNetwork() {
return noNetwork;
}
public void setAlwaysOn(boolean alwaysOn) {
this.alwaysOn = alwaysOn;
}
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
public void setPrivate(boolean priv) {
this.priv = priv;
}
public void setFree(boolean free) {
this.free = free;
}
public void setBackwards(boolean backwards) {
this.backwards = backwards;
}
public void setShown(boolean show) {
this.show = show;
}
public void setNoNetwork(boolean noNetwork) {
this.noNetwork = noNetwork;
}
/** /**
* Getters and Setters * Getters and Setters
*/ */
@ -160,6 +194,22 @@ public class Portal {
return rotX; return rotX;
} }
public Player getActivePlayer() {
return activePlayer;
}
public String getNetwork() {
return network;
}
public void setNetwork(String network) {
this.network = network;
}
public long getOpenTime() {
return openTime;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -220,10 +270,27 @@ public class Portal {
return frame; return frame;
} }
public Block getSign() {
return id.getBlock();
}
public World getWorld() { public World getWorld() {
return world; return world;
} }
public Block getButton() {
if (button == null) return null;
return button.getBlock();
}
public void setButton(Blox button) {
this.button = button;
}
public static ArrayList<String> getNetwork(String network) {
return allPortalsNet.get(network);
}
public boolean open(boolean force) { public boolean open(boolean force) {
return open(null, force); return open(null, force);
} }
@ -490,18 +557,6 @@ public class Portal {
return isFixed() || (destinations.size() > 0); return isFixed() || (destinations.size() > 0);
} }
public Player getActivePlayer() {
return activePlayer;
}
public String getNetwork() {
return network;
}
public long getOpenTime() {
return openTime;
}
public void cycleDestination(Player player) { public void cycleDestination(Player player) {
cycleDestination(player, 1); cycleDestination(player, 1);
} }
@ -542,11 +597,17 @@ public class Portal {
if (!isActive()) { if (!isActive()) {
id.setText(++done, "Right click to"); id.setText(++done, "Right click to");
id.setText(++done, "use the gate"); id.setText(++done, "use the gate");
id.setText(++done, " (" + network + ") "); if (!noNetwork) {
id.setText(++done, " (" + network + ") ");
}
} else { } else {
if (isFixed()) { if (isFixed()) {
id.setText(++done, "To: " + destination); id.setText(++done, "To: " + destination);
id.setText(++done, " (" + network + ") "); if (noNetwork) {
id.setText(++done, "");
} else {
id.setText(++done, " (" + network + ") ");
}
Portal dest = Portal.getByName(destination, network); Portal dest = Portal.getByName(destination, network);
if (dest == null) { if (dest == null) {
id.setText(++done, "(Not Connected)"); id.setText(++done, "(Not Connected)");
@ -659,6 +720,7 @@ public class Portal {
} }
private void register() { private void register() {
fixed = destination.length() > 0;
if (!lookupNamesNet.containsKey(getNetwork().toLowerCase())) { if (!lookupNamesNet.containsKey(getNetwork().toLowerCase())) {
Stargate.debug("register", "Network not in lookupNamesNet, adding"); Stargate.debug("register", "Network not in lookupNamesNet, adding");
lookupNamesNet.put(getNetwork().toLowerCase(), new HashMap<String, Portal>()); lookupNamesNet.put(getNetwork().toLowerCase(), new HashMap<String, Portal>());
@ -713,6 +775,7 @@ public class Portal {
boolean free = (options.indexOf('f') != - 1|| options.indexOf('F') != -1); boolean free = (options.indexOf('f') != - 1|| options.indexOf('F') != -1);
boolean backwards = (options.indexOf('b') != -1 || options.indexOf('B') != -1); boolean backwards = (options.indexOf('b') != -1 || options.indexOf('B') != -1);
boolean show = (options.indexOf('s') != -1 || options.indexOf('S') != -1); boolean show = (options.indexOf('s') != -1 || options.indexOf('S') != -1);
boolean noNetwork = (options.indexOf('n') != -1 || options.indexOf('N') != -1);
// Check permissions for options. // Check permissions for options.
if (hidden && !Stargate.canOption(player, "hidden")) hidden = false; if (hidden && !Stargate.canOption(player, "hidden")) hidden = false;
@ -721,6 +784,7 @@ public class Portal {
if (free && !Stargate.canOption(player, "free")) free = false; if (free && !Stargate.canOption(player, "free")) free = false;
if (backwards && !Stargate.canOption(player, "backwards")) backwards = false; if (backwards && !Stargate.canOption(player, "backwards")) backwards = false;
if (show && !Stargate.canOption(player, "show")) show = false; if (show && !Stargate.canOption(player, "show")) show = false;
if (noNetwork && !Stargate.canOption(player, "nonetwork")) noNetwork = false;
// Can not create a non-fixed always-on gate. // Can not create a non-fixed always-on gate.
if (alwaysOn && destName.length() == 0) { if (alwaysOn && destName.length() == 0) {
@ -792,12 +856,15 @@ public class Portal {
} }
// Debug // Debug
Stargate.debug("createPortal", "h = " + hidden + " a = " + alwaysOn + " p = " + priv + " f = " + free + " b = " + backwards + " s = " + show); Stargate.debug("createPortal", "h = " + hidden + " a = " + alwaysOn + " p = " + priv + " f = " + free + " b = " + backwards + " s = " + show + " n = " + noNetwork);
if ((network.length() < 1) || (network.length() > 11)) { if ((network.length() < 1) || (network.length() > 11)) {
network = Stargate.getDefaultNetwork(); network = Stargate.getDefaultNetwork();
} }
boolean deny = false;
String denyMsg = "";
// Check if the player can create gates on this network // Check if the player can create gates on this network
if (!Stargate.canCreate(player, network)) { if (!Stargate.canCreate(player, network)) {
Stargate.debug("createPortal", "Player doesn't have create permissions on network. Trying personal"); Stargate.debug("createPortal", "Player doesn't have create permissions on network. Trying personal");
@ -808,48 +875,34 @@ public class Portal {
Stargate.sendMessage(player, Stargate.getString("createPersonal")); Stargate.sendMessage(player, Stargate.getString("createPersonal"));
} else { } else {
Stargate.debug("createPortal", "Player does not have access to network"); Stargate.debug("createPortal", "Player does not have access to network");
Stargate.sendMessage(player, Stargate.getString("createNetDeny")); deny = true;
return null; denyMsg = Stargate.getString("createNetDeny");
//return null;
} }
} }
// Check if the player can create this gate layout // Check if the player can create this gate layout
String gateName = gate.getFilename(); String gateName = gate.getFilename();
gateName = gateName.substring(0, gateName.indexOf('.')); gateName = gateName.substring(0, gateName.indexOf('.'));
if (!Stargate.canCreateGate(player, gateName)) { if (!deny && !Stargate.canCreateGate(player, gateName)) {
Stargate.debug("createPortal", "Player does not have access to gate layout"); Stargate.debug("createPortal", "Player does not have access to gate layout");
Stargate.sendMessage(player, Stargate.getString("createGateDeny")); deny = true;
return null; denyMsg = Stargate.getString("createGateDeny");
} //Stargate.sendMessage(player, Stargate.getString("createGateDeny"));
//return null;
if (name.length() < 1 || name.length() > 11) {
Stargate.debug("createPortal", "Name length error");
Stargate.sendMessage(player, Stargate.getString("createNameLength"));
return null;
}
if (getByName(name, network) != null) {
Stargate.debug("createPortal", "Name Error");
Stargate.sendMessage(player, Stargate.getString("createExists"));
return null;
}
// Check if there are too many gates in this network
ArrayList<String> netList = allPortalsNet.get(network.toLowerCase());
if (Stargate.maxGates > 0 && netList != null && netList.size() >= Stargate.maxGates) {
Stargate.sendMessage(player, Stargate.getString("createFull"));
return null;
} }
// Check if the user can create gates to this world. // Check if the user can create gates to this world.
if (destName.length() > 0) { if (!deny && destName.length() > 0) {
Portal p = Portal.getByName(destName, network); Portal p = Portal.getByName(destName, network);
if (p != null) { if (p != null) {
String world = p.getWorld().getName(); String world = p.getWorld().getName();
if (!Stargate.canAccessWorld(player, world)) { if (!Stargate.canAccessWorld(player, world)) {
Stargate.debug("canCreate", "Player does not have access to destination world"); Stargate.debug("canCreate", "Player does not have access to destination world");
Stargate.sendMessage(player, Stargate.getString("createWorldDeny")); //Stargate.sendMessage(player, Stargate.getString("createWorldDeny"));
return null; deny = true;
denyMsg = Stargate.getString("createWorldDeny");
//return null;
} }
} }
} }
@ -864,9 +917,55 @@ public class Portal {
} }
} }
Blox button = null;
Portal portal = null;
portal = new Portal(topleft, modX, modZ, rotX, id, button, destName, name, false, network, gate, player.getName(), hidden, alwaysOn, priv, free, backwards, show, noNetwork);
int cost = Stargate.getCreateCost(player, gate); int cost = Stargate.getCreateCost(player, gate);
// Call StargateCreateEvent
StargateCreateEvent cEvent = new StargateCreateEvent(player, portal, event.getLines(), deny, denyMsg, cost);
Stargate.server.getPluginManager().callEvent(cEvent);
if (cEvent.isCancelled()) {
return null;
}
if (cEvent.getDeny()) {
Stargate.sendMessage(player, cEvent.getDenyReason());
return null;
}
cost = cEvent.getCost();
// No button on an always-open gate.
if (!alwaysOn) {
button = topleft.modRelative(buttonVector.getRight(), buttonVector.getDepth(), buttonVector.getDistance() + 1, modX, 1, modZ);
button.setType(Material.STONE_BUTTON.getId());
button.setData(facing);
portal.setButton(button);
}
// Name & Network can be changed in the event, so do these checks here.
if (portal.getName().length() < 1 || portal.getName().length() > 11) {
Stargate.debug("createPortal", "Name length error");
Stargate.sendMessage(player, Stargate.getString("createNameLength"));
return null;
}
if (getByName(portal.getName(), portal.getNetwork()) != null) {
Stargate.debug("createPortal", "Name Error");
Stargate.sendMessage(player, Stargate.getString("createExists"));
return null;
}
// Check if there are too many gates in this network
ArrayList<String> netList = allPortalsNet.get(portal.getNetwork().toLowerCase());
if (Stargate.maxGates > 0 && netList != null && netList.size() >= Stargate.maxGates) {
Stargate.sendMessage(player, Stargate.getString("createFull"));
return null;
}
if (cost > 0) { if (cost > 0) {
if (!Stargate.chargePlayer(player, null, gate.getCreateCost())) { if (!Stargate.chargePlayer(player, null, cost)) {
String inFundMsg = Stargate.getString("ecoInFunds"); String inFundMsg = Stargate.getString("ecoInFunds");
inFundMsg = Stargate.replaceVars(inFundMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), name}); inFundMsg = Stargate.replaceVars(inFundMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), name});
Stargate.sendMessage(player, inFundMsg); Stargate.sendMessage(player, inFundMsg);
@ -878,17 +977,8 @@ public class Portal {
Stargate.sendMessage(player, deductMsg, false); Stargate.sendMessage(player, deductMsg, false);
} }
Portal portal = null; portal.register();
portal.drawSign();
Blox button = null;
// No button on an always-open gate.
if (!alwaysOn) {
button = topleft.modRelative(buttonVector.getRight(), buttonVector.getDepth(), buttonVector.getDistance() + 1, modX, 1, modZ);
button.setType(Material.STONE_BUTTON.getId());
button.setData(facing);
}
portal = new Portal(topleft, modX, modZ, rotX, id, button, destName, name, true, network, gate, player.getName(), hidden, alwaysOn, priv, free, backwards, show);
// Open always on gate // Open always on gate
if (portal.isAlwaysOn()) { if (portal.isAlwaysOn()) {
Portal dest = Portal.getByName(destName, portal.getNetwork()); Portal dest = Portal.getByName(destName, portal.getNetwork());
@ -984,6 +1074,8 @@ public class Portal {
builder.append(portal.isBackwards()); builder.append(portal.isBackwards());
builder.append(':'); builder.append(':');
builder.append(portal.isShown()); builder.append(portal.isShown());
builder.append(':');
builder.append(portal.isNoNetwork());
bw.append(builder.toString()); bw.append(builder.toString());
bw.newLine(); bw.newLine();
@ -1052,8 +1144,10 @@ public class Portal {
boolean free = (split.length > 15) ? split[15].equalsIgnoreCase("true") : false; boolean free = (split.length > 15) ? split[15].equalsIgnoreCase("true") : false;
boolean backwards = (split.length > 16) ? split[16].equalsIgnoreCase("true") : false; boolean backwards = (split.length > 16) ? split[16].equalsIgnoreCase("true") : false;
boolean show = (split.length > 17) ? split[17].equalsIgnoreCase("true") : false; boolean show = (split.length > 17) ? split[17].equalsIgnoreCase("true") : false;
boolean noNetwork = (split.length > 18) ? split[18].equalsIgnoreCase("true") : false;
Portal portal = new Portal(topLeft, modX, modZ, rotX, sign, button, dest, name, false, network, gate, owner, hidden, alwaysOn, priv, free, backwards, show); Portal portal = new Portal(topLeft, modX, modZ, rotX, sign, button, dest, name, false, network, gate, owner, hidden, alwaysOn, priv, free, backwards, show, noNetwork);
portal.register();
portal.close(true); portal.close(true);
} }
scanner.close(); scanner.close();

View File

@ -7,6 +7,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.TheDgtl.Stargate.event.StargateAccessEvent; import net.TheDgtl.Stargate.event.StargateAccessEvent;
import net.TheDgtl.Stargate.event.StargateDestroyEvent;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -21,27 +22,21 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle; import org.bukkit.entity.Vehicle;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Result; import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.event.vehicle.VehicleListener;
import org.bukkit.event.vehicle.VehicleMoveEvent; import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.event.world.WorldListener;
import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
@ -57,17 +52,11 @@ import com.nijikokun.bukkit.Permissions.Permissions;
* @author Dinnerbone * @author Dinnerbone
* @author Steven "Drakia" Scott * @author Steven "Drakia" Scott
*/ */
@SuppressWarnings("unused")
public class Stargate extends JavaPlugin { public class Stargate extends JavaPlugin {
// Permissions // Permissions
private static Permissions permissions = null; private static Permissions permissions = null;
private final bListener blockListener = new bListener();
private final pListener playerListener = new pListener();
private final vListener vehicleListener = new vListener();
private final wListener worldListener = new wListener();
private final eListener entityListener = new eListener();
private final sListener serverListener = new sListener();
public static Logger log; public static Logger log;
private FileConfiguration newConfig; private FileConfiguration newConfig;
private PluginManager pm; private PluginManager pm;
@ -85,6 +74,7 @@ public class Stargate extends JavaPlugin {
private static int activeTime = 10; private static int activeTime = 10;
private static int openTime = 10; private static int openTime = 10;
public static boolean destMemory = false; public static boolean destMemory = false;
public static boolean handleVehicles = true;
// Temp workaround for snowmen, don't check gate entrance // Temp workaround for snowmen, don't check gate entrance
public static boolean ignoreEntrance = false; public static boolean ignoreEntrance = false;
@ -116,9 +106,6 @@ public class Stargate extends JavaPlugin {
log.info(pdfFile.getName() + " v." + pdfFile.getVersion() + " is enabled."); log.info(pdfFile.getName() + " v." + pdfFile.getVersion() + " is enabled.");
pm.registerEvent(Event.Type.BLOCK_FROMTO, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this);
this.loadConfig(); this.loadConfig();
this.migrate(); this.migrate();
this.reloadGates(); this.reloadGates();
@ -137,29 +124,13 @@ public class Stargate extends JavaPlugin {
log.info("[Stargate] Vault v" + iConomyHandler.vault.getDescription().getVersion() + " found"); log.info("[Stargate] Vault v" + iConomyHandler.vault.getDescription().getVersion() + " found");
} }
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this); pm.registerEvents(new pListener(), this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Priority.Normal, this); pm.registerEvents(new bListener(), this);
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this); pm.registerEvents(new vListener(), this);
pm.registerEvent(Event.Type.SIGN_CHANGE, blockListener, Priority.Normal, this); pm.registerEvents(new eListener(), this);
pm.registerEvents(new wListener(), this);
pm.registerEvents(new sListener(), this);
pm.registerEvent(Event.Type.VEHICLE_MOVE, vehicleListener, Priority.Normal, this);
pm.registerEvent(Event.Type.WORLD_LOAD, worldListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this);
// TODO: Add when snowmanTrailEvent is pulled
//pm.registerEvent(Event.Type.SNOWMAN_TRAIL, entityListener, Priority.Normal, this);
//pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.Normal, this);
//pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Priority.Normal, this);
// Used to disable built-in portal for Stargates
pm.registerEvent(Event.Type.PLAYER_PORTAL, playerListener, Priority.Normal, this);
// Dependency Loading
pm.registerEvent(Event.Type.PLUGIN_ENABLE, serverListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Priority.Monitor, this);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L); getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L);
} }
@ -179,6 +150,7 @@ public class Stargate extends JavaPlugin {
langName = newConfig.getString("lang"); langName = newConfig.getString("lang");
destMemory = newConfig.getBoolean("destMemory"); destMemory = newConfig.getBoolean("destMemory");
ignoreEntrance = newConfig.getBoolean("ignoreEntrance"); ignoreEntrance = newConfig.getBoolean("ignoreEntrance");
handleVehicles = newConfig.getBoolean("handleVehicles");
// Debug // Debug
debug = newConfig.getBoolean("debug"); debug = newConfig.getBoolean("debug");
permDebug = newConfig.getBoolean("permdebug"); permDebug = newConfig.getBoolean("permdebug");
@ -598,9 +570,10 @@ public class Stargate extends JavaPlugin {
return format; return format;
} }
private class vListener extends VehicleListener { private class vListener implements Listener {
@Override @EventHandler
public void onVehicleMove(VehicleMoveEvent event) { public void onVehicleMove(VehicleMoveEvent event) {
if (!handleVehicles) return;
Entity passenger = event.getVehicle().getPassenger(); Entity passenger = event.getVehicle().getPassenger();
Vehicle vehicle = event.getVehicle(); Vehicle vehicle = event.getVehicle();
@ -666,8 +639,8 @@ public class Stargate extends JavaPlugin {
} }
} }
private class pListener extends PlayerListener { private class pListener implements Listener {
@Override @EventHandler
public void onPlayerPortal(PlayerPortalEvent event) { public void onPlayerPortal(PlayerPortalEvent event) {
// Do a quick check for a stargate // Do a quick check for a stargate
Location from = event.getFrom(); Location from = event.getFrom();
@ -695,7 +668,7 @@ public class Stargate extends JavaPlugin {
} }
} }
@Override @EventHandler
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Portal portal = Portal.getByEntrance(event.getTo()); Portal portal = Portal.getByEntrance(event.getTo());
@ -758,7 +731,7 @@ public class Stargate extends JavaPlugin {
portal.close(false); portal.close(false);
} }
@Override @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
@ -865,8 +838,8 @@ public class Stargate extends JavaPlugin {
} }
} }
private class bListener extends BlockListener { private class bListener implements Listener {
@Override @EventHandler
public void onSignChange(SignChangeEvent event) { public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getBlock(); Block block = event.getBlock();
@ -885,7 +858,7 @@ public class Stargate extends JavaPlugin {
}, 1); }, 1);
} }
@Override @EventHandler
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) return;
Block block = event.getBlock(); Block block = event.getBlock();
@ -897,14 +870,30 @@ public class Stargate extends JavaPlugin {
Portal portal = Portal.getByBlock(block); Portal portal = Portal.getByBlock(block);
if (portal == null) return; if (portal == null) return;
boolean deny = false;
String denyMsg = "";
if (!Stargate.canDestroy(player, portal)) { if (!Stargate.canDestroy(player, portal)) {
Stargate.sendMessage(player, "Permission Denied"); denyMsg = "Permission Denied"; // TODO: Change to Stargate.getString()
deny = true;
Stargate.log.info("[Stargate] " + player.getName() + " tried to destroy gate"); Stargate.log.info("[Stargate] " + player.getName() + " tried to destroy gate");
}
int cost = Stargate.getDestroyCost(player, portal.getGate());
StargateDestroyEvent dEvent = new StargateDestroyEvent(portal, player, deny, denyMsg, cost);
Stargate.server.getPluginManager().callEvent(dEvent);
if (dEvent.isCancelled()) {
event.setCancelled(true);
return;
}
if (dEvent.getDeny()) {
Stargate.sendMessage(player, dEvent.getDenyReason());
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
int cost = Stargate.getDestroyCost(player, portal.getGate()); cost = dEvent.getCost();
if (cost != 0) { if (cost != 0) {
if (!Stargate.chargePlayer(player, null, cost)) { if (!Stargate.chargePlayer(player, null, cost)) {
@ -929,14 +918,14 @@ public class Stargate extends JavaPlugin {
Stargate.sendMessage(player, Stargate.getString("destroyMsg"), false); Stargate.sendMessage(player, Stargate.getString("destroyMsg"), false);
} }
@Override @EventHandler
public void onBlockPhysics(BlockPhysicsEvent event) { public void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();
Portal portal = Portal.getByEntrance(block); Portal portal = Portal.getByEntrance(block);
if (portal != null) event.setCancelled(true); if (portal != null) event.setCancelled(true);
} }
@Override @EventHandler
public void onBlockFromTo(BlockFromToEvent event) { public void onBlockFromTo(BlockFromToEvent event) {
Portal portal = Portal.getByEntrance(event.getBlock()); Portal portal = Portal.getByEntrance(event.getBlock());
@ -946,8 +935,8 @@ public class Stargate extends JavaPlugin {
} }
} }
private class wListener extends WorldListener { private class wListener implements Listener {
@Override @EventHandler
public void onWorldLoad(WorldLoadEvent event) { public void onWorldLoad(WorldLoadEvent event) {
World w = event.getWorld(); World w = event.getWorld();
// We have to make sure the world is actually loaded. This gets called twice for some reason. // We have to make sure the world is actually loaded. This gets called twice for some reason.
@ -957,8 +946,8 @@ public class Stargate extends JavaPlugin {
} }
} }
private class eListener extends EntityListener { private class eListener implements Listener {
@Override @EventHandler
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) return;
for (Block b : event.blockList()) { for (Block b : event.blockList()) {
@ -1066,8 +1055,8 @@ public class Stargate extends JavaPlugin {
}*/ }*/
} }
private class sListener extends ServerListener { private class sListener implements Listener {
@Override @EventHandler
public void onPluginEnable(PluginEnableEvent event) { public void onPluginEnable(PluginEnableEvent event) {
if (iConomyHandler.setupRegister(event.getPlugin())) { if (iConomyHandler.setupRegister(event.getPlugin())) {
log.info("[Stargate] Register v" + iConomyHandler.register.getDescription().getVersion() + " found"); log.info("[Stargate] Register v" + iConomyHandler.register.getDescription().getVersion() + " found");
@ -1083,7 +1072,7 @@ public class Stargate extends JavaPlugin {
} }
} }
@Override @EventHandler
public void onPluginDisable(PluginDisableEvent event) { public void onPluginDisable(PluginDisableEvent event) {
if (iConomyHandler.checkLost(event.getPlugin())) { if (iConomyHandler.checkLost(event.getPlugin())) {
log.info("[Stargate] Register/Vault plugin lost."); log.info("[Stargate] Register/Vault plugin lost.");

View File

@ -1,17 +1,25 @@
package net.TheDgtl.Stargate.event; package net.TheDgtl.Stargate.event;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import net.TheDgtl.Stargate.Portal; import net.TheDgtl.Stargate.Portal;
public class StargateAccessEvent extends StargateEvent { public class StargateAccessEvent extends StargateEvent {
/**
*
*/
private static final long serialVersionUID = -1009056668229801760L; private static final long serialVersionUID = -1009056668229801760L;
private Player player; private Player player;
private boolean deny; private boolean deny;
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public StargateAccessEvent(Player player, Portal portal, boolean deny) { public StargateAccessEvent(Player player, Portal portal, boolean deny) {
super("StargateAccessEvent", portal); super("StargateAccessEvent", portal);

View File

@ -1,6 +1,7 @@
package net.TheDgtl.Stargate.event; package net.TheDgtl.Stargate.event;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import net.TheDgtl.Stargate.Portal; import net.TheDgtl.Stargate.Portal;
@ -9,6 +10,15 @@ public class StargateActivateEvent extends StargateEvent {
Player player; Player player;
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public StargateActivateEvent(Portal portal, Player player) { public StargateActivateEvent(Portal portal, Player player) {
super("StargatActivateEvent", portal); super("StargatActivateEvent", portal);

View File

@ -1,11 +1,22 @@
package net.TheDgtl.Stargate.event; package net.TheDgtl.Stargate.event;
import org.bukkit.event.HandlerList;
import net.TheDgtl.Stargate.Portal; 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; private boolean force;
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public StargateCloseEvent(Portal portal, boolean force) { public StargateCloseEvent(Portal portal, boolean force) {
super("StargateCloseEvent", portal); super("StargateCloseEvent", portal);

View File

@ -0,0 +1,66 @@
package net.TheDgtl.Stargate.event;
import net.TheDgtl.Stargate.Portal;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
public class StargateCreateEvent extends StargateEvent {
private static final long serialVersionUID = -4719797912801580960L;
private Player player;
private boolean deny;
private String denyReason;
private String[] lines;
private int cost;
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public StargateCreateEvent(Player player, Portal portal, String[] lines, boolean deny, String denyReason, int cost) {
super("StargateCreateEvent", portal);
this.player = player;
this.lines = lines;
this.deny = deny;
this.denyReason = denyReason;
this.cost = cost;
}
public Player getPlayer() {
return player;
}
public String getLine(int index) throws IndexOutOfBoundsException {
return lines[index];
}
public boolean getDeny() {
return deny;
}
public void setDeny(boolean deny) {
this.deny = deny;
}
public String getDenyReason() {
return denyReason;
}
public void setDenyReason(String denyReason) {
this.denyReason = denyReason;
}
public int getCost() {
return cost;
}
public void setCost(int cost) {
this.cost = cost;
}
}

View File

@ -1,10 +1,21 @@
package net.TheDgtl.Stargate.event; package net.TheDgtl.Stargate.event;
import org.bukkit.event.HandlerList;
import net.TheDgtl.Stargate.Portal; import net.TheDgtl.Stargate.Portal;
public class StargateDeactivateEvent extends StargateEvent { public class StargateDeactivateEvent extends StargateEvent {
private static final long serialVersionUID = -1863190375834892100L; private static final long serialVersionUID = -1863190375834892100L;
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public StargateDeactivateEvent(Portal portal) { public StargateDeactivateEvent(Portal portal) {
super("StargatDeactivateEvent", portal); super("StargatDeactivateEvent", portal);

View File

@ -0,0 +1,60 @@
package net.TheDgtl.Stargate.event;
import net.TheDgtl.Stargate.Portal;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
public class StargateDestroyEvent extends StargateEvent {
private static final long serialVersionUID = 1429032103662930225L;
private Player player;
private boolean deny;
private String denyReason;
private int cost;
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public StargateDestroyEvent(Portal portal, Player player, boolean deny, String denyMsg, int cost) {
super("StargateDestroyEvent", portal);
this.player = player;
this.deny = deny;
this.denyReason = denyMsg;
this.cost = cost;
}
public Player getPlayer() {
return player;
}
public boolean getDeny() {
return deny;
}
public void setDeny(boolean deny) {
this.deny = deny;
}
public String getDenyReason() {
return denyReason;
}
public void setDenyReason(String denyReason) {
this.denyReason = denyReason;
}
public int getCost() {
return cost;
}
public void setCost(int cost) {
this.cost = cost;
}
}

View File

@ -29,5 +29,4 @@ public class StargateEvent extends Event implements Cancellable {
public void setCancelled(boolean cancelled) { public void setCancelled(boolean cancelled) {
this.cancelled = cancelled; this.cancelled = cancelled;
} }
} }

View File

@ -1,52 +0,0 @@
package net.TheDgtl.Stargate.event;
import org.bukkit.event.CustomEventListener;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
public class StargateListener extends CustomEventListener implements Listener {
public StargateListener() {
}
public void onStargateOpen(StargateOpenEvent event) {
}
public void onStargateClose(StargateCloseEvent event) {
}
public void onStargateActivate(StargateActivateEvent event) {
}
public void onStargateDeactivate(StargateDeactivateEvent event) {
}
public void onStargatePortal(StargatePortalEvent event) {
}
public void onStargateAccess(StargateAccessEvent 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);
} else if (event instanceof StargatePortalEvent) {
onStargatePortal((StargatePortalEvent)event);
} else if (event instanceof StargateAccessEvent) {
onStargateAccess((StargateAccessEvent)event);
}
}
}

View File

@ -3,12 +3,22 @@ package net.TheDgtl.Stargate.event;
import net.TheDgtl.Stargate.Portal; import net.TheDgtl.Stargate.Portal;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
public class StargateOpenEvent extends StargateEvent { public class StargateOpenEvent extends StargateEvent {
private static final long serialVersionUID = -2804865767733660648L; private static final long serialVersionUID = -2804865767733660648L;
private Player player; private Player player;
private boolean force; private boolean force;
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public StargateOpenEvent(Player player, Portal portal, boolean force) { public StargateOpenEvent(Player player, Portal portal, boolean force) {
super ("StargateOpenEvent", portal); super ("StargateOpenEvent", portal);

View File

@ -4,6 +4,7 @@ import net.TheDgtl.Stargate.Portal;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
public class StargatePortalEvent extends StargateEvent { public class StargatePortalEvent extends StargateEvent {
private static final long serialVersionUID = -7263321536459960366L; private static final long serialVersionUID = -7263321536459960366L;
@ -11,6 +12,16 @@ public class StargatePortalEvent extends StargateEvent {
private Portal destination; private Portal destination;
private Location exit; private Location exit;
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public StargatePortalEvent(Player player, Portal portal, Portal dest, Location exit) { public StargatePortalEvent(Player player, Portal portal, Portal dest, Location exit) {
super ("StargatePortalEvent", portal); super ("StargatePortalEvent", portal);

View File

@ -1,6 +1,6 @@
name: Stargate name: Stargate
main: net.TheDgtl.Stargate.Stargate main: net.TheDgtl.Stargate.Stargate
version: 0.7.4.4 version: 0.7.5.0
description: Stargate mod for Bukkit description: Stargate mod for Bukkit
author: Drakia author: Drakia
website: http://www.thedgtl.net website: http://www.thedgtl.net