Update some sponge classes

Update world generator
Replace some broken code with TODO
FIxed a few errors
Started on block placement
Other sponge stuff
This commit is contained in:
Jesse Boyd 2016-02-20 05:52:26 +11:00
parent 60629db042
commit de1328e78c
26 changed files with 880 additions and 1384 deletions

View File

@ -359,7 +359,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
} }
}, 20); }, 20);
return (ChunkGenerator) result.specify(world); return (ChunkGenerator) result.specify();
} }
@Override @Override
@ -690,7 +690,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
@Override @Override
public GeneratorWrapper<?> wrapPlotGenerator(String world, IndependentPlotGenerator generator) { public GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator) {
return new BukkitPlotGenerator(generator); return new BukkitPlotGenerator(generator);
} }

View File

@ -23,7 +23,7 @@ public class SpongeHybridUtils extends HybridUtils {
for (int x = x1; x <= x2; x++) { for (int x = x1; x <= x2; x++) {
for (int z = z1; z <= z2; z++) { for (int z = z1; z <= z2; z++) {
final BlockState state = world.getBlock(x, y, z); final BlockState state = world.getBlock(x, y, z);
final PlotBlock block = SpongeMain.THIS.getPlotBlock(state); final PlotBlock block = SpongeUtil.getPlotBlock(state);
boolean same = false; boolean same = false;
for (final PlotBlock p : blocks) { for (final PlotBlock p : blocks) {
if (block.id == p.id) { if (block.id == p.id) {

View File

@ -1,27 +1,14 @@
package com.plotsquared.sponge; package com.plotsquared.sponge;
import java.io.File; import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.spongepowered.api.CatalogType;
import org.spongepowered.api.Game; import org.spongepowered.api.Game;
import org.spongepowered.api.Server; import org.spongepowered.api.Server;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent; import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent;
@ -31,11 +18,9 @@ import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.profile.GameProfileManager; import org.spongepowered.api.profile.GameProfileManager;
import org.spongepowered.api.text.Text; import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.translation.Translatable;
import org.spongepowered.api.text.translation.Translation;
import org.spongepowered.api.world.DimensionTypes;
import org.spongepowered.api.world.GeneratorTypes;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import org.spongepowered.api.world.gen.GenerationPopulator;
import org.spongepowered.api.world.gen.WorldGenerator;
import org.spongepowered.api.world.gen.WorldGeneratorModifier; import org.spongepowered.api.world.gen.WorldGeneratorModifier;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -43,30 +28,34 @@ import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.IPlotMain; import com.intellectualcrafters.plot.IPlotMain;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.SetupObject;
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;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.InventoryUtil; import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.PlotQueue;
import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
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.intellectualcrafters.plot.util.UUIDHandlerImplementation; import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.sponge.generator.SpongeBasicGen; import com.plotsquared.sponge.generator.SpongePlotGenerator;
import com.plotsquared.sponge.generator.SpongeGeneratorWrapper; import com.plotsquared.sponge.listener.ChunkProcessor;
import com.plotsquared.sponge.generator.WorldModify;
import com.plotsquared.sponge.listener.MainListener; import com.plotsquared.sponge.listener.MainListener;
import com.plotsquared.sponge.listener.WorldEvents;
import com.plotsquared.sponge.util.KillRoadMobs; import com.plotsquared.sponge.util.KillRoadMobs;
import com.plotsquared.sponge.util.SpongeBlockManager;
import com.plotsquared.sponge.util.SpongeChatManager; import com.plotsquared.sponge.util.SpongeChatManager;
import com.plotsquared.sponge.util.SpongeChunkManager; import com.plotsquared.sponge.util.SpongeChunkManager;
import com.plotsquared.sponge.util.SpongeCommand; import com.plotsquared.sponge.util.SpongeCommand;
@ -77,6 +66,9 @@ import com.plotsquared.sponge.util.SpongeMetrics;
import com.plotsquared.sponge.util.SpongeTaskManager; import com.plotsquared.sponge.util.SpongeTaskManager;
import com.plotsquared.sponge.util.SpongeTitleManager; import com.plotsquared.sponge.util.SpongeTitleManager;
import com.plotsquared.sponge.util.SpongeUtil; import com.plotsquared.sponge.util.SpongeUtil;
import com.plotsquared.sponge.util.SpongeWorldUtil;
import com.plotsquared.sponge.util.block.FastQueue;
import com.plotsquared.sponge.util.block.SlowQueue;
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper; import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper; import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeUUIDHandler; import com.plotsquared.sponge.uuid.SpongeUUIDHandler;
@ -97,9 +89,6 @@ public class SpongeMain implements IPlotMain, PluginContainer {
private GameProfileManager resolver; private GameProfileManager resolver;
private WorldModify modify;
// stuff //
@Override @Override
public Logger getLogger() { public Logger getLogger() {
return logger; return logger;
@ -121,69 +110,6 @@ public class SpongeMain implements IPlotMain, PluginContainer {
return THIS; return THIS;
} }
public Text getText(final String m) {
return Texts.of(m);
}
public Translatable getTranslation(final String m) {
return new Translatable() {
@Override
public Translation getTranslation() {
return new Translation() {
@Override
public String getId() {
return m;
}
@Override
public String get(final Locale l, final Object... args) {
return m;
}
@Override
public String get(final Locale l) {
return m;
}
};
}
};
}
private final PlotBlock NULL_BLOCK = new PlotBlock((short) 0, (byte) 0);
private BlockState[][] blockMap;
private Map<BlockState, PlotBlock> blockMapReverse;
public BlockState getBlockState(final PlotBlock block) {
if (blockMap[block.id] == null) {
log("UNKNOWN BLOCK: " + block.toString());
return null;
} else if (blockMap[block.id].length <= block.data) {
log("UNKNOWN BLOCK: " + block.toString() + " -> Using " + block.id + ":0 instead");
return blockMap[block.id][0];
}
return blockMap[block.id][block.data];
}
public BlockState getBlockState(final int id) {
return blockMap[id][0];
}
public Collection<BlockState> getAllStates() {
return blockMapReverse.keySet();
}
public PlotBlock getPlotBlock(final BlockState state) {
final PlotBlock val = blockMapReverse.get(state);
if (val == null) {
return NULL_BLOCK;
}
return val;
}
/////////
////////////////////// SPONGE PLUGIN REGISTRATION ////////////////////
@Override @Override
public String getId() { public String getId() {
return "PlotSquared"; return "PlotSquared";
@ -211,188 +137,25 @@ public class SpongeMain implements IPlotMain, PluginContainer {
return result; return result;
} }
///////////////////////////////////////////////////////////////////////
///////////////////// ON ENABLE /////////////////////
@Listener @Listener
public void init(final GameInitializationEvent event) { public void init(final GameInitializationEvent event) {
log("P^2 INIT"); log("PlotSquared: Game init");
} }
@Listener @Listener
public void onInit(final GamePreInitializationEvent event) { public void onInit(final GamePreInitializationEvent event) {
// Hook for Project Worlds log("PlotSquared: Game pre init");
hookProjectWorlds();
} }
public void hookProjectWorlds() {
Optional<PluginContainer> plugin = game.getPluginManager().getPlugin("Project Worlds");
if (plugin.isPresent()) {
try {
Class<?> clazz = Class.forName("com.gmail.trentech.pjw.modifiers.Modifiers");
Method method = clazz.getMethod("put", String.class, WorldGeneratorModifier.class);
SpongeBasicGen generator = new SpongeBasicGen(null);
method.invoke(null, "plotsquared", new WorldModify(generator, false));
log("Adding plotsquared modifier to Project Worlds");
}
catch (Throwable e) {
e.printStackTrace();
}
}
}
@Listener @Listener
public void onServerAboutToStart(final GameAboutToStartServerEvent event) { public void onServerAboutToStart(final GameAboutToStartServerEvent event) {
log("P^2 ABOUT START"); log("PlotSquared: Server init");
THIS = this; THIS = this;
//
resolver = game.getServiceManager().provide(GameProfileManager.class).get(); resolver = game.getServiceManager().provide(GameProfileManager.class).get();
server = game.getServer(); server = game.getServer();
// game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) new HybridGen().specify());
new PS(this, "Sponge"); new PS(this, "Sponge");
registerBlocks();
final ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
if (worldSection != null) {
for (final String world : worldSection.getKeys(false)) {
createWorldFromConfig(world);
}
}
}
public World createWorldFromConfig(final String world) {
final SpongeBasicGen generator = new SpongeBasicGen(world);
final PlotArea plotworld = generator.getNewPlotWorld(world);
SpongeGeneratorWrapper wrapper;
if (plotworld.TYPE == 0) {
wrapper = new SpongeGeneratorWrapper(world, generator);
} else {
wrapper = new SpongeGeneratorWrapper(world, null);
}
PS.get().loadWorld(world, wrapper);
switch (plotworld.TYPE) {
// Normal
case 0: {
modify = new WorldModify(generator, false);
game.getRegistry().registerWorldGeneratorModifier(modify);
final Optional<World> builder = game.getRegistry().createBuilder(WorldBuilder.class).name(world).enabled(true).loadsOnStartup(true).keepsSpawnLoaded(true).dimensionType(DimensionTypes.OVERWORLD)
.generator(GeneratorTypes.FLAT).usesMapFeatures(false).generatorModifiers(modify).build();
return builder.get();
}
// Augmented
default: {
modify = new WorldModify(generator, true);
game.getRegistry().registerWorldGeneratorModifier(modify);
final Optional<World> builder = game.getRegistry().createBuilder(WorldBuilder.class).name(world).enabled(true).loadsOnStartup(true).keepsSpawnLoaded(true).dimensionType(DimensionTypes.OVERWORLD)
.generator(GeneratorTypes.OVERWORLD).usesMapFeatures(false).generatorModifiers(modify).build();
return builder.get();
}
}
}
public void registerBlock(final PlotBlock block, final BlockState state) {
final BlockState[] val = blockMap[block.id];
if (val == null) {
blockMap[block.id] = new BlockState[block.data + 1];
} else if (val.length <= block.data) {
blockMap[block.id] = Arrays.copyOf(val, block.data + 1);
} else if (val[block.data] != null) {
return;
}
blockMap[block.id][block.data] = state;
blockMapReverse.put(state, block);
}
public PlotBlock registerBlock(final BlockState state) {
final PlotBlock val = blockMapReverse.get(state);
if (val != null) {
return val;
}
byte data;
if (blockMap[0] == null) {
blockMap[0] = new BlockState[1];
data = 0;
} else {
data = (byte) (blockMap[0].length);
}
final PlotBlock block = new PlotBlock((short) 0, data);
registerBlock(block, state);
return block;
}
public void registerBlocks() {
blockMap = new BlockState[256][];
blockMapReverse = new HashMap<BlockState, PlotBlock>();
final HashMap<String, BlockState> states = new HashMap<>();
PS.get().copyFile("ids.txt", "config");
PS.get().copyFile("data.txt", "config");
try {
final File id_file = new File(getDirectory(), "config" + File.separator + "ids.txt");
final List<String> id_lines = Files.readAllLines(id_file.toPath(), StandardCharsets.UTF_8);
final File data_file = new File(getDirectory(), "config" + File.separator + "data.txt");
final List<String> data_lines = Files.readAllLines(data_file.toPath(), StandardCharsets.UTF_8);
Field[] fields = BlockTypes.class.getDeclaredFields();
for (final Field field : fields) {
final BlockType type = (BlockType) field.get(null);
final BlockState state = type.getDefaultState();
if (state != null) {
try {
states.put(type.getId() + ":" + 0, state);
} catch (final Exception e) {}
}
}
final String packaze = "org.spongepowered.api.data.type.";
for (int i = 0; i < data_lines.size(); i++) {
final String classname = packaze + data_lines.get(i).trim();
try {
final Class<?> clazz = Class.forName(classname);
fields = clazz.getDeclaredFields();
for (final Field field : fields) {
final CatalogType type = (CatalogType) field.get(null);
final String minecraft_id = type.getId();
final BlockState state = states.get(minecraft_id + ":" + 0);
if (state == null) {
continue;
}
}
} catch (final Throwable e) {}
}
PlotBlock block = null;
for (int i = 0; i < id_lines.size(); i++) {
final String line = id_lines.get(i).trim();
switch (i % 3) {
case 0: {
block = Configuration.BLOCK.parseString(line);
break;
}
case 1: {
break;
}
case 2: {
final String minecraft_id = line;
final BlockState state = states.remove(minecraft_id + ":" + block.data);
if (state == null) {
continue;
}
registerBlock(block, state);
break;
}
}
}
for (final Entry<String, BlockState> state : states.entrySet()) {
log("REGISTERING: " + registerBlock(state.getValue()) + " | " + state.getValue().getType());
}
} catch (final Exception e) {
e.printStackTrace();
}
} }
@Override @Override
@ -405,7 +168,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
logger.info(message); logger.info(message);
return; return;
} }
server.getConsole().sendMessage(Texts.of(message)); server.getConsole().sendMessage(Text.of(message));
} }
@Override @Override
@ -446,28 +209,11 @@ public class SpongeMain implements IPlotMain, PluginContainer {
return new SpongeInventoryUtil(); return new SpongeInventoryUtil();
} }
@Override
public SpongeGeneratorWrapper getGenerator(final String world, final String name) {
if (name == null) {
return new SpongeGeneratorWrapper(world, null);
}
if (name.equals("PlotSquared")) {
return new SpongeGeneratorWrapper(world, new SpongeBasicGen(world));
} else {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
}
@Override @Override
public EconHandler getEconomyHandler() { public EconHandler getEconomyHandler() {
// TODO Auto-generated method stub SpongeEconHandler econ = new SpongeEconHandler();
// Nothing like Vault exists yet game.getEventManager().registerListeners(this, econ);
return new SpongeEconHandler(); return econ;
}
@Override
public BlockManager initBlockManager() {
return new SpongeBlockManager();
} }
@Override @Override
@ -517,8 +263,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
@Override @Override
public void registerInventoryEvents() { public void registerInventoryEvents() {
// TODO Auto-generated method stub // Part of PlayerEvents - can be moved if necessary
log("registerInventoryEvents is not implemented!");
} }
@Override @Override
@ -556,8 +301,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
@Override @Override
public boolean initPlotMeConverter() { public boolean initPlotMeConverter() {
// TODO Auto-generated method stub // PlotMe was never ported to sponge
PS.log("initPlotMeConverter NOT IMPLEMENTED YET");
return false; return false;
} }
@ -568,19 +312,16 @@ public class SpongeMain implements IPlotMain, PluginContainer {
@Override @Override
public void registerChunkProcessor() { public void registerChunkProcessor() {
// TODO Auto-generated method stub game.getEventManager().registerListeners(this, new ChunkProcessor());
PS.log("registerChunkProcessor NOT IMPLEMENTED YET");
} }
@Override @Override
public void registerWorldEvents() { public void registerWorldEvents() {
// TODO Auto-generated method stub game.getEventManager().registerListeners(this, new WorldEvents());
PS.log("registerWorldEvents NOT IMPLEMENTED YET");
} }
@Override @Override
public String getServerName() { public String getServerName() {
// TODO FIXME
throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
} }
@ -596,8 +337,44 @@ public class SpongeMain implements IPlotMain, PluginContainer {
} }
@Override @Override
public void setGenerator(final String world) { public void setGenerator(final String worldname) {
// TODO THIS IS DONE DURING STARTUP ALREADY World world = SpongeUtil.getWorld(worldname);
if (world == null) {
// create world
final ConfigurationSection worldConfig = PS.get().config.getConfigurationSection("worlds." + worldname);
String manager = worldConfig.getString("generator.plugin");
if (manager == null) {
manager = "PlotSquared";
}
String generator = worldConfig.getString("generator.init");
if (generator == null) {
generator = manager;
}
final int type = worldConfig.getInt("generator.type");
final int terrain = worldConfig.getInt("generator.terrain");
final SetupObject setup = new SetupObject();
setup.plotManager = manager;
setup.setupGenerator = generator;
setup.type = type;
setup.terrain = terrain;
setup.step = new ConfigurationNode[0];
setup.world = worldname;
SetupUtils.manager.setupWorld(setup);
} else {
throw new IllegalArgumentException("World already loaded: " + worldname + "???");
}
WorldGenerator wg = world.getWorldGenerator();
GenerationPopulator gen = wg.getBaseGenerationPopulator();
if (gen instanceof SpongePlotGenerator) {
PS.get().loadWorld(worldname, (SpongePlotGenerator) gen);
} else if (gen != null) {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET!");
} else {
if (PS.get().config.contains("worlds." + worldname)) {
PS.get().loadWorld(worldname, null);
}
}
} }
@Override @Override
@ -610,24 +387,67 @@ public class SpongeMain implements IPlotMain, PluginContainer {
if (obj instanceof Player) { if (obj instanceof Player) {
return SpongeUtil.getPlayer((Player) obj); return SpongeUtil.getPlayer((Player) obj);
} }
// else if (obj instanceof OfflinePlayer) {
// return BukkitUtil.getPlayer((OfflinePlayer) obj);
// }
else if (obj instanceof String) { else if (obj instanceof String) {
return UUIDHandler.getPlayer((String) obj); return UUIDHandler.getPlayer((String) obj);
} else if (obj instanceof UUID) { } else if (obj instanceof UUID) {
return UUIDHandler.getPlayer((UUID) obj); return UUIDHandler.getPlayer((UUID) obj);
} }
// TODO FIXME offline player
return null; return null;
} }
@Override @Override
public String getNMSPackage() { public String getNMSPackage() {
return "1_8_R3"; return "TODO";//TODO FIXME
} }
@Override @Override
public ChatManager<?> initChatManager() { public ChatManager<?> initChatManager() {
return new SpongeChatManager(); return new SpongeChatManager();
} }
@Override
public PlotQueue initPlotQueue() {
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) {
try {
return new FastQueue();
} catch (Throwable e) {
e.printStackTrace();
}
}
return new SlowQueue();
}
@Override
public WorldUtil initWorldUtil() {
return new SpongeWorldUtil();
}
@Override
public GeneratorWrapper<?> getGenerator(String world, String name) {
if (name == null) {
return null;
}
Collection<WorldGeneratorModifier> wgms = game.getRegistry().getAllOf(WorldGeneratorModifier.class);
for (WorldGeneratorModifier wgm : wgms) {
if (StringMan.isEqualIgnoreCaseToAny(name, wgm.getName(), wgm.getId())) {
if (wgm instanceof GeneratorWrapper<?>) {
return (GeneratorWrapper<?>) wgm;
}
return new SpongePlotGenerator(wgm);
}
}
return new SpongePlotGenerator(new HybridGen());
}
@Override
public GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator) {
return new SpongePlotGenerator(generator);
}
@Override
public List<String> getPluginIds() {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -1,5 +1,14 @@
package com.plotsquared.sponge; package com.plotsquared.sponge;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.world.World;
import com.intellectualcrafters.jnbt.ByteArrayTag; import com.intellectualcrafters.jnbt.ByteArrayTag;
import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.jnbt.IntTag; import com.intellectualcrafters.jnbt.IntTag;
@ -16,14 +25,6 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.sponge.util.SpongeUtil; import com.plotsquared.sponge.util.SpongeUtil;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.world.World;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
public class SpongeSchematicHandler extends SchematicHandler { public class SpongeSchematicHandler extends SchematicHandler {
@ -144,10 +145,7 @@ public class SpongeSchematicHandler extends SchematicHandler {
final int index = i2 + rx; final int index = i2 + rx;
final BlockState state = worldObj.getBlock(x, y, z); final BlockState state = worldObj.getBlock(x, y, z);
PlotBlock block = SpongeMain.THIS.getPlotBlock(state); PlotBlock block = SpongeUtil.getPlotBlock(state);
if (block == null) {
block = SpongeMain.THIS.registerBlock(state);
}
final int id = block.id; final int id = block.id;
switch (id) { switch (id) {
case 0: case 0:
@ -280,4 +278,11 @@ public class SpongeSchematicHandler extends SchematicHandler {
}); });
} }
@Override
public void restoreTag(CompoundTag ct, short x, short y, short z, Schematic schem) {
// TODO Auto-generated method stub
// This method should place the compound tag at a location e.g. chest contents
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
} }

View File

@ -1,22 +1,19 @@
package com.plotsquared.sponge; package com.plotsquared.sponge;
import com.intellectualcrafters.plot.PS; import java.io.IOException;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.generator.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.plotsquared.sponge.generator.AugmentedPopulator;
import com.plotsquared.sponge.generator.SpongeBasicGen;
import com.plotsquared.sponge.generator.SpongeGeneratorWrapper;
import com.plotsquared.sponge.generator.SpongePlotGenerator;
import com.plotsquared.sponge.util.SpongeUtil;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import org.spongepowered.api.world.gen.WorldGenerator; import org.spongepowered.api.world.gen.WorldGenerator;
import java.io.IOException; import com.intellectualcrafters.plot.PS;
import java.util.Map.Entry; 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 { public class SpongeSetupUtils extends SetupUtils {
@ -25,9 +22,9 @@ public class SpongeSetupUtils extends SetupUtils {
if (!SetupUtils.generators.isEmpty()) { if (!SetupUtils.generators.isEmpty()) {
return; return;
} }
SetupUtils.generators.put("PlotSquared", new SpongePlotGenerator(new HybridGen()));
// TODO get external world generators // TODO get external world generators
final String testWorld = "CheckingPlotSquaredGenerator"; throw new UnsupportedOperationException("TODO FETCH EXTERNAL WorldGenerationModifiers");
SetupUtils.generators.put("PlotSquared", new SpongeGeneratorWrapper(testWorld, new SpongeBasicGen(testWorld)));
} }
@Override @Override
@ -40,15 +37,7 @@ public class SpongeSetupUtils extends SetupUtils {
return null; return null;
} }
final WorldGenerator generator = world.getWorldGenerator(); final WorldGenerator generator = world.getWorldGenerator();
if (!(generator instanceof SpongePlotGenerator)) { throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
return null;
}
for (final Entry<String, PlotGenerator<?>> entry : generators.entrySet()) {
if (entry.getValue().generator.getClass().getName().equals(generator.getClass().getName())) {
return entry.getKey();
}
}
return null;
} }
@Override @Override
@ -76,12 +65,8 @@ public class SpongeSetupUtils extends SetupUtils {
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
SpongeMain.THIS.createWorldFromConfig(world); // TODO FIXME
return object.world; throw new UnsupportedOperationException("NOT IMPLEMENTED YET: Create a new world here");
} // return object.world;
@Override
public void removePopulator(final String world, final PlotCluster cluster) {
AugmentedPopulator.removePopulator(world, cluster);
} }
} }

View File

@ -1,334 +0,0 @@
package com.plotsquared.sponge.generator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Random;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.util.DiscreteTransform3;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.ImmutableBlockVolume;
import org.spongepowered.api.world.extent.MutableBlockVolume;
import org.spongepowered.api.world.extent.StorageType;
import org.spongepowered.api.world.extent.UnmodifiableBlockVolume;
import org.spongepowered.api.world.gen.GenerationPopulator;
import org.spongepowered.api.world.gen.Populator;
import org.spongepowered.api.world.gen.WorldGenerator;
import com.flowpowered.math.vector.Vector3i;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.util.SpongeUtil;
public class AugmentedPopulator implements Populator {
public final PlotArea plotworld;
public final PlotManager manager;
public final SpongePlotGenerator generator;
public final GenerationPopulator populator;
public final PlotCluster cluster;
public final Random r = new Random();
public final boolean p;
public final boolean b;
public final boolean o;
private final int bx;
private final int bz;
private final int tx;
private final int tz;
public AugmentedPopulator(final String worldname, final WorldGenerator gen, final SpongePlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b) {
// MainUtil.initCache();
// Initialize any chach that's needed
this.cluster = cluster;
this.generator = generator;
populator = generator.getBaseGenerationPopulator();
plotworld = generator.getNewPlotWorld(worldname);
manager = generator.getPlotManager();
this.p = p;
this.b = b;
o = (plotworld.TERRAIN == 1) || (plotworld.TERRAIN == 2);
if (cluster != null) {
final Location bl = manager.getPlotBottomLocAbs(plotworld, cluster.getP1()).subtract(1, 0, 1);
final Location tl = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1, 0, 1);
bx = bl.getX();
bz = bl.getZ();
tx = tl.getX();
tz = tl.getZ();
} else {
bx = Integer.MIN_VALUE;
bz = Integer.MIN_VALUE;
tx = Integer.MAX_VALUE;
tz = Integer.MAX_VALUE;
}
// Add the populator
final List<Populator> populators = gen.getPopulators();
if (o) {
populators.add(0, this);
} else {
populators.add(this);
}
}
public static void removePopulator(final String worldname, final PlotCluster cluster) {
final World world = SpongeUtil.getWorld(worldname);
final List<Populator> populators = world.getWorldGenerator().getPopulators();
for (final Iterator<Populator> iterator = populators.iterator(); iterator.hasNext();) {
final Populator populator = iterator.next();
if (populator instanceof AugmentedPopulator) {
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
iterator.remove();
}
}
}
}
@Override
public void populate(final Chunk chunk, final Random r_unused) {
final Vector3i min = chunk.getBlockMin();
final World worldObj = chunk.getWorld();
final String world = worldObj.getName();
final int cx = min.getX() >> 4;
final int cz = min.getZ() >> 4;
final int bx = cx << 4;
final int bz = cz << 4;
final int tx = bx + 15;
final int tz = bz + 15;
final boolean inX1 = ((bx >= this.bx) && (bx <= this.tx));
final boolean inX2 = ((tx >= this.bx) && (tx <= this.tx));
final boolean inZ1 = ((bz >= this.bz) && (bz <= this.tz));
final boolean inZ2 = ((tz >= this.bz) && (tz <= this.tz));
final boolean inX = inX1 || inX2;
final boolean inZ = inZ1 || inZ2;
if (!inX || !inZ) {
return;
}
if (plotworld.TERRAIN == 3) {
final int X = min.getX();
final int Z = min.getZ();
if (ChunkManager.FORCE_PASTE) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z));
final HashMap<Short, Short> blocks = ChunkManager.GENERATE_BLOCKS.get(loc);
final HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(loc);
for (final Entry<Short, Short> entry : blocks.entrySet()) {
final int y = entry.getKey();
if (datas != null) {
SetQueue.IMP.setBlock(world, x, y, z, new PlotBlock(blocks.get(y), datas.get(y)));
} else {
SetQueue.IMP.setBlock(world, x, y, z, blocks.get(y));
}
}
}
}
return;
}
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
PlotLoc loc;
for (final Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet()) {
final HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(entry.getKey());
for (final Entry<Short, Byte> entry2 : entry.getValue().entrySet()) {
final Short y = entry2.getKey();
byte data;
if (datas != null) {
data = datas.get(y);
} else {
data = 0;
}
loc = entry.getKey();
final int xx = loc.x - X;
final int zz = loc.z - Z;
if ((xx >= 0) && (xx < 16)) {
if ((zz >= 0) && (zz < 16)) {
SetQueue.IMP.setBlock(world, xx, y, zz, new PlotBlock(entry2.getValue(), data));
}
}
}
}
}
return;
}
final boolean check;
check = !inX1 || !inX2 || !inZ1 || !inZ2;
if (plotworld.TERRAIN > 1) {
final PlotId plot1 = manager.getPlotIdAbs(plotworld, bx, 0, bz);
final PlotId plot2 = manager.getPlotIdAbs(plotworld, tx, 0, tz);
if ((plot1 != null) && (plot2 != null) && plot1.equals(plot2)) {
return;
}
}
if (o) {
populateBlocks(worldObj, chunk, cx, cz, bx, bz, check);
} else {
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
// TODO populate biome
}
}, 20 + r.nextInt(10));
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
populateBlocks(worldObj, chunk, cx, cz, bx, bz, check);
}
}, 40 + r.nextInt(40));
}
}
private void populateBlocks(final World world, final Chunk chunk, final int X, final int Z, final int x, final int z, final boolean check) {
final String worldname = world.getName();
final MutableBlockVolume blocks = new MutableBlockVolume() {
@Override
public void setBlock(final int x, final int y, final int z, final BlockState t) {
if (check && (((z) < bz) || ((z) > tz) || ((x) < bx) || ((x) > tx))) {
return;
}
if (p) {
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
if (ChunkManager.CURRENT_PLOT_CLEAR.isIn(x, z)) {
return;
}
} else if (manager.getPlotIdAbs(plotworld, x, 0, z) != null) {
return;
}
}
final PlotBlock block = SpongeMain.THIS.getPlotBlock(t);
if (block != null) {
SetQueue.IMP.setBlock(worldname, x, y, z, block);
}
}
@Override
public void setBlock(final Vector3i v, final BlockState t) {
setBlock(v.getX(), v.getY(), v.getZ(), t);
}
@Override
public BlockType getBlockType(final int x, final int y, final int z) {
return world.getBlockType(x, y, z);
}
@Override
public BlockType getBlockType(final Vector3i v) {
return getBlockType(v.getX(), v.getY(), v.getZ());
}
@Override
public Vector3i getBlockSize() {
return chunk.getBlockSize();
}
@Override
public Vector3i getBlockMin() {
return chunk.getBlockMin();
}
@Override
public Vector3i getBlockMax() {
return chunk.getBlockMax();
}
@Override
public BlockState getBlock(final int x, final int y, final int z) {
return world.getBlock(x, y, z);
}
@Override
public BlockState getBlock(final Vector3i v) {
return getBlock(v.getX(), v.getY(), v.getZ());
}
@Override
public boolean containsBlock(final int x, final int y, final int z) {
return ((x) >= bz) && ((z) <= tz) && ((x) >= bx) && ((z) <= tx);
}
@Override
public boolean containsBlock(final Vector3i v) {
return containsBlock(v.getX(), v.getY(), v.getZ());
}
@Override
public void setBlockType(final int x, final int y, final int z, final BlockType t) {
if (check && (((z) < bz) || ((z) > tz) || ((x) < bx) || ((x) > tx))) {
return;
}
if (p) {
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
if (ChunkManager.CURRENT_PLOT_CLEAR.isIn(x, z)) {
return;
}
} else if (manager.getPlotIdAbs(plotworld, x, 0, z) != null) {
return;
}
}
final PlotBlock block = SpongeMain.THIS.getPlotBlock(t.getDefaultState());
if (block != null) {
SetQueue.IMP.setBlock(worldname, x, y, z, block);
}
}
@Override
public void setBlockType(final Vector3i v, final BlockType t) {
setBlockType(v.getX(), v.getY(), v.getZ(), t);
}
@Override
public MutableBlockVolume getBlockCopy() {
// TODO Auto-generated method stub
return this;
}
@Override
public MutableBlockVolume getBlockCopy(final StorageType arg0) {
// TODO Auto-generated method stub
return this;
}
@Override
public ImmutableBlockVolume getImmutableBlockCopy() {
// TODO Auto-generated method stub
return null;
}
@Override
public UnmodifiableBlockVolume getUnmodifiableBlockView() {
// TODO Auto-generated method stub
return null;
}
@Override
public MutableBlockVolume getBlockView(final DiscreteTransform3 arg0) {
// TODO Auto-generated method stub
return this;
}
@Override
public MutableBlockVolume getBlockView(final Vector3i arg0, final Vector3i arg1) {
// TODO Auto-generated method stub
return this;
}
@Override
public MutableBlockVolume getRelativeBlockView() {
// TODO Auto-generated method stub
return this;
}
};
populator.populate(world, blocks, null);
}
}

View File

@ -0,0 +1,77 @@
package com.plotsquared.sponge.generator;
import java.util.List;
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 org.spongepowered.api.world.gen.WorldGenerator;
import com.flowpowered.math.vector.Vector3i;
import com.intellectualcrafters.plot.generator.AugmentedUtils;
import com.intellectualcrafters.plot.object.LazyResult;
import com.intellectualcrafters.plot.util.PlotChunk;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.plotsquared.sponge.util.SpongeUtil;
public class SpongeAugmentedGenerator implements GenerationPopulator {
private static SpongeAugmentedGenerator generator;
private SpongeAugmentedGenerator() {};
public static SpongeAugmentedGenerator get(World world) {
WorldGenerator wg = world.getWorldGenerator();
List<GenerationPopulator> populators = wg.getGenerationPopulators();
for (GenerationPopulator poplator : populators) {
if (poplator instanceof SpongeAugmentedGenerator) {
return (SpongeAugmentedGenerator) poplator;
}
}
if (generator == null) {
generator = new SpongeAugmentedGenerator();
}
populators.add(generator);
return generator;
}
@Override
public void populate(final World world, final MutableBlockVolume terrain, final ImmutableBiomeArea biome) {
Vector3i min = terrain.getBlockMin();
final int bx = min.getX();
final int bz = min.getZ();
final int cx = bx >> 4;
final int cz = bz >> 4;
AugmentedUtils.generate(world.getName(), cx, cz, new LazyResult<PlotChunk<?>>() {
@Override
public PlotChunk<?> create() {
ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(world.getName(), cx, cz);
return new PlotChunk<ChunkWrapper>(wrap) {
@Override
public ChunkWrapper getChunkAbs() {
return getChunkWrapper();
}
@Override
public void setBlock(int x, int y, int z, int id, byte data) {
terrain.setBlock(bx + x, y, bz + z, SpongeUtil.getBlockState(id, data));
}
@Override
public void setBiome(int x, int z, int biome) {
world.setBiome(bx + x, bz + z, null);
}
@Override
public PlotChunk clone() {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@Override
public PlotChunk shallowClone() {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
};
}
});
}
}

View File

@ -1,37 +0,0 @@
package com.plotsquared.sponge.generator;
import org.spongepowered.api.world.biome.BiomeType;
import org.spongepowered.api.world.biome.BiomeTypes;
import org.spongepowered.api.world.extent.MutableBiomeArea;
import org.spongepowered.api.world.gen.BiomeGenerator;
import com.flowpowered.math.vector.Vector2i;
import com.intellectualcrafters.plot.object.PlotArea;
public class SpongeBasicBiomeProvider implements BiomeGenerator {
private final PlotArea plotworld;
public SpongeBasicBiomeProvider(final PlotArea plotworld) {
this.plotworld = plotworld;
}
@Override
public void generateBiomes(final MutableBiomeArea biomeBase) {
final Vector2i min = biomeBase.getBiomeMin();
final int bx = min.getX();
final int bz = min.getY();
BiomeType biome = BiomeTypes.FOREST;
try {
biome = (BiomeType) BiomeTypes.class.getField(plotworld.PLOT_BIOME.toUpperCase()).get(null);
} catch (final Exception e) {
e.printStackTrace();
}
for (int x = bx; x < (bx + 16); x++) {
for (int z = bz; z < (bz + 16); z++) {
biomeBase.setBiome(x, z, biome);
}
}
}
}

View File

@ -1,129 +0,0 @@
package com.plotsquared.sponge.generator;
import java.util.ArrayList;
import java.util.List;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.world.gen.BiomeGenerator;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.HybridPlotManager;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotManager;
import com.plotsquared.sponge.SpongeMain;
public class SpongeBasicGen extends SpongePlotGenerator {
public final BlockState AIR = BlockTypes.AIR.getDefaultState();
private static HybridPlotManager manager;
public HybridPlotWorld plotworld;
public SpongeBasicGen(final String world) {
super(world);
}
/**
* Some generator specific variables (implementation dependent)
*/
public int plotsize;
public int pathsize;
public int size;
public int roadheight;
public int wallheight;
public int plotheight;
public short pathWidthLower;
public short pathWidthUpper;
public boolean doState = false;
BlockState wall;
BlockState wallfilling;
BlockState roadblock;
BlockState[] plotfloors;
BlockState[] filling;
@Override
public void init(final PlotArea plotworld) {
if (plotworld != null) {
this.plotworld = (HybridPlotWorld) plotworld;
}
plotsize = this.plotworld.PLOT_WIDTH;
pathsize = this.plotworld.ROAD_WIDTH;
size = pathsize + plotsize;
wallheight = this.plotworld.WALL_HEIGHT;
roadheight = this.plotworld.ROAD_HEIGHT;
plotheight = this.plotworld.PLOT_HEIGHT;
if (pathsize == 0) {
pathWidthLower = (short) -1;
pathWidthUpper = (short) (plotsize + 1);
} else {
if ((pathsize % 2) == 0) {
pathWidthLower = (short) (Math.floor(pathsize / 2) - 1);
} else {
pathWidthLower = (short) (Math.floor(pathsize / 2));
}
pathWidthUpper = (short) (pathWidthLower + plotsize + 1);
}
roadblock = SpongeMain.THIS.getBlockState(this.plotworld.ROAD_BLOCK);
wallfilling = SpongeMain.THIS.getBlockState(this.plotworld.WALL_FILLING);
wall = SpongeMain.THIS.getBlockState(this.plotworld.WALL_BLOCK);
plotfloors = new BlockState[this.plotworld.TOP_BLOCK.length];
for (int i = 0; i < this.plotworld.TOP_BLOCK.length; i++) {
plotfloors[i] = SpongeMain.THIS.getBlockState(this.plotworld.TOP_BLOCK[i]);
}
filling = new BlockState[this.plotworld.MAIN_BLOCK.length];
for (int i = 0; i < this.plotworld.MAIN_BLOCK.length; i++) {
filling[i] = SpongeMain.THIS.getBlockState(this.plotworld.MAIN_BLOCK[i]);
}
if ((filling.length > 1) || (plotfloors.length > 1)) {
doState = true;
}
}
@Override
public PlotArea getNewPlotWorld(final String world) {
if (plotworld == null) {
plotworld = (HybridPlotWorld) PS.get().getPlotArea(world);
if (plotworld == null) {
plotworld = new HybridPlotWorld(world);
}
}
return plotworld;
}
@Override
public PlotManager getPlotManager() {
if (SpongeBasicGen.manager == null) {
SpongeBasicGen.manager = new HybridPlotManager();
}
return SpongeBasicGen.manager;
}
@Override
public List<SpongePlotPopulator> getPlotPopulators() {
// TODO Auto-generated method stub
return new ArrayList<>();
}
private SpongeBasicPop generator;
@Override
public SpongePlotPopulator getGenerator() {
if (generator == null) {
generator = new SpongeBasicPop(this);
}
return generator;
}
private BiomeGenerator biome;
@Override
public BiomeGenerator getPlotBiomeProvider() {
if (biome == null) {
biome = new SpongeBasicBiomeProvider(plotworld);
}
return biome;
}
}

View File

@ -1,125 +0,0 @@
package com.plotsquared.sponge.generator;
import java.util.HashMap;
import java.util.HashSet;
import org.spongepowered.api.world.World;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.sponge.SpongeMain;
public class SpongeBasicPop extends SpongePlotPopulator<SpongeBasicGen> {
public SpongeBasicPop(final SpongeBasicGen generator) {
super(generator);
}
@Override
public void populate(final World world, final RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz) {
int sx = (short) ((X - generator.plotworld.ROAD_OFFSET_X) % generator.size);
int sz = (short) ((Z - generator.plotworld.ROAD_OFFSET_Z) % generator.size);
if (sx < 0) {
sx += generator.size;
}
if (sz < 0) {
sz += generator.size;
}
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
final int absX = ((sx + x) % generator.size);
final int absZ = ((sz + z) % generator.size);
final boolean gx = absX > generator.pathWidthLower;
final boolean gz = absZ > generator.pathWidthLower;
final boolean lx = absX < generator.pathWidthUpper;
final boolean lz = absZ < generator.pathWidthUpper;
// inside plot
if (gx && gz && lx && lz) {
for (short y = 1; y < generator.plotheight; y++) {
setBlock(x, y, z, generator.filling);
}
setBlock(x, (short) generator.plotheight, z, generator.plotfloors);
if ((generator.plotworld.TYPE != 0) && (generator.plotworld.TERRAIN < 2)) {
for (int y = generator.plotheight + 1; y < 128; y++) {
setBlock(x, y, z, generator.AIR);
}
}
if (generator.plotworld.PLOT_SCHEMATIC) {
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Short> blocks = generator.plotworld.G_SCH.get(loc);
if (blocks != null) {
final HashMap<Short, Byte> datas = generator.plotworld.G_SCH_DATA.get(loc);
if (datas != null) {
for (final short y : blocks.keySet()) {
final Byte data = datas.get(y);
setBlock(x, (short) (generator.plotheight + y), z, SpongeMain.THIS.getBlockState(new PlotBlock(blocks.get(y), data == null ? 0 : data)));
}
} else {
for (final short y : blocks.keySet()) {
setBlock(x, (short) (generator.plotheight + y), z, SpongeMain.THIS.getBlockState(blocks.get(y)));
}
}
}
if (generator.plotworld.G_SCH_STATE != null) {
final HashSet<PlotItem> states = generator.plotworld.G_SCH_STATE.get(loc);
if (states != null) {
for (final PlotItem items : states) {
items.x = X + x;
items.z = Z + z;
WorldUtil.IMP.addItems(generator.plotworld.worldname, items);
}
}
}
}
} else if (generator.pathsize != 0) {
// wall
if (((absX >= generator.pathWidthLower) && (absX <= generator.pathWidthUpper) && (absZ >= generator.pathWidthLower) && (absZ <= generator.pathWidthUpper))) {
for (short y = 1; y <= generator.wallheight; y++) {
setBlock(x, y, z, generator.wallfilling);
}
if ((generator.plotworld.TYPE != 0) && (generator.plotworld.TERRAIN < 3)) {
for (int y = generator.wallheight + 2; y < 128; y++) {
setBlock(x, y, z, generator.AIR);
}
}
if (!generator.plotworld.ROAD_SCHEMATIC_ENABLED) {
setBlock(x, generator.wallheight + 1, z, generator.wall);
}
}
// road
else {
for (short y = 1; y <= generator.roadheight; y++) {
setBlock(x, y, z, generator.roadblock);
}
if ((generator.plotworld.TYPE != 0) && (generator.plotworld.TERRAIN < 3)) {
for (int y = generator.roadheight + 1; y < 128; y++) {
setBlock(x, y, z, generator.AIR);
}
}
}
if (generator.plotworld.ROAD_SCHEMATIC_ENABLED) {
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Short> blocks = generator.plotworld.G_SCH.get(loc);
if (blocks != null) {
final HashMap<Short, Byte> datas = generator.plotworld.G_SCH_DATA.get(loc);
if (datas != null) {
for (final short y : blocks.keySet()) {
final Byte data = datas.get(y);
setBlock(x, (short) (generator.plotheight + y), z, SpongeMain.THIS.getBlockState(new PlotBlock(blocks.get(y), data == null ? 0 : data)));
}
} else {
for (final short y : blocks.keySet()) {
setBlock(x, (short) (generator.plotheight + y), z, SpongeMain.THIS.getBlockState(blocks.get(y)));
}
}
}
}
}
}
}
}
}

View File

@ -1,93 +0,0 @@
package com.plotsquared.sponge.generator;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.gen.WorldGenerator;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.SetupObject;
import com.plotsquared.sponge.util.SpongeUtil;
public class SpongeGeneratorWrapper extends PlotGenerator<WorldGenerator> {
public final boolean full;
public SpongeGeneratorWrapper(final String world, final WorldGenerator generator) {
super(world, generator);
full = (generator instanceof SpongePlotGenerator);
}
@Override
public void initialize(final PlotArea plotworld) {
if (generator instanceof SpongePlotGenerator) {
((SpongePlotGenerator) generator).init(plotworld);
}
}
@Override
public void augment(final PlotCluster cluster, final PlotArea plotworld) {
if (generator instanceof SpongePlotGenerator) {
final SpongePlotGenerator plotgen = (SpongePlotGenerator) generator;
final World worldObj = SpongeUtil.getWorld(world);
if (worldObj != null) {
if (cluster != null) {
new AugmentedPopulator(world, worldObj.getWorldGenerator(), plotgen, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
} else {
new AugmentedPopulator(world, worldObj.getWorldGenerator(), plotgen, null, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
}
}
}
}
@Override
public void setGenerator(final String gen_string) {
if (gen_string == null) {
generator = new SpongeBasicGen(world);
} else {
final PlotGenerator<WorldGenerator> gen_wrapper = (PlotGenerator<WorldGenerator>) PS.get().IMP.getGenerator(world, gen_string);
if (gen_wrapper != null) {
generator = gen_wrapper.generator;
}
}
}
@Override
public PlotArea getNewPlotWorld(final String world) {
if (!(generator instanceof SpongePlotGenerator)) {
return null;
}
return ((SpongePlotGenerator) generator).getNewPlotWorld(world);
}
@Override
public PlotManager getPlotManager() {
if (!(generator instanceof SpongePlotGenerator)) {
return null;
}
return ((SpongePlotGenerator) generator).getPlotManager();
}
@Override
public boolean isFull() {
return full;
}
@Override
public String getName() {
if (generator == null) {
return "Null";
}
return generator.getClass().getName();
}
@Override
public void processSetup(final SetupObject object) {
if (generator instanceof SpongePlotGenerator) {
((SpongePlotGenerator) generator).processSetup(object);
}
}
}

View File

@ -1,118 +1,153 @@
package com.plotsquared.sponge.generator; package com.plotsquared.sponge.generator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.spongepowered.api.world.biome.BiomeGenerationSettings; import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.WorldCreationSettings;
import org.spongepowered.api.world.biome.BiomeType; import org.spongepowered.api.world.biome.BiomeType;
import org.spongepowered.api.world.extent.ImmutableBiomeArea;
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.BiomeGenerator;
import org.spongepowered.api.world.gen.GenerationPopulator; import org.spongepowered.api.world.gen.GenerationPopulator;
import org.spongepowered.api.world.gen.Populator;
import org.spongepowered.api.world.gen.WorldGenerator; 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.PlotArea;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.SetupObject; 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.plotsquared.sponge.util.SpongeUtil;
import com.plotsquared.sponge.util.block.GenChunk;
public abstract class SpongePlotGenerator implements WorldGenerator { public class SpongePlotGenerator implements WorldGeneratorModifier, GeneratorWrapper<WorldGeneratorModifier> {
public String world; private final PseudoRandom random = new PseudoRandom();
private final IndependentPlotGenerator plotGenerator;
private final List<GenerationPopulator> populators = new ArrayList<>();
private final boolean loaded = false;
private PlotManager manager;
private final WorldGeneratorModifier platformGenerator;
private final boolean full;
public SpongePlotGenerator(final String world) { public SpongePlotGenerator(IndependentPlotGenerator generator) {
this.world = world; this.plotGenerator = generator;
this.platformGenerator = this;
this.full = true;
MainUtil.initCache();
}
public SpongePlotGenerator(WorldGeneratorModifier wgm) {
this.plotGenerator = null;
this.platformGenerator = wgm;
this.full = false;
MainUtil.initCache();
}
@Override
public String getId() {
return "PlotSquared";
} }
@Override @Override
public GenerationPopulator getBaseGenerationPopulator() { public String getName() {
return getGenerator(); return "PlotSquared";
} }
@Override @Override
public BiomeGenerator getBiomeGenerator() { public void modifyWorldGenerator(WorldCreationSettings settings, DataContainer data, WorldGenerator wg) {
return getPlotBiomeProvider(); if (full) {
} final String worldname = settings.getWorldName();
wg.getGenerationPopulators().clear();
@Override wg.getPopulators().clear();
public List<Populator> getPopulators() { wg.setBaseGenerationPopulator(new GenerationPopulator() {
return new ArrayList<>(); @Override
} public void populate(World world, MutableBlockVolume terrain, ImmutableBiomeArea biome) {
System.out.println("POPULATE!");
@Override Vector3i size = terrain.getBlockSize();
public void setBiomeGenerator(final BiomeGenerator biomeGenerator) { if (size.getX() != 16 || size.getZ() != 16) {
// TODO throw new UnsupportedOperationException("NON CHUNK POPULATION NOT SUPPORTED");
throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); }
} String worldname = world.getName();
Vector3i min = terrain.getBlockMin();
@Override int cx = min.getX() >> 4;
public BiomeGenerationSettings getBiomeSettings(BiomeType type) { int cz = min.getZ() >> 4;
// TODO Auto-generated method stub ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(worldname, cx, cz);
throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); // Create the result object
} GenChunk result = new GenChunk(terrain, null, wrap);
// Catch any exceptions
@Override try {
public List<GenerationPopulator> getGenerationPopulators() { // Fill the result data if necessary
final List<GenerationPopulator> pops = new ArrayList<>(); if (platformGenerator != SpongePlotGenerator.this) {
pops.addAll(getPlotPopulators()); throw new UnsupportedOperationException("NOT IMPLEMENTED YET!");
return pops; } else {
} // Set random seed
random.state = (cx << 16) | (cz & 0xFFFF);
@Override // Process the chunk
public List<GenerationPopulator> getGenerationPopulators(Class<? extends GenerationPopulator> clazz) { result.modified = false;
List<GenerationPopulator> list = getGenerationPopulators(); ChunkManager.preProcessChunk(result);
Iterator<GenerationPopulator> iter = list.iterator(); if (result.modified) {
while (iter.hasNext()) { return;
GenerationPopulator pop = iter.next(); }
if (!clazz.isInstance(pop)) { PlotArea area = PS.get().getPlotArea(world.getName(), null);
iter.remove(); plotGenerator.generateChunk(result, area, random);
} ChunkManager.postProcessChunk(result);
return;
}
} catch (Throwable e) {
e.printStackTrace();
}
}
});
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");
} }
return list;
} }
@Override @Override
public List<Populator> getPopulators(Class<? extends Populator> arg0) { public IndependentPlotGenerator getPlotGenerator() {
return new ArrayList<>(); return plotGenerator;
} }
@Override @Override
public void setBaseGenerationPopulator(GenerationPopulator arg0) { public WorldGeneratorModifier getPlatformGenerator() {
// TODO return platformGenerator;
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
} }
public abstract SpongePlotPopulator getGenerator();
public abstract BiomeGenerator getPlotBiomeProvider(); @Override
public void augment(PlotArea area) {
SpongeAugmentedGenerator.get(SpongeUtil.getWorld(area.worldname));
}
public abstract List<SpongePlotPopulator> getPlotPopulators(); @Override
public boolean isFull() {
return full;
}
/**
* This is called when the generator is initialized.
* You don't need to do anything with it necessarily.
* @param plotworld
*/
public abstract void init(final PlotArea plotworld);
/**
* Return a new instance of the PlotArea for a world
* @param world
* @return
*/
public abstract PlotArea getNewPlotWorld(final String world);
/**
* Get the PlotManager class for this generator
* @return
*/
public abstract PlotManager getPlotManager();
/**
* If you need to do anything fancy for /plot setup<br>
* - Otherwise it will just use the PlotArea configuration<br>
* Feel free to extend BukkitSetupUtils and customize world creation
* @param object
*/
public void processSetup(final SetupObject object) {}
} }

View File

@ -1,87 +0,0 @@
package com.plotsquared.sponge.generator;
import org.bukkit.block.BlockState;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.ChunkManager;
public abstract class SpongePlotPopulator<T extends SpongePlotGenerator> implements GenerationPopulator {
public final T generator;
private final PseudoRandom random = new PseudoRandom();
public int X;
public int Z;
public String worldname;
private MutableBlockVolume buffer;
public SpongePlotPopulator(final T generator) {
this.generator = generator;
}
// @Override
// public void populate(Chunk chunk, Random random) {
// this.world = chunk.getWorld();
// this.worldname = world.getName();
// Vector3i min = chunk.getBlockMin();
// }
@Override
public void populate(final World world, final MutableBlockVolume buffer, final ImmutableBiomeArea biomeBase) {
try {
this.worldname = world.getName();
this.buffer = buffer;
final Vector3i min = buffer.getBlockMin();
this.X = min.getX();
this.Z = min.getZ();
final int cx = X >> 4;
final int cz = Z >> 4;
int h = 1;
final int prime = 13;
h = (prime * h) + cx;
h = (prime * h) + cz;
this.random.state = h;
// TODO plot clearing stuff
populate(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz);
} catch (final Exception e) {
e.printStackTrace();
}
}
public abstract void populate(final World world, final RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz);
/**
* Set the id and data at a location. (x, y, z) must be between [0,15], [0,255], [0,15]
* @param x
* @param y
* @param z
* @param state
*/
public void setBlock(final int x, final int y, final int z, final BlockState state) {
buffer.setBlock(X + x, y, Z + z, state);
}
public void setBlock(final int x, final int y, final int z, final BlockState[] states) {
if (states.length == 1) {
setBlock(x, y, z, states[0]);
}
setBlock(x, y, z, states[random.random(states.length)]);
}
/**
* check if a region contains a location. (x, z) must be between [0,15], [0,15]
* @param plot
* @param x
* @param z
* @return
*/
public boolean contains(final RegionWrapper plot, final int x, final int z) {
final int xx = X + x;
final int zz = Z + z;
return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ));
}
}

View File

@ -1,52 +0,0 @@
package com.plotsquared.sponge.generator;
import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.world.WorldCreationSettings;
import org.spongepowered.api.world.gen.WorldGenerator;
import org.spongepowered.api.world.gen.WorldGeneratorModifier;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.util.ClusterManager;
public class WorldModify implements WorldGeneratorModifier {
private final SpongePlotGenerator plotgen;
private final boolean augment;
public WorldModify(final SpongePlotGenerator plotgen, final boolean augment) {
this.plotgen = plotgen;
this.augment = augment;
}
@Override
public void modifyWorldGenerator(final WorldCreationSettings world, final DataContainer settings, final WorldGenerator gen) {
if (augment) {
final String worldname = world.getWorldName();
plotgen.world = worldname;
final PlotArea plotworld = plotgen.getNewPlotWorld(worldname);
if (plotworld.TYPE == 2) {
for (final PlotCluster cluster : ClusterManager.getClusters(worldname)) {
new AugmentedPopulator(worldname, gen, plotgen, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
}
} else {
new AugmentedPopulator(worldname, gen, plotgen, null, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
}
} else {
gen.getGenerationPopulators().clear();
gen.getPopulators().clear();
gen.setBaseGenerationPopulator(plotgen.getBaseGenerationPopulator());
gen.setBiomeGenerator(plotgen.getBiomeGenerator());
}
}
@Override
public String getName() {
return "plotsquared";
}
@Override
public String getId() {
return "plotsquared";
}
}

View File

@ -0,0 +1,5 @@
package com.plotsquared.sponge.listener;
public class ChunkProcessor {
// TODO FIXME
}

View File

@ -9,14 +9,41 @@ import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.bukkit.block.BlockState; import org.spongepowered.api.block.BlockSnapshot;
import org.bukkit.entity.Ambient; import org.spongepowered.api.block.BlockState;
import org.bukkit.entity.Boat; import org.spongepowered.api.data.Transaction;
import org.bukkit.entity.Explosive; import org.spongepowered.api.entity.Entity;
import org.bukkit.entity.Minecart; import org.spongepowered.api.entity.EntityTypes;
import org.bukkit.entity.Monster; import org.spongepowered.api.entity.Transform;
import org.spongepowered.api.entity.explosive.Explosive;
import org.spongepowered.api.entity.explosive.PrimedTNT;
import org.spongepowered.api.entity.living.Ambient;
import org.spongepowered.api.entity.living.Living;
import org.spongepowered.api.entity.living.animal.Animal;
import org.spongepowered.api.entity.living.monster.Monster;
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.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.command.SendCommandEvent;
import org.spongepowered.api.event.entity.BreedEntityEvent;
import org.spongepowered.api.event.entity.DisplaceEntityEvent;
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.profile.GameProfile;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.Extent;
import com.avaje.ebean.Transaction; import com.flowpowered.math.vector.Vector3d;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -42,7 +69,6 @@ import com.plotsquared.listener.PlotListener;
import com.plotsquared.sponge.SpongeMain; 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 com.sk89q.worldedit.extent.Extent;
public class MainListener { public class MainListener {
@ -123,7 +149,7 @@ public class MainListener {
// } // }
public <T> T getCause(Cause cause, Class<T> clazz) { public <T> T getCause(Cause cause, Class<T> clazz) {
Optional<?> root = cause.root(); Optional<?> root = Optional.of(cause.root());
if (root.isPresent()) { if (root.isPresent()) {
Object source = root.get(); Object source = root.get();
if (clazz.isInstance(source)) { if (clazz.isInstance(source)) {
@ -137,13 +163,13 @@ public class MainListener {
public void onCommand(final BreedEntityEvent.Breed event) { public void onCommand(final BreedEntityEvent.Breed event) {
final Location loc = SpongeUtil.getLocation(event.getTargetEntity()); final Location loc = SpongeUtil.getLocation(event.getTargetEntity());
final String world = loc.getWorld(); final String world = loc.getWorld();
final PlotArea plotworld = PS.get().getPlotArea(world); final PlotArea plotworld = PS.get().getPlotAreaByString(world);
if (plotworld == null) { if (plotworld == null) {
return; return;
} }
final Plot plot = MainUtil.getPlot(loc); final Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (MainUtil.isPlotRoad(loc)) { if (loc.isPlotRoad()) {
event.setCancelled(true); event.setCancelled(true);
} }
return; return;
@ -156,7 +182,7 @@ public class MainListener {
@Listener @Listener
public void onMobSpawn(final SpawnEntityEvent event) { public void onMobSpawn(final SpawnEntityEvent event) {
World world = event.getTargetWorld(); World world = event.getTargetWorld();
final PlotArea plotworld = PS.get().getPlotArea(world.getName()); final PlotArea plotworld = PS.get().getPlotAreaByString(world.getName());
if (plotworld == null) { if (plotworld == null) {
return; return;
} }
@ -169,9 +195,9 @@ public class MainListener {
return true; return true;
} }
final Location loc = SpongeUtil.getLocation(entity); final Location loc = SpongeUtil.getLocation(entity);
final Plot plot = MainUtil.getPlot(loc); final Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (MainUtil.isPlotRoad(loc)) { if (loc.isPlotRoad()) {
return false; return false;
} }
return true; return true;
@ -202,7 +228,7 @@ public class MainListener {
return false; return false;
} }
if (mobs == null) { if (mobs == null) {
mobs = MainUtil.countEntities(plot); mobs = plot.countEntities();
} }
if (mobs[3] >= cap) { if (mobs[3] >= cap) {
return false; return false;
@ -216,7 +242,7 @@ public class MainListener {
return false; return false;
} }
if (mobs == null) { if (mobs == null) {
mobs = MainUtil.countEntities(plot); mobs = plot.countEntities();
} }
if (mobs[1] >= cap) { if (mobs[1] >= cap) {
return false; return false;
@ -231,7 +257,7 @@ public class MainListener {
return false; return false;
} }
if (mobs == null) { if (mobs == null) {
mobs = MainUtil.countEntities(plot); mobs = plot.countEntities();
} }
if (mobs[2] >= cap) { if (mobs[2] >= cap) {
return false; return false;
@ -248,7 +274,7 @@ public class MainListener {
return false; return false;
} }
if (mobs == null) { if (mobs == null) {
mobs = MainUtil.countEntities(plot); mobs = plot.countEntities();
} }
if (mobs[4] >= cap) { if (mobs[4] >= cap) {
return false; return false;
@ -262,7 +288,7 @@ public class MainListener {
return false; return false;
} }
if (mobs == null) { if (mobs == null) {
mobs = MainUtil.countEntities(plot); mobs = plot.countEntities();
} }
if (mobs[0] >= cap) { if (mobs[0] >= cap) {
return false; return false;
@ -286,9 +312,9 @@ public class MainListener {
return; return;
} }
if (Settings.USE_PLOTME_ALIAS) { if (Settings.USE_PLOTME_ALIAS) {
SpongeMain.THIS.getGame().getCommandDispatcher().process(source, ("plots " + event.getArguments()).trim()); SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim());
} else { } else {
source.sendMessage(SpongeMain.THIS.getText(C.NOT_USING_PLOTME.s())); source.sendMessage(SpongeUtil.text(C.NOT_USING_PLOTME.s()));
} }
event.setCancelled(true); event.setCancelled(true);
} }
@ -304,9 +330,9 @@ public class MainListener {
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()); Location loc = SpongeUtil.getLocation(worldname, first.getOriginal().getPosition());
Plot plot = MainUtil.getPlot(loc); Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null /*MainUtil.isPlotAreaAbs(loc)*/) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
@ -316,7 +342,7 @@ public class MainListener {
@Override @Override
public boolean test(org.spongepowered.api.world.Location<World> loc) { public boolean test(org.spongepowered.api.world.Location<World> loc) {
if (MainUtil.isPlotRoad(SpongeUtil.getLocation(worldname, loc))) { if (SpongeUtil.getLocation(worldname, loc).isPlotRoad()) {
return false; return false;
} }
return true; return true;
@ -342,7 +368,7 @@ public class MainListener {
public void printCause(String method, Cause cause) { public void printCause(String method, Cause cause) {
System.out.println(method + ": " + cause.toString()); System.out.println(method + ": " + cause.toString());
System.out.println(method + ": " + cause.getClass()); System.out.println(method + ": " + cause.getClass());
System.out.println(method + ": " + (cause.root().isPresent() ? cause.root().get() : null)); System.out.println(method + ": " + (cause.root()));
} }
@Listener @Listener
@ -356,17 +382,17 @@ public class MainListener {
if (!PS.get().hasPlotArea(world)) { if (!PS.get().hasPlotArea(world)) {
return; return;
} }
final PlotArea plotworld = PS.get().getPlotArea(world); final PlotArea plotworld = PS.get().getPlotAreaByString(world);
final PlotPlayer plr = SpongeUtil.getPlayer(player); final PlotPlayer plr = SpongeUtil.getPlayer(player);
if (!plotworld.PLOT_CHAT && ((plr.getMeta("chat") == null) || !(Boolean) plr.getMeta("chat"))) { if (!plotworld.PLOT_CHAT && ((plr.getMeta("chat") == null) || !(Boolean) plr.getMeta("chat"))) {
return; return;
} }
final Location loc = SpongeUtil.getLocation(player); final Location loc = SpongeUtil.getLocation(player);
final Plot plot = MainUtil.getPlot(loc); final Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
return; return;
} }
final Text message = event.getMessage(); final Text message = event.getMessage().get();
// TODO use display name rather than username // TODO use display name rather than username
// - Getting displayname currently causes NPE, so wait until sponge fixes that // - Getting displayname currently causes NPE, so wait until sponge fixes that
@ -374,12 +400,12 @@ public class MainListener {
final String sender = player.getName(); final String sender = player.getName();
final PlotId id = plot.getId(); final PlotId id = plot.getId();
final String newMessage = StringMan.replaceAll(C.PLOT_CHAT_FORMAT.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender); final String newMessage = StringMan.replaceAll(C.PLOT_CHAT_FORMAT.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender);
final Text forcedMessage = event.getMessage(); final Text forcedMessage = event.getMessage().get();
// String forcedMessage = StringMan.replaceAll(C.PLOT_CHAT_FORCED.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender); // String forcedMessage = StringMan.replaceAll(C.PLOT_CHAT_FORCED.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender);
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) { for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer user = entry.getValue(); PlotPlayer user = entry.getValue();
String toSend; String toSend;
if (plot.equals(MainUtil.getPlot(user.getLocation()))) { if (plot.equals(user.getLocation().getPlot())) {
toSend = newMessage; toSend = newMessage;
} else if (Permissions.hasPermission(user, C.PERMISSION_COMMANDS_CHAT)) { } else if (Permissions.hasPermission(user, C.PERMISSION_COMMANDS_CHAT)) {
((SpongePlayer) user).player.sendMessage(forcedMessage); ((SpongePlayer) user).player.sendMessage(forcedMessage);
@ -396,9 +422,9 @@ public class MainListener {
} else { } else {
prefix = message; prefix = message;
} }
components.add(Texts.of(part)); components.add(Text.of(part));
} }
((SpongePlayer) user).player.sendMessage(Texts.join(components)); ((SpongePlayer) user).player.sendMessage(Text.join(components));
} }
event.setMessage(null); event.setMessage(null);
} }
@ -424,7 +450,7 @@ public class MainListener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (originPlot == null && !MainUtil.isPlotAreaAbs(current)) { if (originPlot == null && current.getPlotAbs() == null /*May not work*/) {
return; return;
} }
if (!FlagManager.isPlotFlagTrue(currentPlot, "explosion")) { if (!FlagManager.isPlotFlagTrue(currentPlot, "explosion")) {
@ -467,10 +493,10 @@ public class MainListener {
onBlockChange(event); onBlockChange(event);
} }
@Listener // @Listener
public void onBlockBreak(final ChangeBlockEvent.Fluid event) { // public void onBlockBreak(final ChangeBlockEvent.Fluid event) {
onBlockChange(event); // onBlockChange(event);
} // }
@Listener @Listener
public void onBlockBreak(final ChangeBlockEvent.Grow event) { public void onBlockBreak(final ChangeBlockEvent.Grow event) {
@ -499,9 +525,9 @@ public class MainListener {
Transaction<BlockSnapshot> first = transactions.get(0); Transaction<BlockSnapshot> first = transactions.get(0);
BlockSnapshot pos = first.getOriginal(); BlockSnapshot pos = first.getOriginal();
Location loc = SpongeUtil.getLocation(worldname, pos.getPosition()); Location loc = SpongeUtil.getLocation(worldname, pos.getPosition());
Plot plot = MainUtil.getPlot(loc); Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null) {
return; return;
} }
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
@ -523,7 +549,7 @@ public class MainListener {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
final Flag destroy = FlagManager.getPlotFlagRaw(plot, "break"); final Flag destroy = FlagManager.getPlotFlagRaw(plot, "break");
final BlockState state = pos.getState(); final BlockState state = pos.getState();
if ((destroy == null) || !((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeMain.THIS.getPlotBlock(state))) { if ((destroy == null) || !((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeUtil.getPlotBlock(state))) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -536,7 +562,7 @@ public class MainListener {
Location loc = SpongeUtil.getLocation(worldname, l); Location loc = SpongeUtil.getLocation(worldname, l);
Plot plot = loc.getPlot(); Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null) {
return true; return true;
} }
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
@ -556,7 +582,7 @@ public class MainListener {
} else { } else {
final Flag destroy = FlagManager.getPlotFlagRaw(plot, "break"); final Flag destroy = FlagManager.getPlotFlagRaw(plot, "break");
final BlockState state = l.getBlock(); final BlockState state = l.getBlock();
if ((destroy != null) && ((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeMain.THIS.getPlotBlock(state))) { if ((destroy != null) && ((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeUtil.getPlotBlock(state))) {
return true; return true;
} }
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
@ -583,9 +609,9 @@ public class MainListener {
Transaction<BlockSnapshot> first = transactions.get(0); Transaction<BlockSnapshot> first = transactions.get(0);
BlockSnapshot pos = first.getOriginal(); BlockSnapshot pos = first.getOriginal();
Location loc = SpongeUtil.getLocation(worldname, pos.getPosition()); Location loc = SpongeUtil.getLocation(worldname, pos.getPosition());
Plot plot = MainUtil.getPlot(loc); Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null) {
return; return;
} }
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
@ -607,7 +633,7 @@ public class MainListener {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
final Flag BUILD = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s()); final Flag BUILD = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s());
final BlockState state = pos.getState(); final BlockState state = pos.getState();
if ((BUILD == null) || !((HashSet<PlotBlock>) BUILD.getValue()).contains(SpongeMain.THIS.getPlotBlock(state))) { if ((BUILD == null) || !((HashSet<PlotBlock>) BUILD.getValue()).contains(SpongeUtil.getPlotBlock(state))) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -620,7 +646,7 @@ public class MainListener {
Location loc = SpongeUtil.getLocation(worldname, l); Location loc = SpongeUtil.getLocation(worldname, l);
Plot plot = loc.getPlot(); Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null) {
return true; return true;
} }
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
@ -640,7 +666,7 @@ public class MainListener {
} else { } else {
final Flag build = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s()); final Flag build = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s());
final BlockState state = l.getBlock(); final BlockState state = l.getBlock();
if ((build != null) && ((HashSet<PlotBlock>) build.getValue()).contains(SpongeMain.THIS.getPlotBlock(state))) { if ((build != null) && ((HashSet<PlotBlock>) build.getValue()).contains(SpongeUtil.getPlotBlock(state))) {
return true; return true;
} }
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
@ -663,10 +689,10 @@ public class MainListener {
} }
org.spongepowered.api.world.Location<World> l = target.get(); org.spongepowered.api.world.Location<World> l = target.get();
Location loc = SpongeUtil.getLocation(l); Location loc = SpongeUtil.getLocation(l);
Plot plot = MainUtil.getPlot(loc); Plot plot = loc.getPlot();
PlotPlayer pp = SpongeUtil.getPlayer(player); PlotPlayer pp = SpongeUtil.getPlayer(player);
if (plot == null) { if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) { if (loc.getPlotAbs() == null) {
return; return;
} }
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) {
@ -687,7 +713,7 @@ public class MainListener {
return; return;
} else { } else {
final Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); final Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
if ((flag != null) && ((HashSet<PlotBlock>) flag.getValue()).contains(SpongeMain.THIS.getPlotBlock(l.getBlock()))) { if ((flag != null) && ((HashSet<PlotBlock>) flag.getValue()).contains(SpongeUtil.getPlotBlock(l.getBlock()))) {
return; return;
} }
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER);
@ -726,12 +752,12 @@ public class MainListener {
}, 20); }, 20);
} }
final Location loc = SpongeUtil.getLocation(player); final Location loc = SpongeUtil.getLocation(player);
final Plot plot = MainUtil.getPlot(loc); final Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
return; return;
} }
if (Settings.TELEPORT_ON_LOGIN) { if (Settings.TELEPORT_ON_LOGIN) {
MainUtil.teleportPlayer(pp, pp.getLocation(), plot); pp.teleport(loc);
MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD); MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD);
} }
PlotListener.plotEntry(pp, plot); PlotListener.plotEntry(pp, plot);
@ -764,11 +790,11 @@ public class MainListener {
pp.setMeta("location", SpongeUtil.getLocation(player)); pp.setMeta("location", SpongeUtil.getLocation(player));
final World world = (World) extent; final World world = (World) extent;
final String worldname = ((World) extent).getName(); final String worldname = ((World) extent).getName();
final PlotArea plotworld = PS.get().getPlotArea(worldname); final PlotArea plotworld = PS.get().getPlotAreaByString(worldname);
if (plotworld == null) { if (plotworld == null) {
return; return;
} }
final PlotManager plotManager = PS.get().getPlotManager(worldname); 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, getInt(to.getZ()));
final Plot lastPlot = (Plot) pp.getMeta("lastplot"); final Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) { if (id == null) {
@ -777,7 +803,7 @@ public class MainListener {
} }
if (!PlotListener.plotExit(pp, lastPlot)) { if (!PlotListener.plotExit(pp, lastPlot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { if (lastPlot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) {
event.setCancelled(true); event.setCancelled(true);
} else { } else {
event.setToTransform(new Transform<>(world.getSpawnLocation())); event.setToTransform(new Transform<>(world.getSpawnLocation()));
@ -787,10 +813,10 @@ public class MainListener {
} else if ((lastPlot != null) && id.equals(lastPlot.getId())) { } else if ((lastPlot != null) && id.equals(lastPlot.getId())) {
return; return;
} else { } else {
final Plot plot = MainUtil.getPlot(worldname, id); final Plot plot = PS.get().getPlot(PS.get().getPlotAreaByString(worldname), id);
if (!PlotListener.plotEntry(pp, plot)) { if (!PlotListener.plotEntry(pp, plot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.getBasePlot(false).equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { if (!plot.getBasePlot(false).equals(SpongeUtil.getLocation(worldname, from).getPlot())) {
event.setCancelled(true); event.setCancelled(true);
} else { } else {
event.setToTransform(new Transform<>(world.getSpawnLocation())); event.setToTransform(new Transform<>(world.getSpawnLocation()));
@ -798,7 +824,7 @@ public class MainListener {
return; return;
} }
} }
final Integer border = MainUtil.worldBorder.get(worldname); final Integer border = plotworld.getBorder(); //worldBorder.get(worldname); **May not work**
if (border != null) { if (border != null) {
if (x2 > border) { if (x2 > border) {
final Vector3d pos = to.getPosition(); final Vector3d pos = to.getPosition();
@ -826,11 +852,11 @@ public class MainListener {
pp.setMeta("location", SpongeUtil.getLocation(player)); pp.setMeta("location", SpongeUtil.getLocation(player));
final World world = (World) extent; final World world = (World) extent;
final String worldname = ((World) extent).getName(); final String worldname = ((World) extent).getName();
final PlotArea plotworld = PS.get().getPlotArea(worldname); final PlotArea plotworld = PS.get().getPlotAreaByString(worldname);
if (plotworld == null) { if (plotworld == null) {
return; return;
} }
final PlotManager plotManager = PS.get().getPlotManager(worldname); final PlotManager plotManager = PS.get().getPlotManager(PS.get().getPlot(plotworld, plotworld.getMin()));
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2); final PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2);
final Plot lastPlot = (Plot) pp.getMeta("lastplot"); final Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) { if (id == null) {
@ -839,7 +865,7 @@ public class MainListener {
} }
if (!PlotListener.plotExit(pp, lastPlot)) { if (!PlotListener.plotExit(pp, lastPlot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { if (lastPlot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) {
event.setCancelled(true); event.setCancelled(true);
} else { } else {
event.setToTransform(new Transform<>(world.getSpawnLocation())); event.setToTransform(new Transform<>(world.getSpawnLocation()));
@ -849,10 +875,10 @@ public class MainListener {
} else if ((lastPlot != null) && id.equals(lastPlot.getId())) { } else if ((lastPlot != null) && id.equals(lastPlot.getId())) {
return; return;
} else { } else {
final Plot plot = MainUtil.getPlot(worldname, id); final Plot plot = PS.get().getPlot(PS.get().getPlotAreaByString(worldname), id);
if (!PlotListener.plotEntry(pp, plot)) { if (!PlotListener.plotEntry(pp, plot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { if (!plot.equals(SpongeUtil.getLocation(worldname, from).getPlot())) {
event.setCancelled(true); event.setCancelled(true);
} else { } else {
event.setToTransform(new Transform<>(world.getSpawnLocation())); event.setToTransform(new Transform<>(world.getSpawnLocation()));
@ -860,7 +886,7 @@ public class MainListener {
return; return;
} }
} }
final Integer border = MainUtil.worldBorder.get(worldname); final Integer border = plotworld.getBorder(); //worldBorder.get(worldname); **May not work**
if (border != null) { if (border != null) {
if (z2 > border) { if (z2 > border) {
final Vector3d pos = to.getPosition(); final Vector3d pos = to.getPosition();
@ -876,4 +902,4 @@ public class MainListener {
} }
} }
} }
} }

View File

@ -0,0 +1,5 @@
package com.plotsquared.sponge.listener;
public class WorldEvents {
// TODO FIXME
}

View File

@ -1,6 +1,6 @@
package com.plotsquared.sponge.object; package com.plotsquared.sponge.object;
import java.util.Date; import java.time.Instant;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
@ -11,17 +11,17 @@ import org.spongepowered.api.effect.sound.SoundTypes;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.living.player.gamemode.GameMode; import org.spongepowered.api.entity.living.player.gamemode.GameMode;
import org.spongepowered.api.entity.living.player.gamemode.GameModes; import org.spongepowered.api.entity.living.player.gamemode.GameModes;
import org.spongepowered.api.profile.GameProfile;
import org.spongepowered.api.service.ban.BanService; 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.chat.ChatTypes;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotGamemode; import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather; import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
@ -42,11 +42,6 @@ public class SpongePlayer extends PlotPlayer {
super.populatePersistentMetaMap(); super.populatePersistentMetaMap();
} }
@Override
public void sendMessage(final C c, final String... args) {
MainUtil.sendMessage(this, c, args);
}
@Override @Override
public RequiredType getSuperCaller() { public RequiredType getSuperCaller() {
return RequiredType.PLAYER; return RequiredType.PLAYER;
@ -54,9 +49,12 @@ public class SpongePlayer extends PlotPlayer {
@Override @Override
public long getPreviousLogin() { public long getPreviousLogin() {
final Value<Date> data = player.getJoinData().lastPlayed(); if (last != 0) {
return last;
}
final Value<Instant> data = player.getJoinData().lastPlayed();
if (data.exists()) { if (data.exists()) {
return last = data.get().getSeconds() * 1000; return last = data.get().getEpochSecond() * 1000;
} }
return 0; return 0;
} }
@ -103,7 +101,7 @@ public class SpongePlayer extends PlotPlayer {
@Override @Override
public void sendMessage(final String message) { public void sendMessage(final String message) {
player.sendMessage(ChatTypes.CHAT, Texts.of(message)); player.sendMessage(ChatTypes.CHAT, Text.of(message));
} }
@Override @Override
@ -205,7 +203,6 @@ public class SpongePlayer extends PlotPlayer {
@Override @Override
public void setGamemode(final PlotGamemode gamemode) { public void setGamemode(final PlotGamemode gamemode) {
// TODO Auto-generated method stub
switch (gamemode) { switch (gamemode) {
case ADVENTURE: case ADVENTURE:
player.offer(Keys.GAME_MODE, GameModes.ADVENTURE); player.offer(Keys.GAME_MODE, GameModes.ADVENTURE);
@ -282,12 +279,12 @@ public class SpongePlayer extends PlotPlayer {
@Override @Override
public void kick(final String message) { public void kick(final String message) {
player.kick(SpongeMain.THIS.getText(message)); player.kick(SpongeUtil.text(message));
} }
@Override @Override
public boolean isBanned() { public boolean isBanned() {
BanService service = SpongeMain.THIS.getGame().getServiceManager().provide(BanService.class).get(); BanService service = SpongeMain.THIS.getGame().getServiceManager().provide(BanService.class).get();
return service.isBanned(player); return service.isBanned((GameProfile) player);
} }
} }

View File

@ -1,51 +1,63 @@
package com.plotsquared.sponge.util; package com.plotsquared.sponge.util;
import java.util.UUID; import java.math.BigDecimal;
import java.util.Optional;
import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.NotImplementedException;
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.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer; import com.plotsquared.sponge.object.SpongePlayer;
public class SpongeEconHandler extends EconHandler { public class SpongeEconHandler extends EconHandler {
private Object TE_SERVICE; private EconomyService econ;
private Object EL_SERVICE;
public SpongeEconHandler() { @Listener
try { public void onChangeServiceProvider(ChangeServiceProviderEvent event) {
Class<?> clazz = Class.forName("com.erigitic.service.TEService"); if (event.getService().equals(EconomyService.class)) {
this.TE_SERVICE = SpongeMain.THIS.getGame().getServiceManager().provide(clazz).get(); this.econ = (EconomyService) event.getNewProviderRegistration().getProvider();
} catch (Exception e) {
try {
Class<?> clazz = Class.forName("me.Flibio.EconomyLite.API.EconomyLiteAPI");
this.EL_SERVICE = SpongeMain.THIS.getGame().getServiceManager().provide(clazz).get();
} catch (Exception e2) {
PS.log("No economy service found! (EconomyLite, TotalEconomy)");
}
} }
} }
@Override @Override
public void withdrawMoney(PlotPlayer player, double amount) { public void withdrawMoney(PlotPlayer player, double amount) {
UUID uuid = ((SpongePlayer) player).player.getUniqueId(); if (econ != null) {
Optional<UniqueAccount> uOpt = econ.getAccount(player.getUUID());
if (uOpt.isPresent()) {
UniqueAccount acc = uOpt.get();
acc.withdraw(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
}
}
} }
@Override @Override
public void depositMoney(PlotPlayer player, double amount) { public void depositMoney(PlotPlayer player, double amount) {
UUID uuid = ((SpongePlayer) player).player.getUniqueId(); if (econ != null) {
Optional<UniqueAccount> uOpt = econ.getAccount(player.getUUID());
if (uOpt.isPresent()) {
UniqueAccount acc = uOpt.get();
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
}
}
} }
@Override @Override
public void depositMoney(OfflinePlotPlayer player, double amount) { public void depositMoney(OfflinePlotPlayer player, double amount) {
UUID uuid = player.getUUID(); if (econ != null) {
Optional<UniqueAccount> uOpt = econ.getAccount(player.getUUID());
if (uOpt.isPresent()) {
UniqueAccount acc = uOpt.get();
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
}
}
} }
@Override @Override
@ -64,4 +76,17 @@ public class SpongeEconHandler extends EconHandler {
return false; return false;
} }
@Override
public double getBalance(PlotPlayer player) {
if (econ != null) {
Optional<UniqueAccount> uOpt = econ.getAccount(player.getUUID());
if (uOpt.isPresent()) {
UniqueAccount acc = uOpt.get();
BigDecimal balance = acc.getBalance(econ.getDefaultCurrency());
return balance.doubleValue();
}
}
return 0;
}
} }

View File

@ -43,6 +43,15 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import org.spongepowered.api.Game;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.scheduler.Task;
import com.google.inject.Inject;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
public class SpongeMetrics { public class SpongeMetrics {

View File

@ -1,15 +1,24 @@
package com.plotsquared.sponge.util; package com.plotsquared.sponge.util;
import java.lang.reflect.Field;
import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.translation.Translatable;
import org.spongepowered.api.text.translation.Translation;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import org.spongepowered.api.world.biome.BiomeType;
import org.spongepowered.api.world.biome.BiomeTypes;
import org.spongepowered.api.world.extent.Extent; import org.spongepowered.api.world.extent.Extent;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i; import com.flowpowered.math.vector.Vector3i;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
@ -25,6 +34,60 @@ public class SpongeUtil {
return new Location(world, pos.getX(), pos.getY(), pos.getZ()); return new Location(world, pos.getX(), pos.getY(), pos.getZ());
} }
private static BiomeType[] biomes;
public static BiomeType getBiome(int index) {
if (biomes == null) {
try {
Field[] fields = BiomeTypes.class.getFields();
biomes = new BiomeType[fields.length];
for (int i = 0; i < fields.length; i++) {
biomes[i] = (BiomeType) fields[i].get(null);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
return biomes[index];
}
public static Text text(String m) {
return Text.of(m);
}
public static Translation getTranslation(final String m) {
return new Translatable() {
@Override
public Translation getTranslation() {
return new Translation() {
@Override
public String getId() {
return m;
}
@Override
public String get(final Locale l, final Object... args) {
return m;
}
@Override
public String get(final Locale l) {
return m;
}
};
}
}.getTranslation();
}
public static BlockState getBlockState(int id, int data) {
}
public static PlotBlock getPlotBlock(BlockState state) {
}
public static Location getLocation(final org.spongepowered.api.world.Location<World> block) { public static Location getLocation(final org.spongepowered.api.world.Location<World> block) {
return getLocation(block.getExtent().getName(), block); return getLocation(block.getExtent().getName(), block);
} }

View File

@ -12,10 +12,11 @@ import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.SpongeMain;
import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.blocks.BlockType;
public class SpongeBlockManager extends BlockManager { public class SpongeWorldUtil extends WorldUtil {
@Override @Override
public boolean isBlockSolid(final PlotBlock block) { public boolean isBlockSolid(final PlotBlock block) {

View File

@ -0,0 +1,5 @@
package com.plotsquared.sponge.util.block;
public class FastQueue extends SlowQueue {
// TODO FIXME
}

View File

@ -0,0 +1,54 @@
package com.plotsquared.sponge.util.block;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.extent.MutableBiomeArea;
import org.spongepowered.api.world.extent.MutableBlockVolume;
import com.intellectualcrafters.plot.util.PlotChunk;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.plotsquared.sponge.util.SpongeUtil;
public class GenChunk extends PlotChunk<Chunk> {
public boolean modified = false;
private final MutableBlockVolume terain;
private final MutableBiomeArea biome;
private final int bz;
private final int bx;
public GenChunk(MutableBlockVolume terain, MutableBiomeArea biome, ChunkWrapper wrap) {
super(wrap);
this.bx = wrap.x << 4;
this.bz = wrap.z << 4;
this.terain = terain;
this.biome = biome;
}
@Override
public Chunk getChunkAbs() {
ChunkWrapper wrap = getChunkWrapper();
return SpongeUtil.getWorld(wrap.world).getChunk(wrap.x << 4, 0, wrap.z << 4).orElse(null);
}
@Override
public void setBiome(int x, int z, int biome) {
if (this.biome != null) {
this.biome.setBiome(bx + x, bz + z, SpongeUtil.getBiome(biome));
}
}
@Override
public void setBlock(int x, int y, int z, int id, byte data) {
terain.setBlock(bx + x, y, bz + z, SpongeUtil.getBlockState(id, data));
}
@Override
public PlotChunk clone() {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@Override
public PlotChunk shallowClone() {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
}

View File

@ -0,0 +1,66 @@
package com.plotsquared.sponge.util.block;
import org.spongepowered.api.world.Chunk;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotChunk;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.plotsquared.sponge.util.SpongeUtil;
public class SlowChunk extends PlotChunk<Chunk> {
public PlotBlock[][] result = new PlotBlock[16][];
public int[][] biomes;
private PlotBlock lastBlock;
public SlowChunk(ChunkWrapper chunk) {
super(chunk);
}
@Override
public Chunk getChunkAbs() {
ChunkWrapper loc = getChunkWrapper();
return SpongeUtil.getWorld(loc.world).getChunk(loc.x << 4, 0, loc.z << 4).get();
}
@Override
public void setBiome(int x, int z, int biome) {
if (biomes == null) {
biomes = new int[16][16];
}
biomes[x][z] = biome;
}
@Override
public void setBlock(int x, int y, int z, int id, byte data) {
if (result[y >> 4] == null) {
result[y >> 4] = new PlotBlock[4096];
}
if (id == lastBlock.id && data == lastBlock.data) {
result[MainUtil.CACHE_I[x][y][z]][MainUtil.CACHE_J[x][y][z]] = lastBlock;
} else {
result[MainUtil.CACHE_I[x][y][z]][MainUtil.CACHE_J[x][y][z]] = new PlotBlock((short) id, data);
}
}
@Override
public PlotChunk clone() {
SlowChunk toReturn = new SlowChunk(getChunkWrapper());
for (int i = 0; i < result.length; i++) {
PlotBlock[] matrix = result[i];
if (matrix != null) {
toReturn.result[i] = new PlotBlock[matrix.length];
System.arraycopy(matrix, 0, toReturn.result[i], 0, matrix.length);
}
}
return toReturn;
}
@Override
public PlotChunk shallowClone() {
SlowChunk toReturn = new SlowChunk(getChunkWrapper());
toReturn.result = result;
return toReturn;
}
}

View File

@ -0,0 +1,175 @@
package com.plotsquared.sponge.util.block;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.world.Chunk;
import com.flowpowered.math.vector.Vector3i;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotChunk;
import com.intellectualcrafters.plot.util.PlotQueue;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.plotsquared.sponge.util.SpongeUtil;
public class SlowQueue implements PlotQueue<Chunk> {
private final ConcurrentHashMap<ChunkWrapper, PlotChunk<Chunk>> blocks = new ConcurrentHashMap<>();
@Override
public boolean setBlock(String world, int x, int y, int z, short id, byte data) {
if (y > 255 || y < 0) {
return false;
}
final ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(world, x >> 4, z >> 4);
x = x & 15;
z = z & 15;
PlotChunk<Chunk> result = blocks.get(wrap);
if (result == null) {
result = getChunk(wrap);
result.setBlock(x, y, z, id, data);
final PlotChunk<Chunk> previous = blocks.put(wrap, result);
if (previous == null) {
return true;
}
blocks.put(wrap, previous);
result = previous;
}
result.setBlock(x, y, z, id, data);
return true;
}
@Override
public void setChunk(PlotChunk<Chunk> chunk) {
blocks.put(chunk.getChunkWrapper(), chunk);
}
@Override
public PlotChunk<Chunk> next() {
if (!PS.get().isMainThread(Thread.currentThread())) {
throw new IllegalStateException("Must be called from main thread!");
}
try {
if (blocks.isEmpty()) {
return null;
}
final Iterator<Entry<ChunkWrapper, PlotChunk<Chunk>>> iter = blocks.entrySet().iterator();
final PlotChunk<Chunk> toReturn = iter.next().getValue();
if (SetQueue.IMP.isWaiting()) {
return null;
}
iter.remove();
execute(toReturn);
fixLighting(toReturn, true);
return toReturn;
} catch (final Throwable e) {
e.printStackTrace();
return null;
}
}
@Override
public PlotChunk<Chunk> next(ChunkWrapper wrap, boolean fixLighting) {
if (!PS.get().isMainThread(Thread.currentThread())) {
throw new IllegalStateException("Must be called from main thread!");
}
try {
if (blocks.isEmpty()) {
return null;
}
final PlotChunk<Chunk> toReturn = blocks.remove(wrap);
if (toReturn == null) {
return null;
}
execute(toReturn);
fixLighting(toReturn, fixLighting);
return toReturn;
} catch (final Throwable e) {
e.printStackTrace();
return null;
}
}
@Override
public void clear() {
blocks.clear();
}
/**
* This should be overriden by any specialized queues
* @param pc
*/
public void execute(PlotChunk<Chunk> pc) {
SlowChunk sc = (SlowChunk) pc;
Chunk chunk = pc.getChunk();
chunk.loadChunk(true);
Vector3i min = chunk.getBlockMin();
int bx = min.getX();
int bz = min.getZ();
for (int i = 0; i < sc.result.length; i++) {
PlotBlock[] result2 = sc.result[i];
if (result2 == null) {
continue;
}
for (int j = 0; j < 4096; j++) {
final int x = MainUtil.x_loc[i][j];
final int y = MainUtil.y_loc[i][j];
final int z = MainUtil.z_loc[i][j];
PlotBlock newBlock = result2[j];
BlockState state = SpongeUtil.getBlockState(newBlock.id, newBlock.data);
chunk.setBlock(bx + x, y, bz + z, state, false);
}
}
int[][] biomes = sc.biomes;
if (biomes != null) {
for (int x = 0; x < 16; x++) {
int[] array = biomes[x];
if (array == null) {
continue;
}
for (int z = 0; z < 16; z++) {
int biome = array[z];
if (biome == 0) {
continue;
}
chunk.setBiome(bx + x, bz + z, SpongeUtil.getBiome(biome));
}
}
}
}
/**
* This should be overriden by any specialized queues
* @param wrap
*/
@Override
public PlotChunk<Chunk> getChunk(ChunkWrapper wrap) {
return new SlowChunk(wrap);
}
/**
* This should be overriden by any specialized queues
* @param fixAll
*/
@Override
public boolean fixLighting(PlotChunk<Chunk> chunk, boolean fixAll) {
// Do nothing
return true;
}
/**
* This should be overriden by any specialized queues
* @param locs
*/
@Override
public void sendChunk(String world, Collection<ChunkLoc> locs) {
// Do nothing
}
}