Renames the blox populator and block populator thread as I finally understand what they actually do
This commit is contained in:
@ -0,0 +1,67 @@
|
||||
package net.knarcraft.stargate.thread;
|
||||
|
||||
import net.knarcraft.stargate.BlockChangeRequest;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.EndGateway;
|
||||
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 blockPopulateQueue each time it's called.</p>
|
||||
*/
|
||||
public class BlockChangeThread implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
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;
|
||||
}
|
||||
|
||||
//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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents end gateway portal from behaving strangely
|
||||
* @param block <p>The block to fix</p>
|
||||
*/
|
||||
private void fixEndGatewayGate(Block block) {
|
||||
EndGateway gateway = (EndGateway) block.getState();
|
||||
gateway.setExitLocation(block.getLocation());
|
||||
gateway.setExactTeleport(true);
|
||||
gateway.update(false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the orientation axis of the placed block
|
||||
* @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) {
|
||||
Orientable orientable = (Orientable) block.getBlockData();
|
||||
orientable.setAxis(axis);
|
||||
block.setBlockData(orientable);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user