Some sponge fixes

This commit is contained in:
Jesse Boyd 2017-04-07 08:25:08 +10:00
parent c1a6c75ebe
commit 6e0ade4f63
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
6 changed files with 49 additions and 44 deletions

View File

@ -2033,7 +2033,7 @@ public class Plot {
for (int i = 4; i > 0; i--) { for (int i = 4; i > 0; i--) {
String caption = C.valueOf("OWNER_SIGN_LINE_" + i).s(); String caption = C.valueOf("OWNER_SIGN_LINE_" + i).s();
int index = caption.indexOf("%plr%"); int index = caption.indexOf("%plr%");
if (index == -1) { if (index < 0) {
continue; continue;
} }
String line = lines[i - 1]; String line = lines[i - 1];

View File

@ -36,11 +36,7 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
result.setCuboid(dirt1, dirt2, PlotBlock.get(3, 0)); result.setCuboid(dirt1, dirt2, PlotBlock.get(3, 0));
result.setCuboid(grass1, grass2, PlotBlock.get(2, 0)); result.setCuboid(grass1, grass2, PlotBlock.get(2, 0));
} }
for (int x = 0; x < 16; x++) { result.fillBiome("PLAINS");
for (int z = 0; z < 16; z++) {
result.setBiome(x, z, "PLAINS");
}
}
} }
@Override @Override

View File

@ -18,6 +18,7 @@ import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager; import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea; import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager; 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.AbstractTitle;
import com.intellectualcrafters.plot.util.ChatManager; import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
@ -143,6 +144,7 @@ public class SpongeMain implements IPlotMain {
new PS(this, "Sponge"); new PS(this, "Sponge");
this.server = this.game.getServer(); 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) PS.get().IMP.getDefaultGenerator().specify(null));
this.game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) new SingleWorldGenerator().specify(null));
if (Settings.Enabled_Components.WORLDS) { if (Settings.Enabled_Components.WORLDS) {
TaskManager.IMP.taskRepeat(new Runnable() { TaskManager.IMP.taskRepeat(new Runnable() {
@Override @Override
@ -172,6 +174,7 @@ public class SpongeMain implements IPlotMain {
return; return;
} }
} }
System.out.println("Unload " + world);
Sponge.getServer().unloadWorld(world); Sponge.getServer().unloadWorld(world);
} }
} }
@ -200,7 +203,7 @@ public class SpongeMain implements IPlotMain {
@Override @Override
public File getWorldContainer() { public File getWorldContainer() {
return game.getSavesDirectory().toFile(); return new File(game.getSavesDirectory().toFile(), "world");
} }
@Override @Override

View File

@ -18,6 +18,7 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.listener.PlotListener; import com.plotsquared.listener.PlotListener;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer; import com.plotsquared.sponge.object.SpongePlayer;
import com.plotsquared.sponge.util.SpongeUtil; import com.plotsquared.sponge.util.SpongeUtil;
import java.util.ArrayList; import java.util.ArrayList;
@ -161,7 +162,6 @@ public class MainListener {
@Listener @Listener
public void onSpawnEntity(SpawnEntityEvent event) { public void onSpawnEntity(SpawnEntityEvent event) {
World world = event.getTargetWorld();
event.filterEntities(entity -> { event.filterEntities(entity -> {
if (entity instanceof Player) { if (entity instanceof Player) {
return true; return true;
@ -389,14 +389,12 @@ public class MainListener {
} }
public void onChangeBlock(ChangeBlockEvent event) { public void onChangeBlock(ChangeBlockEvent event) {
World world = event.getTargetWorld();
String worldName = world.getName();
if (!PS.get().hasPlotArea(worldName)) {
return;
}
List<Transaction<BlockSnapshot>> transactions = event.getTransactions(); List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
Transaction<BlockSnapshot> first = transactions.get(0); Transaction<BlockSnapshot> first = transactions.get(0);
Location loc = SpongeUtil.getLocation(worldName, first.getOriginal().getPosition()); BlockSnapshot original = first.getOriginal();
Optional<World> world = SpongeMain.THIS.getServer().getWorld(original.getWorldUniqueId());
String worldName = world.get().getName();
Location loc = SpongeUtil.getLocation(worldName, original.getPosition());
PlotArea area = loc.getPlotArea(); PlotArea area = loc.getPlotArea();
if (area == null) { if (area == null) {
return; return;
@ -435,15 +433,12 @@ public class MainListener {
return; return;
} }
PlotPlayer pp = SpongeUtil.getPlayer(player); PlotPlayer pp = SpongeUtil.getPlayer(player);
World world = event.getTargetWorld();
String worldName = world.getName();
if (!PS.get().hasPlotArea(worldName)) {
return;
}
List<Transaction<BlockSnapshot>> transactions = event.getTransactions(); List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
Transaction<BlockSnapshot> first = transactions.get(0); Transaction<BlockSnapshot> first = transactions.get(0);
BlockSnapshot pos = first.getOriginal(); BlockSnapshot original = first.getOriginal();
Location loc = SpongeUtil.getLocation(worldName, pos.getPosition()); Optional<World> world = SpongeMain.THIS.getServer().getWorld(original.getWorldUniqueId());
String worldName = world.get().getName();
Location loc = SpongeUtil.getLocation(worldName, original.getPosition());
Plot plot = loc.getPlot(); Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (!loc.isPlotArea()) { if (!loc.isPlotArea()) {
@ -468,7 +463,7 @@ public class MainListener {
} else { } else {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
com.google.common.base.Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK); com.google.common.base.Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
BlockState state = pos.getState(); BlockState state = original.getState();
if (!destroy.isPresent() || !destroy.get().contains(SpongeUtil.getPlotBlock(state))) { if (!destroy.isPresent() || !destroy.get().contains(SpongeUtil.getPlotBlock(state))) {
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -511,14 +506,10 @@ public class MainListener {
return; return;
} }
PlotPlayer pp = SpongeUtil.getPlayer(player); PlotPlayer pp = SpongeUtil.getPlayer(player);
World world = event.getTargetWorld();
String worldName = world.getName();
if (!PS.get().hasPlotArea(worldName)) {
return;
}
List<org.spongepowered.api.world.Location<World>> locs = event.getLocations(); List<org.spongepowered.api.world.Location<World>> locs = event.getLocations();
org.spongepowered.api.world.Location<World> first = locs.get(0); org.spongepowered.api.world.Location<World> 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(); PlotArea area = loc.getPlotArea();
if (area == null) { if (area == null) {
return; return;
@ -559,14 +550,11 @@ public class MainListener {
return; return;
} }
PlotPlayer pp = SpongeUtil.getPlayer(player); PlotPlayer pp = SpongeUtil.getPlayer(player);
World world = event.getTargetWorld();
String worldName = world.getName();
if (!PS.get().hasPlotArea(worldName)) {
return;
}
List<Transaction<BlockSnapshot>> transactions = event.getTransactions(); List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
Transaction<BlockSnapshot> first = transactions.get(0); Transaction<BlockSnapshot> first = transactions.get(0);
BlockSnapshot pos = first.getOriginal(); BlockSnapshot pos = first.getOriginal();
Optional<World> world = SpongeMain.THIS.getServer().getWorld(pos.getWorldUniqueId());
String worldName = world.get().getName();
Location loc = SpongeUtil.getLocation(worldName, pos.getPosition()); Location loc = SpongeUtil.getLocation(worldName, pos.getPosition());
PlotArea area = loc.getPlotArea(); PlotArea area = loc.getPlotArea();
if (area == null) { if (area == null) {

View File

@ -6,6 +6,7 @@ import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
import com.plotsquared.sponge.generator.SpongePlotGenerator; import com.plotsquared.sponge.generator.SpongePlotGenerator;
import java.io.IOException; import java.io.IOException;
@ -14,6 +15,7 @@ import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.UUID;
import org.spongepowered.api.Sponge; import org.spongepowered.api.Sponge;
import org.spongepowered.api.world.DimensionTypes; import org.spongepowered.api.world.DimensionTypes;
import org.spongepowered.api.world.GeneratorTypes; import org.spongepowered.api.world.GeneratorTypes;
@ -31,6 +33,7 @@ public class SpongeSetupUtils extends SetupUtils {
return; return;
} }
SetupUtils.generators.put(PS.imp().getPluginName(), new SpongePlotGenerator(PS.get().IMP.getDefaultGenerator())); 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 // TODO get external world generators
Collection<WorldGeneratorModifier> wgms = Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class); Collection<WorldGeneratorModifier> wgms = Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class);
for (WorldGeneratorModifier wgm : wgms) { for (WorldGeneratorModifier wgm : wgms) {
@ -75,12 +78,12 @@ public class SpongeSetupUtils extends SetupUtils {
String world = object.world; String world = object.world;
int type = object.type; int type = object.type;
String worldPath = "worlds." + object.world; 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) { switch (type) {
case 2: { case 2: {
if (!PS.get().worlds.contains(worldPath)) {
PS.get().worlds.createSection(worldPath);
}
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath);
if (object.id != null) { if (object.id != null) {
String areaName = object.id + "-" + object.min + "-" + object.max; String areaName = object.id + "-" + object.min + "-" + object.max;
String areaPath = "areas." + areaName; String areaPath = "areas." + areaName;
@ -117,7 +120,11 @@ public class SpongeSetupUtils extends SetupUtils {
} }
break; 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) { for (ConfigurationNode step : steps) {
worldSection.set(step.getConstant(), step.getValue()); worldSection.set(step.getConstant(), step.getValue());
} }
@ -132,11 +139,19 @@ public class SpongeSetupUtils extends SetupUtils {
object.setupGenerator = null; object.setupGenerator = null;
} }
break; break;
case 0: }
for (ConfigurationNode step : steps) { case 0: {
worldSection.set(step.getConstant(), step.getValue()); 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; break;
}
} }
try { try {
PS.get().worlds.save(PS.get().worldsFile); PS.get().worlds.save(PS.get().worldsFile);
@ -147,6 +162,7 @@ public class SpongeSetupUtils extends SetupUtils {
// create world with generator // create world with generator
GeneratorWrapper<?> gw = SetupUtils.generators.get(object.setupGenerator); GeneratorWrapper<?> gw = SetupUtils.generators.get(object.setupGenerator);
WorldGeneratorModifier wgm = (WorldGeneratorModifier) gw.getPlatformGenerator(); WorldGeneratorModifier wgm = (WorldGeneratorModifier) gw.getPlatformGenerator();
System.out.println("GW " + gw + " | " + wgm);
WorldArchetype settings = WorldArchetype.builder() WorldArchetype settings = WorldArchetype.builder()
.loadsOnStartup(true) .loadsOnStartup(true)
@ -156,7 +172,7 @@ public class SpongeSetupUtils extends SetupUtils {
.usesMapFeatures(false) .usesMapFeatures(false)
.enabled(true) .enabled(true)
.generatorModifiers(wgm) .generatorModifiers(wgm)
.build("PS",object.world); .build("PS-" + UUID.randomUUID(),object.world);
WorldProperties properties = null; WorldProperties properties = null;
try { try {
properties = Sponge.getServer().createWorldProperties(object.world, settings); properties = Sponge.getServer().createWorldProperties(object.world, settings);
@ -168,7 +184,9 @@ public class SpongeSetupUtils extends SetupUtils {
if (world1.isPresent()) { if (world1.isPresent()) {
worldObj = world1.get(); worldObj = world1.get();
} }
System.out.println("Create normal world");
} else { } else {
System.out.println("Create vanilla world");
// create vanilla world // create vanilla world
WorldArchetype settings = WorldArchetype.builder() WorldArchetype settings = WorldArchetype.builder()
.loadsOnStartup(true) .loadsOnStartup(true)
@ -177,7 +195,7 @@ public class SpongeSetupUtils extends SetupUtils {
.generator(GeneratorTypes.OVERWORLD) .generator(GeneratorTypes.OVERWORLD)
.usesMapFeatures(true) .usesMapFeatures(true)
.enabled(true) .enabled(true)
.build("PS",object.world); .build("PS-" + UUID.randomUUID(),object.world);
WorldProperties properties = null; WorldProperties properties = null;
try { try {
properties = Sponge.getServer().createWorldProperties(object.world, settings); properties = Sponge.getServer().createWorldProperties(object.world, settings);

View File

@ -1,3 +1,3 @@
rootProject.name = 'PlotSquared' rootProject.name = 'PlotSquared'
include 'Core', 'Bukkit', 'Nukkit' //,'Sponge' include 'Core', 'Bukkit', 'Nukkit' ,'Sponge'