From eabb5f31805035c9592056781ad0cb6fb3228f04 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 20 Feb 2016 06:55:49 +1100 Subject: [PATCH] Fix remaining compile errors Note: Sponge version needs a number of things implemented before it will actually run --- pom.xml | 18 +- .../plot/util/ReflectionUtils.java | 16 ++ .../com/plotsquared/sponge/SpongeMain.java | 3 +- .../sponge/util/SpongeChunkManager.java | 19 +- .../sponge/util/SpongeInventoryUtil.java | 2 +- .../sponge/util/SpongeTitleManager.java | 11 +- .../plotsquared/sponge/util/SpongeUtil.java | 240 +++++++++++++++++- .../sponge/util/SpongeWorldUtil.java | 233 ----------------- 8 files changed, 263 insertions(+), 279 deletions(-) delete mode 100644 src/main/java/com/plotsquared/sponge/util/SpongeWorldUtil.java diff --git a/pom.xml b/pom.xml index 7a2d2ec823..4c38abd8b0 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ - ${project.name}-Bukkit + ${project.name}-Uber-${project.version} src/main/java @@ -78,7 +78,7 @@ TODO: fix sponge compilation --> - maven-jar-plugin 2.6 @@ -129,7 +129,6 @@ - --> org.apache.maven.plugins @@ -138,9 +137,6 @@ 1.7 ${javaVersion} - - **/com/plotsquared/sponge/** - @@ -200,8 +196,6 @@ spigot-repo https://hub.spigotmc.org/nexus/content/groups/public/ - - - sk89q http://maven.sk89q.com/repo/ - vault-repo http://nexus.theyeticave.net/content/repositories/pub_releases @@ -249,8 +240,7 @@ - - org.spongepowered spongeapi @@ -264,8 +254,6 @@ - --> - org.bukkit bukkit diff --git a/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java b/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java index 9c67b4f969..7ccf2caf65 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java @@ -51,6 +51,22 @@ public ReflectionUtils(final String version) { preClassM += "." + version; } + public static List getStaticFields(Class clazz) { + ArrayList list = new ArrayList(); + 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) { final String className = "net.minecraft.server." + version + "." + name; return getClass(className); diff --git a/src/main/java/com/plotsquared/sponge/SpongeMain.java b/src/main/java/com/plotsquared/sponge/SpongeMain.java index 7485bdc18b..c545084c79 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -67,7 +67,6 @@ import com.plotsquared.sponge.util.SpongeTaskManager; import com.plotsquared.sponge.util.SpongeTitleManager; 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.SlowQueue; import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper; @@ -421,7 +420,7 @@ public PlotQueue initPlotQueue() { @Override public WorldUtil initWorldUtil() { - return new SpongeWorldUtil(); + return new SpongeUtil(); } @Override diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java index e6b9ac8e3b..8493d7a3ac 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java @@ -14,18 +14,11 @@ import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.util.ChunkManager; -import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.intellectualcrafters.plot.util.TaskManager; public class SpongeChunkManager extends ChunkManager { - @Override - public void setChunk(final ChunkWrapper loc, final PlotBlock[][] result) { - // TODO Auto-generated method stub - } - @Override public int[] countEntities(final Plot plot) { final Location pos1 = plot.getBottomAbs(); @@ -94,12 +87,6 @@ public boolean copyRegion(final Location pos1, final Location pos2, final Locati return false; } - @Override - public boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone) { - TaskManager.runTask(whenDone); - return false; - } - @Override public void clearAllEntities(final Location pos1, final Location pos2) { final String worldname = pos1.getWorld(); @@ -139,4 +126,10 @@ public void unloadChunk(String world, ChunkLoc loc, boolean save, boolean safe) } } + @Override + public boolean regenerateRegion(Location pos1, Location pos2, boolean ignoreAugment, Runnable whenDone) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + } + } diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeInventoryUtil.java b/src/main/java/com/plotsquared/sponge/util/SpongeInventoryUtil.java index cff68a4e50..afec553f6b 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeInventoryUtil.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeInventoryUtil.java @@ -32,7 +32,7 @@ public void open(final PlotInventory inv) { final SpongePlayer sp = (SpongePlayer) inv.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(); for (int i = 0; i < (inv.size * 9); i++) { final PlotItemStack item = items[i]; diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java index 242dd59f9c..444ec5b6c2 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java @@ -1,18 +1,23 @@ package com.plotsquared.sponge.util; +import org.spongepowered.api.text.Text; import org.spongepowered.api.text.title.Title; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.AbstractTitle; -import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.object.SpongePlayer; public class SpongeTitleManager extends AbstractTitle { @Override 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 - (delay * 20).fadeOut(out * 20).build(); + final Title title = Title.builder() + .title(Text.of(head)) + .subtitle(Text.of(sub)) + .fadeIn(in * 20) + .stay(delay * 20) + .fadeOut(out * 20) + .build(); ((SpongePlayer) player).player.sendTitle(title); } } diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java b/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java index 278ac7168e..008abecd36 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java @@ -1,10 +1,20 @@ package com.plotsquared.sponge.util; import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Optional; +import org.spongepowered.api.Sponge; 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.living.player.Player; import org.spongepowered.api.text.Text; @@ -20,12 +30,17 @@ 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; 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.WorldUtil; import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.object.SpongePlayer; -public class SpongeUtil { +public class SpongeUtil extends WorldUtil { public static Location getLocation(final Entity player) { final String world = player.getWorld().getName(); @@ -35,18 +50,35 @@ public static Location getLocation(final Entity player) { } private static BiomeType[] biomes; + private static HashMap biomeMap; - public static BiomeType getBiome(int index) { + public static BiomeType getBiome(String biome) { if (biomes == null) { - try { - Field[] fields = BiomeTypes.class.getFields(); - biomes = new BiomeType[fields.length]; - for (int i = 0; i < fields.length; i++) { - biomes[i] = (BiomeType) fields[i].get(null); - } - } catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); + initBiomeCache(); + } + return biomes[biomeMap.get(biome.toUpperCase())]; + } + + 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); } + + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + } + + public static BiomeType getBiome(int index) { + if (biomes == null) { + initBiomeCache(); } return biomes[index]; } @@ -81,11 +113,11 @@ public String get(final Locale l) { } public static BlockState getBlockState(int id, int data) { - + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } public static PlotBlock getPlotBlock(BlockState state) { - + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } public static Location getLocation(final org.spongepowered.api.world.Location block) { @@ -177,4 +209,188 @@ public static Location getLocation(String world, Vector3i 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())); } + + @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.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 types = ReflectionUtils. getStaticFields(BlockTypes.class); + final StringComparison.ComparisonResult comparison = new StringComparison(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 outer = new StringComparison(); + 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 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 optional = sign.getOrCreate(SignData.class); + if (!optional.isPresent()) { + return null; + } + final String[] result = new String[4]; + ListValue 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 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 = new ArrayList<>(4); + for (int i = 0; i < 4; i++) { + text.add(Text.of(lines[i])); + } + try { + final Optional 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); + } + } + } } diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeWorldUtil.java b/src/main/java/com/plotsquared/sponge/util/SpongeWorldUtil.java deleted file mode 100644 index f0f9021555..0000000000 --- a/src/main/java/com/plotsquared/sponge/util/SpongeWorldUtil.java +++ /dev/null @@ -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.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.ComparisonResult comparison = new StringComparison(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 outer = new StringComparison(); - 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 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 optional = sign.getOrCreate(SignData.class); - if (!optional.isPresent()) { - return null; - } - final String[] result = new String[4]; - final ListValue 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 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 = new ArrayList<>(4); - for (int i = 0; i < 4; i++) { - text.add(SpongeMain.THIS.getText(lines[i])); - } - try { - final Optional 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); - } - } - -}