diff --git a/README b/README index a7f21d2..450aaa4 100644 --- a/README +++ b/README @@ -13,7 +13,6 @@ Known Issues ============= - Vehicle implementation is nowhere near done. - Signs aren't always updating, I don't know what's causing this, I think it's a Bukkit thing. - - You need to right-click the sign to initialize the gate, waiting on SIGN_CHANGE hook update. ============= Permissions @@ -36,17 +35,16 @@ Building a gate: - Type a set destination name on the second line if desired. - Type a network name on the third line if desired. - Type any options on the 4th line if desired. - - Right click the sign block to initialize the gate as a Stargate. (Bug Alert: Sign may not update right away) Sign Layout: - Line 1: Gate Name (Max 12 characters) - - Line 2: Destination Name (Max 12 characters, used for fixed-gates only) - - Line 3: Network name (Max 12 characters) - - Line 4: Options ('A' for always-on fixed gate, 'H' for hidden networked gate) + - Line 2: Destination Name [Optional] (Max 12 characters, used for fixed-gates only) + - Line 3: Network name [Optional] (Max 12 characters) + - Line 4: Options [Optional] ('A' for always-on fixed gate, 'H' for hidden networked gate) Using a gate: - Right click the sign to choose a destination. - - Right click the button to open up a portal. + - Right/left click the button to open up a portal. - Step through. Fixed gates: @@ -68,11 +66,23 @@ Hidden Gates: ============== Configuration ============== - - To change the text shown during events edit stargates.txt +default-gate-network - The default gate network +not-selected-message - The message when no destination is selected +portal-destroy-message - The message when a gate is destroyed +portal-create-message - The message when a gate is created +not-owner-message - The message when you aren't allowed to push the gate button +other-side-blocked-message - The message when the gate you're dialing is open +teleport-message - The message when you are teleported +portal-save-location - The file your portal database is saved as +gate-folder - The folder containing your .gate files ============= Changes ============= +[Version 0.08] + - Gates can now consist of any material. + - You can left or right click the button to open a gate + - Gates are now initialized on sign placement, not more right clicking! [Version 0.07] - Fixed where the default gate is saved to. [Version 0.06] diff --git a/src/net/TheDgtl/Stargate/Blox.java b/src/net/TheDgtl/Stargate/Blox.java index 9119bb4..9080c24 100644 --- a/src/net/TheDgtl/Stargate/Blox.java +++ b/src/net/TheDgtl/Stargate/Blox.java @@ -93,6 +93,8 @@ public class Blox { public String toString() { StringBuilder builder = new StringBuilder(); + //builder.append(world.getName()); + //builder.append(','); builder.append(x); builder.append(','); builder.append(y); diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index 4aa4fde..3da27cc 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -217,7 +217,7 @@ public class Portal { public void teleport(Vehicle vehicle, Portal origin) { Location traveller = new Location(this.world, vehicle.getLocation().getX(), vehicle.getLocation().getY(), vehicle.getLocation().getZ()); Location exit = getExit(traveller, origin); - + double velocity = vehicle.getVelocity().length(); // Stop and teleport @@ -311,7 +311,7 @@ public class Portal { } public boolean isVerified() { - verified = verified || getBlockAt(1, 0).getType() == OBSIDIAN; + verified = verified || getBlockAt(1, 0).getBlock().getTypeId() == gate.getControlBlock(); return verified; } @@ -584,7 +584,7 @@ public class Portal { public static Portal createPortal(SignPost id, Player player) { Block idParent = id.getParent(); - if (idParent.getType() != Material.OBSIDIAN) return null; + if (Gate.getGatesByControlBlock(idParent).length == 0) return null; Blox parent = new Blox(player.getWorld(), idParent.getX(), idParent.getY(), idParent.getZ()); Blox topleft = null; diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index c816408..7cd1d8e 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -20,6 +20,7 @@ import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockRightClickEvent; +import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.vehicle.VehicleListener; @@ -102,14 +103,14 @@ public class Stargate extends JavaPlugin implements Runnable { pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.VEHICLE_MOVE, vehicleListener, Priority.Normal, this); - //pm.registerEvent(Event.Type.SIGN_CHANGE, blockListener, Priority.Normal, this); + pm.registerEvent(Event.Type.SIGN_CHANGE, blockListener, Priority.Normal, this); setInterval(160); // 8 seconds. clock.start(); } - public void reloadConfig() { + public void reloadConfig() { config.load(); portalFile = config.getString("portal-save-location", portalFile); gateFolder = config.getString("gate-folder", gateFolder); @@ -122,7 +123,7 @@ public class Stargate extends JavaPlugin implements Runnable { defNetwork = config.getString("default-gate-network", defNetwork).trim(); saveConfig(); } - + public void saveConfig() { config.setProperty("portal-save-location", portalFile); config.setProperty("gate-folder", gateFolder); @@ -135,7 +136,7 @@ public class Stargate extends JavaPlugin implements Runnable { config.setProperty("default-gate-network", defNetwork); config.save(); } - + public void reloadGates() { Gate.loadGates(gateFolder); Portal.loadAllGates(this.getServer().getWorlds().get(0)); @@ -159,7 +160,7 @@ public class Stargate extends JavaPlugin implements Runnable { file.renameTo(new File(gateFolder + file.getName())); } } - } + } public synchronized void doWork() { Portal open = Portal.getNextOpen(); @@ -219,12 +220,12 @@ public class Stargate extends JavaPlugin implements Runnable { public void setupPermissions() { Plugin perm = pm.getPlugin("Permissions"); - if(perm != null) { - Stargate.Permissions = ((Permissions)perm).getHandler(); - } else { - log.info("[" + this.getDescription().getName() + "] Permission system not enabled. Disabling plugin."); + if(perm != null) { + Stargate.Permissions = ((Permissions)perm).getHandler(); + } else { + log.info("[" + this.getDescription().getName() + "] Permission system not enabled. Disabling plugin."); pm.disablePlugin(this); - } + } } private class vListener extends VehicleListener { @@ -236,24 +237,24 @@ public class Stargate extends JavaPlugin implements Runnable { Portal portal = Portal.getByEntrance(event.getTo()); if (portal != null && portal.isOpen()) { if (passenger instanceof Player) { - Player player = (Player)event.getVehicle().getPassenger(); + Player player = (Player)event.getVehicle().getPassenger(); if (!portal.isOpenFor(player)) { player.sendMessage(ChatColor.RED + denyMsg); return; - } + } Portal dest = portal.getDestination(); if (dest == null) return; dest.teleport(vehicle, portal); - + if (!teleMsg.isEmpty()) player.sendMessage(ChatColor.BLUE + teleMsg); - portal.close(false); - } else { + portal.close(false); + } else { - } - } - } + } + } } + } private class pListener extends PlayerListener { @Override @@ -293,6 +294,34 @@ public class Stargate extends JavaPlugin implements Runnable { if (portal != null) event.setCancelled(true); } } + + @Override + public void onSignChange(SignChangeEvent event) { + Player player = event.getPlayer(); + Block block = event.getBlock(); + // Initialize a stargate + if (Stargate.Permissions.has(player, "stargate.create")) { + SignPost sign = new SignPost(new Blox(block)); + // Set sign text so we can create a gate with it. + sign.setText(0, event.getLine(0)); + sign.setText(1, event.getLine(1)); + sign.setText(2, event.getLine(2)); + sign.setText(3, event.getLine(3)); + Portal portal = Portal.createPortal(sign, player); + if (portal == null) return; + + if (!regMsg.isEmpty()) { + player.sendMessage(ChatColor.GREEN + regMsg); + } + log.info("Initialized stargate: " + portal.getName()); + portal.drawSign(true); + // Set event text so our new sign is instantly initialized + event.setLine(0, sign.getText(0)); + event.setLine(1, sign.getText(1)); + event.setLine(2, sign.getText(2)); + event.setLine(3, sign.getText(3)); + } + } @Override public void onBlockRightClick(BlockRightClickEvent event) { @@ -308,21 +337,7 @@ public class Stargate extends JavaPlugin implements Runnable { } } } - - // Check if the player is initializing a stargate - if (portal == null && Stargate.Permissions.has(player, "stargate.create")) { - SignPost sign = new SignPost(new Blox(block)); - portal = Portal.createPortal(sign, player); - - if (portal != null && !regMsg.isEmpty()) { - player.sendMessage(ChatColor.GREEN + regMsg); - } - - if (portal == null) return; - log.info("Initialized stargate: " + portal.getName()); - portal.drawSign(true); - } - } + } // Implement right-click to toggle a stargate, gets around spawn protection problem. if ((block.getType() == Material.STONE_BUTTON)) { @@ -339,7 +354,20 @@ public class Stargate extends JavaPlugin implements Runnable { public void onBlockDamage(BlockDamageEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); - if (block.getType() != Material.WALL_SIGN && block.getType() != Material.OBSIDIAN && block.getType() != Material.STONE_BUTTON) { + // Check if we're pushing a button. + if (block.getType() == Material.STONE_BUTTON && event.getDamageLevel() == BlockDamageLevel.STOPPED) { + if (Stargate.Permissions.has(player, "stargate.use")) { + Portal portal = Portal.getByBlock(block); + if (portal != null) { + onButtonPressed(player, portal); + } + } + } + + // Drop out if we're not breaking a block + if (event.getDamageLevel() != BlockDamageLevel.BROKEN) return; + + if (block.getType() != Material.WALL_SIGN && block.getType() != Material.STONE_BUTTON && Gate.getGatesByControlBlock(block).length == 0) { return; } @@ -351,11 +379,9 @@ public class Stargate extends JavaPlugin implements Runnable { return; } - if (event.getDamageLevel() == BlockDamageLevel.BROKEN) { - portal.unregister(); - if (!dmgMsg.isEmpty()) { - player.sendMessage(ChatColor.RED + dmgMsg); - } + portal.unregister(); + if (!dmgMsg.isEmpty()) { + player.sendMessage(ChatColor.RED + dmgMsg); } } diff --git a/src/plugin.yml b/src/plugin.yml index e14a346..ec107d1 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.07 +version: 0.08 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net \ No newline at end of file