Fixing some more things

This commit is contained in:
boy0001
2015-07-31 00:25:16 +10:00
parent bfa877e607
commit e1dad77d8f
264 changed files with 6920 additions and 2146 deletions

View File

@ -1,158 +0,0 @@
package com.plotsquared.sponge;
import com.flowpowered.math.vector.Vector3i;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockTypes;
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.GeneratorPopulator;
public class PlotGen implements GeneratorPopulator {
public String worldname;
public long seed;
public final int PLOT_HEIGHT = 64; // Plot height of 64
public final int PLOT_WIDTH = 42; // Plot width of 42
public final int ROAD_WIDTH = 7; // Road width of 7
public final BlockState ROAD_BLOCK = BlockTypes.QUARTZ_BLOCK.getDefaultState(); // Quartz
public final BlockState MAIN_BLOCK = BlockTypes.STONE.getDefaultState(); // Stone
public final BlockState WALL_BLOCK = BlockTypes.BEDROCK.getDefaultState(); // Bedrock
public final BlockState BORDER_BLOCK = BlockTypes.STONE_SLAB.getDefaultState(); // Stone slab
public final BlockState[] FLOOR_BLOCK = new BlockState[] {BlockTypes.GRASS.getDefaultState(), BlockTypes.SPONGE.getDefaultState()}; // Grass and sponge
public final int total_width;
public final int road_width_lower;
public final int road_width_upper;
/**
* I'm using my PseudoRandom class as it's more efficient and we don't need secure randomness
*/
public final PseudoRandom RANDOM = new PseudoRandom();
private SpongeMain main;
public PlotGen(SpongeMain main, String worldname, long seed) {
this.main = main;
this.worldname = worldname;
this.seed = seed;
total_width = PLOT_WIDTH + ROAD_WIDTH;
// Calculating the bottom and top road portions (this is for a PlotSquared compatible generator, but you can have any offset you want)
if ((ROAD_WIDTH % 2) == 0) {
road_width_lower = ROAD_WIDTH / 2 - 1;
} else {
road_width_lower = ROAD_WIDTH / 2;
}
road_width_upper = road_width_lower + PLOT_WIDTH + 1;
main.log("LOADED GEN FOR: " + worldname);
}
/**
* This simple pairing function is used for the seed for each chunk,
* - This is useful if you want generation to appear random, but be the same each time
* - You could also use a simple hash function like `return x + y * 31` - but this looks fancier
* @param x
* @param y
* @return
*/
public int pair(int x, int y) {
long hash;
if (x >= 0) {
if (y >= 0) {
hash = (x * x) + (3 * x) + (2 * x * y) + y + (y * y) + 2;
} else {
final int y1 = -y;
hash = (x * x) + (3 * x) + (2 * x * y1) + y1 + (y1 * y1) + 1;
}
} else {
final int x1 = -x;
if (y >= 0) {
hash = -((x1 * x1) + (3 * x1) + (2 * x1 * y) + y + (y * y));
} else {
final int y1 = -y;
hash = -((x1 * x1) + (3 * x1) + (2 * x1 * y1) + y1 + (y1 * y1) + 1);
}
}
return (int) (hash % Integer.MAX_VALUE);
}
@Override
public void populate(World world, MutableBlockVolume buffer, ImmutableBiomeArea biomeBase) {
try {
Vector3i min = buffer.getBlockMin();
int X = min.getX();
int Z = min.getZ();
int cx = X >> 4;
int cz = Z >> 4;
main.log("POPULATING " + worldname + " | " + cx + "," + cz);
// If you have any random elements to your generation, you will want to set the state of the random class
RANDOM.state = pair(cx, cz);
// TODO set bedrock
// We want all plots to be the same
// To do this we will need to reduce the coordinates to the same base location
// To get the world coord from a chunk coord we multiply by 16 `cx << 4`
// Then we find the remainder of that `(cx << 4) % total_width`
// We don't want negative numbers though so add the `total_width` if the remainder is less than 0
// We have to do this as the plot size will not necessarily have to be a multiple of 16, and so it won't always align to the chunk
// If the total width is a multiple of 16, you can in fact make some neat optimizations, see PlotSquaredMG source for more info
int bx = (cx << 4) % total_width + (cx < 0 ? total_width : 0);
int bz = (cz << 4) % total_width + (cz < 0 ? total_width : 0);
// This is our main loop where we go over all the columns in the chunk and set the blocks
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
// Getting the reduced coordinate
int xx = (x + bx);
int zz = (z + bz);
// If it's greater than the total width, we need to reduce it
// Although we reduced the chunk coordinates before, that only means the base coordinate of the chunk is reduced
// The top coordinate could still be outside our desired range
if (xx >= total_width) xx -= total_width;
if (zz >= total_width) zz -= total_width;
// ROAD
if (xx < road_width_lower || zz < road_width_lower || xx > road_width_upper || zz > road_width_upper) {
for (int y = 0; y < PLOT_HEIGHT; y++) setBlock(buffer, X + x, y, Z + z, ROAD_BLOCK);
}
// WALL
else if (xx == road_width_lower || zz == road_width_lower || xx == road_width_upper || zz == road_width_upper) {
// Set the wall block
for (int y = 0; y < PLOT_HEIGHT; y++) setBlock(buffer, X + x, y, Z + z, WALL_BLOCK);
// Set the border block (on top of the wall)
setBlock(buffer, X + x, PLOT_HEIGHT, Z + z, BORDER_BLOCK);
}
// PLOT
else {
// Set the main plot block
for (int y = 0; y < PLOT_HEIGHT - 1; y++) setBlock(buffer, X + x, y, Z + z, MAIN_BLOCK);
// Set the plot floor
setBlock(buffer, X + x, PLOT_HEIGHT - 1, Z + z, FLOOR_BLOCK);
}
}
}
main.log("SUCCESS " + worldname + " | " + cx + "," + cz);
}
catch (Exception e) {
// Normally if something goes wrong in your code it will fail silently with world generators
// Having this try/catch will help recover the exception
e.printStackTrace();
}
}
public void setBlock(MutableBlockVolume buffer, int x, int y, int z, BlockState...states) {
if (states.length == 1) {
setBlock(buffer, x, y, z, states[0]);
}
setBlock(buffer, x, y, z, states[RANDOM.random(states.length)]);
}
public void setBlock(MutableBlockVolume buffer, int x, int y, int z, BlockState state) {
buffer.setBlock(x, y, z, state);
}
}

View File

@ -1,26 +0,0 @@
package com.plotsquared.sponge;
public class PseudoRandom {
public long state = 1;
public long nextLong() {
final long a = state;
state = xorShift64(a);
return a;
}
public long xorShift64(long a) {
a ^= (a << 21);
a ^= (a >>> 35);
a ^= (a << 4);
return a;
}
public int random(final int n) {
if (n == 1) {
return 0;
}
final long r = ((nextLong() >>> 32) * n) >> 32;
return (int) r;
}
}

View File

@ -0,0 +1,128 @@
package com.plotsquared.sponge;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.storage.ChunkDataStream;
import org.spongepowered.api.world.storage.WorldStorage;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.SetBlockQueue.ChunkWrapper;
import com.plotsquared.sponge.util.SpongeUtil;
public class SpongeChunkManager extends ChunkManager {
@Override
public void setChunk(ChunkWrapper loc, PlotBlock[][] result) {
// TODO Auto-generated method stub
}
@Override
public int[] countEntities(Plot plot) {
// TODO Auto-generated method stub
return new int[5];
}
@Override
public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
World worldObj = SpongeUtil.getWorld(world);
return worldObj.loadChunk(loc.x << 4, 0, loc.z << 4, force).isPresent();
}
@Override
public boolean unloadChunk(String world, ChunkLoc loc, boolean save, boolean safe) {
World worldObj = SpongeUtil.getWorld(world);
Optional<Chunk> chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4);
if (chunk.isPresent()) {
return worldObj.unloadChunk(chunk.get());
}
return false;
}
@Override
public List<ChunkLoc> getChunkChunks(String world) {
ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
World worldObj = SpongeUtil.getWorld(world);
ChunkDataStream storage = worldObj.getWorldStorage().getGeneratedChunks();
while (storage.hasNext()) {
DataContainer data = storage.next();
// TODO get chunk from DataContainer
}
return chunks;
}
@Override
public void regenerateChunk(String world, ChunkLoc loc) {
World worldObj = SpongeUtil.getWorld(world);
Optional<Chunk> chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4);
if (chunk.isPresent()) {
// TODO regenerate chunk
}
}
@Override
public void deleteRegionFile(String world, ChunkLoc loc) {
// TODO Auto-generated method stub
}
@Override
public void deleteRegionFiles(String world, List<ChunkLoc> chunks) {
// TODO Auto-generated method stub
}
@Override
public Plot hasPlot(String world, ChunkLoc chunk) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean copyRegion(Location pos1, Location pos2, Location newPos, Runnable whenDone) {
// TODO Auto-generated method stub
TaskManager.runTask(whenDone);
return false;
}
@Override
public boolean regenerateRegion(Location pos1, Location pos2, Runnable whenDone) {
// TODO Auto-generated method stub
TaskManager.runTask(whenDone);
return false;
}
@Override
public void clearAllEntities(Plot plot) {
// TODO Auto-generated method stub
}
@Override
public void swap(String world, PlotId id, PlotId plotid) {
// TODO Auto-generated method stub
}
@Override
public void swap(String worldname, Location bot1, Location top1, Location bot2, Location top2) {
// TODO Auto-generated method stub
}
}

View File

@ -1,65 +0,0 @@
package com.plotsquared.sponge;
import com.intellectualcrafters.plot.generator.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject;
import org.spongepowered.api.world.gen.WorldGenerator;
public class SpongeGeneratorWrapper extends PlotGenerator<WorldGenerator>{
public SpongeGeneratorWrapper(String world, WorldGenerator generator) {
super(world, generator);
// TODO Auto-generated constructor stub
}
@Override
public void initialize(PlotWorld plotworld) {
// TODO Auto-generated method stub
}
@Override
public void augment(PlotCluster cluster, PlotWorld plotworld) {
// TODO Auto-generated method stub
}
@Override
public void setGenerator(String generator) {
// TODO Auto-generated method stub
}
@Override
public PlotWorld getNewPlotWorld(String world) {
// TODO Auto-generated method stub
return null;
}
@Override
public PlotManager getPlotManager() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isFull() {
// TODO Auto-generated method stub
return false;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void processSetup(SetupObject object) {
// TODO Auto-generated method stub
}
}

View File

@ -1,24 +1,29 @@
package com.plotsquared.sponge;
import com.google.inject.Inject;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.IPlotMain;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.listener.APlotListener;
import java.io.File;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.spongepowered.api.CatalogType;
import org.spongepowered.api.Game;
import org.spongepowered.api.GameRegistry;
import org.spongepowered.api.MinecraftVersion;
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.data.manipulator.block.StoneData;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.entity.player.gamemode.GameModes;
import org.spongepowered.api.event.EventHandler;
import org.spongepowered.api.event.Subscribe;
import org.spongepowered.api.event.entity.player.PlayerChatEvent;
import org.spongepowered.api.event.state.PreInitializationEvent;
@ -26,13 +31,56 @@ import org.spongepowered.api.event.state.ServerAboutToStartEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.service.profile.GameProfileResolver;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.Texts;
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.gen.WorldGeneratorModifier;
import java.io.File;
import java.util.Collection;
import java.util.UUID;
import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.IPlotMain;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ConsoleColors;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.sponge.generator.SpongeBasicGen;
import com.plotsquared.sponge.generator.SpongeGeneratorWrapper;
import com.plotsquared.sponge.generator.WorldModify;
import com.plotsquared.sponge.listener.MainListener;
import com.plotsquared.sponge.util.KillRoadMobs;
import com.plotsquared.sponge.util.SpongeBlockManager;
import com.plotsquared.sponge.util.SpongeCommand;
import com.plotsquared.sponge.util.SpongeEventUtil;
import com.plotsquared.sponge.util.SpongeInventoryUtil;
import com.plotsquared.sponge.util.SpongeMetrics;
import com.plotsquared.sponge.util.SpongeTaskManager;
import com.plotsquared.sponge.util.SpongeUtil;
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper;
import com.plotsquared.sponge.uuid.SpongeUUIDHandler;
/**
* Created by robin on 01/11/2014
@ -70,7 +118,68 @@ public class SpongeMain implements IPlotMain, PluginContainer {
}
public Object getPlugin() {
return this.plugin;
return plugin;
}
public Text getText(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(Locale l, Object... args) {
return m;
}
@Override
public String get(Locale l) {
return m;
}
};
}
};
}
private PlotBlock NULL_BLOCK = new PlotBlock((short) 0, (byte) 0);
private BlockState[][] blockMap;
private Map<BlockState, PlotBlock> blockMapReverse;
public BlockState getBlockState(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(int id) {
return blockMap[id][0];
}
public Collection<BlockState> getAllStates() {
return this.blockMapReverse.keySet();
}
public PlotBlock getPlotBlock(BlockState state) {
PlotBlock val = blockMapReverse.get(state);
if (val == null) {
return NULL_BLOCK;
}
return val;
}
/////////
@ -114,43 +223,159 @@ public class SpongeMain implements IPlotMain, PluginContainer {
log("INIT");
THIS = this;
// resolver
//
resolver = game.getServiceManager().provide(GameProfileResolver.class).get();
plugin = game.getPluginManager().getPlugin("PlotSquared").get().getInstance();
log("PLUGIN IS THIS: " + (plugin == this));
plugin = this;
server = game.getServer();
//
PS.instance = new PS(this);
// Set the generators for each world...
server = game.getServer();
Collection<World> worlds = server.getWorlds();
if (worlds.size() > 0) {
log("INJECTING WORLDS!!!!!!!");
for (World world : server.getWorlds()) {
log("INJECTING WORLD: " + world.getName());
world.setWorldGenerator(new SpongePlotGenerator(world.getName()));
}
}
// TODO Until P^2 has json chat stuff for sponge, disable this
Settings.FANCY_CHAT = false;
// done
registerBlocks();
ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
if (worldSection != null) {
for (String world : worldSection.getKeys(false)) {
this.modify = new WorldModify(this);
SpongeBasicGen generator = new SpongeBasicGen(world);
PS.get().loadWorld(world, new SpongeGeneratorWrapper(world, generator));
this.modify = new WorldModify(generator);
Game game = event.getGame();
game.getRegistry().registerWorldGeneratorModifier(modify);
game.getRegistry().getWorldBuilder()
Optional<World> builder = game.getRegistry().getWorldBuilder()
.name(world)
.enabled(true)
.loadsOnStartup(true)
.keepsSpawnLoaded(true)
.dimensionType(DimensionTypes.OVERWORLD)
.generator(GeneratorTypes.DEBUG)
.generator(GeneratorTypes.FLAT)
.gameMode(GameModes.CREATIVE)
.usesMapFeatures(false)
.generatorModifiers(modify)
.build();
World worldObj = builder.get();
}
}
}
public void registerBlock(PlotBlock block, BlockState state) {
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(BlockState state) {
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);
}
PlotBlock block = new PlotBlock((short) 0, data);
registerBlock(block, state);
return block;
}
public void registerBlocks() {
blockMap = new BlockState[256][];
blockMapReverse = new ConcurrentHashMap<BlockState, PlotBlock>();
HashMap<String, BlockState> states = new HashMap<>();
PS.get().copyFile("ids.txt", "config");
PS.get().copyFile("data.txt", "config");
try {
File id_file = new File(getDirectory(), "config" + File.separator + "ids.txt");
List<String> id_lines = Files.readAllLines(id_file.toPath(), StandardCharsets.UTF_8);
File data_file = new File(getDirectory(), "config" + File.separator + "data.txt");
List<String> data_lines = Files.readAllLines(data_file.toPath(), StandardCharsets.UTF_8);
Field[] fields = BlockTypes.class.getDeclaredFields();
for (Field field : fields) {
BlockType type = (BlockType) field.get(null);
BlockState state = type.getDefaultState();
if (state != null) {
try {
states.put(type.getId() + ":" + 0, state);
}
catch (Exception e) {}
}
}
String packaze = "org.spongepowered.api.data.type.";
for (int i = 0; i < data_lines.size(); i++) {
String classname = packaze + data_lines.get(i).trim();
try {
Class<?> clazz = Class.forName(classname);
fields = clazz.getDeclaredFields();
for (Field field : fields) {
CatalogType type = (CatalogType) field.get(null);
String minecraft_id = type.getId();
BlockState state = states.get(minecraft_id + ":" + 0);
if (state == null) {
continue;
}
state.getManipulator(StoneData.class);
}
}
catch (Throwable e) {}
}
PlotBlock block = null;
for (int i = 0; i < id_lines.size(); i++) {
String line = id_lines.get(i).trim();
switch(i%3) {
case 0: {
block = Configuration.BLOCK.parseString(line);
break;
}
case 1: {
break;
}
case 2: {
String minecraft_id = line;
BlockState state = states.remove(minecraft_id + ":" + block.data);
if (state == null) {
continue;
}
registerBlock(block, state);
break;
}
}
}
for (Entry<String, BlockState> state : states.entrySet()) {
log("REGISTERING: " + registerBlock(state.getValue()) + " | " + state.getValue().getType());
}
}
catch (Exception e) {
e.printStackTrace();
}
}
@Subscribe
public void onPlayerChat(PlayerChatEvent event) {
// This is how events sort of work?
@ -160,8 +385,15 @@ public class SpongeMain implements IPlotMain, PluginContainer {
@Override
public void log(String message) {
message = ConsoleColors.fromString(message);
logger.info(message);
message = C.format(message, C.replacements);
if (!Settings.CONSOLE_COLOR) {
message = message.replaceAll('\u00a7' + "[a-z|0-9]", "");
}
if (server == null || server.getConsole() == null) {
logger.info(message);
return;
}
server.getConsole().sendMessage(Texts.of(message));
}
@Override
@ -191,6 +423,66 @@ public class SpongeMain implements IPlotMain, PluginContainer {
String[] split = version.split("\\.");
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };
}
@Override
public InventoryUtil initInventoryUtil() {
return new SpongeInventoryUtil();
}
@Override
public SpongeGeneratorWrapper getGenerator(String world, String name) {
if (name == null) {
return new SpongeGeneratorWrapper(world, null);
}
if (name.equals("PlotSquared")) {
return new SpongeGeneratorWrapper(world, null);
}
else {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
}
@Override
public EconHandler getEconomyHandler() {
// TODO Auto-generated method stub
// Nothing like Vault exists yet
PS.log("getEconomyHandler NOT IMPLEMENTED YET");
return null;
}
@Override
public BlockManager initBlockManager() {
return new SpongeBlockManager();
}
@Override
public EventUtil initEventUtil() {
return new SpongeEventUtil();
}
@Override
public ChunkManager initChunkManager() {
return new SpongeChunkManager();
}
@Override
public SetupUtils initSetupUtils() {
// TODO Auto-generated method stub
return null;
}
@Override
public HybridUtils initHybridUtils() {
// TODO Auto-generated method stub
return null;
}
@Override
public SchematicHandler initSchematicHandler() {
// TODO Auto-generated method stub
return null;
}
@Override
public TaskManager getTaskManager() {
@ -199,20 +491,17 @@ public class SpongeMain implements IPlotMain, PluginContainer {
@Override
public void runEntityTask() {
// TODO Auto-generated method stub
log("runEntityTask is not implemented!");
new KillRoadMobs().run();
}
@Override
public void registerCommands() {
// TODO Auto-generated method stub
log("registerCommands is not implemented!");
getGame().getCommandDispatcher().register(plugin, new SpongeCommand(), "plots", "p", "plot", "ps", "plotsquared", "p2");
}
@Override
public void registerPlayerEvents() {
// TODO Auto-generated method stub
log("registerPlayerEvents is not implemented!");
game.getEventManager().register(this, new MainListener());
}
@Override
@ -245,42 +534,6 @@ public class SpongeMain implements IPlotMain, PluginContainer {
log("registerTNTListener is not implemented!");
}
@Override
public EconHandler getEconomyHandler() {
// TODO Auto-generated method stub
return null;
}
@Override
public BlockManager initBlockManager() {
// TODO Auto-generated method stub
return null;
}
@Override
public EventUtil initEventUtil() {
// TODO Auto-generated method stub
return null;
}
@Override
public ChunkManager initChunkManager() {
// TODO Auto-generated method stub
return null;
}
@Override
public SetupUtils initSetupUtils() {
// TODO Auto-generated method stub
return null;
}
@Override
public HybridUtils initHybridUtils() {
// TODO Auto-generated method stub
return null;
}
@Override
public UUIDHandlerImplementation initUUIDHandler() {
UUIDWrapper wrapper;
@ -293,57 +546,33 @@ public class SpongeMain implements IPlotMain, PluginContainer {
return new SpongeUUIDHandler(wrapper);
}
@Override
public InventoryUtil initInventoryUtil() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean initPlotMeConverter() {
// TODO Auto-generated method stub
PS.log("initPlotMeConverter NOT IMPLEMENTED YET");
return false;
}
@Override
public void unregister(PlotPlayer player) {
// TODO Auto-generated method stub
}
@Override
public SpongeGeneratorWrapper getGenerator(String world, String name) {
// TODO Auto-generated method stub
return null;
}
@Override
public APlotListener initPlotListener() {
// TODO Auto-generated method stub
return null;
SpongeUtil.removePlayer(player.getName());
}
@Override
public void registerChunkProcessor() {
// TODO Auto-generated method stub
PS.log("registerChunkProcessor NOT IMPLEMENTED YET");
}
@Override
public void registerWorldEvents() {
// TODO Auto-generated method stub
}
@Override
public PlayerManager initPlayerManager() {
// TODO Auto-generated method stub
return null;
PS.log("registerWorldEvents NOT IMPLEMENTED YET");
}
@Override
public String getServerName() {
// TODO FIXME
// TODO FIXME
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@ -360,7 +589,11 @@ public class SpongeMain implements IPlotMain, PluginContainer {
@Override
public void setGenerator(String world) {
// TODO Auto-generated method stub
// THIS IS DONE DURING STARTUP ALREADY
}
@Override
public AbstractTitle initTitleManager() {
return new SpongeTitleManager();
}
}

View File

@ -4,13 +4,17 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.entity.player.gamemode.GameMode;
import org.spongepowered.api.entity.player.gamemode.GameModes;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.text.Texts;
import org.spongepowered.api.text.chat.ChatTypes;
import org.spongepowered.api.text.title.Title;
import org.spongepowered.api.world.World;
import com.flowpowered.math.vector.Vector3d;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
@ -18,7 +22,10 @@ import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.sponge.util.SpongeUtil;
public class SpongePlayer implements PlotPlayer {
@ -97,12 +104,13 @@ public class SpongePlayer implements PlotPlayer {
@Override
public void teleport(Location loc) {
String world = player.getWorld().getName();
if (world != loc.getWorld()) {
player.transferToWorld(world, new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
if (!world.equals(loc.getWorld())) {
player.transferToWorld(loc.getWorld(), new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
}
else {
org.spongepowered.api.world.Location current = player.getLocation();
player.setLocationSafely(current.setPosition(new Vector3d(loc.getX(), loc.getY(), loc.getZ())));
current = current.setPosition(new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
player.setLocation(current);
}
}
@ -188,13 +196,10 @@ public class SpongePlayer implements PlotPlayer {
@Override
public boolean getAttribute(String key) {
key = "plotsquared_user_attributes." + key;
Permission perm = Bukkit.getServer().getPluginManager().getPermission(key);
if (perm == null) {
perm = new Permission(key, PermissionDefault.FALSE);
Bukkit.getServer().getPluginManager().addPermission(perm);
Bukkit.getServer().getPluginManager().recalculatePermissionDefaults(perm);
}
return player.hasPermission(key);
// TODO register attributes
return false;
}
@Override
@ -202,4 +207,71 @@ public class SpongePlayer implements PlotPlayer {
key = "plotsquared_user_attributes." + key;
EconHandler.manager.setPermission(this, key, false);
}
@Override
public void setWeather(PlotWeather weather) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@Override
public PlotGamemode getGamemode() {
// TODO Auto-generated method stub
GameMode gamemode = player.getGameModeData().getValue();
if (gamemode == GameModes.ADVENTURE) {
return PlotGamemode.ADVENTURE;
}
if (gamemode == GameModes.CREATIVE) {
return PlotGamemode.CREATIVE;
}
if (gamemode == GameModes.SPECTATOR) {
return PlotGamemode.SPECTATOR;
}
if (gamemode == GameModes.SURVIVAL) {
return PlotGamemode.SURVIVAL;
}
throw new UnsupportedOperationException("INVALID GAMEMODE");
}
@Override
public void setGamemode(PlotGamemode gamemode) {
// TODO Auto-generated method stub
switch (gamemode) {
case ADVENTURE:
player.getGameModeData().setGameMode(GameModes.ADVENTURE);
return;
case CREATIVE:
player.getGameModeData().setGameMode(GameModes.CREATIVE);
return;
case SPECTATOR:
player.getGameModeData().setGameMode(GameModes.SPECTATOR);
return;
case SURVIVAL:
player.getGameModeData().setGameMode(GameModes.SURVIVAL);
return;
}
}
@Override
public void setTime(long time) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@Override
public void setFlight(boolean fly) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@Override
public void playMusic(Location loc, int id) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@Override
public void kick(String message) {
player.kick(SpongeMain.THIS.getText(message));
}
}

View File

@ -1,50 +0,0 @@
package com.plotsquared.sponge;
import org.spongepowered.api.world.gen.BiomeGenerator;
import org.spongepowered.api.world.gen.GeneratorPopulator;
import org.spongepowered.api.world.gen.Populator;
import org.spongepowered.api.world.gen.WorldGenerator;
import java.util.List;
public class SpongePlotGenerator implements WorldGenerator {
public SpongePlotGenerator(String world) {
}
@Override
public GeneratorPopulator getBaseGeneratorPopulator() {
// TODO Auto-generated method stub
return null;
}
@Override
public BiomeGenerator getBiomeGenerator() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<GeneratorPopulator> getGeneratorPopulators() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Populator> getPopulators() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setBaseGeneratorPopulator(GeneratorPopulator arg0) {
// TODO Auto-generated method stub
}
@Override
public void setBiomeGenerator(BiomeGenerator arg0) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,15 @@
package com.plotsquared.sponge;
import org.spongepowered.api.text.title.Title;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.AbstractTitle;
public class SpongeTitleManager extends AbstractTitle {
@Override
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
((SpongePlayer) player).player.sendTitle(new Title(SpongeMain.THIS.getText(head), SpongeMain.THIS.getText(sub), in * 20, delay * 20, out * 20, false, false));
}
}

View File

@ -1,28 +0,0 @@
package com.plotsquared.sponge;
import org.spongepowered.api.entity.Entity;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.util.MathMan;
public class SpongeUtil {
public static Location getLocation(Entity player) {
String world = player.getWorld().getName();
org.spongepowered.api.world.Location loc = player.getLocation();
Vector3i pos = loc.getBlockPosition();
return new Location(world, pos.getX(), pos.getY(), pos.getZ());
}
public static Location getLocationFull(Entity player) {
String world = player.getWorld().getName();
Vector3d rot = player.getRotation();
float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ());
org.spongepowered.api.world.Location loc = player.getLocation();
Vector3i pos = loc.getBlockPosition();
return new Location(world, pos.getX(), pos.getY(), pos.getZ(), pitchYaw[1], pitchYaw[0]);
}
}

View File

@ -1,29 +0,0 @@
package com.plotsquared.sponge;
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;
public class WorldModify implements WorldGeneratorModifier {
private SpongeMain main;
public WorldModify(SpongeMain main) {
this.main = main;
}
@Override
public void modifyWorldGenerator(WorldCreationSettings world, DataContainer settings, WorldGenerator worldGenerator) {
worldGenerator.setBaseGeneratorPopulator(new PlotGen(main, world.getWorldName(), world.getSeed()));
}
@Override
public String getName() {
return "PlotSquared";
}
@Override
public String getId() {
return "PlotSquared";
}
}

View File

@ -0,0 +1,47 @@
package com.plotsquared.sponge.events;
import org.spongepowered.api.event.AbstractEvent;
import org.spongepowered.api.event.Cancellable;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.PlotCluster;
public class ClusterFlagRemoveEvent extends AbstractEvent implements Cancellable {
private final PlotCluster cluster;
private final Flag flag;
private boolean cancelled;
public ClusterFlagRemoveEvent(final Flag flag, final PlotCluster cluster) {
this.cluster = cluster;
this.flag = flag;
}
/**
* Get the cluster involved
*
* @return PlotCluster
*/
public PlotCluster getCluster() {
return this.cluster;
}
/**
* Get the flag involved
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View File

@ -0,0 +1,51 @@
package com.plotsquared.sponge.events;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.event.Cancellable;
import com.intellectualcrafters.plot.object.Plot;
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
private final Plot plot;
private final boolean auto;
private boolean cancelled;
/**
* PlayerClaimPlotEvent: Called when a plot is claimed
*
* @param player Player that claimed the plot
* @param plot Plot that was claimed
*/
public PlayerClaimPlotEvent(final Player player, final Plot plot, final boolean auto) {
super(player);
this.plot = plot;
this.auto = auto;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* @return true if it was an automated claim, else false
*/
public boolean wasAuto() {
return this.auto;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View File

@ -0,0 +1,31 @@
package com.plotsquared.sponge.events;
import org.spongepowered.api.entity.player.Player;
import com.intellectualcrafters.plot.object.Plot;
public class PlayerEnterPlotEvent extends PlayerEvent {
private final Plot plot;
private boolean cancelled;
/**
* PlayerEnterPlotEvent: Called when a player leaves a plot
*
* @param player Player that entered the plot
* @param plot Plot that was entered
*/
public PlayerEnterPlotEvent(final Player player, final Plot plot) {
super(player);
this.plot = plot;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
}

View File

@ -0,0 +1,18 @@
package com.plotsquared.sponge.events;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.event.AbstractEvent;
public abstract class PlayerEvent extends AbstractEvent {
public final Player player;
public PlayerEvent(Player player) {
this.player = player;
}
public Player getPlayer() {
return this.player;
}
}

View File

@ -0,0 +1,31 @@
package com.plotsquared.sponge.events;
import org.spongepowered.api.entity.player.Player;
import com.intellectualcrafters.plot.object.Plot;
public class PlayerLeavePlotEvent extends PlayerEvent {
private final Plot plot;
private boolean cancelled;
/**
* PlayerLeavePlotEvent: Called when a player leaves a plot
*
* @param player Player that left the plot
* @param plot Plot that was left
*/
public PlayerLeavePlotEvent(final Player player, final Plot plot) {
super(player);
this.plot = plot;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
}

View File

@ -0,0 +1,56 @@
package com.plotsquared.sponge.events;
import java.util.UUID;
import org.spongepowered.api.entity.player.Player;
import com.intellectualcrafters.plot.object.Plot;
public class PlayerPlotDeniedEvent extends PlotEvent {
private final Player initiator;
private final boolean added;
private final UUID player;
/**
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a plot
*
* @param initiator Player that initiated the event
* @param plot Plot in which the event occurred
* @param player Player that was denied/un-denied
* @param added true of add to deny list, false if removed
*/
public PlayerPlotDeniedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
super(plot);
this.initiator = initiator;
this.added = added;
this.player = player;
}
/**
* If a user was added
*
* @return boolean
*/
public boolean wasAdded() {
return this.added;
}
/**
* The player added/removed
*
* @return UUID
*/
public UUID getPlayer() {
return this.player;
}
/**
* The player initiating the action
*
* @return Player
*/
public Player getInitiator() {
return this.initiator;
}
}

View File

@ -0,0 +1,56 @@
package com.plotsquared.sponge.events;
import java.util.UUID;
import org.spongepowered.api.entity.player.Player;
import com.intellectualcrafters.plot.object.Plot;
public class PlayerPlotHelperEvent extends PlotEvent {
private final Player initiator;
private final boolean added;
private final UUID player;
/**
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
*
* @param initiator Player that initiated the event
* @param plot Plot in which the event occurred
* @param player Player that was added/removed from the helper list
* @param added true of the player was added, false if the player was removed
*/
public PlayerPlotHelperEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
super(plot);
this.initiator = initiator;
this.added = added;
this.player = player;
}
/**
* If a user was added
*
* @return boolean
*/
public boolean wasAdded() {
return this.added;
}
/**
* The player added/removed
*
* @return UUID
*/
public UUID getPlayer() {
return this.player;
}
/**
* The player initiating the action
*
* @return Player
*/
public Player getInitiator() {
return this.initiator;
}
}

View File

@ -0,0 +1,56 @@
package com.plotsquared.sponge.events;
import java.util.UUID;
import org.spongepowered.api.entity.player.Player;
import com.intellectualcrafters.plot.object.Plot;
public class PlayerPlotTrustedEvent extends PlotEvent {
private final Player initiator;
private final boolean added;
private final UUID player;
/**
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
*
* @param initiator Player that initiated the event
* @param plot Plot in which the event occurred
* @param player Player that was added/removed from the trusted list
* @param added true of the player was added, false if the player was removed
*/
public PlayerPlotTrustedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
super(plot);
this.initiator = initiator;
this.added = added;
this.player = player;
}
/**
* If a user was added
*
* @return boolean
*/
public boolean wasAdded() {
return this.added;
}
/**
* The player added/removed
*
* @return UUID
*/
public UUID getPlayer() {
return this.player;
}
/**
* The player initiating the action
*
* @return Player
*/
public Player getInitiator() {
return this.initiator;
}
}

View File

@ -0,0 +1,55 @@
package com.plotsquared.sponge.events;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.event.Cancellable;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellable {
private final Location from;
private final Plot plot;
private boolean cancelled;
/**
* PlayerTeleportToPlotEvent: Called when a player teleports to a plot
*
* @param player That was teleported
* @param from Start location
* @param plot Plot to which the player was teleported
*/
public PlayerTeleportToPlotEvent(final Player player, final Location from, final Plot plot) {
super(player);
this.from = from;
this.plot = plot;
}
/**
* Get the from location
*
* @return Location
*/
public Location getFrom() {
return this.from;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View File

@ -0,0 +1,51 @@
package com.plotsquared.sponge.events;
import org.spongepowered.api.event.AbstractEvent;
import org.spongepowered.api.event.Cancellable;
import com.intellectualcrafters.plot.object.PlotId;
public class PlotClearEvent extends AbstractEvent implements Cancellable {
private final PlotId id;
private final String world;
private boolean cancelled;
/**
* PlotDeleteEvent: Called when a plot is cleared
*
* @param world The world in which the plot was cleared
* @param id The plot that was cleared
*/
public PlotClearEvent(final String world, final PlotId id) {
this.id = id;
this.world = world;
}
/**
* Get the PlotId
*
* @return PlotId
*/
public PlotId getPlotId() {
return this.id;
}
/**
* Get the world name
*
* @return String
*/
public String getWorld() {
return this.world;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View File

@ -0,0 +1,39 @@
package com.plotsquared.sponge.events;
import org.spongepowered.api.event.AbstractEvent;
import com.intellectualcrafters.plot.object.PlotId;
public class PlotDeleteEvent extends AbstractEvent {
private final PlotId id;
private final String world;
/**
* PlotDeleteEvent: Called when a plot is deleted
*
* @param world The world in which the plot was deleted
* @param id The ID of the plot that was deleted
*/
public PlotDeleteEvent(final String world, final PlotId id) {
this.id = id;
this.world = world;
}
/**
* Get the PlotId
*
* @return PlotId
*/
public PlotId getPlotId() {
return this.id;
}
/**
* Get the world name
*
* @return String
*/
public String getWorld() {
return this.world;
}
}

View File

@ -0,0 +1,19 @@
package com.plotsquared.sponge.events;
import org.spongepowered.api.event.AbstractEvent;
import com.intellectualcrafters.plot.object.Plot;
public abstract class PlotEvent extends AbstractEvent {
private final Plot plot;
public PlotEvent(final Plot plot) {
this.plot = plot;
}
public final Plot getPlot() {
return this.plot;
}
}

View File

@ -0,0 +1,41 @@
package com.plotsquared.sponge.events;
import org.spongepowered.api.event.Cancellable;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
private final Flag flag;
private boolean cancelled;
/**
* PlotFlagAddEvent: Called when a Flag is added to a plot
*
* @param flag Flag that was added
* @param plot Plot to which the flag was added
*/
public PlotFlagAddEvent(final Flag flag, final Plot plot) {
super(plot);
this.flag = flag;
}
/**
* Get the flag involved
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View File

@ -0,0 +1,41 @@
package com.plotsquared.sponge.events;
import org.spongepowered.api.event.Cancellable;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
private final Flag flag;
private boolean cancelled;
/**
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
*
* @param flag Flag that was removed
* @param plot Plot from which the flag was removed
*/
public PlotFlagRemoveEvent(final Flag flag, final Plot plot) {
super(plot);
this.flag = flag;
}
/**
* Get the flag involved
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View File

@ -0,0 +1,60 @@
package com.plotsquared.sponge.events;
import java.util.ArrayList;
import org.spongepowered.api.event.AbstractEvent;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.world.World;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
public class PlotMergeEvent extends AbstractEvent implements Cancellable {
private final ArrayList<PlotId> plots;
private boolean cancelled;
private Plot plot;
private World world;
/**
* PlotMergeEvent: Called when plots are merged
*
* @param world World in which the event occurred
* @param plot Plot that was merged
* @param plots A list of plots involved in the event
*/
public PlotMergeEvent(final World world, final Plot plot, final ArrayList<PlotId> plots) {
this.plots = plots;
}
/**
* Get the plots being added;
*
* @return Plot
*/
public ArrayList<PlotId> getPlots() {
return this.plots;
}
/**
* Get the main plot
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
public World getWorld() {
return this.world;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View File

@ -0,0 +1,28 @@
package com.plotsquared.sponge.events;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating;
public class PlotRateEvent extends PlotEvent {
private final PlotPlayer rater;
private Rating rating;
public PlotRateEvent(final PlotPlayer rater, final Rating rating, final Plot plot) {
super(plot);
this.rater = rater;
this.rating = rating;
}
public PlotPlayer getRater() {
return this.rater;
}
public void setRating(Rating rating) {
this.rating = rating;
}
public Rating getRating() {
return this.rating;
}
}

View File

@ -0,0 +1,49 @@
package com.plotsquared.sponge.events;
import java.util.ArrayList;
import org.spongepowered.api.event.AbstractEvent;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.world.World;
import com.intellectualcrafters.plot.object.PlotId;
public class PlotUnlinkEvent extends AbstractEvent implements Cancellable {
private final ArrayList<PlotId> plots;
private final World world;
private boolean cancelled;
/**
* Called when a mega-plot is unlinked.
*
* @param world World in which the event occurred
* @param plots Plots that are involved in the event
*/
public PlotUnlinkEvent(final World world, final ArrayList<PlotId> plots) {
this.plots = plots;
this.world = world;
}
/**
* Get the plots involved
*
* @return PlotId
*/
public ArrayList<PlotId> getPlots() {
return this.plots;
}
public World getWorld() {
return this.world;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View File

@ -0,0 +1,38 @@
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.PlotWorld;
public class SpongeBasicBiomeProvider implements BiomeGenerator {
private PlotWorld plotworld;
public SpongeBasicBiomeProvider(PlotWorld plotworld) {
this.plotworld = plotworld;
}
@Override
public void generateBiomes(MutableBiomeArea biomeBase) {
Vector2i min = biomeBase.getBiomeMin();
int bx = min.getX();
int bz = min.getY();
BiomeType biome = BiomeTypes.FOREST;
try {
biome = (BiomeType) BiomeTypes.class.getField(plotworld.PLOT_BIOME.toUpperCase()).get(null);
}
catch (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

@ -0,0 +1,135 @@
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.generator.HybridPlotManager;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.plotsquared.sponge.SpongeMain;
public class SpongeBasicGen extends SpongePlotGenerator {
public final BlockState ROAD_BLOCK = BlockTypes.QUARTZ_BLOCK.getDefaultState(); // Quartz
public final BlockState MAIN_BLOCK = BlockTypes.STONE.getDefaultState(); // Stone
public final BlockState WALL_BLOCK = BlockTypes.BEDROCK.getDefaultState(); // Bedrock
public final BlockState BORDER_BLOCK = BlockTypes.STONE_SLAB.getDefaultState(); // Stone slab
public final BlockState[] FLOOR_BLOCK = new BlockState[] {BlockTypes.GRASS.getDefaultState(), BlockTypes.SPONGE.getDefaultState(), BlockTypes.PLANKS.getDefaultState() }; // Grass and sponge
private static HybridPlotManager manager;
public HybridPlotWorld plotworld;
public SpongeBasicGen(String world) {
super(world);
}
/**
* Some generator specific variables (implementation dependent)
*
* TODO USE THESE
*
*/
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(PlotWorld plotworld) {
if (plotworld != null) {
this.plotworld = (HybridPlotWorld) plotworld;
}
this.plotsize = this.plotworld.PLOT_WIDTH;
this.pathsize = this.plotworld.ROAD_WIDTH;
this.size = this.pathsize + this.plotsize;
this.wallheight = this.plotworld.WALL_HEIGHT;
this.roadheight = this.plotworld.ROAD_HEIGHT;
this.plotheight = this.plotworld.PLOT_HEIGHT;
if (this.pathsize == 0) {
this.pathWidthLower = (short) -1;
this.pathWidthUpper = (short) (this.plotsize + 1);
}
else {
if ((this.pathsize % 2) == 0) {
this.pathWidthLower = (short) (Math.floor(this.pathsize / 2) - 1);
} else {
this.pathWidthLower = (short) (Math.floor(this.pathsize / 2));
}
this.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1);
}
this.roadblock = SpongeMain.THIS.getBlockState(this.plotworld.ROAD_BLOCK);
this.wallfilling = SpongeMain.THIS.getBlockState(this.plotworld.WALL_FILLING);
this.wall = SpongeMain.THIS.getBlockState(this.plotworld.WALL_BLOCK);
this.plotfloors = new BlockState[this.plotworld.TOP_BLOCK.length];
for (int i = 0; i < this.plotworld.TOP_BLOCK.length; i++) {
this.plotfloors[i] = SpongeMain.THIS.getBlockState(this.plotworld.TOP_BLOCK[i]);
}
this.filling = new BlockState[this.plotworld.MAIN_BLOCK.length];
for (int i = 0; i < this.plotworld.MAIN_BLOCK.length; i++) {
this.filling[i] = SpongeMain.THIS.getBlockState(this.plotworld.MAIN_BLOCK[i]);
}
if ((this.filling.length > 1) || (this.plotfloors.length > 1)) {
this.doState = true;
}
}
@Override
public PlotWorld getNewPlotWorld(String world) {
if (this.plotworld == null) {
this.plotworld = new HybridPlotWorld(world);
}
return this.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

@ -0,0 +1,99 @@
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.BlockManager;
import com.plotsquared.sponge.SpongeMain;
public class SpongeBasicPop extends SpongePlotPopulator<SpongeBasicGen> {
public SpongeBasicPop(SpongeBasicGen generator) {
super(generator);
}
@Override
public void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz) {
int sx = (short) ((this.X - generator.plotworld.ROAD_OFFSET_X) % generator.size);
int sz = (short) ((this.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.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);
for (final short y : blocks.keySet()) {
Byte data = datas.get(y);
setBlock(x, (short) (generator.plotheight + y), z, SpongeMain.THIS.getBlockState(new PlotBlock(blocks.get(y), data == null ? 0 : data)));
}
}
if (generator.plotworld.G_SCH_STATE != null) {
HashSet<PlotItem> states = generator.plotworld.G_SCH_STATE.get(loc);
if (states != null) {
for (PlotItem items : states) {
items.x = this.X + x;
items.z = this.Z + z;
BlockManager.manager.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.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.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);
for (final short y : blocks.keySet()) {
Byte data = datas.get(y);
setBlock(x, (short) (generator.plotheight + y), z, SpongeMain.THIS.getBlockState(new PlotBlock(blocks.get(y), data == null ? 0 : data)));
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,91 @@
package com.plotsquared.sponge.generator;
import org.spongepowered.api.world.gen.WorldGenerator;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject;
public class SpongeGeneratorWrapper extends PlotGenerator<WorldGenerator>{
public final boolean full;
public SpongeGeneratorWrapper(String world, WorldGenerator generator) {
super(world, generator);
full = (generator instanceof SpongePlotGenerator);
}
@Override
public void initialize(PlotWorld plotworld) {
if (generator instanceof SpongePlotGenerator) {
((SpongePlotGenerator) generator).init(plotworld);
}
}
@Override
public void augment(PlotCluster cluster, PlotWorld plotworld) {
if (generator instanceof SpongePlotGenerator) {
SpongePlotGenerator plotgen = (SpongePlotGenerator) generator;
if (cluster != null) {
// TODO Augment partial
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
else {
// TODO augment full
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
}
}
@Override
public void setGenerator(String gen_string) {
if (gen_string == null) {
generator = new SpongeBasicGen(world);
} else {
PlotGenerator<WorldGenerator> gen_wrapper = (PlotGenerator<WorldGenerator>) PS.get().IMP.getGenerator(world, gen_string);
if (gen_wrapper != null) {
generator = gen_wrapper.generator;
}
}
}
@Override
public PlotWorld getNewPlotWorld(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(SetupObject object) {
if (generator instanceof SpongePlotGenerator) {
((SpongePlotGenerator) generator).processSetup(object);
}
}
}

View File

@ -0,0 +1,91 @@
package com.plotsquared.sponge.generator;
import java.util.ArrayList;
import java.util.List;
import org.spongepowered.api.world.gen.BiomeGenerator;
import org.spongepowered.api.world.gen.GeneratorPopulator;
import org.spongepowered.api.world.gen.Populator;
import org.spongepowered.api.world.gen.WorldGenerator;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject;
public abstract class SpongePlotGenerator implements WorldGenerator {
public final String world;
public SpongePlotGenerator(String world) {
this.world = world;
}
@Override
public GeneratorPopulator getBaseGeneratorPopulator() {
return getGenerator();
}
@Override
public BiomeGenerator getBiomeGenerator() {
return getPlotBiomeProvider();
}
@Override
public List<GeneratorPopulator> getGeneratorPopulators() {
List<GeneratorPopulator> pops = new ArrayList<>();
pops.addAll(this.getPlotPopulators());
return pops;
}
@Override
public List<Populator> getPopulators() {
return new ArrayList<>();
}
@Override
public void setBaseGeneratorPopulator(GeneratorPopulator arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@Override
public void setBiomeGenerator(BiomeGenerator biomeGenerator) {
// TODO
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
public abstract SpongePlotPopulator getGenerator();
public abstract BiomeGenerator getPlotBiomeProvider();
public abstract List<SpongePlotPopulator> getPlotPopulators();
/**
* This is called when the generator is initialized.
* You don't need to do anything with it necessarily.
* @param plotworld
*/
public abstract void init(PlotWorld plotworld);
/**
* Return a new instance of the PlotWorld for a world
* @param world
* @return
*/
public abstract PlotWorld 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 PlotWorld configuration<br>
* Feel free to extend BukkitSetupUtils and customize world creation
* @param object
*/
public void processSetup(SetupObject object) {}
}

View File

@ -0,0 +1,97 @@
package com.plotsquared.sponge.generator;
import org.spongepowered.api.block.BlockState;
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.GeneratorPopulator;
import com.flowpowered.math.vector.Vector3i;
import com.intellectualcrafters.plot.PS;
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 GeneratorPopulator {
public int X;
public int Z;
public String worldname;
private World world;
private PseudoRandom random = new PseudoRandom();
private MutableBlockVolume buffer;
public final T generator;
public SpongePlotPopulator(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();
// }
public void populate(World world, MutableBlockVolume buffer, ImmutableBiomeArea biomeBase) {
try {
this.world = world;
this.worldname = world.getName();
this.buffer = buffer;
Vector3i min = buffer.getBlockMin();
this.X = min.getX();
this.Z = min.getZ();
int cx = X >> 4;
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 (Exception e) {
PS.debug("ERROR GENERATING CHUNK!");
e.printStackTrace();
}
};
public abstract void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, 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 id
* @param data
*/
public void setBlock(int x, int y, int z, BlockState state) {
buffer.setBlock(X + x, y, Z + z, state);
}
public void setBlock(int x, int y, int z, 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) {
int xx = X + x;
int zz = Z + z;
return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ));
}
}

View File

@ -0,0 +1,40 @@
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 org.spongepowered.common.world.gen.SpongeWorldGenerator;
import com.intellectualcrafters.plot.PS;
import com.plotsquared.sponge.SpongeMain;
public class WorldModify implements WorldGeneratorModifier {
private SpongePlotGenerator plotgen;
public WorldModify(SpongePlotGenerator plotgen) {
this.plotgen = plotgen;
}
@Override
public void modifyWorldGenerator(WorldCreationSettings world, DataContainer settings, WorldGenerator gen) {
gen.setBaseGeneratorPopulator(plotgen.getBaseGeneratorPopulator());
gen.setBiomeGenerator(plotgen.getBiomeGenerator());
// if (gen instanceof SpongeWorldGenerator) {
// SpongePlotGenerator plotgen = (SpongePlotGenerator) gen;
// plotgen.setBaseGeneratorPopulator(plotgen.getGenerator());
// plotgen.setBiomeGenerator(plotgen.getPlotBiomeProvider());
// }
}
@Override
public String getName() {
return "PlotSquared";
}
@Override
public String getId() {
return "PlotSquared";
}
}

View File

@ -0,0 +1,836 @@
package com.plotsquared.sponge.listener;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_ADMIN_BUILD_OTHER;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_ADMIN_BUILD_ROAD;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_ADMIN_BUILD_UNOWNED;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_ADMIN_DESTROY_OTHER;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_ADMIN_DESTROY_ROAD;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_ADMIN_DESTROY_UNOWNED;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_ADMIN_ENTRY_DENIED;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_ADMIN_EXIT_DENIED;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_ADMIN_INTERACT_OTHER;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_ADMIN_INTERACT_ROAD;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_ADMIN_INTERACT_UNOWNED;
import static com.intellectualcrafters.plot.object.StaticStrings.PERMISSION_COMMANDS_CHAT;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Subscribe;
import org.spongepowered.api.event.block.BlockMoveEvent;
import org.spongepowered.api.event.block.BlockRedstoneUpdateEvent;
import org.spongepowered.api.event.block.FloraGrowEvent;
import org.spongepowered.api.event.entity.EntityChangeBlockEvent;
import org.spongepowered.api.event.entity.EntityExplosionEvent;
import org.spongepowered.api.event.entity.EntitySpawnEvent;
import org.spongepowered.api.event.entity.EntityTeleportEvent;
import org.spongepowered.api.event.entity.player.PlayerBreakBlockEvent;
import org.spongepowered.api.event.entity.player.PlayerChangeWorldEvent;
import org.spongepowered.api.event.entity.player.PlayerChatEvent;
import org.spongepowered.api.event.entity.player.PlayerInteractBlockEvent;
import org.spongepowered.api.event.entity.player.PlayerJoinEvent;
import org.spongepowered.api.event.entity.player.PlayerMessageEvent;
import org.spongepowered.api.event.entity.player.PlayerMoveEvent;
import org.spongepowered.api.event.entity.player.PlayerPlaceBlockEvent;
import org.spongepowered.api.event.entity.player.PlayerQuitEvent;
import org.spongepowered.api.event.message.CommandEvent;
import org.spongepowered.api.event.network.PlayerConnectionEvent;
import org.spongepowered.api.event.world.ChunkLoadEvent;
import org.spongepowered.api.event.world.ChunkPreGenerateEvent;
import org.spongepowered.api.event.world.ChunkPrePopulateEvent;
import org.spongepowered.api.network.PlayerConnection;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.Texts;
import org.spongepowered.api.util.command.CommandSource;
import org.spongepowered.api.util.event.callback.EventCallback;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.Extent;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import com.google.common.base.Predicate;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.listener.PlotListener;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.SpongePlayer;
import com.plotsquared.sponge.util.SpongeUtil;
public class MainListener {
/*
* TODO:
* - Anything marked with a TODO below
* - BlockSpreadEvent
* - BlockPhysicsEvent
* - BlockFormEvent
* - BlockFadeEvent
* - BlockFromToEvent
* - BlockDamageEvent
* - Structure (tree etc)
* - Per plot mob caps
* - PlayerIgniteBlockEvent
* - PlayerBucketEmptyEvent
* - PlayerBucketFillEvent
* - VehicleCreateEvent
* - HangingPlaceEvent
* - HangingBreakEvent
* - PVP
* - PVE
* - VehicleDestroy
* - Projectile
*/
@Subscribe
public void onMobSpawn(EntitySpawnEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Player) {
return;
}
final Location loc = SpongeUtil.getLocation(event.getLocation());
final String world = loc.getWorld();
if (!PS.get().isPlotWorld(world)) {
return;
}
Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
if (MainUtil.isPlotRoad(loc)) {
event.setCancelled(true);
}
return;
}
final PlotWorld pW = PS.get().getPlotWorld(world);
// TODO selectively cancel depending on spawn reason
// - Not sure if possible to get spawn reason (since there are no callbacks)
event.setCancelled(true);
}
@Subscribe
public void onBlockChange(EntityChangeBlockEvent event) {
Entity entity = event.getEntity();
if (entity.getType() == EntityTypes.PLAYER) {
return;
}
if (PS.get().isPlotWorld(entity.getWorld().getName())) {
event.setCancelled(true);
}
}
@Subscribe
public void onCommand(CommandEvent event) {
switch (event.getCommand().toLowerCase()) {
case "plotme": {
CommandSource source = event.getSource();
if (Settings.USE_PLOTME_ALIAS) {
SpongeMain.THIS.getGame().getCommandDispatcher().process(source, ("plots " + event.getArguments()).trim());
} else {
source.sendMessage(SpongeMain.THIS.getText(C.NOT_USING_PLOTME.s()));
}
event.setCancelled(true);
}
}
// TODO
}
@Subscribe
public void onBlockMove(BlockMoveEvent event) {
org.spongepowered.api.world.Location block = event.getBlocks().get(0);
Extent extent = block.getExtent();
if (extent instanceof World) {
World world = (World) extent;
final String worldname = world.getName();
if (!PS.get().isPlotWorld(worldname)) {
return;
}
event.filter(new Predicate<org.spongepowered.api.world.Location>() {
@Override
public boolean apply(org.spongepowered.api.world.Location loc) {
if (MainUtil.isPlotRoad(SpongeUtil.getLocation(worldname, loc))) {
return false;
}
return true;
}
});
}
}
@Subscribe
public void onFloraGrow(FloraGrowEvent event) {
org.spongepowered.api.world.Location block = event.getBlock();
Extent extent = block.getExtent();
if (extent instanceof World) {
World world = (World) extent;
final String worldname = world.getName();
if (!PS.get().isPlotWorld(worldname)) {
return;
}
if (MainUtil.isPlotRoad(SpongeUtil.getLocation(worldname, block))) {
event.setCancelled(true);
}
}
}
@Subscribe
public void onChat(PlayerChatEvent event) {
final Player player = event.getEntity();
final String world = player.getWorld().getName();
if (!PS.get().isPlotWorld(world)) {
return;
}
final PlotWorld plotworld = PS.get().getPlotWorld(world);
final PlotPlayer plr = SpongeUtil.getPlayer(player);
if (!plotworld.PLOT_CHAT && (plr.getMeta("chat") == null || !(Boolean) plr.getMeta("chat"))) {
return;
}
final Location loc = SpongeUtil.getLocation(player);
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return;
}
Text message = event.getUnformattedMessage();
// TODO use display name rather than username
// - Getting displayname currently causes NPE, so wait until sponge fixes that
String sender = player.getName();
PlotId id = plot.id;
String newMessage = StringMan.replaceAll(C.PLOT_CHAT_FORMAT.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 (PlotPlayer user : UUIDHandler.getPlayers().values()) {
String toSend;
if (plot.equals(MainUtil.getPlot(user.getLocation()))) {
toSend = newMessage;
}
else if (Permissions.hasPermission(user, PERMISSION_COMMANDS_CHAT)) {
toSend = forcedMessage;
}
else {
continue;
}
String[] split = (toSend + " ").split("%msg%");
List<Text> components = new ArrayList<>();
Text prefix = null;
for (String part : split) {
if (prefix != null) {
components.add(prefix);
}
else {
prefix = message;
}
components.add(Texts.of(part));
}
((SpongePlayer) user).player.sendMessage(Texts.join(components));
}
event.setNewMessage(Texts.of());
event.setCancelled(true);
}
@Subscribe
public void onBigBoom(final EntityExplosionEvent event) {
Location loc = SpongeUtil.getLocation(event.getExplosionLocation());
final String world = loc.getWorld();
if (!PS.get().isPlotWorld(world)) {
return;
}
final Plot plot = MainUtil.getPlot(loc);
if ((plot != null) && plot.hasOwner()) {
if (FlagManager.isPlotFlagTrue(plot, "explosion")) {
event.filter(new Predicate<org.spongepowered.api.world.Location>() {
@Override
public boolean apply(org.spongepowered.api.world.Location loc) {
if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(loc)))) {
return false;
}
return true;
}
});
return;
}
}
if (MainUtil.isPlotArea(loc)) {
event.setYield(0);
} else {
if (FlagManager.isPlotFlagTrue(plot, "explosion")) {
event.filter(new Predicate<org.spongepowered.api.world.Location>() {
@Override
public boolean apply(org.spongepowered.api.world.Location loc) {
if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(loc)))) {
return false;
}
return true;
}
});
return;
}
}
}
@Subscribe
public void onChunkPreGenerator(ChunkPreGenerateEvent event) {
org.spongepowered.api.world.Chunk chunk = event.getChunk();
World world = chunk.getWorld();
final String worldname = world.getName();
if (MainUtil.worldBorder.containsKey(worldname)) {
final int border = MainUtil.getBorder(worldname);
Vector3i min = world.getBlockMin();
final int x = Math.abs(min.getX());
final int z = Math.abs(min.getZ());
if ((x > border) || (z > border)) {
// TODO cancel this chunk from loading
// - Currently not possible / this event doesn't seem to be called
}
}
}
@Subscribe
public void onRedstoneEvent(BlockRedstoneUpdateEvent event) {
org.spongepowered.api.world.Location block = event.getBlock();
Location loc = SpongeUtil.getLocation(block);
if (loc == null || !PS.get().isPlotWorld(loc.getWorld())) {
return;
}
Plot plot = MainUtil.getPlot(loc);
if (plot == null || !plot.hasOwner()) {
return;
}
if (event.getOldSignalStrength() > event.getNewSignalStrength()) {
return;
}
if (Settings.REDSTONE_DISABLER) {
if (UUIDHandler.getPlayer(plot.owner) == null) {
boolean disable = true;
for (UUID trusted : plot.getTrusted()) {
if (UUIDHandler.getPlayer(trusted) != null) {
disable = false;
break;
}
}
if (disable) {
event.setNewSignalStrength(0);
return;
}
}
}
Flag redstone = FlagManager.getPlotFlag(plot, "redstone");
if (FlagManager.isPlotFlagFalse(plot, "redstone")) {
event.setNewSignalStrength(0);
// TODO only disable clocks
}
}
@Subscribe
public void onBlockBreak(PlayerBreakBlockEvent event) {
Player player = event.getEntity();
World world = player.getWorld();
String worldname = world.getName();
org.spongepowered.api.world.Location blockLoc = event.getBlock();
final Location loc = SpongeUtil.getLocation(worldname, event.getBlock());
final Plot plot = MainUtil.getPlot(loc);
if (plot != null) {
if (event.getBlock().getY() == 0) {
event.setCancelled(true);
return;
}
if (!plot.hasOwner()) {
final PlotPlayer pp = SpongeUtil.getPlayer(player);
if (Permissions.hasPermission(pp, PERMISSION_ADMIN_DESTROY_UNOWNED)) {
return;
}
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_DESTROY_UNOWNED);
event.setCancelled(true);
return;
}
final PlotPlayer pp = SpongeUtil.getPlayer(player);
if (!plot.isAdded(pp.getUUID())) {
final Flag destroy = FlagManager.getPlotFlag(plot, "break");
BlockState state = blockLoc.getBlock();
if ((destroy != null) && ((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeMain.THIS.getPlotBlock(state))) {
return;
}
if (Permissions.hasPermission(pp, PERMISSION_ADMIN_DESTROY_OTHER)) {
return;
}
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_DESTROY_OTHER);
event.setCancelled(true);
}
return;
}
final PlotPlayer pp = SpongeUtil.getPlayer(player);
if (Permissions.hasPermission(pp, PERMISSION_ADMIN_DESTROY_ROAD)) {
return;
}
if (MainUtil.isPlotArea(loc)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_DESTROY_ROAD);
event.setCancelled(true);
}
}
@Subscribe
public void onBlockPlace(PlayerPlaceBlockEvent event) {
Player player = event.getEntity();
World world = player.getWorld();
String worldname = world.getName();
org.spongepowered.api.world.Location blockLoc = event.getBlock();
final Location loc = SpongeUtil.getLocation(worldname, event.getBlock());
final Plot plot = MainUtil.getPlot(loc);
if (plot != null) {
if (event.getBlock().getY() == 0) {
event.setCancelled(true);
return;
}
if (!plot.hasOwner()) {
final PlotPlayer pp = SpongeUtil.getPlayer(player);
if (Permissions.hasPermission(pp, PERMISSION_ADMIN_BUILD_UNOWNED)) {
return;
}
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_BUILD_UNOWNED);
event.setCancelled(true);
return;
}
final PlotPlayer pp = SpongeUtil.getPlayer(player);
if (!plot.isAdded(pp.getUUID())) {
final Flag destroy = FlagManager.getPlotFlag(plot, "place");
BlockState state = blockLoc.getBlock();
if ((destroy != null) && ((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeMain.THIS.getPlotBlock(state))) {
return;
}
if (Permissions.hasPermission(pp, PERMISSION_ADMIN_BUILD_OTHER)) {
return;
}
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_DESTROY_OTHER);
event.setCancelled(true);
}
return;
}
final PlotPlayer pp = SpongeUtil.getPlayer(player);
if (Permissions.hasPermission(pp, PERMISSION_ADMIN_BUILD_ROAD)) {
return;
}
if (MainUtil.isPlotArea(loc)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_BUILD_ROAD);
event.setCancelled(true);
}
}
@Subscribe
public void onBlockInteract(PlayerInteractBlockEvent event) {
Player player = event.getEntity();
World world = player.getWorld();
String worldname = world.getName();
org.spongepowered.api.world.Location blockLoc = event.getBlock();
final Location loc = SpongeUtil.getLocation(worldname, event.getBlock());
final Plot plot = MainUtil.getPlot(loc);
if (plot != null) {
if (event.getBlock().getY() == 0) {
event.setCancelled(true);
return;
}
if (!plot.hasOwner()) {
final PlotPlayer pp = SpongeUtil.getPlayer(player);
if (Permissions.hasPermission(pp, PERMISSION_ADMIN_INTERACT_UNOWNED)) {
return;
}
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_INTERACT_UNOWNED);
event.setCancelled(true);
return;
}
final PlotPlayer pp = SpongeUtil.getPlayer(player);
if (!plot.isAdded(pp.getUUID())) {
final Flag destroy = FlagManager.getPlotFlag(plot, "use");
BlockState state = blockLoc.getBlock();
if ((destroy != null) && ((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeMain.THIS.getPlotBlock(state))) {
return;
}
if (Permissions.hasPermission(pp, PERMISSION_ADMIN_INTERACT_OTHER)) {
return;
}
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_INTERACT_OTHER);
event.setCancelled(true);
}
return;
}
final PlotPlayer pp = SpongeUtil.getPlayer(player);
if (Permissions.hasPermission(pp, PERMISSION_ADMIN_INTERACT_ROAD)) {
return;
}
if (MainUtil.isPlotArea(loc)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_INTERACT_ROAD);
event.setCancelled(true);
}
}
@Subscribe
public void onConnect(PlayerConnectionEvent event) {
PlayerConnection connection = event.getConnection();
Player player = connection.getPlayer();
String name = player.getName();
PlotPlayer pp = SpongeUtil.getPlayer(player);
if (name.equals("PlotSquared") || pp.getUUID().equals(DBFunc.everyone)) {
player.kick();
SpongeUtil.removePlayer(pp.getName());
}
}
@Subscribe
public void onJoin(PlayerJoinEvent event) {
final Player player = event.getUser();
SpongeUtil.removePlayer(player.getName());
final PlotPlayer pp = SpongeUtil.getPlayer(player);
final String username = pp.getName();
final StringWrapper name = new StringWrapper(username);
final UUID uuid = pp.getUUID();
UUIDHandler.add(name, uuid);
ExpireManager.dates.put(uuid, System.currentTimeMillis());
// TODO worldedit bypass
if (PS.get().update != null && pp.hasPermission("plots.admin")) {
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(pp, "&6An update for PlotSquared is available: &7/plot update");
}
}, 20);
}
final Location loc = SpongeUtil.getLocation(player);
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return;
}
if (Settings.TELEPORT_ON_LOGIN) {
MainUtil.teleportPlayer(pp, pp.getLocation(), plot);
MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD);
}
PlotListener.plotEntry(pp, plot);
}
@Subscribe
public void onQuit(PlayerQuitEvent event) {
Player player = event.getEntity();
PlotPlayer pp = SpongeUtil.getPlayer(player);
ExpireManager.dates.put(pp.getUUID(), System.currentTimeMillis());
EventUtil.unregisterPlayer(pp);
// TODO unregister WorldEdit manager
// TODO delete plots on ban
SpongeUtil.removePlayer(pp.getName());
}
public int getInt(double value) {
return (int) (value < 0 ? value - 1 : value);
}
@Subscribe
public void onMove(PlayerMoveEvent event) {
org.spongepowered.api.world.Location from = event.getOldLocation();
org.spongepowered.api.world.Location to = event.getNewLocation();
int x2;
if (getInt(from.getX()) != (x2 = getInt(to.getX()))) {
Extent extent = to.getExtent();
if (!(extent instanceof World)) {
return;
}
World world = (World) extent;
String worldname = ((World) extent).getName();
PlotWorld plotworld = PS.get().getPlotWorld(worldname);
if (plotworld == null) {
return;
}
PlotManager plotManager = PS.get().getPlotManager(worldname);
PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ()));
Player player = event.getUser();
PlotPlayer pp = SpongeUtil.getPlayer(player);
Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) {
if (lastPlot == null) {
return;
}
if (!PlotListener.plotExit(pp, lastPlot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
event.setNewLocation(from);
}
else {
event.setNewLocation(world.getSpawnLocation());
}
return;
}
}
else if (lastPlot != null && id.equals(lastPlot.id)) {
return;
}
else {
Plot plot = MainUtil.getPlot(worldname, id);
if (!PlotListener.plotEntry(pp, plot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
event.setNewLocation(from);
}
else {
event.setNewLocation(world.getSpawnLocation());
}
return;
}
}
Integer border = MainUtil.worldBorder.get(worldname);
if (border != null) {
if (x2 > border) {
Vector3d pos = to.getPosition();
to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ()));
event.setNewLocation(to);
MainUtil.sendMessage(pp, C.BORDER);
}
else if (x2 < -border) {
Vector3d pos = to.getPosition();
to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ()));
event.setNewLocation(to);
MainUtil.sendMessage(pp, C.BORDER);
}
}
return;
}
int z2;
if (getInt(from.getZ()) != (z2 = getInt(to.getZ())) ) {
Extent extent = to.getExtent();
if (!(extent instanceof World)) {
return;
}
World world = (World) extent;
String worldname = ((World) extent).getName();
PlotWorld plotworld = PS.get().getPlotWorld(worldname);
if (plotworld == null) {
return;
}
PlotManager plotManager = PS.get().getPlotManager(worldname);
PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2);
Player player = event.getUser();
PlotPlayer pp = SpongeUtil.getPlayer(player);
Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) {
if (lastPlot == null) {
return;
}
if (!PlotListener.plotExit(pp, lastPlot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
event.setNewLocation(from);
}
else {
event.setNewLocation(world.getSpawnLocation());
}
return;
}
}
else if (lastPlot != null && id.equals(lastPlot.id)) {
return;
}
else {
Plot plot = MainUtil.getPlot(worldname, id);
if (!PlotListener.plotEntry(pp, plot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
event.setNewLocation(from);
}
else {
event.setNewLocation(world.getSpawnLocation());
}
return;
}
}
Integer border = MainUtil.worldBorder.get(worldname);
if (border != null) {
if (z2 > border) {
Vector3d pos = to.getPosition();
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4));
event.setNewLocation(to);
MainUtil.sendMessage(pp, C.BORDER);
}
else if (z2 < -border) {
Vector3d pos = to.getPosition();
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4));
event.setNewLocation(to);
MainUtil.sendMessage(pp, C.BORDER);
}
}
}
}
@Subscribe
public void onWorldChange(EntityTeleportEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Player) {
org.spongepowered.api.world.Location from = event.getOldLocation();
org.spongepowered.api.world.Location to = event.getNewLocation();
int x2;
if (getInt(from.getX()) != (x2 = getInt(to.getX()))) {
Extent extent = to.getExtent();
if (!(extent instanceof World)) {
return;
}
World world = (World) extent;
String worldname = ((World) extent).getName();
PlotWorld plotworld = PS.get().getPlotWorld(worldname);
if (plotworld == null) {
return;
}
PlotManager plotManager = PS.get().getPlotManager(worldname);
PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ()));
Player player = (Player) entity;
PlotPlayer pp = SpongeUtil.getPlayer(player);
Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) {
if (lastPlot == null) {
return;
}
if (!PlotListener.plotExit(pp, lastPlot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
event.setNewLocation(from);
}
else {
event.setNewLocation(world.getSpawnLocation());
}
return;
}
}
else if (lastPlot != null && id.equals(lastPlot.id)) {
return;
}
else {
Plot plot = MainUtil.getPlot(worldname, id);
if (!PlotListener.plotEntry(pp, plot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
event.setNewLocation(from);
}
else {
event.setNewLocation(world.getSpawnLocation());
}
return;
}
}
Integer border = MainUtil.worldBorder.get(worldname);
if (border != null) {
if (x2 > border) {
Vector3d pos = to.getPosition();
to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ()));
event.setNewLocation(to);
MainUtil.sendMessage(pp, C.BORDER);
}
else if (x2 < -border) {
Vector3d pos = to.getPosition();
to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ()));
event.setNewLocation(to);
MainUtil.sendMessage(pp, C.BORDER);
}
}
return;
}
int z2;
if (getInt(from.getZ()) != (z2 = getInt(to.getZ())) ) {
Extent extent = to.getExtent();
if (!(extent instanceof World)) {
return;
}
World world = (World) extent;
String worldname = ((World) extent).getName();
PlotWorld plotworld = PS.get().getPlotWorld(worldname);
if (plotworld == null) {
return;
}
PlotManager plotManager = PS.get().getPlotManager(worldname);
PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2);
Player player = (Player) entity;
PlotPlayer pp = SpongeUtil.getPlayer(player);
Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) {
if (lastPlot == null) {
return;
}
if (!PlotListener.plotExit(pp, lastPlot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
event.setNewLocation(from);
}
else {
event.setNewLocation(player.getWorld().getSpawnLocation());
}
return;
}
}
else if (lastPlot != null && id.equals(lastPlot.id)) {
return;
}
else {
Plot plot = MainUtil.getPlot(worldname, id);
if (!PlotListener.plotEntry(pp, plot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
event.setNewLocation(from);
}
else {
event.setNewLocation(player.getWorld().getSpawnLocation());
}
return;
}
}
Integer border = MainUtil.worldBorder.get(worldname);
if (border != null) {
if (z2 > border) {
Vector3d pos = to.getPosition();
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4));
event.setNewLocation(to);
MainUtil.sendMessage(pp, C.BORDER);
}
else if (z2 < -border) {
Vector3d pos = to.getPosition();
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4));
event.setNewLocation(to);
MainUtil.sendMessage(pp, C.BORDER);
}
}
}
}
}
@Subscribe
public void onWorldChange(PlayerChangeWorldEvent event) {
final PlotPlayer player = SpongeUtil.getPlayer(event.getUser());
// TODO worldedit mask
((BukkitPlayer) player).hasPerm = new HashSet<>();
((BukkitPlayer) player).noPerm = new HashSet<>();
}
}

View File

@ -0,0 +1,7 @@
package com.plotsquared.sponge.util;
public class KillRoadMobs {
public void run() {
// TODO kill road mobs
}
}

View File

@ -0,0 +1,202 @@
package com.plotsquared.sponge.util;
import java.util.List;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.block.tileentity.Sign;
import org.spongepowered.api.data.manipulator.tileentity.SignData;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.biome.BiomeType;
import org.spongepowered.api.world.biome.BiomeTypes;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.StringComparison;
import com.plotsquared.sponge.SpongeMain;
public class SpongeBlockManager extends BlockManager {
@Override
public boolean isBlockSolid(PlotBlock block) {
BlockState state = SpongeMain.THIS.getBlockState(block);
BlockType type = state.getType();
return type.isSolidCube() && !type.isAffectedByGravity();
}
@Override
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
try {
double match;
short id;
byte data;
String[] split = name.split(":");
if (split.length == 2) {
data = Byte.parseByte(split[1]);
name = split[0];
}
else {
data = 0;
}
if (MathMan.isInteger(split[0])) {
id = Short.parseShort(split[0]);
match = 0;
}
else {
StringComparison<BlockState>.ComparisonResult comparison = new StringComparison<BlockState>(name, SpongeMain.THIS.getAllStates()) {
public String getString(BlockState o) {
return o.getType().getId();
};
}.getBestMatchAdvanced();
match = comparison.match;
id = SpongeMain.THIS.getPlotBlock(comparison.best).id;
}
PlotBlock block = new PlotBlock(id, data);
StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
return outer.new ComparisonResult(match, block);
}
catch (Exception e) {}
return null;
}
@Override
public String getClosestMatchingName(PlotBlock block) {
// TODO Auto-generated method stub
return null;
}
@Override
public String[] getBiomeList() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean addItems(String world, PlotItem items) {
// TODO Auto-generated method stub
return false;
}
@Override
public int getBiomeFromString(String biome) {
// TODO Auto-generated method stub
return 0;
}
@Override
public PlotBlock getPlotBlockFromString(String block) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getHeighestBlock(String worldname, int x, int z) {
World world = SpongeUtil.getWorld(worldname);
for (int y = 255; y > 0; y--) {
BlockState block = world.getBlock(x, y, z);
if (block != null && block.getType() != BlockTypes.AIR) {
return y+1;
}
}
return 64;
}
@Override
public String getBiome(String world, int x, int z) {
return SpongeUtil.getWorld(world).getBiome(x, z).getName().toUpperCase();
}
@Override
public PlotBlock getBlock(Location loc) {
BlockState state = SpongeUtil.getWorld(loc.getWorld()).getBlock(loc.getX(), loc.getY(), loc.getZ());
PlotBlock block = SpongeMain.THIS.getPlotBlock(state);
if (block == null) {
block = SpongeMain.THIS.registerBlock(state);
}
return block;
}
@Override
public Location getSpawn(String world) {
return SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
}
@Override
public String[] getSign(Location loc) {
BlockState block = SpongeUtil.getWorld(loc.getWorld()).getBlock(loc.getX(), loc.getY(), loc.getZ());
if (!(block instanceof Sign)) {
return null;
}
Sign sign = (Sign) block;
String[] result = new String[4];
List<Text> lines = sign.getData().get().getLines();
for (int i = 0; i < 4; i++) {
result[i] = lines.get(i).toString();
}
return result;
}
@Override
public boolean isWorld(String world) {
return SpongeUtil.getWorld(world) != null;
}
@Override
public void functionSetBlocks(String worldname, int[] xv, int[] yv, int[] zv, int[] id, byte[] data) {
for (int i = 0; i < xv.length; i++) {
functionSetBlock(worldname, xv[i], yv[i], zv[i], id[i], data[i]);
}
}
@Override
public void functionSetSign(String worldname, int x, int y, int z, String[] lines) {
World world = SpongeUtil.getWorld(worldname);
world.setBlock(x, y, z, BlockTypes.WALL_SIGN.getDefaultState());
BlockState block = world.getBlock(x, y, z);
if (!(block instanceof Sign)) {
return;
}
Sign sign = (Sign) block;
SignData data = sign.getData().get();
for (int i = 0; i < 4; i++) {
data.setLine(i, SpongeMain.THIS.getText(lines[i]));
}
}
@Override
public void functionSetBlock(String worldname, int x, int y, int z, int id, byte data) {
BlockState state;
if (data == 0) {
state = SpongeMain.THIS.getBlockState(id);
}
else {
state = SpongeMain.THIS.getBlockState(new PlotBlock((short) id, data));
}
if (state == null) {
return;
}
SpongeUtil.getWorld(worldname).setBlock(x, y, z, state);
}
@Override
public void functionSetBiomes(String worldname, int[] xv, int[] zv, String biomeName) {
BiomeType biome;
try {
biome = (BiomeType) BiomeTypes.class.getField(biomeName.toUpperCase()).get(null);
} catch (Exception e) {
e.printStackTrace();
biome = BiomeTypes.FOREST;
}
for (int i = 0; i < xv.length; i++) {
SpongeUtil.getWorld(worldname).setBiome(xv[i], zv[i], biome);
}
}
}

View File

@ -0,0 +1,71 @@
package com.plotsquared.sponge.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.Texts;
import org.spongepowered.api.util.command.CommandCallable;
import org.spongepowered.api.util.command.CommandException;
import org.spongepowered.api.util.command.CommandResult;
import org.spongepowered.api.util.command.CommandSource;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.sponge.SpongeMain;
public class SpongeCommand implements CommandCallable {
@Override
public CommandResult process(CommandSource cmd, String string) throws CommandException {
String id = cmd.getIdentifier();
PlotPlayer pp;
try {
UUID uuid = UUID.fromString(id);
Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get();
pp = SpongeUtil.getPlayer(player);
}
catch (Exception e) {
pp = ConsolePlayer.getConsole();
}
if (MainCommand.onCommand(pp, cmd.getName(), string.split(" "))) {
return CommandResult.success();
}
else {
return CommandResult.empty();
}
}
@Override
public List<String> getSuggestions(CommandSource cmd, String string) throws CommandException {
// TODO Auto-generated method stub
return new ArrayList<>(Arrays.asList("TEST"));
}
@Override
public boolean testPermission(CommandSource cmd) {
return true;
}
@Override
public Optional<? extends Text> getShortDescription(CommandSource cmd) {
return Optional.of(Texts.of("Shows plot help"));
}
@Override
public Optional<? extends Text> getHelp(CommandSource cmd) {
return Optional.of(Texts.of("/plot help"));
}
@Override
public Text getUsage(CommandSource cmd) {
return Texts.of("/plot <command>");
}
}

View File

@ -0,0 +1,119 @@
package com.plotsquared.sponge.util;
import java.util.ArrayList;
import java.util.UUID;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.service.event.EventManager;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EventUtil;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.events.ClusterFlagRemoveEvent;
import com.plotsquared.sponge.events.PlayerClaimPlotEvent;
import com.plotsquared.sponge.events.PlayerEnterPlotEvent;
import com.plotsquared.sponge.events.PlayerLeavePlotEvent;
import com.plotsquared.sponge.events.PlayerPlotDeniedEvent;
import com.plotsquared.sponge.events.PlayerPlotHelperEvent;
import com.plotsquared.sponge.events.PlayerPlotTrustedEvent;
import com.plotsquared.sponge.events.PlayerTeleportToPlotEvent;
import com.plotsquared.sponge.events.PlotClearEvent;
import com.plotsquared.sponge.events.PlotDeleteEvent;
import com.plotsquared.sponge.events.PlotFlagAddEvent;
import com.plotsquared.sponge.events.PlotFlagRemoveEvent;
import com.plotsquared.sponge.events.PlotMergeEvent;
import com.plotsquared.sponge.events.PlotUnlinkEvent;
public class SpongeEventUtil extends EventUtil {
public EventManager events;
public SpongeEventUtil() {
this.events = SpongeMain.THIS.getGame().getEventManager();
}
public boolean callEvent(Event event) {
events.post(event);
if (event instanceof Cancellable) {
return !((Cancellable) event).isCancelled();
}
return true;
}
@Override
public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) {
return callEvent(new PlayerClaimPlotEvent(SpongeUtil.getPlayer(player), plot, auto));
}
@Override
public boolean callTeleport(PlotPlayer player, Location from, Plot plot) {
return callEvent(new PlayerTeleportToPlotEvent(SpongeUtil.getPlayer(player), from, plot));
}
@Override
public boolean callClear(String world, PlotId id) {
return callEvent(new PlotClearEvent(world, id));
}
@Override
public void callDelete(String world, PlotId id) {
callEvent(new PlotDeleteEvent(world, id));
}
@Override
public boolean callFlagAdd(Flag flag, Plot plot) {
return callEvent(new PlotFlagAddEvent(flag, plot));
}
@Override
public boolean callFlagRemove(Flag flag, Plot plot) {
return callEvent(new PlotFlagRemoveEvent(flag, plot));
}
@Override
public boolean callMerge(String world, Plot plot, ArrayList<PlotId> plots) {
return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(world), plot, plots));
}
@Override
public boolean callUnlink(String world, ArrayList<PlotId> plots) {
return callEvent(new PlotUnlinkEvent(SpongeUtil.getWorld(world), plots));
}
@Override
public void callEntry(PlotPlayer player, Plot plot) {
callEvent(new PlayerEnterPlotEvent(SpongeUtil.getPlayer(player), plot));
}
@Override
public void callLeave(PlotPlayer player, Plot plot) {
callEvent(new PlayerLeavePlotEvent(SpongeUtil.getPlayer(player), plot));
}
@Override
public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
callEvent(new PlayerPlotDeniedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
}
@Override
public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
callEvent(new PlayerPlotHelperEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
}
@Override
public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
callEvent(new PlayerPlotTrustedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
}
@Override
public boolean callFlagRemove(Flag flag, PlotCluster cluster) {
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
}
}

View File

@ -0,0 +1,116 @@
package com.plotsquared.sponge.util;
import java.util.ArrayList;
import java.util.Locale;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.inventory.Carrier;
import org.spongepowered.api.item.inventory.Inventories;
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackBuilder;
import org.spongepowered.api.item.inventory.custom.CustomInventory;
import org.spongepowered.api.item.inventory.property.SlotIndex;
import org.spongepowered.api.item.inventory.type.CarriedInventory;
import com.intellectualcrafters.plot.object.PlotInventory;
import com.intellectualcrafters.plot.object.PlotItemStack;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.InventoryUtil;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.SpongePlayer;
public class SpongeInventoryUtil extends InventoryUtil {
public ItemStackBuilder builder;
public SpongeInventoryUtil() {
this.builder = SpongeMain.THIS.getGame().getRegistry().getItemBuilder();
}
@Override
public void open(PlotInventory inv) {
// TODO Auto-generated method stub
SpongePlayer sp = (SpongePlayer) inv.player;
Player player = sp.player;
CustomInventory inventory = Inventories.customInventoryBuilder().name(SpongeMain.THIS.getTranslation(inv.getTitle())).size(inv.size).build();
PlotItemStack[] items = inv.getItems();
for (int i = 0; i < inv.size * 9; i++) {
PlotItemStack item = items[i];
if (item != null) {
inventory.set(new SlotIndex(i), getItem(item));
}
}
inv.player.setMeta("inventory", inv);
player.openInventory(inventory);
}
public ItemStack getItem(PlotItemStack item) {
// FIXME item type, item data, item name, item lore
return builder.itemType(ItemTypes.SPONGE).quantity(item.amount).build();
}
@Override
public void close(PlotInventory inv) {
if (!inv.isOpen()) {
return;
}
inv.player.deleteMeta("inventory");
SpongePlayer sp = (SpongePlayer) inv.player;
sp.player.closeInventory();
}
@Override
public void setItem(PlotInventory inv, int index, PlotItemStack item) {
if (!inv.isOpen()) {
return;
}
SpongePlayer sp = (SpongePlayer) inv.player;
Player player = sp.player;
Inventory inventory = player.getOpenInventory().get();
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
public PlotItemStack getItem(ItemStack item) {
if (item == null) {
return null;
}
ItemType type = item.getItem();
String id = type.getId();
int amount = item.getQuantity();
// TODO name / lore
return new PlotItemStack(id, amount, null);
}
@Override
public PlotItemStack[] getItems(PlotPlayer player) {
SpongePlayer sp = (SpongePlayer) player;
CarriedInventory<? extends Carrier> inv = sp.player.getInventory();
ArrayList<PlotItemStack> list = new ArrayList<PlotItemStack>();
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
// return list.toArray();
}
@Override
public boolean isOpen(PlotInventory inv) {
if (!inv.isOpen()) {
return false;
}
SpongePlayer sp = (SpongePlayer) inv.player;
Player player = sp.player;
if (player.isViewingInventory()) {
CarriedInventory<? extends Carrier> inventory = player.getInventory();
return inv.getTitle().equals(inventory.getName().getTranslation().get(Locale.ENGLISH));
}
return false;
}
}

View File

@ -1,4 +1,4 @@
package com.plotsquared.sponge;
package com.plotsquared.sponge.util;
/*
* Copyright 2011-2013 Tyler Blair. All rights reserved.
@ -28,16 +28,13 @@ package com.plotsquared.sponge;
* either expressed or implied, of anybody else.
*/
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.service.scheduler.Task;
import org.spongepowered.api.service.scheduler.TaskBuilder;
import javax.inject.Inject;
import java.io.*;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
@ -46,6 +43,17 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPOutputStream;
import javax.inject.Inject;
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.service.scheduler.Task;
import org.spongepowered.api.service.scheduler.TaskBuilder;
public class SpongeMetrics {
/**

View File

@ -1,4 +1,4 @@
package com.plotsquared.sponge;
package com.plotsquared.sponge.util;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;
@ -7,6 +7,7 @@ import org.spongepowered.api.service.scheduler.Task;
import org.spongepowered.api.service.scheduler.TaskBuilder;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.sponge.SpongeMain;
public class SpongeTaskManager extends TaskManager {
@ -27,25 +28,25 @@ public class SpongeTaskManager extends TaskManager {
@Override
public void taskAsync(Runnable r) {
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder();
builder.async().execute(r);
builder.async().execute(r).submit(SpongeMain.THIS.getPlugin());
}
@Override
public void task(Runnable r) {
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder();
builder.execute(r);
builder.execute(r).submit(SpongeMain.THIS.getPlugin());
}
@Override
public void taskLater(Runnable r, int delay) {
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder();
builder.delay(delay).execute(r);
builder.delay(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
}
@Override
public void taskLaterAsync(Runnable r, int delay) {
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder();
builder.async().delay(delay).execute(r);
builder.async().delay(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
}
@Override

View File

@ -0,0 +1,86 @@
package com.plotsquared.sponge.util;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.Extent;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.SpongePlayer;
public class SpongeUtil {
public static Location getLocation(Entity player) {
String world = player.getWorld().getName();
org.spongepowered.api.world.Location loc = player.getLocation();
Vector3i pos = loc.getBlockPosition();
return new Location(world, pos.getX(), pos.getY(), pos.getZ());
}
public static Location getLocation(org.spongepowered.api.world.Location block) {
Extent extent = block.getExtent();
if (extent instanceof World) {
return getLocation(((World) extent).getName(), block);
}
return null;
}
public static Location getLocationFull(Entity player) {
String world = player.getWorld().getName();
Vector3d rot = player.getRotation();
float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ());
org.spongepowered.api.world.Location loc = player.getLocation();
Vector3i pos = loc.getBlockPosition();
return new Location(world, pos.getX(), pos.getY(), pos.getZ(), pitchYaw[1], pitchYaw[0]);
}
private static Player lastPlayer = null;
private static PlotPlayer lastPlotPlayer = null;
public static PlotPlayer getPlayer(Player player) {
if (player == lastPlayer) {
return lastPlotPlayer;
}
String name = player.getName();
PlotPlayer pp = UUIDHandler.getPlayers().get(name);
if (pp != null) {
return pp;
}
lastPlotPlayer = new SpongePlayer(player);
UUIDHandler.getPlayers().put(name, lastPlotPlayer);
lastPlayer = player;
return lastPlotPlayer;
}
public static Player getPlayer(PlotPlayer player) {
if (player instanceof SpongePlayer) {
return ((SpongePlayer) player).player;
}
return null;
}
public static World getWorld(String world) {
Optional<World> optional = SpongeMain.THIS.getServer().getWorld(world);
if (!optional.isPresent()) {
return null;
}
return optional.get();
}
public static void removePlayer(String player) {
lastPlayer = null;
lastPlotPlayer = null;
UUIDHandler.getPlayers().remove(player);
}
public static Location getLocation(String world, org.spongepowered.api.world.Location spawn) {
return new Location(world, spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ());
}
}

View File

@ -1,18 +1,16 @@
package com.plotsquared.sponge;
package com.plotsquared.sponge.uuid;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import org.spongepowered.api.GameProfile;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.service.profile.GameProfileResolver;
import com.google.common.base.Charsets;
import com.google.inject.Inject;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.sponge.SpongeMain;
public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper {

View File

@ -1,12 +1,13 @@
package com.plotsquared.sponge;
package com.plotsquared.sponge.uuid;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.SpongePlayer;
public class SpongeOnlineUUIDWrapper extends UUIDWrapper {

View File

@ -1,18 +1,16 @@
package com.plotsquared.sponge;
package com.plotsquared.sponge.uuid;
import java.util.Collection;
import java.util.UUID;
import org.spongepowered.api.GameProfile;
import org.spongepowered.api.service.profile.GameProfileResolver;
import com.google.inject.Inject;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.sponge.SpongeMain;
public class SpongeUUIDHandler extends UUIDHandlerImplementation {