From 5c34a21bf660302a69591389a7e3f1d1aae9650f Mon Sep 17 00:00:00 2001 From: Steven Scott Date: Sat, 7 Jan 2012 12:59:20 -0800 Subject: [PATCH] [Version 0.7.4.0] - Fixed issue with non-air closed portal blocks - Added StargatePortalEvent/onStargatePortal event --- README | 3 ++ src/net/TheDgtl/Stargate/Gate.java | 12 +++-- src/net/TheDgtl/Stargate/Portal.java | 21 +++++++- .../Stargate/event/StargateListener.java | 6 +++ .../Stargate/event/StargatePortalEvent.java | 52 +++++++++++++++++++ src/plugin.yml | 2 +- 6 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 src/net/TheDgtl/Stargate/event/StargatePortalEvent.java diff --git a/README b/README index 4b9b636..98fb877 100644 --- a/README +++ b/README @@ -198,6 +198,9 @@ createConflict=Gate conflicts with existing gate ============= Changes ============= +[Version 0.7.4.0] + - Fixed issue with non-air closed portal blocks + - Added StargatePortalEvent/onStargatePortal event [Version 0.7.3.3] - Added "ignoreEntrance" option to not check entrance to gate on integrity check (Workaround for snowmen until event is pulled) [Version 0.7.3.2] diff --git a/src/net/TheDgtl/Stargate/Gate.java b/src/net/TheDgtl/Stargate/Gate.java index 9a60d8a..d6f1433 100644 --- a/src/net/TheDgtl/Stargate/Gate.java +++ b/src/net/TheDgtl/Stargate/Gate.java @@ -216,12 +216,12 @@ public class Gate { public Boolean getToOwner() { return toOwner; } - - public boolean matches(Block topleft, int modX, int modZ) { - return matches(new Blox(topleft), modX, modZ); + + public boolean matches(Blox topleft, int modX, int modZ) { + return matches(topleft, modX, modZ, false); } - public boolean matches(Blox topleft, int modX, int modZ) { + public boolean matches(Blox topleft, int modX, int modZ, boolean onCreate) { for (int y = 0; y < layout.length; y++) { for (int x = 0; x < layout[y].length; x++) { int id = types.get(layout[y][x]); @@ -231,6 +231,10 @@ public class Gate { if (Stargate.ignoreEntrance) continue; int type = topleft.modRelative(x, y, 0, modX, 1, modZ).getType(); + + // Ignore entrance if it's air and we're creating a new gate + if (onCreate && type == Material.AIR.getId()) continue; + if (type != portalBlockClosed && type != portalBlockOpen) { // Special case for water gates if (portalBlockOpen == Material.WATER.getId() || portalBlockOpen == Material.STATIONARY_WATER.getId()) { diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index 207604e..41b52bb 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -13,6 +13,7 @@ import net.TheDgtl.Stargate.event.StargateActivateEvent; import net.TheDgtl.Stargate.event.StargateCloseEvent; import net.TheDgtl.Stargate.event.StargateDeactivateEvent; import net.TheDgtl.Stargate.event.StargateOpenEvent; +import net.TheDgtl.Stargate.event.StargatePortalEvent; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -326,6 +327,19 @@ public class Portal { // Handle backwards gates int adjust = isBackwards() ? 0 :180; exit.setYaw(origin.getRotation() - traveller.getYaw() + this.getRotation() + adjust); + + // Call the StargatePortalEvent to allow plugins to change destination + if (!origin.equals(this)) { + StargatePortalEvent pEvent = new StargatePortalEvent(player, origin, this, exit); + Stargate.server.getPluginManager().callEvent(pEvent); + // Teleport is cancelled + if (pEvent.isCancelled()) { + origin.teleport(player, origin, event); + return; + } + // Update exit if needed + exit = pEvent.getExit(); + } // The new method to teleport in a move event is set the "to" field. event.setTo(exit); @@ -755,7 +769,7 @@ public class Portal { Blox tl = parent.modRelative(-vector.getRight(), -vector.getDepth(), -vector.getDistance(), modX, 1, modZ); if (gate == null) { - if (possibility.matches(tl, modX, modZ)) { + if (possibility.matches(tl, modX, modZ, true)) { gate = possibility; topleft = tl; @@ -882,6 +896,11 @@ public class Portal { portal.open(true); dest.drawSign(); } + // Set the inside of the gate to its closed material + } else { + for (Blox inside : portal.getEntrances()) { + inside.setType(portal.getGate().getPortalBlockClosed()); + } } // Open any always on gate pointing at this gate diff --git a/src/net/TheDgtl/Stargate/event/StargateListener.java b/src/net/TheDgtl/Stargate/event/StargateListener.java index d09ea9a..b1b909e 100644 --- a/src/net/TheDgtl/Stargate/event/StargateListener.java +++ b/src/net/TheDgtl/Stargate/event/StargateListener.java @@ -25,6 +25,10 @@ public class StargateListener extends CustomEventListener implements Listener { } + public void onStargatePortal(StargatePortalEvent event) { + + } + @Override public void onCustomEvent(Event event) { if (event instanceof StargateOpenEvent) { @@ -35,6 +39,8 @@ public class StargateListener extends CustomEventListener implements Listener { onStargateActivate((StargateActivateEvent)event); } else if (event instanceof StargateDeactivateEvent) { onStargateDeactivate((StargateDeactivateEvent)event); + } else if (event instanceof StargatePortalEvent) { + onStargatePortal((StargatePortalEvent)event); } } } diff --git a/src/net/TheDgtl/Stargate/event/StargatePortalEvent.java b/src/net/TheDgtl/Stargate/event/StargatePortalEvent.java new file mode 100644 index 0000000..3d0c78c --- /dev/null +++ b/src/net/TheDgtl/Stargate/event/StargatePortalEvent.java @@ -0,0 +1,52 @@ +package net.TheDgtl.Stargate.event; + +import net.TheDgtl.Stargate.Portal; + +import org.bukkit.Location; +import org.bukkit.entity.Player; + +public class StargatePortalEvent extends StargateEvent { + private static final long serialVersionUID = -7263321536459960366L; + private Player player; + private Portal destination; + private Location exit; + + public StargatePortalEvent(Player player, Portal portal, Portal dest, Location exit) { + super ("StargatePortalEvent", portal); + + this.player = player; + this.destination = dest; + this.exit = exit; + } + + /** + * Return the player that went through the gate. + * @return player that went through the gate + */ + public Player getPlayer() { + return player; + } + + /** + * Return the destination gate + * @return destination gate + */ + public Portal getDestination() { + return destination; + } + + /** + * Return the location of the players exit point + * @return org.bukkit.Location Location of the exit point + */ + public Location getExit() { + return exit; + } + + /** + * Set the location of the players exit point + */ + public void setExit(Location loc) { + this.exit = loc; + } +} diff --git a/src/plugin.yml b/src/plugin.yml index 3c20aa5..fcebdd6 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.7.3.3 +version: 0.7.4.0 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net