2015-07-30 16:25:16 +02:00
|
|
|
package com.plotsquared.sponge.util;
|
|
|
|
|
2016-02-23 15:55:40 +01:00
|
|
|
import com.flowpowered.math.vector.Vector3d;
|
|
|
|
import com.flowpowered.math.vector.Vector3i;
|
|
|
|
import com.intellectualcrafters.plot.PS;
|
2016-02-25 10:13:07 +01:00
|
|
|
import com.intellectualcrafters.plot.config.C;
|
2016-02-23 15:55:40 +01:00
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.RegionWrapper;
|
|
|
|
import com.intellectualcrafters.plot.object.schematic.PlotItem;
|
2016-03-01 02:13:18 +01:00
|
|
|
import com.intellectualcrafters.plot.util.MathMan;
|
|
|
|
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
|
|
|
import com.intellectualcrafters.plot.util.StringComparison;
|
|
|
|
import com.intellectualcrafters.plot.util.StringMan;
|
|
|
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
|
|
import com.intellectualcrafters.plot.util.WorldUtil;
|
2016-02-23 15:55:40 +01:00
|
|
|
import com.plotsquared.sponge.SpongeMain;
|
|
|
|
import com.plotsquared.sponge.object.SpongePlayer;
|
|
|
|
import net.minecraft.block.Block;
|
2016-06-03 01:38:35 +02:00
|
|
|
import net.minecraft.world.biome.Biome;
|
2016-02-19 20:55:49 +01:00
|
|
|
import org.spongepowered.api.Sponge;
|
2016-02-19 19:52:26 +01:00
|
|
|
import org.spongepowered.api.block.BlockState;
|
2016-02-19 20:55:49 +01:00
|
|
|
import org.spongepowered.api.block.BlockType;
|
|
|
|
import org.spongepowered.api.block.BlockTypes;
|
|
|
|
import org.spongepowered.api.block.tileentity.Sign;
|
|
|
|
import org.spongepowered.api.block.tileentity.TileEntity;
|
2016-02-23 15:55:40 +01:00
|
|
|
import org.spongepowered.api.data.key.Keys;
|
2016-02-19 20:55:49 +01:00
|
|
|
import org.spongepowered.api.data.manipulator.mutable.tileentity.SignData;
|
2016-02-23 15:55:40 +01:00
|
|
|
import org.spongepowered.api.data.property.block.SolidCubeProperty;
|
2016-02-19 20:55:49 +01:00
|
|
|
import org.spongepowered.api.data.value.mutable.ListValue;
|
2015-07-30 16:25:16 +02:00
|
|
|
import org.spongepowered.api.entity.Entity;
|
2015-10-07 08:33:33 +02:00
|
|
|
import org.spongepowered.api.entity.living.player.Player;
|
2016-02-22 07:20:22 +01:00
|
|
|
import org.spongepowered.api.event.cause.Cause;
|
2016-03-12 17:57:24 +01:00
|
|
|
import org.spongepowered.api.event.cause.NamedCause;
|
2016-02-19 19:52:26 +01:00
|
|
|
import org.spongepowered.api.text.Text;
|
2016-02-25 10:13:07 +01:00
|
|
|
import org.spongepowered.api.text.serializer.TextSerializers;
|
2016-02-19 19:52:26 +01:00
|
|
|
import org.spongepowered.api.text.translation.Translation;
|
2015-07-30 16:25:16 +02:00
|
|
|
import org.spongepowered.api.world.World;
|
2016-02-19 19:52:26 +01:00
|
|
|
import org.spongepowered.api.world.biome.BiomeType;
|
|
|
|
import org.spongepowered.api.world.biome.BiomeTypes;
|
2015-07-30 16:25:16 +02:00
|
|
|
import org.spongepowered.api.world.extent.Extent;
|
|
|
|
|
2016-06-03 01:38:35 +02:00
|
|
|
import java.io.IOException;
|
2016-04-05 18:37:11 +02:00
|
|
|
import java.lang.reflect.Field;
|
2016-04-26 16:14:22 +02:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2016-04-05 18:37:11 +02:00
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Optional;
|
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
public class SpongeUtil extends WorldUtil {
|
2016-03-12 17:57:24 +01:00
|
|
|
|
|
|
|
public static Cause CAUSE = Cause.of(NamedCause.source("PlotSquared"));
|
2016-03-23 02:41:37 +01:00
|
|
|
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;
|
2016-03-12 17:57:24 +01:00
|
|
|
|
2016-03-23 02:41:37 +01:00
|
|
|
public static Location getLocation(Entity player) {
|
|
|
|
String world = player.getWorld().getName();
|
|
|
|
org.spongepowered.api.world.Location loc = player.getLocation();
|
|
|
|
Vector3i pos = loc.getBlockPosition();
|
2015-07-30 16:25:16 +02:00
|
|
|
return new Location(world, pos.getX(), pos.getY(), pos.getZ());
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
public static BiomeType getBiome(String biome) {
|
2016-02-19 19:52:26 +01:00
|
|
|
if (biomes == null) {
|
2016-02-19 20:55:49 +01:00
|
|
|
initBiomeCache();
|
|
|
|
}
|
|
|
|
return biomes[biomeMap.get(biome.toUpperCase())];
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2016-02-22 07:20:22 +01:00
|
|
|
public static <T> T getCause(Cause cause, Class<T> clazz) {
|
|
|
|
Optional<?> root = Optional.of(cause.root());
|
|
|
|
if (root.isPresent()) {
|
|
|
|
Object source = root.get();
|
|
|
|
if (clazz.isInstance(source)) {
|
|
|
|
return (T) source;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void printCause(String method, Cause cause) {
|
|
|
|
System.out.println(method + ": " + cause.toString());
|
|
|
|
System.out.println(method + ": " + cause.getClass());
|
|
|
|
System.out.println(method + ": " + StringMan.getString(cause.all()));
|
2016-03-21 00:35:40 +01:00
|
|
|
System.out.println(method + ": " + cause.root());
|
2016-02-22 07:20:22 +01:00
|
|
|
}
|
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
public static void initBiomeCache() {
|
|
|
|
try {
|
|
|
|
Field[] fields = BiomeTypes.class.getFields();
|
|
|
|
biomes = new BiomeType[fields.length];
|
|
|
|
biomeMap = new HashMap<>();
|
|
|
|
for (int i = 0; i < fields.length; i++) {
|
|
|
|
Field field = fields[i];
|
|
|
|
String name = field.getName();
|
|
|
|
biomeMap.put(name, i);
|
|
|
|
biomes[i] = (BiomeType) field.get(null);
|
2016-02-19 19:52:26 +01:00
|
|
|
}
|
2016-02-23 15:55:40 +01:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BiomeType getBiome(int index) {
|
2016-06-03 01:38:35 +02:00
|
|
|
return (BiomeType) Biome.getBiome(index);
|
2016-02-19 19:52:26 +01:00
|
|
|
}
|
2016-02-23 15:55:40 +01:00
|
|
|
|
2016-02-25 10:13:07 +01:00
|
|
|
public static Text getText(String m) {
|
|
|
|
return TextSerializers.LEGACY_FORMATTING_CODE.deserialize(C.color(m));
|
|
|
|
}
|
|
|
|
|
2016-03-23 02:41:37 +01:00
|
|
|
public static Translation getTranslation(String m) {
|
2016-03-01 02:13:18 +01:00
|
|
|
return new Translation() {
|
|
|
|
|
2016-02-19 19:52:26 +01:00
|
|
|
@Override
|
2016-03-01 02:13:18 +01:00
|
|
|
public String getId() {
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public String get(Locale l, Object... args) {
|
2016-03-01 02:13:18 +01:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public String get(Locale l) {
|
2016-03-01 02:13:18 +01:00
|
|
|
return m;
|
2016-02-19 19:52:26 +01:00
|
|
|
}
|
2016-03-01 02:13:18 +01:00
|
|
|
};
|
2016-02-19 19:52:26 +01:00
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-22 07:20:22 +01:00
|
|
|
private static void initBlockCache() {
|
|
|
|
try {
|
|
|
|
PS.debug("Caching block id/data: Please wait...");
|
|
|
|
stateArray = new BlockState[Character.MAX_VALUE];
|
|
|
|
stateMap = new HashMap<>();
|
2016-04-30 00:14:12 +02:00
|
|
|
Method methodGetByCombinedId = ReflectionUtils
|
|
|
|
.findMethod(Class.forName("net.minecraft.block.Block"), true, Class.forName("net.minecraft.block.state.IBlockState"), int.class);
|
2016-02-22 07:20:22 +01:00
|
|
|
for (int i = 0; i < Character.MAX_VALUE; i++) {
|
|
|
|
try {
|
|
|
|
BlockState state = (BlockState) methodGetByCombinedId.invoke(null, i);
|
|
|
|
if (state.getType() == BlockTypes.AIR) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-06-03 22:20:13 +02:00
|
|
|
PlotBlock plotBlock = PlotBlock.get((short) (i & 0xFFF), (byte) (i >> 12 & 0xF));
|
2016-02-22 07:20:22 +01:00
|
|
|
stateArray[i] = state;
|
|
|
|
stateMap.put(state, plotBlock);
|
2016-04-26 16:14:22 +02:00
|
|
|
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {
|
|
|
|
}
|
2016-02-22 07:20:22 +01:00
|
|
|
}
|
|
|
|
PS.debug("Done!");
|
2016-04-30 00:14:12 +02:00
|
|
|
} catch (ClassNotFoundException e) {
|
2016-02-22 07:20:22 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2016-02-19 19:52:26 +01:00
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-22 07:20:22 +01:00
|
|
|
public static BlockState getBlockState(int id, int data) {
|
2016-02-23 15:55:40 +01:00
|
|
|
return (BlockState) Block.getBlockById(id).getStateFromMeta(data);
|
2016-02-22 07:20:22 +01:00
|
|
|
}
|
|
|
|
|
2016-02-19 19:52:26 +01:00
|
|
|
public static PlotBlock getPlotBlock(BlockState state) {
|
2016-02-22 07:20:22 +01:00
|
|
|
if (stateMap == null) {
|
|
|
|
initBlockCache();
|
|
|
|
}
|
|
|
|
return stateMap.get(state);
|
2016-02-19 19:52:26 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 02:41:37 +01:00
|
|
|
public static Location getLocation(org.spongepowered.api.world.Location<World> block) {
|
2015-10-07 08:33:33 +02:00
|
|
|
return getLocation(block.getExtent().getName(), block);
|
2015-07-30 16:25:16 +02:00
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
|
|
|
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();
|
2015-07-30 16:25:16 +02:00
|
|
|
return new Location(world, pos.getX(), pos.getY(), pos.getZ(), pitchYaw[1], pitchYaw[0]);
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
|
|
|
public static PlotPlayer getPlayer(Player player) {
|
2015-09-13 06:04:31 +02:00
|
|
|
if (player == lastPlayer) {
|
|
|
|
return lastPlotPlayer;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
String name = player.getName();
|
|
|
|
PlotPlayer pp = UUIDHandler.getPlayer(name);
|
2015-09-13 06:04:31 +02:00
|
|
|
if (pp != null) {
|
|
|
|
return pp;
|
|
|
|
}
|
2015-07-30 16:25:16 +02:00
|
|
|
lastPlotPlayer = new SpongePlayer(player);
|
|
|
|
UUIDHandler.getPlayers().put(name, lastPlotPlayer);
|
|
|
|
lastPlayer = player;
|
|
|
|
return lastPlotPlayer;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
|
|
|
public static Player getPlayer(PlotPlayer player) {
|
2015-09-13 06:04:31 +02:00
|
|
|
if (player instanceof SpongePlayer) {
|
|
|
|
return ((SpongePlayer) player).player;
|
|
|
|
}
|
2015-07-30 16:25:16 +02:00
|
|
|
return null;
|
|
|
|
}
|
2016-02-23 15:55:40 +01:00
|
|
|
|
2016-03-23 02:41:37 +01:00
|
|
|
public static World getWorld(String world) {
|
2016-02-23 19:12:07 +01:00
|
|
|
if (StringMan.isEqual(world, last)) {
|
2015-09-13 06:04:31 +02:00
|
|
|
return lastWorld;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
Optional<World> optional = Sponge.getServer().getWorld(world);
|
2015-09-13 06:04:31 +02:00
|
|
|
if (!optional.isPresent()) {
|
2016-02-23 19:12:07 +01:00
|
|
|
last = null;
|
|
|
|
return lastWorld = null;
|
2015-09-13 06:04:31 +02:00
|
|
|
}
|
2016-02-23 19:12:07 +01:00
|
|
|
last = world;
|
|
|
|
return lastWorld = optional.get();
|
2015-07-30 16:25:16 +02:00
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
|
|
|
public static void removePlayer(String player) {
|
2015-07-30 16:25:16 +02:00
|
|
|
lastPlayer = null;
|
|
|
|
lastPlotPlayer = null;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
|
|
|
public static Location getLocation(String world, org.spongepowered.api.world.Location spawn) {
|
2015-07-30 16:25:16 +02:00
|
|
|
return new Location(world, spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ());
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
|
|
|
public static String getWorldName(org.spongepowered.api.world.Location origin) {
|
|
|
|
Extent extent = origin.getExtent();
|
2015-09-13 06:04:31 +02:00
|
|
|
if (extent == lastWorld) {
|
2016-02-23 15:55:40 +01:00
|
|
|
return lastWorld.getName();
|
2015-09-13 06:04:31 +02:00
|
|
|
}
|
|
|
|
if (extent instanceof World) {
|
2015-08-11 20:04:17 +02:00
|
|
|
lastWorld = (World) extent;
|
2016-02-23 15:55:40 +01:00
|
|
|
return lastWorld.getName();
|
2015-08-11 20:04:17 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
|
|
|
public static org.spongepowered.api.world.Location<World> getLocation(Location location) {
|
|
|
|
Optional<World> world = SpongeMain.THIS.getServer().getWorld(location.getWorld());
|
2015-09-13 06:04:31 +02:00
|
|
|
if (!world.isPresent()) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
return new org.spongepowered.api.world.Location<>(world.get(), location.getX(), location.getY(), location.getZ());
|
2015-08-14 00:52:31 +02:00
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2015-10-07 08:33:33 +02:00
|
|
|
public static Location getLocation(String world, Vector3i position) {
|
|
|
|
return new Location(world, position.getX(), position.getY(), position.getZ());
|
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2015-10-07 08:33:33 +02:00
|
|
|
public static Location getLocation(String world, Vector3d position) {
|
|
|
|
return new Location(world, MathMan.roundInt(position.getX()), MathMan.roundInt(position.getY()), MathMan.roundInt(position.getZ()));
|
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public boolean isBlockSolid(PlotBlock block) {
|
|
|
|
BlockState state = SpongeUtil.getBlockState(block.id, block.data);
|
2016-02-23 15:55:40 +01:00
|
|
|
Optional<SolidCubeProperty> property = state.getType().getProperty(SolidCubeProperty.class);
|
|
|
|
if (property.isPresent()) {
|
|
|
|
return property.get().getValue();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-19 20:55:49 +01:00
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
|
|
|
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
|
|
|
try {
|
2016-02-23 15:55:40 +01:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
byte data;
|
2016-03-23 02:41:37 +01:00
|
|
|
String[] split = name.split(":");
|
2016-02-19 20:55:49 +01:00
|
|
|
if (split.length == 2) {
|
|
|
|
data = Byte.parseByte(split[1]);
|
|
|
|
name = split[0];
|
|
|
|
} else {
|
|
|
|
data = 0;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
short id;
|
|
|
|
double match;
|
2016-02-19 20:55:49 +01:00
|
|
|
if (MathMan.isInteger(split[0])) {
|
|
|
|
id = Short.parseShort(split[0]);
|
|
|
|
match = 0;
|
|
|
|
} else {
|
2016-03-21 00:35:40 +01:00
|
|
|
List<BlockType> types = ReflectionUtils.getStaticFields(BlockTypes.class);
|
2016-03-23 02:41:37 +01:00
|
|
|
StringComparison<BlockType>.ComparisonResult comparison =
|
2016-02-23 15:55:40 +01:00
|
|
|
new StringComparison<BlockType>(name, types.toArray(new BlockType[types.size()])) {
|
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public String getString(BlockType type) {
|
2016-02-23 15:55:40 +01:00
|
|
|
return type.getId();
|
|
|
|
}
|
|
|
|
}.getBestMatchAdvanced();
|
2016-02-19 20:55:49 +01:00
|
|
|
match = comparison.match;
|
|
|
|
id = SpongeUtil.getPlotBlock(comparison.best.getDefaultState()).id;
|
|
|
|
}
|
2016-06-03 22:20:13 +02:00
|
|
|
PlotBlock block = PlotBlock.get(id, data);
|
2016-03-23 02:41:37 +01:00
|
|
|
StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
2016-02-19 20:55:49 +01:00
|
|
|
return outer.new ComparisonResult(match, block);
|
2016-02-23 15:55:40 +01:00
|
|
|
|
2016-04-30 00:14:12 +02:00
|
|
|
} catch (NumberFormatException ignored) {}
|
2016-02-19 20:55:49 +01:00
|
|
|
return null;
|
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public String getClosestMatchingName(PlotBlock block) {
|
2016-02-19 20:55:49 +01:00
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
|
|
|
public String[] getBiomeList() {
|
|
|
|
if (biomes == null) {
|
|
|
|
initBiomeCache();
|
|
|
|
}
|
|
|
|
return biomeMap.keySet().toArray(new String[biomeMap.size()]);
|
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public boolean addItems(String world, PlotItem items) {
|
2016-02-19 20:55:49 +01:00
|
|
|
// TODO Auto-generated method stub
|
|
|
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public int getBiomeFromString(String biome) {
|
2016-02-19 20:55:49 +01:00
|
|
|
if (biomes == null) {
|
|
|
|
initBiomeCache();
|
|
|
|
}
|
|
|
|
return biomeMap.get(biome.toUpperCase());
|
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public String getBiome(String world, int x, int z) {
|
2016-02-19 20:55:49 +01:00
|
|
|
return SpongeUtil.getWorld(world).getBiome(x, z).getName().toUpperCase();
|
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public PlotBlock getBlock(Location location) {
|
|
|
|
BlockState state = SpongeUtil.getWorld(location.getWorld()).getBlock(location.getX(), location.getY(), location.getZ());
|
2016-02-19 20:55:49 +01:00
|
|
|
return SpongeUtil.getPlotBlock(state);
|
|
|
|
}
|
2016-03-31 11:48:46 +02:00
|
|
|
|
|
|
|
@Override
|
2016-06-03 01:38:35 +02:00
|
|
|
public Location getSpawn(PlotPlayer plotPlayer) {
|
|
|
|
World world = getWorld(plotPlayer.getLocation().getWorld());
|
|
|
|
return SpongeUtil.getLocation(world.getSpawnLocation());
|
2016-03-31 11:48:46 +02:00
|
|
|
}
|
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public Location getSpawn(String world) {
|
|
|
|
Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
|
2016-02-19 20:55:49 +01:00
|
|
|
result.setY(getHighestBlock(world, result.getX(), result.getZ()));
|
|
|
|
return result;
|
|
|
|
}
|
2016-03-17 10:11:07 +01:00
|
|
|
|
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public void setSpawn(Location location) {
|
|
|
|
World world = getWorld(location.getWorld());
|
2016-03-17 10:11:07 +01:00
|
|
|
if (world != null) {
|
2016-03-23 02:41:37 +01:00
|
|
|
world.getProperties().setSpawnPosition(new Vector3i(location.getX(), location.getY(), location.getZ()));
|
2016-03-17 10:11:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-29 21:47:59 +02:00
|
|
|
public void saveWorld(String worldName) {
|
2016-06-03 01:38:35 +02:00
|
|
|
try {
|
|
|
|
SpongeUtil.getWorld(worldName).save();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
PS.debug("Failed to save world.");
|
|
|
|
}
|
2016-03-17 10:11:07 +01:00
|
|
|
}
|
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public String[] getSign(Location location) {
|
|
|
|
World world = SpongeUtil.getWorld(location.getWorld());
|
|
|
|
Optional<TileEntity> block = world.getTileEntity(location.getX(), location.getY(), location.getZ());
|
2016-02-19 20:55:49 +01:00
|
|
|
if (!block.isPresent()) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
TileEntity tile = block.get();
|
2016-02-19 20:55:49 +01:00
|
|
|
if (!(tile instanceof Sign)) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
Sign sign = (Sign) tile;
|
|
|
|
Optional<SignData> optional = sign.get(SignData.class);
|
2016-02-19 20:55:49 +01:00
|
|
|
if (!optional.isPresent()) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
String[] result = new String[4];
|
2016-02-19 20:55:49 +01:00
|
|
|
ListValue<Text> lines = optional.get().lines();
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
result[i] = lines.get(i).toString();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-29 21:47:59 +02:00
|
|
|
public boolean isWorld(String worldName) {
|
|
|
|
return SpongeUtil.getWorld(worldName) != null;
|
2016-02-19 20:55:49 +01:00
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
|
|
|
public String getMainWorld() {
|
|
|
|
return Sponge.getServer().getWorlds().iterator().next().getName();
|
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-29 21:47:59 +02:00
|
|
|
public int getHighestBlock(String worldName, int x, int z) {
|
|
|
|
World world = SpongeUtil.getWorld(worldName);
|
2016-02-19 20:55:49 +01:00
|
|
|
if (world == null) {
|
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
for (int y = 255; y > 0; y--) {
|
2016-03-23 02:41:37 +01:00
|
|
|
BlockState block = world.getBlock(x, y, z);
|
2016-02-23 15:55:40 +01:00
|
|
|
if (block.getType() != BlockTypes.AIR) {
|
2016-02-19 20:55:49 +01:00
|
|
|
return y + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 64;
|
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-29 21:47:59 +02:00
|
|
|
public void setSign(String worldName, int x, int y, int z, String[] lines) {
|
|
|
|
World world = SpongeUtil.getWorld(worldName);
|
2016-02-19 20:55:49 +01:00
|
|
|
world.setBlock(x, y, z, BlockTypes.WALL_SIGN.getDefaultState());
|
2016-03-23 02:41:37 +01:00
|
|
|
Optional<TileEntity> block = world.getTileEntity(x, y, z);
|
2016-02-19 20:55:49 +01:00
|
|
|
if (!block.isPresent()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
TileEntity tile = block.get();
|
2016-02-19 20:55:49 +01:00
|
|
|
if (!(tile instanceof Sign)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
Sign sign = (Sign) tile;
|
|
|
|
List<Text> text = new ArrayList<>(4);
|
2016-02-19 20:55:49 +01:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2016-02-25 10:13:07 +01:00
|
|
|
text.add(SpongeUtil.getText(lines[i]));
|
2016-02-19 20:55:49 +01:00
|
|
|
}
|
2016-02-23 15:55:40 +01:00
|
|
|
sign.offer(Keys.SIGN_LINES, text);
|
2016-02-19 20:55:49 +01:00
|
|
|
}
|
2016-04-30 00:14:12 +02:00
|
|
|
|
2016-02-19 20:55:49 +01:00
|
|
|
@Override
|
2016-03-29 21:47:59 +02:00
|
|
|
public void setBiomes(String worldName, RegionWrapper region, String biomename) {
|
|
|
|
World world = SpongeUtil.getWorld(worldName);
|
2016-03-23 02:41:37 +01:00
|
|
|
BiomeType biome = SpongeUtil.getBiome(biomename);
|
2016-02-19 20:55:49 +01:00
|
|
|
for (int x = region.minX; x <= region.maxX; x++) {
|
|
|
|
for (int z = region.minZ; z <= region.maxZ; z++) {
|
|
|
|
world.setBiome(x, z, biome);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-30 16:25:16 +02:00
|
|
|
}
|