mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-24 02:07:39 +00:00
More general-purpose vector code abstracted from craftbook and more convenience methods for conversion.
This commit is contained in:
parent
0f4d331e7a
commit
e6f3a1b5af
@ -44,6 +44,28 @@ public class BlockWorldVector extends WorldVector {
|
|||||||
super(world, pt);
|
super(world, pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the Vector object.
|
||||||
|
*
|
||||||
|
* @param world
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
* @param z
|
||||||
|
*/
|
||||||
|
public BlockWorldVector(WorldVector world, int x, int y, int z) {
|
||||||
|
super(world.getWorld(), x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the Vector object.
|
||||||
|
*
|
||||||
|
* @param world
|
||||||
|
* @param v
|
||||||
|
*/
|
||||||
|
public BlockWorldVector(WorldVector world, Vector v) {
|
||||||
|
super(world.getWorld(), v.x, v.y, v.z);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the Vector object.
|
* Construct the Vector object.
|
||||||
*
|
*
|
||||||
|
@ -19,27 +19,42 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.bukkit;
|
package com.sk89q.worldedit.bukkit;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
|
import org.bukkit.block.*;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.*;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
|
|
||||||
public class BukkitUtil {
|
public class BukkitUtil {
|
||||||
private BukkitUtil() {
|
private BukkitUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location toLocation(World world, Vector loc) {
|
private static final Map<World,LocalWorld> wlw = new HashMap<World,LocalWorld>();
|
||||||
return new Location(world, loc.getX(), loc.getY(), loc.getZ());
|
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) {
|
public static BlockVector toVector(Block block) {
|
||||||
return new BlockVector(block.getX(), block.getY(), block.getZ());
|
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) {
|
public static Vector toVector(Location loc) {
|
||||||
return new Vector(loc.getX(), loc.getY(), loc.getZ());
|
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());
|
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) {
|
public static Player matchSinglePlayer(Server server, String name) {
|
||||||
List<Player> players = server.matchPlayer(name);
|
List<Player> players = server.matchPlayer(name);
|
||||||
if (players.size() == 0) {
|
if (players.size() == 0) {
|
||||||
@ -55,4 +74,12 @@ public class BukkitUtil {
|
|||||||
}
|
}
|
||||||
return players.get(0);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user