Move vectors to static creators, for caching

This commit is contained in:
Kenzie Togami
2018-10-19 13:13:32 -07:00
committed by IronApollo
parent a9919d130c
commit 4d6045813c
138 changed files with 670 additions and 531 deletions

View File

@ -35,8 +35,8 @@ public class GriefPreventionFilter extends CuboidRegionFilter {
org.bukkit.Location bot = claim.getGreaterBoundaryCorner();
if (world.equals(bot.getWorld())) {
org.bukkit.Location top = claim.getGreaterBoundaryCorner();
BlockVector2 pos1 = new BlockVector2(bot.getBlockX(), bot.getBlockZ());
BlockVector2 pos2 = new BlockVector2(top.getBlockX(), top.getBlockZ());
BlockVector2 pos1 = BlockVector2.at(bot.getBlockX(), bot.getBlockZ());
BlockVector2 pos2 = BlockVector2.at(top.getBlockX(), top.getBlockZ());
add(pos1, pos2);
}
}

View File

@ -49,8 +49,8 @@ public class WorldGuardFilter extends CuboidRegionFilter {
@Override
public boolean containsChunk(int chunkX, int chunkZ) {
if (!large) return super.containsChunk(chunkX, chunkZ);
BlockVector3 pos1 = new BlockVector3(chunkX << 4, 0, chunkZ << 4);
BlockVector3 pos2 = new BlockVector3(pos1.getBlockX() + 15, 255, pos1.getBlockZ() + 15);
BlockVector3 pos1 = BlockVector3.at(chunkX << 4, 0, chunkZ << 4);
BlockVector3 pos2 = BlockVector3.at(pos1.getBlockX() + 15, 255, pos1.getBlockZ() + 15);
ProtectedCuboidRegion chunkRegion = new ProtectedCuboidRegion("unimportant", pos1, pos2);
ApplicableRegionSet set = manager.getApplicableRegions(chunkRegion);
return set.size() > 0 && !set.getRegions().iterator().next().getId().equals("__global__");
@ -59,8 +59,8 @@ public class WorldGuardFilter extends CuboidRegionFilter {
@Override
public boolean containsRegion(int mcaX, int mcaZ) {
if (!large) return super.containsRegion(mcaX, mcaZ);
BlockVector3 pos1 = new BlockVector3(mcaX << 9, 0, mcaZ << 9);
BlockVector3 pos2 = new BlockVector3(pos1.getBlockX() + 511, 255, pos1.getBlockZ() + 511);
BlockVector3 pos1 = BlockVector3.at(mcaX << 9, 0, mcaZ << 9);
BlockVector3 pos2 = BlockVector3.at(pos1.getBlockX() + 511, 255, pos1.getBlockZ() + 511);
ProtectedCuboidRegion regionRegion = new ProtectedCuboidRegion("unimportant", pos1, pos2);
ApplicableRegionSet set = manager.getApplicableRegions(regionRegion);
return set.size() > 0 && !set.getRegions().iterator().next().getId().equals("__global__");

View File

@ -253,7 +253,7 @@ public class BukkitImageListener implements Listener {
fp.runAction(new Runnable() {
@Override
public void run() {
BlockVector3 wPos = new BlockVector3(worldX, 0, worldZ);
BlockVector3 wPos = BlockVector3.at(worldX, 0, worldZ);
viewer.refresh();
int topY = generator.getNearestSurfaceTerrainBlock(wPos.getBlockX(), wPos.getBlockZ(), 255, 0, 255);
wPos = wPos.withY(topY);

View File

@ -139,7 +139,7 @@ public class CFIPacketListener implements Listener {
int ocx = origin.getBlockX() >> 4;
int ocz = origin.getBlockZ() >> 4;
if (gen.contains(new BlockVector3((cx - ocx) << 4, 0, (cz - ocz) << 4))) {
if (gen.contains(BlockVector3.at((cx - ocx) << 4, 0, (cz - ocz) << 4))) {
event.setCancelled(true);
Player plr = event.getPlayer();
@ -166,7 +166,7 @@ public class CFIPacketListener implements Listener {
VirtualWorld gen = getGenerator(event);
if (gen != null) {
BlockVector3 origin = gen.getOrigin().toBlockPoint();
BlockVector3 pt = new BlockVector3(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
BlockVector3 pt = BlockVector3.at(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
StructureModifier<Integer> ints = event.getPacket().getIntegers();
int id = ints.read(0);
@ -191,11 +191,11 @@ public class CFIPacketListener implements Listener {
VirtualWorld gen = getGenerator(event);
if (gen != null) {
BlockVector3 origin = gen.getOrigin().toBlockPoint();
BlockVector3 from = new BlockVector3(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
BlockVector3 from = BlockVector3.at(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
PacketContainer packet = event.getPacket();
StructureModifier<Double> doubles = packet.getDoubles();
BlockVector3 to = new BlockVector3(doubles.read(0), doubles.read(1), doubles.read(2));
BlockVector3 to = BlockVector3.at(doubles.read(0), doubles.read(1), doubles.read(2));
if (gen.contains(to.subtract(origin)) && from.distanceSq(to) < 8) {
int id = packet.getIntegers().read(0);
PacketContainer reply = new PacketContainer(PacketType.Play.Client.TELEPORT_ACCEPT);
@ -225,7 +225,7 @@ public class CFIPacketListener implements Listener {
BlockVector3 origin = gen.getOrigin().toBlockPoint();
int cx = chunk.getChunkX() - (origin.getBlockX() >> 4);
int cz = chunk.getChunkZ() - (origin.getBlockX() >> 4);
if (gen.contains(new BlockVector3(cx << 4, 0, cz << 4))) {
if (gen.contains(BlockVector3.at(cx << 4, 0, cz << 4))) {
event.setCancelled(true);
}
}
@ -288,7 +288,7 @@ public class CFIPacketListener implements Listener {
BlockPosition loc = position.readSafely(0);
if (loc == null) return null;
BlockVector3 origin = generator.getOrigin().toBlockPoint();
BlockVector3 pt = new BlockVector3(loc.getX() - origin.getBlockX(), loc.getY() - origin.getBlockY(), loc.getZ() - origin.getBlockZ());
BlockVector3 pt = BlockVector3.at(loc.getX() - origin.getBlockX(), loc.getY() - origin.getBlockY(), loc.getZ() - origin.getBlockZ());
return pt;
}

View File

@ -12,6 +12,6 @@ public class BukkitMask extends FaweMask {
}
public BukkitMask(Location pos1, Location pos2, String name) {
super(new BlockVector3(pos1.getBlockX(), pos1.getBlockY(), pos1.getBlockZ()), new BlockVector3(pos2.getBlockX(), pos2.getBlockY(), pos2.getBlockZ()), name);
super(BlockVector3.at(pos1.getBlockX(), pos1.getBlockY(), pos1.getBlockZ()), BlockVector3.at(pos2.getBlockX(), pos2.getBlockY(), pos2.getBlockZ()), name);
}
}

View File

@ -55,7 +55,7 @@ public class FreeBuildRegion extends BukkitMaskManager {
World bukkitWorld = player.parent.getWorld();
AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld);
BlockVector3 vec1 = new BlockVector3(0, 0, 0);
BlockVector3 vec1 = BlockVector3.at(0, 0, 0);
BlockVector3 vec2 = vec1;
Location pos1 = BukkitAdapter.adapt(bukkitWorld, vec1);
Location pos2 = BukkitAdapter.adapt(bukkitWorld, vec2);

View File

@ -41,8 +41,8 @@ public class PreciousStonesFeature extends BukkitMaskManager implements Listener
boolean member = fp.hasPermission("fawe.preciousstones.member");
for (final Field myField : fields) {
if (isAllowed(player, myField, type, member)) {
BlockVector3 pos1 = new BlockVector3(myField.getMinx(), myField.getMiny(), myField.getMinz());
BlockVector3 pos2 = new BlockVector3(myField.getMaxx(), myField.getMaxy(), myField.getMaxz());
BlockVector3 pos1 = BlockVector3.at(myField.getMinx(), myField.getMiny(), myField.getMinz());
BlockVector3 pos2 = BlockVector3.at(myField.getMaxx(), myField.getMaxy(), myField.getMaxz());
return new FaweMask(pos1, pos2, "FIELD: " + myField) {
@Override
public boolean isValid(FawePlayer player, MaskType type) {

View File

@ -61,7 +61,7 @@ public class Worldguard extends BukkitMaskManager implements Listener {
if (global != null && isAllowed(player, global)) {
return global;
}
final ApplicableRegionSet regions = manager.getApplicableRegions(new BlockVector3(loc.getX(), loc.getY(), loc.getZ()));
final ApplicableRegionSet regions = manager.getApplicableRegions(BlockVector3.at(loc.getX(), loc.getY(), loc.getZ()));
for (final ProtectedRegion region : regions) {
if (isAllowed(player, region)) {
return region;

View File

@ -57,7 +57,7 @@ public class StructureCUI extends CUI {
int x = Integer.parseInt(param[1]);
int y = Integer.parseInt(param[2]);
int z = Integer.parseInt(param[3]);
BlockVector3 pos = new BlockVector3(x, y, z);
BlockVector3 pos = BlockVector3.at(x, y, z);
if (id == 0) {
pos1 = pos;
} else {
@ -188,7 +188,7 @@ public class StructureCUI extends CUI {
NbtCompound compound = constructStructureNbt(x, y, z, posX, posY, posZ, sizeX, sizeY, sizeZ);
Block block = player.getWorld().getBlockAt(x, y, z);
remove = new BlockVector3(x, y, z);
remove = BlockVector3.at(x, y, z);
state = BukkitAdapter.adapt(block.getBlockData());
removeTag = compound;

View File

@ -211,7 +211,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
return;
}
setPosition(new Vector3(x + 0.5, y, z + 0.5));
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
player.setFlying(true);
}

View File

@ -200,7 +200,7 @@ public class BukkitWorld extends AbstractWorld {
com.sk89q.worldedit.world.block.BlockStateHolder[] history = new com.sk89q.worldedit.world.block.BlockState[16 * 16 * (getMaxY() + 1)];
for (BlockVector2 chunk : region.getChunks()) {
BlockVector3 min = new BlockVector3(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
BlockVector3 min = BlockVector3.at(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
// First save all the blocks inside
for (int x = 0; x < 16; ++x) {

View File

@ -40,7 +40,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override
public boolean setBlockData(int x, int y, int z, BlockData blockData) {
try {
editSession.setBlock(new BlockVector3(x, y, z), BukkitAdapter.adapt(blockData));
editSession.setBlock(BlockVector3.at(x, y, z), BukkitAdapter.adapt(blockData));
} catch (MaxChangedBlocksException e) {
return false;
}
@ -49,7 +49,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override
public BlockData getBlockData(int x, int y, int z) {
return BukkitAdapter.adapt(editSession.getBlock(new BlockVector3(x, y, z)));
return BukkitAdapter.adapt(editSession.getBlock(BlockVector3.at(x, y, z)));
}
@Override
@ -59,7 +59,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override
public boolean isEmpty(int x, int y, int z) {
return editSession.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isAir();
return editSession.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isAir();
}
}

View File

@ -165,7 +165,7 @@ public interface IBukkitAdapter {
*/
default Vector3 asVector(org.bukkit.Location location) {
checkNotNull(location);
return new Vector3(location.getX(), location.getY(), location.getZ());
return Vector3.at(location.getX(), location.getY(), location.getZ());
}
/**
@ -176,7 +176,7 @@ public interface IBukkitAdapter {
*/
default BlockVector3 asBlockVector(org.bukkit.Location location) {
checkNotNull(location);
return new BlockVector3(location.getX(), location.getY(), location.getZ());
return BlockVector3.at(location.getX(), location.getY(), location.getZ());
}
/**