2015-07-30 16:25:16 +02:00
|
|
|
package com.plotsquared.sponge.util;
|
|
|
|
|
|
|
|
import org.spongepowered.api.entity.Entity;
|
2015-09-06 03:53:56 +02:00
|
|
|
import org.spongepowered.api.entity.player.Player;
|
2015-07-30 16:25:16 +02:00
|
|
|
import org.spongepowered.api.world.World;
|
|
|
|
import org.spongepowered.api.world.extent.Extent;
|
|
|
|
|
|
|
|
import com.flowpowered.math.vector.Vector3d;
|
|
|
|
import com.flowpowered.math.vector.Vector3i;
|
|
|
|
import com.google.common.base.Optional;
|
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.util.MathMan;
|
|
|
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
|
|
import com.plotsquared.sponge.SpongeMain;
|
2015-07-30 19:24:01 +02:00
|
|
|
import com.plotsquared.sponge.object.SpongePlayer;
|
2015-07-30 16:25:16 +02:00
|
|
|
|
|
|
|
public class SpongeUtil {
|
|
|
|
|
|
|
|
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 Location getLocation(org.spongepowered.api.world.Location block) {
|
|
|
|
Extent extent = block.getExtent();
|
|
|
|
if (extent instanceof World) {
|
|
|
|
return getLocation(((World) extent).getName(), block);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
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(Player player) {
|
|
|
|
if (player == lastPlayer) {
|
|
|
|
return lastPlotPlayer;
|
|
|
|
}
|
|
|
|
String name = player.getName();
|
|
|
|
PlotPlayer pp = UUIDHandler.getPlayers().get(name);
|
|
|
|
if (pp != null) {
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
lastPlotPlayer = new SpongePlayer(player);
|
|
|
|
UUIDHandler.getPlayers().put(name, lastPlotPlayer);
|
|
|
|
lastPlayer = player;
|
|
|
|
return lastPlotPlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Player getPlayer(PlotPlayer player) {
|
|
|
|
if (player instanceof SpongePlayer) {
|
|
|
|
return ((SpongePlayer) player).player;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-08-03 20:20:04 +02:00
|
|
|
|
|
|
|
private static World lastWorld;
|
|
|
|
private static String last;
|
2015-07-30 16:25:16 +02:00
|
|
|
|
|
|
|
public static World getWorld(String world) {
|
2015-08-03 20:20:04 +02:00
|
|
|
if (world == last) {
|
|
|
|
return lastWorld;
|
|
|
|
}
|
2015-07-30 16:25:16 +02:00
|
|
|
Optional<World> optional = SpongeMain.THIS.getServer().getWorld(world);
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return optional.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removePlayer(String player) {
|
|
|
|
lastPlayer = null;
|
|
|
|
lastPlotPlayer = null;
|
|
|
|
UUIDHandler.getPlayers().remove(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Location getLocation(String world, org.spongepowered.api.world.Location spawn) {
|
|
|
|
return new Location(world, spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ());
|
|
|
|
}
|
2015-08-11 20:04:17 +02:00
|
|
|
|
|
|
|
public static String getWorldName(org.spongepowered.api.world.Location origin) {
|
|
|
|
Extent extent = origin.getExtent();
|
|
|
|
if (extent == lastWorld) {
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
if (extent instanceof World) {
|
|
|
|
lastWorld = (World) extent;
|
|
|
|
last = ((World) extent).getName();
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-08-14 00:52:31 +02:00
|
|
|
|
|
|
|
public static org.spongepowered.api.world.Location getLocation(Location loc) {
|
|
|
|
Optional<World> world = SpongeMain.THIS.getServer().getWorld(loc.getWorld());
|
|
|
|
if (!world.isPresent()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return new org.spongepowered.api.world.Location(world.get(), loc.getX(), loc.getY(), loc.getZ());
|
|
|
|
}
|
2015-07-30 16:25:16 +02:00
|
|
|
}
|