mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Fix remaining compile errors
Note: Sponge version needs a number of things implemented before it will actually run
This commit is contained in:
parent
92b3ddb0ac
commit
eabb5f3180
18
pom.xml
18
pom.xml
@ -52,7 +52,7 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.name}-Bukkit</finalName>
|
<finalName>${project.name}-Uber-${project.version}</finalName>
|
||||||
<sourceDirectory>src/main/java</sourceDirectory>
|
<sourceDirectory>src/main/java</sourceDirectory>
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
@ -78,7 +78,7 @@
|
|||||||
TODO: fix sponge compilation
|
TODO: fix sponge compilation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- Invalid
|
<!-- Invalid -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>2.6</version>
|
<version>2.6</version>
|
||||||
@ -129,7 +129,6 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
-->
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
@ -138,9 +137,6 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>1.7</source>
|
||||||
<target>${javaVersion}</target>
|
<target>${javaVersion}</target>
|
||||||
<excludes>
|
|
||||||
<exclude>**/com/plotsquared/sponge/**</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
@ -200,8 +196,6 @@
|
|||||||
<id>spigot-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<!--
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>sponge-maven-repo</id>
|
<id>sponge-maven-repo</id>
|
||||||
<url>http://repo.spongepowered.org/maven</url>
|
<url>http://repo.spongepowered.org/maven</url>
|
||||||
@ -212,13 +206,10 @@
|
|||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
</repository>
|
</repository>
|
||||||
-->
|
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>sk89q</id>
|
<id>sk89q</id>
|
||||||
<url>http://maven.sk89q.com/repo/</url>
|
<url>http://maven.sk89q.com/repo/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>vault-repo</id>
|
<id>vault-repo</id>
|
||||||
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
|
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
|
||||||
@ -249,8 +240,7 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Sponge API -->
|
||||||
<!-- Sponge API
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spongepowered</groupId>
|
<groupId>org.spongepowered</groupId>
|
||||||
<artifactId>spongeapi</artifactId>
|
<artifactId>spongeapi</artifactId>
|
||||||
@ -264,8 +254,6 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
-->
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
|
@ -51,6 +51,22 @@ public class ReflectionUtils {
|
|||||||
preClassM += "." + version;
|
preClassM += "." + version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> List<T> getStaticFields(Class clazz) {
|
||||||
|
ArrayList<T> list = new ArrayList<T>();
|
||||||
|
try {
|
||||||
|
Field[] fields = clazz.getFields();
|
||||||
|
for (int i = 0; i < fields.length; i++) {
|
||||||
|
Object value = fields[i].get(null);
|
||||||
|
try {
|
||||||
|
list.add((T) value);
|
||||||
|
} catch (ClassCastException e) {}
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public static Class<?> getNmsClass(final String name) {
|
public static Class<?> getNmsClass(final String name) {
|
||||||
final String className = "net.minecraft.server." + version + "." + name;
|
final String className = "net.minecraft.server." + version + "." + name;
|
||||||
return getClass(className);
|
return getClass(className);
|
||||||
|
@ -67,7 +67,6 @@ import com.plotsquared.sponge.util.SpongeMetrics;
|
|||||||
import com.plotsquared.sponge.util.SpongeTaskManager;
|
import com.plotsquared.sponge.util.SpongeTaskManager;
|
||||||
import com.plotsquared.sponge.util.SpongeTitleManager;
|
import com.plotsquared.sponge.util.SpongeTitleManager;
|
||||||
import com.plotsquared.sponge.util.SpongeUtil;
|
import com.plotsquared.sponge.util.SpongeUtil;
|
||||||
import com.plotsquared.sponge.util.SpongeWorldUtil;
|
|
||||||
import com.plotsquared.sponge.util.block.FastQueue;
|
import com.plotsquared.sponge.util.block.FastQueue;
|
||||||
import com.plotsquared.sponge.util.block.SlowQueue;
|
import com.plotsquared.sponge.util.block.SlowQueue;
|
||||||
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
|
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
|
||||||
@ -421,7 +420,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorldUtil initWorldUtil() {
|
public WorldUtil initWorldUtil() {
|
||||||
return new SpongeWorldUtil();
|
return new SpongeUtil();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,18 +14,11 @@ import org.spongepowered.api.world.World;
|
|||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||||
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
|
||||||
public class SpongeChunkManager extends ChunkManager {
|
public class SpongeChunkManager extends ChunkManager {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setChunk(final ChunkWrapper loc, final PlotBlock[][] result) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] countEntities(final Plot plot) {
|
public int[] countEntities(final Plot plot) {
|
||||||
final Location pos1 = plot.getBottomAbs();
|
final Location pos1 = plot.getBottomAbs();
|
||||||
@ -94,12 +87,6 @@ public class SpongeChunkManager extends ChunkManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone) {
|
|
||||||
TaskManager.runTask(whenDone);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearAllEntities(final Location pos1, final Location pos2) {
|
public void clearAllEntities(final Location pos1, final Location pos2) {
|
||||||
final String worldname = pos1.getWorld();
|
final String worldname = pos1.getWorld();
|
||||||
@ -139,4 +126,10 @@ public class SpongeChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean regenerateRegion(Location pos1, Location pos2, boolean ignoreAugment, Runnable whenDone) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public class SpongeInventoryUtil extends InventoryUtil {
|
|||||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||||
final Player player = sp.player;
|
final Player player = sp.player;
|
||||||
|
|
||||||
final CustomInventory inventory = SpongeMain.THIS.getGame().getRegistry().createBuilder(CustomInventory.Builder.class).name(SpongeMain.THIS.getTranslation(inv.getTitle()).getTranslation()).size(inv.size).build();
|
final CustomInventory inventory = SpongeMain.THIS.getGame().getRegistry().createBuilder(CustomInventory.Builder.class).name(SpongeUtil.getTranslation(inv.getTitle())).size(inv.size).build();
|
||||||
final PlotItemStack[] items = inv.getItems();
|
final PlotItemStack[] items = inv.getItems();
|
||||||
for (int i = 0; i < (inv.size * 9); i++) {
|
for (int i = 0; i < (inv.size * 9); i++) {
|
||||||
final PlotItemStack item = items[i];
|
final PlotItemStack item = items[i];
|
||||||
|
@ -1,18 +1,23 @@
|
|||||||
package com.plotsquared.sponge.util;
|
package com.plotsquared.sponge.util;
|
||||||
|
|
||||||
|
import org.spongepowered.api.text.Text;
|
||||||
import org.spongepowered.api.text.title.Title;
|
import org.spongepowered.api.text.title.Title;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
import com.intellectualcrafters.plot.util.AbstractTitle;
|
||||||
import com.plotsquared.sponge.SpongeMain;
|
|
||||||
import com.plotsquared.sponge.object.SpongePlayer;
|
import com.plotsquared.sponge.object.SpongePlayer;
|
||||||
|
|
||||||
public class SpongeTitleManager extends AbstractTitle {
|
public class SpongeTitleManager extends AbstractTitle {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) {
|
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) {
|
||||||
final Title title = Title.builder().title(SpongeMain.THIS.getText(head)).subtitle(SpongeMain.THIS.getText(sub)).fadeIn(in * 20).stay
|
final Title title = Title.builder()
|
||||||
(delay * 20).fadeOut(out * 20).build();
|
.title(Text.of(head))
|
||||||
|
.subtitle(Text.of(sub))
|
||||||
|
.fadeIn(in * 20)
|
||||||
|
.stay(delay * 20)
|
||||||
|
.fadeOut(out * 20)
|
||||||
|
.build();
|
||||||
((SpongePlayer) player).player.sendTitle(title);
|
((SpongePlayer) player).player.sendTitle(title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,20 @@
|
|||||||
package com.plotsquared.sponge.util;
|
package com.plotsquared.sponge.util;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.spongepowered.api.Sponge;
|
||||||
import org.spongepowered.api.block.BlockState;
|
import org.spongepowered.api.block.BlockState;
|
||||||
|
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;
|
||||||
|
import org.spongepowered.api.data.manipulator.mutable.tileentity.SignData;
|
||||||
|
import org.spongepowered.api.data.value.mutable.ListValue;
|
||||||
import org.spongepowered.api.entity.Entity;
|
import org.spongepowered.api.entity.Entity;
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
import org.spongepowered.api.text.Text;
|
import org.spongepowered.api.text.Text;
|
||||||
@ -20,12 +30,17 @@ import com.flowpowered.math.vector.Vector3i;
|
|||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||||
|
import com.intellectualcrafters.plot.object.schematic.PlotItem;
|
||||||
import com.intellectualcrafters.plot.util.MathMan;
|
import com.intellectualcrafters.plot.util.MathMan;
|
||||||
|
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
||||||
|
import com.intellectualcrafters.plot.util.StringComparison;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||||
import com.plotsquared.sponge.SpongeMain;
|
import com.plotsquared.sponge.SpongeMain;
|
||||||
import com.plotsquared.sponge.object.SpongePlayer;
|
import com.plotsquared.sponge.object.SpongePlayer;
|
||||||
|
|
||||||
public class SpongeUtil {
|
public class SpongeUtil extends WorldUtil {
|
||||||
|
|
||||||
public static Location getLocation(final Entity player) {
|
public static Location getLocation(final Entity player) {
|
||||||
final String world = player.getWorld().getName();
|
final String world = player.getWorld().getName();
|
||||||
@ -35,19 +50,36 @@ public class SpongeUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static BiomeType[] biomes;
|
private static BiomeType[] biomes;
|
||||||
|
private static HashMap<String, Integer> biomeMap;
|
||||||
|
|
||||||
public static BiomeType getBiome(int index) {
|
public static BiomeType getBiome(String biome) {
|
||||||
if (biomes == null) {
|
if (biomes == null) {
|
||||||
|
initBiomeCache();
|
||||||
|
}
|
||||||
|
return biomes[biomeMap.get(biome.toUpperCase())];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initBiomeCache() {
|
||||||
try {
|
try {
|
||||||
Field[] fields = BiomeTypes.class.getFields();
|
Field[] fields = BiomeTypes.class.getFields();
|
||||||
biomes = new BiomeType[fields.length];
|
biomes = new BiomeType[fields.length];
|
||||||
|
biomeMap = new HashMap<>();
|
||||||
for (int i = 0; i < fields.length; i++) {
|
for (int i = 0; i < fields.length; i++) {
|
||||||
biomes[i] = (BiomeType) fields[i].get(null);
|
Field field = fields[i];
|
||||||
|
String name = field.getName();
|
||||||
|
biomeMap.put(name, i);
|
||||||
|
biomes[i] = (BiomeType) field.get(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BiomeType getBiome(int index) {
|
||||||
|
if (biomes == null) {
|
||||||
|
initBiomeCache();
|
||||||
|
}
|
||||||
return biomes[index];
|
return biomes[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +113,11 @@ public class SpongeUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static BlockState getBlockState(int id, int data) {
|
public static BlockState getBlockState(int id, int data) {
|
||||||
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlotBlock getPlotBlock(BlockState state) {
|
public static PlotBlock getPlotBlock(BlockState state) {
|
||||||
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location getLocation(final org.spongepowered.api.world.Location<World> block) {
|
public static Location getLocation(final org.spongepowered.api.world.Location<World> block) {
|
||||||
@ -177,4 +209,188 @@ public class SpongeUtil {
|
|||||||
public static Location getLocation(String world, Vector3d position) {
|
public static Location getLocation(String world, Vector3d position) {
|
||||||
return new Location(world, MathMan.roundInt(position.getX()), MathMan.roundInt(position.getY()), MathMan.roundInt(position.getZ()));
|
return new Location(world, MathMan.roundInt(position.getX()), MathMan.roundInt(position.getY()), MathMan.roundInt(position.getZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBlockSolid(final PlotBlock block) {
|
||||||
|
final BlockState state = SpongeUtil.getBlockState(block.id, block.data);
|
||||||
|
final BlockType type = state.getType();
|
||||||
|
// TODO check if solid;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
double match;
|
||||||
|
short id;
|
||||||
|
byte data;
|
||||||
|
final String[] split = name.split(":");
|
||||||
|
if (split.length == 2) {
|
||||||
|
data = Byte.parseByte(split[1]);
|
||||||
|
name = split[0];
|
||||||
|
} else {
|
||||||
|
data = 0;
|
||||||
|
}
|
||||||
|
if (MathMan.isInteger(split[0])) {
|
||||||
|
id = Short.parseShort(split[0]);
|
||||||
|
match = 0;
|
||||||
|
} else {
|
||||||
|
List<BlockType> types = ReflectionUtils.<BlockType> getStaticFields(BlockTypes.class);
|
||||||
|
final StringComparison<BlockType>.ComparisonResult comparison = new StringComparison<BlockType>(name, types.toArray(new BlockType[types.size()])) {
|
||||||
|
@Override
|
||||||
|
public String getString(final BlockType type) {
|
||||||
|
return type.getId();
|
||||||
|
};
|
||||||
|
}.getBestMatchAdvanced();
|
||||||
|
match = comparison.match;
|
||||||
|
id = SpongeUtil.getPlotBlock(comparison.best.getDefaultState()).id;
|
||||||
|
}
|
||||||
|
final PlotBlock block = new PlotBlock(id, data);
|
||||||
|
final StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
||||||
|
return outer.new ComparisonResult(match, block);
|
||||||
|
|
||||||
|
} catch (final Exception e) {}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClosestMatchingName(final PlotBlock block) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getBiomeList() {
|
||||||
|
if (biomes == null) {
|
||||||
|
initBiomeCache();
|
||||||
|
}
|
||||||
|
return biomeMap.keySet().toArray(new String[biomeMap.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addItems(final String world, final PlotItem items) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBiomeFromString(final String biome) {
|
||||||
|
if (biomes == null) {
|
||||||
|
initBiomeCache();
|
||||||
|
}
|
||||||
|
return biomeMap.get(biome.toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBiome(final String world, final int x, final int z) {
|
||||||
|
return SpongeUtil.getWorld(world).getBiome(x, z).getName().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlotBlock getBlock(final Location loc) {
|
||||||
|
final BlockState state = SpongeUtil.getWorld(loc.getWorld()).getBlock(loc.getX(), loc.getY(), loc.getZ());
|
||||||
|
return SpongeUtil.getPlotBlock(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getSpawn(final String world) {
|
||||||
|
final World worldObj = SpongeUtil.getWorld(world);
|
||||||
|
worldObj.getSpawnLocation();
|
||||||
|
final Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
|
||||||
|
result.setY(getHighestBlock(world, result.getX(), result.getZ()));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getSign(final Location loc) {
|
||||||
|
final World world = SpongeUtil.getWorld(loc.getWorld());
|
||||||
|
final Optional<TileEntity> block = world.getTileEntity(loc.getX(), loc.getY(), loc.getZ());
|
||||||
|
if (!block.isPresent()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final TileEntity tile = block.get();
|
||||||
|
if (!(tile instanceof Sign)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final Sign sign = (Sign) tile;
|
||||||
|
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||||
|
if (!optional.isPresent()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final String[] result = new String[4];
|
||||||
|
ListValue<Text> lines = optional.get().lines();
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
result[i] = lines.get(i).toString();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWorld(final String world) {
|
||||||
|
return SpongeUtil.getWorld(world) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMainWorld() {
|
||||||
|
return Sponge.getServer().getWorlds().iterator().next().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHighestBlock(String worldname, int x, int z) {
|
||||||
|
final World world = SpongeUtil.getWorld(worldname);
|
||||||
|
if (world == null) {
|
||||||
|
return 64;
|
||||||
|
}
|
||||||
|
for (int y = 255; y > 0; y--) {
|
||||||
|
final BlockState block = world.getBlock(x, y, z);
|
||||||
|
if ((block != null) && (block.getType() != BlockTypes.AIR)) {
|
||||||
|
return y + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSign(String worldname, int x, int y, int z, String[] lines) {
|
||||||
|
final World world = SpongeUtil.getWorld(worldname);
|
||||||
|
world.setBlock(x, y, z, BlockTypes.WALL_SIGN.getDefaultState());
|
||||||
|
final Optional<TileEntity> block = world.getTileEntity(x, y, z);
|
||||||
|
if (!block.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final TileEntity tile = block.get();
|
||||||
|
if (!(tile instanceof Sign)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Sign sign = (Sign) tile;
|
||||||
|
final List<Text> text = new ArrayList<>(4);
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
text.add(Text.of(lines[i]));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||||
|
if (optional.isPresent()) {
|
||||||
|
final SignData offering = optional.get();
|
||||||
|
offering.lines().set(0, Text.of(lines[0]));
|
||||||
|
offering.lines().set(1, Text.of(lines[1]));
|
||||||
|
offering.lines().set(2, Text.of(lines[2]));
|
||||||
|
offering.lines().set(3, Text.of(lines[3]));
|
||||||
|
sign.offer(offering);
|
||||||
|
}
|
||||||
|
} catch (final NullPointerException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBiomes(String worldname, RegionWrapper region, String biomename) {
|
||||||
|
final World world = SpongeUtil.getWorld(worldname);
|
||||||
|
final BiomeType biome = SpongeUtil.getBiome(biomename);
|
||||||
|
for (int x = region.minX; x <= region.maxX; x++) {
|
||||||
|
for (int z = region.minZ; z <= region.maxZ; z++) {
|
||||||
|
world.setBiome(x, z, biome);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,233 +0,0 @@
|
|||||||
package com.plotsquared.sponge.util;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.FlagValue.ListValue;
|
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
|
||||||
import com.intellectualcrafters.plot.object.schematic.PlotItem;
|
|
||||||
import com.intellectualcrafters.plot.util.MathMan;
|
|
||||||
import com.intellectualcrafters.plot.util.StringComparison;
|
|
||||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
|
||||||
import com.plotsquared.sponge.SpongeMain;
|
|
||||||
import com.sk89q.worldedit.blocks.BlockType;
|
|
||||||
|
|
||||||
public class SpongeWorldUtil extends WorldUtil {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBlockSolid(final PlotBlock block) {
|
|
||||||
final BlockState state = SpongeMain.THIS.getBlockState(block);
|
|
||||||
final BlockType type = state.getType();
|
|
||||||
// TODO check if solid;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
double match;
|
|
||||||
short id;
|
|
||||||
byte data;
|
|
||||||
final String[] split = name.split(":");
|
|
||||||
if (split.length == 2) {
|
|
||||||
data = Byte.parseByte(split[1]);
|
|
||||||
name = split[0];
|
|
||||||
} else {
|
|
||||||
data = 0;
|
|
||||||
}
|
|
||||||
if (MathMan.isInteger(split[0])) {
|
|
||||||
id = Short.parseShort(split[0]);
|
|
||||||
match = 0;
|
|
||||||
} else {
|
|
||||||
final StringComparison<BlockState>.ComparisonResult comparison = new StringComparison<BlockState>(name, SpongeMain.THIS.getAllStates()) {
|
|
||||||
@Override
|
|
||||||
public String getString(final BlockState o) {
|
|
||||||
return o.getType().getId();
|
|
||||||
};
|
|
||||||
}.getBestMatchAdvanced();
|
|
||||||
match = comparison.match;
|
|
||||||
id = SpongeMain.THIS.getPlotBlock(comparison.best).id;
|
|
||||||
}
|
|
||||||
final PlotBlock block = new PlotBlock(id, data);
|
|
||||||
final StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
|
||||||
return outer.new ComparisonResult(match, block);
|
|
||||||
|
|
||||||
} catch (final Exception e) {}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getClosestMatchingName(final PlotBlock block) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getBiomeList() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addItems(final String world, final PlotItem items) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBiomeFromString(final String biome) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PlotBlock getPlotBlockFromString(final String block) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeighestBlock(final String worldname, final int x, final int z) {
|
|
||||||
final World world = SpongeUtil.getWorld(worldname);
|
|
||||||
if (world == null) {
|
|
||||||
return 64;
|
|
||||||
}
|
|
||||||
for (int y = 255; y > 0; y--) {
|
|
||||||
final BlockState block = world.getBlock(x, y, z);
|
|
||||||
if ((block != null) && (block.getType() != BlockTypes.AIR)) {
|
|
||||||
return y + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getBiome(final String world, final int x, final int z) {
|
|
||||||
return SpongeUtil.getWorld(world).getBiome(x, z).getName().toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PlotBlock getBlock(final Location loc) {
|
|
||||||
final BlockState state = SpongeUtil.getWorld(loc.getWorld()).getBlock(loc.getX(), loc.getY(), loc.getZ());
|
|
||||||
PlotBlock block = SpongeMain.THIS.getPlotBlock(state);
|
|
||||||
if (block == null) {
|
|
||||||
block = SpongeMain.THIS.registerBlock(state);
|
|
||||||
}
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getSpawn(final String world) {
|
|
||||||
final World worldObj = SpongeUtil.getWorld(world);
|
|
||||||
worldObj.getSpawnLocation();
|
|
||||||
final Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
|
|
||||||
result.setY(getHeighestBlock(world, result.getX(), result.getZ()));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getSign(final Location loc) {
|
|
||||||
final World world = SpongeUtil.getWorld(loc.getWorld());
|
|
||||||
final Optional<TileEntity> block = world.getTileEntity(loc.getX(), loc.getY(), loc.getZ());
|
|
||||||
if (!block.isPresent()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final TileEntity tile = block.get();
|
|
||||||
if (!(tile instanceof Sign)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final Sign sign = (Sign) tile;
|
|
||||||
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
|
||||||
if (!optional.isPresent()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final String[] result = new String[4];
|
|
||||||
final ListValue<Text> lines = optional.get().lines();
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
result[i] = lines.get(i).toString();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isWorld(final String world) {
|
|
||||||
return SpongeUtil.getWorld(world) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void functionSetBlocks(final String worldname, final int[] xv, final int[] yv, final int[] zv, final int[] id, final byte[] data) {
|
|
||||||
for (int i = 0; i < xv.length; i++) {
|
|
||||||
functionSetBlock(worldname, xv[i], yv[i], zv[i], id[i], data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void functionSetSign(final String worldname, final int x, final int y, final int z, final String[] lines) {
|
|
||||||
final World world = SpongeUtil.getWorld(worldname);
|
|
||||||
world.setBlock(x, y, z, BlockTypes.WALL_SIGN.getDefaultState());
|
|
||||||
final Optional<TileEntity> block = world.getTileEntity(x, y, z);
|
|
||||||
if (!block.isPresent()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final TileEntity tile = block.get();
|
|
||||||
if (!(tile instanceof Sign)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Sign sign = (Sign) tile;
|
|
||||||
final List<Text> text = new ArrayList<>(4);
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
text.add(SpongeMain.THIS.getText(lines[i]));
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
|
||||||
if (optional.isPresent()) {
|
|
||||||
final SignData offering = optional.get();
|
|
||||||
offering.lines().set(0, SpongeMain.THIS.getText(lines[0]));
|
|
||||||
offering.lines().set(1, SpongeMain.THIS.getText(lines[1]));
|
|
||||||
offering.lines().set(2, SpongeMain.THIS.getText(lines[2]));
|
|
||||||
offering.lines().set(3, SpongeMain.THIS.getText(lines[3]));
|
|
||||||
sign.offer(offering);
|
|
||||||
}
|
|
||||||
} catch (final NullPointerException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void functionSetBlock(final String worldname, final int x, final int y, final int z, final int id, final byte data) {
|
|
||||||
BlockState state;
|
|
||||||
if (data == 0) {
|
|
||||||
state = SpongeMain.THIS.getBlockState(id);
|
|
||||||
} else {
|
|
||||||
state = SpongeMain.THIS.getBlockState(new PlotBlock((short) id, data));
|
|
||||||
}
|
|
||||||
if (state == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final World world = SpongeUtil.getWorld(worldname);
|
|
||||||
final BlockState block = world.getBlock(x, y, z);
|
|
||||||
if (block != state) {
|
|
||||||
world.setBlock(x, y, z, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void functionSetBiomes(final String worldname, final int[] xv, final int[] zv, final String biomeName) {
|
|
||||||
BiomeType biome;
|
|
||||||
try {
|
|
||||||
biome = (BiomeType) BiomeTypes.class.getField(biomeName.toUpperCase()).get(null);
|
|
||||||
} catch (final Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
biome = BiomeTypes.FOREST;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < xv.length; i++) {
|
|
||||||
SpongeUtil.getWorld(worldname).setBiome(xv[i], zv[i], biome);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user