From 432ab3bbc838af8d4d21fbe9ab9104b08db4ae3a Mon Sep 17 00:00:00 2001 From: Drakia Date: Sun, 13 Mar 2011 03:07:17 -0700 Subject: [PATCH] Fixed a bug with worlds in subfolders Fixed gates being destroyed with explosions Added stargate.destroy.owner --- README | 11 +++++-- src/net/TheDgtl/Stargate/Stargate.java | 43 +++++++++++++++++++++----- src/plugin.yml | 2 +- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/README b/README index 73c257f..089e82b 100644 --- a/README +++ b/README @@ -21,7 +21,9 @@ Known Issues ============= - stargate.use - Allow this player/group to use stargates. - stargate.create - Allow this player/group to create new stargates. - - stargate.destroy - Allow this player/group to destroy existing stargates. + - stargate.destroy - Allow this player/group to destroy existing stargates. (Deprecated) + - stargate.destroy.all - Allow this player/group to destroy any existing stargate (Replaces stargate.destroy) + - stargate.destroy.owner - Allow this player/group to destroy any stargate that they are the owner of. - stargate.hidden - Allow this player/group to see all hidden stargates. - stargate.private - Allow this player/group to use all private stargates. @@ -78,10 +80,15 @@ other-side-blocked-message - The message when the gate you're dialing is open teleport-message - The message when you are teleported portal-folder - The folder your portal databases are saved in gate-folder - The folder containing your .gate files - +destroyexplosion - Whether to destroy a stargate with explosions, or stop an explosion if it contains a gates controls. + ============= Changes ============= +[Version 0.25] + - Fixed a bug with worlds in subfolders + - Fixed gates being destroyed with explosions + - Added stargate.destroy.owner [Version 0.24] - Fixed a loading bug in which invalid gates caused file truncation [Version 0.23] diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index 3275de9..e1dfaca 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -23,6 +23,8 @@ 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.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityListener; import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.vehicle.VehicleListener; @@ -52,6 +54,7 @@ public class Stargate extends JavaPlugin { private final pListener playerListener = new pListener(); private final vListener vehicleListener = new vListener(); private final wListener worldListener = new wListener(); + private final eListener entityListener = new eListener(); public static Logger log; private Configuration config; private PluginManager pm; @@ -65,6 +68,7 @@ public class Stargate extends JavaPlugin { private static String invMsg = "Invalid Destination"; private static String blockMsg = "Destination Blocked"; private static String defNetwork = "central"; + private static boolean destroyExplosion = false; private static int activeLimit = 10; private static int openLimit = 10; @@ -115,6 +119,8 @@ public class Stargate extends JavaPlugin { pm.registerEvent(Event.Type.WORLD_LOADED, worldListener, Priority.Normal, this); + pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this); + getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L); } @@ -129,6 +135,7 @@ public class Stargate extends JavaPlugin { invMsg = config.getString("not-selected-message", invMsg); blockMsg = config.getString("other-side-blocked-message", blockMsg); defNetwork = config.getString("default-gate-network", defNetwork).trim(); + destroyExplosion = config.getBoolean("destroyexplosion", destroyExplosion); saveConfig(); } @@ -142,6 +149,7 @@ public class Stargate extends JavaPlugin { config.setProperty("not-selected-message", invMsg); config.setProperty("other-side-blocked-message", blockMsg); config.setProperty("default-gate-network", defNetwork); + config.setProperty("destroyexplosion", destroyExplosion); config.save(); } @@ -165,6 +173,7 @@ public class Stargate extends JavaPlugin { } File newFile = new File(portalFolder, getServer().getWorlds().get(0).getName() + ".db"); if (!newFile.exists()) { + newFile.getParentFile().mkdirs(); // Migrate not-so-old stargate db File oldishFile = new File("plugins/Stargate/stargate.db"); if (oldishFile.exists()) { @@ -417,15 +426,15 @@ public class Stargate extends JavaPlugin { Portal portal = Portal.getByBlock(block); if (portal == null) return; - if (!hasPerm(player, "stargate.destroy", player.isOp())) { - event.setCancelled(true); - return; - } - - portal.unregister(); - if (!dmgMsg.isEmpty()) { - player.sendMessage(ChatColor.RED + dmgMsg); + if (hasPerm(player, "stargate.destroy", player.isOp()) || hasPerm(player, "stargate.destroy.all", player.isOp()) || + ( portal.getOwner().equalsIgnoreCase(player.getName()) && hasPerm(player, "stargate.destroy.owner", false) )) { + portal.unregister(); + if (!dmgMsg.isEmpty()) { + player.sendMessage(ChatColor.RED + dmgMsg); + } } + + event.setCancelled(true); } @Override @@ -457,6 +466,24 @@ public class Stargate extends JavaPlugin { } } + private class eListener extends EntityListener { + @Override + public void onEntityExplode(EntityExplodeEvent event) { + if (event.isCancelled()) return; + for (Block b : event.blockList()) { + if (b.getTypeId() != Material.WALL_SIGN.getId() && b.getTypeId() != Material.STONE_BUTTON.getId()) continue; + Portal portal = Portal.getByBlock(b); + if (portal == null) continue; + if (destroyExplosion) { + portal.unregister(); + } else { + b.setType(b.getType()); + event.setCancelled(true); + } + } + } + } + private class SGThread implements Runnable { public void run() { long time = System.currentTimeMillis() / 1000; diff --git a/src/plugin.yml b/src/plugin.yml index 5bf7ccf..6af2702 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.24 +version: 0.25 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net \ No newline at end of file