From 6e0ade4f63a72540f1ab1637aedd422484225c39 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 7 Apr 2017 08:25:08 +1000 Subject: [PATCH] Some sponge fixes --- .../plot/object/Plot.java | 2 +- .../object/worlds/SingleWorldGenerator.java | 6 +-- .../com/plotsquared/sponge/SpongeMain.java | 5 ++- .../sponge/listener/MainListener.java | 40 +++++++------------ .../sponge/util/SpongeSetupUtils.java | 38 +++++++++++++----- settings.gradle | 2 +- 6 files changed, 49 insertions(+), 44 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index fd2874983..b8dc06e18 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -2033,7 +2033,7 @@ public class Plot { for (int i = 4; i > 0; i--) { String caption = C.valueOf("OWNER_SIGN_LINE_" + i).s(); int index = caption.indexOf("%plr%"); - if (index == -1) { + if (index < 0) { continue; } String line = lines[i - 1]; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SingleWorldGenerator.java b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SingleWorldGenerator.java index 499378296..f4ab7db32 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SingleWorldGenerator.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SingleWorldGenerator.java @@ -36,11 +36,7 @@ public class SingleWorldGenerator extends IndependentPlotGenerator { result.setCuboid(dirt1, dirt2, PlotBlock.get(3, 0)); result.setCuboid(grass1, grass2, PlotBlock.get(2, 0)); } - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - result.setBiome(x, z, "PLAINS"); - } - } + result.fillBiome("PLAINS"); } @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java index ddc6cc304..ef5bec076 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -18,6 +18,7 @@ import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.worlds.PlotAreaManager; import com.intellectualcrafters.plot.object.worlds.SinglePlotArea; import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager; +import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator; import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.ChatManager; import com.intellectualcrafters.plot.util.ChunkManager; @@ -143,6 +144,7 @@ public class SpongeMain implements IPlotMain { new PS(this, "Sponge"); this.server = this.game.getServer(); this.game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) PS.get().IMP.getDefaultGenerator().specify(null)); + this.game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) new SingleWorldGenerator().specify(null)); if (Settings.Enabled_Components.WORLDS) { TaskManager.IMP.taskRepeat(new Runnable() { @Override @@ -172,6 +174,7 @@ public class SpongeMain implements IPlotMain { return; } } + System.out.println("Unload " + world); Sponge.getServer().unloadWorld(world); } } @@ -200,7 +203,7 @@ public class SpongeMain implements IPlotMain { @Override public File getWorldContainer() { - return game.getSavesDirectory().toFile(); + return new File(game.getSavesDirectory().toFile(), "world"); } @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java index 65425f844..47e570682 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -18,6 +18,7 @@ import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.listener.PlotListener; +import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.object.SpongePlayer; import com.plotsquared.sponge.util.SpongeUtil; import java.util.ArrayList; @@ -161,7 +162,6 @@ public class MainListener { @Listener public void onSpawnEntity(SpawnEntityEvent event) { - World world = event.getTargetWorld(); event.filterEntities(entity -> { if (entity instanceof Player) { return true; @@ -389,14 +389,12 @@ public class MainListener { } public void onChangeBlock(ChangeBlockEvent event) { - World world = event.getTargetWorld(); - String worldName = world.getName(); - if (!PS.get().hasPlotArea(worldName)) { - return; - } List> transactions = event.getTransactions(); Transaction first = transactions.get(0); - Location loc = SpongeUtil.getLocation(worldName, first.getOriginal().getPosition()); + BlockSnapshot original = first.getOriginal(); + Optional world = SpongeMain.THIS.getServer().getWorld(original.getWorldUniqueId()); + String worldName = world.get().getName(); + Location loc = SpongeUtil.getLocation(worldName, original.getPosition()); PlotArea area = loc.getPlotArea(); if (area == null) { return; @@ -435,15 +433,12 @@ public class MainListener { return; } PlotPlayer pp = SpongeUtil.getPlayer(player); - World world = event.getTargetWorld(); - String worldName = world.getName(); - if (!PS.get().hasPlotArea(worldName)) { - return; - } List> transactions = event.getTransactions(); Transaction first = transactions.get(0); - BlockSnapshot pos = first.getOriginal(); - Location loc = SpongeUtil.getLocation(worldName, pos.getPosition()); + BlockSnapshot original = first.getOriginal(); + Optional world = SpongeMain.THIS.getServer().getWorld(original.getWorldUniqueId()); + String worldName = world.get().getName(); + Location loc = SpongeUtil.getLocation(worldName, original.getPosition()); Plot plot = loc.getPlot(); if (plot == null) { if (!loc.isPlotArea()) { @@ -468,7 +463,7 @@ public class MainListener { } else { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); com.google.common.base.Optional> destroy = plot.getFlag(Flags.BREAK); - BlockState state = pos.getState(); + BlockState state = original.getState(); if (!destroy.isPresent() || !destroy.get().contains(SpongeUtil.getPlotBlock(state))) { event.setCancelled(true); return; @@ -511,14 +506,10 @@ public class MainListener { return; } PlotPlayer pp = SpongeUtil.getPlayer(player); - World world = event.getTargetWorld(); - String worldName = world.getName(); - if (!PS.get().hasPlotArea(worldName)) { - return; - } List> locs = event.getLocations(); org.spongepowered.api.world.Location first = locs.get(0); - Location loc = SpongeUtil.getLocation(worldName, first); + String worldName = first.getExtent().getName(); + Location loc = SpongeUtil.getLocation(worldName, first.getPosition()); PlotArea area = loc.getPlotArea(); if (area == null) { return; @@ -559,14 +550,11 @@ public class MainListener { return; } PlotPlayer pp = SpongeUtil.getPlayer(player); - World world = event.getTargetWorld(); - String worldName = world.getName(); - if (!PS.get().hasPlotArea(worldName)) { - return; - } List> transactions = event.getTransactions(); Transaction first = transactions.get(0); BlockSnapshot pos = first.getOriginal(); + Optional world = SpongeMain.THIS.getServer().getWorld(pos.getWorldUniqueId()); + String worldName = world.get().getName(); Location loc = SpongeUtil.getLocation(worldName, pos.getPosition()); PlotArea area = loc.getPlotArea(); if (area == null) { diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java index d6843d317..78fa67f57 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java @@ -6,6 +6,7 @@ import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.SetupObject; +import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator; import com.intellectualcrafters.plot.util.SetupUtils; import com.plotsquared.sponge.generator.SpongePlotGenerator; import java.io.IOException; @@ -14,6 +15,7 @@ import java.util.HashMap; import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; +import java.util.UUID; import org.spongepowered.api.Sponge; import org.spongepowered.api.world.DimensionTypes; import org.spongepowered.api.world.GeneratorTypes; @@ -31,6 +33,7 @@ public class SpongeSetupUtils extends SetupUtils { return; } SetupUtils.generators.put(PS.imp().getPluginName(), new SpongePlotGenerator(PS.get().IMP.getDefaultGenerator())); + SetupUtils.generators.put(PS.imp().getPluginName() + ":single", new SpongePlotGenerator(new SingleWorldGenerator())); // TODO get external world generators Collection wgms = Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class); for (WorldGeneratorModifier wgm : wgms) { @@ -75,12 +78,12 @@ public class SpongeSetupUtils extends SetupUtils { String world = object.world; int type = object.type; String worldPath = "worlds." + object.world; - if (!PS.get().worlds.contains(worldPath)) { - PS.get().worlds.createSection(worldPath); - } - ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath); switch (type) { case 2: { + if (!PS.get().worlds.contains(worldPath)) { + PS.get().worlds.createSection(worldPath); + } + ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath); if (object.id != null) { String areaName = object.id + "-" + object.min + "-" + object.max; String areaPath = "areas." + areaName; @@ -117,7 +120,11 @@ public class SpongeSetupUtils extends SetupUtils { } break; } - case 1: + case 1: { + if (!PS.get().worlds.contains(worldPath)) { + PS.get().worlds.createSection(worldPath); + } + ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath); for (ConfigurationNode step : steps) { worldSection.set(step.getConstant(), step.getValue()); } @@ -132,11 +139,19 @@ public class SpongeSetupUtils extends SetupUtils { object.setupGenerator = null; } break; - case 0: - for (ConfigurationNode step : steps) { - worldSection.set(step.getConstant(), step.getValue()); + } + case 0: { + if (steps.length != 0) { + if (!PS.get().worlds.contains(worldPath)) { + PS.get().worlds.createSection(worldPath); + } + ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath); + for (ConfigurationNode step : steps) { + worldSection.set(step.getConstant(), step.getValue()); + } } break; + } } try { PS.get().worlds.save(PS.get().worldsFile); @@ -147,6 +162,7 @@ public class SpongeSetupUtils extends SetupUtils { // create world with generator GeneratorWrapper gw = SetupUtils.generators.get(object.setupGenerator); WorldGeneratorModifier wgm = (WorldGeneratorModifier) gw.getPlatformGenerator(); + System.out.println("GW " + gw + " | " + wgm); WorldArchetype settings = WorldArchetype.builder() .loadsOnStartup(true) @@ -156,7 +172,7 @@ public class SpongeSetupUtils extends SetupUtils { .usesMapFeatures(false) .enabled(true) .generatorModifiers(wgm) - .build("PS",object.world); + .build("PS-" + UUID.randomUUID(),object.world); WorldProperties properties = null; try { properties = Sponge.getServer().createWorldProperties(object.world, settings); @@ -168,7 +184,9 @@ public class SpongeSetupUtils extends SetupUtils { if (world1.isPresent()) { worldObj = world1.get(); } + System.out.println("Create normal world"); } else { + System.out.println("Create vanilla world"); // create vanilla world WorldArchetype settings = WorldArchetype.builder() .loadsOnStartup(true) @@ -177,7 +195,7 @@ public class SpongeSetupUtils extends SetupUtils { .generator(GeneratorTypes.OVERWORLD) .usesMapFeatures(true) .enabled(true) - .build("PS",object.world); + .build("PS-" + UUID.randomUUID(),object.world); WorldProperties properties = null; try { properties = Sponge.getServer().createWorldProperties(object.world, settings); diff --git a/settings.gradle b/settings.gradle index 2735f683c..16f742df9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,3 @@ rootProject.name = 'PlotSquared' -include 'Core', 'Bukkit', 'Nukkit' //,'Sponge' \ No newline at end of file +include 'Core', 'Bukkit', 'Nukkit' ,'Sponge' \ No newline at end of file