Minor cleanup

This commit is contained in:
Jesse Boyd 2017-04-09 14:19:03 +10:00
parent 1d02901e39
commit 4229665e14
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
9 changed files with 55 additions and 64 deletions

View File

@ -41,6 +41,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.ChunkLoadEvent;
@ -146,7 +147,8 @@ public class FaweBukkit implements IFawe, Listener {
if (existing != null) {
return existing;
}
return new BukkitPlayer(Bukkit.getPlayer(name));
Player player = Bukkit.getPlayer(name);
return player != null ? new BukkitPlayer(player) : null;
} else if (obj instanceof Player) {
Player player = (Player) obj;
FawePlayer existing = Fawe.get().getCachedPlayer(player.getName());
@ -404,7 +406,7 @@ public class FaweBukkit implements IFawe, Listener {
SetQueue.IMP.runMiscTasks();
}
@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
FawePlayer fp = FawePlayer.wrap(player);

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.bukkit;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.wrappers.WorldWrapper;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
@ -43,6 +44,7 @@ import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Dye;
@ -153,8 +155,13 @@ public class BukkitPlayer extends LocalPlayer {
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(),
pos.getZ(), yaw, pitch));
World world;
if (pos instanceof WorldVector) {
world = ((BukkitWorld) WorldWrapper.unwrap(((WorldVector) pos).getWorld())).getWorld();
} else {
world = player.getWorld();
}
player.teleport(new Location(world, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch));
}
@Override

View File

@ -163,6 +163,10 @@ public class Config {
private HashMap<String, T> INSTANCES = new HashMap<>();
public T remove(String key) {
return INSTANCES.remove(key);
}
public T get(String key) {
return INSTANCES.get(key);
}
@ -253,7 +257,7 @@ public class Config {
}
}
BlockName blockNames = current.getAnnotation(BlockName.class);
if (blockNames != null) {
if (blockNames != null) {
writer.write(spacing + toNodeName(current.getSimpleName()) + ":" + CTRF);
ConfigBlock configBlock = (ConfigBlock) field.get(instance);
if (configBlock == null || configBlock.getInstances().isEmpty()) {

View File

@ -1,5 +1,7 @@
package com.boydti.fawe.util;
import java.util.Arrays;
public class ArrayUtil {
public static final void fill(byte[] a, int fromIndex, int toIndex, byte val) {
for (int i = fromIndex; i < toIndex; i++) a[i] = val;
@ -8,4 +10,18 @@ public class ArrayUtil {
public static final void fill(char[] a, int fromIndex, int toIndex, char val) {
for (int i = fromIndex; i < toIndex; i++) a[i] = val;
}
public static <T> T[] concatAll(T[] first, T[]... rest) {
int totalLength = first.length;
for (T[] array : rest) {
totalLength += array.length;
}
T[] result = Arrays.copyOf(first, totalLength);
int offset = first.length;
for (T[] array : rest) {
System.arraycopy(array, 0, result, offset, array.length);
offset += array.length;
}
return result;
}
}

View File

@ -80,34 +80,7 @@ public class PlayerWrapper extends AbstractPlayerActor {
TaskManager.IMP.sync(new RunnableVal<Boolean>() {
@Override
public void run(Boolean value) {
World world = searchPos.getWorld();
int x = searchPos.getBlockX();
int y = Math.max(0, searchPos.getBlockY());
int origY = y;
int z = searchPos.getBlockZ();
byte free = 0;
while (y <= world.getMaxY() + 2) {
if (BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) {
++free;
} else {
free = 0;
}
if (free == 2) {
if (y - 1 != origY) {
final Vector pos = new Vector(x, y - 2, z);
final int id = world.getBlockType(pos);
final int data = world.getBlockData(pos);
setPosition(new WorldVector((LocalWorld) world, x + 0.5, y - 2 + BlockType.centralTopLimit(id, data), z + 0.5));
}
return;
}
++y;
}
PlayerWrapper.super.findFreePosition(searchPos);
}
});
}
@ -117,22 +90,7 @@ public class PlayerWrapper extends AbstractPlayerActor {
TaskManager.IMP.sync(new RunnableVal<Boolean>() {
@Override
public void run(Boolean value) {
World world = searchPos.getWorld();
int x = searchPos.getBlockX();
int y = Math.max(0, searchPos.getBlockY());
int z = searchPos.getBlockZ();
while (y >= 0) {
final Vector pos = new Vector(x, y, z);
final int id = world.getBlockType(pos);
final int data = world.getBlockData(pos);
if (!BlockType.canPassThrough(id, data)) {
setPosition(new WorldVector((LocalWorld) world, x + 0.5, y + BlockType.centralTopLimit(id, data), z + 0.5));
return;
}
--y;
}
PlayerWrapper.super.setOnGround(searchPos);
}
});
}

View File

@ -23,6 +23,7 @@ import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.registry.WorldData;
import java.util.List;
@ -42,6 +43,13 @@ public class WorldWrapper extends LocalWorld {
return new WorldWrapper(world);
}
public static World unwrap(World world) {
if (world instanceof WorldWrapper) {
return ((WorldWrapper) world).getParent();
}
return world;
}
private WorldWrapper(AbstractWorld parent) {
this.parent = parent;
}

View File

@ -379,12 +379,12 @@ public class SchematicCommands {
private List<File> allFiles(File root, boolean recursive) {
File[] files = root.listFiles();
if (files == null) return null;
if (files == null) return new ArrayList<>();
List<File> fileList = new ArrayList<File>();
for (File f : files) {
if (recursive && f.isDirectory()) {
List<File> subFiles = allFiles(f, recursive);
if (subFiles == null) continue; // empty subdir
if (subFiles == null || subFiles.isEmpty()) continue; // empty subdir
fileList.addAll(subFiles);
} else {
fileList.add(f);

View File

@ -21,6 +21,7 @@ package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.BlockWorldVector;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.PlayerDirection;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
@ -92,7 +93,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public void findFreePosition(WorldVector searchPos) {
World world = searchPos.getWorld();
LocalWorld world = searchPos.getWorld();
int x = searchPos.getBlockX();
int y = Math.max(0, searchPos.getBlockY());
int origY = y;
@ -108,23 +109,21 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
}
if (free == 2) {
if (y - 1 != origY) {
final Vector pos = new Vector(x, y - 2, z);
final int id = world.getBlockType(pos);
final int data = world.getBlockData(pos);
setPosition(new Vector(x + 0.5, y - 2 + BlockType.centralTopLimit(id, data), z + 0.5));
}
final Vector pos = new Vector(x, y - 2, z);
final int id = world.getBlockType(pos);
final int data = world.getBlockData(pos);
setPosition(new WorldVector(world, x + 0.5, y - 2 + BlockType.centralTopLimit(id, data), z + 0.5));
return;
}
++y;
}
System.out.println("Not found");
}
@Override
public void setOnGround(WorldVector searchPos) {
World world = searchPos.getWorld();
LocalWorld world = searchPos.getWorld();
int x = searchPos.getBlockX();
int y = Math.max(0, searchPos.getBlockY());
int z = searchPos.getBlockZ();
@ -134,7 +133,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
final int id = world.getBlockType(pos);
final int data = world.getBlockData(pos);
if (!BlockType.canPassThrough(id, data)) {
setPosition(new Vector(x + 0.5, y + BlockType.centralTopLimit(id, data), z + 0.5));
setPosition(new WorldVector(world, x + 0.5, y + BlockType.centralTopLimit(id, data), z + 0.5));
return;
}

View File

@ -186,7 +186,6 @@ public final class CommandManager {
Dispatcher dispatcher = graph.graph().getDispatcher();
platform.registerCommands(dispatcher);
} else {
System.out.println("Put in method map " + clazz);
methodMap.put(clazz, aliases);
}
}
@ -195,7 +194,6 @@ public final class CommandManager {
* Initialize the dispatcher
*/
public void setupDispatcher() {
System.out.println("Setup dispatcher!");
ParametricBuilder builder = new ParametricBuilder();
builder.setAuthorizer(new ActorAuthorizer());
builder.setDefaultCompleter(new UserCommandCompleter(platformManager));
@ -212,7 +210,6 @@ public final class CommandManager {
// add command
String[] aliases = entry.getValue();
if (aliases.length == 0) {
System.out.println("Add class " + entry.getKey());
graph = graph.registerMethods(entry.getKey());
} else {
graph = graph.group(aliases).registerMethods(entry.getKey()).parent();