Adds missing comments to BlockPopulatorThread and make end gateways teleport entities back to itself to prevent strange behavior

Because of the teleport change, end gateways work to teleport player,
and end gateways work to the end for vehicles, but vehicles cannot teleport back from the end
This commit is contained in:
Kristian Knarvik 2021-03-02 17:55:14 +01:00
parent 44dfa2a10d
commit b1aa53c1a9

View File

@ -8,27 +8,42 @@ import org.bukkit.block.Block;
import org.bukkit.block.EndGateway; import org.bukkit.block.EndGateway;
import org.bukkit.block.data.Orientable; import org.bukkit.block.data.Orientable;
/**
* This thread changes gate blocks to display a gate as open or closed
*
* <p>This thread fetches some entries from blockPopulatorQueue each time it's called.</p>
*/
public class BlockPopulatorThread implements Runnable { public class BlockPopulatorThread implements Runnable {
@Override
public void run() { public void run() {
long sTime = System.nanoTime(); long sTime = System.nanoTime();
//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
BloxPopulator bloxPopulator = Stargate.blockPopulatorQueue.poll(); BloxPopulator bloxPopulator = Stargate.blockPopulatorQueue.poll();
if (bloxPopulator == null) { if (bloxPopulator == null) {
return; return;
} }
//Change the material of the pulled block
Block block = bloxPopulator.getBlockLocation().getBlock(); Block block = bloxPopulator.getBlockLocation().getBlock();
block.setType(bloxPopulator.getMaterial(), false); block.setType(bloxPopulator.getMaterial(), false);
if (bloxPopulator.getMaterial() == Material.END_GATEWAY && block.getWorld().getEnvironment() == World.Environment.THE_END) {
// force a location to prevent exit gateway generation if (bloxPopulator.getMaterial() == Material.END_GATEWAY &&
block.getWorld().getEnvironment() == World.Environment.THE_END) {
//Force a specific location to prevent exit gateway generation
EndGateway gateway = (EndGateway) block.getState(); EndGateway gateway = (EndGateway) block.getState();
gateway.setExitLocation(block.getWorld().getSpawnLocation()); gateway.setExitLocation(block.getLocation());
gateway.setExactTeleport(true); gateway.setExactTeleport(true);
gateway.update(false, false); gateway.update(false, false);
} else if (bloxPopulator.getAxis() != null) { } else if (bloxPopulator.getAxis() != null) {
//If orientation is relevant, adjust the block's orientation
Orientable orientable = (Orientable) block.getBlockData(); Orientable orientable = (Orientable) block.getBlockData();
orientable.setAxis(bloxPopulator.getAxis()); orientable.setAxis(bloxPopulator.getAxis());
block.setBlockData(orientable); block.setBlockData(orientable);
} }
} }
} }
} }