mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 10:56:42 +00:00
More general-purpose vector code abstracted from craftbook and more convenience methods for conversion.
This commit is contained in:
@ -19,27 +19,42 @@
|
||||
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.block.Block;
|
||||
import java.util.*;
|
||||
|
||||
import org.bukkit.block.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
public class BukkitUtil {
|
||||
private BukkitUtil() {
|
||||
}
|
||||
|
||||
public static Location toLocation(World world, Vector loc) {
|
||||
return new Location(world, loc.getX(), loc.getY(), loc.getZ());
|
||||
private static final Map<World,LocalWorld> wlw = new HashMap<World,LocalWorld>();
|
||||
public static LocalWorld getLocalWorld(World w) {
|
||||
LocalWorld lw = wlw.get(w);
|
||||
if (lw == null) {
|
||||
lw = new BukkitWorld(w);
|
||||
wlw.put(w, lw);
|
||||
}
|
||||
return lw;
|
||||
}
|
||||
|
||||
public static BlockVector toVector(Block block) {
|
||||
return new BlockVector(block.getX(), block.getY(), block.getZ());
|
||||
}
|
||||
|
||||
public static BlockVector toVector(BlockFace face) {
|
||||
return new BlockVector(face.getModX(), face.getModY(), face.getModZ());
|
||||
}
|
||||
|
||||
public static BlockWorldVector toWorldVector(Block block) {
|
||||
return new BlockWorldVector(getLocalWorld(block.getWorld()), block.getX(), block.getY(), block.getZ());
|
||||
}
|
||||
|
||||
public static Vector toVector(Location loc) {
|
||||
return new Vector(loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
@ -48,6 +63,10 @@ public class BukkitUtil {
|
||||
return new Vector(vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
public static Location toLocation(WorldVector pt) {
|
||||
return new Location(toWorld(pt), pt.getX(), pt.getY(), pt.getZ());
|
||||
}
|
||||
|
||||
public static Player matchSinglePlayer(Server server, String name) {
|
||||
List<Player> players = server.matchPlayer(name);
|
||||
if (players.size() == 0) {
|
||||
@ -55,4 +74,12 @@ public class BukkitUtil {
|
||||
}
|
||||
return players.get(0);
|
||||
}
|
||||
|
||||
public static Block toBlock(BlockWorldVector pt) {
|
||||
return toWorld(pt).getBlockAt(toLocation(pt));
|
||||
}
|
||||
|
||||
public static World toWorld(WorldVector pt) {
|
||||
return ((BukkitWorld)pt.getWorld()).getWorld();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user