Fixes some portal closing bugs, a NullPointerException and a typo
Fixes a typo in nn-no Fixes a bug causing always-on portals not to be closed properly Fixes a possible NullPointerException in onEntityPortalEnter Waits for block change request on reload which makes it possible to change the open-material with just a reload
This commit is contained in:
parent
1c906528f2
commit
5c730eb613
@ -1,10 +1,13 @@
|
|||||||
package net.knarcraft.stargate.config;
|
package net.knarcraft.stargate.config;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
|
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||||
import net.knarcraft.stargate.listener.BungeeCordListener;
|
import net.knarcraft.stargate.listener.BungeeCordListener;
|
||||||
import net.knarcraft.stargate.portal.GateHandler;
|
import net.knarcraft.stargate.portal.GateHandler;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
|
import net.knarcraft.stargate.portal.PortalHandler;
|
||||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
|
import net.knarcraft.stargate.thread.BlockChangeThread;
|
||||||
import net.knarcraft.stargate.utility.FileHelper;
|
import net.knarcraft.stargate.utility.FileHelper;
|
||||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -121,7 +124,15 @@ public final class StargateConfig {
|
|||||||
public void reload(CommandSender sender) {
|
public void reload(CommandSender sender) {
|
||||||
//Unload all saved data
|
//Unload all saved data
|
||||||
unload();
|
unload();
|
||||||
|
|
||||||
|
//Perform all block change requests to prevent mismatch if a gate's open-material changes. Changing the
|
||||||
|
// closed-material still requires a restart.
|
||||||
|
BlockChangeRequest firstElement = Stargate.blockChangeRequestQueue.peek();
|
||||||
|
while (firstElement != null) {
|
||||||
|
BlockChangeThread.pollQueue();
|
||||||
|
firstElement = Stargate.blockChangeRequestQueue.peek();
|
||||||
|
}
|
||||||
|
|
||||||
//Store the old enable bungee state in case it changes
|
//Store the old enable bungee state in case it changes
|
||||||
boolean oldEnableBungee = stargateGateConfig.enableBungee();
|
boolean oldEnableBungee = stargateGateConfig.enableBungee();
|
||||||
|
|
||||||
@ -145,7 +156,9 @@ public final class StargateConfig {
|
|||||||
activePortal.getPortalActivator().deactivate();
|
activePortal.getPortalActivator().deactivate();
|
||||||
}
|
}
|
||||||
//Force all portals to close
|
//Force all portals to close
|
||||||
closeAllPortals();
|
closeAllOpenPortals();
|
||||||
|
PortalHandler.closeAllPortals();
|
||||||
|
|
||||||
//Clear queues and lists
|
//Clear queues and lists
|
||||||
activePortalsQueue.clear();
|
activePortalsQueue.clear();
|
||||||
openPortalsQueue.clear();
|
openPortalsQueue.clear();
|
||||||
@ -247,9 +260,9 @@ public final class StargateConfig {
|
|||||||
/**
|
/**
|
||||||
* Forces all open portals to close
|
* Forces all open portals to close
|
||||||
*/
|
*/
|
||||||
public void closeAllPortals() {
|
public void closeAllOpenPortals() {
|
||||||
for (Portal openPortal : openPortalsQueue) {
|
for (Portal openPortal : openPortalsQueue) {
|
||||||
openPortal.getPortalOpener().closePortal(true);
|
openPortal.getPortalOpener().closePortal(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +60,9 @@ public class PortalEventListener implements Listener {
|
|||||||
if (entity instanceof Player player && location.getBlock().getType() == Material.END_PORTAL && world != null &&
|
if (entity instanceof Player player && location.getBlock().getType() == Material.END_PORTAL && world != null &&
|
||||||
world.getEnvironment() == World.Environment.THE_END) {
|
world.getEnvironment() == World.Environment.THE_END) {
|
||||||
Portal portal = PortalHandler.getByAdjacentEntrance(location);
|
Portal portal = PortalHandler.getByAdjacentEntrance(location);
|
||||||
|
if (portal == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Remove any old player teleportations in case weird things happen
|
//Remove any old player teleportations in case weird things happen
|
||||||
playersFromTheEnd.removeIf((teleportation -> teleportation.getPlayer() == player));
|
playersFromTheEnd.removeIf((teleportation -> teleportation.getPlayer() == player));
|
||||||
|
@ -146,7 +146,7 @@ public class PortalOpener {
|
|||||||
*/
|
*/
|
||||||
public void closePortal(boolean force) {
|
public void closePortal(boolean force) {
|
||||||
//No need to close a portal which is already closed
|
//No need to close a portal which is already closed
|
||||||
if (!isOpen) {
|
if (!isOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,24 +21,31 @@ public class BlockChangeThread implements Runnable {
|
|||||||
long sTime = System.nanoTime();
|
long sTime = System.nanoTime();
|
||||||
//Repeat for at most 0.025 seconds
|
//Repeat for at most 0.025 seconds
|
||||||
while (System.nanoTime() - sTime < 25000000) {
|
while (System.nanoTime() - sTime < 25000000) {
|
||||||
//Abort if there's no work to be done
|
pollQueue();
|
||||||
BlockChangeRequest blockChangeRequest = Stargate.blockChangeRequestQueue.poll();
|
}
|
||||||
if (blockChangeRequest == null) {
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Change the material of the pulled block
|
/**
|
||||||
Block block = blockChangeRequest.getBlockLocation().getBlock();
|
* Polls the block change request queue for any waiting requests
|
||||||
block.setType(blockChangeRequest.getMaterial(), false);
|
*/
|
||||||
|
public static void pollQueue() {
|
||||||
|
//Abort if there's no work to be done
|
||||||
|
BlockChangeRequest blockChangeRequest = Stargate.blockChangeRequestQueue.poll();
|
||||||
|
if (blockChangeRequest == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (blockChangeRequest.getMaterial() == Material.END_GATEWAY &&
|
//Change the material of the pulled block
|
||||||
block.getWorld().getEnvironment() == World.Environment.THE_END) {
|
Block block = blockChangeRequest.getBlockLocation().getBlock();
|
||||||
//Force a specific location to prevent exit gateway generation
|
block.setType(blockChangeRequest.getMaterial(), false);
|
||||||
fixEndGatewayGate(block);
|
|
||||||
} else if (blockChangeRequest.getAxis() != null) {
|
if (blockChangeRequest.getMaterial() == Material.END_GATEWAY &&
|
||||||
//If orientation is relevant, adjust the block's orientation
|
block.getWorld().getEnvironment() == World.Environment.THE_END) {
|
||||||
orientBlock(block, blockChangeRequest.getAxis());
|
//Force a specific location to prevent exit gateway generation
|
||||||
}
|
fixEndGatewayGate(block);
|
||||||
|
} else if (blockChangeRequest.getAxis() != null) {
|
||||||
|
//If orientation is relevant, adjust the block's orientation
|
||||||
|
orientBlock(block, blockChangeRequest.getAxis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +54,7 @@ public class BlockChangeThread implements Runnable {
|
|||||||
*
|
*
|
||||||
* @param block <p>The block to fix</p>
|
* @param block <p>The block to fix</p>
|
||||||
*/
|
*/
|
||||||
private void fixEndGatewayGate(Block block) {
|
private static void fixEndGatewayGate(Block block) {
|
||||||
EndGateway gateway = (EndGateway) block.getState();
|
EndGateway gateway = (EndGateway) block.getState();
|
||||||
gateway.setExitLocation(block.getLocation());
|
gateway.setExitLocation(block.getLocation());
|
||||||
gateway.setExactTeleport(true);
|
gateway.setExactTeleport(true);
|
||||||
@ -60,7 +67,7 @@ public class BlockChangeThread implements Runnable {
|
|||||||
* @param block <p>The block to orient</p>
|
* @param block <p>The block to orient</p>
|
||||||
* @param axis <p>The axis to use for orienting the block</p>
|
* @param axis <p>The axis to use for orienting the block</p>
|
||||||
*/
|
*/
|
||||||
private void orientBlock(Block block, Axis axis) {
|
private static void orientBlock(Block block, Axis axis) {
|
||||||
Orientable orientable = (Orientable) block.getBlockData();
|
Orientable orientable = (Orientable) block.getBlockData();
|
||||||
orientable.setAxis(axis);
|
orientable.setAxis(axis);
|
||||||
block.setBlockData(orientable);
|
block.setBlockData(orientable);
|
||||||
|
@ -26,12 +26,12 @@ public final class PermissionHelper {
|
|||||||
public static void openPortal(Player player, Portal portal) {
|
public static void openPortal(Player player, Portal portal) {
|
||||||
Portal destination = portal.getPortalActivator().getDestination();
|
Portal destination = portal.getPortalActivator().getDestination();
|
||||||
|
|
||||||
//Always-open gate -- Do nothing
|
//Always-open portal -- Do nothing
|
||||||
if (portal.getOptions().isAlwaysOn()) {
|
if (portal.getOptions().isAlwaysOn()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Random gate -- Do nothing
|
//Random portal -- Do nothing
|
||||||
if (portal.getOptions().isRandom()) {
|
if (portal.getOptions().isRandom()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -42,16 +42,16 @@ public final class PermissionHelper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Gate is already open
|
//Portal is already open
|
||||||
if (portal.isOpen()) {
|
if (portal.isOpen()) {
|
||||||
// Close if this player opened the gate
|
//Close if this player opened the portal
|
||||||
if (portal.getActivePlayer() == player) {
|
if (portal.getActivePlayer() == player) {
|
||||||
portal.getPortalOpener().closePortal(false);
|
portal.getPortalOpener().closePortal(false);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Gate that someone else is using -- Deny access
|
//Portal is used by another player -- Deny access
|
||||||
if ((!portal.getOptions().isFixed()) && portal.getPortalActivator().isActive() &&
|
if ((!portal.getOptions().isFixed()) && portal.getPortalActivator().isActive() &&
|
||||||
(portal.getActivePlayer() != player)) {
|
(portal.getActivePlayer() != player)) {
|
||||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("denyMsg"));
|
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||||
|
@ -34,4 +34,4 @@ signDisconnected=Kopla frå
|
|||||||
bungeeDisabled=BungeeCord støtte er slått av.
|
bungeeDisabled=BungeeCord støtte er slått av.
|
||||||
bungeeDeny=Du har ikkje løyve til å opprette BungeeCord portar.
|
bungeeDeny=Du har ikkje løyve til å opprette BungeeCord portar.
|
||||||
bungeeEmpty=BungeeCord portar treng bade ein destinasjon og eit nettverk.
|
bungeeEmpty=BungeeCord portar treng bade ein destinasjon og eit nettverk.
|
||||||
bungeeSign=Teleportar til
|
bungeeSign=Teleporter til
|
||||||
|
Loading…
x
Reference in New Issue
Block a user