Fixes Stargate verification
This commit is contained in:
@@ -75,10 +75,10 @@ public class PortalCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Get necessary information from the gate's sign
|
//Get necessary information from the gate's sign
|
||||||
String portalName = PortalHandler.filterName(event.getLine(0));
|
@NotNull String portalName = PortalHandler.filterName(event.getLine(0));
|
||||||
String destinationName = PortalHandler.filterName(event.getLine(1));
|
@NotNull String destinationName = PortalHandler.filterName(event.getLine(1));
|
||||||
String network = PortalHandler.filterName(event.getLine(2));
|
@NotNull String network = PortalHandler.filterName(event.getLine(2));
|
||||||
String options = PortalHandler.filterName(event.getLine(3)).toLowerCase();
|
@NotNull String options = PortalHandler.filterName(event.getLine(3)).toLowerCase();
|
||||||
|
|
||||||
PortalStrings portalStrings = new PortalStrings(portalName, network, destinationName);
|
PortalStrings portalStrings = new PortalStrings(portalName, network, destinationName);
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ public class PortalCreator {
|
|||||||
* @return <p>The portal or null if its creation was denied</p>
|
* @return <p>The portal or null if its creation was denied</p>
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Portal validatePortal(@NotNull String denyMessage, String[] lines, boolean deny) {
|
public Portal validatePortal(@NotNull String denyMessage, @NotNull String[] lines, boolean deny) {
|
||||||
PortalLocation portalLocation = portal.getLocation();
|
PortalLocation portalLocation = portal.getLocation();
|
||||||
Gate gate = portal.getStructure().getGate();
|
Gate gate = portal.getStructure().getGate();
|
||||||
PortalOptions portalOptions = portal.getOptions();
|
PortalOptions portalOptions = portal.getOptions();
|
||||||
|
@@ -2,6 +2,7 @@ package net.knarcraft.stargate.portal;
|
|||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.Message;
|
||||||
|
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
import net.knarcraft.stargate.container.BlockLocation;
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||||
@@ -12,6 +13,7 @@ import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
|||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -218,7 +220,7 @@ public class PortalHandler {
|
|||||||
Portal origin = getByName(originName, portal.getCleanNetwork());
|
Portal origin = getByName(originName, portal.getCleanNetwork());
|
||||||
if (origin == null ||
|
if (origin == null ||
|
||||||
!Portal.cleanString(origin.getDestinationName()).equals(portal.getCleanName()) ||
|
!Portal.cleanString(origin.getDestinationName()).equals(portal.getCleanName()) ||
|
||||||
!origin.getStructure().isVerified()) {
|
!new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(origin.getLocation().getSignLocation().getType())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//Update sign of fixed gates pointing at this gate
|
//Update sign of fixed gates pointing at this gate
|
||||||
@@ -434,7 +436,18 @@ public class PortalHandler {
|
|||||||
for (Portal portal : PortalRegistry.getAllPortals()) {
|
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||||
//Try and verify the portal. Invalidate it if it cannot be validated
|
//Try and verify the portal. Invalidate it if it cannot be validated
|
||||||
PortalStructure structure = portal.getStructure();
|
PortalStructure structure = portal.getStructure();
|
||||||
if (!structure.wasVerified() && (!structure.isVerified() || !structure.checkIntegrity())) {
|
|
||||||
|
Stargate.debug("PortalHandler::verifyAllPortals", "Checking portal: " + portal.getName() + " | " + portal.getNetwork());
|
||||||
|
if (!portal.getOptions().hasNoSign() && !(new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(
|
||||||
|
portal.getLocation().getSignLocation().getType()))) {
|
||||||
|
Stargate.debug("PortalHandler::verifyAllPortals", "Stargate is missing its sign");
|
||||||
|
invalidPortals.add(portal);
|
||||||
|
} else if (!portal.getOptions().isAlwaysOn() && portal.getLocation().getButtonVector() != null &&
|
||||||
|
!MaterialHelper.isButtonCompatible(portal.getBlockAt(portal.getLocation().getButtonVector().addOut(1)).getType())) {
|
||||||
|
Stargate.debug("PortalHandler::verifyAllPortals", "Stargate is missing a valid button");
|
||||||
|
invalidPortals.add(portal);
|
||||||
|
} else if (!structure.checkIntegrity()) {
|
||||||
|
Stargate.debug("PortalHandler::verifyAllPortals", "Stargate's border or entrance has invalid blocks");
|
||||||
invalidPortals.add(portal);
|
invalidPortals.add(portal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -462,7 +475,7 @@ public class PortalHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PortalRegistry.unregisterPortal(portal, false);
|
PortalRegistry.unregisterPortal(portal, false);
|
||||||
Stargate.logInfo(String.format("Destroying stargate at %s", portal));
|
Stargate.logInfo(String.format("Disabled stargate at %s", portal));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package net.knarcraft.stargate.portal;
|
package net.knarcraft.stargate.portal;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
|
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
||||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
import net.knarcraft.stargate.container.BlockLocation;
|
||||||
import net.knarcraft.stargate.event.StargateCloseEvent;
|
import net.knarcraft.stargate.event.StargateCloseEvent;
|
||||||
@@ -10,6 +11,7 @@ import net.knarcraft.stargate.utility.ListHelper;
|
|||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
import org.bukkit.Axis;
|
import org.bukkit.Axis;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.block.data.Orientable;
|
import org.bukkit.block.data.Orientable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -144,8 +146,8 @@ public class PortalOpener {
|
|||||||
//Set the destination portal to this opener's portal
|
//Set the destination portal to this opener's portal
|
||||||
destination.getPortalActivator().setDestination(portal);
|
destination.getPortalActivator().setDestination(portal);
|
||||||
|
|
||||||
//Update the destination's sign if it's verified
|
//Update the destination's sign if it exists
|
||||||
if (destination.getStructure().isVerified()) {
|
if (new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(destination.getLocation().getSignLocation().getType())) {
|
||||||
destination.drawSign();
|
destination.drawSign();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,10 @@ package net.knarcraft.stargate.portal;
|
|||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.DynmapManager;
|
import net.knarcraft.stargate.config.DynmapManager;
|
||||||
|
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
import net.knarcraft.stargate.container.BlockLocation;
|
||||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||||
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -203,7 +205,7 @@ public class PortalRegistry {
|
|||||||
for (String originName : allPortalNetworks.get(networkName)) {
|
for (String originName : allPortalNetworks.get(networkName)) {
|
||||||
Portal origin = PortalHandler.getByName(originName, portal.getCleanNetwork());
|
Portal origin = PortalHandler.getByName(originName, portal.getCleanNetwork());
|
||||||
if (origin == null || !origin.getDestinationName().equalsIgnoreCase(portalName) ||
|
if (origin == null || !origin.getDestinationName().equalsIgnoreCase(portalName) ||
|
||||||
!origin.getStructure().isVerified()) {
|
!new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(origin.getLocation().getSignLocation().getType())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//Update the portal's sign
|
//Update the portal's sign
|
||||||
|
@@ -21,7 +21,6 @@ public class PortalStructure {
|
|||||||
private BlockLocation button;
|
private BlockLocation button;
|
||||||
private BlockLocation[] frame;
|
private BlockLocation[] frame;
|
||||||
private BlockLocation[] entrances;
|
private BlockLocation[] entrances;
|
||||||
private boolean verified;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new portal structure
|
* Instantiates a new portal structure
|
||||||
@@ -33,7 +32,6 @@ public class PortalStructure {
|
|||||||
public PortalStructure(@NotNull Portal portal, @NotNull Gate gate, @Nullable BlockLocation button) {
|
public PortalStructure(@NotNull Portal portal, @NotNull Gate gate, @Nullable BlockLocation button) {
|
||||||
this.portal = portal;
|
this.portal = portal;
|
||||||
this.gate = gate;
|
this.gate = gate;
|
||||||
this.verified = false;
|
|
||||||
this.button = button;
|
this.button = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,35 +64,6 @@ public class PortalStructure {
|
|||||||
this.button = button;
|
this.button = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that all control blocks in this portal follows its gate template
|
|
||||||
*
|
|
||||||
* @return <p>True if all control blocks were verified</p>
|
|
||||||
*/
|
|
||||||
public boolean isVerified() {
|
|
||||||
boolean verified = true;
|
|
||||||
if (!Stargate.getGateConfig().verifyPortals()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
for (RelativeBlockVector control : gate.getLayout().getControls()) {
|
|
||||||
verified = verified && gate.isValidControlBlock(portal.getBlockAt(control).getBlock().getType());
|
|
||||||
}
|
|
||||||
this.verified = verified;
|
|
||||||
return verified;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the result of the last portal verification
|
|
||||||
*
|
|
||||||
* @return <p>True if this portal was verified</p>
|
|
||||||
*/
|
|
||||||
public boolean wasVerified() {
|
|
||||||
if (!Stargate.getGateConfig().verifyPortals()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return verified;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if all blocks in a gate matches the gate template
|
* Checks if all blocks in a gate matches the gate template
|
||||||
*
|
*
|
||||||
|
@@ -88,16 +88,6 @@ public class Gate {
|
|||||||
return new HashMap<>(characterMaterialMap);
|
return new HashMap<>(characterMaterialMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the given material is valid for control blocks
|
|
||||||
*
|
|
||||||
* @param material <p>The material to check</p>
|
|
||||||
* @return <p>True if the material is valid for control blocks</p>
|
|
||||||
*/
|
|
||||||
public boolean isValidControlBlock(@NotNull Material material) {
|
|
||||||
return getControlBlockMaterials().contains(new BukkitMaterialSpecifier(material));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the material type used for this gate's control blocks
|
* Gets the material type used for this gate's control blocks
|
||||||
*
|
*
|
||||||
@@ -233,7 +223,7 @@ public class Gate {
|
|||||||
if (materialInLayout != null) {
|
if (materialInLayout != null) {
|
||||||
if (!MaterialHelper.specifiersToMaterials(materialInLayout).contains(materialAtLocation)) {
|
if (!MaterialHelper.specifiersToMaterials(materialInLayout).contains(materialAtLocation)) {
|
||||||
Stargate.debug("Gate::Matches", String.format("Block Type Mismatch: %s != %s",
|
Stargate.debug("Gate::Matches", String.format("Block Type Mismatch: %s != %s",
|
||||||
materialAtLocation, materialInLayout));
|
materialAtLocation, MaterialHelper.specifiersToMaterials(materialInLayout)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user