From 218484f445a23e3e420dd8623ec0733bf7d23fb4 Mon Sep 17 00:00:00 2001 From: Steven Scott Date: Thu, 2 Feb 2012 22:00:30 -0800 Subject: [PATCH] [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) --- README | 10 + src/config.yml | 2 + src/net/TheDgtl/Stargate/Portal.java | 214 +++++++++++++----- src/net/TheDgtl/Stargate/Stargate.java | 109 ++++----- .../Stargate/event/StargateAccessEvent.java | 14 +- .../Stargate/event/StargateActivateEvent.java | 12 +- .../Stargate/event/StargateCloseEvent.java | 13 +- .../Stargate/event/StargateCreateEvent.java | 66 ++++++ .../event/StargateDeactivateEvent.java | 13 +- .../Stargate/event/StargateDestroyEvent.java | 60 +++++ .../TheDgtl/Stargate/event/StargateEvent.java | 1 - .../Stargate/event/StargateListener.java | 52 ----- .../Stargate/event/StargateOpenEvent.java | 10 + .../Stargate/event/StargatePortalEvent.java | 11 + src/plugin.yml | 2 +- 15 files changed, 409 insertions(+), 180 deletions(-) create mode 100644 src/net/TheDgtl/Stargate/event/StargateCreateEvent.java create mode 100644 src/net/TheDgtl/Stargate/event/StargateDestroyEvent.java delete mode 100644 src/net/TheDgtl/Stargate/event/StargateListener.java diff --git a/README b/README index 12ec7db..d8c2862 100644 --- a/README +++ b/README @@ -27,6 +27,7 @@ stargate.option -- Allow use of all options stargate.option.free -- Allow use of 'F'ree stargate.option.backwards -- Allow use of 'B'ackwards 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.personal -- Allow creating gates on network {playername} @@ -80,6 +81,7 @@ Sign Layout: 'F' for a free gate 'B' is for a backwards facing gate (You will exit the back) 'S' is for showing an always-on gate in the network list + 'N' is for hiding the network name Options: 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) 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. +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 permdebug - Whether to show massive permission debug output @@ -198,6 +201,13 @@ createConflict=Gate conflicts with existing gate ============= 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] - Changed the implementation of StargateAccessEvent. - Disable Permissions if version is 2.7.2 (Common version used between bridges) diff --git a/src/config.yml b/src/config.yml index 28be59d..f1fc4c8 100644 --- a/src/config.yml +++ b/src/config.yml @@ -17,6 +17,8 @@ lang: en destMemory: false # Ignore the entrance blocks of a gate when checking. Used to work around snowmen ignoreEntrance: false +# Whether to allow vehicles through gates +handleVehicles: true # Stargate economy options diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index 0555f44..682496d 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -11,6 +11,7 @@ import java.util.logging.Level; import net.TheDgtl.Stargate.event.StargateActivateEvent; import net.TheDgtl.Stargate.event.StargateCloseEvent; +import net.TheDgtl.Stargate.event.StargateCreateEvent; import net.TheDgtl.Stargate.event.StargateDeactivateEvent; import net.TheDgtl.Stargate.event.StargateOpenEvent; import net.TheDgtl.Stargate.event.StargatePortalEvent; @@ -76,6 +77,7 @@ public class Portal { private boolean free = false; private boolean backwards = false; private boolean show = false; + private boolean noNetwork = false; // In-use information private Player player; @@ -88,7 +90,7 @@ public class Portal { float rotX, SignPost id, Blox button, String dest, String name, 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.modX = modX; this.modZ = modZ; @@ -107,6 +109,7 @@ public class Portal { this.free = free; this.backwards = backwards; this.show = show; + this.noNetwork = noNetwork; this.world = topLeft.getWorld(); this.fixed = dest.length() > 0; @@ -114,8 +117,7 @@ public class Portal { this.alwaysOn = false; Stargate.debug("Portal", "Can not create a non-fixed always-on gate. Setting AlwaysOn = false"); } - - this.register(); + if (verified) { this.drawSign(); } @@ -152,6 +154,38 @@ public class Portal { 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 */ @@ -159,6 +193,22 @@ public class Portal { public float getRotation() { 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() { return name; @@ -220,9 +270,26 @@ public class Portal { return frame; } + public Block getSign() { + return id.getBlock(); + } + public World getWorld() { return world; } + + public Block getButton() { + if (button == null) return null; + return button.getBlock(); + } + + public void setButton(Blox button) { + this.button = button; + } + + public static ArrayList getNetwork(String network) { + return allPortalsNet.get(network); + } public boolean open(boolean force) { return open(null, force); @@ -490,18 +557,6 @@ public class Portal { 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) { cycleDestination(player, 1); } @@ -542,11 +597,17 @@ public class Portal { if (!isActive()) { id.setText(++done, "Right click to"); id.setText(++done, "use the gate"); - id.setText(++done, " (" + network + ") "); + if (!noNetwork) { + id.setText(++done, " (" + network + ") "); + } } else { if (isFixed()) { 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); if (dest == null) { id.setText(++done, "(Not Connected)"); @@ -659,6 +720,7 @@ public class Portal { } private void register() { + fixed = destination.length() > 0; if (!lookupNamesNet.containsKey(getNetwork().toLowerCase())) { Stargate.debug("register", "Network not in lookupNamesNet, adding"); lookupNamesNet.put(getNetwork().toLowerCase(), new HashMap()); @@ -713,6 +775,7 @@ public class Portal { boolean free = (options.indexOf('f') != - 1|| options.indexOf('F') != -1); boolean backwards = (options.indexOf('b') != -1 || options.indexOf('B') != -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. if (hidden && !Stargate.canOption(player, "hidden")) hidden = false; @@ -721,6 +784,7 @@ public class Portal { if (free && !Stargate.canOption(player, "free")) free = false; if (backwards && !Stargate.canOption(player, "backwards")) backwards = 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. if (alwaysOn && destName.length() == 0) { @@ -792,12 +856,15 @@ public class Portal { } // 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)) { network = Stargate.getDefaultNetwork(); } + boolean deny = false; + String denyMsg = ""; + // Check if the player can create gates on this network if (!Stargate.canCreate(player, network)) { 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")); } else { Stargate.debug("createPortal", "Player does not have access to network"); - Stargate.sendMessage(player, Stargate.getString("createNetDeny")); - return null; + deny = true; + denyMsg = Stargate.getString("createNetDeny"); + //return null; } } // Check if the player can create this gate layout String gateName = gate.getFilename(); 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.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 netList = allPortalsNet.get(network.toLowerCase()); - if (Stargate.maxGates > 0 && netList != null && netList.size() >= Stargate.maxGates) { - Stargate.sendMessage(player, Stargate.getString("createFull")); - return null; + deny = true; + denyMsg = Stargate.getString("createGateDeny"); + //Stargate.sendMessage(player, Stargate.getString("createGateDeny")); + //return null; } // 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); if (p != null) { String world = p.getWorld().getName(); if (!Stargate.canAccessWorld(player, world)) { Stargate.debug("canCreate", "Player does not have access to destination world"); - Stargate.sendMessage(player, Stargate.getString("createWorldDeny")); - return null; + //Stargate.sendMessage(player, Stargate.getString("createWorldDeny")); + deny = true; + denyMsg = Stargate.getString("createWorldDeny"); + //return null; } } } @@ -864,9 +917,55 @@ public class Portal { } } - int cost = Stargate.getCreateCost(player, gate); + 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); + + // 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 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 (!Stargate.chargePlayer(player, null, gate.getCreateCost())) { + if (!Stargate.chargePlayer(player, null, cost)) { String inFundMsg = Stargate.getString("ecoInFunds"); inFundMsg = Stargate.replaceVars(inFundMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), name}); Stargate.sendMessage(player, inFundMsg); @@ -877,18 +976,9 @@ public class Portal { deductMsg = Stargate.replaceVars(deductMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), name}); Stargate.sendMessage(player, deductMsg, false); } - - Portal portal = null; - - 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); - + + portal.register(); + portal.drawSign(); // Open always on gate if (portal.isAlwaysOn()) { Portal dest = Portal.getByName(destName, portal.getNetwork()); @@ -984,6 +1074,8 @@ public class Portal { builder.append(portal.isBackwards()); builder.append(':'); builder.append(portal.isShown()); + builder.append(':'); + builder.append(portal.isNoNetwork()); bw.append(builder.toString()); bw.newLine(); @@ -1052,8 +1144,10 @@ public class Portal { boolean free = (split.length > 15) ? split[15].equalsIgnoreCase("true") : false; boolean backwards = (split.length > 16) ? split[16].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); } scanner.close(); diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index 10fe24b..f01a2b4 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -7,6 +7,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import net.TheDgtl.Stargate.event.StargateAccessEvent; +import net.TheDgtl.Stargate.event.StargateDestroyEvent; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -21,27 +22,21 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; 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.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockFromToEvent; -import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntityListener; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.server.PluginDisableEvent; 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.world.WorldListener; import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; @@ -57,17 +52,11 @@ import com.nijikokun.bukkit.Permissions.Permissions; * @author Dinnerbone * @author Steven "Drakia" Scott */ +@SuppressWarnings("unused") public class Stargate extends JavaPlugin { // Permissions 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; private FileConfiguration newConfig; private PluginManager pm; @@ -85,6 +74,7 @@ public class Stargate extends JavaPlugin { private static int activeTime = 10; private static int openTime = 10; public static boolean destMemory = false; + public static boolean handleVehicles = true; // Temp workaround for snowmen, don't check gate entrance public static boolean ignoreEntrance = false; @@ -116,9 +106,6 @@ public class Stargate extends JavaPlugin { 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.migrate(); this.reloadGates(); @@ -137,29 +124,13 @@ public class Stargate extends JavaPlugin { log.info("[Stargate] Vault v" + iConomyHandler.vault.getDescription().getVersion() + " found"); } - pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Priority.Normal, this); + pm.registerEvents(new pListener(), this); + pm.registerEvents(new bListener(), this); - pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this); - pm.registerEvent(Event.Type.SIGN_CHANGE, blockListener, Priority.Normal, 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); + pm.registerEvents(new vListener(), this); + pm.registerEvents(new eListener(), this); + pm.registerEvents(new wListener(), this); + pm.registerEvents(new sListener(), this); getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L); } @@ -179,6 +150,7 @@ public class Stargate extends JavaPlugin { langName = newConfig.getString("lang"); destMemory = newConfig.getBoolean("destMemory"); ignoreEntrance = newConfig.getBoolean("ignoreEntrance"); + handleVehicles = newConfig.getBoolean("handleVehicles"); // Debug debug = newConfig.getBoolean("debug"); permDebug = newConfig.getBoolean("permdebug"); @@ -598,9 +570,10 @@ public class Stargate extends JavaPlugin { return format; } - private class vListener extends VehicleListener { - @Override + private class vListener implements Listener { + @EventHandler public void onVehicleMove(VehicleMoveEvent event) { + if (!handleVehicles) return; Entity passenger = event.getVehicle().getPassenger(); Vehicle vehicle = event.getVehicle(); @@ -666,8 +639,8 @@ public class Stargate extends JavaPlugin { } } - private class pListener extends PlayerListener { - @Override + private class pListener implements Listener { + @EventHandler public void onPlayerPortal(PlayerPortalEvent event) { // Do a quick check for a stargate Location from = event.getFrom(); @@ -695,7 +668,7 @@ public class Stargate extends JavaPlugin { } } - @Override + @EventHandler public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); Portal portal = Portal.getByEntrance(event.getTo()); @@ -758,7 +731,7 @@ public class Stargate extends JavaPlugin { portal.close(false); } - @Override + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); Block block = event.getClickedBlock(); @@ -865,8 +838,8 @@ public class Stargate extends JavaPlugin { } } - private class bListener extends BlockListener { - @Override + private class bListener implements Listener { + @EventHandler public void onSignChange(SignChangeEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); @@ -885,7 +858,7 @@ public class Stargate extends JavaPlugin { }, 1); } - @Override + @EventHandler public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled()) return; Block block = event.getBlock(); @@ -897,14 +870,30 @@ public class Stargate extends JavaPlugin { Portal portal = Portal.getByBlock(block); if (portal == null) return; + boolean deny = false; + String denyMsg = ""; + 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"); + } + + 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); return; } - int cost = Stargate.getDestroyCost(player, portal.getGate()); + cost = dEvent.getCost(); if (cost != 0) { if (!Stargate.chargePlayer(player, null, cost)) { @@ -929,14 +918,14 @@ public class Stargate extends JavaPlugin { Stargate.sendMessage(player, Stargate.getString("destroyMsg"), false); } - @Override + @EventHandler public void onBlockPhysics(BlockPhysicsEvent event) { Block block = event.getBlock(); Portal portal = Portal.getByEntrance(block); if (portal != null) event.setCancelled(true); } - @Override + @EventHandler public void onBlockFromTo(BlockFromToEvent event) { Portal portal = Portal.getByEntrance(event.getBlock()); @@ -946,8 +935,8 @@ public class Stargate extends JavaPlugin { } } - private class wListener extends WorldListener { - @Override + private class wListener implements Listener { + @EventHandler public void onWorldLoad(WorldLoadEvent event) { World w = event.getWorld(); // 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 { - @Override + private class eListener implements Listener { + @EventHandler public void onEntityExplode(EntityExplodeEvent event) { if (event.isCancelled()) return; for (Block b : event.blockList()) { @@ -1066,8 +1055,8 @@ public class Stargate extends JavaPlugin { }*/ } - private class sListener extends ServerListener { - @Override + private class sListener implements Listener { + @EventHandler public void onPluginEnable(PluginEnableEvent event) { if (iConomyHandler.setupRegister(event.getPlugin())) { 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) { if (iConomyHandler.checkLost(event.getPlugin())) { log.info("[Stargate] Register/Vault plugin lost."); diff --git a/src/net/TheDgtl/Stargate/event/StargateAccessEvent.java b/src/net/TheDgtl/Stargate/event/StargateAccessEvent.java index e6bc947..5346001 100644 --- a/src/net/TheDgtl/Stargate/event/StargateAccessEvent.java +++ b/src/net/TheDgtl/Stargate/event/StargateAccessEvent.java @@ -1,17 +1,25 @@ package net.TheDgtl.Stargate.event; import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; import net.TheDgtl.Stargate.Portal; public class StargateAccessEvent extends StargateEvent { - /** - * - */ private static final long serialVersionUID = -1009056668229801760L; private Player player; 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) { super("StargateAccessEvent", portal); diff --git a/src/net/TheDgtl/Stargate/event/StargateActivateEvent.java b/src/net/TheDgtl/Stargate/event/StargateActivateEvent.java index 2df02be..ecc30c5 100644 --- a/src/net/TheDgtl/Stargate/event/StargateActivateEvent.java +++ b/src/net/TheDgtl/Stargate/event/StargateActivateEvent.java @@ -1,6 +1,7 @@ package net.TheDgtl.Stargate.event; import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; import net.TheDgtl.Stargate.Portal; @@ -8,7 +9,16 @@ public class StargateActivateEvent extends StargateEvent { private static final long serialVersionUID = -8058490029263773684L; 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) { super("StargatActivateEvent", portal); diff --git a/src/net/TheDgtl/Stargate/event/StargateCloseEvent.java b/src/net/TheDgtl/Stargate/event/StargateCloseEvent.java index 15cc98e..37d59f5 100644 --- a/src/net/TheDgtl/Stargate/event/StargateCloseEvent.java +++ b/src/net/TheDgtl/Stargate/event/StargateCloseEvent.java @@ -1,11 +1,22 @@ package net.TheDgtl.Stargate.event; +import org.bukkit.event.HandlerList; + import net.TheDgtl.Stargate.Portal; public class StargateCloseEvent extends StargateEvent { private static final long serialVersionUID = -4382967941863636023L; 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) { super("StargateCloseEvent", portal); diff --git a/src/net/TheDgtl/Stargate/event/StargateCreateEvent.java b/src/net/TheDgtl/Stargate/event/StargateCreateEvent.java new file mode 100644 index 0000000..99ceb6d --- /dev/null +++ b/src/net/TheDgtl/Stargate/event/StargateCreateEvent.java @@ -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; + } + +} diff --git a/src/net/TheDgtl/Stargate/event/StargateDeactivateEvent.java b/src/net/TheDgtl/Stargate/event/StargateDeactivateEvent.java index 72fae31..829676b 100644 --- a/src/net/TheDgtl/Stargate/event/StargateDeactivateEvent.java +++ b/src/net/TheDgtl/Stargate/event/StargateDeactivateEvent.java @@ -1,10 +1,21 @@ package net.TheDgtl.Stargate.event; +import org.bukkit.event.HandlerList; + import net.TheDgtl.Stargate.Portal; public class StargateDeactivateEvent extends StargateEvent { 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) { super("StargatDeactivateEvent", portal); diff --git a/src/net/TheDgtl/Stargate/event/StargateDestroyEvent.java b/src/net/TheDgtl/Stargate/event/StargateDestroyEvent.java new file mode 100644 index 0000000..c0d55b2 --- /dev/null +++ b/src/net/TheDgtl/Stargate/event/StargateDestroyEvent.java @@ -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; + } + +} diff --git a/src/net/TheDgtl/Stargate/event/StargateEvent.java b/src/net/TheDgtl/Stargate/event/StargateEvent.java index 5f02517..44b1597 100644 --- a/src/net/TheDgtl/Stargate/event/StargateEvent.java +++ b/src/net/TheDgtl/Stargate/event/StargateEvent.java @@ -29,5 +29,4 @@ public class StargateEvent extends Event implements Cancellable { public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } - } diff --git a/src/net/TheDgtl/Stargate/event/StargateListener.java b/src/net/TheDgtl/Stargate/event/StargateListener.java deleted file mode 100644 index 48498aa..0000000 --- a/src/net/TheDgtl/Stargate/event/StargateListener.java +++ /dev/null @@ -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); - } - } -} diff --git a/src/net/TheDgtl/Stargate/event/StargateOpenEvent.java b/src/net/TheDgtl/Stargate/event/StargateOpenEvent.java index f4aae84..c837514 100644 --- a/src/net/TheDgtl/Stargate/event/StargateOpenEvent.java +++ b/src/net/TheDgtl/Stargate/event/StargateOpenEvent.java @@ -3,12 +3,22 @@ package net.TheDgtl.Stargate.event; import net.TheDgtl.Stargate.Portal; import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; public class StargateOpenEvent extends StargateEvent { private static final long serialVersionUID = -2804865767733660648L; private Player player; 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) { super ("StargateOpenEvent", portal); diff --git a/src/net/TheDgtl/Stargate/event/StargatePortalEvent.java b/src/net/TheDgtl/Stargate/event/StargatePortalEvent.java index 3d0c78c..8c06ad7 100644 --- a/src/net/TheDgtl/Stargate/event/StargatePortalEvent.java +++ b/src/net/TheDgtl/Stargate/event/StargatePortalEvent.java @@ -4,6 +4,7 @@ import net.TheDgtl.Stargate.Portal; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; public class StargatePortalEvent extends StargateEvent { private static final long serialVersionUID = -7263321536459960366L; @@ -11,6 +12,16 @@ public class StargatePortalEvent extends StargateEvent { private Portal destination; 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) { super ("StargatePortalEvent", portal); diff --git a/src/plugin.yml b/src/plugin.yml index 8d5f791..9c2439d 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.7.4.4 +version: 0.7.5.0 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net