diff --git a/README.md b/README.md index b1d13c4..6062e71 100644 --- a/README.md +++ b/README.md @@ -255,7 +255,6 @@ gates: destroyedByExplosion - Whether to destroy a stargate with explosions, or stop an explosion if it contains a gates controls. verifyPortals - Whether or not all the non-sign blocks are checked to match the gate layout when an old stargate is loaded at startup. protectEntrance - If true, will protect from users breaking gate entrance blocks (This is more resource intensive than the usual check, and should only be enabled for servers that use solid open/close blocks) - ignoreEntranceSet this option to true to not check the entrance of a gate on startup. This is a workaround for snowmen breaking gates. functionality: enableBungee - Enable this for BungeeCord support. This allows portals across Bungee servers. handleVehicles - Whether or not to handle vehicles going through gates. Set to false to disallow vehicles (Manned or not) going through gates. @@ -349,6 +348,7 @@ bungeeSign=Teleport to - Comments all the code - Extracts portal options and portal-related locations to try and reduce size - Rewrites tons of code to make it more readable and manageable +- Implements proper snowman snow blocking, and removes the "temporary" ignoreEntrances option #### \[Version 0.8.0.3] PseudoKnight fork diff --git a/src/main/java/net/knarcraft/stargate/Stargate.java b/src/main/java/net/knarcraft/stargate/Stargate.java index a187dd1..1fea40c 100644 --- a/src/main/java/net/knarcraft/stargate/Stargate.java +++ b/src/main/java/net/knarcraft/stargate/Stargate.java @@ -68,8 +68,6 @@ public class Stargate extends JavaPlugin { public static boolean enableBungee = true; public static boolean verifyPortals = true; private static boolean destroyExplosion = false; - //Temp workaround for snowmen, don't check gate entrance - public static boolean ignoreEntrance = false; private String dataFolderPath; public static ChatColor signColor; @@ -453,7 +451,6 @@ public class Stargate extends JavaPlugin { //Integrity protectEntrance = newConfig.getBoolean("gates.integrity.protectEntrance"); verifyPortals = newConfig.getBoolean("gates.integrity.verifyPortals"); - ignoreEntrance = newConfig.getBoolean("gates.integrity.ignoreEntrance"); destroyExplosion = newConfig.getBoolean("gates.integrity.destroyedByExplosion"); //Cosmetic diff --git a/src/main/java/net/knarcraft/stargate/listener/BlockEventListener.java b/src/main/java/net/knarcraft/stargate/listener/BlockEventListener.java index 63fa088..56955ab 100644 --- a/src/main/java/net/knarcraft/stargate/listener/BlockEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/BlockEventListener.java @@ -12,6 +12,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.data.type.WallSign; import org.bukkit.entity.Player; +import org.bukkit.entity.Snowman; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -21,6 +22,7 @@ import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPistonEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.block.SignChangeEvent; import java.util.List; @@ -31,6 +33,26 @@ import java.util.List; @SuppressWarnings("unused") public class BlockEventListener implements Listener { + /** + * Detects snowmen ruining portals + * + * @param event

The triggered event

+ */ + @EventHandler + public void onBlockFormedByEntity(EntityBlockFormEvent event) { + if (event.isCancelled() || (!Stargate.protectEntrance && !Stargate.verifyPortals)) { + return; + } + //We are only interested in snowman events + if (!(event.getEntity() instanceof Snowman)) { + return; + } + //Cancel the event if a snowman is trying to place snow in the portal's entrance + if (PortalHandler.getByEntrance(event.getBlock()) != null) { + event.setCancelled(true); + } + } + /** * Detects sign changes to detect if the user is creating a new gate * @@ -66,7 +88,7 @@ public class BlockEventListener implements Listener { */ @EventHandler(priority = EventPriority.HIGHEST) public void onBlockBreak(BlockBreakEvent event) { - if (event.isCancelled()) { + if (event.isCancelled() || !Stargate.protectEntrance) { return; } Block block = event.getBlock(); @@ -74,7 +96,7 @@ public class BlockEventListener implements Listener { //Decide if a portal is broken Portal portal = PortalHandler.getByBlock(block); - if (portal == null && Stargate.protectEntrance) { + if (portal == null) { portal = PortalHandler.getByEntrance(block); } if (portal == null) { diff --git a/src/main/java/net/knarcraft/stargate/portal/Gate.java b/src/main/java/net/knarcraft/stargate/portal/Gate.java index e071b60..92145b4 100644 --- a/src/main/java/net/knarcraft/stargate/portal/Gate.java +++ b/src/main/java/net/knarcraft/stargate/portal/Gate.java @@ -214,16 +214,13 @@ public class Gate { * @return

Whether this is used in the context of creating a new gate

*/ private boolean verifyGateEntrancesMatch(BlockLocation topLeft, double yaw, boolean onCreate) { - if (Stargate.ignoreEntrance) { - return true; - } Stargate.debug("verifyGateEntrancesMatch", String.valueOf(topLeft)); for (RelativeBlockVector entranceVector : layout.getEntrances()) { Stargate.debug("verifyGateEntrancesMatch", String.valueOf(entranceVector)); Material type = getBlockAt(topLeft, entranceVector, yaw).getType(); - //Ignore entrance if it's air, and we're creating a new gate - if (onCreate && type == Material.AIR) { + //Ignore entrance if it's air or water, and we're creating a new gate + if (onCreate && (type == Material.AIR || type == Material.WATER)) { continue; } diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java index c11f5e1..3f9d947 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java @@ -52,6 +52,12 @@ public class PortalHandler { } + /** + * Gets names of all portals within a network + * + * @param network

The network to get portals from

+ * @return

A list of portal names

+ */ public static List getNetwork(String network) { return allPortalNetworks.get(network.toLowerCase()); } diff --git a/src/main/resources/config-migrations.txt b/src/main/resources/config-migrations.txt index eb53155..9326497 100644 --- a/src/main/resources/config-migrations.txt +++ b/src/main/resources/config-migrations.txt @@ -5,7 +5,8 @@ default-gate-network=gates.defaultGateNetwork destroyexplosion=gates.integrity.destroyedByExplosion maxgates=gates.maxGatesEachNetwork destMemory=gates.cosmetic.rememberDestination -ignoreEntrance=gates.integrity.ignoreEntrance +ignoreEntrance= +gates.integrity.ignoreEntrance= handleVehicles=gates.functionality.handleVehicles sortLists=gates.cosmetic.sortNetworkDestinations protectEntrance=gates.integrity.protectEntrance diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 22dd8a1..9c53803 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -8,7 +8,6 @@ # maxGatesEachNetwork - The maximum number of gates allowed on a network - 0 for unlimited # language - The language file to load for messages # rememberDestination - Whether to remember the cursor location between uses -# ignoreEntrance - Ignore the entrance blocks of a gate when checking. Used to work around snowmen # handleVehicles - Whether to allow vehicles through gates # sortNetworkDestinations - Whether to sort network lists alphabetically # protectEntrance - Whether to protect gate entrance material (More resource intensive. Only enable if using destroyable open/closed material) @@ -45,7 +44,6 @@ gates: destroyedByExplosion: false verifyPortals: false protectEntrance: false - ignoreEntrance: false functionality: enableBungee: false handleVehicles: true