Major code reformatting

This commit is contained in:
MattBDev
2016-03-22 21:41:37 -04:00
parent e18e1d4816
commit 9e2c6f2182
209 changed files with 9551 additions and 9237 deletions

View File

@ -53,24 +53,29 @@ import java.util.Optional;
public class SpongeUtil extends WorldUtil {
public static Cause CAUSE = Cause.of(NamedCause.source("PlotSquared"));
public static Location getLocation(final Entity player) {
final String world = player.getWorld().getName();
final org.spongepowered.api.world.Location loc = player.getLocation();
final Vector3i pos = loc.getBlockPosition();
return new Location(world, pos.getX(), pos.getY(), pos.getZ());
}
private static BiomeType[] biomes;
private static HashMap<String, Integer> biomeMap;
private static HashMap<BlockState, PlotBlock> stateMap;
private static BlockState[] stateArray;
private static Player lastPlayer = null;
private static PlotPlayer lastPlotPlayer = null;
private static World lastWorld;
private static String last;
public static Location getLocation(Entity player) {
String world = player.getWorld().getName();
org.spongepowered.api.world.Location loc = player.getLocation();
Vector3i pos = loc.getBlockPosition();
return new Location(world, pos.getX(), pos.getY(), pos.getZ());
}
public static BiomeType getBiome(String biome) {
if (biomes == null) {
initBiomeCache();
}
return biomes[biomeMap.get(biome.toUpperCase())];
}
public static <T> T getCause(Cause cause, Class<T> clazz) {
Optional<?> root = Optional.of(cause.root());
if (root.isPresent()) {
@ -114,7 +119,7 @@ public class SpongeUtil extends WorldUtil {
return TextSerializers.LEGACY_FORMATTING_CODE.deserialize(C.color(m));
}
public static Translation getTranslation(final String m) {
public static Translation getTranslation(String m) {
return new Translation() {
@Override
@ -123,19 +128,16 @@ public class SpongeUtil extends WorldUtil {
}
@Override
public String get(final Locale l, final Object... args) {
public String get(Locale l, Object... args) {
return m;
}
@Override
public String get(final Locale l) {
public String get(Locale l) {
return m;
}
};
}
private static HashMap<BlockState, PlotBlock> stateMap;
private static BlockState[] stateArray;
private static void initBlockCache() {
try {
@ -171,28 +173,25 @@ public class SpongeUtil extends WorldUtil {
return stateMap.get(state);
}
public static Location getLocation(final org.spongepowered.api.world.Location<World> block) {
public static Location getLocation(org.spongepowered.api.world.Location<World> block) {
return getLocation(block.getExtent().getName(), block);
}
public static Location getLocationFull(final Entity player) {
final String world = player.getWorld().getName();
final Vector3d rot = player.getRotation();
final float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ());
final org.spongepowered.api.world.Location loc = player.getLocation();
final Vector3i pos = loc.getBlockPosition();
public static Location getLocationFull(Entity player) {
String world = player.getWorld().getName();
Vector3d rot = player.getRotation();
float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ());
org.spongepowered.api.world.Location loc = player.getLocation();
Vector3i pos = loc.getBlockPosition();
return new Location(world, pos.getX(), pos.getY(), pos.getZ(), pitchYaw[1], pitchYaw[0]);
}
private static Player lastPlayer = null;
private static PlotPlayer lastPlotPlayer = null;
public static PlotPlayer getPlayer(final Player player) {
public static PlotPlayer getPlayer(Player player) {
if (player == lastPlayer) {
return lastPlotPlayer;
}
final String name = player.getName();
final PlotPlayer pp = UUIDHandler.getPlayer(name);
String name = player.getName();
PlotPlayer pp = UUIDHandler.getPlayer(name);
if (pp != null) {
return pp;
}
@ -201,22 +200,19 @@ public class SpongeUtil extends WorldUtil {
lastPlayer = player;
return lastPlotPlayer;
}
public static Player getPlayer(final PlotPlayer player) {
public static Player getPlayer(PlotPlayer player) {
if (player instanceof SpongePlayer) {
return ((SpongePlayer) player).player;
}
return null;
}
private static World lastWorld;
private static String last;
public static World getWorld(final String world) {
public static World getWorld(String world) {
if (StringMan.isEqual(world, last)) {
return lastWorld;
}
final Optional<World> optional = Sponge.getServer().getWorld(world);
Optional<World> optional = Sponge.getServer().getWorld(world);
if (!optional.isPresent()) {
last = null;
return lastWorld = null;
@ -224,18 +220,18 @@ public class SpongeUtil extends WorldUtil {
last = world;
return lastWorld = optional.get();
}
public static void removePlayer(final String player) {
public static void removePlayer(String player) {
lastPlayer = null;
lastPlotPlayer = null;
}
public static Location getLocation(final String world, final org.spongepowered.api.world.Location spawn) {
public static Location getLocation(String world, org.spongepowered.api.world.Location spawn) {
return new Location(world, spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ());
}
public static String getWorldName(final org.spongepowered.api.world.Location origin) {
final Extent extent = origin.getExtent();
public static String getWorldName(org.spongepowered.api.world.Location origin) {
Extent extent = origin.getExtent();
if (extent == lastWorld) {
return lastWorld.getName();
}
@ -245,13 +241,13 @@ public class SpongeUtil extends WorldUtil {
}
return null;
}
public static org.spongepowered.api.world.Location getLocation(final Location loc) {
final Optional<World> world = SpongeMain.THIS.getServer().getWorld(loc.getWorld());
public static org.spongepowered.api.world.Location<World> getLocation(Location location) {
Optional<World> world = SpongeMain.THIS.getServer().getWorld(location.getWorld());
if (!world.isPresent()) {
return null;
}
return new org.spongepowered.api.world.Location(world.get(), loc.getX(), loc.getY(), loc.getZ());
return new org.spongepowered.api.world.Location<>(world.get(), location.getX(), location.getY(), location.getZ());
}
public static Location getLocation(String world, Vector3i position) {
@ -263,8 +259,8 @@ public class SpongeUtil extends WorldUtil {
}
@Override
public boolean isBlockSolid(final PlotBlock block) {
final BlockState state = SpongeUtil.getBlockState(block.id, block.data);
public boolean isBlockSolid(PlotBlock block) {
BlockState state = SpongeUtil.getBlockState(block.id, block.data);
Optional<SolidCubeProperty> property = state.getType().getProperty(SolidCubeProperty.class);
if (property.isPresent()) {
return property.get().getValue();
@ -277,42 +273,42 @@ public class SpongeUtil extends WorldUtil {
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
try {
double match;
short id;
byte data;
final String[] split = name.split(":");
String[] split = name.split(":");
if (split.length == 2) {
data = Byte.parseByte(split[1]);
name = split[0];
} else {
data = 0;
}
short id;
double match;
if (MathMan.isInteger(split[0])) {
id = Short.parseShort(split[0]);
match = 0;
} else {
List<BlockType> types = ReflectionUtils.getStaticFields(BlockTypes.class);
final StringComparison<BlockType>.ComparisonResult comparison =
StringComparison<BlockType>.ComparisonResult comparison =
new StringComparison<BlockType>(name, types.toArray(new BlockType[types.size()])) {
@Override
public String getString(final BlockType type) {
public String getString(BlockType type) {
return type.getId();
}
}.getBestMatchAdvanced();
match = comparison.match;
id = SpongeUtil.getPlotBlock(comparison.best.getDefaultState()).id;
}
final PlotBlock block = new PlotBlock(id, data);
final StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
PlotBlock block = new PlotBlock(id, data);
StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
return outer.new ComparisonResult(match, block);
} catch (NumberFormatException e) {
} catch (NumberFormatException ignored) {
}
return null;
}
@Override
public String getClosestMatchingName(final PlotBlock block) {
public String getClosestMatchingName(PlotBlock block) {
// TODO Auto-generated method stub
return null;
}
@ -326,13 +322,13 @@ public class SpongeUtil extends WorldUtil {
}
@Override
public boolean addItems(final String world, final PlotItem items) {
public boolean addItems(String world, PlotItem items) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@Override
public int getBiomeFromString(final String biome) {
public int getBiomeFromString(String biome) {
if (biomes == null) {
initBiomeCache();
}
@ -340,28 +336,28 @@ public class SpongeUtil extends WorldUtil {
}
@Override
public String getBiome(final String world, final int x, final int z) {
public String getBiome(String world, int x, int z) {
return SpongeUtil.getWorld(world).getBiome(x, z).getName().toUpperCase();
}
@Override
public PlotBlock getBlock(final Location loc) {
final BlockState state = SpongeUtil.getWorld(loc.getWorld()).getBlock(loc.getX(), loc.getY(), loc.getZ());
public PlotBlock getBlock(Location location) {
BlockState state = SpongeUtil.getWorld(location.getWorld()).getBlock(location.getX(), location.getY(), location.getZ());
return SpongeUtil.getPlotBlock(state);
}
@Override
public Location getSpawn(final String world) {
final Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
public Location getSpawn(String world) {
Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
result.setY(getHighestBlock(world, result.getX(), result.getZ()));
return result;
}
@Override
public void setSpawn(Location loc) {
World world = getWorld(loc.getWorld());
public void setSpawn(Location location) {
World world = getWorld(location.getWorld());
if (world != null) {
world.getProperties().setSpawnPosition(new Vector3i(loc.getX(), loc.getY(), loc.getZ()));
world.getProperties().setSpawnPosition(new Vector3i(location.getX(), location.getY(), location.getZ()));
}
}
@ -371,22 +367,22 @@ public class SpongeUtil extends WorldUtil {
}
@Override
public String[] getSign(final Location loc) {
final World world = SpongeUtil.getWorld(loc.getWorld());
final Optional<TileEntity> block = world.getTileEntity(loc.getX(), loc.getY(), loc.getZ());
public String[] getSign(Location location) {
World world = SpongeUtil.getWorld(location.getWorld());
Optional<TileEntity> block = world.getTileEntity(location.getX(), location.getY(), location.getZ());
if (!block.isPresent()) {
return null;
}
final TileEntity tile = block.get();
TileEntity tile = block.get();
if (!(tile instanceof Sign)) {
return null;
}
final Sign sign = (Sign) tile;
final Optional<SignData> optional = sign.get(SignData.class);
Sign sign = (Sign) tile;
Optional<SignData> optional = sign.get(SignData.class);
if (!optional.isPresent()) {
return null;
}
final String[] result = new String[4];
String[] result = new String[4];
ListValue<Text> lines = optional.get().lines();
for (int i = 0; i < 4; i++) {
result[i] = lines.get(i).toString();
@ -395,7 +391,7 @@ public class SpongeUtil extends WorldUtil {
}
@Override
public boolean isWorld(final String world) {
public boolean isWorld(String world) {
return SpongeUtil.getWorld(world) != null;
}
@ -406,12 +402,12 @@ public class SpongeUtil extends WorldUtil {
@Override
public int getHighestBlock(String worldname, int x, int z) {
final World world = SpongeUtil.getWorld(worldname);
World world = SpongeUtil.getWorld(worldname);
if (world == null) {
return 64;
}
for (int y = 255; y > 0; y--) {
final BlockState block = world.getBlock(x, y, z);
BlockState block = world.getBlock(x, y, z);
if (block.getType() != BlockTypes.AIR) {
return y + 1;
}
@ -421,18 +417,18 @@ public class SpongeUtil extends WorldUtil {
@Override
public void setSign(String worldname, int x, int y, int z, String[] lines) {
final World world = SpongeUtil.getWorld(worldname);
World world = SpongeUtil.getWorld(worldname);
world.setBlock(x, y, z, BlockTypes.WALL_SIGN.getDefaultState());
final Optional<TileEntity> block = world.getTileEntity(x, y, z);
Optional<TileEntity> block = world.getTileEntity(x, y, z);
if (!block.isPresent()) {
return;
}
final TileEntity tile = block.get();
TileEntity tile = block.get();
if (!(tile instanceof Sign)) {
return;
}
final Sign sign = (Sign) tile;
final List<Text> text = new ArrayList<>(4);
Sign sign = (Sign) tile;
List<Text> text = new ArrayList<>(4);
for (int i = 0; i < 4; i++) {
text.add(SpongeUtil.getText(lines[i]));
}
@ -441,8 +437,8 @@ public class SpongeUtil extends WorldUtil {
@Override
public void setBiomes(String worldname, RegionWrapper region, String biomename) {
final World world = SpongeUtil.getWorld(worldname);
final BiomeType biome = SpongeUtil.getBiome(biomename);
World world = SpongeUtil.getWorld(worldname);
BiomeType biome = SpongeUtil.getBiome(biomename);
for (int x = region.minX; x <= region.maxX; x++) {
for (int z = region.minZ; z <= region.maxZ; z++) {
world.setBiome(x, z, biome);

View File

@ -1,6 +1,5 @@
package com.plotsquared.sponge.util.block;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.MainUtil;
@ -18,24 +17,29 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.World;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class FastQueue extends SlowQueue {
public HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
public final SendChunk chunkSender;
public HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
public FastQueue() throws NoSuchMethodException, RuntimeException {
TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {
if (toUpdate.isEmpty()) {
if (FastQueue.this.toUpdate.isEmpty()) {
return;
}
int count = 0;
final ArrayList<Chunk> chunks = new ArrayList<Chunk>();
final Iterator<Entry<ChunkWrapper, Chunk>> i = toUpdate.entrySet().iterator();
ArrayList<Chunk> chunks = new ArrayList<Chunk>();
Iterator<Entry<ChunkWrapper, Chunk>> i = FastQueue.this.toUpdate.entrySet().iterator();
while (i.hasNext() && (count < 128)) {
chunks.add(i.next().getValue());
i.remove();
@ -47,31 +51,31 @@ public class FastQueue extends SlowQueue {
update(chunks);
}
}, 1);
chunkSender = new SendChunk();
this.chunkSender = new SendChunk();
MainUtil.initCache();
}
public void update(final Collection<Chunk> chunks) {
public void update(Collection<Chunk> chunks) {
if (chunks.isEmpty()) {
return;
}
if (!MainUtil.canSendChunk) {
for (final Chunk chunk : chunks) {
for (Chunk chunk : chunks) {
chunk.unloadChunk();
chunk.loadChunk(false);
}
return;
}
try {
chunkSender.sendChunk(chunks);
} catch (final Throwable e) {
this.chunkSender.sendChunk(chunks);
} catch (Throwable e) {
e.printStackTrace();
MainUtil.canSendChunk = false;
}
}
/**
* This should be overridden by any specialized queues
* This should be overridden by any specialized queues.
* @param pc
*/
@Override
@ -80,12 +84,12 @@ public class FastQueue extends SlowQueue {
Chunk spongeChunk = pc.getChunk();
net.minecraft.world.World nmsWorld = (net.minecraft.world.World) spongeChunk.getWorld();
ChunkWrapper wrapper = pc.getChunkWrapper();
if (!toUpdate.containsKey(wrapper)) {
toUpdate.put(wrapper, spongeChunk);
if (!this.toUpdate.containsKey(wrapper)) {
this.toUpdate.put(wrapper, spongeChunk);
}
spongeChunk.loadChunk(true);
try {
final boolean flag = !nmsWorld.provider.getHasNoSky();
boolean flag = !nmsWorld.provider.getHasNoSky();
// Sections
net.minecraft.world.chunk.Chunk nmsChunk = (net.minecraft.world.chunk.Chunk) spongeChunk;
ExtendedBlockStorage[] sections = nmsChunk.getBlockStorageArray();
@ -97,12 +101,12 @@ public class FastQueue extends SlowQueue {
while (iter.hasNext()) {
Entry<BlockPos,TileEntity> tile = iter.next();
BlockPos pos = tile.getKey();
final int lx = pos.getX() & 15;
final int ly = pos.getY();
final int lz = pos.getZ() & 15;
final int j = MainUtil.CACHE_I[ly][lx][lz];
final int k = MainUtil.CACHE_J[ly][lx][lz];
final char[] array = fs.getIdArray(j);
int lx = pos.getX() & 15;
int ly = pos.getY();
int lz = pos.getZ() & 15;
int j = MainUtil.CACHE_I[ly][lx][lz];
int k = MainUtil.CACHE_J[ly][lx][lz];
char[] array = fs.getIdArray(j);
if (array == null) {
continue;
}
@ -121,7 +125,7 @@ public class FastQueue extends SlowQueue {
if (fs.getCount(j) == 0) {
continue;
}
final char[] newArray = fs.getIdArray(j);
char[] newArray = fs.getIdArray(j);
if (newArray == null) {
continue;
}
@ -132,10 +136,10 @@ public class FastQueue extends SlowQueue {
sections[j] = section;
continue;
}
final char[] currentArray = section.getData();
char[] currentArray = section.getData();
boolean fill = true;
for (int k = 0; k < newArray.length; k++) {
final char n = newArray[k];
char n = newArray[k];
switch (n) {
case 0:
fill = false;
@ -176,7 +180,7 @@ public class FastQueue extends SlowQueue {
}
/**
* This should be overridden by any specialized queues
* This should be overridden by any specialized queues.
* @param wrap
*/
@Override
@ -185,15 +189,15 @@ public class FastQueue extends SlowQueue {
}
/**
* This should be overridden by any specialized queues
* This should be overridden by any specialized queues.
* @param pc
*/
@Override
public boolean fixLighting(PlotChunk<Chunk> pc, boolean fixAll) {
try {
FastChunk bc = (FastChunk) pc;
final Chunk spongeChunk = bc.getChunk();
final net.minecraft.world.chunk.Chunk nmsChunk = (net.minecraft.world.chunk.Chunk) spongeChunk;
Chunk spongeChunk = bc.getChunk();
net.minecraft.world.chunk.Chunk nmsChunk = (net.minecraft.world.chunk.Chunk) spongeChunk;
if (!spongeChunk.isLoaded()) {
if (!spongeChunk.loadChunk(false)) {
return false;
@ -204,14 +208,14 @@ public class FastQueue extends SlowQueue {
}
// TODO load adjaced chunks
nmsChunk.generateSkylightMap();
if ((bc.getTotalRelight() == 0 && !fixAll)) {
if (bc.getTotalRelight() == 0 && !fixAll) {
return true;
}
ExtendedBlockStorage[] sections = nmsChunk.getBlockStorageArray();
net.minecraft.world.World nmsWorld = nmsChunk.getWorld();
final int X = pc.getX() << 4;
final int Z = pc.getZ() << 4;
int X = pc.getX() << 4;
int Z = pc.getZ() << 4;
for (int j = 0; j < sections.length; j++) {
@ -222,14 +226,14 @@ public class FastQueue extends SlowQueue {
if ((bc.getRelight(j) == 0 && !fixAll) || bc.getCount(j) == 0 || (bc.getCount(j) >= 4096 && bc.getAir(j) == 0)) {
continue;
}
final char[] array = section.getData();
char[] array = section.getData();
int l = PseudoRandom.random.random(2);
for (int k = 0; k < array.length; k++) {
final int i = array[k];
int i = array[k];
if (i < 16) {
continue;
}
final short id = (short) (i >> 4);
short id = (short) (i >> 4);
switch (id) { // Lighting
default:
if (!fixAll) {
@ -254,9 +258,9 @@ public class FastQueue extends SlowQueue {
case 130:
case 138:
case 169:
final int x = MainUtil.x_loc[j][k];
final int y = MainUtil.y_loc[j][k];
final int z = MainUtil.z_loc[j][k];
int x = MainUtil.x_loc[j][k];
int y = MainUtil.y_loc[j][k];
int z = MainUtil.z_loc[j][k];
if (isSurrounded(sections, x, y, z)) {
continue;
}
@ -266,7 +270,7 @@ public class FastQueue extends SlowQueue {
}
}
return true;
} catch (final Throwable e) {
} catch (Throwable e) {
e.printStackTrace();
}
return false;
@ -302,17 +306,17 @@ public class FastQueue extends SlowQueue {
}
/**
* This should be overridden by any specialized queues
* This should be overridden by any specialized queues.
* @param world
* @param locs
* @param locations
*/
@Override
public void sendChunk(String world, Collection<ChunkLoc> locs) {
public void sendChunk(String world, Collection<ChunkLoc> locations) {
World spongeWorld = SpongeUtil.getWorld(world);
for (ChunkLoc loc : locs) {
for (ChunkLoc loc : locations) {
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
if (!toUpdate.containsKey(wrapper)) {
toUpdate.put(wrapper, spongeWorld.getChunk(loc.x, 0, loc.z).get());
if (!this.toUpdate.containsKey(wrapper)) {
this.toUpdate.put(wrapper, spongeWorld.getChunk(loc.x, 0, loc.z).get());
}
}
}

View File

@ -8,18 +8,18 @@ import org.spongepowered.api.world.extent.MutableBiomeArea;
import org.spongepowered.api.world.extent.MutableBlockVolume;
public class GenChunk extends PlotChunk<Chunk> {
public boolean modified = false;
private final MutableBlockVolume terain;
private final MutableBlockVolume terrain;
private final MutableBiomeArea biome;
private final int bz;
private final int bx;
public GenChunk(MutableBlockVolume terain, MutableBiomeArea biome, ChunkWrapper wrap) {
public boolean modified = false;
public GenChunk(MutableBlockVolume terrain, MutableBiomeArea biome, ChunkWrapper wrap) {
super(wrap);
this.bx = wrap.x << 4;
this.bz = wrap.z << 4;
this.terain = terain;
this.terrain = terrain;
this.biome = biome;
}
@ -32,13 +32,13 @@ public class GenChunk extends PlotChunk<Chunk> {
@Override
public void setBiome(int x, int z, int biome) {
if (this.biome != null) {
this.biome.setBiome(bx + x, bz + z, SpongeUtil.getBiome(biome));
this.biome.setBiome(this.bx + x, this.bz + z, SpongeUtil.getBiome(biome));
}
}
@Override
public void setBlock(int x, int y, int z, int id, byte data) {
terain.setBlock(bx + x, y, bz + z, SpongeUtil.getBlockState(id, data));
this.terrain.setBlock(this.bx + x, y, this.bz + z, SpongeUtil.getBlockState(id, data));
}
@Override