diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Area.java b/src/main/java/com/intellectualcrafters/plot/commands/Area.java index 9cde7dcb2..76e57ce11 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Area.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Area.java @@ -438,9 +438,14 @@ public class Area extends SubCommand { C.NOT_VALID_PLOT_WORLD.send(plr, args[1]); return false; } - RegionWrapper region = area.getRegion(); - Location center = new Location(area.worldname, region.minX + (region.maxX - region.minX) / 2, 0, region.minZ + (region.maxZ - region.minZ) / 2); - center.setY(WorldUtil.IMP.getHighestBlock(area.worldname, center.getX(), center.getZ())); + Location center; + if (area.TYPE != 2) { + center = WorldUtil.IMP.getSpawn(area.worldname); + } else { + RegionWrapper region = area.getRegion(); + center = new Location(area.worldname, region.minX + (region.maxX - region.minX) / 2, 0, region.minZ + (region.maxZ - region.minZ) / 2); + center.setY(WorldUtil.IMP.getHighestBlock(area.worldname, center.getX(), center.getZ())); + } plr.teleport(center); return true; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index 7b666ca2c..6edd81a0d 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -20,6 +20,15 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.UUID; + +import org.apache.commons.lang.mutable.MutableInt; + import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; @@ -36,14 +45,6 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.Command; import com.plotsquared.general.commands.CommandDeclaration; -import org.apache.commons.lang.mutable.MutableInt; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.UUID; @CommandDeclaration( command = "rate", @@ -83,7 +84,7 @@ public class Rate extends SubCommand { }); final UUID uuid = player.getUUID(); for (final Plot p : plots) { - if ((!Settings.REQUIRE_DONE || p.getFlags().containsKey("done")) && p.isBasePlot() && (p.getRatings().isEmpty() || !p.getRatings() + if ((!Settings.REQUIRE_DONE || p.getFlags().containsKey("done")) && p.isBasePlot() && (p.hasRatings() || !p.getRatings() .containsKey(uuid)) && !p.isAdded(uuid)) { p.teleportPlayer(player); MainUtil.sendMessage(player, C.RATE_THIS); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/plugin.java b/src/main/java/com/intellectualcrafters/plot/commands/plugin.java index 4e4d1ecef..17cbee36c 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/plugin.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/plugin.java @@ -34,8 +34,7 @@ public class plugin extends SubCommand { MainUtil.sendMessage(plr, String.format("$2>> $1&lPlotSquared $2($1Version$2: $1%s$2)", StringMan.join(PS.get().IMP.getPluginVersion(), "."))); MainUtil.sendMessage(plr, "$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92"); MainUtil.sendMessage(plr, "$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki"); - MainUtil.sendMessage(plr, - "$2>> $1&lNewest Version$2: $1" + (PS.get().update == null ? StringMan.join(PS.get().IMP.getPluginVersion(), ".") : PS.get().update)); + MainUtil.sendMessage(plr, "$2>> $1&lNewest Version$2: $1" + (PS.get().update == null ? StringMan.join(PS.get().IMP.getPluginVersion(), ".") : PS.get().update)); return true; } } diff --git a/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 0747d797b..6884787e3 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -20,6 +20,25 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.object; +import java.awt.Rectangle; +import java.awt.geom.Area; +import java.awt.geom.PathIterator; +import java.io.File; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; + import com.google.common.collect.BiMap; import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.plot.PS; @@ -41,25 +60,6 @@ import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.listener.PlotListener; -import java.awt.Rectangle; -import java.awt.geom.Area; -import java.awt.geom.PathIterator; -import java.io.File; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - /** * The plot class */ @@ -1206,6 +1206,11 @@ public class Plot { return map; } + public boolean hasRatings() { + Plot base = this.getBasePlot(false); + return base.settings != null && base.settings.ratings != null; + } + /** * Resend all chunks inside the plot to nearby players
* This should not need to be called diff --git a/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java b/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java index 7ccf2caf6..c8c03ba02 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java @@ -35,7 +35,6 @@ import java.util.List; */ public class ReflectionUtils { - private static String version; /** * prefix of bukkit classes */ @@ -46,9 +45,10 @@ public class ReflectionUtils { private static String preClassM = "net.minecraft.server"; public ReflectionUtils(final String version) { - ReflectionUtils.version = version; - preClassB += "." + version; - preClassM += "." + version; + if (version != null) { + preClassB += "." + version; + preClassM += "." + version; + } } public static List getStaticFields(Class clazz) { @@ -66,14 +66,14 @@ public class ReflectionUtils { } return list; } - + public static Class getNmsClass(final String name) { - final String className = "net.minecraft.server." + version + "." + name; + final String className = preClassM + "." + name; return getClass(className); } public static Class getCbClass(final String name) { - final String className = "org.bukkit.craftbukkit." + version + "." + name; + final String className = preClassB + "." + name; return getClass(className); } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 7106a597a..7f6023daf 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1,33 +1,16 @@ package com.plotsquared.bukkit.listeners; -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotArea; -import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PlotHandler; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotInventory; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.EventUtil; -import com.intellectualcrafters.plot.util.ExpireManager; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.MathMan; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.RegExUtil; -import com.intellectualcrafters.plot.util.StringMan; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.UUIDHandler; -import com.plotsquared.bukkit.BukkitMain; -import com.plotsquared.bukkit.object.BukkitLazyBlock; -import com.plotsquared.bukkit.object.BukkitPlayer; -import com.plotsquared.bukkit.util.BukkitUtil; -import com.plotsquared.listener.PlayerBlockEventType; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; +import java.util.regex.Pattern; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -106,16 +89,34 @@ import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.regex.Pattern; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotHandler; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotInventory; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.ExpireManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.MathMan; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.RegExUtil; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.plotsquared.bukkit.BukkitMain; +import com.plotsquared.bukkit.object.BukkitLazyBlock; +import com.plotsquared.bukkit.object.BukkitPlayer; +import com.plotsquared.bukkit.util.BukkitUtil; +import com.plotsquared.listener.PlayerBlockEventType; /** * Player Events involving plots @@ -486,7 +487,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen event.setCancelled(true); return; } - } else if (lastPlot != null && now.equals(lastPlot)) { + } else if (now.equals(lastPlot)) { return; } else if (!plotEntry(pp, now)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); @@ -538,7 +539,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen event.setCancelled(true); return; } - } else if (lastPlot != null && now.equals(lastPlot)) { + } else if (now.equals(lastPlot)) { return; } else if (!plotEntry(pp, now)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); diff --git a/src/main/java/com/plotsquared/sponge/SpongeMain.java b/src/main/java/com/plotsquared/sponge/SpongeMain.java index c545084c7..450309f64 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -10,6 +10,7 @@ import java.util.UUID; import org.slf4j.Logger; import org.spongepowered.api.Game; import org.spongepowered.api.Server; +import org.spongepowered.api.Sponge; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent; @@ -62,8 +63,11 @@ import com.plotsquared.sponge.util.SpongeChunkManager; import com.plotsquared.sponge.util.SpongeCommand; import com.plotsquared.sponge.util.SpongeEconHandler; import com.plotsquared.sponge.util.SpongeEventUtil; +import com.plotsquared.sponge.util.SpongeHybridUtils; import com.plotsquared.sponge.util.SpongeInventoryUtil; import com.plotsquared.sponge.util.SpongeMetrics; +import com.plotsquared.sponge.util.SpongeSchematicHandler; +import com.plotsquared.sponge.util.SpongeSetupUtils; import com.plotsquared.sponge.util.SpongeTaskManager; import com.plotsquared.sponge.util.SpongeTitleManager; import com.plotsquared.sponge.util.SpongeUtil; @@ -77,8 +81,8 @@ import com.plotsquared.sponge.uuid.SpongeUUIDHandler; * Created by robin on 01/11/2014 */ -@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.0.0", dependencies = "before:WorldEdit,required-after:TotalEconomy") -public class SpongeMain implements IPlotMain, PluginContainer { +@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.3.0", dependencies = "before:WorldEdit") +public class SpongeMain implements IPlotMain { public static SpongeMain THIS; @Inject @@ -89,7 +93,7 @@ public class SpongeMain implements IPlotMain, PluginContainer { private GameProfileManager resolver; - @Override + // @Override public Logger getLogger() { return logger; } @@ -103,6 +107,9 @@ public class SpongeMain implements IPlotMain, PluginContainer { } public GameProfileManager getResolver() { + if (resolver == null) { + resolver = game.getServer().getGameProfileManager(); + } return resolver; } @@ -110,22 +117,22 @@ public class SpongeMain implements IPlotMain, PluginContainer { return THIS; } - @Override + // @Override public String getId() { return "PlotSquared"; } - @Override + // @Override public Optional getInstance() { return Optional. of(THIS); } - @Override + // @Override public String getName() { return "PlotSquared"; } - @Override + // @Override public String getVersion() { final int[] version = PS.get().getVersion(); String result = ""; @@ -151,11 +158,9 @@ public class SpongeMain implements IPlotMain, PluginContainer { public void onServerAboutToStart(final GameAboutToStartServerEvent event) { log("PlotSquared: Server init"); THIS = this; - resolver = game.getServiceManager().provide(GameProfileManager.class).get(); + new PS(this, "Sponge"); server = game.getServer(); game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) new HybridGen().specify()); - new PS(this, "Sponge"); - } @Override @@ -212,7 +217,7 @@ public class SpongeMain implements IPlotMain, PluginContainer { @Override public EconHandler getEconomyHandler() { SpongeEconHandler econ = new SpongeEconHandler(); - game.getEventManager().registerListeners(this, econ); + Sponge.getEventManager().registerListeners(this, econ); return econ; } @@ -258,7 +263,7 @@ public class SpongeMain implements IPlotMain, PluginContainer { @Override public void registerPlayerEvents() { - game.getEventManager().registerListeners(this, new MainListener()); + Sponge.getEventManager().registerListeners(this, new MainListener()); } @Override @@ -312,12 +317,12 @@ public class SpongeMain implements IPlotMain, PluginContainer { @Override public void registerChunkProcessor() { - game.getEventManager().registerListeners(this, new ChunkProcessor()); + Sponge.getEventManager().registerListeners(this, new ChunkProcessor()); } @Override public void registerWorldEvents() { - game.getEventManager().registerListeners(this, new WorldEvents()); + Sponge.getEventManager().registerListeners(this, new WorldEvents()); } @Override @@ -328,7 +333,7 @@ public class SpongeMain implements IPlotMain, PluginContainer { @Override public void startMetrics() { try { - final SpongeMetrics metrics = new SpongeMetrics(game, this); + final SpongeMetrics metrics = new SpongeMetrics(game, (PluginContainer) this); metrics.start(); log(C.PREFIX.s() + "&6Metrics enabled."); } catch (final Exception e) { @@ -398,7 +403,7 @@ public class SpongeMain implements IPlotMain, PluginContainer { @Override public String getNMSPackage() { - return "TODO";//TODO FIXME + return "";//TODO FIXME } @Override diff --git a/src/main/java/com/plotsquared/sponge/SpongeSetupUtils.java b/src/main/java/com/plotsquared/sponge/SpongeSetupUtils.java deleted file mode 100644 index d89d175fa..000000000 --- a/src/main/java/com/plotsquared/sponge/SpongeSetupUtils.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.plotsquared.sponge; - -import java.io.IOException; - -import org.spongepowered.api.world.World; -import org.spongepowered.api.world.gen.WorldGenerator; - -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.config.ConfigurationNode; -import com.intellectualcrafters.plot.generator.HybridGen; -import com.intellectualcrafters.plot.generator.PlotGenerator; -import com.intellectualcrafters.plot.object.PlotArea; -import com.intellectualcrafters.plot.object.SetupObject; -import com.intellectualcrafters.plot.util.SetupUtils; -import com.plotsquared.sponge.generator.SpongePlotGenerator; -import com.plotsquared.sponge.util.SpongeUtil; - -public class SpongeSetupUtils extends SetupUtils { - - @Override - public void updateGenerators() { - if (!SetupUtils.generators.isEmpty()) { - return; - } - SetupUtils.generators.put("PlotSquared", new SpongePlotGenerator(new HybridGen())); - // TODO get external world generators - throw new UnsupportedOperationException("TODO FETCH EXTERNAL WorldGenerationModifiers"); - } - - @Override - public String getGenerator(final PlotArea plotworld) { - if (SetupUtils.generators.isEmpty()) { - updateGenerators(); - } - final World world = SpongeUtil.getWorld(plotworld.worldname); - if (world == null) { - return null; - } - final WorldGenerator generator = world.getWorldGenerator(); - throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); - } - - @Override - public String setupWorld(final SetupObject object) { - SetupUtils.manager.updateGenerators(); - final ConfigurationNode[] steps = object.step; - final String world = object.world; - for (final ConfigurationNode step : steps) { - PS.get().config.set("worlds." + world + "." + step.getConstant(), step.getValue()); - } - if (object.type != 0) { - PS.get().config.set("worlds." + world + "." + "generator.type", object.type); - PS.get().config.set("worlds." + world + "." + "generator.terrain", object.terrain); - PS.get().config.set("worlds." + world + "." + "generator.plugin", object.plotManager); - if ((object.setupGenerator != null) && !object.setupGenerator.equals(object.plotManager)) { - PS.get().config.set("worlds." + world + "." + "generator.init", object.setupGenerator); - } - final PlotGenerator gen = (PlotGenerator) generators.get(object.setupGenerator); - if ((gen != null) && (gen.generator instanceof SpongePlotGenerator)) { - object.setupGenerator = null; - } - } - try { - PS.get().config.save(PS.get().configFile); - } catch (final IOException e) { - e.printStackTrace(); - } - // TODO FIXME - throw new UnsupportedOperationException("NOT IMPLEMENTED YET: Create a new world here"); - // return object.world; - } -} diff --git a/src/main/java/com/plotsquared/sponge/generator/SpongePlotGenerator.java b/src/main/java/com/plotsquared/sponge/generator/SpongePlotGenerator.java index 880803be4..caa96314a 100644 --- a/src/main/java/com/plotsquared/sponge/generator/SpongePlotGenerator.java +++ b/src/main/java/com/plotsquared/sponge/generator/SpongePlotGenerator.java @@ -4,35 +4,28 @@ import java.util.ArrayList; import java.util.List; import org.spongepowered.api.data.DataContainer; -import org.spongepowered.api.world.World; import org.spongepowered.api.world.WorldCreationSettings; +import org.spongepowered.api.world.biome.BiomeGenerationSettings; import org.spongepowered.api.world.biome.BiomeType; -import org.spongepowered.api.world.extent.ImmutableBiomeArea; +import org.spongepowered.api.world.biome.BiomeTypes; import org.spongepowered.api.world.extent.MutableBiomeArea; -import org.spongepowered.api.world.extent.MutableBlockVolume; import org.spongepowered.api.world.gen.BiomeGenerator; import org.spongepowered.api.world.gen.GenerationPopulator; import org.spongepowered.api.world.gen.WorldGenerator; import org.spongepowered.api.world.gen.WorldGeneratorModifier; import com.flowpowered.math.vector.Vector2i; -import com.flowpowered.math.vector.Vector3i; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotManager; -import com.intellectualcrafters.plot.object.PseudoRandom; -import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.SetQueue; -import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; +import com.intellectualcrafters.plot.util.ReflectionUtils; import com.plotsquared.sponge.util.SpongeUtil; -import com.plotsquared.sponge.util.block.GenChunk; public class SpongePlotGenerator implements WorldGeneratorModifier, GeneratorWrapper { - private final PseudoRandom random = new PseudoRandom(); private final IndependentPlotGenerator plotGenerator; private final List populators = new ArrayList<>(); private final boolean loaded = false; @@ -56,78 +49,54 @@ public class SpongePlotGenerator implements WorldGeneratorModifier, GeneratorWra @Override public String getId() { - return "PlotSquared"; + if (plotGenerator == null) { + if (platformGenerator != this) { + return platformGenerator.getId(); + } + return "null"; + } + return plotGenerator.getName(); } @Override public String getName() { - return "PlotSquared"; + if (plotGenerator == null) { + if (platformGenerator != this) { + return platformGenerator.getName(); + } + return "null"; + } + return plotGenerator.getName(); } @Override public void modifyWorldGenerator(WorldCreationSettings settings, DataContainer data, WorldGenerator wg) { - if (full) { - final String worldname = settings.getWorldName(); - wg.getGenerationPopulators().clear(); - wg.getPopulators().clear(); - wg.setBaseGenerationPopulator(new GenerationPopulator() { - @Override - public void populate(World world, MutableBlockVolume terrain, ImmutableBiomeArea biome) { - System.out.println("POPULATE!"); - Vector3i size = terrain.getBlockSize(); - if (size.getX() != 16 || size.getZ() != 16) { - throw new UnsupportedOperationException("NON CHUNK POPULATION NOT SUPPORTED"); - } - String worldname = world.getName(); - Vector3i min = terrain.getBlockMin(); - int cx = min.getX() >> 4; - int cz = min.getZ() >> 4; - ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(worldname, cx, cz); - // Create the result object - GenChunk result = new GenChunk(terrain, null, wrap); - // Catch any exceptions - try { - // Fill the result data if necessary - if (platformGenerator != SpongePlotGenerator.this) { - throw new UnsupportedOperationException("NOT IMPLEMENTED YET!"); - } else { - // Set random seed - random.state = (cx << 16) | (cz & 0xFFFF); - // Process the chunk - result.modified = false; - ChunkManager.preProcessChunk(result); - if (result.modified) { - return; - } - PlotArea area = PS.get().getPlotArea(world.getName(), null); - plotGenerator.generateChunk(result, area, random); - ChunkManager.postProcessChunk(result); - return; - } - } catch (Throwable e) { - e.printStackTrace(); + final String worldname = settings.getWorldName(); + wg.setBaseGenerationPopulator(new SpongeTerrainGen(this, plotGenerator)); + wg.setBiomeGenerator(new BiomeGenerator() { + @Override + public void generateBiomes(MutableBiomeArea buffer) { + PlotArea area = PS.get().getPlotArea(worldname, null); + if (area != null) { + BiomeType biome = SpongeUtil.getBiome(area.PLOT_BIOME); + Vector2i min = buffer.getBiomeMin(); + Vector2i max = buffer.getBiomeMax(); + for (int x = min.getX(); x <= max.getX(); x++) { + for (int z = min.getY(); z <= max.getY(); z++) { + buffer.setBiome(x, z, biome); } } - }); - wg.setBiomeGenerator(new BiomeGenerator() { - @Override - public void generateBiomes(MutableBiomeArea buffer) { - PlotArea area = PS.get().getPlotArea(worldname, null); - if (area != null) { - BiomeType biome = SpongeUtil.getBiome(area.PLOT_BIOME); - Vector2i min = buffer.getBiomeMin(); - Vector2i max = buffer.getBiomeMax(); - for (int x = min.getX(); x <= max.getX(); x++) { - for (int z = min.getY(); z <= max.getY(); z++) { - buffer.setBiome(x, z, biome); - } - } - } } - }); - } else { - throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } + }); + for (BiomeType type : ReflectionUtils. getStaticFields(BiomeTypes.class)) { + BiomeGenerationSettings biomeSettings = wg.getBiomeSettings(type); + biomeSettings.getGenerationPopulators().clear(); + biomeSettings.getPopulators().clear(); + } + wg.getGenerationPopulators().clear(); + wg.getPopulators().clear(); + PS.get().loadWorld(worldname, this); } @Override diff --git a/src/main/java/com/plotsquared/sponge/generator/SpongeTerrainGen.java b/src/main/java/com/plotsquared/sponge/generator/SpongeTerrainGen.java new file mode 100644 index 000000000..670d41653 --- /dev/null +++ b/src/main/java/com/plotsquared/sponge/generator/SpongeTerrainGen.java @@ -0,0 +1,61 @@ +package com.plotsquared.sponge.generator; + +import org.spongepowered.api.world.World; +import org.spongepowered.api.world.extent.ImmutableBiomeArea; +import org.spongepowered.api.world.extent.MutableBlockVolume; +import org.spongepowered.api.world.gen.GenerationPopulator; + +import com.flowpowered.math.vector.Vector3i; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PseudoRandom; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.SetQueue; +import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; +import com.plotsquared.sponge.util.block.GenChunk; + +public class SpongeTerrainGen implements GenerationPopulator { + + public final SpongePlotGenerator parent; + public final IndependentPlotGenerator child; + private final PseudoRandom random = new PseudoRandom(); + + public SpongeTerrainGen(SpongePlotGenerator parent, IndependentPlotGenerator ipg) { + this.parent = parent; + this.child = ipg; + } + + @Override + public void populate(World world, MutableBlockVolume terrain, ImmutableBiomeArea biomes) { + Vector3i size = terrain.getBlockSize(); + if (size.getX() != 16 || size.getZ() != 16) { + throw new UnsupportedOperationException("NON CHUNK POPULATION NOT SUPPORTED"); + } + String worldname = world.getName(); + Vector3i min = terrain.getBlockMin(); + int cx = min.getX() >> 4; + int cz = min.getZ() >> 4; + ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(worldname, cx, cz); + // Create the result object + GenChunk result = new GenChunk(terrain, null, wrap); + // Catch any exceptions + try { + // Set random seed + random.state = (cx << 16) | (cz & 0xFFFF); + // Process the chunk + result.modified = false; + ChunkManager.preProcessChunk(result); + if (result.modified) { + return; + } + // Fill the result data + PlotArea area = PS.get().getPlotArea(world.getName(), null); + child.generateChunk(result, area, random); + ChunkManager.postProcessChunk(result); + return; + } catch (Throwable e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/src/main/java/com/plotsquared/sponge/listener/MainListener.java index 4989d53c9..20eabc9af 100644 --- a/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -7,6 +7,7 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; import org.spongepowered.api.block.BlockSnapshot; @@ -25,12 +26,9 @@ import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.vehicle.Boat; import org.spongepowered.api.entity.vehicle.minecart.Minecart; import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.action.LightningEvent; +import org.spongepowered.api.event.action.InteractEvent; import org.spongepowered.api.event.block.ChangeBlockEvent; -import org.spongepowered.api.event.block.GrowBlockEvent; -import org.spongepowered.api.event.block.InteractBlockEvent; -import org.spongepowered.api.event.block.MoveBlockEvent; -import org.spongepowered.api.event.cause.Cause; +import org.spongepowered.api.event.block.NotifyNeighborBlockEvent; import org.spongepowered.api.event.command.SendCommandEvent; import org.spongepowered.api.event.entity.BreedEntityEvent; import org.spongepowered.api.event.entity.DisplaceEntityEvent; @@ -38,6 +36,7 @@ import org.spongepowered.api.event.entity.SpawnEntityEvent; import org.spongepowered.api.event.message.MessageEvent; import org.spongepowered.api.event.network.ClientConnectionEvent; import org.spongepowered.api.event.world.ExplosionEvent; +import org.spongepowered.api.event.world.ExplosionEvent.Detonate; import org.spongepowered.api.profile.GameProfile; import org.spongepowered.api.text.Text; import org.spongepowered.api.world.World; @@ -96,71 +95,85 @@ public class MainListener { * - Projectile * - enderman harvest */ - - // @Listener - // public void onFluidSpread(final NotifyNeighborBlockEvent event) { - // onPhysics(event); - // } - // - // @Listener - // public void onFluidSpread(final NotifyNeighborBlockEvent.Burn event) { - // onPhysics(event); - // } - // - // @Listener - // public void onFluidSpread(final NotifyNeighborBlockEvent.Ignite event) { - // onPhysics(event); - // } - // - // @Listener - // public void onFluidSpread(final NotifyNeighborBlockEvent.Power event) { - // // TODO redstone - // } - // - // public void onPhysics(final NotifyNeighborBlockEvent event) { - // final AtomicBoolean cancelled = new AtomicBoolean(false); - // final Map> relatives = event.getRelatives(); - // event.filterDirections(new Predicate() { - // - // @Override - // public boolean test(Direction dir) { - // if (cancelled.get()) { - // return true; - // } - // org.spongepowered.api.world.Location loc = relatives.get(dir); - // com.intellectualcrafters.plot.object.Location plotloc = SpongeUtil.getLocation(loc.getExtent().getName(), loc); - // Plot plot = MainUtil.getPlot(plotloc); - // if (plot == null) { - // if (MainUtil.isPlotAreaAbs(plotloc)) { - // cancelled.set(true); - // return false; - // } - // cancelled.set(true); - // return true; - // } - // org.spongepowered.api.world.Location relative = loc.getRelative(dir); - // com.intellectualcrafters.plot.object.Location relLoc = SpongeUtil.getLocation(relative.getExtent().getName(), relative); - // if (plot.equals(MainUtil.getPlot(relLoc))) { - // return true; - // } - // return false; - // } - // }); - // } - - public T getCause(Cause cause, Class clazz) { - Optional root = Optional.of(cause.root()); - if (root.isPresent()) { - Object source = root.get(); - if (clazz.isInstance(source)) { - return (T) source; + + @Listener + public void onCommand(final SendCommandEvent event) { + switch (event.getCommand().toLowerCase()) { + case "plotme": { + Player source = SpongeUtil. getCause(event.getCause(), Player.class); + if (source == null) { + return; + } + if (Settings.USE_PLOTME_ALIAS) { + SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim()); + } else { + source.sendMessage(SpongeUtil.text(C.NOT_USING_PLOTME.s())); + } + event.setCancelled(true); } } - return null; } @Listener - public void onCommand(final BreedEntityEvent.Breed event) { + public void onChat(final MessageEvent event) { + // TODO + Player player = SpongeUtil. getCause(event.getCause(), Player.class); + if (player == null) { + return; + } + final String world = player.getWorld().getName(); + if (!PS.get().hasPlotArea(world)) { + return; + } + final PlotArea plotworld = PS.get().getPlotAreaByString(world); + final PlotPlayer plr = SpongeUtil.getPlayer(player); + if (!plotworld.PLOT_CHAT && ((plr.getMeta("chat") == null) || !(Boolean) plr.getMeta("chat"))) { + return; + } + final Location loc = SpongeUtil.getLocation(player); + final Plot plot = loc.getPlot(); + if (plot == null) { + return; + } + final Text message = event.getMessage().orElse(Text.EMPTY); + + // TODO use display name rather than username + // - Getting displayname currently causes NPE, so wait until sponge fixes that + + final String sender = player.getName(); + final PlotId id = plot.getId(); + final String newMessage = StringMan.replaceAll(C.PLOT_CHAT_FORMAT.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender); + final Text forcedMessage = event.getMessage().orElse(Text.EMPTY); + // String forcedMessage = StringMan.replaceAll(C.PLOT_CHAT_FORCED.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender); + for (Entry entry : UUIDHandler.getPlayers().entrySet()) { + PlotPlayer user = entry.getValue(); + String toSend; + if (plot.equals(user.getLocation().getPlot())) { + toSend = newMessage; + } else if (Permissions.hasPermission(user, C.PERMISSION_COMMANDS_CHAT)) { + ((SpongePlayer) user).player.sendMessage(forcedMessage); + continue; + } else { + continue; + } + final String[] split = (toSend + " ").split("%msg%"); + final List components = new ArrayList<>(); + Text prefix = null; + for (final String part : split) { + if (prefix != null) { + components.add(prefix); + } else { + prefix = message; + } + components.add(Text.of(part)); + } + ((SpongePlayer) user).player.sendMessage(Text.join(components)); + } + event.setMessage(null); + } + + @Listener + public void onBreedEntity(final BreedEntityEvent.Breed event) { final Location loc = SpongeUtil.getLocation(event.getTargetEntity()); final String world = loc.getWorld(); final PlotArea plotworld = PS.get().getPlotAreaByString(world); @@ -178,17 +191,14 @@ public class MainListener { event.setCancelled(true); } } - - @Listener - public void onMobSpawn(final SpawnEntityEvent event) { + + public void onSpawnEntity(SpawnEntityEvent event) throws Exception { World world = event.getTargetWorld(); final PlotArea plotworld = PS.get().getPlotAreaByString(world.getName()); if (plotworld == null) { return; } - List entities = event.getEntities(); event.filterEntities(new Predicate() { - @Override public boolean test(Entity entity) { if (entity instanceof Player) { @@ -302,26 +312,135 @@ public class MainListener { } }); } - + + public void onNotifyNeighborBlock(NotifyNeighborBlockEvent event) throws Exception { + final AtomicBoolean cancelled = new AtomicBoolean(false); + SpongeUtil.printCause("physics", event.getCause()); + // PlotArea area = plotloc.getPlotArea(); + // event.filterDirections(new Predicate() { + // + // @Override + // public boolean test(Direction dir) { + // if (cancelled.get()) { + // return true; + // } + // org.spongepowered.api.world.Location loc = relatives.get(dir); + // com.intellectualcrafters.plot.object.Location plotloc = SpongeUtil.getLocation(loc.getExtent().getName(), loc); + // if (area == null) { + // return true; + // } + // plot = area.get + // Plot plot = plotloc.getPlot(); + // if (plot == null) { + // if (MainUtil.isPlotAreaAbs(plotloc)) { + // cancelled.set(true); + // return false; + // } + // cancelled.set(true); + // return true; + // } + // org.spongepowered.api.world.Location relative = loc.getRelative(dir); + // com.intellectualcrafters.plot.object.Location relLoc = SpongeUtil.getLocation(relative.getExtent().getName(), relative); + // if (plot.equals(MainUtil.getPlot(relLoc))) { + // return true; + // } + // return false; + // } + // }); + } + @Listener - public void onCommand(final SendCommandEvent event) { - switch (event.getCommand().toLowerCase()) { - case "plotme": { - Player source = this. getCause(event.getCause(), Player.class); - if (source == null) { - return; - } - if (Settings.USE_PLOTME_ALIAS) { - SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim()); - } else { - source.sendMessage(SpongeUtil.text(C.NOT_USING_PLOTME.s())); - } - event.setCancelled(true); + public void onInteract(InteractEvent event) throws Exception { + final Player player = SpongeUtil. getCause(event.getCause(), Player.class); + if (player == null) { + event.setCancelled(true); + return; + } + Optional target = event.getInteractionPoint(); + if (!target.isPresent()) { + return; + } + Location loc = SpongeUtil.getLocation(player.getWorld().getName(), target.get()); + org.spongepowered.api.world.Location l = SpongeUtil.getLocation(loc); + Plot plot = loc.getPlot(); + PlotPlayer pp = SpongeUtil.getPlayer(player); + if (plot == null) { + if (loc.getPlotAbs() == null) { + return; } + if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) { + event.setCancelled(true); + return; + } + return; + } + if (!plot.hasOwner()) { + if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED)) { + return; + } + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_UNOWNED); + event.setCancelled(true); + return; + } + if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) { + return; + } else { + final Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); + if ((flag != null) && ((HashSet) flag.getValue()).contains(SpongeUtil.getPlotBlock(l.getBlock()))) { + return; + } + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER); + event.setCancelled(true); + return; } } - public void onBlockChange(ChangeBlockEvent event) { + @Listener + public void onExplosion(ExplosionEvent e) throws Exception { + if (e instanceof ExplosionEvent.Detonate) { + ExplosionEvent.Detonate event = (Detonate) e; + final World world = event.getTargetWorld(); + final String worldname = world.getName(); + if (!PS.get().hasPlotArea(worldname)) { + return; + } + Optional source = event.getExplosion().getSourceExplosive(); + if (!source.isPresent()) { + event.setCancelled(true); + return; + } + Explosive tnt = source.get(); + Location origin = SpongeUtil.getLocation(worldname, tnt.getRotation()); + Plot originPlot = origin.getPlot(); + Location current = SpongeUtil.getLocation(tnt); + final Plot currentPlot = current.getPlot(); + if (!Objects.equals(originPlot, currentPlot)) { + event.setCancelled(true); + return; + } + if (originPlot == null && current.getPlotAbs() == null) { + return; + } + if (!FlagManager.isPlotFlagTrue(currentPlot, "explosion")) { + event.setCancelled(true); + return; + } + event.filter(new Predicate>() { + @Override + public boolean test(org.spongepowered.api.world.Location loc) { + return currentPlot.equals(SpongeUtil.getLocation(loc.getExtent().getName(), loc).getPlot()); + } + }); + event.filterEntities(new Predicate() { + @Override + public boolean test(Entity entity) { + return currentPlot.equals(SpongeUtil.getLocation(entity).getPlot()); + } + }); + } + } + + public void onChangeBlock(ChangeBlockEvent event) { final World world = event.getTargetWorld(); final String worldname = world.getName(); if (!PS.get().hasPlotArea(worldname)) { @@ -332,7 +451,7 @@ public class MainListener { Location loc = SpongeUtil.getLocation(worldname, first.getOriginal().getPosition()); Plot plot = loc.getPlot(); if (plot == null) { - if (loc.getPlotAbs() == null ) { + if (loc.getPlotAbs() == null) { return; } event.setCancelled(true); @@ -349,162 +468,25 @@ public class MainListener { } }); } - - @Listener - public void onBlockMove(final MoveBlockEvent event) { - onBlockChange(event); - } - - @Listener - public void onFloraGrow(final GrowBlockEvent event) { - onBlockChange(event); - } - - @Listener - public void onLightning(final LightningEvent.Strike event) { - onBlockChange(event); - } - - public void printCause(String method, Cause cause) { - System.out.println(method + ": " + cause.toString()); - System.out.println(method + ": " + cause.getClass()); - System.out.println(method + ": " + (cause.root())); - } - - @Listener - public void onChat(final MessageEvent event) { - // TODO - Player player = this. getCause(event.getCause(), Player.class); - if (player == null) { - return; - } - final String world = player.getWorld().getName(); - if (!PS.get().hasPlotArea(world)) { - return; - } - final PlotArea plotworld = PS.get().getPlotAreaByString(world); - final PlotPlayer plr = SpongeUtil.getPlayer(player); - if (!plotworld.PLOT_CHAT && ((plr.getMeta("chat") == null) || !(Boolean) plr.getMeta("chat"))) { - return; - } - final Location loc = SpongeUtil.getLocation(player); - final Plot plot = loc.getPlot(); - if (plot == null) { - return; - } - final Text message = event.getMessage().orElse(Text.EMPTY); - - // TODO use display name rather than username - // - Getting displayname currently causes NPE, so wait until sponge fixes that - - final String sender = player.getName(); - final PlotId id = plot.getId(); - final String newMessage = StringMan.replaceAll(C.PLOT_CHAT_FORMAT.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender); - final Text forcedMessage = event.getMessage().orElse(Text.EMPTY); - // String forcedMessage = StringMan.replaceAll(C.PLOT_CHAT_FORCED.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender); - for (Entry entry : UUIDHandler.getPlayers().entrySet()) { - PlotPlayer user = entry.getValue(); - String toSend; - if (plot.equals(user.getLocation().getPlot())) { - toSend = newMessage; - } else if (Permissions.hasPermission(user, C.PERMISSION_COMMANDS_CHAT)) { - ((SpongePlayer) user).player.sendMessage(forcedMessage); - continue; - } else { - continue; - } - final String[] split = (toSend + " ").split("%msg%"); - final List components = new ArrayList<>(); - Text prefix = null; - for (final String part : split) { - if (prefix != null) { - components.add(prefix); - } else { - prefix = message; - } - components.add(Text.of(part)); - } - ((SpongePlayer) user).player.sendMessage(Text.join(components)); - } - event.setMessage(null); - } - - @Listener - public void onBigBoom(final ExplosionEvent.Detonate event) { - final World world = event.getTargetWorld(); - final String worldname = world.getName(); - if (!PS.get().hasPlotArea(worldname)) { - return; - } - Optional source = event.getExplosion().getSourceExplosive(); - if (!source.isPresent()) { - event.setCancelled(true); - return; - } - Explosive tnt = source.get(); - Location origin = SpongeUtil.getLocation(worldname, tnt.getRotation()); - Plot originPlot = origin.getPlot(); - Location current = SpongeUtil.getLocation(tnt); - final Plot currentPlot = current.getPlot(); - if (!Objects.equals(originPlot, currentPlot)) { - event.setCancelled(true); - return; - } - if (originPlot == null && current.getPlotAbs() == null) { - return; - } - if (!FlagManager.isPlotFlagTrue(currentPlot, "explosion")) { - event.setCancelled(true); - return; - } - event.filter(new Predicate>() { - @Override - public boolean test(org.spongepowered.api.world.Location loc) { - return currentPlot.equals(SpongeUtil.getLocation(loc.getExtent().getName(), loc).getPlot()); - } - }); - event.filterEntities(new Predicate() { - @Override - public boolean test(Entity entity) { - return currentPlot.equals(SpongeUtil.getLocation(entity).getPlot()); - } - }); - } - - // @Listener - // public void onChunkPreGenerator(final ChunkPreGenerateEvent event) { - // final org.spongepowered.api.world.Chunk chunk = event.getChunk(); - // final World world = chunk.getWorld(); - // final String worldname = world.getName(); - // if (MainUtil.worldBorder.containsKey(worldname)) { - // final int border = MainUtil.getBorder(worldname); - // final Vector3i min = world.getBlockMin(); - // final int x = Math.abs(min.getX()); - // final int z = Math.abs(min.getZ()); - // if ((x > border) || (z > border)) { - // // TODO cancel this chunk from loading - // // - Currently not possible / this event doesn't seem to be called - // } - // } - // } - + @Listener public void onBlockBreak(final ChangeBlockEvent.Decay event) { - onBlockChange(event); + onChangeBlock(event); } + @Listener public void onBlockBreak(final ChangeBlockEvent.Grow event) { - onBlockChange(event); + onChangeBlock(event); } @Listener public void onBlockBreak(final ChangeBlockEvent.Modify event) { - onBlockChange(event); + onChangeBlock(event); } @Listener public void onBlockBreak(final ChangeBlockEvent.Break event) { - Player player = this. getCause(event.getCause(), Player.class); + Player player = SpongeUtil. getCause(event.getCause(), Player.class); if (player == null) { event.setCancelled(true); return; @@ -588,7 +570,7 @@ public class MainListener { @Listener public void onBlockPlace(final ChangeBlockEvent.Place event) { - Player player = this. getCause(event.getCause(), Player.class); + Player player = SpongeUtil. getCause(event.getCause(), Player.class); if (player == null) { event.setCancelled(true); return; @@ -670,52 +652,6 @@ public class MainListener { }); } - @Listener - public void onBlockInteract(final InteractBlockEvent.Secondary event) { - final Player player = this. getCause(event.getCause(), Player.class); - if (player == null) { - event.setCancelled(true); - return; - } - Optional> target = event.getTargetBlock().getLocation(); - if (!target.isPresent()) { - return; - } - org.spongepowered.api.world.Location l = target.get(); - Location loc = SpongeUtil.getLocation(l); - Plot plot = loc.getPlot(); - PlotPlayer pp = SpongeUtil.getPlayer(player); - if (plot == null) { - if (loc.getPlotAbs() == null) { - return; - } - if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) { - event.setCancelled(true); - return; - } - return; - } - if (!plot.hasOwner()) { - if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED)) { - return; - } - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_UNOWNED); - event.setCancelled(true); - return; - } - if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) { - return; - } else { - final Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); - if ((flag != null) && ((HashSet) flag.getValue()).contains(SpongeUtil.getPlotBlock(l.getBlock()))) { - return; - } - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER); - event.setCancelled(true); - return; - } - } - @Listener public void onConnect(final ClientConnectionEvent.Login event) { GameProfile profile = event.getProfile(); @@ -764,16 +700,12 @@ public class MainListener { pp.unregister(); } - public int getInt(final double value) { - return (int) (value < 0 ? value - 1 : value); - } - @Listener public void onMove(final DisplaceEntityEvent.TargetPlayer event) { final org.spongepowered.api.world.Location from = event.getFromTransform().getLocation(); org.spongepowered.api.world.Location to = event.getToTransform().getLocation(); int x2; - if (getInt(from.getX()) != (x2 = getInt(to.getX()))) { + if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) { final Player player = event.getTargetEntity(); final PlotPlayer pp = SpongeUtil.getPlayer(player); final Extent extent = to.getExtent(); @@ -789,7 +721,7 @@ public class MainListener { return; } final PlotManager plotManager = PS.get().getPlotManager(PS.get().getPlot(plotworld, plotworld.getMin())); - final PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ())); + final PlotId id = plotManager.getPlotId(plotworld, x2, 0, MathMan.roundInt(to.getZ())); final Plot lastPlot = (Plot) pp.getMeta("lastplot"); if (id == null) { if (lastPlot == null) { @@ -835,7 +767,7 @@ public class MainListener { return; } int z2; - if (getInt(from.getZ()) != (z2 = getInt(to.getZ()))) { + if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) { final Player player = event.getTargetEntity(); final PlotPlayer pp = SpongeUtil.getPlayer(player); final Extent extent = to.getExtent(); diff --git a/src/main/java/com/plotsquared/sponge/listener/WorldEvents.java b/src/main/java/com/plotsquared/sponge/listener/WorldEvents.java index 92c564e48..626ca2a9a 100644 --- a/src/main/java/com/plotsquared/sponge/listener/WorldEvents.java +++ b/src/main/java/com/plotsquared/sponge/listener/WorldEvents.java @@ -1,5 +1,28 @@ package com.plotsquared.sponge.listener; +import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.world.LoadWorldEvent; +import org.spongepowered.api.world.World; +import org.spongepowered.api.world.gen.GenerationPopulator; +import org.spongepowered.api.world.gen.WorldGenerator; + +import com.intellectualcrafters.plot.PS; +import com.plotsquared.sponge.generator.SpongeTerrainGen; + public class WorldEvents { - // TODO FIXME + + @Listener + public void onLoadWorld(LoadWorldEvent event) { + final World world = event.getTargetWorld(); + final String name = world.getName(); + WorldGenerator generator = world.getWorldGenerator(); + GenerationPopulator terrain = generator.getBaseGenerationPopulator(); + if (terrain instanceof SpongeTerrainGen) { + SpongeTerrainGen stg = (SpongeTerrainGen) terrain; + PS.get().loadWorld(name, stg.parent); + } + else if (PS.get().config.contains("worlds." + name)) { + PS.get().loadWorld(name, null); + } + } } diff --git a/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java b/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java index 2f79e5ebc..bca246f79 100644 --- a/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java +++ b/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java @@ -15,6 +15,7 @@ import org.spongepowered.api.entity.living.player.gamemode.GameModes; import org.spongepowered.api.service.ban.BanService; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.chat.ChatTypes; +import org.spongepowered.api.text.serializer.TextSerializers; import com.flowpowered.math.vector.Vector3d; import com.intellectualcrafters.plot.commands.RequiredType; @@ -99,7 +100,7 @@ public class SpongePlayer extends PlotPlayer { @Override public void sendMessage(final String message) { - player.sendMessage(ChatTypes.CHAT, Text.of(message)); + player.sendMessage(ChatTypes.CHAT, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message)); } @Override diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java index aac8190d9..507c0f839 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java @@ -1,12 +1,14 @@ package com.plotsquared.sponge.util; +import org.spongepowered.api.text.Text; +import org.spongepowered.api.text.action.TextActions; +import org.spongepowered.api.text.serializer.TextSerializers; + import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.PlotMessage; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.ChatManager; import com.plotsquared.sponge.object.SpongePlayer; -import org.spongepowered.api.text.Text; -import org.spongepowered.api.text.action.TextActions; public class SpongeChatManager extends ChatManager { @@ -17,7 +19,7 @@ public class SpongeChatManager extends ChatManager { @Override public void color(final PlotMessage m, final String color) { - m.$(this).color(Text.of(color).getColor()); + m.$(this).color(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(color).getColor()); } @Override diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java index 8493d7a3a..76e097fab 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java @@ -74,9 +74,11 @@ public class SpongeChunkManager extends ChunkManager { @Override public void regenerateChunk(final String world, final ChunkLoc loc) { final World worldObj = SpongeUtil.getWorld(world); - final Optional chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4); - if (chunk.isPresent()) { - // TODO regenerate chunk + final Optional chunkOpt = worldObj.getChunk(loc.x << 4, 0, loc.z << 4); + if (chunkOpt.isPresent()) { + Chunk chunk = chunkOpt.get(); + // TODO FIXME + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } } @@ -114,7 +116,7 @@ public class SpongeChunkManager extends ChunkManager { @Override public void swap(Location bot1, Location top1, Location bot2, Location top2, Runnable whenDone) { // TODO swap region - + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } @Override diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeEconHandler.java b/src/main/java/com/plotsquared/sponge/util/SpongeEconHandler.java index c0e2303cc..0efdbebfe 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeEconHandler.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeEconHandler.java @@ -3,13 +3,13 @@ package com.plotsquared.sponge.util; import java.math.BigDecimal; import java.util.Optional; -import org.apache.commons.lang.NotImplementedException; import org.spongepowered.api.Sponge; +import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.cause.Cause; +import org.spongepowered.api.event.service.ChangeServiceProviderEvent; import org.spongepowered.api.service.economy.EconomyService; import org.spongepowered.api.service.economy.account.UniqueAccount; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.EconHandler; @@ -22,8 +22,13 @@ public class SpongeEconHandler extends EconHandler { public SpongeEconHandler() { if (Sponge.getServiceManager().isRegistered(EconomyService.class)) { econ = Sponge.getServiceManager().provide(EconomyService.class).get(); - } else { - PS.log("No economy service was registered."); + } + } + + @Listener + public void onChangeServiceProvider(ChangeServiceProviderEvent event) { + if (event.getService().equals(EconomyService.class)) { + econ = (EconomyService) event.getNewProviderRegistration().getProvider(); } } @@ -33,6 +38,7 @@ public class SpongeEconHandler extends EconHandler { Optional accOpt = econ.getAccount(player.getUUID()); if (accOpt.isPresent()) { UniqueAccount acc = accOpt.get(); + acc.withdraw(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared")); } } @@ -63,7 +69,7 @@ public class SpongeEconHandler extends EconHandler { @Override public void setPermission(String world, String player, String perm, boolean value) { // TODO Auto-generated method stub - throw new NotImplementedException("TODO/WIP/NOT IMPLEMENTED!"); + throw new UnsupportedOperationException("TODO/WIP/NOT IMPLEMENTED!"); } @Override diff --git a/src/main/java/com/plotsquared/sponge/SpongeHybridUtils.java b/src/main/java/com/plotsquared/sponge/util/SpongeHybridUtils.java similarity index 90% rename from src/main/java/com/plotsquared/sponge/SpongeHybridUtils.java rename to src/main/java/com/plotsquared/sponge/util/SpongeHybridUtils.java index d4072ef1e..6ce3c5ada 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeHybridUtils.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeHybridUtils.java @@ -1,22 +1,19 @@ -package com.plotsquared.sponge; +package com.plotsquared.sponge.util; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockTypes; import org.spongepowered.api.world.World; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.object.PlotAnalysis; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; -import com.plotsquared.sponge.util.SpongeUtil; public class SpongeHybridUtils extends HybridUtils { @Override public int checkModified(final String worldname, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks) { - PS.debug("checkModified is not implemented"); final World world = SpongeUtil.getWorld(worldname); int count = 0; for (int y = y1; y <= y2; y++) { @@ -61,8 +58,7 @@ public class SpongeHybridUtils extends HybridUtils { @Override public void analyzeRegion(String world, RegionWrapper region, RunnableVal whenDone) { - // TODO Auto-generated method stub - whenDone.run(); + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } } diff --git a/src/main/java/com/plotsquared/sponge/SpongeSchematicHandler.java b/src/main/java/com/plotsquared/sponge/util/SpongeSchematicHandler.java similarity index 88% rename from src/main/java/com/plotsquared/sponge/SpongeSchematicHandler.java rename to src/main/java/com/plotsquared/sponge/util/SpongeSchematicHandler.java index ebfc1e512..f60894031 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeSchematicHandler.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeSchematicHandler.java @@ -1,12 +1,16 @@ -package com.plotsquared.sponge; +package com.plotsquared.sponge.util; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import org.spongepowered.api.block.BlockState; +import org.spongepowered.api.item.inventory.Carrier; +import org.spongepowered.api.item.inventory.type.CarriedInventory; import org.spongepowered.api.world.World; import com.intellectualcrafters.jnbt.ByteArrayTag; @@ -24,7 +28,6 @@ import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.TaskManager; -import com.plotsquared.sponge.util.SpongeUtil; public class SpongeSchematicHandler extends SchematicHandler { @@ -253,8 +256,27 @@ public class SpongeSchematicHandler extends SchematicHandler { case 33: case 151: case 178: { - // TODO wrap block state... - // TODO add block state to map + CompoundTag rawTag; + if (state instanceof Carrier) { + Carrier chest = (Carrier) state; + CarriedInventory inv = chest.getInventory(); + // TODO serialize inventory + rawTag = null; + } else { + rawTag = null; + } + if (rawTag != null) { + final Map values = new HashMap(); + for (final Entry entry : rawTag.getValue().entrySet()) { + values.put(entry.getKey(), entry.getValue()); + } + values.put("id", new StringTag("id", "Chest")); + values.put("x", new IntTag("x", x)); + values.put("y", new IntTag("y", y)); + values.put("z", new IntTag("z", z)); + final CompoundTag tileEntityTag = new CompoundTag(values); + tileEntities.add(tileEntityTag); + } } default: { blockData[index] = block.data; diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java b/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java new file mode 100644 index 000000000..ea80e866b --- /dev/null +++ b/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java @@ -0,0 +1,176 @@ +package com.plotsquared.sponge.util; + +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Objects; + +import org.spongepowered.api.Sponge; +import org.spongepowered.api.world.DimensionTypes; +import org.spongepowered.api.world.GeneratorTypes; +import org.spongepowered.api.world.World; +import org.spongepowered.api.world.WorldCreationSettings; +import org.spongepowered.api.world.WorldCreationSettings.Builder; +import org.spongepowered.api.world.gen.WorldGenerator; +import org.spongepowered.api.world.gen.WorldGeneratorModifier; +import org.spongepowered.api.world.storage.WorldProperties; + +import com.intellectualcrafters.configuration.ConfigurationSection; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.config.ConfigurationNode; +import com.intellectualcrafters.plot.generator.GeneratorWrapper; +import com.intellectualcrafters.plot.generator.HybridGen; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.SetupObject; +import com.intellectualcrafters.plot.util.SetupUtils; +import com.plotsquared.sponge.generator.SpongePlotGenerator; + +public class SpongeSetupUtils extends SetupUtils { + + @Override + public void updateGenerators() { + if (!SetupUtils.generators.isEmpty()) { + return; + } + SetupUtils.generators.put("PlotSquared", new SpongePlotGenerator(new HybridGen())); + // TODO get external world generators + Collection wgms = Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class); + for (WorldGeneratorModifier wgm : wgms) { + String id = wgm.getId(); + String name = wgm.getName(); + if (wgm instanceof GeneratorWrapper) { + generators.put(id, (GeneratorWrapper) wgm); + generators.put(name, (GeneratorWrapper) wgm); + } else { + SpongePlotGenerator wrap = new SpongePlotGenerator(wgm); + generators.put(id, wrap); + generators.put(name, wrap); + } + } + } + + @Override + public String getGenerator(final PlotArea plotworld) { + if (SetupUtils.generators.isEmpty()) { + updateGenerators(); + } + final World world = SpongeUtil.getWorld(plotworld.worldname); + if (world == null) { + return null; + } + final WorldGenerator generator = world.getWorldGenerator(); + throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + } + + @Override + public String setupWorld(final SetupObject object) { + SetupUtils.manager.updateGenerators(); + ConfigurationNode[] steps = object.step == null ? new ConfigurationNode[0] : object.step; + final String world = object.world; + int type = object.type; + String worldPath = "worlds." + object.world; + if (!PS.get().config.contains(worldPath)) { + PS.get().config.createSection(worldPath); + } + ConfigurationSection worldSection = PS.get().config.getConfigurationSection(worldPath); + switch (type) { + case 2: { + if (object.id != null) { + String areaname = object.id + "-" + object.min + "-" + object.max; + String areaPath = "areas." + areaname; + if (!worldSection.contains(areaPath)) { + worldSection.createSection(areaPath); + } + ConfigurationSection areaSection = worldSection.getConfigurationSection(areaPath); + HashMap options = new HashMap<>(); + for (final ConfigurationNode step : steps) { + options.put(step.getConstant(), step.getValue()); + } + options.put("generator.type", object.type); + options.put("generator.terrain", object.terrain); + options.put("generator.plugin", object.plotManager); + if ((object.setupGenerator != null) && !object.setupGenerator.equals(object.plotManager)) { + options.put("generator.init", object.setupGenerator); + } + for (Entry entry : options.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + if (worldSection.contains(key)) { + Object current = worldSection.get(key); + if (!Objects.equals(value, current)) { + areaSection.set(key, value); + } + } else { + worldSection.set(key, value); + } + } + } + GeneratorWrapper gen = generators.get(object.setupGenerator); + if ((gen != null) && gen.isFull()) { + object.setupGenerator = null; + } + break; + } + case 1: { + for (final ConfigurationNode step : steps) { + worldSection.set(step.getConstant(), step.getValue()); + } + PS.get().config.set("worlds." + world + "." + "generator.type", object.type); + PS.get().config.set("worlds." + world + "." + "generator.terrain", object.terrain); + PS.get().config.set("worlds." + world + "." + "generator.plugin", object.plotManager); + if ((object.setupGenerator != null) && !object.setupGenerator.equals(object.plotManager)) { + PS.get().config.set("worlds." + world + "." + "generator.init", object.setupGenerator); + } + GeneratorWrapper gen = generators.get(object.setupGenerator); + if ((gen != null) && gen.isFull()) { + object.setupGenerator = null; + } + break; + } + case 0: { + for (final ConfigurationNode step : steps) { + worldSection.set(step.getConstant(), step.getValue()); + } + break; + } + } + try { + PS.get().config.save(PS.get().configFile); + } catch (final IOException e) { + e.printStackTrace(); + } + if (object.setupGenerator != null) { + // create world with generator + GeneratorWrapper gw = generators.get(object.setupGenerator); + WorldGeneratorModifier wgm = (WorldGeneratorModifier) gw.getPlatformGenerator(); + + WorldCreationSettings settings = Sponge.getRegistry().createBuilder(Builder.class) + .name(object.world) + .loadsOnStartup(true) + .keepsSpawnLoaded(false) + .dimension(DimensionTypes.OVERWORLD) + .generator(GeneratorTypes.FLAT) + .usesMapFeatures(false) + .enabled(true) + .generatorModifiers(wgm) + .build(); + WorldProperties properties = Sponge.getServer().createWorldProperties(settings).get(); + World worldObj = Sponge.getServer().loadWorld(properties).get(); + } else { + // create vanilla world + WorldCreationSettings settings = Sponge.getRegistry().createBuilder(Builder.class) + .name(object.world) + .loadsOnStartup(true) + .keepsSpawnLoaded(false) + .dimension(DimensionTypes.OVERWORLD) + .generator(GeneratorTypes.OVERWORLD) + .usesMapFeatures(true) + .enabled(true) + .build(); + WorldProperties properties = Sponge.getServer().createWorldProperties(settings).get(); + World worldObj = Sponge.getServer().loadWorld(properties).get(); + } + return object.world; + } +} diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java b/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java index 008abecd3..6ec798db9 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java @@ -1,6 +1,8 @@ package com.plotsquared.sponge.util; import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -17,6 +19,7 @@ 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.event.cause.Cause; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.translation.Translatable; import org.spongepowered.api.text.translation.Translation; @@ -27,6 +30,7 @@ import org.spongepowered.api.world.extent.Extent; import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3i; +import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -35,6 +39,7 @@ 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.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.sponge.SpongeMain; @@ -59,6 +64,24 @@ public class SpongeUtil extends WorldUtil { return biomes[biomeMap.get(biome.toUpperCase())]; } + public static T getCause(Cause cause, Class 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())); + System.out.println(method + ": " + (cause.root())); + } + public static void initBiomeCache() { try { Field[] fields = BiomeTypes.class.getFields(); @@ -112,12 +135,61 @@ public class SpongeUtil extends WorldUtil { }.getTranslation(); } - public static BlockState getBlockState(int id, int data) { - throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + private static HashMap stateMap; + private static BlockState[] stateArray; + + private static void initBlockCache() { + try { + PS.debug("Caching block id/data: Please wait..."); + stateArray = new BlockState[Character.MAX_VALUE]; + stateMap = new HashMap<>(); + Class classBlock = Class.forName("net.minecraft.block.Block"); + Class classBlockState = Class.forName("net.minecraft.block.state.IBlockState"); + Method[] blockMethods = classBlock.getDeclaredMethods(); + Method methodGetByCombinedId = null; + for (Method method : blockMethods) { + Class result = method.getReturnType(); + Class[] param = method.getParameterTypes(); + int paramCount = param.length; + boolean isStatic = Modifier.isStatic(method.getModifiers()); + if (methodGetByCombinedId == null) { + if (isStatic && result == classBlockState && paramCount == 1 && param[0] == int.class) { + methodGetByCombinedId = method; + continue; + } + } + } + for (int i = 0; i < Character.MAX_VALUE; i++) { + try { + BlockState state = (BlockState) methodGetByCombinedId.invoke(null, i); + if (state.getType() == BlockTypes.AIR) { + continue; + } + int id = i & 0xFFF; + int data = i >> 12 & 0xF; + PlotBlock plotBlock = new PlotBlock((short) id, (byte) data); + stateArray[i] = state; + stateMap.put(state, plotBlock); + } catch (Throwable e) {} + } + PS.debug("Done!"); + } catch (Throwable e) { + e.printStackTrace(); + } } + public static BlockState getBlockState(int id, int data) { + if (stateArray == null) { + initBlockCache(); + } + return stateArray[id + (data << 12)]; + } + public static PlotBlock getPlotBlock(BlockState state) { - throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + if (stateMap == null) { + initBlockCache(); + } + return stateMap.get(state); } public static Location getLocation(final org.spongepowered.api.world.Location block) { @@ -165,7 +237,7 @@ public class SpongeUtil extends WorldUtil { if (world == last) { return lastWorld; } - final Optional optional = SpongeMain.THIS.getServer().getWorld(world); + final Optional optional = Sponge.getServer().getWorld(world); if (!optional.isPresent()) { return null; } diff --git a/src/main/resources/data.txt b/src/main/resources/data.txt deleted file mode 100644 index 91bc2de45..000000000 --- a/src/main/resources/data.txt +++ /dev/null @@ -1,40 +0,0 @@ -Arts -BannerPatternShapes -BigMushroomTypes -BodyParts -BrickTypes -Careers -CoalTypes -Comparisons -CookedFishes -DirtTypes -DisguisedBlockTypes -DoubleSizePlantTypes -DyeColors -Fishes -GoldenApples -Hinges -HorseColors -HorseStyles -HorseVariants -InstrumentTypes -NotePitches -OcelotTypes -PistonTypes -PlantTypes -PortionTypes -PrismarineTypes -Professions -QuartzTypes -RabbitTypes -RailDirections -SandstoneTypes -SandTypes -ShrubTypes -SkeletonTypes -SkullTypes -SlabTypes -StairShapes -StoneTypes -TreeTypes -WallTypes \ No newline at end of file diff --git a/src/main/resources/ids.txt b/src/main/resources/ids.txt deleted file mode 100644 index f40c897d9..000000000 --- a/src/main/resources/ids.txt +++ /dev/null @@ -1,1068 +0,0 @@ -0 -Air -minecraft:air -1 -Stone -minecraft:stone -1:1 -Granite -minecraft:stone -1:2 -Polished_Granite -minecraft:stone -1:3 -Diorite -minecraft:stone -1:4 -Polished_Diorite -minecraft:stone -1:5 -Andesite -minecraft:stone -1:6 -Polished_Andesite -minecraft:stone -2 -Grass -minecraft:grass -3 -Dirt -minecraft:dirt -3:1 -Coarse_Dirt -minecraft:dirt -3:2 -Podzol -minecraft:dirt -4 -Cobblestone -minecraft:cobblestone -5 -Oak_Wood_Plank -minecraft:planks -5:1 -Spruce_Wood_Plank -minecraft:planks -5:2 -Birch_Wood_Plank -minecraft:planks -5:3 -Jungle_Wood_Plank -minecraft:planks -5:4 -Acacia_Wood_Plank -minecraft:planks -5:5 -Dark_Oak_Wood_Plank -minecraft:planks -6 -Oak_Sapling -minecraft:sapling -6:1 -Spruce_Sapling -minecraft:sapling -6:2 -Birch_Sapling -minecraft:sapling -6:3 -Jungle_Sapling -minecraft:sapling -6:4 -Acacia_Sapling -minecraft:sapling -6:5 -Dark_Oak_Sapling -minecraft:sapling -7 -Bedrock -minecraft:bedrock -8 -Flowing_Water -minecraft:flowing_water -9 -Still_Water -minecraft:water -10 -Flowing_Lava -minecraft:flowing_lava -11 -Still_Lava -minecraft:lava -12 -Sand -minecraft:sand -12:1 -Red_Sand -minecraft:sand -13 -Gravel -minecraft:gravel -14 -Gold_Ore -minecraft:gold_ore -15 -Iron_Ore -minecraft:iron_ore -16 -Coal_Ore -minecraft:coal_ore -17 -Oak_Wood -minecraft:log -17:1 -Spruce_Wood -minecraft:log -17:2 -Birch_Wood -minecraft:log -17:3 -Jungle_Wood -minecraft:log -18 -Oak_Leaves -minecraft:leaves -18:1 -Spruce_Leaves -minecraft:leaves -18:2 -Birch_Leaves -minecraft:leaves -18:3 -Jungle_Leaves -minecraft:leaves -19 -Sponge -minecraft:sponge -19:1 -Wet_Sponge -minecraft:sponge -20 -Glass -minecraft:glass -21 -Lapis_Lazuli_Ore -minecraft:lapis_ore -22 -Lapis_Lazuli_Block -minecraft:lapis_block -23 -Dispenser -minecraft:dispenser -24 -Sandstone -minecraft:sandstone -24:1 -Chiseled_Sandstone -minecraft:sandstone -24:2 -Smooth_Sandstone -minecraft:sandstone -25 -Note_Block -minecraft:noteblock -26 -Bed -minecraft:bed -27 -Powered_Rail -minecraft:golden_rail -28 -Detector_Rail -minecraft:detector_rail -29 -Sticky_Piston -minecraft:sticky_piston -30 -Cobweb -minecraft:web -31 -Dead_Shrub -minecraft:tallgrass -31:1 -Grass -minecraft:tallgrass -31:2 -Fern -minecraft:tallgrass -32 -Dead_Bush -minecraft:deadbush -33 -Piston -minecraft:piston -34 -Piston_Head -minecraft:piston_head -35 -White_Wool -minecraft:wool -35:1 -Orange_Wool -minecraft:wool -35:2 -Magenta_Wool -minecraft:wool -35:3 -Light_Blue_Wool -minecraft:wool -35:4 -Yellow_Wool -minecraft:wool -35:5 -Lime_Wool -minecraft:wool -35:6 -Pink_Wool -minecraft:wool -35:7 -Gray_Wool -minecraft:wool -35:8 -Light_Gray_Wool -minecraft:wool -35:9 -Cyan_Wool -minecraft:wool -35:10 -Purple_Wool -minecraft:wool -35:11 -Blue_Wool -minecraft:wool -35:12 -Brown_Wool -minecraft:wool -35:13 -Green_Wool -minecraft:wool -35:14 -Red_Wool -minecraft:wool -35:15 -Black_Wool -minecraft:wool -37 -Dandelion -minecraft:yellow_flower -38 -Poppy -minecraft:red_flower -38:1 -Blue_Orchid -minecraft:red_flower -38:2 -Allium -minecraft:red_flower -38:3 -Azure_Bluet -minecraft:red_flower -38:4 -Red_Tulip -minecraft:red_flower -38:5 -Orange_Tulip -minecraft:red_flower -38:6 -White_Tulip -minecraft:red_flower -38:7 -Pink_Tulip -minecraft:red_flower -38:8 -Oxeye_Daisy -minecraft:red_flower -39 -Brown_Mushroom -minecraft:brown_mushroom -40 -Red_Mushroom -minecraft:red_mushroom -41 -Gold_Block -minecraft:gold_block -42 -Iron_Block -minecraft:iron_block -43 -Double_Stone_Slab -minecraft:double_stone_slab -43:1 -Double_Sandstone_Slab -minecraft:double_stone_slab -43:2 -Double_Wooden_Slab -minecraft:double_stone_slab -43:3 -Double_Cobblestone_Slab -minecraft:double_stone_slab -43:4 -Double_Brick_Slab -minecraft:double_stone_slab -43:5 -Double_Stone_Brick_Slab -minecraft:double_stone_slab -43:6 -Double_Nether_Brick_Slab -minecraft:double_stone_slab -43:7 -Double_Quartz_Slab -minecraft:double_stone_slab -44 -Stone_Slab -minecraft:stone_slab -44:1 -Sandstone_Slab -minecraft:stone_slab -44:2 -Wooden_Slab -minecraft:stone_slab -44:3 -Cobblestone_Slab -minecraft:stone_slab -44:4 -Brick_Slab -minecraft:stone_slab -44:5 -Stone_Brick_Slab -minecraft:stone_slab -44:6 -Nether_Brick_Slab -minecraft:stone_slab -44:7 -Quartz_Slab -minecraft:stone_slab -45 -Bricks -minecraft:brick_block -46 -TNT -minecraft:tnt -47 -Bookshelf -minecraft:bookshelf -48 -Moss_Stone -minecraft:mossy_cobblestone -49 -Obsidian -minecraft:obsidian -50 -Torch -minecraft:torch -51 -Fire -minecraft:fire -52 -Monster_Spawner -minecraft:mob_spawner -53 -Oak_Wood_Stairs -minecraft:oak_stairs -54 -Chest -minecraft:chest -55 -Redstone_Wire -minecraft:redstone_wire -56 -Diamond_Ore -minecraft:diamond_ore -57 -Diamond_Block -minecraft:diamond_block -58 -Crafting_Table -minecraft:crafting_table -59 -Wheat_Crops -minecraft:wheat -60 -Farmland -minecraft:farmland -61 -Furnace -minecraft:furnace -62 -Burning_Furnace -minecraft:lit_furnace -63 -Standing_Sign_Block -minecraft:standing_sign -64 -Oak_Door_Block -minecraft:wooden_door -65 -Ladder -minecraft:ladder -66 -Rail -minecraft:rail -67 -Cobblestone_Stairs -minecraft:stone_stairs -68 -Wall-mounted_Sign_Block -minecraft:wall_sign -69 -Lever -minecraft:lever -70 -Stone_Pressure_Plate -minecraft:stone_pressure_plate -71 -Iron_Door_Block -minecraft:iron_door -72 -Wooden_Pressure_Plate -minecraft:wooden_pressure_plate -73 -Redstone_Ore -minecraft:redstone_ore -74 -Glowing_Redstone_Ore -minecraft:lit_redstone_ore -75 -Redstone_Torch_off -minecraft:unlit_redstone_torch -76 -Redstone_Torch_on -minecraft:redstone_torch -77 -Stone_Button -minecraft:stone_button -78 -Snow -minecraft:snow_layer -79 -Ice -minecraft:ice -80 -Snow_Block -minecraft:snow -81 -Cactus -minecraft:cactus -82 -Clay -minecraft:clay -83 -Sugar_Canes -minecraft:reeds -84 -Jukebox -minecraft:jukebox -85 -Oak_Fence -minecraft:fence -86 -Pumpkin -minecraft:pumpkin -87 -Netherrack -minecraft:netherrack -88 -Soul_Sand -minecraft:soul_sand -89 -Glowstone -minecraft:glowstone -90 -Nether_Portal -minecraft:portal -91 -Jack_o'Lantern -minecraft:lit_pumpkin -92 -Cake_Block -minecraft:cake -93 -Redstone_Repeater_Block_off -minecraft:unpowered_repeater -94 -Redstone_Repeater_Block_on -minecraft:powered_repeater -95 -White_Stained_Glass -minecraft:stained_glass -95:1 -Orange_Stained_Glass -minecraft:stained_glass -95:2 -Magenta_Stained_Glass -minecraft:stained_glass -95:3 -Light_Blue_Stained_Glass -minecraft:stained_glass -95:4 -Yellow_Stained_Glass -minecraft:stained_glass -95:5 -Lime_Stained_Glass -minecraft:stained_glass -95:6 -Pink_Stained_Glass -minecraft:stained_glass -95:7 -Gray_Stained_Glass -minecraft:stained_glass -95:8 -Light_Gray_Stained_Glass -minecraft:stained_glass -95:9 -Cyan_Stained_Glass -minecraft:stained_glass -95:10 -Purple_Stained_Glass -minecraft:stained_glass -95:11 -Blue_Stained_Glass -minecraft:stained_glass -95:12 -Brown_Stained_Glass -minecraft:stained_glass -95:13 -Green_Stained_Glass -minecraft:stained_glass -95:14 -Red_Stained_Glass -minecraft:stained_glass -95:15 -Black_Stained_Glass -minecraft:stained_glass -96 -Wooden_Trapdoor -minecraft:trapdoor -97 -Stone_Monster_Egg -minecraft:monster_egg -97:1 -Cobblestone_Monster_Egg -minecraft:monster_egg -97:2 -Stone_Brick_Monster_Egg -minecraft:monster_egg -97:3 -Mossy_Stone_Brick_Monster_Egg -minecraft:monster_egg -97:4 -Cracked_Stone_Brick_Monster_Egg -minecraft:monster_egg -97:5 -Chiseled_Stone_Brick_Monster_Egg -minecraft:monster_egg -98 -Stone_Bricks -minecraft:stonebrick -98:1 -Mossy_Stone_Bricks -minecraft:stonebrick -98:2 -Cracked_Stone_Bricks -minecraft:stonebrick -98:3 -Chiseled_Stone_Bricks -minecraft:stonebrick -99 -Brown_Mushroom_Block -minecraft:brown_mushroom_block -100 -Red_Mushroom_Block -minecraft:red_mushroom_block -101 -Iron_Bars -minecraft:iron_bars -102 -Glass_Pane -minecraft:glass_pane -103 -Melon_Block -minecraft:melon_block -104 -Pumpkin_Stem -minecraft:pumpkin_stem -105 -Melon_Stem -minecraft:melon_stem -106 -Vines -minecraft:vine -107 -Oak_Fence_Gate -minecraft:fence_gate -108 -Brick_Stairs -minecraft:brick_stairs -109 -Stone_Brick_Stairs -minecraft:stone_brick_stairs -110 -Mycelium -minecraft:mycelium -111 -Lily_Pad -minecraft:waterlily -112 -Nether_Brick -minecraft:nether_brick -113 -Nether_Brick_Fence -minecraft:nether_brick_fence -114 -Nether_Brick_Stairs -minecraft:nether_brick_stairs -115 -Nether_Wart -minecraft:nether_wart -116 -Enchantment_Table -minecraft:enchanting_table -117 -Brewing_Stand -minecraft:brewing_stand -118 -Cauldron -minecraft:cauldron -119 -End_Portal -minecraft:end_portal -120 -End_Portal_Frame -minecraft:end_portal_frame -121 -End_Stone -minecraft:end_stone -122 -Dragon_Egg -minecraft:dragon_egg -123 -Redstone_Lamp_inactive -minecraft:redstone_lamp -124 -Redstone_Lamp_active -minecraft:lit_redstone_lamp -125 -Double_Oak_Wood_Slab -minecraft:double_wooden_slab -125:1 -Double_Spruce_Wood_Slab -minecraft:double_wooden_slab -125:2 -Double_Birch_Wood_Slab -minecraft:double_wooden_slab -125:3 -Double_Jungle_Wood_Slab -minecraft:double_wooden_slab -125:4 -Double_Acacia_Wood_Slab -minecraft:double_wooden_slab -125:5 -Double_Dark_Oak_Wood_Slab -minecraft:double_wooden_slab -126 -Oak_Wood_Slab -minecraft:wooden_slab -126:1 -Spruce_Wood_Slab -minecraft:wooden_slab -126:2 -Birch_Wood_Slab -minecraft:wooden_slab -126:3 -Jungle_Wood_Slab -minecraft:wooden_slab -126:4 -Acacia_Wood_Slab -minecraft:wooden_slab -126:5 -Dark_Oak_Wood_Slab -minecraft:wooden_slab -127 -Cocoa -minecraft:cocoa -128 -Sandstone_Stairs -minecraft:sandstone_stairs -129 -Emerald_Ore -minecraft:emerald_ore -130 -Ender_Chest -minecraft:ender_chest -131 -Tripwire_Hook -minecraft:tripwire_hook -132 -Tripwire -minecraft:tripwire_hook -133 -Emerald_Block -minecraft:emerald_block -134 -Spruce_Wood_Stairs -minecraft:spruce_stairs -135 -Birch_Wood_Stairs -minecraft:birch_stairs -136 -Jungle_Wood_Stairs -minecraft:jungle_stairs -137 -Command_Block -minecraft:command_block -138 -Beacon -minecraft:beacon -139 -Cobblestone_Wall -minecraft:cobblestone_wall -139:1 -Mossy_Cobblestone_Wall -minecraft:cobblestone_wall -140 -Flower_Pot -minecraft:flower_pot -141 -Carrots -minecraft:carrots -142 -Potatoes -minecraft:potatoes -143 -Wooden_Button -minecraft:wooden_button -144 -Mob_Head -minecraft:skull -145 -Anvil -minecraft:anvil -146 -Trapped_Chest -minecraft:trapped_chest -147 -Weighted_Pressure_Plate_light -minecraft:light_weighted_pressure_plate -148 -Weighted_Pressure_Plate_heavy -minecraft:heavy_weighted_pressure_plate -149 -Redstone_Comparator_inactive -minecraft:unpowered_comparator -150 -Redstone_Comparator_active -minecraft:powered_comparator -151 -Daylight_Sensor -minecraft:daylight_detector -152 -Redstone_Block -minecraft:redstone_block -153 -Nether_Quartz_Ore -minecraft:quartz_ore -154 -Hopper -minecraft:hopper -155 -Quartz_Block -minecraft:quartz_block -155:1 -Chiseled_Quartz_Block -minecraft:quartz_block -155:2 -Pillar_Quartz_Block -minecraft:quartz_block -156 -Quartz_Stairs -minecraft:quartz_stairs -157 -Activator_Rail -minecraft:activator_rail -158 -Dropper -minecraft:dropper -159 -White_Stained_Clay -minecraft:stained_hardened_clay -159:1 -Orange_Stained_Clay -minecraft:stained_hardened_clay -159:2 -Magenta_Stained_Clay -minecraft:stained_hardened_clay -159:3 -Light_Blue_Stained_Clay -minecraft:stained_hardened_clay -159:4 -Yellow_Stained_Clay -minecraft:stained_hardened_clay -159:5 -Lime_Stained_Clay -minecraft:stained_hardened_clay -159:6 -Pink_Stained_Clay -minecraft:stained_hardened_clay -159:7 -Gray_Stained_Clay -minecraft:stained_hardened_clay -159:8 -Light_Gray_Stained_Clay -minecraft:stained_hardened_clay -159:9 -Cyan_Stained_Clay -minecraft:stained_hardened_clay -159:10 -Purple_Stained_Clay -minecraft:stained_hardened_clay -159:11 -Blue_Stained_Clay -minecraft:stained_hardened_clay -159:12 -Brown_Stained_Clay -minecraft:stained_hardened_clay -159:13 -Green_Stained_Clay -minecraft:stained_hardened_clay -159:14 -Red_Stained_Clay -minecraft:stained_hardened_clay -159:15 -Black_Stained_Clay -minecraft:stained_hardened_clay -160 -White_Stained_Glass_Pane -minecraft:stained_glass_pane -160:1 -Orange_Stained_Glass_Pane -minecraft:stained_glass_pane -160:2 -Magenta_Stained_Glass_Pane -minecraft:stained_glass_pane -160:3 -Light_Blue_Stained_Glass_Pane -minecraft:stained_glass_pane -160:4 -Yellow_Stained_Glass_Pane -minecraft:stained_glass_pane -160:5 -Lime_Stained_Glass_Pane -minecraft:stained_glass_pane -160:6 -Pink_Stained_Glass_Pane -minecraft:stained_glass_pane -160:7 -Gray_Stained_Glass_Pane -minecraft:stained_glass_pane -160:8 -Light_Gray_Stained_Glass_Pane -minecraft:stained_glass_pane -160:9 -Cyan_Stained_Glass_Pane -minecraft:stained_glass_pane -160:10 -Purple_Stained_Glass_Pane -minecraft:stained_glass_pane -160:11 -Blue_Stained_Glass_Pane -minecraft:stained_glass_pane -160:12 -Brown_Stained_Glass_Pane -minecraft:stained_glass_pane -160:13 -Green_Stained_Glass_Pane -minecraft:stained_glass_pane -160:14 -Red_Stained_Glass_Pane -minecraft:stained_glass_pane -160:15 -Black_Stained_Glass_Pane -minecraft:stained_glass_pane -161 -Acacia_Leaves -minecraft:leaves2 -161:1 -Dark_Oak_Leaves -minecraft:leaves2 -162 -Acacia_Wood -minecraft:log2 -162:1 -Dark_Oak_Wood -minecraft:log2 -163 -Acacia_Wood_Stairs -minecraft:acacia_stairs -164 -Dark_Oak_Wood_Stairs -minecraft:dark_oak_stairs -165 -Slime_Block -minecraft:slime -166 -Barrier -minecraft:barrier -167 -Iron_Trapdoor -minecraft:iron_trapdoor -168 -Prismarine -minecraft:prismarine -168:1 -Prismarine_Bricks -minecraft:prismarine -168:2 -Dark_Prismarine -minecraft:prismarine -169 -Sea_Lantern -minecraft:sea_lantern -170 -Hay_Bale -minecraft:hay_block -171 -White_Carpet -minecraft:carpet -171:1 -Orange_Carpet -minecraft:carpet -171:2 -Magenta_Carpet -minecraft:carpet -171:3 -Light_Blue_Carpet -minecraft:carpet -171:4 -Yellow_Carpet -minecraft:carpet -171:5 -Lime_Carpet -minecraft:carpet -171:6 -Pink_Carpet -minecraft:carpet -171:7 -Gray_Carpet -minecraft:carpet -171:8 -Light_Gray_Carpet -minecraft:carpet -171:9 -Cyan_Carpet -minecraft:carpet -171:10 -Purple_Carpet -minecraft:carpet -171:11 -Blue_Carpet -minecraft:carpet -171:12 -Brown_Carpet -minecraft:carpet -171:13 -Green_Carpet -minecraft:carpet -171:14 -Red_Carpet -minecraft:carpet -171:15 -Black_Carpet -minecraft:carpet -172 -Hardened_Clay -minecraft:hardened_clay -173 -Block_of_Coal -minecraft:coal_block -174 -Packed_Ice -minecraft:packed_ice -175 -Sunflower -minecraft:double_plant -175:1 -Lilac -minecraft:double_plant -175:2 -Double_Tallgrass -minecraft:double_plant -175:3 -Large_Fern -minecraft:double_plant -175:4 -Rose_Bush -minecraft:double_plant -175:5 -Peony -minecraft:double_plant -176 -Free-standing_Banner -minecraft:standing_banner -177 -Wall-mounted_Banner -minecraft:wall_banner -178 -Inverted_Daylight_Sensor -minecraft:daylight_detector_inverted -179 -Red_Sandstone -minecraft:red_sandstone -179:1 -Chiseled_Red_Sandstone -minecraft:red_sandstone -179:2 -Smooth_Red_Sandstone -minecraft:red_sandstone -180 -Red_Sandstone_Stairs -minecraft:red_sandstone_stairs -181 -Double_Red_Sandstone_Slab -minecraft:stone_slab2 -182 -Red_Sandstone_Slab -minecraft:double_stone_slab2 -183 -Spruce_Fence_Gate -minecraft:spruce_fence_gate -184 -Birch_Fence_Gate -minecraft:birch_fence_gate -185 -Jungle_Fence_Gate -minecraft:jungle_fence_gate -186 -Dark_Oak_Fence_Gate -minecraft:dark_oak_fence_gate -187 -Acacia_Fence_Gate -minecraft:acacia_fence_gate -188 -Spruce_Fence -minecraft:spruce_fence -189 -Birch_Fence -minecraft:birch_fence -190 -Jungle_Fence -minecraft:jungle_fence -191 -Dark_Oak_Fence -minecraft:dark_oak_fence -192 -Acacia_Fence -minecraft:acacia_fence -193 -Spruce_Door_Block -minecraft:spruce_door -194 -Birch_Door_Block -minecraft:birch_door -195 -Jungle_Door_Block -minecraft:jungle_door -196 -Acacia_Door_Block -minecraft:acacia_door -197 -Dark_Oak_Door_Block -minecraft:dark_oak_door \ No newline at end of file