Compare commits
1 Commits
dev
...
yml-storag
| Author | SHA1 | Date | |
|---|---|---|---|
| 0edb800cd3 |
@@ -20,13 +20,13 @@ import net.knarcraft.stargate.listener.PlayerEventListener;
|
||||
import net.knarcraft.stargate.listener.StargateBreakListener;
|
||||
import net.knarcraft.stargate.listener.StargateCreateDestroyListener;
|
||||
import net.knarcraft.stargate.listener.StargateTeleportListener;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.thread.BlockChangeThread;
|
||||
import net.knarcraft.stargate.thread.ChunkUnloadThread;
|
||||
import net.knarcraft.stargate.thread.ControlBlocksUpdateThread;
|
||||
import net.knarcraft.stargate.thread.StarGateThread;
|
||||
import net.knarcraft.stargate.utility.BStatsHelper;
|
||||
import net.knarcraft.stargate.utility.PortalUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@@ -336,7 +336,7 @@ public class Stargate extends ConfigCommentPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
PortalHandler.closeAllPortals();
|
||||
PortalUtil.closeAllPortals();
|
||||
PortalRegistry.clearPortals();
|
||||
if (stargateConfig != null) {
|
||||
stargateConfig.clearManagedWorlds();
|
||||
|
||||
@@ -15,7 +15,7 @@ public enum Permission {
|
||||
|
||||
SEE_HIDDEN("admin.hidden"),
|
||||
USE_PRIVATE("admin.private"),
|
||||
|
||||
|
||||
FREE_USAGE("free.use"),
|
||||
FREE_DESTRUCTION("free.destroy"),
|
||||
FREE_CREATION("free.create"),
|
||||
|
||||
@@ -12,12 +12,12 @@ import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
||||
import net.knarcraft.stargate.thread.BlockChangeThread;
|
||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import net.knarcraft.stargate.utility.PortalUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -284,7 +284,7 @@ public final class StargateConfig {
|
||||
}
|
||||
//Force all portals to close
|
||||
closeAllOpenPortals();
|
||||
PortalHandler.closeAllPortals();
|
||||
PortalUtil.closeAllPortals();
|
||||
|
||||
//Clear queues and lists
|
||||
activePortalsQueue.clear();
|
||||
|
||||
@@ -74,7 +74,7 @@ public final class DynmapManager {
|
||||
if (markerSet == null || Stargate.getStargateConfig().isDynmapDisabled()) {
|
||||
return;
|
||||
}
|
||||
World world = portal.getWorld();
|
||||
World world = portal.getLocation().getWorld();
|
||||
if (portal.getOptions().isHidden() || world == null) {
|
||||
return;
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public final class DynmapManager {
|
||||
Location location;
|
||||
@Nullable RelativeBlockVector exit = portal.getGate().getLayout().getExit();
|
||||
if (exit == null) {
|
||||
location = portal.getTopLeft();
|
||||
location = portal.getLocation().getTopLeft();
|
||||
} else {
|
||||
location = portal.getBlockAt(exit);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.knarcraft.stargate.container;
|
||||
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -10,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class BlockChangeRequest {
|
||||
|
||||
private final BlockLocation blockLocation;
|
||||
private final Block blockLocation;
|
||||
private final Material newMaterial;
|
||||
private final Axis newAxis;
|
||||
|
||||
@@ -21,7 +22,7 @@ public class BlockChangeRequest {
|
||||
* @param material <p>The new material to change the block to</p>
|
||||
* @param axis <p>The new axis to orient the block along</p>
|
||||
*/
|
||||
public BlockChangeRequest(@NotNull BlockLocation blockLocation, @NotNull Material material, @Nullable Axis axis) {
|
||||
public BlockChangeRequest(@NotNull Block blockLocation, @NotNull Material material, @Nullable Axis axis) {
|
||||
this.blockLocation = blockLocation;
|
||||
newMaterial = material;
|
||||
newAxis = axis;
|
||||
@@ -33,7 +34,7 @@ public class BlockChangeRequest {
|
||||
* @return <p>The location of the block</p>
|
||||
*/
|
||||
@NotNull
|
||||
public BlockLocation getBlockLocation() {
|
||||
public Block getBlockLocation() {
|
||||
return blockLocation;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.type.Sign;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -22,8 +18,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class BlockLocation extends Location {
|
||||
|
||||
private BlockLocation parent = null;
|
||||
|
||||
/**
|
||||
* Creates a new block location
|
||||
*
|
||||
@@ -148,50 +142,6 @@ public class BlockLocation extends Location {
|
||||
return this.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this block location's parent block
|
||||
*
|
||||
* <p>The parent block is the block the item at this block location is attached to. Usually this is the block a
|
||||
* sign or wall sign is attached to.</p>
|
||||
*
|
||||
* @return <p>This block location's parent block</p>
|
||||
*/
|
||||
@Nullable
|
||||
public Block getParent() {
|
||||
if (parent == null) {
|
||||
findParent();
|
||||
}
|
||||
if (parent == null) {
|
||||
return null;
|
||||
}
|
||||
return parent.getBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find the parent block location
|
||||
*
|
||||
* <p>If this block location is a sign, the parent is the block location of the block the sign is connected to.</p>
|
||||
*/
|
||||
private void findParent() {
|
||||
int offsetX = 0;
|
||||
int offsetY = 0;
|
||||
int offsetZ = 0;
|
||||
|
||||
BlockData blockData = getBlock().getBlockData();
|
||||
if (blockData instanceof Directional) {
|
||||
//Get the offset of the block "behind" this block
|
||||
BlockFace facing = ((Directional) blockData).getFacing().getOppositeFace();
|
||||
offsetX = facing.getModX();
|
||||
offsetZ = facing.getModZ();
|
||||
} else if (blockData instanceof Sign) {
|
||||
//Get offset the block beneath the sign
|
||||
offsetY = -1;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
parent = this.makeRelativeBlockLocation(offsetX, offsetY, offsetZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
|
||||
@@ -8,11 +8,11 @@ import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalActivator;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.PortalUtil;
|
||||
import net.knarcraft.stargate.utility.UUIDMigrationHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -70,7 +70,7 @@ public class PlayerEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Portal portal = PortalHandler.getBungeePortal(destination);
|
||||
Portal portal = PortalUtil.getBungeePortal(destination);
|
||||
if (portal == null) {
|
||||
Stargate.debug("PlayerJoin", "Error fetching destination portal: " + destination);
|
||||
return;
|
||||
@@ -115,7 +115,7 @@ public class PlayerEventListener implements Listener {
|
||||
*/
|
||||
private void handleSignClick(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull Block block,
|
||||
boolean leftClick) {
|
||||
Portal portal = PortalHandler.getByBlock(block);
|
||||
Portal portal = PortalUtil.getByBlock(block);
|
||||
if (portal == null) {
|
||||
return;
|
||||
}
|
||||
@@ -225,7 +225,7 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
|
||||
if (MaterialHelper.isButtonCompatible(block.getType())) {
|
||||
Portal portal = PortalHandler.getByBlock(block);
|
||||
Portal portal = PortalUtil.getByBlock(block);
|
||||
if (portal == null) {
|
||||
return;
|
||||
}
|
||||
@@ -261,7 +261,7 @@ public class PlayerEventListener implements Listener {
|
||||
* @param player <p>The player that clicked the block</p>
|
||||
*/
|
||||
private void displayPortalInfo(@NotNull Block block, @NotNull Player player) {
|
||||
Portal portal = PortalHandler.getByBlock(block);
|
||||
Portal portal = PortalUtil.getByBlock(block);
|
||||
if (portal == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.utility.PortalUtil;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
@@ -56,7 +56,7 @@ public class StargateBreakListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Block block = event.getBlock();
|
||||
Portal portal = PortalHandler.getByEntrance(block);
|
||||
Portal portal = PortalUtil.getByEntrance(block);
|
||||
if (portal != null) {
|
||||
//Prevent blocks from being placed in the entrance, if protectEntrance is enabled, as breaking the block
|
||||
// would destroy the portal
|
||||
@@ -75,7 +75,7 @@ public class StargateBreakListener implements Listener {
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onEntityExplode(@NotNull EntityExplodeEvent event) {
|
||||
for (Block block : event.blockList()) {
|
||||
Portal portal = PortalHandler.getByBlock(block);
|
||||
Portal portal = PortalUtil.getByBlock(block);
|
||||
if (portal == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class StargateBreakListener implements Listener {
|
||||
public void onCreatureSpawn(@NotNull CreatureSpawnEvent event) {
|
||||
//Prevent Zombified Piglins and other creatures form spawning at stargates
|
||||
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NETHER_PORTAL &&
|
||||
PortalHandler.getByEntrance(event.getLocation()) != null) {
|
||||
PortalUtil.getByEntrance(event.getLocation()) != null) {
|
||||
event.setCancelled(true);
|
||||
Stargate.debug("EntitySpawnListener", "Prevented creature from spawning at Stargate");
|
||||
}
|
||||
@@ -213,8 +213,8 @@ public class StargateBreakListener implements Listener {
|
||||
* @param block <p>The block in question</p>
|
||||
*/
|
||||
private boolean cancelIfAtEntrance(@NotNull Cancellable event, @NotNull Block block) {
|
||||
if (PortalHandler.getByEntrance(block) != null || PortalHandler.getByControl(block) != null ||
|
||||
PortalHandler.getByBlock(block) != null) {
|
||||
if (PortalUtil.getByEntrance(block) != null || PortalUtil.getByControl(block) != null ||
|
||||
PortalUtil.getByBlock(block) != null) {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -8,11 +8,11 @@ import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.event.StargateDestroyEvent;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalCreator;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import net.knarcraft.stargate.utility.PortalUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
@@ -51,8 +51,8 @@ public class StargateCreateDestroyListener implements Listener {
|
||||
|
||||
//Remove the sign if the no sign option is enabled
|
||||
if (portal.getOptions().hasNoSign()) {
|
||||
Material replaceMaterial = PortalFileHelper.decideRemovalMaterial(portal.getSignLocation(), portal);
|
||||
BlockChangeRequest request = new BlockChangeRequest(portal.getSignLocation(), replaceMaterial, null);
|
||||
Material replaceMaterial = PortalFileHelper.decideRemovalMaterial(portal.getLocation().getSignBlock(), portal);
|
||||
BlockChangeRequest request = new BlockChangeRequest(portal.getLocation().getSignBlock(), replaceMaterial, null);
|
||||
Stargate.addControlBlockUpdateRequest(request);
|
||||
}
|
||||
|
||||
@@ -73,9 +73,9 @@ public class StargateCreateDestroyListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
//Decide if a portal is broken
|
||||
Portal portal = PortalHandler.getByBlock(block);
|
||||
Portal portal = PortalUtil.getByBlock(block);
|
||||
if (portal == null && Stargate.getGateConfig().protectEntrance()) {
|
||||
portal = PortalHandler.getByEntrance(block);
|
||||
portal = PortalUtil.getByEntrance(block);
|
||||
}
|
||||
if (portal == null) {
|
||||
return;
|
||||
|
||||
@@ -6,7 +6,6 @@ import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.FromTheEndTeleportation;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||
@@ -14,6 +13,7 @@ import net.knarcraft.stargate.utility.EconomyHelper;
|
||||
import net.knarcraft.stargate.utility.EntityHelper;
|
||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.PortalUtil;
|
||||
import net.knarcraft.stargate.utility.TeleportHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -71,7 +71,7 @@ public class StargateTeleportListener implements Listener {
|
||||
if (!event.isCancelled() && (cause == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL ||
|
||||
cause == PlayerTeleportEvent.TeleportCause.END_GATEWAY ||
|
||||
cause == PlayerTeleportEvent.TeleportCause.END_PORTAL)
|
||||
&& PortalHandler.getByAdjacentEntrance(event.getFrom()) != null) {
|
||||
&& PortalUtil.getByAdjacentEntrance(event.getFrom()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public class StargateTeleportListener implements Listener {
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
//Cancel normal portal event is near a stargate
|
||||
if (PortalHandler.getByAdjacentEntrance(event.getFrom(), EntityHelper.getEntityMaxSizeInt(entity)) != null) {
|
||||
if (PortalUtil.getByAdjacentEntrance(event.getFrom(), EntityHelper.getEntityMaxSizeInt(entity)) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -110,9 +110,9 @@ public class StargateTeleportListener implements Listener {
|
||||
Portal entrancePortal;
|
||||
int entitySize = EntityHelper.getEntityMaxSizeInt(vehicle);
|
||||
if (EntityHelper.getEntityMaxSize(vehicle) > 1) {
|
||||
entrancePortal = PortalHandler.getByAdjacentEntrance(event.getTo(), entitySize - 1);
|
||||
entrancePortal = PortalUtil.getByAdjacentEntrance(event.getTo(), entitySize - 1);
|
||||
} else {
|
||||
entrancePortal = PortalHandler.getByEntrance(event.getTo());
|
||||
entrancePortal = PortalUtil.getByEntrance(event.getTo());
|
||||
}
|
||||
|
||||
//Return if the portal cannot be teleported through
|
||||
@@ -142,10 +142,10 @@ public class StargateTeleportListener implements Listener {
|
||||
if (!isRelevantMoveEvent(event, player, fromLocation, toLocation)) {
|
||||
return;
|
||||
}
|
||||
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
||||
Portal entrancePortal = PortalUtil.getByEntrance(toLocation);
|
||||
//Check an additional block away in case the portal is a bungee portal using END_PORTAL
|
||||
if (entrancePortal == null) {
|
||||
entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation);
|
||||
entrancePortal = PortalUtil.getByAdjacentEntrance(toLocation);
|
||||
// This should never realistically be null
|
||||
if (entrancePortal == null) {
|
||||
return;
|
||||
@@ -183,7 +183,7 @@ public class StargateTeleportListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Portal portal = PortalHandler.getByAdjacentEntrance(location);
|
||||
Portal portal = PortalUtil.getByAdjacentEntrance(location);
|
||||
if (portal == null) {
|
||||
return;
|
||||
}
|
||||
@@ -258,8 +258,8 @@ public class StargateTeleportListener implements Listener {
|
||||
Stargate.debug(route, "Unable to find portal destination");
|
||||
return;
|
||||
}
|
||||
Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " +
|
||||
destinationPortal.getSignLocation());
|
||||
Stargate.debug("vehicleTeleport", destinationPortal.getLocation().getWorld() + " " +
|
||||
destinationPortal.getLocation().getSignBlock());
|
||||
new VehicleTeleporter(destinationPortal, vehicle).teleportEntity(entrancePortal);
|
||||
}
|
||||
}
|
||||
@@ -461,14 +461,14 @@ public class StargateTeleportListener implements Listener {
|
||||
* @return <p>The portal the player entered, or null if no portal was entered</p>
|
||||
*/
|
||||
private Portal getEnteredPortal(@NotNull BlockLocation toLocation, @NotNull Player player) {
|
||||
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
||||
Portal entrancePortal = PortalUtil.getByEntrance(toLocation);
|
||||
// Return if in an entrance
|
||||
if (entrancePortal != null) {
|
||||
return entrancePortal;
|
||||
}
|
||||
|
||||
//Check an additional block away for special cases like BungeeCord portals using END_PORTAL as its material
|
||||
entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation);
|
||||
entrancePortal = PortalUtil.getByAdjacentEntrance(toLocation);
|
||||
if (entrancePortal == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||
import net.knarcraft.stargate.portal.property.PortalOption;
|
||||
import net.knarcraft.stargate.portal.property.PortalOptions;
|
||||
@@ -9,10 +7,8 @@ import net.knarcraft.stargate.portal.property.PortalOwner;
|
||||
import net.knarcraft.stargate.portal.property.PortalStrings;
|
||||
import net.knarcraft.stargate.portal.property.PortalStructure;
|
||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
||||
import net.knarcraft.stargate.utility.DirectionHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -28,7 +24,6 @@ public class Portal {
|
||||
private final String cleanName;
|
||||
private final String network;
|
||||
private final String cleanNetwork;
|
||||
private final SimpleVectorOperation vectorOperation;
|
||||
|
||||
private final PortalOwner portalOwner;
|
||||
private boolean isRegistered;
|
||||
@@ -50,7 +45,7 @@ public class Portal {
|
||||
* @param portalOwner <p>The portal's owner</p>
|
||||
* @param options <p>A map containing all possible portal options, with true for the ones enabled</p>
|
||||
*/
|
||||
public Portal(@NotNull PortalLocation portalLocation, @Nullable BlockLocation button,
|
||||
public Portal(@NotNull PortalLocation portalLocation, @Nullable Block button,
|
||||
@NotNull PortalStrings portalStrings, @NotNull Gate gate, @NotNull PortalOwner portalOwner,
|
||||
@NotNull Map<PortalOption, Boolean> options) {
|
||||
this.location = portalLocation;
|
||||
@@ -64,7 +59,6 @@ public class Portal {
|
||||
this.portalActivator = portalOpener.getPortalActivator();
|
||||
this.cleanName = cleanString(name);
|
||||
this.cleanNetwork = cleanString(network);
|
||||
this.vectorOperation = new SimpleVectorOperation(DirectionHelper.getBlockFaceFromYaw(portalLocation.getYaw()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,59 +261,6 @@ public class Portal {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the world this portal belongs to
|
||||
*
|
||||
* @return <p>The world this portal belongs to</p>
|
||||
*/
|
||||
@Nullable
|
||||
public World getWorld() {
|
||||
return location.getWorld();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location of this portal's sign
|
||||
*
|
||||
* @return <p>The location of this portal's sign</p>
|
||||
*/
|
||||
@NotNull
|
||||
public BlockLocation getSignLocation() {
|
||||
return this.location.getSignLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rotation (yaw) of this portal
|
||||
*
|
||||
* <p>The yaw is used to calculate all kinds of directions. See DirectionHelper to see how the yaw is used to
|
||||
* calculate to/from other direction types.</p>
|
||||
*
|
||||
* @return <p>The rotation (yaw) of this portal</p>
|
||||
*/
|
||||
public float getYaw() {
|
||||
return this.location.getYaw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location of the top-left block of the portal
|
||||
*
|
||||
* @return <p>The location of the top-left portal block</p>
|
||||
*/
|
||||
@NotNull
|
||||
public BlockLocation getTopLeft() {
|
||||
return this.location.getTopLeft();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block at the given location relative to this portal's top-left block
|
||||
*
|
||||
* @param vector <p>The relative block vector explaining the position of the block</p>
|
||||
* @return <p>The block at the given relative position</p>
|
||||
*/
|
||||
@NotNull
|
||||
public BlockLocation getBlockAt(@NotNull RelativeBlockVector vector) {
|
||||
return (BlockLocation) getTopLeft().clone().add(vectorOperation.performToRealSpaceOperation(vector.toVector()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans a string by removing color codes, lower-casing and replacing spaces with underscores
|
||||
*
|
||||
@@ -328,13 +269,14 @@ public class Portal {
|
||||
*/
|
||||
@NotNull
|
||||
public static String cleanString(@NotNull String string) {
|
||||
// TODO: Replace special characters such as : and .
|
||||
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', string)).toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
return String.format("Portal [id=%s, network=%s name=%s, type=%s]", getSignLocation(), network, name,
|
||||
return String.format("Portal [id=%s, network=%s name=%s, type=%s]", this.location.getSignBlock(), network, name,
|
||||
structure.getGate().getFilename());
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.event.StargateActivateEvent;
|
||||
import net.knarcraft.stargate.event.StargateDeactivateEvent;
|
||||
import net.knarcraft.stargate.utility.ListHelper;
|
||||
import net.knarcraft.stargate.utility.PortalUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -74,16 +75,16 @@ public class PortalActivator {
|
||||
String portalNetwork = portal.getCleanNetwork();
|
||||
if (portal.getOptions().isRandom()) {
|
||||
//Find possible destinations
|
||||
List<String> destinations = PortalHandler.getDestinations(portal, player, portalNetwork);
|
||||
List<String> destinations = PortalUtil.getDestinations(portal, player, portalNetwork);
|
||||
if (destinations.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
//Get one random destination
|
||||
String randomDestination = ListHelper.getRandom(destinations);
|
||||
return PortalHandler.getByName(randomDestination, portalNetwork);
|
||||
return PortalUtil.getByName(randomDestination, portalNetwork);
|
||||
} else {
|
||||
//Just return the normal fixed destination
|
||||
return PortalHandler.getByName(destination, portalNetwork);
|
||||
return PortalUtil.getByName(destination, portalNetwork);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +147,7 @@ public class PortalActivator {
|
||||
activePlayer = player;
|
||||
|
||||
String network = portal.getCleanNetwork();
|
||||
destinations = PortalHandler.getDestinations(portal, player, network);
|
||||
destinations = PortalUtil.getDestinations(portal, player, network);
|
||||
|
||||
//Sort destinations if enabled
|
||||
if (Stargate.getGateConfig().sortNetworkDestinations()) {
|
||||
@@ -250,7 +251,7 @@ public class PortalActivator {
|
||||
}
|
||||
activate = true;
|
||||
|
||||
List<String> portalsInNetwork = PortalHandler.getNetwork(portal.getCleanNetwork());
|
||||
List<String> portalsInNetwork = PortalUtil.getNetwork(portal.getCleanNetwork());
|
||||
if (portalsInNetwork != null) {
|
||||
Stargate.debug("cycleDestination", "Network Size: " + portalsInNetwork.size());
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package net.knarcraft.stargate.portal;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
import net.knarcraft.stargate.event.StargateCreateEvent;
|
||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||
import net.knarcraft.stargate.portal.property.PortalOption;
|
||||
@@ -19,11 +17,13 @@ import net.knarcraft.stargate.utility.ListHelper;
|
||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import net.knarcraft.stargate.utility.PortalUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -60,8 +60,8 @@ public class PortalCreator {
|
||||
@Nullable
|
||||
public Portal createPortal() {
|
||||
String route = "PortalCreator::createPortal";
|
||||
BlockLocation signLocation = new BlockLocation(event.getBlock());
|
||||
Block signControlBlock = signLocation.getParent();
|
||||
Block signLocation = event.getBlock();
|
||||
Block signControlBlock = DirectionHelper.getParent(signLocation);
|
||||
|
||||
//Return early if the sign is not placed on a block, or the block is not a control block
|
||||
if (signControlBlock == null || GateHandler.getGatesByControlBlock(signControlBlock).isEmpty()) {
|
||||
@@ -70,50 +70,51 @@ public class PortalCreator {
|
||||
}
|
||||
|
||||
//The control block is already part of another portal
|
||||
if (PortalHandler.getByBlock(signControlBlock) != null) {
|
||||
if (PortalUtil.getByBlock(signControlBlock) != null) {
|
||||
Stargate.debug(route, "idParent belongs to existing stargate");
|
||||
return null;
|
||||
}
|
||||
|
||||
//Get necessary information from the gate's sign
|
||||
@NotNull String portalName = PortalHandler.filterName(event.getLine(0));
|
||||
@NotNull String destinationName = PortalHandler.filterName(event.getLine(1));
|
||||
@NotNull String network = PortalHandler.filterName(event.getLine(2));
|
||||
@NotNull String options = PortalHandler.filterName(event.getLine(3)).toLowerCase();
|
||||
@NotNull String portalName = PortalUtil.filterName(event.getLine(0));
|
||||
@NotNull String destinationName = PortalUtil.filterName(event.getLine(1));
|
||||
@NotNull String network = PortalUtil.filterName(event.getLine(2));
|
||||
@NotNull String options = PortalUtil.filterName(event.getLine(3)).toLowerCase();
|
||||
|
||||
PortalStrings portalStrings = new PortalStrings(portalName, network, destinationName);
|
||||
|
||||
//Get portal options available to the player creating the portal
|
||||
Map<PortalOption, Boolean> portalOptions = PortalHandler.getPortalOptions(player, destinationName, options);
|
||||
Map<PortalOption, Boolean> portalOptions = PortalUtil.getPortalOptions(player, destinationName, options);
|
||||
|
||||
//Get the yaw
|
||||
float yaw = DirectionHelper.getYawFromLocationDifference(signControlBlock.getLocation(),
|
||||
signLocation.getLocation());
|
||||
|
||||
//Get the direction the button should be facing
|
||||
BlockFace buttonFacing = DirectionHelper.getBlockFaceFromYaw(yaw);
|
||||
|
||||
PortalLocation portalLocation = new PortalLocation();
|
||||
portalLocation.setButtonFacing(buttonFacing).setYaw(yaw).setSignLocation(signLocation);
|
||||
BlockFace facing = DirectionHelper.getFacing(signLocation);
|
||||
if (facing == null) {
|
||||
facing = DirectionHelper.getBlockFaceFromLocationDifference(signControlBlock.getLocation(),
|
||||
signLocation.getLocation());
|
||||
}
|
||||
|
||||
PortalLocation portalLocation = new PortalLocation(signLocation, facing);
|
||||
|
||||
Stargate.debug(route, "Finished getting all portal info");
|
||||
|
||||
return createPortal(portalStrings, portalOptions, yaw, portalLocation);
|
||||
return createPortal(portalStrings, portalOptions, portalLocation);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Portal createPortal(@NotNull PortalStrings portalStrings, @NotNull Map<PortalOption, Boolean> portalOptions,
|
||||
float yaw, @NotNull PortalLocation portalLocation) {
|
||||
@NotNull PortalLocation portalLocation) {
|
||||
String route = "PortalCreator::createPortal";
|
||||
//Try and find a gate matching the new portal
|
||||
Gate gate = PortalHandler.findMatchingGate(portalLocation, player.getWorld());
|
||||
if ((gate == null) || (portalLocation.getButtonVector() == null)) {
|
||||
Gate gate = PortalUtil.findMatchingGate(portalLocation);
|
||||
if ((gate == null) || (portalLocation.getButtonBlock() == null)) {
|
||||
Stargate.debug(route, "Could not find matching gate layout");
|
||||
return null;
|
||||
}
|
||||
|
||||
//If the portal is a bungee portal and invalid, abort here
|
||||
if (!PortalHandler.isValidBungeePortal(portalOptions, player, portalStrings.destination(),
|
||||
if (!PortalUtil.isValidBungeePortal(portalOptions, player, portalStrings.destination(),
|
||||
portalStrings.network())) {
|
||||
Stargate.debug(route, "Portal is an invalid bungee portal");
|
||||
return null;
|
||||
@@ -151,7 +152,7 @@ public class PortalCreator {
|
||||
}
|
||||
|
||||
//Check if a conflict exists
|
||||
if (conflictsWithExistingPortal(gate, portalLocation.getTopLeft(), yaw, player)) {
|
||||
if (conflictsWithExistingPortal(gate, portalLocation, player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -209,9 +210,9 @@ public class PortalCreator {
|
||||
|
||||
//Check if the user can create portals to this world.
|
||||
if (!bungee && !destinationName.isEmpty()) {
|
||||
Portal destinationPortal = PortalHandler.getByName(destinationName, network);
|
||||
if (destinationPortal != null && destinationPortal.getWorld() != null) {
|
||||
String world = destinationPortal.getWorld().getName();
|
||||
Portal destinationPortal = PortalUtil.getByName(destinationName, network);
|
||||
if (destinationPortal != null) {
|
||||
String world = destinationPortal.getLocation().getWorld().getName();
|
||||
if (PermissionHelper.cannotAccessWorld(player, world)) {
|
||||
Stargate.debug("PortalCreator::canCreatePortal", "Player does not have access to destination world");
|
||||
return new SGFormatBuilder(Message.CREATION_WORLD_DENIED).toString();
|
||||
@@ -265,21 +266,19 @@ public class PortalCreator {
|
||||
|
||||
//Add button if the portal is not always on
|
||||
if (!portalOptions.isAlwaysOn()) {
|
||||
PortalFileHelper.generatePortalButton(portal, portalLocation.getButtonFacing());
|
||||
PortalFileHelper.generatePortalButton(portal, portalLocation.getFacing());
|
||||
}
|
||||
|
||||
//Register the new portal
|
||||
PortalHandler.registerPortal(portal);
|
||||
PortalUtil.registerPortal(portal);
|
||||
updateNewPortalOpenState(destinationName);
|
||||
|
||||
//Update portals pointing at this one if it's not a bungee portal
|
||||
if (!portal.getOptions().isBungee()) {
|
||||
PortalHandler.updatePortalsPointingAtNewPortal(portal);
|
||||
PortalUtil.updatePortalsPointingAtNewPortal(portal);
|
||||
}
|
||||
|
||||
if (portal.getWorld() != null) {
|
||||
PortalFileHelper.saveAllPortals(portal.getWorld());
|
||||
}
|
||||
PortalFileHelper.saveAllPortals(portal.getLocation().getWorld());
|
||||
|
||||
return portal;
|
||||
}
|
||||
@@ -311,14 +310,14 @@ public class PortalCreator {
|
||||
}
|
||||
} else {
|
||||
//Check if the portal name has been duplicated on the network
|
||||
if (PortalHandler.getByName(portal.getCleanName(), portal.getCleanNetwork()) != null) {
|
||||
if (PortalUtil.getByName(portal.getCleanName(), portal.getCleanNetwork()) != null) {
|
||||
Stargate.debug(route, "Gate name duplicate");
|
||||
new SGFormatBuilder(Message.CREATION_NAME_COLLISION).error(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check if the number of portals in the network has been surpassed
|
||||
List<String> networkList = PortalHandler.getNetwork(portal.getCleanNetwork());
|
||||
List<String> networkList = PortalUtil.getNetwork(portal.getCleanNetwork());
|
||||
int maxGates = Stargate.getGateConfig().maxGatesEachNetwork();
|
||||
if (maxGates > 0 && networkList != null && networkList.size() >= maxGates) {
|
||||
new SGFormatBuilder(Message.CREATION_NETWORK_FULL).error(player);
|
||||
@@ -351,7 +350,7 @@ public class PortalCreator {
|
||||
portal.getPortalOpener().openPortal(true);
|
||||
} else if (portal.getOptions().isAlwaysOn()) {
|
||||
//For a normal always-on portal, open both the portal and the destination
|
||||
Portal destinationPortal = PortalHandler.getByName(destinationName, portal.getCleanNetwork());
|
||||
Portal destinationPortal = PortalUtil.getByName(destinationName, portal.getCleanNetwork());
|
||||
if (destinationPortal != null) {
|
||||
portal.getPortalOpener().openPortal(true);
|
||||
destinationPortal.drawSign();
|
||||
@@ -363,7 +362,7 @@ public class PortalCreator {
|
||||
portal.getGate().getPortalClosedMaterials()).stream().toList();
|
||||
Material closedType = ListHelper.getRandom(possibleMaterials);
|
||||
|
||||
for (BlockLocation entrance : portal.getStructure().getEntrances()) {
|
||||
for (Block entrance : portal.getStructure().getEntrances()) {
|
||||
entrance.setType(closedType);
|
||||
}
|
||||
}
|
||||
@@ -372,17 +371,16 @@ public class PortalCreator {
|
||||
/**
|
||||
* Checks whether the new portal conflicts with an existing portal
|
||||
*
|
||||
* @param gate <p>The gate type of the new portal</p>
|
||||
* @param topLeft <p>The top-left block of the new portal</p>
|
||||
* @param yaw <p>The yaw when looking directly outwards from the portal</p>
|
||||
* @param player <p>The player creating the new portal</p>
|
||||
* @param gate <p>The gate type of the new portal</p>
|
||||
* @param portalLocation <p>The location of the portal to check</p>
|
||||
* @param player <p>The player creating the new portal</p>
|
||||
* @return <p>True if a conflict was found. False otherwise</p>
|
||||
*/
|
||||
private static boolean conflictsWithExistingPortal(@NotNull Gate gate, @NotNull BlockLocation topLeft, double yaw,
|
||||
private static boolean conflictsWithExistingPortal(@NotNull Gate gate, @NotNull PortalLocation portalLocation,
|
||||
@NotNull Player player) {
|
||||
for (RelativeBlockVector borderVector : gate.getLayout().getBorder()) {
|
||||
BlockLocation borderBlockLocation = topLeft.getRelativeLocation(borderVector, yaw);
|
||||
if (PortalHandler.getByBlock(borderBlockLocation.getBlock()) != null) {
|
||||
for (BlockVector borderVector : gate.getLayout().getBorder()) {
|
||||
Block borderBlockLocation = portalLocation.getRelative(borderVector);
|
||||
if (PortalUtil.getByBlock(borderBlockLocation) != null) {
|
||||
Stargate.debug("PortalCreator::conflictsWithExistingPortal",
|
||||
"Gate conflicts with existing gate");
|
||||
new SGFormatBuilder(Message.CREATION_CONFLICT).error(player);
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.knarcraft.stargate.portal;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.event.StargateCloseEvent;
|
||||
import net.knarcraft.stargate.event.StargateOpenEvent;
|
||||
import net.knarcraft.stargate.portal.property.PortalOptions;
|
||||
@@ -12,6 +11,7 @@ import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Orientable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -98,10 +98,10 @@ public class PortalOpener {
|
||||
Material openType = ListHelper.getRandom(possibleMaterials);
|
||||
|
||||
//Adjust orientation if applicable
|
||||
Axis axis = (openType.createBlockData() instanceof Orientable) ? portal.getLocation().getRotationAxis() : null;
|
||||
Axis axis = (openType.createBlockData() instanceof Orientable) ? portal.getLocation().getVectorOperation().getNormalAxis() : null;
|
||||
|
||||
//Change the entrance blocks to the correct type
|
||||
for (BlockLocation inside : portal.getStructure().getEntrances()) {
|
||||
for (Block inside : portal.getStructure().getEntrances()) {
|
||||
Stargate.addControlBlockUpdateRequest(new BlockChangeRequest(inside, openType, axis));
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class PortalOpener {
|
||||
destination.getPortalActivator().setDestination(portal);
|
||||
|
||||
//Update the destination's sign if it exists
|
||||
if (new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(destination.getLocation().getSignLocation().getType())) {
|
||||
if (new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(destination.getLocation().getSignBlock().getType())) {
|
||||
destination.drawSign();
|
||||
}
|
||||
}
|
||||
@@ -182,9 +182,9 @@ public class PortalOpener {
|
||||
Material closedType = ListHelper.getRandom(possibleMaterials);
|
||||
|
||||
//Adjust orientation if applicable
|
||||
Axis axis = (closedType.createBlockData() instanceof Orientable) ? portal.getLocation().getRotationAxis() : null;
|
||||
Axis axis = (closedType.createBlockData() instanceof Orientable) ? portal.getLocation().getVectorOperation().getNormalAxis() : null;
|
||||
|
||||
for (BlockLocation entrance : portal.getStructure().getEntrances()) {
|
||||
for (Block entrance : portal.getStructure().getEntrances()) {
|
||||
Stargate.addControlBlockUpdateRequest(new BlockChangeRequest(entrance, closedType, axis));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,11 @@ package net.knarcraft.stargate.portal;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.addons.DynmapManager;
|
||||
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import net.knarcraft.stargate.utility.PortalUtil;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -20,9 +21,9 @@ import java.util.Map;
|
||||
*/
|
||||
public class PortalRegistry {
|
||||
|
||||
private static final Map<BlockLocation, Portal> lookupBlocks = new HashMap<>();
|
||||
private static final Map<BlockLocation, Portal> lookupEntrances = new HashMap<>();
|
||||
private static final Map<BlockLocation, Portal> lookupControls = new HashMap<>();
|
||||
private static final Map<Block, Portal> lookupBlocks = new HashMap<>();
|
||||
private static final Map<Block, Portal> lookupEntrances = new HashMap<>();
|
||||
private static final Map<Block, Portal> lookupControls = new HashMap<>();
|
||||
|
||||
private static final Map<String, Map<String, Portal>> portalLookupByNetwork = new HashMap<>();
|
||||
private static final Map<String, List<String>> allPortalNetworks = new HashMap<>();
|
||||
@@ -52,7 +53,7 @@ public class PortalRegistry {
|
||||
//Storing the portals to clear is necessary to avoid a concurrent modification exception
|
||||
List<Portal> portalsToRemove = new ArrayList<>();
|
||||
allPortals.forEach((portal) -> {
|
||||
if (portal.getWorld() != null && portal.getWorld().equals(world)) {
|
||||
if (portal.getLocation().getWorld().equals(world)) {
|
||||
portalsToRemove.add(portal);
|
||||
}
|
||||
});
|
||||
@@ -103,7 +104,7 @@ public class PortalRegistry {
|
||||
* @return <p>The portal the frame block belongs to, or null</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static Portal getPortalFromFrame(@NotNull BlockLocation blockLocation) {
|
||||
public static Portal getPortalFromFrame(@NotNull Block blockLocation) {
|
||||
return lookupBlocks.get(blockLocation);
|
||||
}
|
||||
|
||||
@@ -114,7 +115,7 @@ public class PortalRegistry {
|
||||
* @return <p>The portal the control block belongs to, or null</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static Portal getPortalFromControl(@NotNull BlockLocation blockLocation) {
|
||||
public static Portal getPortalFromControl(@NotNull Block blockLocation) {
|
||||
return lookupControls.get(blockLocation);
|
||||
}
|
||||
|
||||
@@ -141,7 +142,7 @@ public class PortalRegistry {
|
||||
* @return <p>A portal, or null</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static Portal getPortalFromEntrance(@NotNull BlockLocation blockLocation) {
|
||||
public static Portal getPortalFromEntrance(@NotNull Block blockLocation) {
|
||||
return lookupEntrances.get(blockLocation);
|
||||
}
|
||||
|
||||
@@ -203,9 +204,9 @@ public class PortalRegistry {
|
||||
|
||||
//Update all portals in the same network with this portal as its destination
|
||||
for (String originName : allPortalNetworks.get(networkName)) {
|
||||
Portal origin = PortalHandler.getByName(originName, portal.getCleanNetwork());
|
||||
Portal origin = PortalUtil.getByName(originName, portal.getCleanNetwork());
|
||||
if (origin == null || !origin.getDestinationName().equalsIgnoreCase(portalName) ||
|
||||
!new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(origin.getLocation().getSignLocation().getType())) {
|
||||
!new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(origin.getLocation().getSignBlock().getType())) {
|
||||
continue;
|
||||
}
|
||||
//Update the portal's sign
|
||||
@@ -222,9 +223,7 @@ public class PortalRegistry {
|
||||
//Mark the portal's sign as unregistered
|
||||
new PortalSignDrawer(portal).drawUnregisteredSign();
|
||||
|
||||
if (portal.getWorld() != null) {
|
||||
PortalFileHelper.saveAllPortals(portal.getWorld());
|
||||
}
|
||||
PortalFileHelper.saveAllPortals(portal.getLocation().getWorld());
|
||||
portal.setRegistered(false);
|
||||
DynmapManager.removePortalMarker(portal);
|
||||
}
|
||||
@@ -237,22 +236,22 @@ public class PortalRegistry {
|
||||
*/
|
||||
private static void clearLookupMaps(@NotNull Portal portal, boolean removeAll) {
|
||||
//Remove portal from lookup blocks
|
||||
for (BlockLocation block : portal.getStructure().getFrame()) {
|
||||
for (Block block : portal.getStructure().getFrame()) {
|
||||
lookupBlocks.remove(block);
|
||||
}
|
||||
|
||||
//Remove registered info about the lookup controls and blocks
|
||||
lookupBlocks.remove(portal.getSignLocation());
|
||||
lookupControls.remove(portal.getSignLocation());
|
||||
lookupBlocks.remove(portal.getLocation().getSignBlock());
|
||||
lookupControls.remove(portal.getLocation().getSignBlock());
|
||||
|
||||
BlockLocation button = portal.getStructure().getButton();
|
||||
Block button = portal.getStructure().getButton();
|
||||
if (button != null) {
|
||||
lookupBlocks.remove(button);
|
||||
lookupControls.remove(button);
|
||||
}
|
||||
|
||||
//Remove entrances
|
||||
for (BlockLocation entrance : portal.getStructure().getEntrances()) {
|
||||
for (Block entrance : portal.getStructure().getEntrances()) {
|
||||
lookupEntrances.remove(entrance);
|
||||
}
|
||||
|
||||
@@ -303,23 +302,23 @@ public class PortalRegistry {
|
||||
}
|
||||
|
||||
//Register all frame blocks to the lookup list
|
||||
for (BlockLocation block : portal.getStructure().getFrame()) {
|
||||
for (Block block : portal.getStructure().getFrame()) {
|
||||
lookupBlocks.put(block, portal);
|
||||
}
|
||||
//Register the sign and button to the lookup lists
|
||||
if (!portal.getOptions().hasNoSign()) {
|
||||
lookupBlocks.put(portal.getSignLocation(), portal);
|
||||
lookupControls.put(portal.getSignLocation(), portal);
|
||||
lookupBlocks.put(portal.getLocation().getSignBlock(), portal);
|
||||
lookupControls.put(portal.getLocation().getSignBlock(), portal);
|
||||
}
|
||||
|
||||
BlockLocation button = portal.getStructure().getButton();
|
||||
Block button = portal.getStructure().getButton();
|
||||
if (button != null) {
|
||||
lookupBlocks.put(button, portal);
|
||||
lookupControls.put(button, portal);
|
||||
}
|
||||
|
||||
//Register entrances to the lookup list
|
||||
for (BlockLocation entrance : portal.getStructure().getEntrances()) {
|
||||
for (Block entrance : portal.getStructure().getEntrances()) {
|
||||
lookupEntrances.put(entrance, portal);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.container.SignData;
|
||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.PortalUtil;
|
||||
import net.knarcraft.stargate.utility.SignHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@@ -130,7 +131,7 @@ public class PortalSignDrawer {
|
||||
*/
|
||||
@Nullable
|
||||
private Sign getSign() {
|
||||
Block signBlock = portal.getSignLocation().getBlock();
|
||||
Block signBlock = portal.getLocation().getSignBlock();
|
||||
BlockState state = signBlock.getState();
|
||||
if (!(state instanceof Sign sign)) {
|
||||
if (!portal.getOptions().hasNoSign()) {
|
||||
@@ -272,7 +273,7 @@ public class PortalSignDrawer {
|
||||
ChatColor highlightColor = signData.getHighlightSignColor();
|
||||
ChatColor mainColor = signData.getMainSignColor();
|
||||
if (freeGatesColored) {
|
||||
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||
Portal destination = PortalUtil.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||
boolean free = PermissionHelper.isFree(Objects.requireNonNull(portal.getActivePlayer()), portal, destination);
|
||||
ChatColor nameColor = (free ? freeColor : highlightColor);
|
||||
setLine(signData, signLineIndex, nameColor + ">" + (free ? freeColor : mainColor) +
|
||||
@@ -311,7 +312,7 @@ public class PortalSignDrawer {
|
||||
PortalActivator destinations = portal.getPortalActivator();
|
||||
String destinationName = destinations.getDestinations().get(destinationIndex);
|
||||
if (freeGatesColored) {
|
||||
Portal destination = PortalHandler.getByName(destinationName, portal.getNetwork());
|
||||
Portal destination = PortalUtil.getByName(destinationName, portal.getNetwork());
|
||||
boolean free = PermissionHelper.isFree(Objects.requireNonNull(portal.getActivePlayer()), portal, destination);
|
||||
setLine(signData, signLineIndex, (free ? freeColor : mainColor) + translateAllColorCodes(destinationName), output);
|
||||
} else {
|
||||
@@ -365,7 +366,7 @@ public class PortalSignDrawer {
|
||||
private void drawFixedSign(@NotNull SignData signData, @NotNull String[] output) {
|
||||
ChatColor highlightColor = signData.getHighlightSignColor();
|
||||
ChatColor mainColor = signData.getMainSignColor();
|
||||
Portal destinationPortal = PortalHandler.getByName(portal.getDestinationName(), portal.getCleanNetwork());
|
||||
Portal destinationPortal = PortalUtil.getByName(portal.getDestinationName(), portal.getCleanNetwork());
|
||||
String destinationName = portal.getOptions().isRandom() ? new SGFormatBuilder(Message.SIGN_RANDOM).toString() :
|
||||
(destinationPortal != null ? destinationPortal.getName() : portal.getDestinationName());
|
||||
setLine(signData, 1, highlightColor + ">" + mainColor + translateAllColorCodes(destinationName) +
|
||||
@@ -377,7 +378,7 @@ public class PortalSignDrawer {
|
||||
setLine(signData, 2, highlightColor + "(" + mainColor +
|
||||
translateAllColorCodes(portal.getNetwork()) + highlightColor + ")", output);
|
||||
}
|
||||
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||
Portal destination = PortalUtil.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||
if (destination == null && !portal.getOptions().isRandom()) {
|
||||
setLine(signData, 3, errorColor + new SGFormatBuilder(Message.SIGN_DISCONNECTED).toString(), output);
|
||||
} else {
|
||||
@@ -394,7 +395,7 @@ public class PortalSignDrawer {
|
||||
*/
|
||||
public static void markPortalWithInvalidGate(@NotNull PortalLocation portalLocation, @NotNull String gateName,
|
||||
int lineIndex) {
|
||||
BlockState blockState = portalLocation.getSignLocation().getBlock().getState();
|
||||
BlockState blockState = portalLocation.getSignBlock().getState();
|
||||
if (!(blockState instanceof Sign sign)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.knarcraft.stargate.portal.property;
|
||||
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
import org.bukkit.Axis;
|
||||
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -14,29 +14,61 @@ import org.jetbrains.annotations.Nullable;
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public class PortalLocation {
|
||||
|
||||
private BlockLocation topLeft;
|
||||
private float yaw;
|
||||
private BlockLocation signLocation;
|
||||
private RelativeBlockVector buttonVector;
|
||||
private BlockFace buttonFacing;
|
||||
private @Nullable Block topLeft;
|
||||
private @NotNull BlockFace facing;
|
||||
private @NotNull Block signBlock;
|
||||
private @Nullable Block buttonBlock;
|
||||
private final @NotNull World world;
|
||||
private final SimpleVectorOperation vectorOperation;
|
||||
|
||||
/**
|
||||
* Instantiates a new portal location
|
||||
*
|
||||
* @param topLeft <p>The top-left block of the portal</p>
|
||||
* @param facing <p>The direction the portal is facing</p>
|
||||
* @param signBlock <p>The block the sign is attached to</p>
|
||||
* @param buttonBlock <p>The block of the portal, or null if the portal doesn't need a button</p>
|
||||
*/
|
||||
public PortalLocation(@NotNull Block topLeft, @NotNull BlockFace facing, @NotNull Block signBlock,
|
||||
@Nullable Block buttonBlock) {
|
||||
this.world = topLeft.getWorld();
|
||||
this.topLeft = topLeft;
|
||||
this.facing = facing;
|
||||
this.signBlock = signBlock;
|
||||
this.buttonBlock = buttonBlock;
|
||||
this.vectorOperation = new SimpleVectorOperation(facing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new portal location
|
||||
*
|
||||
* @param signBlock <p>The block the sign is attached to</p>
|
||||
* @param facing <p>The direction the portal is facing</p>
|
||||
*/
|
||||
public PortalLocation(@NotNull Block signBlock, @NotNull BlockFace facing) {
|
||||
this.world = signBlock.getWorld();
|
||||
this.signBlock = signBlock;
|
||||
this.facing = facing;
|
||||
this.vectorOperation = new SimpleVectorOperation(facing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the top-left block of the portal
|
||||
*
|
||||
* @return <p>The top-left block of the portal</p>
|
||||
*/
|
||||
@NotNull
|
||||
public BlockLocation getTopLeft() {
|
||||
@Nullable
|
||||
public Block getTopLeft() {
|
||||
return topLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the yaw for looking outwards from the portal
|
||||
* Gets the block face the portal is facing towards
|
||||
*
|
||||
* @return <p>The portal's yaw</p>
|
||||
* @return <p>The portal's facing direction</p>
|
||||
*/
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
public BlockFace getFacing() {
|
||||
return facing;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,8 +77,8 @@ public class PortalLocation {
|
||||
* @return <p>The location of the portal's sign</p>
|
||||
*/
|
||||
@NotNull
|
||||
public BlockLocation getSignLocation() {
|
||||
return signLocation;
|
||||
public Block getSignBlock() {
|
||||
return signBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,30 +87,8 @@ public class PortalLocation {
|
||||
* @return <p>The relative location of the portal's button</p>
|
||||
*/
|
||||
@Nullable
|
||||
public RelativeBlockVector getButtonVector() {
|
||||
return buttonVector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block face determining the button's direction
|
||||
*
|
||||
* @return <p>The button's block face</p>
|
||||
*/
|
||||
@NotNull
|
||||
public BlockFace getButtonFacing() {
|
||||
return buttonFacing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rotation axis, which is the axis along which the gate is placed
|
||||
*
|
||||
* <p>The portal's rotation axis is the cross axis of the button's axis</p>
|
||||
*
|
||||
* @return <p>The portal's rotation axis</p>
|
||||
*/
|
||||
@NotNull
|
||||
public Axis getRotationAxis() {
|
||||
return getYaw() == 0.0F || getYaw() == 180.0F ? Axis.X : Axis.Z;
|
||||
public Block getButtonBlock() {
|
||||
return buttonBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,9 +96,19 @@ public class PortalLocation {
|
||||
*
|
||||
* @return <p>The world this portal resides in</p>
|
||||
*/
|
||||
@Nullable
|
||||
@NotNull
|
||||
public World getWorld() {
|
||||
return topLeft.getWorld();
|
||||
return this.world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vector operation to use in order to convert this portal's relative vectors to the real space
|
||||
*
|
||||
* @return <p>The vector operation</p>
|
||||
*/
|
||||
@NotNull
|
||||
public SimpleVectorOperation getVectorOperation() {
|
||||
return this.vectorOperation;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,59 +121,62 @@ public class PortalLocation {
|
||||
* @return <p>The portal location Object</p>
|
||||
*/
|
||||
@NotNull
|
||||
public PortalLocation setTopLeft(@NotNull BlockLocation topLeft) {
|
||||
public PortalLocation setTopLeft(@NotNull Block topLeft) {
|
||||
this.topLeft = topLeft;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the portal's yaw
|
||||
* Sets the portal's facing direction
|
||||
*
|
||||
* <p>The portal's yaw is the yaw a player would get when looking directly out from the portal</p>
|
||||
* <p>The portal's facing direction is the direction a player would get when looking directly out from the portal</p>
|
||||
*
|
||||
* @param yaw <p>The portal's new yaw</p>
|
||||
* @param facing <p>The portal's new facing direction</p>
|
||||
* @return <p>The portal location Object</p>
|
||||
*/
|
||||
@NotNull
|
||||
public PortalLocation setYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
public PortalLocation setFacing(@NotNull BlockFace facing) {
|
||||
this.facing = facing;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location of the portal's sign
|
||||
*
|
||||
* @param signLocation <p>The new sign location</p>
|
||||
* @param signBlock <p>The new sign location</p>
|
||||
* @return <p>The portal location Object</p>
|
||||
*/
|
||||
@NotNull
|
||||
public PortalLocation setSignLocation(@NotNull BlockLocation signLocation) {
|
||||
this.signLocation = signLocation;
|
||||
public PortalLocation setSignBlock(@NotNull Block signBlock) {
|
||||
this.signBlock = signBlock;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the relative location of the portal's button
|
||||
*
|
||||
* @param buttonVector <p>The new relative button location</p>
|
||||
* @param buttonBlock <p>The new relative button location</p>
|
||||
* @return <p>The portal location Object</p>
|
||||
*/
|
||||
@NotNull
|
||||
public PortalLocation setButtonVector(@Nullable RelativeBlockVector buttonVector) {
|
||||
this.buttonVector = buttonVector;
|
||||
public PortalLocation setButtonBlock(@Nullable Block buttonBlock) {
|
||||
this.buttonBlock = buttonBlock;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the block face for the direction the portal button is facing
|
||||
* Gets a block relative to this portal's top-left block
|
||||
*
|
||||
* @param buttonFacing <p>The new block face of the portal's button</p>
|
||||
* @return <p>The portal location Object</p>
|
||||
* @param vector <p>The relative vector pointing at the block</p>
|
||||
* @return <p>The block</p>
|
||||
* @throws IllegalStateException <p>If the top-left location is not set</p>
|
||||
*/
|
||||
@NotNull
|
||||
public PortalLocation setButtonFacing(@NotNull BlockFace buttonFacing) {
|
||||
this.buttonFacing = buttonFacing;
|
||||
return this;
|
||||
public Block getRelative(@NotNull BlockVector vector) throws IllegalStateException {
|
||||
if (this.topLeft == null) {
|
||||
throw new IllegalStateException("Top-left is not set");
|
||||
}
|
||||
return this.vectorOperation.getRealLocationBlock(this.topLeft, vector);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -194,4 +194,14 @@ public class PortalOptions {
|
||||
return this.options.get(PortalOption.INVISIBLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given portal option is true
|
||||
*
|
||||
* @param option <p>The option to check</p>
|
||||
* @return <p>True if enabled for the portal</p>
|
||||
*/
|
||||
public boolean checkOption(@NotNull PortalOption option) {
|
||||
return this.options.get(option);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.knarcraft.stargate.portal.property;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -18,9 +18,9 @@ public class PortalStructure {
|
||||
|
||||
private final Portal portal;
|
||||
private final Gate gate;
|
||||
private BlockLocation button;
|
||||
private BlockLocation[] frame;
|
||||
private BlockLocation[] entrances;
|
||||
private Block button;
|
||||
private Block[] frame;
|
||||
private Block[] entrances;
|
||||
|
||||
/**
|
||||
* Instantiates a new portal structure
|
||||
@@ -29,7 +29,7 @@ public class PortalStructure {
|
||||
* @param gate <p>The gate type used by this portal structure</p>
|
||||
* @param button <p>The real location of the portal's button</p>
|
||||
*/
|
||||
public PortalStructure(@NotNull Portal portal, @NotNull Gate gate, @Nullable BlockLocation button) {
|
||||
public PortalStructure(@NotNull Portal portal, @NotNull Gate gate, @Nullable Block button) {
|
||||
this.portal = portal;
|
||||
this.gate = gate;
|
||||
this.button = button;
|
||||
@@ -51,7 +51,7 @@ public class PortalStructure {
|
||||
* @return <p>The location of this portal's button</p>
|
||||
*/
|
||||
@Nullable
|
||||
public BlockLocation getButton() {
|
||||
public Block getButton() {
|
||||
return button;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class PortalStructure {
|
||||
*
|
||||
* @param button <p>The location of this portal's button</p>
|
||||
*/
|
||||
public void setButton(@NotNull BlockLocation button) {
|
||||
public void setButton(@NotNull Block button) {
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class PortalStructure {
|
||||
*/
|
||||
public boolean checkIntegrity() {
|
||||
if (Stargate.getGateConfig().verifyPortals()) {
|
||||
return gate.matches(portal.getTopLeft(), portal.getYaw());
|
||||
return gate.matches(portal.getLocation().getTopLeft(), portal.getLocation().getFacing());
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
@@ -87,10 +87,10 @@ public class PortalStructure {
|
||||
* @return <p>A list of block locations</p>
|
||||
*/
|
||||
@NotNull
|
||||
private BlockLocation[] relativeBlockVectorsToBlockLocations(@NotNull RelativeBlockVector[] vectors) {
|
||||
BlockLocation[] locations = new BlockLocation[vectors.length];
|
||||
private Block[] relativeBlockVectorsToBlockLocations(@NotNull BlockVector[] vectors) {
|
||||
Block[] locations = new Block[vectors.length];
|
||||
for (int i = 0; i < vectors.length; i++) {
|
||||
locations[i] = portal.getBlockAt(vectors[i]);
|
||||
locations[i] = portal.getLocation().getRelative(vectors[i]);
|
||||
}
|
||||
return locations;
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class PortalStructure {
|
||||
* @return <p>The locations of this portal's entrances</p>
|
||||
*/
|
||||
@NotNull
|
||||
public BlockLocation[] getEntrances() {
|
||||
public Block[] getEntrances() {
|
||||
if (entrances == null) {
|
||||
//Get the locations of the entrances once, and only if necessary as it's an expensive operation
|
||||
entrances = relativeBlockVectorsToBlockLocations(gate.getLayout().getEntrances());
|
||||
@@ -115,7 +115,7 @@ public class PortalStructure {
|
||||
* @return <p>The locations of this portal's frame</p>
|
||||
*/
|
||||
@NotNull
|
||||
public BlockLocation[] getFrame() {
|
||||
public Block[] getFrame() {
|
||||
if (frame == null) {
|
||||
//Get the locations of the frame blocks once, and only if necessary as it's an expensive operation
|
||||
frame = relativeBlockVectorsToBlockLocations(gate.getLayout().getBorder());
|
||||
|
||||
@@ -3,10 +3,12 @@ package net.knarcraft.stargate.portal.property.gate;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.material.BukkitMaterialSpecifier;
|
||||
import net.knarcraft.stargate.config.material.MaterialSpecifier;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -181,11 +183,11 @@ public class Gate {
|
||||
* Checks whether a portal's gate matches this gate type
|
||||
*
|
||||
* @param topLeft <p>The top-left block of the portal's gate</p>
|
||||
* @param yaw <p>The yaw when looking directly outwards</p>
|
||||
* @param facing <p>The direction the portal is facing</p>
|
||||
* @return <p>True if this gate matches the portal</p>
|
||||
*/
|
||||
public boolean matches(@NotNull BlockLocation topLeft, double yaw) {
|
||||
return matches(topLeft, yaw, false);
|
||||
public boolean matches(@NotNull Block topLeft, @NotNull BlockFace facing) {
|
||||
return matches(topLeft, facing, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,34 +198,34 @@ public class Gate {
|
||||
* containing AIR or WATER will cause the gate to not match.</p>
|
||||
*
|
||||
* @param topLeft <p>The top-left block of the portal's gate</p>
|
||||
* @param yaw <p>The yaw when looking directly outwards</p>
|
||||
* @param facing <p>The direction the portal is facing</p>
|
||||
* @param onCreate <p>Whether this is used in the context of creating a new gate</p>
|
||||
* @return <p>True if this gate matches the portal</p>
|
||||
*/
|
||||
public boolean matches(@NotNull BlockLocation topLeft, double yaw, boolean onCreate) {
|
||||
return verifyGateEntrancesMatch(topLeft, yaw, onCreate) && verifyGateBorderMatches(topLeft, yaw);
|
||||
public boolean matches(@NotNull Block topLeft, @NotNull BlockFace facing, boolean onCreate) {
|
||||
return verifyGateEntrancesMatch(topLeft, facing, onCreate) && verifyGateBorderMatches(topLeft, facing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that all border blocks of a portal matches this gate type
|
||||
*
|
||||
* @param topLeft <p>The top-left block of the portal</p>
|
||||
* @param yaw <p>The yaw when looking directly outwards from the portal</p>
|
||||
* @param topLeft <p>The top-left block of the portal's gate</p>
|
||||
* @param facing <p>The direction the portal is facing</p>
|
||||
* @return <p>True if all border blocks of the gate match the layout</p>
|
||||
*/
|
||||
private boolean verifyGateBorderMatches(@NotNull BlockLocation topLeft, double yaw) {
|
||||
for (RelativeBlockVector borderVector : layout.getBorder()) {
|
||||
int rowIndex = borderVector.right();
|
||||
int lineIndex = borderVector.down();
|
||||
private boolean verifyGateBorderMatches(@NotNull Block topLeft, @NotNull BlockFace facing) {
|
||||
for (BlockVector borderVector : layout.getBorder()) {
|
||||
int rowIndex = borderVector.getBlockX();
|
||||
int lineIndex = borderVector.getBlockY();
|
||||
Character key = layout.getLayout()[lineIndex][rowIndex];
|
||||
|
||||
List<MaterialSpecifier> materialInLayout = characterMaterialMap.get(key);
|
||||
Material materialAtLocation = topLeft.getRelativeLocation(borderVector, yaw).getType();
|
||||
Material type = new SimpleVectorOperation(facing).getRealLocationBlock(topLeft, borderVector).getType();
|
||||
|
||||
if (materialInLayout != null) {
|
||||
if (!MaterialHelper.specifiersToMaterials(materialInLayout).contains(materialAtLocation)) {
|
||||
if (!MaterialHelper.specifiersToMaterials(materialInLayout).contains(type)) {
|
||||
Stargate.debug("Gate::Matches", String.format("Block Type Mismatch: %s != %s",
|
||||
materialAtLocation, MaterialHelper.specifiersToMaterials(materialInLayout)));
|
||||
type, MaterialHelper.specifiersToMaterials(materialInLayout)));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -231,9 +233,9 @@ public class Gate {
|
||||
* recognized, but still allowed in previous checks, verify the gate as long as all such instances of
|
||||
* the character correspond to the same material in the physical gate. All subsequent gates will also
|
||||
* need to match the first verified gate. */
|
||||
this.characterMaterialMap.put(key, List.of(new BukkitMaterialSpecifier(materialAtLocation)));
|
||||
this.characterMaterialMap.put(key, List.of(new BukkitMaterialSpecifier(type)));
|
||||
Stargate.debug("Gate::Matches", String.format("Missing layout material in %s. Using %s from the" +
|
||||
" physical portal.", getFilename(), materialAtLocation));
|
||||
" physical portal.", getFilename(), type));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -242,16 +244,16 @@ public class Gate {
|
||||
/**
|
||||
* Verifies that all entrances of a portal gate matches this gate type
|
||||
*
|
||||
* @param topLeft <p>The top-left block of this portal</p>
|
||||
* @param yaw <p>The yaw when looking directly outwards</p>
|
||||
* @param topLeft <p>The top-left block of the portal's gate</p>
|
||||
* @param facing <p>The direction the portal is facing</p>
|
||||
* @param onCreate <p>Whether this is used in the context of creating a new gate</p>
|
||||
* @return <p>Whether this is used in the context of creating a new gate</p>
|
||||
*/
|
||||
private boolean verifyGateEntrancesMatch(@NotNull BlockLocation topLeft, double yaw, boolean onCreate) {
|
||||
private boolean verifyGateEntrancesMatch(@NotNull Block topLeft, @NotNull BlockFace facing, boolean onCreate) {
|
||||
Stargate.debug("verifyGateEntrancesMatch", String.valueOf(topLeft));
|
||||
for (RelativeBlockVector entranceVector : layout.getEntrances()) {
|
||||
for (BlockVector entranceVector : layout.getEntrances()) {
|
||||
Stargate.debug("verifyGateEntrancesMatch", String.valueOf(entranceVector));
|
||||
Material type = topLeft.getRelativeLocation(entranceVector, yaw).getType();
|
||||
Material type = new SimpleVectorOperation(facing).getRealLocationBlock(topLeft, entranceVector).getType();
|
||||
|
||||
//Ignore entrance if it's air or water, and we're creating a new gate
|
||||
if (onCreate && (type.isAir() || type == Material.WATER)) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.knarcraft.stargate.portal.property.gate;
|
||||
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -19,11 +19,11 @@ import java.util.List;
|
||||
public class GateLayout {
|
||||
|
||||
private final Character[][] layout;
|
||||
private final List<RelativeBlockVector> exits = new ArrayList<>();
|
||||
private RelativeBlockVector[] entrances = new RelativeBlockVector[0];
|
||||
private RelativeBlockVector[] border = new RelativeBlockVector[0];
|
||||
private RelativeBlockVector[] controls = new RelativeBlockVector[0];
|
||||
private RelativeBlockVector exitBlock = null;
|
||||
private final List<BlockVector> exits = new ArrayList<>();
|
||||
private BlockVector[] entrances = new BlockVector[0];
|
||||
private BlockVector[] border = new BlockVector[0];
|
||||
private BlockVector[] controls = new BlockVector[0];
|
||||
private BlockVector exitBlock = null;
|
||||
|
||||
/**
|
||||
* Instantiates a new gate layout
|
||||
@@ -53,7 +53,7 @@ public class GateLayout {
|
||||
* @return <p>The locations of entrances for this gate</p>
|
||||
*/
|
||||
@NotNull
|
||||
public RelativeBlockVector[] getEntrances() {
|
||||
public BlockVector[] getEntrances() {
|
||||
return entrances;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class GateLayout {
|
||||
* @return <p>The locations of border blocks for this gate</p>
|
||||
*/
|
||||
@NotNull
|
||||
public RelativeBlockVector[] getBorder() {
|
||||
public BlockVector[] getBorder() {
|
||||
return border;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class GateLayout {
|
||||
* @return <p>The exit block defined in the layout</p>
|
||||
*/
|
||||
@Nullable
|
||||
public RelativeBlockVector getExit() {
|
||||
public BlockVector getExit() {
|
||||
return exitBlock;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class GateLayout {
|
||||
* @return <p>All possible exits</p>
|
||||
*/
|
||||
@NotNull
|
||||
public List<RelativeBlockVector> getExits() {
|
||||
public List<BlockVector> getExits() {
|
||||
return exits;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class GateLayout {
|
||||
* @return <p>The locations of the control blocks for this gate</p>
|
||||
*/
|
||||
@NotNull
|
||||
public RelativeBlockVector[] getControls() {
|
||||
public BlockVector[] getControls() {
|
||||
return controls;
|
||||
}
|
||||
|
||||
@@ -127,9 +127,9 @@ public class GateLayout {
|
||||
* <p>This methods reads the layout and stores exits, entrances, border blocks and control blocks.</p>
|
||||
*/
|
||||
private void readLayout() {
|
||||
List<RelativeBlockVector> entranceList = new ArrayList<>();
|
||||
List<RelativeBlockVector> borderList = new ArrayList<>();
|
||||
List<RelativeBlockVector> controlList = new ArrayList<>();
|
||||
List<BlockVector> entranceList = new ArrayList<>();
|
||||
List<BlockVector> borderList = new ArrayList<>();
|
||||
List<BlockVector> controlList = new ArrayList<>();
|
||||
|
||||
readLayout(controlList, entranceList, borderList);
|
||||
|
||||
@@ -145,9 +145,9 @@ public class GateLayout {
|
||||
* @param entranceList <p>The list of entrances to save to</p>
|
||||
* @param borderList <p>The list of border blocks to save to</p>
|
||||
*/
|
||||
private void readLayout(@NotNull List<RelativeBlockVector> controlList,
|
||||
@NotNull List<RelativeBlockVector> entranceList,
|
||||
@NotNull List<RelativeBlockVector> borderList) {
|
||||
private void readLayout(@NotNull List<BlockVector> controlList,
|
||||
@NotNull List<BlockVector> entranceList,
|
||||
@NotNull List<BlockVector> borderList) {
|
||||
//Store the lowest opening for each column
|
||||
int[] exitDepths = new int[layout[0].length];
|
||||
|
||||
@@ -166,7 +166,7 @@ public class GateLayout {
|
||||
for (int x = 0; x < exitDepths.length; x++) {
|
||||
//Ignore invalid exits
|
||||
if (exitDepths[x] > 0) {
|
||||
this.exits.add(new RelativeBlockVector(x, exitDepths[x], 0));
|
||||
this.exits.add(new BlockVector(x, exitDepths[x], 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,26 +183,26 @@ public class GateLayout {
|
||||
* @param borderList <p>The list of border blocks to save to</p>
|
||||
*/
|
||||
private void parseLayoutCharacter(@NotNull Character key, int columnIndex, int rowIndex, int[] exitDepths,
|
||||
@NotNull List<RelativeBlockVector> controlList,
|
||||
@NotNull List<RelativeBlockVector> entranceList,
|
||||
@NotNull List<RelativeBlockVector> borderList) {
|
||||
@NotNull List<BlockVector> controlList,
|
||||
@NotNull List<BlockVector> entranceList,
|
||||
@NotNull List<BlockVector> borderList) {
|
||||
//Add control blocks to the control block list
|
||||
if (key.equals(GateHandler.getControlBlockCharacter())) {
|
||||
controlList.add(new RelativeBlockVector(columnIndex, rowIndex, 0));
|
||||
controlList.add(new BlockVector(columnIndex, rowIndex, 0));
|
||||
}
|
||||
|
||||
if (isOpening(key)) {
|
||||
//Register entrance
|
||||
entranceList.add(new RelativeBlockVector(columnIndex, rowIndex, 0));
|
||||
entranceList.add(new BlockVector(columnIndex, rowIndex, 0));
|
||||
//Overwrite the lowest exit location for this column/x-coordinate
|
||||
exitDepths[columnIndex] = rowIndex;
|
||||
//Register exit if found
|
||||
if (key.equals(GateHandler.getExitCharacter())) {
|
||||
this.exitBlock = new RelativeBlockVector(columnIndex, rowIndex, 0);
|
||||
this.exitBlock = new BlockVector(columnIndex, rowIndex, 0);
|
||||
}
|
||||
} else if (!key.equals(GateHandler.getAnythingCharacter())) {
|
||||
//Register border block
|
||||
borderList.add(new RelativeBlockVector(columnIndex, rowIndex, 0));
|
||||
borderList.add(new BlockVector(columnIndex, rowIndex, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PlayerTeleporter extends Teleporter {
|
||||
}
|
||||
|
||||
//Calculate the exit velocity of the player
|
||||
Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(portal.getYaw());
|
||||
Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(portal.getLocation().getYaw());
|
||||
Vector newVelocity = newVelocityDirection.multiply(velocity * Stargate.getGateConfig().getExitVelocity());
|
||||
|
||||
//Load chunks to make sure not to teleport to the void
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package net.knarcraft.stargate.portal.teleporter;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.ChunkUnloadRequest;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
import net.knarcraft.stargate.event.StargateTeleportEvent;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
||||
import net.knarcraft.stargate.utility.DirectionHelper;
|
||||
import net.knarcraft.stargate.utility.EntityHelper;
|
||||
import net.knarcraft.stargate.utility.TeleportHelper;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Slab;
|
||||
@@ -19,6 +21,7 @@ import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -132,7 +135,7 @@ public abstract class Teleporter {
|
||||
if (portal.getOptions().isBackwards()) {
|
||||
adjust = 180;
|
||||
}
|
||||
float newYaw = (portal.getYaw() + adjust) % 360;
|
||||
float newYaw = (portal.getLocation().getYaw() + adjust) % 360;
|
||||
Stargate.debug("Portal::adjustRotation", "Setting exit yaw to " + newYaw);
|
||||
exit.setDirection(DirectionHelper.getDirectionVectorFromYaw(newYaw));
|
||||
}
|
||||
@@ -174,7 +177,7 @@ public abstract class Teleporter {
|
||||
if (openingWidth > 1) {
|
||||
newOffset -= 0.5;
|
||||
}
|
||||
exitLocation = DirectionHelper.moveLocation(exitLocation, newOffset, 0, 0, portal.getYaw());
|
||||
exitLocation = DirectionHelper.moveLocation(exitLocation, newOffset, 0, 0, portal.getLocation().getYaw());
|
||||
|
||||
//Move large entities further from the portal
|
||||
return moveExitLocationOutwards(exitLocation, entity);
|
||||
@@ -203,7 +206,7 @@ public abstract class Teleporter {
|
||||
if (entity instanceof AbstractHorse) {
|
||||
entityOffset += 1;
|
||||
}
|
||||
exitLocation = DirectionHelper.moveLocation(exitLocation, 0, 0, entityOffset, portal.getYaw());
|
||||
exitLocation = DirectionHelper.moveLocation(exitLocation, 0, 0, entityOffset, portal.getLocation().getYaw());
|
||||
}
|
||||
return exitLocation;
|
||||
}
|
||||
@@ -269,17 +272,19 @@ public abstract class Teleporter {
|
||||
*/
|
||||
@NotNull
|
||||
private Location getExit(@NotNull Entity entity) {
|
||||
Location exitLocation = null;
|
||||
RelativeBlockVector relativeExit = portal.getGate().getLayout().getExit();
|
||||
Block exitLocation = null;
|
||||
BlockVector relativeExit = portal.getGate().getLayout().getExit();
|
||||
if (relativeExit != null) {
|
||||
BlockLocation exit = portal.getBlockAt(relativeExit);
|
||||
Block exit = portal.getBlockAt(relativeExit);
|
||||
|
||||
//Move one block out to prevent exiting inside the portal
|
||||
float portalYaw = portal.getYaw();
|
||||
BlockFace facing = portal.getLocation().getFacing();
|
||||
if (portal.getOptions().isBackwards()) {
|
||||
portalYaw += 180;
|
||||
facing = facing.getOppositeFace();
|
||||
}
|
||||
exitLocation = exit.getRelativeLocation(0D, 0D, 1, portalYaw);
|
||||
SimpleVectorOperation operation = new SimpleVectorOperation(facing);
|
||||
exitLocation = operation.getRealLocationBlock(portal.getLocation().getTopLeft(),
|
||||
new BlockVector(0, 0, 1));
|
||||
|
||||
double entitySize = EntityHelper.getEntityMaxSize(entity);
|
||||
//Prevent exit suffocation for players riding horses or similar
|
||||
@@ -305,8 +310,8 @@ public abstract class Teleporter {
|
||||
@NotNull
|
||||
private List<Chunk> getChunksToLoad() {
|
||||
List<Chunk> chunksToLoad = new ArrayList<>();
|
||||
for (RelativeBlockVector vector : portal.getGate().getLayout().getEntrances()) {
|
||||
BlockLocation entranceLocation = portal.getBlockAt(vector);
|
||||
for (BlockVector vector : portal.getGate().getLayout().getEntrances()) {
|
||||
Block entranceLocation = portal.getBlockAt(vector);
|
||||
Chunk chunk = entranceLocation.getChunk();
|
||||
//Make sure not to load chunks twice
|
||||
if (!chunksToLoad.contains(chunk)) {
|
||||
@@ -315,8 +320,7 @@ public abstract class Teleporter {
|
||||
|
||||
//Get the chunk in front of the gate entrance
|
||||
int blockOffset = portal.getOptions().isBackwards() ? -5 : 5;
|
||||
Location fiveBlocksForward = DirectionHelper.moveLocation(entranceLocation, 0, 0, blockOffset,
|
||||
portal.getYaw());
|
||||
Block fiveBlocksForward = entranceLocation.getRelative(portal.getLocation().getFacing(), blockOffset);
|
||||
//Load the chunk five blocks forward to make sure the teleported entity will never spawn in unloaded chunks
|
||||
Chunk forwardChunk = fiveBlocksForward.getChunk();
|
||||
if (!chunksToLoad.contains(forwardChunk)) {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class VehicleTeleporter extends EntityTeleporter {
|
||||
teleportingVehicle.setVelocity(new Vector());
|
||||
|
||||
//Get new velocity
|
||||
Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(portal.getYaw());
|
||||
Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(portal.getLocation().getYaw());
|
||||
Vector newVelocity = newVelocityDirection.multiply(velocity);
|
||||
|
||||
//Call the StargateEntityPortalEvent to allow plugins to change destination
|
||||
|
||||
@@ -2,13 +2,12 @@ package net.knarcraft.stargate.thread;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.ControlBlockUpdateRequest;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.utility.DirectionHelper;
|
||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
/**
|
||||
* This thread updates the signs and buttons of Stargates, if deemed necessary
|
||||
@@ -26,7 +25,7 @@ public class ControlBlocksUpdateThread implements Runnable {
|
||||
Portal portal = controlBlockUpdateRequest.portal();
|
||||
portal.drawSign();
|
||||
|
||||
BlockLocation buttonLocation = PortalFileHelper.getButtonLocation(portal);
|
||||
Block buttonLocation = portal.getLocation().getButtonBlock();
|
||||
if (buttonLocation == null) {
|
||||
return;
|
||||
}
|
||||
@@ -42,7 +41,7 @@ public class ControlBlocksUpdateThread implements Runnable {
|
||||
} else {
|
||||
//Replace button if the material is not a button
|
||||
if (!MaterialHelper.isButtonCompatible(buttonLocation.getType())) {
|
||||
PortalFileHelper.generatePortalButton(portal, DirectionHelper.getBlockFaceFromYaw(portal.getYaw()));
|
||||
PortalFileHelper.generatePortalButton(portal, portal.getLocation().getFacing());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.knarcraft.stargate.transformation;
|
||||
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -24,7 +25,7 @@ public class SimpleVectorOperation {
|
||||
private static final Axis defaultVerticalAxis = Axis.Y;
|
||||
|
||||
private final Axis normalAxis;
|
||||
private boolean flipZAxis = false;
|
||||
private boolean flipXAxis = false;
|
||||
private final BlockFace facing;
|
||||
|
||||
/**
|
||||
@@ -65,12 +66,12 @@ public class SimpleVectorOperation {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to flip the Z- axis
|
||||
* Sets whether to flip the X- axis
|
||||
*
|
||||
* @param flipZAxis <p>Whether to flip the z-axis</p>
|
||||
* @param flipXAxis <p>Whether to flip the X-axis</p>
|
||||
*/
|
||||
public void setFlipZAxis(boolean flipZAxis) {
|
||||
this.flipZAxis = flipZAxis;
|
||||
public void setFlipXAxis(boolean flipXAxis) {
|
||||
this.flipXAxis = flipXAxis;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,8 +84,8 @@ public class SimpleVectorOperation {
|
||||
public Vector performToAbstractSpaceOperation(@NotNull Vector vector) {
|
||||
Vector clone = vector.clone();
|
||||
clone.rotateAroundAxis(rotationAxes.get(facing), rotationAngles.get(facing));
|
||||
if (flipZAxis) {
|
||||
clone.setZ(-clone.getZ());
|
||||
if (flipXAxis) {
|
||||
clone.setX(-clone.getX());
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
@@ -98,8 +99,8 @@ public class SimpleVectorOperation {
|
||||
@NotNull
|
||||
public Vector performToRealSpaceOperation(@NotNull Vector vector) {
|
||||
Vector clone = vector.clone();
|
||||
if (flipZAxis) {
|
||||
clone.setZ(-clone.getZ());
|
||||
if (flipXAxis) {
|
||||
clone.setX(-clone.getX());
|
||||
}
|
||||
return clone.rotateAroundAxis(rotationAxes.get(facing), -rotationAngles.get(facing));
|
||||
}
|
||||
@@ -115,6 +116,28 @@ public class SimpleVectorOperation {
|
||||
return performToRealSpaceOperation((Vector) vector).toBlockVector();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block vector pointing to the real location of the relative block vector
|
||||
*
|
||||
* @param topLeft <p>The vector of the top-left portal block</p>
|
||||
* @param relative <p>The relative vector of a portal block</p>
|
||||
* @return <p>The vector for the true location of the block in the real space</p>
|
||||
*/
|
||||
public BlockVector getRealLocationVector(@NotNull BlockVector topLeft, @NotNull BlockVector relative) {
|
||||
return topLeft.clone().add(this.performToRealSpaceOperation(relative)).toBlockVector();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block pointing to the real location of the relative block vector
|
||||
*
|
||||
* @param topLeft <p>The top-left portal block</p>
|
||||
* @param relative <p>The relative vector of a portal block</p>
|
||||
* @return <p>The corresponding block</p>
|
||||
*/
|
||||
public Block getRealLocationBlock(@NotNull Block topLeft, @NotNull BlockVector relative) {
|
||||
return topLeft.getLocation().clone().add(this.performToRealSpaceOperation(relative)).getBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the operations used for rotating to each block-face
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.ConfigOption;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
@@ -40,7 +39,7 @@ public final class BStatsHelper {
|
||||
Metrics metrics = new Metrics(plugin, pluginId);
|
||||
|
||||
Map<ConfigOption, Object> configValues = Stargate.getStargateConfig().getConfigOptions();
|
||||
Map<String, List<String>> portalNetworks = PortalHandler.getAllPortalNetworks();
|
||||
Map<String, List<String>> portalNetworks = PortalUtil.getAllPortalNetworks();
|
||||
int totalPortals = 0;
|
||||
for (List<String> portals : portalNetworks.values()) {
|
||||
totalPortals += portals.size();
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
@@ -164,7 +163,7 @@ public final class BungeeHelper {
|
||||
if (player == null) {
|
||||
bungeeQueue.put(playerUUID, destination);
|
||||
} else {
|
||||
Portal destinationPortal = PortalHandler.getBungeePortal(destination);
|
||||
Portal destinationPortal = PortalUtil.getBungeePortal(destination);
|
||||
//If teleporting to an invalid portal, let the server decide where the player arrives
|
||||
if (destinationPortal == null) {
|
||||
Stargate.logInfo(String.format("Bungee portal %s does not exist", destination));
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.type.Sign;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This class helps with direction-related calculations
|
||||
@@ -14,6 +19,22 @@ public final class DirectionHelper {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the direction the given block is facing
|
||||
*
|
||||
* @param block <p>The block to get the direction of</p>
|
||||
* @return <p>The direction the block is facing, or null if the block is not directional</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static BlockFace getFacing(@NotNull Block block) {
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Directional directional) {
|
||||
return directional.getFacing();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a yaw by comparing two locations
|
||||
*
|
||||
@@ -39,6 +60,32 @@ public final class DirectionHelper {
|
||||
throw new IllegalArgumentException("Locations given are equal or at the same x and y axis");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a block face by comparing two locations
|
||||
*
|
||||
* <p>The block face here is the direction an observer at the from location has to look to face the to location.
|
||||
* The block face is only meant to be calculated for locations where both have either the same x value or the same
|
||||
* z value. Equal locations, or locations with equal x and equal z will throw an exception.</p>
|
||||
*
|
||||
* @param fromLocation <p>The origin location</p>
|
||||
* @param toLocation <p>The target location, which the block face will point towards</p>
|
||||
* @return <p>The yaw pointing from the first location to the second location</p>
|
||||
* @throws IllegalArgumentException <p>If the locations are the same, or equal except y</p>
|
||||
*/
|
||||
public static BlockFace getBlockFaceFromLocationDifference(@NotNull Location fromLocation, @NotNull Location toLocation) throws IllegalArgumentException {
|
||||
Location difference = fromLocation.clone().subtract(toLocation.clone());
|
||||
if (difference.getX() > 0) {
|
||||
return BlockFace.WEST;
|
||||
} else if (difference.getX() < 0) {
|
||||
return BlockFace.EAST;
|
||||
} else if (difference.getZ() > 0) {
|
||||
return BlockFace.NORTH;
|
||||
} else if (difference.getZ() < 0) {
|
||||
return BlockFace.SOUTH;
|
||||
}
|
||||
throw new IllegalArgumentException("Locations given are equal or at the same x and y axis");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a block face given a yaw value
|
||||
*
|
||||
@@ -66,6 +113,23 @@ public final class DirectionHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a yaw from the specified block face
|
||||
*
|
||||
* @param blockFace <p>The block face to convert into a yaw</p>
|
||||
* @return <p>The yaw of the block face</p>
|
||||
* @throws IllegalArgumentException <p>If the block face is not pointing to one of the four primary directions</p>
|
||||
*/
|
||||
public static double getYawFromBlockFace(@NotNull BlockFace blockFace) throws IllegalArgumentException {
|
||||
return switch (blockFace) {
|
||||
case SOUTH -> 0;
|
||||
case WEST -> 90;
|
||||
case NORTH -> 180;
|
||||
case EAST -> 270;
|
||||
default -> throw new IllegalArgumentException("Invalid block face given. It must be one of N,S,W,E");
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a direction vector given a yaw
|
||||
*
|
||||
@@ -142,6 +206,36 @@ public final class DirectionHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this block location's parent block
|
||||
*
|
||||
* <p>The parent block is the block the item at this block location is attached to. Usually this is the block a
|
||||
* sign or wall sign is attached to.</p>
|
||||
*
|
||||
* @return <p>This block location's parent block</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static Block getParent(@NotNull Block block) {
|
||||
int offsetX = 0;
|
||||
int offsetY = 0;
|
||||
int offsetZ = 0;
|
||||
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Directional) {
|
||||
//Get the offset of the block "behind" this block
|
||||
BlockFace facing = ((Directional) blockData).getFacing().getOppositeFace();
|
||||
offsetX = facing.getModX();
|
||||
offsetZ = facing.getModZ();
|
||||
} else if (blockData instanceof Sign) {
|
||||
//Get offset the block beneath the sign
|
||||
offsetY = -1;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return block.getRelative(offsetX, offsetY, offsetZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a yaw to make it positive and no larger than 360 degrees
|
||||
*
|
||||
|
||||
@@ -145,8 +145,7 @@ public final class PermissionHelper {
|
||||
//If there is no destination, deny
|
||||
Stargate.debug(route, "Portal has no destination");
|
||||
deny = true;
|
||||
} else if (destination.getWorld() != null &&
|
||||
PermissionHelper.cannotAccessWorld(player, destination.getWorld().getName())) {
|
||||
} else if (PermissionHelper.cannotAccessWorld(player, destination.getLocation().getWorld().getName())) {
|
||||
//If the player does not have access to the portal's world, deny
|
||||
Stargate.debug(route, "Cannot access world");
|
||||
deny = true;
|
||||
|
||||
@@ -2,11 +2,8 @@ package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.ControlBlockUpdateRequest;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||
import net.knarcraft.stargate.portal.property.PortalOptions;
|
||||
@@ -14,16 +11,19 @@ import net.knarcraft.stargate.portal.property.PortalOwner;
|
||||
import net.knarcraft.stargate.portal.property.PortalStrings;
|
||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
||||
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@@ -57,17 +57,12 @@ public final class PortalFileHelper {
|
||||
|
||||
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||
//Skip portals in other worlds
|
||||
if (portal.getWorld() == null) {
|
||||
Stargate.logSevere(String.format("Could not save portal %s because its world is null",
|
||||
portal.getName()));
|
||||
} else {
|
||||
String worldName = portal.getWorld().getName();
|
||||
if (!worldName.equalsIgnoreCase(world.getName())) {
|
||||
continue;
|
||||
}
|
||||
//Save the portal
|
||||
savePortal(bufferedWriter, portal);
|
||||
String worldName = portal.getLocation().getWorld().getName();
|
||||
if (!worldName.equalsIgnoreCase(world.getName())) {
|
||||
continue;
|
||||
}
|
||||
//Save the portal
|
||||
savePortal(bufferedWriter, portal);
|
||||
}
|
||||
|
||||
bufferedWriter.close();
|
||||
@@ -85,19 +80,19 @@ public final class PortalFileHelper {
|
||||
*/
|
||||
private static void savePortal(@NotNull BufferedWriter bufferedWriter, @NotNull Portal portal) throws IOException {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
BlockLocation button = portal.getStructure().getButton();
|
||||
Block button = portal.getStructure().getButton();
|
||||
|
||||
//WARNING: Because of the primitive save format, any change in order will break everything!
|
||||
builder.append(portal.getName()).append(':');
|
||||
builder.append(portal.getSignLocation()).append(':');
|
||||
builder.append(portal.getLocation().getSignBlock()).append(':');
|
||||
builder.append((button != null) ? button.toString() : "").append(':');
|
||||
|
||||
//Add removes config values to keep indices consistent
|
||||
builder.append(0).append(':');
|
||||
builder.append(0).append(':');
|
||||
|
||||
builder.append(portal.getYaw()).append(':');
|
||||
builder.append(portal.getTopLeft()).append(':');
|
||||
builder.append(DirectionHelper.getYawFromBlockFace(portal.getLocation().getFacing())).append(':');
|
||||
builder.append(portal.getLocation().getTopLeft()).append(':');
|
||||
builder.append(portal.getGate().getFilename()).append(':');
|
||||
|
||||
//Only save the destination name if the gate is fixed as it doesn't matter otherwise
|
||||
@@ -127,11 +122,7 @@ public final class PortalFileHelper {
|
||||
builder.append(options.isHidden()).append(':');
|
||||
builder.append(options.isAlwaysOn()).append(':');
|
||||
builder.append(options.isPrivate()).append(':');
|
||||
if (portal.getWorld() != null) {
|
||||
builder.append(portal.getWorld().getName()).append(':');
|
||||
} else {
|
||||
builder.append(':');
|
||||
}
|
||||
builder.append(portal.getLocation().getWorld().getName()).append(':');
|
||||
builder.append(options.isFree()).append(':');
|
||||
builder.append(options.isBackwards()).append(':');
|
||||
builder.append(options.isShown()).append(':');
|
||||
@@ -229,9 +220,9 @@ public final class PortalFileHelper {
|
||||
*/
|
||||
private static void doPostLoadTasks(@NotNull World world, boolean needsToSaveDatabase) {
|
||||
//Open any always-on portals. Do this here as it should be more efficient than in the loop.
|
||||
PortalHandler.verifyAllPortals();
|
||||
PortalUtil.verifyAllPortals();
|
||||
int portalCount = PortalRegistry.getAllPortals().size();
|
||||
int openCount = PortalHandler.openAlwaysOpenPortals();
|
||||
int openCount = PortalUtil.openAlwaysOpenPortals();
|
||||
|
||||
//Print info about loaded stargates so that admins can see if all stargates loaded
|
||||
Stargate.logInfo(String.format("{%s} Loaded %d stargates with %d set as always-on", world.getName(),
|
||||
@@ -242,8 +233,8 @@ public final class PortalFileHelper {
|
||||
Stargate.debug("PortalFileHelper::doPostLoadTasks::update",
|
||||
String.format("Queueing portal sign/button updates for %s", world));
|
||||
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||
if (portal.isRegistered() && portal.getWorld() != null && portal.getWorld().equals(world) &&
|
||||
world.getWorldBorder().isInside(portal.getSignLocation())) {
|
||||
if (portal.isRegistered() && portal.getLocation().getWorld().equals(world) &&
|
||||
world.getWorldBorder().isInside(portal.getLocation().getSignBlock().getLocation())) {
|
||||
Stargate.addControlBlockUpdateRequest(new ControlBlockUpdateRequest(portal));
|
||||
Stargate.debug("UpdateSignsButtons", String.format("Queued sign and button updates for portal %s",
|
||||
portal.getName()));
|
||||
@@ -267,13 +258,13 @@ public final class PortalFileHelper {
|
||||
private static boolean loadPortal(@NotNull String[] portalData, @NotNull World world, int lineIndex) {
|
||||
//Load min. required portal data
|
||||
String name = portalData[0];
|
||||
BlockLocation button = (!portalData[2].isEmpty()) ? new BlockLocation(world, portalData[2]) : null;
|
||||
Block button = (!portalData[2].isEmpty()) ? getBlock(world, portalData[2]) : null;
|
||||
|
||||
//Load the portal's location
|
||||
PortalLocation portalLocation = new PortalLocation();
|
||||
portalLocation.setSignLocation(new BlockLocation(world, portalData[1]));
|
||||
portalLocation.setYaw(Float.parseFloat(portalData[5]));
|
||||
portalLocation.setTopLeft(new BlockLocation(world, portalData[6]));
|
||||
|
||||
|
||||
PortalLocation portalLocation = new PortalLocation(getBlock(world, portalData[6]),
|
||||
DirectionHelper.getBlockFaceFromYaw(Float.parseFloat(portalData[5])), getBlock(world, portalData[1]), button);
|
||||
|
||||
//Check if the portal's gate type exists and is loaded
|
||||
Gate gate = GateHandler.getGateByName(portalData[7]);
|
||||
@@ -295,11 +286,11 @@ public final class PortalFileHelper {
|
||||
//Create the new portal
|
||||
PortalStrings portalStrings = new PortalStrings(name, network, destination);
|
||||
Portal portal = new Portal(portalLocation, button, portalStrings, gate, owner,
|
||||
PortalHandler.getPortalOptions(portalData));
|
||||
PortalUtil.getPortalOptions(portalData));
|
||||
|
||||
//Register the portal, and close it in case it wasn't properly closed when the server stopped
|
||||
boolean buttonLocationChanged = updateButtonVector(portal);
|
||||
PortalHandler.registerPortal(portal);
|
||||
PortalUtil.registerPortal(portal);
|
||||
portal.getPortalOpener().closePortal(true);
|
||||
return buttonLocationChanged;
|
||||
}
|
||||
@@ -307,15 +298,16 @@ public final class PortalFileHelper {
|
||||
/**
|
||||
* Decides the material to use for removing a portal's button/sign
|
||||
*
|
||||
* @param location <p>The location of the button/sign to replace</p>
|
||||
* @param portal <p>The portal the button/sign belongs to</p>
|
||||
* @param block <p>The location of the button/sign to replace</p>
|
||||
* @param portal <p>The portal the button/sign belongs to</p>
|
||||
* @return <p>The material to use for removing the button/sign</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static Material decideRemovalMaterial(@NotNull BlockLocation location, @NotNull Portal portal) {
|
||||
public static Material decideRemovalMaterial(@NotNull Block block, @NotNull Portal portal) {
|
||||
//Get the blocks to each side of the location
|
||||
Location leftLocation = location.getRelativeLocation(-1, 0, 0, portal.getYaw());
|
||||
Location rightLocation = location.getRelativeLocation(1, 0, 0, portal.getYaw());
|
||||
SimpleVectorOperation vectorOperation = portal.getLocation().getVectorOperation();
|
||||
Location leftLocation = block.getLocation().clone().add(vectorOperation.performToRealSpaceOperation(new Vector(-1, 0, 0)));
|
||||
Location rightLocation = block.getLocation().clone().add(vectorOperation.performToRealSpaceOperation(new Vector(1, 0, 0)));
|
||||
|
||||
//If the block is water or is waterlogged, assume the portal is underwater
|
||||
if (isUnderwater(leftLocation) || isUnderwater(rightLocation)) {
|
||||
@@ -349,15 +341,12 @@ public final class PortalFileHelper {
|
||||
* @return <p>True if the calculated button location is not the same as the one in the portal file</p>
|
||||
*/
|
||||
private static boolean updateButtonVector(@NotNull Portal portal) {
|
||||
for (RelativeBlockVector control : portal.getGate().getLayout().getControls()) {
|
||||
BlockLocation controlLocation = portal.getLocation().getTopLeft().getRelativeLocation(control,
|
||||
portal.getYaw());
|
||||
BlockLocation buttonLocation = controlLocation.getRelativeLocation(
|
||||
new RelativeBlockVector(0, 0, 1), portal.getYaw());
|
||||
if (!buttonLocation.equals(portal.getLocation().getSignLocation())) {
|
||||
portal.getLocation().setButtonVector(control);
|
||||
for (BlockVector control : portal.getGate().getLayout().getControls()) {
|
||||
Block buttonLocation = portal.getLocation().getRelative(control.clone().add(new Vector(0, 0, 1)).toBlockVector());
|
||||
if (!buttonLocation.equals(portal.getLocation().getSignBlock())) {
|
||||
portal.getLocation().setButtonBlock(buttonLocation);
|
||||
|
||||
BlockLocation oldButtonLocation = portal.getStructure().getButton();
|
||||
Block oldButtonLocation = portal.getStructure().getButton();
|
||||
if (oldButtonLocation != null && !oldButtonLocation.equals(buttonLocation)) {
|
||||
Stargate.addControlBlockUpdateRequest(new BlockChangeRequest(oldButtonLocation, Material.AIR, null));
|
||||
portal.getStructure().setButton(buttonLocation);
|
||||
@@ -376,7 +365,7 @@ public final class PortalFileHelper {
|
||||
*/
|
||||
public static void generatePortalButton(@NotNull Portal portal, @NotNull BlockFace buttonFacing) {
|
||||
//Go one block outwards to find the button's location rather than the control block's location
|
||||
BlockLocation button = getButtonLocation(portal);
|
||||
Block button = portal.getLocation().getButtonBlock();
|
||||
|
||||
// If the button location is null here, it is assumed that the button generation wasn't necessary
|
||||
if (button == null) {
|
||||
@@ -390,27 +379,24 @@ public final class PortalFileHelper {
|
||||
|
||||
Directional buttonData = (Directional) Bukkit.createBlockData(buttonType);
|
||||
buttonData.setFacing(buttonFacing);
|
||||
button.getBlock().setBlockData(buttonData);
|
||||
button.setBlockData(buttonData);
|
||||
}
|
||||
portal.getStructure().setButton(button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location of a portal's button
|
||||
* Gets the block specified in the input
|
||||
*
|
||||
* @param portal <p>The portal to find the button for</p>
|
||||
* @return <p>The location of the portal's button</p>
|
||||
* @param world <p>The world the block belongs to</p>
|
||||
* @param string <p>Comma-separated coordinate string</p>
|
||||
* @return <p>The specified block</p>
|
||||
* @throws NumberFormatException <p>If non-numeric values are encountered</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static BlockLocation getButtonLocation(@NotNull Portal portal) {
|
||||
BlockLocation topLeft = portal.getTopLeft();
|
||||
RelativeBlockVector buttonVector = portal.getLocation().getButtonVector();
|
||||
|
||||
if (buttonVector == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return topLeft.getRelativeLocation(buttonVector.addOut(1), portal.getYaw());
|
||||
@NotNull
|
||||
private static Block getBlock(@NotNull World world, @NotNull String string) throws NumberFormatException {
|
||||
String[] parts = string.split(",");
|
||||
return new Location(world, Integer.parseInt(parts[0]), Integer.parseInt(parts[1]),
|
||||
Integer.parseInt(parts[2])).getBlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Permission;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||
import net.knarcraft.stargate.portal.property.PortalOption;
|
||||
import net.knarcraft.stargate.portal.property.PortalStructure;
|
||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -30,9 +29,9 @@ import java.util.Map;
|
||||
/**
|
||||
* Keeps track of all loaded portals, and handles portal creation
|
||||
*/
|
||||
public class PortalHandler {
|
||||
public final class PortalUtil {
|
||||
|
||||
private PortalHandler() {
|
||||
private PortalUtil() {
|
||||
|
||||
}
|
||||
|
||||
@@ -118,8 +117,7 @@ public class PortalHandler {
|
||||
return true;
|
||||
}
|
||||
//Check if this player can access the destination world
|
||||
if (destinationPortal.getWorld() != null && PermissionHelper.cannotAccessWorld(player,
|
||||
destinationPortal.getWorld().getName())) {
|
||||
if (PermissionHelper.cannotAccessWorld(player, destinationPortal.getLocation().getWorld().getName())) {
|
||||
return false;
|
||||
}
|
||||
//The portal is visible to the player
|
||||
@@ -166,36 +164,33 @@ public class PortalHandler {
|
||||
* Tries to find a gate matching the portal the user is trying to create
|
||||
*
|
||||
* @param portalLocation <p>The location data for the new portal</p>
|
||||
* @param world <p>The world the player is located in</p>
|
||||
* @return <p>The matching gate type, or null if no such gate could be found</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static Gate findMatchingGate(@NotNull PortalLocation portalLocation, @NotNull World world) {
|
||||
Block signParent = portalLocation.getSignLocation().getParent();
|
||||
public static Gate findMatchingGate(@NotNull PortalLocation portalLocation) {
|
||||
Block signParent = DirectionHelper.getParent(portalLocation.getSignBlock());
|
||||
if (signParent == null) {
|
||||
return null;
|
||||
}
|
||||
BlockLocation parent = new BlockLocation(world, signParent.getX(), signParent.getY(),
|
||||
signParent.getZ());
|
||||
|
||||
//Get all gates with the used type of control blocks
|
||||
List<Gate> possibleGates = GateHandler.getGatesByControlBlock(signParent);
|
||||
double yaw = portalLocation.getYaw();
|
||||
Gate gate = null;
|
||||
|
||||
for (Gate possibleGate : possibleGates) {
|
||||
//Get gate controls
|
||||
RelativeBlockVector[] vectors = possibleGate.getLayout().getControls();
|
||||
BlockVector[] vectors = possibleGate.getLayout().getControls();
|
||||
|
||||
portalLocation.setButtonVector(null);
|
||||
for (RelativeBlockVector controlVector : vectors) {
|
||||
portalLocation.setButtonBlock(null);
|
||||
for (BlockVector controlVector : vectors) {
|
||||
//Assuming the top-left location is pointing to the gate's top-left location, check if it's a match
|
||||
BlockLocation possibleTopLocation = parent.getRelativeLocation(controlVector.invert(), yaw);
|
||||
if (possibleGate.matches(possibleTopLocation, portalLocation.getYaw(), true)) {
|
||||
Block possibleTopLocation = portalLocation.getRelative(controlVector);
|
||||
|
||||
if (possibleGate.matches(possibleTopLocation, portalLocation.getFacing(), true)) {
|
||||
gate = possibleGate;
|
||||
portalLocation.setTopLeft(possibleTopLocation);
|
||||
} else {
|
||||
portalLocation.setButtonVector(controlVector);
|
||||
portalLocation.setButtonBlock(possibleTopLocation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +217,7 @@ public class PortalHandler {
|
||||
Portal origin = getByName(originName, portal.getCleanNetwork());
|
||||
if (origin == null ||
|
||||
!Portal.cleanString(origin.getDestinationName()).equals(portal.getCleanName()) ||
|
||||
!new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(origin.getLocation().getSignLocation().getType())) {
|
||||
!new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(origin.getLocation().getSignBlock().getType())) {
|
||||
continue;
|
||||
}
|
||||
//Update sign of fixed gates pointing at this gate
|
||||
@@ -300,8 +295,7 @@ public class PortalHandler {
|
||||
if (location.getWorld() == null) {
|
||||
return null;
|
||||
}
|
||||
return PortalRegistry.getPortalFromEntrance(new BlockLocation(location.getWorld(), location.getBlockX(),
|
||||
location.getBlockY(), location.getBlockZ()));
|
||||
return PortalRegistry.getPortalFromEntrance(location.getBlock());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,7 +306,7 @@ public class PortalHandler {
|
||||
*/
|
||||
@Nullable
|
||||
public static Portal getByEntrance(@NotNull Block block) {
|
||||
return PortalRegistry.getPortalFromEntrance(new BlockLocation(block));
|
||||
return PortalRegistry.getPortalFromEntrance(block);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,24 +329,24 @@ public class PortalHandler {
|
||||
*/
|
||||
@Nullable
|
||||
public static Portal getByAdjacentEntrance(@NotNull Location location, int range) {
|
||||
List<BlockLocation> adjacentPositions = new ArrayList<>();
|
||||
BlockLocation centerLocation = new BlockLocation(location.getBlock());
|
||||
List<Block> adjacentPositions = new ArrayList<>();
|
||||
Block centerLocation = location.getBlock();
|
||||
adjacentPositions.add(centerLocation);
|
||||
|
||||
for (int index = 1; index <= range; index++) {
|
||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, 0));
|
||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(-index, 0, 0));
|
||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(0, 0, index));
|
||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(0, 0, -index));
|
||||
adjacentPositions.add(location.clone().add(new Vector(index, 0, 0)).getBlock());
|
||||
adjacentPositions.add(location.clone().add(new Vector(-index, 0, 0)).getBlock());
|
||||
adjacentPositions.add(location.clone().add(new Vector(0, 0, index)).getBlock());
|
||||
adjacentPositions.add(location.clone().add(new Vector(0, 0, -index)).getBlock());
|
||||
if (index < range) {
|
||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, index));
|
||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(-index, 0, -index));
|
||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, -index));
|
||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(-index, 0, index));
|
||||
adjacentPositions.add(location.clone().add(new Vector(index, 0, index)).getBlock());
|
||||
adjacentPositions.add(location.clone().add(new Vector(-index, 0, -index)).getBlock());
|
||||
adjacentPositions.add(location.clone().add(new Vector(index, 0, -index)).getBlock());
|
||||
adjacentPositions.add(location.clone().add(new Vector(-index, 0, index)).getBlock());
|
||||
}
|
||||
}
|
||||
|
||||
for (BlockLocation adjacentPosition : adjacentPositions) {
|
||||
for (Block adjacentPosition : adjacentPositions) {
|
||||
Portal portal = PortalRegistry.getPortalFromEntrance(adjacentPosition);
|
||||
if (portal != null) {
|
||||
return portal;
|
||||
@@ -369,7 +363,7 @@ public class PortalHandler {
|
||||
*/
|
||||
@Nullable
|
||||
public static Portal getByControl(@NotNull Block block) {
|
||||
return PortalRegistry.getPortalFromControl(new BlockLocation(block));
|
||||
return PortalRegistry.getPortalFromControl(block);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,7 +374,7 @@ public class PortalHandler {
|
||||
*/
|
||||
@Nullable
|
||||
public static Portal getByBlock(@NotNull Block block) {
|
||||
return PortalRegistry.getPortalFromFrame(new BlockLocation(block));
|
||||
return PortalRegistry.getPortalFromFrame(block);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -441,11 +435,12 @@ public class PortalHandler {
|
||||
|
||||
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()))) {
|
||||
portal.getLocation().getSignBlock().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())) {
|
||||
} else if (!portal.getOptions().isAlwaysOn() && portal.getLocation().getButtonBlock() != null &&
|
||||
!MaterialHelper.isButtonCompatible(portal.getLocation().getButtonBlock().getLocation().add(
|
||||
new Vector(0, 0, 1)).getBlock().getType())) {
|
||||
Stargate.debug("PortalHandler::verifyAllPortals", "Stargate is missing a valid button");
|
||||
invalidPortals.add(portal);
|
||||
} else if (!structure.checkIntegrity()) {
|
||||
@@ -467,8 +462,8 @@ public class PortalHandler {
|
||||
*/
|
||||
private static void unregisterInvalidPortal(@NotNull Portal portal) {
|
||||
//Show debug information
|
||||
for (RelativeBlockVector control : portal.getGate().getLayout().getControls()) {
|
||||
Block block = portal.getBlockAt(control).getBlock();
|
||||
for (BlockVector control : portal.getGate().getLayout().getControls()) {
|
||||
Block block = portal.getLocation().getRelative(control);
|
||||
//Log control blocks not matching the gate layout
|
||||
if (!MaterialHelper.specifiersToMaterials(portal.getGate().getControlBlockMaterials()).contains(
|
||||
block.getType())) {
|
||||
@@ -0,0 +1,107 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.portal.property.PortalOption;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A helper class for saving and loading Stargates from or to YML files
|
||||
*/
|
||||
public final class PortalYMLHelper {
|
||||
|
||||
private PortalYMLHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all portals
|
||||
*
|
||||
* @throws IOException <p>If unable to read or write a portal file</p>
|
||||
*/
|
||||
public void savePortals() throws IOException {
|
||||
Map<World, File> worldFiles = new HashMap<>();
|
||||
Map<World, FileConfiguration> configurations = new HashMap<>();
|
||||
|
||||
// Get and alter each configuration without saving
|
||||
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||
World world = portal.getLocation().getWorld();
|
||||
|
||||
File file = worldFiles.get(world);
|
||||
FileConfiguration configuration = configurations.get(world);
|
||||
if (file == null) {
|
||||
file = new File(Stargate.getStargateConfig().getPortalFolder(), world.getUID() + ".yml");
|
||||
worldFiles.put(world, file);
|
||||
}
|
||||
if (configuration == null) {
|
||||
configuration = new YamlConfiguration();
|
||||
configurations.put(world, configuration);
|
||||
}
|
||||
|
||||
savePortal(portal, configuration);
|
||||
}
|
||||
|
||||
// Save each configuration
|
||||
for (Map.Entry<World, FileConfiguration> configuration : configurations.entrySet()) {
|
||||
configuration.getValue().save(worldFiles.get(configuration.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the given portal
|
||||
*
|
||||
* @param portal <p>The portal to save</p>
|
||||
*/
|
||||
public void savePortal(@NotNull Portal portal, @NotNull FileConfiguration configuration) {
|
||||
|
||||
String root = portal.getNetwork() + "." + portal.getName();
|
||||
ConfigurationSection portalSection = configuration.createSection(root);
|
||||
|
||||
portalSection.set("name", portal.getName());
|
||||
portalSection.set("network", portal.getNetwork());
|
||||
portalSection.set("destination", portal.getOptions().isFixed() ? portal.getDestinationName() : null);
|
||||
portalSection.set("owner", portal.getOwner().getIdentifier());
|
||||
portalSection.set("gate", portal.getGate().getFilename());
|
||||
portalSection.set("topLeft", portal.getLocation().getTopLeft());
|
||||
portalSection.set("signLocation", portal.getLocation().getSignBlock());
|
||||
portalSection.set("buttonLocation", portal.getLocation().getButtonBlock());
|
||||
portalSection.set("facing", portal.getLocation().getFacing());
|
||||
|
||||
for (PortalOption option : PortalOption.values()) {
|
||||
portalSection.set("options." + option.getCharacterRepresentation(), portal.getOptions().checkOption(option));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Portal loadPortal(@NotNull ConfigurationSection portalSection) {
|
||||
|
||||
/* PortalLocation location = new PortalLocation();
|
||||
BlockLocation signLocation = (BlockLocation) portalSection.get("signLocation");
|
||||
BlockLocation topLeft = (BlockLocation) portalSection.get("topLeft");
|
||||
if (signLocation == null || topLeft == null) {
|
||||
return null;
|
||||
}
|
||||
BlockFace facing = (BlockFace) Objects.requireNonNull(portalSection.get("facing"));
|
||||
location.setSignLocation(signLocation).setButtonFacing(facing).setYaw(BlockFace.);
|
||||
|
||||
BlockLocation button;
|
||||
PortalStrings portalStrings = new PortalStrings();
|
||||
Gate gate = GateHandler.getGateByName();
|
||||
PortalOwner owner;
|
||||
Map<PortalOption, Boolean> options;
|
||||
return new Portal(location, button, portalStrings, gate, owner, options);*/
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.portal.property.PortalOwner;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -69,10 +68,10 @@ public final class UUIDMigrationHelper {
|
||||
|
||||
//Get the real portal from the copy and set UUID
|
||||
for (Portal portalCopy : portals) {
|
||||
Portal portal = PortalHandler.getByName(portalCopy.getCleanName(), portalCopy.getCleanNetwork());
|
||||
Portal portal = PortalUtil.getByName(portalCopy.getCleanName(), portalCopy.getCleanNetwork());
|
||||
if (portal != null) {
|
||||
portal.getOwner().setUUID(uniqueId);
|
||||
worldsToSave.add(portal.getWorld());
|
||||
worldsToSave.add(portal.getLocation().getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
src/main/resources/portal.yml
Normal file
21
src/main/resources/portal.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
name: gdgdfg
|
||||
network: central
|
||||
ownerUUID: a62cd062-517c-4894-b00c-a5bfa8910369
|
||||
gate: nether.gate
|
||||
topLeft: -457,72,427
|
||||
signLocation: -456,70,427
|
||||
buttonLocation: -456,70,424
|
||||
# Change this to block face?
|
||||
facing: NORTH
|
||||
options:
|
||||
bungee: false
|
||||
alwaysOn: false
|
||||
hidden: false
|
||||
private: false
|
||||
free: false
|
||||
backwards: false
|
||||
show: false
|
||||
noNetwork: false
|
||||
random: false
|
||||
quiet: false
|
||||
invisible: false
|
||||
Reference in New Issue
Block a user