Removes the temporary ignoreEntrances option and replaces it with proper snowman blocking. Fixes #3

Allows new gates to contain water as underwater gates are a thing now
Adds a check to prevent snowmen from placing snow inside a portal's entrance
Removes the ignoreEntrances option everywhere
This commit is contained in:
Kristian Knarvik 2021-10-09 15:09:14 +02:00
parent f87ffc906c
commit 051a6b8f98
7 changed files with 35 additions and 14 deletions

View File

@ -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

View File

@ -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

View File

@ -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 <p>The triggered event</p>
*/
@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) {

View File

@ -214,16 +214,13 @@ public class Gate {
* @return <p>Whether this is used in the context of creating a new gate</p>
*/
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;
}

View File

@ -52,6 +52,12 @@ public class PortalHandler {
}
/**
* Gets names of all portals within a network
*
* @param network <p>The network to get portals from</p>
* @return <p>A list of portal names</p>
*/
public static List<String> getNetwork(String network) {
return allPortalNetworks.get(network.toLowerCase());
}

View File

@ -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

View File

@ -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