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:
2021-10-26 16:22:20 +02:00
parent 1c906528f2
commit 5c730eb613
6 changed files with 52 additions and 29 deletions

View File

@ -21,24 +21,31 @@ public class BlockChangeThread implements Runnable {
long sTime = System.nanoTime();
//Repeat for at most 0.025 seconds
while (System.nanoTime() - sTime < 25000000) {
//Abort if there's no work to be done
BlockChangeRequest blockChangeRequest = Stargate.blockChangeRequestQueue.poll();
if (blockChangeRequest == null) {
return;
}
pollQueue();
}
}
//Change the material of the pulled block
Block block = blockChangeRequest.getBlockLocation().getBlock();
block.setType(blockChangeRequest.getMaterial(), false);
/**
* Polls the block change request queue for any waiting requests
*/
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 &&
block.getWorld().getEnvironment() == World.Environment.THE_END) {
//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());
}
//Change the material of the pulled block
Block block = blockChangeRequest.getBlockLocation().getBlock();
block.setType(blockChangeRequest.getMaterial(), false);
if (blockChangeRequest.getMaterial() == Material.END_GATEWAY &&
block.getWorld().getEnvironment() == World.Environment.THE_END) {
//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>
*/
private void fixEndGatewayGate(Block block) {
private static void fixEndGatewayGate(Block block) {
EndGateway gateway = (EndGateway) block.getState();
gateway.setExitLocation(block.getLocation());
gateway.setExactTeleport(true);
@ -60,7 +67,7 @@ public class BlockChangeThread implements Runnable {
* @param block <p>The block to orient</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.setAxis(axis);
block.setBlockData(orientable);