mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-21 06:44:43 +02:00
Hows this?
This commit is contained in:
@ -12,45 +12,35 @@ import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class SpongeHybridUtils extends HybridUtils
|
||||
{
|
||||
|
||||
public class SpongeHybridUtils extends HybridUtils {
|
||||
|
||||
@Override
|
||||
public void analyzePlot(final Plot plot, final RunnableVal<PlotAnalysis> whenDone)
|
||||
{
|
||||
public void analyzePlot(final Plot plot, final RunnableVal<PlotAnalysis> whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
PS.debug("analyzePlot is not implemented");
|
||||
if (whenDone != null)
|
||||
{
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int checkModified(final String worldname, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks)
|
||||
{
|
||||
public int checkModified(final String worldname, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks) {
|
||||
PS.debug("checkModified is not implemented");
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
int count = 0;
|
||||
for (int y = y1; y <= y2; y++)
|
||||
{
|
||||
for (int x = x1; x <= x2; x++)
|
||||
{
|
||||
for (int z = z1; z <= z2; z++)
|
||||
{
|
||||
for (int y = y1; y <= y2; y++) {
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
for (int z = z1; z <= z2; z++) {
|
||||
final BlockState state = world.getBlock(x, y, z);
|
||||
final PlotBlock block = SpongeMain.THIS.getPlotBlock(state);
|
||||
boolean same = false;
|
||||
for (final PlotBlock p : blocks)
|
||||
{
|
||||
if (block.id == p.id)
|
||||
{
|
||||
for (final PlotBlock p : blocks) {
|
||||
if (block.id == p.id) {
|
||||
same = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!same)
|
||||
{
|
||||
if (!same) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@ -58,23 +48,17 @@ public class SpongeHybridUtils extends HybridUtils
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int get_ey(final String worldname, final int sx, final int ex, final int sz, final int ez, final int sy)
|
||||
{
|
||||
public int get_ey(final String worldname, final int sx, final int ex, final int sz, final int ez, final int sy) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
int ey = sy;
|
||||
for (int x = sx; x <= ex; x++)
|
||||
{
|
||||
for (int z = sz; z <= ez; z++)
|
||||
{
|
||||
for (int y = sy; y < 256; y++)
|
||||
{
|
||||
if (y > ey)
|
||||
{
|
||||
for (int x = sx; x <= ex; x++) {
|
||||
for (int z = sz; z <= ez; z++) {
|
||||
for (int y = sy; y < 256; y++) {
|
||||
if (y > ey) {
|
||||
final BlockState state = world.getBlock(x, y, z);
|
||||
if ((state != null) && (state.getType() != BlockTypes.AIR))
|
||||
{
|
||||
if ((state != null) && (state.getType() != BlockTypes.AIR)) {
|
||||
ey = y;
|
||||
}
|
||||
}
|
||||
@ -83,5 +67,5 @@ public class SpongeHybridUtils extends HybridUtils
|
||||
}
|
||||
return ey;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -86,362 +86,286 @@ import com.plotsquared.sponge.uuid.SpongeUUIDHandler;
|
||||
*/
|
||||
|
||||
@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.0.0", dependencies = "before:WorldEdit")
|
||||
public class SpongeMain implements IPlotMain, PluginContainer
|
||||
{
|
||||
public class SpongeMain implements IPlotMain, PluginContainer {
|
||||
public static SpongeMain THIS;
|
||||
|
||||
|
||||
@Inject
|
||||
private Logger logger;
|
||||
@Inject
|
||||
private Game game;
|
||||
private Server server;
|
||||
|
||||
|
||||
private GameProfileResolver resolver;
|
||||
|
||||
|
||||
private WorldModify modify;
|
||||
|
||||
|
||||
private Object plugin;
|
||||
|
||||
|
||||
// stuff //
|
||||
public Logger getLogger()
|
||||
{
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public Game getGame()
|
||||
{
|
||||
|
||||
public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
public Server getServer()
|
||||
{
|
||||
|
||||
public Server getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public GameProfileResolver getResolver()
|
||||
{
|
||||
|
||||
public GameProfileResolver getResolver() {
|
||||
return resolver;
|
||||
}
|
||||
|
||||
public Object getPlugin()
|
||||
{
|
||||
|
||||
public Object getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public Text getText(final String m)
|
||||
{
|
||||
|
||||
public Text getText(final String m) {
|
||||
return Texts.of(m);
|
||||
}
|
||||
|
||||
public Translatable getTranslation(final String m)
|
||||
{
|
||||
return new Translatable()
|
||||
{
|
||||
|
||||
public Translatable getTranslation(final String m) {
|
||||
return new Translatable() {
|
||||
@Override
|
||||
public Translation getTranslation()
|
||||
{
|
||||
return new Translation()
|
||||
{
|
||||
|
||||
public Translation getTranslation() {
|
||||
return new Translation() {
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
public String getId() {
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String get(final Locale l, final Object... args)
|
||||
{
|
||||
public String get(final Locale l, final Object... args) {
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String get(final Locale l)
|
||||
{
|
||||
public String get(final Locale l) {
|
||||
return m;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private final PlotBlock NULL_BLOCK = new PlotBlock((short) 0, (byte) 0);
|
||||
private BlockState[][] blockMap;
|
||||
private Map<BlockState, PlotBlock> blockMapReverse;
|
||||
|
||||
public BlockState getBlockState(final PlotBlock block)
|
||||
{
|
||||
if (blockMap[block.id] == null)
|
||||
{
|
||||
|
||||
public BlockState getBlockState(final PlotBlock block) {
|
||||
if (blockMap[block.id] == null) {
|
||||
log("UNKNOWN BLOCK: " + block.toString());
|
||||
return null;
|
||||
}
|
||||
else if (blockMap[block.id].length <= block.data)
|
||||
{
|
||||
} else if (blockMap[block.id].length <= block.data) {
|
||||
log("UNKNOWN BLOCK: " + block.toString() + " -> Using " + block.id + ":0 instead");
|
||||
return blockMap[block.id][0];
|
||||
}
|
||||
return blockMap[block.id][block.data];
|
||||
}
|
||||
|
||||
public BlockState getBlockState(final int id)
|
||||
{
|
||||
|
||||
public BlockState getBlockState(final int id) {
|
||||
return blockMap[id][0];
|
||||
}
|
||||
|
||||
public Collection<BlockState> getAllStates()
|
||||
{
|
||||
|
||||
public Collection<BlockState> getAllStates() {
|
||||
return blockMapReverse.keySet();
|
||||
}
|
||||
|
||||
public PlotBlock getPlotBlock(final BlockState state)
|
||||
{
|
||||
|
||||
public PlotBlock getPlotBlock(final BlockState state) {
|
||||
final PlotBlock val = blockMapReverse.get(state);
|
||||
if (val == null) { return NULL_BLOCK; }
|
||||
if (val == null) {
|
||||
return NULL_BLOCK;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
/////////
|
||||
|
||||
|
||||
////////////////////// SPONGE PLUGIN REGISTRATION ////////////////////
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
public String getId() {
|
||||
return "PlotSquared";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getInstance()
|
||||
{
|
||||
public Object getInstance() {
|
||||
return THIS;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
return "PlotSquared";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getVersion()
|
||||
{
|
||||
public String getVersion() {
|
||||
final int[] version = PS.get().getVersion();
|
||||
String result = "";
|
||||
String prefix = "";
|
||||
for (final int i : version)
|
||||
{
|
||||
for (final int i : version) {
|
||||
result += prefix + i;
|
||||
prefix = ".";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////// ON ENABLE /////////////////////
|
||||
@Subscribe
|
||||
public void init(final InitializationEvent event)
|
||||
{
|
||||
public void init(final InitializationEvent event) {
|
||||
log("INIT");
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onInit(final PreInitializationEvent event)
|
||||
{
|
||||
public void onInit(final PreInitializationEvent event) {
|
||||
log("PRE INIT");
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onServerAboutToStart(final ServerAboutToStartEvent event)
|
||||
{
|
||||
public void onServerAboutToStart(final ServerAboutToStartEvent event) {
|
||||
log("ABOUT START");
|
||||
THIS = this;
|
||||
|
||||
|
||||
//
|
||||
resolver = game.getServiceManager().provide(GameProfileResolver.class).get();
|
||||
plugin = this;
|
||||
server = game.getServer();
|
||||
//
|
||||
|
||||
|
||||
PS.instance = new PS(this, "Sponge");
|
||||
|
||||
|
||||
registerBlocks();
|
||||
|
||||
|
||||
final ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
|
||||
if (worldSection != null)
|
||||
{
|
||||
for (final String world : worldSection.getKeys(false))
|
||||
{
|
||||
if (worldSection != null) {
|
||||
for (final String world : worldSection.getKeys(false)) {
|
||||
createWorldFromConfig(world);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public World createWorldFromConfig(final String world)
|
||||
{
|
||||
|
||||
public World createWorldFromConfig(final String world) {
|
||||
final SpongeBasicGen generator = new SpongeBasicGen(world);
|
||||
final PlotWorld plotworld = generator.getNewPlotWorld(world);
|
||||
SpongeGeneratorWrapper wrapper;
|
||||
if (plotworld.TYPE == 0)
|
||||
{
|
||||
if (plotworld.TYPE == 0) {
|
||||
wrapper = new SpongeGeneratorWrapper(world, generator);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
wrapper = new SpongeGeneratorWrapper(world, null);
|
||||
}
|
||||
PS.get().loadWorld(world, wrapper);
|
||||
switch (plotworld.TYPE)
|
||||
{
|
||||
// Normal
|
||||
case 0:
|
||||
{
|
||||
switch (plotworld.TYPE) {
|
||||
// Normal
|
||||
case 0: {
|
||||
modify = new WorldModify(generator, false);
|
||||
game.getRegistry().registerWorldGeneratorModifier(modify);
|
||||
final Optional<World> builder = game.getRegistry().createWorldBuilder()
|
||||
.name(world)
|
||||
.enabled(true)
|
||||
.loadsOnStartup(true)
|
||||
.keepsSpawnLoaded(true)
|
||||
.dimensionType(DimensionTypes.OVERWORLD)
|
||||
.generator(GeneratorTypes.FLAT)
|
||||
.usesMapFeatures(false)
|
||||
.generatorModifiers(modify)
|
||||
.build();
|
||||
final Optional<World> builder = game.getRegistry().createWorldBuilder().name(world).enabled(true).loadsOnStartup(true).keepsSpawnLoaded(true).dimensionType(DimensionTypes.OVERWORLD)
|
||||
.generator(GeneratorTypes.FLAT).usesMapFeatures(false).generatorModifiers(modify).build();
|
||||
return builder.get();
|
||||
}
|
||||
// Augmented
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
modify = new WorldModify(generator, true);
|
||||
game.getRegistry().registerWorldGeneratorModifier(modify);
|
||||
final Optional<World> builder = game.getRegistry().createWorldBuilder()
|
||||
.name(world)
|
||||
.enabled(true)
|
||||
.loadsOnStartup(true)
|
||||
.keepsSpawnLoaded(true)
|
||||
.dimensionType(DimensionTypes.OVERWORLD)
|
||||
.generator(GeneratorTypes.OVERWORLD)
|
||||
.usesMapFeatures(false)
|
||||
.generatorModifiers(modify)
|
||||
.build();
|
||||
final Optional<World> builder = game.getRegistry().createWorldBuilder().name(world).enabled(true).loadsOnStartup(true).keepsSpawnLoaded(true).dimensionType(DimensionTypes.OVERWORLD)
|
||||
.generator(GeneratorTypes.OVERWORLD).usesMapFeatures(false).generatorModifiers(modify).build();
|
||||
return builder.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerBlock(final PlotBlock block, final BlockState state)
|
||||
{
|
||||
|
||||
public void registerBlock(final PlotBlock block, final BlockState state) {
|
||||
final BlockState[] val = blockMap[block.id];
|
||||
if (val == null)
|
||||
{
|
||||
if (val == null) {
|
||||
blockMap[block.id] = new BlockState[block.data + 1];
|
||||
}
|
||||
else if (val.length <= block.data)
|
||||
{
|
||||
} else if (val.length <= block.data) {
|
||||
blockMap[block.id] = Arrays.copyOf(val, block.data + 1);
|
||||
} else if (val[block.data] != null) {
|
||||
return;
|
||||
}
|
||||
else if (val[block.data] != null) { return; }
|
||||
blockMap[block.id][block.data] = state;
|
||||
blockMapReverse.put(state, block);
|
||||
}
|
||||
|
||||
public PlotBlock registerBlock(final BlockState state)
|
||||
{
|
||||
|
||||
public PlotBlock registerBlock(final BlockState state) {
|
||||
final PlotBlock val = blockMapReverse.get(state);
|
||||
if (val != null) { return val; }
|
||||
if (val != null) {
|
||||
return val;
|
||||
}
|
||||
byte data;
|
||||
if (blockMap[0] == null)
|
||||
{
|
||||
if (blockMap[0] == null) {
|
||||
blockMap[0] = new BlockState[1];
|
||||
data = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
data = (byte) (blockMap[0].length);
|
||||
}
|
||||
final PlotBlock block = new PlotBlock((short) 0, data);
|
||||
registerBlock(block, state);
|
||||
return block;
|
||||
}
|
||||
|
||||
public void registerBlocks()
|
||||
{
|
||||
|
||||
public void registerBlocks() {
|
||||
blockMap = new BlockState[256][];
|
||||
blockMapReverse = new HashMap<BlockState, PlotBlock>();
|
||||
final HashMap<String, BlockState> states = new HashMap<>();
|
||||
|
||||
|
||||
PS.get().copyFile("ids.txt", "config");
|
||||
PS.get().copyFile("data.txt", "config");
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
try {
|
||||
|
||||
final File id_file = new File(getDirectory(), "config" + File.separator + "ids.txt");
|
||||
final List<String> id_lines = Files.readAllLines(id_file.toPath(), StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
final File data_file = new File(getDirectory(), "config" + File.separator + "data.txt");
|
||||
final List<String> data_lines = Files.readAllLines(data_file.toPath(), StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
Field[] fields = BlockTypes.class.getDeclaredFields();
|
||||
for (final Field field : fields)
|
||||
{
|
||||
for (final Field field : fields) {
|
||||
final BlockType type = (BlockType) field.get(null);
|
||||
final BlockState state = type.getDefaultState();
|
||||
if (state != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (state != null) {
|
||||
try {
|
||||
states.put(type.getId() + ":" + 0, state);
|
||||
}
|
||||
catch (final Exception e)
|
||||
{}
|
||||
} catch (final Exception e) {}
|
||||
}
|
||||
}
|
||||
final String packaze = "org.spongepowered.api.data.type.";
|
||||
for (int i = 0; i < data_lines.size(); i++)
|
||||
{
|
||||
for (int i = 0; i < data_lines.size(); i++) {
|
||||
final String classname = packaze + data_lines.get(i).trim();
|
||||
try
|
||||
{
|
||||
try {
|
||||
final Class<?> clazz = Class.forName(classname);
|
||||
fields = clazz.getDeclaredFields();
|
||||
for (final Field field : fields)
|
||||
{
|
||||
for (final Field field : fields) {
|
||||
final CatalogType type = (CatalogType) field.get(null);
|
||||
final String minecraft_id = type.getId();
|
||||
final BlockState state = states.get(minecraft_id + ":" + 0);
|
||||
if (state == null)
|
||||
{
|
||||
if (state == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Throwable e)
|
||||
{}
|
||||
} catch (final Throwable e) {}
|
||||
}
|
||||
|
||||
|
||||
PlotBlock block = null;
|
||||
for (int i = 0; i < id_lines.size(); i++)
|
||||
{
|
||||
for (int i = 0; i < id_lines.size(); i++) {
|
||||
final String line = id_lines.get(i).trim();
|
||||
switch (i % 3)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
switch (i % 3) {
|
||||
case 0: {
|
||||
block = Configuration.BLOCK.parseString(line);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
case 1: {
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
case 2: {
|
||||
final String minecraft_id = line;
|
||||
final BlockState state = states.remove(minecraft_id + ":" + block.data);
|
||||
if (state == null)
|
||||
{
|
||||
if (state == null) {
|
||||
continue;
|
||||
}
|
||||
registerBlock(block, state);
|
||||
@ -449,313 +373,262 @@ public class SpongeMain implements IPlotMain, PluginContainer
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Entry<String, BlockState> state : states.entrySet())
|
||||
{
|
||||
for (final Entry<String, BlockState> state : states.entrySet()) {
|
||||
log("REGISTERING: " + registerBlock(state.getValue()) + " | " + state.getValue().getType());
|
||||
}
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onPlayerChat(final PlayerChatEvent event)
|
||||
{
|
||||
public void onPlayerChat(final PlayerChatEvent event) {
|
||||
// This is how events sort of work?
|
||||
final Player player = event.getUser();
|
||||
log(player.getWorld().getName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void log(String message)
|
||||
{
|
||||
public void log(String message) {
|
||||
message = C.format(message, C.replacements);
|
||||
if (!Settings.CONSOLE_COLOR)
|
||||
{
|
||||
if (!Settings.CONSOLE_COLOR) {
|
||||
message = message.replaceAll('\u00a7' + "[a-z|0-9]", "");
|
||||
}
|
||||
if ((server == null) || (server.getConsole() == null))
|
||||
{
|
||||
if ((server == null) || (server.getConsole() == null)) {
|
||||
logger.info(message);
|
||||
return;
|
||||
}
|
||||
server.getConsole().sendMessage(Texts.of(message));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public File getDirectory()
|
||||
{
|
||||
public File getDirectory() {
|
||||
return new File("mods/PlotSquared");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public File getWorldContainer() {
|
||||
return new File("world");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
PS.get().disable();
|
||||
THIS = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getPluginVersion()
|
||||
{
|
||||
public int[] getPluginVersion() {
|
||||
final PluginContainer plugin = game.getPluginManager().getPlugin("PlotSquared").get();
|
||||
final String version = plugin.getVersion();
|
||||
log("Checking plugin version: PlotSquared: ");
|
||||
final 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 int[] getServerVersion()
|
||||
{
|
||||
public int[] getServerVersion() {
|
||||
log("Checking minecraft version: Sponge: ");
|
||||
final String version = game.getPlatform().getMinecraftVersion().getName();
|
||||
final 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()
|
||||
{
|
||||
public InventoryUtil initInventoryUtil() {
|
||||
return new SpongeInventoryUtil();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SpongeGeneratorWrapper getGenerator(final String world, final String name)
|
||||
{
|
||||
if (name == null) { return new SpongeGeneratorWrapper(world, null); }
|
||||
if (name.equals("PlotSquared"))
|
||||
{
|
||||
return new SpongeGeneratorWrapper(world, new SpongeBasicGen(world));
|
||||
public SpongeGeneratorWrapper getGenerator(final String world, final String name) {
|
||||
if (name == null) {
|
||||
return new SpongeGeneratorWrapper(world, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (name.equals("PlotSquared")) {
|
||||
return new SpongeGeneratorWrapper(world, new SpongeBasicGen(world));
|
||||
} else {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EconHandler getEconomyHandler()
|
||||
{
|
||||
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()
|
||||
{
|
||||
public BlockManager initBlockManager() {
|
||||
return new SpongeBlockManager();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EventUtil initEventUtil()
|
||||
{
|
||||
public EventUtil initEventUtil() {
|
||||
return new SpongeEventUtil();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ChunkManager initChunkManager()
|
||||
{
|
||||
public ChunkManager initChunkManager() {
|
||||
return new SpongeChunkManager();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SetupUtils initSetupUtils()
|
||||
{
|
||||
public SetupUtils initSetupUtils() {
|
||||
return new SpongeSetupUtils();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HybridUtils initHybridUtils()
|
||||
{
|
||||
public HybridUtils initHybridUtils() {
|
||||
return new SpongeHybridUtils();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SchematicHandler initSchematicHandler()
|
||||
{
|
||||
public SchematicHandler initSchematicHandler() {
|
||||
return new SpongeSchematicHandler();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TaskManager getTaskManager()
|
||||
{
|
||||
public TaskManager getTaskManager() {
|
||||
return new SpongeTaskManager();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runEntityTask()
|
||||
{
|
||||
public void runEntityTask() {
|
||||
new KillRoadMobs().run();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerCommands()
|
||||
{
|
||||
public void registerCommands() {
|
||||
getGame().getCommandDispatcher().register(plugin, new SpongeCommand(), new String[] { "plots", "p", "plot", "ps", "plotsquared", "p2", "2" });
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerPlayerEvents()
|
||||
{
|
||||
public void registerPlayerEvents() {
|
||||
game.getEventManager().register(this, new MainListener());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerInventoryEvents()
|
||||
{
|
||||
public void registerInventoryEvents() {
|
||||
// TODO Auto-generated method stub
|
||||
log("registerInventoryEvents is not implemented!");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerPlotPlusEvents()
|
||||
{
|
||||
public void registerPlotPlusEvents() {
|
||||
// TODO Auto-generated method stub
|
||||
log("registerPlotPlusEvents is not implemented!");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerForceFieldEvents()
|
||||
{
|
||||
public void registerForceFieldEvents() {
|
||||
// TODO Auto-generated method stub
|
||||
log("registerForceFieldEvents is not implemented!");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean initWorldEdit()
|
||||
{
|
||||
try
|
||||
{
|
||||
public boolean initWorldEdit() {
|
||||
try {
|
||||
log("CHECKING FOR WORLDEDIT!?");
|
||||
Class.forName("com.sk89q.worldedit.WorldEdit");
|
||||
return true;
|
||||
}
|
||||
catch (final Throwable e)
|
||||
{
|
||||
} catch (final Throwable e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerTNTListener()
|
||||
{
|
||||
public void registerTNTListener() {
|
||||
// TODO Auto-generated method stub
|
||||
log("registerTNTListener is not implemented!");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUIDHandlerImplementation initUUIDHandler()
|
||||
{
|
||||
public UUIDHandlerImplementation initUUIDHandler() {
|
||||
UUIDWrapper wrapper;
|
||||
if (Settings.OFFLINE_MODE || !PS.get().checkVersion(getServerVersion(), 1, 7, 6))
|
||||
{
|
||||
if (Settings.OFFLINE_MODE || !PS.get().checkVersion(getServerVersion(), 1, 7, 6)) {
|
||||
wrapper = new SpongeLowerOfflineUUIDWrapper();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
wrapper = new SpongeOnlineUUIDWrapper();
|
||||
}
|
||||
return new SpongeUUIDHandler(wrapper);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean initPlotMeConverter()
|
||||
{
|
||||
public boolean initPlotMeConverter() {
|
||||
// TODO Auto-generated method stub
|
||||
PS.log("initPlotMeConverter NOT IMPLEMENTED YET");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void unregister(final PlotPlayer player)
|
||||
{
|
||||
public void unregister(final PlotPlayer player) {
|
||||
SpongeUtil.removePlayer(player.getName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerChunkProcessor()
|
||||
{
|
||||
public void registerChunkProcessor() {
|
||||
// TODO Auto-generated method stub
|
||||
PS.log("registerChunkProcessor NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerWorldEvents()
|
||||
{
|
||||
public void registerWorldEvents() {
|
||||
// TODO Auto-generated method stub
|
||||
PS.log("registerWorldEvents NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getServerName()
|
||||
{
|
||||
public String getServerName() {
|
||||
// TODO FIXME
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void startMetrics()
|
||||
{
|
||||
try
|
||||
{
|
||||
public void startMetrics() {
|
||||
try {
|
||||
final SpongeMetrics metrics = new SpongeMetrics(game, this);
|
||||
metrics.start();
|
||||
log(C.PREFIX.s() + "&6Metrics enabled.");
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
log(C.PREFIX.s() + "&cFailed to load up metrics.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setGenerator(final String world)
|
||||
{
|
||||
public void setGenerator(final String world) {
|
||||
// TODO THIS IS DONE DURING STARTUP ALREADY
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractTitle initTitleManager()
|
||||
{
|
||||
public AbstractTitle initTitleManager() {
|
||||
return new SpongeTitleManager();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotPlayer wrapPlayer(final Object obj)
|
||||
{
|
||||
if (obj instanceof Player)
|
||||
{
|
||||
public PlotPlayer wrapPlayer(final Object obj) {
|
||||
if (obj instanceof Player) {
|
||||
return SpongeUtil.getPlayer((Player) obj);
|
||||
}
|
||||
// else if (obj instanceof OfflinePlayer) {
|
||||
// return BukkitUtil.getPlayer((OfflinePlayer) obj);
|
||||
// }
|
||||
else if (obj instanceof String)
|
||||
{
|
||||
else if (obj instanceof String) {
|
||||
return UUIDHandler.getPlayer((String) obj);
|
||||
} else if (obj instanceof UUID) {
|
||||
return UUIDHandler.getPlayer((UUID) obj);
|
||||
}
|
||||
else if (obj instanceof UUID) { return UUIDHandler.getPlayer((UUID) obj); }
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getNMSPackage()
|
||||
{
|
||||
public String getNMSPackage() {
|
||||
return "1_8_R3";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ChatManager<?> initChatManager()
|
||||
{
|
||||
public ChatManager<?> initChatManager() {
|
||||
return new SpongeChatManager();
|
||||
}
|
||||
}
|
||||
|
@ -22,20 +22,16 @@ import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class SpongeSchematicHandler extends SchematicHandler
|
||||
{
|
||||
|
||||
public class SpongeSchematicHandler extends SchematicHandler {
|
||||
|
||||
@Override
|
||||
public void getCompoundTag(final String world, final Location pos1, final Location pos2, final RunnableVal<CompoundTag> whenDone)
|
||||
{
|
||||
|
||||
public void getCompoundTag(final String world, final Location pos1, final Location pos2, final RunnableVal<CompoundTag> whenDone) {
|
||||
|
||||
// async
|
||||
TaskManager.runTaskAsync(new Runnable()
|
||||
{
|
||||
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
// Main positions
|
||||
final int p1x = pos1.getX();
|
||||
final int p1z = pos1.getZ();
|
||||
@ -47,14 +43,14 @@ public class SpongeSchematicHandler extends SchematicHandler
|
||||
final int tcz = p2z >> 4;
|
||||
final int sy = pos1.getY();
|
||||
final int ey = pos2.getY();
|
||||
|
||||
|
||||
final int width = (pos2.getX() - pos1.getX()) + 1;
|
||||
final int height = (pos2.getY() - pos1.getY()) + 1;
|
||||
final int length = (pos2.getZ() - pos1.getZ()) + 1;
|
||||
|
||||
|
||||
// Main Schematic tag
|
||||
final HashMap<String, Tag> schematic = new HashMap<>();
|
||||
|
||||
|
||||
schematic.put("Width", new ShortTag("Width", (short) width));
|
||||
schematic.put("Length", new ShortTag("Length", (short) length));
|
||||
schematic.put("Height", new ShortTag("Height", (short) height));
|
||||
@ -65,87 +61,72 @@ public class SpongeSchematicHandler extends SchematicHandler
|
||||
schematic.put("WEOffsetX", new IntTag("WEOffsetX", 0));
|
||||
schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
|
||||
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
|
||||
|
||||
|
||||
// Arrays of data types
|
||||
final List<Tag> tileEntities = new ArrayList<Tag>();
|
||||
final byte[] blocks = new byte[width * height * length];
|
||||
final byte[] blockData = new byte[width * height * length];
|
||||
|
||||
|
||||
// Generate list of chunks
|
||||
final ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
|
||||
for (int x = bcx; x <= tcx; x++)
|
||||
{
|
||||
for (int z = bcz; z <= tcz; z++)
|
||||
{
|
||||
for (int x = bcx; x <= tcx; x++) {
|
||||
for (int z = bcz; z <= tcz; z++) {
|
||||
chunks.add(new ChunkLoc(x, z));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
// Main thread
|
||||
TaskManager.runTask(new Runnable()
|
||||
{
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
final long start = System.currentTimeMillis();
|
||||
while ((chunks.size() > 0) && ((System.currentTimeMillis() - start) < 20))
|
||||
{
|
||||
while ((chunks.size() > 0) && ((System.currentTimeMillis() - start) < 20)) {
|
||||
// save schematics
|
||||
final ChunkLoc chunk = chunks.remove(0);
|
||||
|
||||
if (!worldObj.loadChunk(chunk.x << 4, 1, chunk.z << 4, false).isPresent())
|
||||
{
|
||||
|
||||
if (!worldObj.loadChunk(chunk.x << 4, 1, chunk.z << 4, false).isPresent()) {
|
||||
System.out.println("COULD NOT LOAD CHUNK AT: " + chunk.x + "," + chunk.z);
|
||||
// TODO continue - right now sponge chunk api seems to be broken :(
|
||||
// continue;
|
||||
}
|
||||
|
||||
|
||||
final int X = chunk.x;
|
||||
final int Z = chunk.z;
|
||||
int xxb = X << 4;
|
||||
int zzb = Z << 4;
|
||||
int xxt = xxb + 15;
|
||||
int zzt = zzb + 15;
|
||||
|
||||
if (X == bcx)
|
||||
{
|
||||
|
||||
if (X == bcx) {
|
||||
xxb = p1x;
|
||||
}
|
||||
if (X == tcx)
|
||||
{
|
||||
if (X == tcx) {
|
||||
xxt = p2x;
|
||||
}
|
||||
if (Z == bcz)
|
||||
{
|
||||
if (Z == bcz) {
|
||||
zzb = p1z;
|
||||
}
|
||||
if (Z == tcz)
|
||||
{
|
||||
if (Z == tcz) {
|
||||
zzt = p2z;
|
||||
}
|
||||
for (int y = sy; y <= Math.min(255, ey); y++)
|
||||
{
|
||||
for (int y = sy; y <= Math.min(255, ey); y++) {
|
||||
final int ry = y - sy;
|
||||
final int i1 = (ry * width * length);
|
||||
for (int z = zzb; z <= zzt; z++)
|
||||
{
|
||||
for (int z = zzb; z <= zzt; z++) {
|
||||
final int rz = z - p1z;
|
||||
final int i2 = i1 + (rz * width);
|
||||
for (int x = xxb; x <= xxt; x++)
|
||||
{
|
||||
for (int x = xxb; x <= xxt; x++) {
|
||||
final int rx = x - p1x;
|
||||
final int index = i2 + rx;
|
||||
|
||||
|
||||
final BlockState state = worldObj.getBlock(x, y, z);
|
||||
PlotBlock block = SpongeMain.THIS.getPlotBlock(state);
|
||||
if (block == null)
|
||||
{
|
||||
if (block == null) {
|
||||
block = SpongeMain.THIS.registerBlock(state);
|
||||
}
|
||||
final int id = block.id;
|
||||
switch (id)
|
||||
{
|
||||
switch (id) {
|
||||
case 0:
|
||||
case 2:
|
||||
case 4:
|
||||
@ -216,8 +197,7 @@ public class SpongeSchematicHandler extends SchematicHandler
|
||||
case 189:
|
||||
case 190:
|
||||
case 191:
|
||||
case 192:
|
||||
{
|
||||
case 192: {
|
||||
break;
|
||||
}
|
||||
case 54:
|
||||
@ -254,13 +234,11 @@ public class SpongeSchematicHandler extends SchematicHandler
|
||||
case 29:
|
||||
case 33:
|
||||
case 151:
|
||||
case 178:
|
||||
{
|
||||
case 178: {
|
||||
// TODO wrap block state...
|
||||
// TODO add block state to map
|
||||
}
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
blockData[index] = block.data;
|
||||
}
|
||||
}
|
||||
@ -268,19 +246,14 @@ public class SpongeSchematicHandler extends SchematicHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (chunks.size() != 0)
|
||||
{
|
||||
if (chunks.size() != 0) {
|
||||
TaskManager.runTaskLater(this, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
TaskManager.runTaskAsync(new Runnable()
|
||||
{
|
||||
} else {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
|
||||
schematic.put("Data", new ByteArrayTag("Data", blockData));
|
||||
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
|
||||
@ -297,5 +270,5 @@ public class SpongeSchematicHandler extends SchematicHandler
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,76 +19,70 @@ import com.plotsquared.sponge.generator.SpongeGeneratorWrapper;
|
||||
import com.plotsquared.sponge.generator.SpongePlotGenerator;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class SpongeSetupUtils extends SetupUtils
|
||||
{
|
||||
|
||||
public class SpongeSetupUtils extends SetupUtils {
|
||||
|
||||
@Override
|
||||
public void updateGenerators()
|
||||
{
|
||||
if (SetupUtils.generators.size() > 0) { return; }
|
||||
public void updateGenerators() {
|
||||
if (SetupUtils.generators.size() > 0) {
|
||||
return;
|
||||
}
|
||||
// TODO get external world generators
|
||||
final String testWorld = "CheckingPlotSquaredGenerator";
|
||||
SetupUtils.generators.put("PlotSquared", new SpongeGeneratorWrapper(testWorld, new SpongeBasicGen(testWorld)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getGenerator(final PlotWorld plotworld)
|
||||
{
|
||||
if (SetupUtils.generators.size() == 0)
|
||||
{
|
||||
public String getGenerator(final PlotWorld plotworld) {
|
||||
if (SetupUtils.generators.size() == 0) {
|
||||
updateGenerators();
|
||||
}
|
||||
final World world = SpongeUtil.getWorld(plotworld.worldname);
|
||||
if (world == null) { return null; }
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
final WorldGenerator generator = world.getWorldGenerator();
|
||||
if (!(generator instanceof SpongePlotGenerator)) { return null; }
|
||||
for (final Entry<String, PlotGenerator<?>> entry : generators.entrySet())
|
||||
{
|
||||
if (entry.getValue().generator.getClass().getName().equals(generator.getClass().getName())) { return entry.getKey(); }
|
||||
if (!(generator instanceof SpongePlotGenerator)) {
|
||||
return null;
|
||||
}
|
||||
for (final Entry<String, PlotGenerator<?>> entry : generators.entrySet()) {
|
||||
if (entry.getValue().generator.getClass().getName().equals(generator.getClass().getName())) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String setupWorld(final SetupObject object)
|
||||
{
|
||||
public String setupWorld(final SetupObject object) {
|
||||
SetupUtils.manager.updateGenerators();
|
||||
final ConfigurationNode[] steps = object.step;
|
||||
final String world = object.world;
|
||||
for (final ConfigurationNode step : steps)
|
||||
{
|
||||
for (final ConfigurationNode step : steps) {
|
||||
PS.get().config.set("worlds." + world + "." + step.getConstant(), step.getValue());
|
||||
}
|
||||
if (object.type != 0)
|
||||
{
|
||||
if (object.type != 0) {
|
||||
PS.get().config.set("worlds." + world + "." + "generator.type", object.type);
|
||||
PS.get().config.set("worlds." + world + "." + "generator.terrain", object.terrain);
|
||||
PS.get().config.set("worlds." + world + "." + "generator.plugin", object.plotManager);
|
||||
if ((object.setupGenerator != null) && !object.setupGenerator.equals(object.plotManager))
|
||||
{
|
||||
if ((object.setupGenerator != null) && !object.setupGenerator.equals(object.plotManager)) {
|
||||
PS.get().config.set("worlds." + world + "." + "generator.init", object.setupGenerator);
|
||||
}
|
||||
final PlotGenerator<WorldGenerator> gen = (PlotGenerator<WorldGenerator>) generators.get(object.setupGenerator);
|
||||
if ((gen != null) && (gen.generator instanceof SpongePlotGenerator))
|
||||
{
|
||||
if ((gen != null) && (gen.generator instanceof SpongePlotGenerator)) {
|
||||
object.setupGenerator = null;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SpongeMain.THIS.createWorldFromConfig(world);
|
||||
return object.world;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removePopulator(final String world, final PlotCluster cluster)
|
||||
{
|
||||
public void removePopulator(final String world, final PlotCluster cluster) {
|
||||
AugmentedPopulator.removePopulator(world, cluster);
|
||||
}
|
||||
}
|
||||
|
@ -6,48 +6,42 @@ 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
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
public ClusterFlagRemoveEvent(final Flag flag, final PlotCluster cluster) {
|
||||
this.cluster = cluster;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the cluster involved
|
||||
*
|
||||
* @return PlotCluster
|
||||
*/
|
||||
public PlotCluster getCluster()
|
||||
{
|
||||
public PlotCluster getCluster() {
|
||||
return cluster;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag()
|
||||
{
|
||||
public Flag getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
|
@ -5,53 +5,47 @@ import org.spongepowered.api.event.Cancellable;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true if it was an automated claim, else false
|
||||
*/
|
||||
public boolean wasAuto()
|
||||
{
|
||||
public boolean wasAuto() {
|
||||
return auto;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
|
@ -4,30 +4,27 @@ import org.spongepowered.api.entity.player.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerEnterPlotEvent extends PlayerEvent
|
||||
{
|
||||
|
||||
public class PlayerEnterPlotEvent extends PlayerEvent {
|
||||
|
||||
private final Plot plot;
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
public PlayerEnterPlotEvent(final Player player, final Plot plot) {
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot()
|
||||
{
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
}
|
||||
|
@ -3,19 +3,16 @@ 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 abstract class PlayerEvent extends AbstractEvent {
|
||||
|
||||
public final Player player;
|
||||
|
||||
public PlayerEvent(final Player player)
|
||||
{
|
||||
|
||||
public PlayerEvent(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,30 +4,27 @@ import org.spongepowered.api.entity.player.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerLeavePlotEvent extends PlayerEvent
|
||||
{
|
||||
|
||||
public class PlayerLeavePlotEvent extends PlayerEvent {
|
||||
|
||||
private final Plot plot;
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
public PlayerLeavePlotEvent(final Player player, final Plot plot) {
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot()
|
||||
{
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,12 @@ import org.spongepowered.api.entity.player.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerPlotDeniedEvent extends PlotEvent
|
||||
{
|
||||
|
||||
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
|
||||
*
|
||||
@ -21,41 +20,37 @@ public class PlayerPlotDeniedEvent extends PlotEvent
|
||||
* @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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public boolean wasAdded() {
|
||||
return added;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The player added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer()
|
||||
{
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator()
|
||||
{
|
||||
public Player getInitiator() {
|
||||
return initiator;
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,12 @@ import org.spongepowered.api.entity.player.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerPlotHelperEvent extends PlotEvent
|
||||
{
|
||||
|
||||
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
|
||||
*
|
||||
@ -21,41 +20,37 @@ public class PlayerPlotHelperEvent extends PlotEvent
|
||||
* @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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public boolean wasAdded() {
|
||||
return added;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The player added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer()
|
||||
{
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator()
|
||||
{
|
||||
public Player getInitiator() {
|
||||
return initiator;
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,12 @@ import org.spongepowered.api.entity.player.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public class PlayerPlotTrustedEvent extends PlotEvent
|
||||
{
|
||||
|
||||
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
|
||||
*
|
||||
@ -21,41 +20,37 @@ public class PlayerPlotTrustedEvent extends PlotEvent
|
||||
* @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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public boolean wasAdded() {
|
||||
return added;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The player added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer()
|
||||
{
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator()
|
||||
{
|
||||
public Player getInitiator() {
|
||||
return initiator;
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,12 @@ 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
|
||||
{
|
||||
|
||||
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
|
||||
*
|
||||
@ -20,42 +19,37 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl
|
||||
* @param from Start location
|
||||
* @param plot Plot to which the player was teleported
|
||||
*/
|
||||
public PlayerTeleportToPlotEvent(final Player player, final Location from, final Plot plot)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public Location getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot()
|
||||
{
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
|
@ -5,53 +5,47 @@ import org.spongepowered.api.event.Cancellable;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public class PlotClearEvent extends AbstractEvent implements Cancellable
|
||||
{
|
||||
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)
|
||||
{
|
||||
public PlotClearEvent(final String world, final PlotId id) {
|
||||
this.id = id;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the PlotId
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
public PlotId getPlotId()
|
||||
{
|
||||
public PlotId getPlotId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the world name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getWorld()
|
||||
{
|
||||
public String getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
|
@ -4,40 +4,36 @@ import org.spongepowered.api.event.AbstractEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public class PlotDeleteEvent extends AbstractEvent
|
||||
{
|
||||
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)
|
||||
{
|
||||
public PlotDeleteEvent(final String world, final PlotId id) {
|
||||
this.id = id;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the PlotId
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
public PlotId getPlotId()
|
||||
{
|
||||
public PlotId getPlotId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the world name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getWorld()
|
||||
{
|
||||
public String getWorld() {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
|
@ -4,19 +4,16 @@ import org.spongepowered.api.event.AbstractEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public abstract class PlotEvent extends AbstractEvent
|
||||
{
|
||||
|
||||
public abstract class PlotEvent extends AbstractEvent {
|
||||
|
||||
private final Plot plot;
|
||||
|
||||
public PlotEvent(final Plot plot)
|
||||
{
|
||||
|
||||
public PlotEvent(final Plot plot) {
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
public final Plot getPlot()
|
||||
{
|
||||
|
||||
public final Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,42 +5,37 @@ 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
|
||||
{
|
||||
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)
|
||||
{
|
||||
public PlotFlagAddEvent(final Flag flag, final Plot plot) {
|
||||
super(plot);
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag()
|
||||
{
|
||||
public Flag getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
|
@ -5,42 +5,37 @@ 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
|
||||
{
|
||||
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)
|
||||
{
|
||||
public PlotFlagRemoveEvent(final Flag flag, final Plot plot) {
|
||||
super(plot);
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag()
|
||||
{
|
||||
public Flag getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,12 @@ 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
|
||||
{
|
||||
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
|
||||
*
|
||||
@ -23,45 +22,39 @@ public class PlotMergeEvent extends AbstractEvent implements Cancellable
|
||||
* @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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public ArrayList<PlotId> getPlots() {
|
||||
return plots;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the main plot
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot()
|
||||
{
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
|
@ -4,30 +4,25 @@ import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
|
||||
public class PlotRateEvent extends PlotEvent
|
||||
{
|
||||
public class PlotRateEvent extends PlotEvent {
|
||||
private final PlotPlayer rater;
|
||||
private Rating rating;
|
||||
|
||||
public PlotRateEvent(final PlotPlayer rater, final Rating rating, final Plot plot)
|
||||
{
|
||||
|
||||
public PlotRateEvent(final PlotPlayer rater, final Rating rating, final Plot plot) {
|
||||
super(plot);
|
||||
this.rater = rater;
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
public PlotPlayer getRater()
|
||||
{
|
||||
|
||||
public PlotPlayer getRater() {
|
||||
return rater;
|
||||
}
|
||||
|
||||
public void setRating(final Rating rating)
|
||||
{
|
||||
|
||||
public void setRating(final Rating rating) {
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
public Rating getRating()
|
||||
{
|
||||
|
||||
public Rating getRating() {
|
||||
return rating;
|
||||
}
|
||||
}
|
||||
|
@ -8,48 +8,42 @@ import org.spongepowered.api.world.World;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public class PlotUnlinkEvent extends AbstractEvent implements Cancellable
|
||||
{
|
||||
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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public ArrayList<PlotId> getPlots() {
|
||||
return plots;
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,8 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class AugmentedPopulator implements Populator
|
||||
{
|
||||
|
||||
public class AugmentedPopulator implements Populator {
|
||||
|
||||
public final PlotWorld plotworld;
|
||||
public final PlotManager manager;
|
||||
public final SpongePlotGenerator generator;
|
||||
@ -49,9 +48,8 @@ public class AugmentedPopulator implements Populator
|
||||
private final int bz;
|
||||
private final int tx;
|
||||
private final int tz;
|
||||
|
||||
public AugmentedPopulator(final String worldname, final WorldGenerator gen, final SpongePlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b)
|
||||
{
|
||||
|
||||
public AugmentedPopulator(final String worldname, final WorldGenerator gen, final SpongePlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b) {
|
||||
// MainUtil.initCache();
|
||||
// Initialize any chach that's needed
|
||||
this.cluster = cluster;
|
||||
@ -62,17 +60,14 @@ public class AugmentedPopulator implements Populator
|
||||
this.p = p;
|
||||
this.b = b;
|
||||
o = (plotworld.TERRAIN == 1) || (plotworld.TERRAIN == 2);
|
||||
if (cluster != null)
|
||||
{
|
||||
if (cluster != null) {
|
||||
final Location bl = manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
|
||||
final Location tl = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1, 0, 1);
|
||||
bx = bl.getX();
|
||||
bz = bl.getZ();
|
||||
tx = tl.getX();
|
||||
tz = tl.getZ();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
bx = Integer.MIN_VALUE;
|
||||
bz = Integer.MIN_VALUE;
|
||||
tx = Integer.MAX_VALUE;
|
||||
@ -80,36 +75,28 @@ public class AugmentedPopulator implements Populator
|
||||
}
|
||||
// Add the populator
|
||||
final List<Populator> populators = gen.getPopulators();
|
||||
if (o)
|
||||
{
|
||||
if (o) {
|
||||
populators.add(0, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
populators.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removePopulator(final String worldname, final PlotCluster cluster)
|
||||
{
|
||||
|
||||
public static void removePopulator(final String worldname, final PlotCluster cluster) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final List<Populator> populators = world.getWorldGenerator().getPopulators();
|
||||
for (final Iterator<Populator> iterator = populators.iterator(); iterator.hasNext();)
|
||||
{
|
||||
for (final Iterator<Populator> iterator = populators.iterator(); iterator.hasNext();) {
|
||||
final Populator populator = iterator.next();
|
||||
if (populator instanceof AugmentedPopulator)
|
||||
{
|
||||
if (((AugmentedPopulator) populator).cluster.equals(cluster))
|
||||
{
|
||||
if (populator instanceof AugmentedPopulator) {
|
||||
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void populate(final Chunk chunk, final Random r_unused)
|
||||
{
|
||||
public void populate(final Chunk chunk, final Random r_unused) {
|
||||
final Vector3i min = chunk.getBlockMin();
|
||||
final World worldObj = chunk.getWorld();
|
||||
final String world = worldObj.getName();
|
||||
@ -125,29 +112,23 @@ public class AugmentedPopulator implements Populator
|
||||
final boolean inZ2 = ((tz >= this.bz) && (tz <= this.tz));
|
||||
final boolean inX = inX1 || inX2;
|
||||
final boolean inZ = inZ1 || inZ2;
|
||||
if (!inX || !inZ) { return; }
|
||||
if (plotworld.TERRAIN == 3)
|
||||
{
|
||||
if (!inX || !inZ) {
|
||||
return;
|
||||
}
|
||||
if (plotworld.TERRAIN == 3) {
|
||||
final int X = min.getX();
|
||||
final int Z = min.getZ();
|
||||
if (ChunkManager.FORCE_PASTE)
|
||||
{
|
||||
for (short x = 0; x < 16; x++)
|
||||
{
|
||||
for (short z = 0; z < 16; z++)
|
||||
{
|
||||
if (ChunkManager.FORCE_PASTE) {
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z));
|
||||
final HashMap<Short, Short> blocks = ChunkManager.GENERATE_BLOCKS.get(loc);
|
||||
final HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(loc);
|
||||
for (final Entry<Short, Short> entry : blocks.entrySet())
|
||||
{
|
||||
for (final Entry<Short, Short> entry : blocks.entrySet()) {
|
||||
final int y = entry.getKey();
|
||||
if (datas != null)
|
||||
{
|
||||
if (datas != null) {
|
||||
SetBlockQueue.setBlock(world, x, y, z, new PlotBlock(blocks.get(y), datas.get(y)));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SetBlockQueue.setBlock(world, x, y, z, blocks.get(y));
|
||||
}
|
||||
}
|
||||
@ -155,31 +136,23 @@ public class AugmentedPopulator implements Populator
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null)
|
||||
{
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
|
||||
PlotLoc loc;
|
||||
for (final Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet())
|
||||
{
|
||||
for (final Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet()) {
|
||||
final HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(entry.getKey());
|
||||
for (final Entry<Short, Byte> entry2 : entry.getValue().entrySet())
|
||||
{
|
||||
for (final Entry<Short, Byte> entry2 : entry.getValue().entrySet()) {
|
||||
final Short y = entry2.getKey();
|
||||
byte data;
|
||||
if (datas != null)
|
||||
{
|
||||
if (datas != null) {
|
||||
data = datas.get(y);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
data = 0;
|
||||
}
|
||||
loc = entry.getKey();
|
||||
final int xx = loc.x - X;
|
||||
final int zz = loc.z - Z;
|
||||
if ((xx >= 0) && (xx < 16))
|
||||
{
|
||||
if ((zz >= 0) && (zz < 16))
|
||||
{
|
||||
if ((xx >= 0) && (xx < 16)) {
|
||||
if ((zz >= 0) && (zz < 16)) {
|
||||
SetBlockQueue.setBlock(world, xx, y, zz, new PlotBlock(entry2.getValue(), data));
|
||||
}
|
||||
}
|
||||
@ -190,208 +163,172 @@ public class AugmentedPopulator implements Populator
|
||||
}
|
||||
final boolean check;
|
||||
check = !inX1 || !inX2 || !inZ1 || !inZ2;
|
||||
if (plotworld.TERRAIN > 1)
|
||||
{
|
||||
if (plotworld.TERRAIN > 1) {
|
||||
final PlotId plot1 = manager.getPlotIdAbs(plotworld, bx, 0, bz);
|
||||
final PlotId plot2 = manager.getPlotIdAbs(plotworld, tx, 0, tz);
|
||||
if ((plot1 != null) && (plot2 != null) && plot1.equals(plot2)) { return; }
|
||||
if ((plot1 != null) && (plot2 != null) && plot1.equals(plot2)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (o)
|
||||
{
|
||||
if (o) {
|
||||
populateBlocks(worldObj, chunk, cx, cz, bx, bz, check);
|
||||
}
|
||||
else
|
||||
{
|
||||
TaskManager.runTaskLater(new Runnable()
|
||||
{
|
||||
} else {
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
// TODO populate biome
|
||||
}
|
||||
}, 20 + r.nextInt(10));
|
||||
TaskManager.runTaskLater(new Runnable()
|
||||
{
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
populateBlocks(worldObj, chunk, cx, cz, bx, bz, check);
|
||||
}
|
||||
}, 40 + r.nextInt(40));
|
||||
}
|
||||
}
|
||||
|
||||
private void populateBlocks(final World world, final Chunk chunk, final int X, final int Z, final int x, final int z, final boolean check)
|
||||
{
|
||||
|
||||
private void populateBlocks(final World world, final Chunk chunk, final int X, final int Z, final int x, final int z, final boolean check) {
|
||||
final String worldname = world.getName();
|
||||
final MutableBlockVolume blocks = new MutableBlockVolume()
|
||||
{
|
||||
final MutableBlockVolume blocks = new MutableBlockVolume() {
|
||||
@Override
|
||||
public void setBlock(final int x, final int y, final int z, final BlockState t)
|
||||
{
|
||||
public void setBlock(final int x, final int y, final int z, final BlockState t) {
|
||||
if (check && (((z) < bz) || ((z) > tz) || ((x) < bx) || ((x) > tx))) {
|
||||
return;
|
||||
}
|
||||
if (p)
|
||||
{
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null)
|
||||
{
|
||||
if (p) {
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR.isIn(x, z)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (manager.getPlotIdAbs(plotworld, x, 0, z) != null) {
|
||||
} else if (manager.getPlotIdAbs(plotworld, x, 0, z) != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final PlotBlock block = SpongeMain.THIS.getPlotBlock(t);
|
||||
if (block != null)
|
||||
{
|
||||
if (block != null) {
|
||||
SetBlockQueue.setBlock(worldname, x, y, z, block);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBlock(final Vector3i v, final BlockState t)
|
||||
{
|
||||
public void setBlock(final Vector3i v, final BlockState t) {
|
||||
setBlock(v.getX(), v.getY(), v.getZ(), t);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockType getBlockType(final int x, final int y, final int z)
|
||||
{
|
||||
public BlockType getBlockType(final int x, final int y, final int z) {
|
||||
return world.getBlockType(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockType getBlockType(final Vector3i v)
|
||||
{
|
||||
public BlockType getBlockType(final Vector3i v) {
|
||||
return getBlockType(v.getX(), v.getY(), v.getZ());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vector3i getBlockSize()
|
||||
{
|
||||
public Vector3i getBlockSize() {
|
||||
return chunk.getBlockSize();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vector3i getBlockMin()
|
||||
{
|
||||
public Vector3i getBlockMin() {
|
||||
return chunk.getBlockMin();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vector3i getBlockMax()
|
||||
{
|
||||
public Vector3i getBlockMax() {
|
||||
return chunk.getBlockMax();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(final int x, final int y, final int z)
|
||||
{
|
||||
public BlockState getBlock(final int x, final int y, final int z) {
|
||||
return world.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(final Vector3i v)
|
||||
{
|
||||
public BlockState getBlock(final Vector3i v) {
|
||||
return getBlock(v.getX(), v.getY(), v.getZ());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean containsBlock(final int x, final int y, final int z)
|
||||
{
|
||||
public boolean containsBlock(final int x, final int y, final int z) {
|
||||
return ((x) >= bz) && ((z) <= tz) && ((x) >= bx) && ((z) <= tx);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean containsBlock(final Vector3i v)
|
||||
{
|
||||
public boolean containsBlock(final Vector3i v) {
|
||||
return containsBlock(v.getX(), v.getY(), v.getZ());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBlockType(final int x, final int y, final int z, final BlockType t)
|
||||
{
|
||||
public void setBlockType(final int x, final int y, final int z, final BlockType t) {
|
||||
if (check && (((z) < bz) || ((z) > tz) || ((x) < bx) || ((x) > tx))) {
|
||||
return;
|
||||
}
|
||||
if (p)
|
||||
{
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null)
|
||||
{
|
||||
if (p) {
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR.isIn(x, z)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (manager.getPlotIdAbs(plotworld, x, 0, z) != null) {
|
||||
} else if (manager.getPlotIdAbs(plotworld, x, 0, z) != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final PlotBlock block = SpongeMain.THIS.getPlotBlock(t.getDefaultState());
|
||||
if (block != null)
|
||||
{
|
||||
if (block != null) {
|
||||
SetBlockQueue.setBlock(worldname, x, y, z, block);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBlockType(final Vector3i v, final BlockType t)
|
||||
{
|
||||
public void setBlockType(final Vector3i v, final BlockType t) {
|
||||
setBlockType(v.getX(), v.getY(), v.getZ(), t);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MutableBlockVolume getBlockCopy()
|
||||
{
|
||||
public MutableBlockVolume getBlockCopy() {
|
||||
// TODO Auto-generated method stub
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MutableBlockVolume getBlockCopy(final StorageType arg0)
|
||||
{
|
||||
public MutableBlockVolume getBlockCopy(final StorageType arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ImmutableBlockVolume getImmutableBlockCopy()
|
||||
{
|
||||
public ImmutableBlockVolume getImmutableBlockCopy() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UnmodifiableBlockVolume getUnmodifiableBlockView()
|
||||
{
|
||||
public UnmodifiableBlockVolume getUnmodifiableBlockView() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MutableBlockVolume getBlockView(final DiscreteTransform3 arg0)
|
||||
{
|
||||
public MutableBlockVolume getBlockView(final DiscreteTransform3 arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MutableBlockVolume getBlockView(final Vector3i arg0, final Vector3i arg1)
|
||||
{
|
||||
public MutableBlockVolume getBlockView(final Vector3i arg0, final Vector3i arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MutableBlockVolume getRelativeBlockView()
|
||||
{
|
||||
public MutableBlockVolume getRelativeBlockView() {
|
||||
// TODO Auto-generated method stub
|
||||
return this;
|
||||
}
|
||||
};
|
||||
populator.populate(world, blocks, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,38 +8,30 @@ import org.spongepowered.api.world.gen.BiomeGenerator;
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
|
||||
public class SpongeBasicBiomeProvider implements BiomeGenerator
|
||||
{
|
||||
|
||||
public class SpongeBasicBiomeProvider implements BiomeGenerator {
|
||||
|
||||
private final PlotWorld plotworld;
|
||||
|
||||
public SpongeBasicBiomeProvider(final PlotWorld plotworld)
|
||||
{
|
||||
|
||||
public SpongeBasicBiomeProvider(final PlotWorld plotworld) {
|
||||
this.plotworld = plotworld;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateBiomes(final MutableBiomeArea biomeBase)
|
||||
{
|
||||
public void generateBiomes(final MutableBiomeArea biomeBase) {
|
||||
final Vector2i min = biomeBase.getBiomeMin();
|
||||
final int bx = min.getX();
|
||||
final int bz = min.getY();
|
||||
BiomeType biome = BiomeTypes.FOREST;
|
||||
try
|
||||
{
|
||||
try {
|
||||
biome = (BiomeType) BiomeTypes.class.getField(plotworld.PLOT_BIOME.toUpperCase()).get(null);
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (int x = bx; x < (bx + 16); x++)
|
||||
{
|
||||
for (int z = bz; z < (bz + 16); z++)
|
||||
{
|
||||
for (int x = bx; x < (bx + 16); x++) {
|
||||
for (int z = bz; z < (bz + 16); z++) {
|
||||
biomeBase.setBiome(x, z, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -14,19 +14,17 @@ import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeBasicGen extends SpongePlotGenerator
|
||||
{
|
||||
|
||||
public class SpongeBasicGen extends SpongePlotGenerator {
|
||||
|
||||
public final BlockState AIR = BlockTypes.AIR.getDefaultState();
|
||||
|
||||
|
||||
private static HybridPlotManager manager;
|
||||
public HybridPlotWorld plotworld;
|
||||
|
||||
public SpongeBasicGen(final String world)
|
||||
{
|
||||
|
||||
public SpongeBasicGen(final String world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Some generator specific variables (implementation dependent)
|
||||
*
|
||||
@ -42,18 +40,16 @@ public class SpongeBasicGen extends SpongePlotGenerator
|
||||
public short pathWidthLower;
|
||||
public short pathWidthUpper;
|
||||
public boolean doState = false;
|
||||
|
||||
|
||||
BlockState wall;
|
||||
BlockState wallfilling;
|
||||
BlockState roadblock;
|
||||
BlockState[] plotfloors;
|
||||
BlockState[] filling;
|
||||
|
||||
|
||||
@Override
|
||||
public void init(final PlotWorld plotworld)
|
||||
{
|
||||
if (plotworld != null)
|
||||
{
|
||||
public void init(final PlotWorld plotworld) {
|
||||
if (plotworld != null) {
|
||||
this.plotworld = (HybridPlotWorld) plotworld;
|
||||
}
|
||||
plotsize = this.plotworld.PLOT_WIDTH;
|
||||
@ -62,96 +58,77 @@ public class SpongeBasicGen extends SpongePlotGenerator
|
||||
wallheight = this.plotworld.WALL_HEIGHT;
|
||||
roadheight = this.plotworld.ROAD_HEIGHT;
|
||||
plotheight = this.plotworld.PLOT_HEIGHT;
|
||||
if (pathsize == 0)
|
||||
{
|
||||
if (pathsize == 0) {
|
||||
pathWidthLower = (short) -1;
|
||||
pathWidthUpper = (short) (plotsize + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pathsize % 2) == 0)
|
||||
{
|
||||
} else {
|
||||
if ((pathsize % 2) == 0) {
|
||||
pathWidthLower = (short) (Math.floor(pathsize / 2) - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pathWidthLower = (short) (Math.floor(pathsize / 2));
|
||||
}
|
||||
pathWidthUpper = (short) (pathWidthLower + plotsize + 1);
|
||||
}
|
||||
|
||||
|
||||
roadblock = SpongeMain.THIS.getBlockState(this.plotworld.ROAD_BLOCK);
|
||||
wallfilling = SpongeMain.THIS.getBlockState(this.plotworld.WALL_FILLING);
|
||||
wall = SpongeMain.THIS.getBlockState(this.plotworld.WALL_BLOCK);
|
||||
plotfloors = new BlockState[this.plotworld.TOP_BLOCK.length];
|
||||
for (int i = 0; i < this.plotworld.TOP_BLOCK.length; i++)
|
||||
{
|
||||
for (int i = 0; i < this.plotworld.TOP_BLOCK.length; i++) {
|
||||
plotfloors[i] = SpongeMain.THIS.getBlockState(this.plotworld.TOP_BLOCK[i]);
|
||||
}
|
||||
filling = new BlockState[this.plotworld.MAIN_BLOCK.length];
|
||||
for (int i = 0; i < this.plotworld.MAIN_BLOCK.length; i++)
|
||||
{
|
||||
for (int i = 0; i < this.plotworld.MAIN_BLOCK.length; i++) {
|
||||
filling[i] = SpongeMain.THIS.getBlockState(this.plotworld.MAIN_BLOCK[i]);
|
||||
}
|
||||
if ((filling.length > 1) || (plotfloors.length > 1))
|
||||
{
|
||||
if ((filling.length > 1) || (plotfloors.length > 1)) {
|
||||
doState = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotWorld getNewPlotWorld(final String world)
|
||||
{
|
||||
if (plotworld == null)
|
||||
{
|
||||
public PlotWorld getNewPlotWorld(final String world) {
|
||||
if (plotworld == null) {
|
||||
plotworld = (HybridPlotWorld) PS.get().getPlotWorld(world);
|
||||
if (plotworld == null)
|
||||
{
|
||||
if (plotworld == null) {
|
||||
plotworld = new HybridPlotWorld(world);
|
||||
}
|
||||
}
|
||||
return plotworld;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotManager getPlotManager()
|
||||
{
|
||||
if (SpongeBasicGen.manager == null)
|
||||
{
|
||||
public PlotManager getPlotManager() {
|
||||
if (SpongeBasicGen.manager == null) {
|
||||
SpongeBasicGen.manager = new HybridPlotManager();
|
||||
}
|
||||
return SpongeBasicGen.manager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<SpongePlotPopulator> getPlotPopulators()
|
||||
{
|
||||
public List<SpongePlotPopulator> getPlotPopulators() {
|
||||
// TODO Auto-generated method stub
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
private SpongeBasicPop generator;
|
||||
|
||||
|
||||
@Override
|
||||
public SpongePlotPopulator getGenerator()
|
||||
{
|
||||
if (generator == null)
|
||||
{
|
||||
public SpongePlotPopulator getGenerator() {
|
||||
if (generator == null) {
|
||||
generator = new SpongeBasicPop(this);
|
||||
}
|
||||
return generator;
|
||||
}
|
||||
|
||||
|
||||
private BiomeGenerator biome;
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeGenerator getPlotBiomeProvider()
|
||||
{
|
||||
if (biome == null)
|
||||
{
|
||||
public BiomeGenerator getPlotBiomeProvider() {
|
||||
if (biome == null) {
|
||||
biome = new SpongeBasicBiomeProvider(plotworld);
|
||||
}
|
||||
return biome;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,31 +13,24 @@ 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(final SpongeBasicGen generator)
|
||||
{
|
||||
public class SpongeBasicPop extends SpongePlotPopulator<SpongeBasicGen> {
|
||||
|
||||
public SpongeBasicPop(final SpongeBasicGen generator) {
|
||||
super(generator);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void populate(final World world, final RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz)
|
||||
{
|
||||
public void populate(final World world, final RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz) {
|
||||
int sx = (short) ((X - generator.plotworld.ROAD_OFFSET_X) % generator.size);
|
||||
int sz = (short) ((Z - generator.plotworld.ROAD_OFFSET_Z) % generator.size);
|
||||
if (sx < 0)
|
||||
{
|
||||
if (sx < 0) {
|
||||
sx += generator.size;
|
||||
}
|
||||
if (sz < 0)
|
||||
{
|
||||
if (sz < 0) {
|
||||
sz += generator.size;
|
||||
}
|
||||
for (short x = 0; x < 16; x++)
|
||||
{
|
||||
for (short z = 0; z < 16; z++)
|
||||
{
|
||||
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;
|
||||
@ -45,50 +38,36 @@ public class SpongeBasicPop extends SpongePlotPopulator<SpongeBasicGen>
|
||||
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++)
|
||||
{
|
||||
if (gx && gz && lx && lz) {
|
||||
for (short y = 1; y < generator.plotheight; y++) {
|
||||
setBlock(x, y, z, generator.filling);
|
||||
}
|
||||
setBlock(x, (short) generator.plotheight, z, generator.plotfloors);
|
||||
if ((generator.plotworld.TYPE != 0) && (generator.plotworld.TERRAIN < 2))
|
||||
{
|
||||
for (int y = generator.plotheight + 1; y < 128; y++)
|
||||
{
|
||||
if ((generator.plotworld.TYPE != 0) && (generator.plotworld.TERRAIN < 2)) {
|
||||
for (int y = generator.plotheight + 1; y < 128; y++) {
|
||||
setBlock(x, y, z, generator.AIR);
|
||||
}
|
||||
}
|
||||
if (generator.plotworld.PLOT_SCHEMATIC)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (blocks != null) {
|
||||
final HashMap<Short, Byte> datas = generator.plotworld.G_SCH_DATA.get(loc);
|
||||
if (datas != null)
|
||||
{
|
||||
for (final short y : blocks.keySet())
|
||||
{
|
||||
if (datas != null) {
|
||||
for (final short y : blocks.keySet()) {
|
||||
final Byte data = datas.get(y);
|
||||
setBlock(x, (short) (generator.plotheight + y), z, SpongeMain.THIS.getBlockState(new PlotBlock(blocks.get(y), data == null ? 0 : data)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (final short y : blocks.keySet())
|
||||
{
|
||||
} else {
|
||||
for (final short y : blocks.keySet()) {
|
||||
setBlock(x, (short) (generator.plotheight + y), z, SpongeMain.THIS.getBlockState(blocks.get(y)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (generator.plotworld.G_SCH_STATE != null)
|
||||
{
|
||||
if (generator.plotworld.G_SCH_STATE != null) {
|
||||
final HashSet<PlotItem> states = generator.plotworld.G_SCH_STATE.get(loc);
|
||||
if (states != null)
|
||||
{
|
||||
for (final PlotItem items : states)
|
||||
{
|
||||
if (states != null) {
|
||||
for (final PlotItem items : states) {
|
||||
items.x = X + x;
|
||||
items.z = Z + z;
|
||||
BlockManager.manager.addItems(generator.plotworld.worldname, items);
|
||||
@ -96,62 +75,44 @@ public class SpongeBasicPop extends SpongePlotPopulator<SpongeBasicGen>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (generator.pathsize != 0)
|
||||
{
|
||||
} 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++)
|
||||
{
|
||||
if (((absX >= generator.pathWidthLower) && (absX <= generator.pathWidthUpper) && (absZ >= generator.pathWidthLower) && (absZ <= generator.pathWidthUpper))) {
|
||||
for (short y = 1; y <= generator.wallheight; y++) {
|
||||
setBlock(x, y, z, generator.wallfilling);
|
||||
}
|
||||
if ((generator.plotworld.TYPE != 0) && (generator.plotworld.TERRAIN < 3))
|
||||
{
|
||||
for (int y = generator.wallheight + 2; y < 128; y++)
|
||||
{
|
||||
if ((generator.plotworld.TYPE != 0) && (generator.plotworld.TERRAIN < 3)) {
|
||||
for (int y = generator.wallheight + 2; y < 128; y++) {
|
||||
setBlock(x, y, z, generator.AIR);
|
||||
}
|
||||
}
|
||||
if (!generator.plotworld.ROAD_SCHEMATIC_ENABLED)
|
||||
{
|
||||
if (!generator.plotworld.ROAD_SCHEMATIC_ENABLED) {
|
||||
setBlock(x, generator.wallheight + 1, z, generator.wall);
|
||||
}
|
||||
}
|
||||
// road
|
||||
else
|
||||
{
|
||||
for (short y = 1; y <= generator.roadheight; y++)
|
||||
{
|
||||
else {
|
||||
for (short y = 1; y <= generator.roadheight; y++) {
|
||||
setBlock(x, y, z, generator.roadblock);
|
||||
}
|
||||
if ((generator.plotworld.TYPE != 0) && (generator.plotworld.TERRAIN < 3))
|
||||
{
|
||||
for (int y = generator.roadheight + 1; y < 128; y++)
|
||||
{
|
||||
if ((generator.plotworld.TYPE != 0) && (generator.plotworld.TERRAIN < 3)) {
|
||||
for (int y = generator.roadheight + 1; y < 128; y++) {
|
||||
setBlock(x, y, z, generator.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (generator.plotworld.ROAD_SCHEMATIC_ENABLED)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (blocks != null) {
|
||||
final HashMap<Short, Byte> datas = generator.plotworld.G_SCH_DATA.get(loc);
|
||||
if (datas != null)
|
||||
{
|
||||
for (final short y : blocks.keySet())
|
||||
{
|
||||
if (datas != null) {
|
||||
for (final short y : blocks.keySet()) {
|
||||
final Byte data = datas.get(y);
|
||||
setBlock(x, (short) (generator.plotheight + y), z, SpongeMain.THIS.getBlockState(new PlotBlock(blocks.get(y), data == null ? 0 : data)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (final short y : blocks.keySet())
|
||||
{
|
||||
} else {
|
||||
for (final short y : blocks.keySet()) {
|
||||
setBlock(x, (short) (generator.plotheight + y), z, SpongeMain.THIS.getBlockState(blocks.get(y)));
|
||||
}
|
||||
}
|
||||
|
@ -11,98 +11,83 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class SpongeGeneratorWrapper extends PlotGenerator<WorldGenerator>
|
||||
{
|
||||
|
||||
public class SpongeGeneratorWrapper extends PlotGenerator<WorldGenerator> {
|
||||
|
||||
public final boolean full;
|
||||
|
||||
public SpongeGeneratorWrapper(final String world, final WorldGenerator generator)
|
||||
{
|
||||
|
||||
public SpongeGeneratorWrapper(final String world, final WorldGenerator generator) {
|
||||
super(world, generator);
|
||||
full = (generator instanceof SpongePlotGenerator);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(final PlotWorld plotworld)
|
||||
{
|
||||
if (generator instanceof SpongePlotGenerator)
|
||||
{
|
||||
public void initialize(final PlotWorld plotworld) {
|
||||
if (generator instanceof SpongePlotGenerator) {
|
||||
((SpongePlotGenerator) generator).init(plotworld);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void augment(final PlotCluster cluster, final PlotWorld plotworld)
|
||||
{
|
||||
if (generator instanceof SpongePlotGenerator)
|
||||
{
|
||||
public void augment(final PlotCluster cluster, final PlotWorld plotworld) {
|
||||
if (generator instanceof SpongePlotGenerator) {
|
||||
final SpongePlotGenerator plotgen = (SpongePlotGenerator) generator;
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
if (worldObj != null)
|
||||
{
|
||||
if (cluster != null)
|
||||
{
|
||||
if (worldObj != null) {
|
||||
if (cluster != null) {
|
||||
new AugmentedPopulator(world, worldObj.getWorldGenerator(), plotgen, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
new AugmentedPopulator(world, worldObj.getWorldGenerator(), plotgen, null, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setGenerator(final String gen_string)
|
||||
{
|
||||
if (gen_string == null)
|
||||
{
|
||||
public void setGenerator(final String gen_string) {
|
||||
if (gen_string == null) {
|
||||
generator = new SpongeBasicGen(world);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
final PlotGenerator<WorldGenerator> gen_wrapper = (PlotGenerator<WorldGenerator>) PS.get().IMP.getGenerator(world, gen_string);
|
||||
if (gen_wrapper != null)
|
||||
{
|
||||
if (gen_wrapper != null) {
|
||||
generator = gen_wrapper.generator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotWorld getNewPlotWorld(final String world)
|
||||
{
|
||||
if (!(generator instanceof SpongePlotGenerator)) { return null; }
|
||||
public PlotWorld getNewPlotWorld(final String world) {
|
||||
if (!(generator instanceof SpongePlotGenerator)) {
|
||||
return null;
|
||||
}
|
||||
return ((SpongePlotGenerator) generator).getNewPlotWorld(world);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotManager getPlotManager()
|
||||
{
|
||||
if (!(generator instanceof SpongePlotGenerator)) { return null; }
|
||||
public PlotManager getPlotManager() {
|
||||
if (!(generator instanceof SpongePlotGenerator)) {
|
||||
return null;
|
||||
}
|
||||
return ((SpongePlotGenerator) generator).getPlotManager();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isFull()
|
||||
{
|
||||
public boolean isFull() {
|
||||
return full;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
if (generator == null) { return "Null"; }
|
||||
public String getName() {
|
||||
if (generator == null) {
|
||||
return "Null";
|
||||
}
|
||||
return generator.getClass().getName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processSetup(final SetupObject object)
|
||||
{
|
||||
if (generator instanceof SpongePlotGenerator)
|
||||
{
|
||||
public void processSetup(final SetupObject object) {
|
||||
if (generator instanceof SpongePlotGenerator) {
|
||||
((SpongePlotGenerator) generator).processSetup(object);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -12,89 +12,80 @@ 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 abstract class SpongePlotGenerator implements WorldGenerator {
|
||||
|
||||
public final String world;
|
||||
|
||||
public SpongePlotGenerator(final String world)
|
||||
{
|
||||
|
||||
public SpongePlotGenerator(final String world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GeneratorPopulator getBaseGeneratorPopulator()
|
||||
{
|
||||
public GeneratorPopulator getBaseGeneratorPopulator() {
|
||||
return getGenerator();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeGenerator getBiomeGenerator()
|
||||
{
|
||||
public BiomeGenerator getBiomeGenerator() {
|
||||
return getPlotBiomeProvider();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<GeneratorPopulator> getGeneratorPopulators()
|
||||
{
|
||||
public List<GeneratorPopulator> getGeneratorPopulators() {
|
||||
final List<GeneratorPopulator> pops = new ArrayList<>();
|
||||
pops.addAll(getPlotPopulators());
|
||||
return pops;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Populator> getPopulators()
|
||||
{
|
||||
public List<Populator> getPopulators() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBaseGeneratorPopulator(final GeneratorPopulator arg0)
|
||||
{
|
||||
public void setBaseGeneratorPopulator(final GeneratorPopulator arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBiomeGenerator(final BiomeGenerator biomeGenerator)
|
||||
{
|
||||
public void setBiomeGenerator(final 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(final 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(final SetupObject object)
|
||||
{}
|
||||
public void processSetup(final SetupObject object) {}
|
||||
}
|
||||
|
@ -11,34 +11,30 @@ 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 abstract class SpongePlotPopulator<T extends SpongePlotGenerator> implements GeneratorPopulator {
|
||||
|
||||
public int X;
|
||||
public int Z;
|
||||
public String worldname;
|
||||
private final PseudoRandom random = new PseudoRandom();
|
||||
private MutableBlockVolume buffer;
|
||||
public final T generator;
|
||||
|
||||
public SpongePlotPopulator(final T generator)
|
||||
{
|
||||
|
||||
public SpongePlotPopulator(final T generator) {
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public void populate(Chunk chunk, Random random) {
|
||||
// this.world = chunk.getWorld();
|
||||
// this.worldname = world.getName();
|
||||
// Vector3i min = chunk.getBlockMin();
|
||||
|
||||
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public void populate(final World world, final MutableBlockVolume buffer, final ImmutableBiomeArea biomeBase)
|
||||
{
|
||||
try
|
||||
{
|
||||
public void populate(final World world, final MutableBlockVolume buffer, final ImmutableBiomeArea biomeBase) {
|
||||
try {
|
||||
this.worldname = world.getName();
|
||||
this.buffer = buffer;
|
||||
final Vector3i min = buffer.getBlockMin();
|
||||
@ -51,19 +47,17 @@ public abstract class SpongePlotPopulator<T extends SpongePlotGenerator> impleme
|
||||
h = (prime * h) + cx;
|
||||
h = (prime * h) + cz;
|
||||
this.random.state = h;
|
||||
|
||||
|
||||
// TODO plot clearing stuff
|
||||
|
||||
|
||||
populate(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz);
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public abstract void populate(final World world, final RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz);
|
||||
|
||||
|
||||
/**
|
||||
* Set the id and data at a location. (x, y, z) must be between [0,15], [0,255], [0,15]
|
||||
* @param x
|
||||
@ -72,20 +66,17 @@ public abstract class SpongePlotPopulator<T extends SpongePlotGenerator> impleme
|
||||
* @param id
|
||||
* @param data
|
||||
*/
|
||||
public void setBlock(final int x, final int y, final int z, final BlockState state)
|
||||
{
|
||||
public void setBlock(final int x, final int y, final int z, final BlockState state) {
|
||||
buffer.setBlock(X + x, y, Z + z, state);
|
||||
}
|
||||
|
||||
public void setBlock(final int x, final int y, final int z, final BlockState[] states)
|
||||
{
|
||||
if (states.length == 1)
|
||||
{
|
||||
|
||||
public void setBlock(final int x, final int y, final int z, final BlockState[] states) {
|
||||
if (states.length == 1) {
|
||||
setBlock(x, y, z, states[0]);
|
||||
}
|
||||
setBlock(x, y, z, states[random.random(states.length)]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check if a region contains a location. (x, z) must be between [0,15], [0,15]
|
||||
* @param plot
|
||||
@ -93,11 +84,10 @@ public abstract class SpongePlotPopulator<T extends SpongePlotGenerator> impleme
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(final RegionWrapper plot, final int x, final int z)
|
||||
{
|
||||
public boolean contains(final RegionWrapper plot, final int x, final int z) {
|
||||
final int xx = X + x;
|
||||
final int zz = Z + z;
|
||||
return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,55 +9,43 @@ import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
|
||||
public class WorldModify implements WorldGeneratorModifier
|
||||
{
|
||||
|
||||
public class WorldModify implements WorldGeneratorModifier {
|
||||
|
||||
private final SpongePlotGenerator plotgen;
|
||||
private final boolean augment;
|
||||
|
||||
public WorldModify(final SpongePlotGenerator plotgen, final boolean augment)
|
||||
{
|
||||
|
||||
public WorldModify(final SpongePlotGenerator plotgen, final boolean augment) {
|
||||
this.plotgen = plotgen;
|
||||
this.augment = augment;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void modifyWorldGenerator(final WorldCreationSettings world, final DataContainer settings, final WorldGenerator gen)
|
||||
{
|
||||
if (augment)
|
||||
{
|
||||
public void modifyWorldGenerator(final WorldCreationSettings world, final DataContainer settings, final WorldGenerator gen) {
|
||||
if (augment) {
|
||||
final String worldname = plotgen.world;
|
||||
final PlotWorld plotworld = plotgen.getNewPlotWorld(worldname);
|
||||
if (plotworld.TYPE == 2)
|
||||
{
|
||||
for (final PlotCluster cluster : ClusterManager.getClusters(worldname))
|
||||
{
|
||||
if (plotworld.TYPE == 2) {
|
||||
for (final PlotCluster cluster : ClusterManager.getClusters(worldname)) {
|
||||
new AugmentedPopulator(worldname, gen, plotgen, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
new AugmentedPopulator(worldname, gen, plotgen, null, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
gen.getGeneratorPopulators().clear();
|
||||
gen.getPopulators().clear();
|
||||
gen.setBaseGeneratorPopulator(plotgen.getBaseGeneratorPopulator());
|
||||
gen.setBiomeGenerator(plotgen.getBiomeGenerator());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
return "plotsquared";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
public String getId() {
|
||||
return "plotsquared";
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,74 +26,68 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
|
||||
public class SpongePlayer extends PlotPlayer
|
||||
{
|
||||
|
||||
public class SpongePlayer extends PlotPlayer {
|
||||
|
||||
public final Player player;
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
private long last = 0;
|
||||
public HashSet<String> hasPerm = new HashSet<>();
|
||||
public HashSet<String> noPerm = new HashSet<>();
|
||||
|
||||
public SpongePlayer(final Player player)
|
||||
{
|
||||
|
||||
public SpongePlayer(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendMessage(final C c, final String... args)
|
||||
{
|
||||
public void sendMessage(final C c, final String... args) {
|
||||
MainUtil.sendMessage(this, c, args);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RequiredType getSuperCaller()
|
||||
{
|
||||
public RequiredType getSuperCaller() {
|
||||
return RequiredType.PLAYER;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getPreviousLogin()
|
||||
{
|
||||
public long getPreviousLogin() {
|
||||
final Value<Date> data = player.getJoinData().lastPlayed();
|
||||
if (data.exists()) { return last = data.get().getSeconds() * 1000; }
|
||||
if (data.exists()) {
|
||||
return last = data.get().getSeconds() * 1000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Location getLocation()
|
||||
{
|
||||
public Location getLocation() {
|
||||
final Location loc = super.getLocation();
|
||||
return loc == null ? SpongeUtil.getLocation(player) : loc;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Location getLocationFull()
|
||||
{
|
||||
public Location getLocationFull() {
|
||||
return SpongeUtil.getLocationFull(player);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID()
|
||||
{
|
||||
if (uuid == null)
|
||||
{
|
||||
public UUID getUUID() {
|
||||
if (uuid == null) {
|
||||
uuid = UUIDHandler.getUUID(this);
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String perm)
|
||||
{
|
||||
if (Settings.PERMISSION_CACHING)
|
||||
{
|
||||
if (noPerm.contains(perm)) { return false; }
|
||||
if (hasPerm.contains(perm)) { return true; }
|
||||
public boolean hasPermission(final String perm) {
|
||||
if (Settings.PERMISSION_CACHING) {
|
||||
if (noPerm.contains(perm)) {
|
||||
return false;
|
||||
}
|
||||
if (hasPerm.contains(perm)) {
|
||||
return true;
|
||||
}
|
||||
final boolean result = player.hasPermission(perm);
|
||||
if (!result)
|
||||
{
|
||||
if (!result) {
|
||||
noPerm.add(perm);
|
||||
return false;
|
||||
}
|
||||
@ -103,112 +97,105 @@ public class SpongePlayer extends PlotPlayer
|
||||
final boolean value = player.hasPermission(perm);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendMessage(final String message)
|
||||
{
|
||||
public void sendMessage(final String message) {
|
||||
player.sendMessage(ChatTypes.CHAT, Texts.of(message));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void teleport(final Location loc)
|
||||
{
|
||||
if ((Math.abs(loc.getX()) >= 30000000) || (Math.abs(loc.getZ()) >= 30000000)) { return; }
|
||||
final String world = player.getWorld().getName();
|
||||
if (!world.equals(loc.getWorld()))
|
||||
{
|
||||
player.transferToWorld(loc.getWorld(), new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
|
||||
public void teleport(final Location loc) {
|
||||
if ((Math.abs(loc.getX()) >= 30000000) || (Math.abs(loc.getZ()) >= 30000000)) {
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
final String world = player.getWorld().getName();
|
||||
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();
|
||||
current = current.setPosition(new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
|
||||
player.setLocation(current);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isOnline()
|
||||
{
|
||||
public boolean isOnline() {
|
||||
return player.isOnline();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
public String getName() {
|
||||
if (name == null) {
|
||||
name = player.getName();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCompassTarget(final Location loc)
|
||||
{
|
||||
public void setCompassTarget(final Location loc) {
|
||||
final TargetedLocationData target = player.getOrCreate(TargetedLocationData.class).get();
|
||||
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(loc));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void loadData()
|
||||
{
|
||||
public void loadData() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void saveData()
|
||||
{
|
||||
public void saveData() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setAttribute(String key)
|
||||
{
|
||||
public void setAttribute(String key) {
|
||||
key = "plotsquared_user_attributes." + key;
|
||||
// EconHandler.manager.setPermission(getName(), key, true);
|
||||
setMeta(key, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getAttribute(String key)
|
||||
{
|
||||
public boolean getAttribute(String key) {
|
||||
key = "plotsquared_user_attributes." + key;
|
||||
return getMeta(key) != null;
|
||||
// TODO register attributes
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String key)
|
||||
{
|
||||
public void removeAttribute(String key) {
|
||||
key = "plotsquared_user_attributes." + key;
|
||||
// EconHandler.manager.setPermission(getName(), key, false);
|
||||
deleteMeta(key);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setWeather(final PlotWeather weather)
|
||||
{
|
||||
public void setWeather(final PlotWeather weather) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotGamemode getGamemode()
|
||||
{
|
||||
public PlotGamemode getGamemode() {
|
||||
final GameMode gamemode = player.getGameModeData().type().get();
|
||||
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; }
|
||||
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(final PlotGamemode gamemode)
|
||||
{
|
||||
public void setGamemode(final PlotGamemode gamemode) {
|
||||
// TODO Auto-generated method stub
|
||||
// switch (gamemode) {
|
||||
// case ADVENTURE:
|
||||
@ -225,31 +212,27 @@ public class SpongePlayer extends PlotPlayer
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setTime(final long time)
|
||||
{
|
||||
public void setTime(final long time) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setFlight(final boolean fly)
|
||||
{
|
||||
public void setFlight(final boolean fly) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void playMusic(final Location loc, final int id)
|
||||
{
|
||||
public void playMusic(final Location loc, final int id) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void kick(final String message)
|
||||
{
|
||||
public void kick(final String message) {
|
||||
player.kick(SpongeMain.THIS.getText(message));
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
public class KillRoadMobs
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
public class KillRoadMobs {
|
||||
public void run() {
|
||||
// TODO kill road mobs
|
||||
}
|
||||
}
|
||||
|
@ -24,47 +24,35 @@ import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeBlockManager extends BlockManager
|
||||
{
|
||||
|
||||
public class SpongeBlockManager extends BlockManager {
|
||||
|
||||
@Override
|
||||
public boolean isBlockSolid(final PlotBlock block)
|
||||
{
|
||||
public boolean isBlockSolid(final PlotBlock block) {
|
||||
final BlockState state = SpongeMain.THIS.getBlockState(block);
|
||||
final BlockType type = state.getType();
|
||||
return type.isSolidCube() && !type.isAffectedByGravity();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
||||
try {
|
||||
double match;
|
||||
short id;
|
||||
byte data;
|
||||
final String[] split = name.split(":");
|
||||
if (split.length == 2)
|
||||
{
|
||||
if (split.length == 2) {
|
||||
data = Byte.parseByte(split[1]);
|
||||
name = split[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
data = 0;
|
||||
}
|
||||
if (MathMan.isInteger(split[0]))
|
||||
{
|
||||
if (MathMan.isInteger(split[0])) {
|
||||
id = Short.parseShort(split[0]);
|
||||
match = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
final StringComparison<BlockState>.ComparisonResult comparison = new StringComparison<BlockState>(name, SpongeMain.THIS.getAllStates())
|
||||
{
|
||||
} else {
|
||||
final StringComparison<BlockState>.ComparisonResult comparison = new StringComparison<BlockState>(name, SpongeMain.THIS.getAllStates()) {
|
||||
@Override
|
||||
public String getString(final BlockState o)
|
||||
{
|
||||
public String getString(final BlockState o) {
|
||||
return o.getType().getId();
|
||||
};
|
||||
}.getBestMatchAdvanced();
|
||||
@ -74,144 +62,136 @@ public class SpongeBlockManager extends BlockManager
|
||||
final PlotBlock block = new PlotBlock(id, data);
|
||||
final StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
||||
return outer.new ComparisonResult(match, block);
|
||||
|
||||
}
|
||||
catch (final Exception e)
|
||||
{}
|
||||
|
||||
} catch (final Exception e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getClosestMatchingName(final PlotBlock block)
|
||||
{
|
||||
public String getClosestMatchingName(final PlotBlock block) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getBiomeList()
|
||||
{
|
||||
public String[] getBiomeList() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean addItems(final String world, final PlotItem items)
|
||||
{
|
||||
public boolean addItems(final String world, final PlotItem items) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getBiomeFromString(final String biome)
|
||||
{
|
||||
public int getBiomeFromString(final String biome) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotBlock getPlotBlockFromString(final String block)
|
||||
{
|
||||
public PlotBlock getPlotBlockFromString(final String block) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getHeighestBlock(final String worldname, final int x, final int z)
|
||||
{
|
||||
public int getHeighestBlock(final String worldname, final int x, final int z) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
if (world == null) { return 64; }
|
||||
for (int y = 255; y > 0; y--)
|
||||
{
|
||||
if (world == null) {
|
||||
return 64;
|
||||
}
|
||||
for (int y = 255; y > 0; y--) {
|
||||
final BlockState block = world.getBlock(x, y, z);
|
||||
if ((block != null) && (block.getType() != BlockTypes.AIR)) { return y + 1; }
|
||||
if ((block != null) && (block.getType() != BlockTypes.AIR)) {
|
||||
return y + 1;
|
||||
}
|
||||
}
|
||||
return 64;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getBiome(final String world, final int x, final int z)
|
||||
{
|
||||
public String getBiome(final String world, final int x, final int z) {
|
||||
return SpongeUtil.getWorld(world).getBiome(x, z).getName().toUpperCase();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotBlock getBlock(final Location loc)
|
||||
{
|
||||
public PlotBlock getBlock(final Location loc) {
|
||||
final BlockState state = SpongeUtil.getWorld(loc.getWorld()).getBlock(loc.getX(), loc.getY(), loc.getZ());
|
||||
PlotBlock block = SpongeMain.THIS.getPlotBlock(state);
|
||||
if (block == null)
|
||||
{
|
||||
if (block == null) {
|
||||
block = SpongeMain.THIS.registerBlock(state);
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Location getSpawn(final String world)
|
||||
{
|
||||
public Location getSpawn(final String world) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
worldObj.getSpawnLocation();
|
||||
final Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
|
||||
result.setY(getHeighestBlock(world, result.getX(), result.getZ()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getSign(final Location loc)
|
||||
{
|
||||
public String[] getSign(final Location loc) {
|
||||
final World world = SpongeUtil.getWorld(loc.getWorld());
|
||||
final Optional<TileEntity> block = world.getTileEntity(loc.getX(), loc.getY(), loc.getZ());
|
||||
if (!block.isPresent()) { return null; }
|
||||
if (!block.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
final TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) { return null; }
|
||||
if (!(tile instanceof Sign)) {
|
||||
return null;
|
||||
}
|
||||
final Sign sign = (Sign) tile;
|
||||
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||
if (!optional.isPresent()) { return null; }
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
final String[] result = new String[4];
|
||||
final ListValue<Text> lines = optional.get().lines();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
result[i] = lines.get(i).toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isWorld(final String world)
|
||||
{
|
||||
public boolean isWorld(final String world) {
|
||||
return SpongeUtil.getWorld(world) != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void functionSetBlocks(final String worldname, final int[] xv, final int[] yv, final int[] zv, final int[] id, final byte[] data)
|
||||
{
|
||||
for (int i = 0; i < xv.length; i++)
|
||||
{
|
||||
public void functionSetBlocks(final String worldname, final int[] xv, final int[] yv, final int[] zv, final int[] id, final 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(final String worldname, final int x, final int y, final int z, final String[] lines)
|
||||
{
|
||||
public void functionSetSign(final String worldname, final int x, final int y, final int z, final String[] lines) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
world.setBlock(x, y, z, BlockTypes.WALL_SIGN.getDefaultState());
|
||||
final Optional<TileEntity> block = world.getTileEntity(x, y, z);
|
||||
if (!block.isPresent()) { return; }
|
||||
if (!block.isPresent()) {
|
||||
return;
|
||||
}
|
||||
final TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) { return; }
|
||||
if (!(tile instanceof Sign)) {
|
||||
return;
|
||||
}
|
||||
final Sign sign = (Sign) tile;
|
||||
final List<Text> text = new ArrayList<>(4);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
text.add(SpongeMain.THIS.getText(lines[i]));
|
||||
}
|
||||
try
|
||||
{
|
||||
try {
|
||||
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||
if (optional.isPresent())
|
||||
{
|
||||
if (optional.isPresent()) {
|
||||
final SignData offering = optional.get();
|
||||
offering.lines().set(0, SpongeMain.THIS.getText(lines[0]));
|
||||
offering.lines().set(1, SpongeMain.THIS.getText(lines[1]));
|
||||
@ -219,52 +199,42 @@ public class SpongeBlockManager extends BlockManager
|
||||
offering.lines().set(3, SpongeMain.THIS.getText(lines[3]));
|
||||
sign.offer(offering);
|
||||
}
|
||||
}
|
||||
catch (final NullPointerException e)
|
||||
{
|
||||
} catch (final NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void functionSetBlock(final String worldname, final int x, final int y, final int z, final int id, final byte data)
|
||||
{
|
||||
public void functionSetBlock(final String worldname, final int x, final int y, final int z, final int id, final byte data) {
|
||||
BlockState state;
|
||||
if (data == 0)
|
||||
{
|
||||
if (data == 0) {
|
||||
state = SpongeMain.THIS.getBlockState(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
state = SpongeMain.THIS.getBlockState(new PlotBlock((short) id, data));
|
||||
}
|
||||
if (state == null) { return; }
|
||||
if (state == null) {
|
||||
return;
|
||||
}
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final BlockState block = world.getBlock(x, y, z);
|
||||
if (block != state)
|
||||
{
|
||||
if (block != state) {
|
||||
world.setBlock(x, y, z, state);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void functionSetBiomes(final String worldname, final int[] xv, final int[] zv, final String biomeName)
|
||||
{
|
||||
public void functionSetBiomes(final String worldname, final int[] xv, final int[] zv, final String biomeName) {
|
||||
BiomeType biome;
|
||||
try
|
||||
{
|
||||
try {
|
||||
biome = (BiomeType) BiomeTypes.class.getField(biomeName.toUpperCase()).get(null);
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
biome = BiomeTypes.FOREST;
|
||||
}
|
||||
for (int i = 0; i < xv.length; i++)
|
||||
{
|
||||
for (int i = 0; i < xv.length; i++) {
|
||||
SpongeUtil.getWorld(worldname).setBiome(xv[i], zv[i], biome);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -10,30 +10,24 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ChatManager;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeChatManager extends ChatManager<TextBuilder>
|
||||
{
|
||||
|
||||
public class SpongeChatManager extends ChatManager<TextBuilder> {
|
||||
|
||||
@Override
|
||||
public TextBuilder builder()
|
||||
{
|
||||
public TextBuilder builder() {
|
||||
return Texts.builder();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void color(final PlotMessage m, final String color)
|
||||
{
|
||||
public void color(final PlotMessage m, final String color) {
|
||||
m.$(this).color(Texts.of(color).getColor());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tooltip(final PlotMessage m, final PlotMessage... tooltips)
|
||||
{
|
||||
public void tooltip(final PlotMessage m, final PlotMessage... tooltips) {
|
||||
final TextBuilder builder = Texts.builder();
|
||||
boolean lb = false;
|
||||
for (final PlotMessage tooltip : tooltips)
|
||||
{
|
||||
if (lb)
|
||||
{
|
||||
for (final PlotMessage tooltip : tooltips) {
|
||||
if (lb) {
|
||||
builder.append(Texts.of("\n"));
|
||||
}
|
||||
builder.append(tooltip.$(this).build());
|
||||
@ -42,36 +36,29 @@ public class SpongeChatManager extends ChatManager<TextBuilder>
|
||||
// AchievementBuilder builder = SpongeMain.THIS.getGame().getRegistry().createAchievementBuilder();
|
||||
m.$(this).onHover(TextActions.showText(builder.toText()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void command(final PlotMessage m, final String command)
|
||||
{
|
||||
public void command(final PlotMessage m, final String command) {
|
||||
m.$(this).onClick(TextActions.runCommand(command));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void text(final PlotMessage m, final String text)
|
||||
{
|
||||
public void text(final PlotMessage m, final String text) {
|
||||
m.$(this).append(Texts.of(text));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void send(final PlotMessage m, final PlotPlayer player)
|
||||
{
|
||||
if (ConsolePlayer.isConsole(player))
|
||||
{
|
||||
public void send(final PlotMessage m, final PlotPlayer player) {
|
||||
if (ConsolePlayer.isConsole(player)) {
|
||||
player.sendMessage(Texts.legacy().to(m.$(this).build()));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
((SpongePlayer) player).player.sendMessage(m.$(this).build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void suggest(final PlotMessage m, final String command)
|
||||
{
|
||||
public void suggest(final PlotMessage m, final String command) {
|
||||
m.$(this).onClick(TextActions.suggestCommand(command));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -22,22 +22,19 @@ import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.SetBlockQueue.ChunkWrapper;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class SpongeChunkManager extends ChunkManager
|
||||
{
|
||||
|
||||
public class SpongeChunkManager extends ChunkManager {
|
||||
|
||||
@Override
|
||||
public void setChunk(final ChunkWrapper loc, final PlotBlock[][] result)
|
||||
{
|
||||
public void setChunk(final ChunkWrapper loc, final PlotBlock[][] result) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] countEntities(final Plot plot)
|
||||
{
|
||||
public int[] countEntities(final Plot plot) {
|
||||
final Location pos1 = plot.getBottom();
|
||||
final Location pos2 = plot.getTop();
|
||||
|
||||
|
||||
final String worldname = pos1.getWorld();
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final int bx = pos1.getX();
|
||||
@ -45,33 +42,23 @@ public class SpongeChunkManager extends ChunkManager
|
||||
final int tx = pos2.getX();
|
||||
final int tz = pos2.getZ();
|
||||
final int[] count = new int[5];
|
||||
world.getEntities(new Predicate<Entity>()
|
||||
{
|
||||
world.getEntities(new Predicate<Entity>() {
|
||||
@Override
|
||||
public boolean apply(final Entity entity)
|
||||
{
|
||||
public boolean apply(final Entity entity) {
|
||||
final org.spongepowered.api.world.Location loc = entity.getLocation();
|
||||
final int x = loc.getBlockX();
|
||||
if ((x >= bx) && (x <= tx))
|
||||
{
|
||||
if ((x >= bx) && (x <= tx)) {
|
||||
final int z = loc.getBlockZ();
|
||||
if ((z >= bz) && (z <= tz))
|
||||
{
|
||||
if ((z >= bz) && (z <= tz)) {
|
||||
count[0]++;
|
||||
if (entity instanceof Living)
|
||||
{
|
||||
if (entity instanceof Living) {
|
||||
count[3]++;
|
||||
if (entity instanceof Animal)
|
||||
{
|
||||
if (entity instanceof Animal) {
|
||||
count[1]++;
|
||||
}
|
||||
else if (entity instanceof Monster)
|
||||
{
|
||||
} else if (entity instanceof Monster) {
|
||||
count[2]++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
count[4]++;
|
||||
}
|
||||
}
|
||||
@ -79,129 +66,113 @@ public class SpongeChunkManager extends ChunkManager
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean loadChunk(final String world, final ChunkLoc loc, final boolean force)
|
||||
{
|
||||
public boolean loadChunk(final String world, final ChunkLoc loc, final boolean force) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
return worldObj.loadChunk(loc.x << 4, 0, loc.z << 4, force).isPresent();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean unloadChunk(final String world, final ChunkLoc loc, final boolean save, final boolean safe)
|
||||
{
|
||||
public boolean unloadChunk(final String world, final ChunkLoc loc, final boolean save, final boolean safe) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
final Optional<Chunk> chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4);
|
||||
if (chunk.isPresent()) { return worldObj.unloadChunk(chunk.get()); }
|
||||
if (chunk.isPresent()) {
|
||||
return worldObj.unloadChunk(chunk.get());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ChunkLoc> getChunkChunks(final String world)
|
||||
{
|
||||
public List<ChunkLoc> getChunkChunks(final String world) {
|
||||
final ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
final ChunkDataStream storage = worldObj.getWorldStorage().getGeneratedChunks();
|
||||
while (storage.hasNext())
|
||||
{
|
||||
while (storage.hasNext()) {
|
||||
storage.next();
|
||||
|
||||
|
||||
// TODO get chunk from DataContainer
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void regenerateChunk(final String world, final ChunkLoc loc)
|
||||
{
|
||||
public void regenerateChunk(final String world, final ChunkLoc loc) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
final Optional<Chunk> chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4);
|
||||
if (chunk.isPresent())
|
||||
{
|
||||
if (chunk.isPresent()) {
|
||||
// TODO regenerate chunk
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteRegionFile(final String world, final ChunkLoc loc)
|
||||
{
|
||||
public void deleteRegionFile(final String world, final ChunkLoc loc) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteRegionFiles(final String world, final List<ChunkLoc> chunks)
|
||||
{
|
||||
public void deleteRegionFiles(final String world, final List<ChunkLoc> chunks) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteRegionFiles(String world, List<ChunkLoc> chunks, Runnable whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Plot hasPlot(final String world, final ChunkLoc chunk)
|
||||
{
|
||||
public Plot hasPlot(final String world, final ChunkLoc chunk) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone)
|
||||
{
|
||||
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
TaskManager.runTask(whenDone);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone)
|
||||
{
|
||||
public boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
TaskManager.runTask(whenDone);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void swap(final String world, final PlotId id, final PlotId plotid)
|
||||
{
|
||||
public void swap(final String world, final PlotId id, final PlotId plotid) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void swap(final String worldname, final Location bot1, final Location top1, final Location bot2, final Location top2)
|
||||
{
|
||||
public void swap(final String worldname, final Location bot1, final Location top1, final Location bot2, final Location top2) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clearAllEntities(final Location pos1, final Location pos2)
|
||||
{
|
||||
public void clearAllEntities(final Location pos1, final Location pos2) {
|
||||
final String worldname = pos1.getWorld();
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final int bx = pos1.getX();
|
||||
final int bz = pos1.getZ();
|
||||
final int tx = pos2.getX();
|
||||
final int tz = pos2.getZ();
|
||||
world.getEntities(new Predicate<Entity>()
|
||||
{
|
||||
world.getEntities(new Predicate<Entity>() {
|
||||
@Override
|
||||
public boolean apply(final Entity entity)
|
||||
{
|
||||
public boolean apply(final Entity entity) {
|
||||
final org.spongepowered.api.world.Location loc = entity.getLocation();
|
||||
final int x = loc.getBlockX();
|
||||
if ((x >= bx) && (x <= tx))
|
||||
{
|
||||
if ((x >= bx) && (x <= tx)) {
|
||||
final int z = loc.getBlockZ();
|
||||
if ((z >= bz) && (z <= tz))
|
||||
{
|
||||
if ((z >= bz) && (z <= tz)) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
@ -209,5 +180,5 @@ public class SpongeChunkManager extends ChunkManager
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,63 +19,50 @@ import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeCommand implements CommandCallable
|
||||
{
|
||||
|
||||
public class SpongeCommand implements CommandCallable {
|
||||
|
||||
@Override
|
||||
public CommandResult process(final CommandSource cmd, final String string) throws CommandException
|
||||
{
|
||||
public CommandResult process(final CommandSource cmd, final String string) throws CommandException {
|
||||
final String id = cmd.getIdentifier();
|
||||
PlotPlayer pp;
|
||||
try
|
||||
{
|
||||
try {
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get();
|
||||
pp = SpongeUtil.getPlayer(player);
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
pp = ConsolePlayer.getConsole();
|
||||
}
|
||||
if (MainCommand.onCommand(pp, cmd.getName(), string.length() == 0 ? new String[] {} : string.split(" ")))
|
||||
{
|
||||
if (MainCommand.onCommand(pp, cmd.getName(), string.length() == 0 ? new String[] {} : string.split(" "))) {
|
||||
return CommandResult.success();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return CommandResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(final CommandSource cmd, final String string) throws CommandException
|
||||
{
|
||||
public List<String> getSuggestions(final CommandSource cmd, final String string) throws CommandException {
|
||||
// TODO Auto-generated method stub
|
||||
return new ArrayList<>(Arrays.asList("TEST"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean testPermission(final CommandSource cmd)
|
||||
{
|
||||
public boolean testPermission(final CommandSource cmd) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getShortDescription(final CommandSource cmd)
|
||||
{
|
||||
public Optional<? extends Text> getShortDescription(final CommandSource cmd) {
|
||||
return Optional.of(Texts.of("Shows plot help"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getHelp(final CommandSource cmd)
|
||||
{
|
||||
public Optional<? extends Text> getHelp(final CommandSource cmd) {
|
||||
return Optional.of(Texts.of("/plot help"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Text getUsage(final CommandSource cmd)
|
||||
{
|
||||
public Text getUsage(final CommandSource cmd) {
|
||||
return Texts.of("/plot <command>");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -32,113 +32,97 @@ import com.plotsquared.sponge.events.PlotMergeEvent;
|
||||
import com.plotsquared.sponge.events.PlotRateEvent;
|
||||
import com.plotsquared.sponge.events.PlotUnlinkEvent;
|
||||
|
||||
public class SpongeEventUtil extends EventUtil
|
||||
{
|
||||
|
||||
public class SpongeEventUtil extends EventUtil {
|
||||
|
||||
public EventManager events;
|
||||
|
||||
public SpongeEventUtil()
|
||||
{
|
||||
|
||||
public SpongeEventUtil() {
|
||||
events = SpongeMain.THIS.getGame().getEventManager();
|
||||
}
|
||||
|
||||
public boolean callEvent(final Event event)
|
||||
{
|
||||
|
||||
public boolean callEvent(final Event event) {
|
||||
events.post(event);
|
||||
if (event instanceof Cancellable) { return !((Cancellable) event).isCancelled(); }
|
||||
if (event instanceof Cancellable) {
|
||||
return !((Cancellable) event).isCancelled();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto)
|
||||
{
|
||||
public boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto) {
|
||||
return callEvent(new PlayerClaimPlotEvent(SpongeUtil.getPlayer(player), plot, auto));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callTeleport(final PlotPlayer player, final Location from, final Plot plot)
|
||||
{
|
||||
public boolean callTeleport(final PlotPlayer player, final Location from, final Plot plot) {
|
||||
return callEvent(new PlayerTeleportToPlotEvent(SpongeUtil.getPlayer(player), from, plot));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callClear(final String world, final PlotId id)
|
||||
{
|
||||
public boolean callClear(final String world, final PlotId id) {
|
||||
return callEvent(new PlotClearEvent(world, id));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callDelete(final String world, final PlotId id)
|
||||
{
|
||||
public void callDelete(final String world, final PlotId id) {
|
||||
callEvent(new PlotDeleteEvent(world, id));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callFlagAdd(final Flag flag, final Plot plot)
|
||||
{
|
||||
public boolean callFlagAdd(final Flag flag, final Plot plot) {
|
||||
return callEvent(new PlotFlagAddEvent(flag, plot));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(final Flag flag, final Plot plot)
|
||||
{
|
||||
public boolean callFlagRemove(final Flag flag, final Plot plot) {
|
||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callMerge(final String world, final Plot plot, final ArrayList<PlotId> plots)
|
||||
{
|
||||
public boolean callMerge(final String world, final Plot plot, final ArrayList<PlotId> plots) {
|
||||
return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(world), plot, plots));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callUnlink(final String world, final ArrayList<PlotId> plots)
|
||||
{
|
||||
public boolean callUnlink(final String world, final ArrayList<PlotId> plots) {
|
||||
return callEvent(new PlotUnlinkEvent(SpongeUtil.getWorld(world), plots));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callEntry(final PlotPlayer player, final Plot plot)
|
||||
{
|
||||
public void callEntry(final PlotPlayer player, final Plot plot) {
|
||||
callEvent(new PlayerEnterPlotEvent(SpongeUtil.getPlayer(player), plot));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callLeave(final PlotPlayer player, final Plot plot)
|
||||
{
|
||||
public void callLeave(final PlotPlayer player, final Plot plot) {
|
||||
callEvent(new PlayerLeavePlotEvent(SpongeUtil.getPlayer(player), plot));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callDenied(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added)
|
||||
{
|
||||
public void callDenied(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
callEvent(new PlayerPlotDeniedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callTrusted(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added)
|
||||
{
|
||||
public void callTrusted(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
callEvent(new PlayerPlotHelperEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callMember(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added)
|
||||
{
|
||||
public void callMember(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
callEvent(new PlayerPlotTrustedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(final Flag flag, final PlotCluster cluster)
|
||||
{
|
||||
public boolean callFlagRemove(final Flag flag, final PlotCluster cluster) {
|
||||
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rating callRating(final PlotPlayer player, final Plot plot, final Rating rating)
|
||||
{
|
||||
public Rating callRating(final PlotPlayer player, final Plot plot, final Rating rating) {
|
||||
final PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||
events.post(event);
|
||||
return event.getRating();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -21,97 +21,93 @@ import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeInventoryUtil extends InventoryUtil
|
||||
{
|
||||
|
||||
public class SpongeInventoryUtil extends InventoryUtil {
|
||||
|
||||
public ItemStackBuilder builder;
|
||||
|
||||
public SpongeInventoryUtil()
|
||||
{
|
||||
|
||||
public SpongeInventoryUtil() {
|
||||
builder = SpongeMain.THIS.getGame().getRegistry().createItemBuilder();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void open(final PlotInventory inv)
|
||||
{
|
||||
public void open(final PlotInventory inv) {
|
||||
// TODO Auto-generated method stub
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
final Player player = sp.player;
|
||||
|
||||
|
||||
final CustomInventory inventory = Inventories.customInventoryBuilder().name(SpongeMain.THIS.getTranslation(inv.getTitle())).size(inv.size).build();
|
||||
final PlotItemStack[] items = inv.getItems();
|
||||
for (int i = 0; i < (inv.size * 9); i++)
|
||||
{
|
||||
for (int i = 0; i < (inv.size * 9); i++) {
|
||||
final PlotItemStack item = items[i];
|
||||
if (item != null)
|
||||
{
|
||||
if (item != null) {
|
||||
inventory.set(new SlotIndex(i), getItem(item));
|
||||
}
|
||||
}
|
||||
inv.player.setMeta("inventory", inv);
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public ItemStack getItem(final PlotItemStack item)
|
||||
{
|
||||
|
||||
public ItemStack getItem(final PlotItemStack item) {
|
||||
// FIXME item type, item data, item name, item lore
|
||||
return builder.itemType(ItemTypes.SPONGE).quantity(item.amount).build();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void close(final PlotInventory inv)
|
||||
{
|
||||
if (!inv.isOpen()) { return; }
|
||||
public void close(final PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
inv.player.deleteMeta("inventory");
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
sp.player.closeInventory();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setItem(final PlotInventory inv, final int index, final PlotItemStack item)
|
||||
{
|
||||
if (!inv.isOpen()) { return; }
|
||||
public void setItem(final PlotInventory inv, final int index, final PlotItemStack item) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
final Player player = sp.player;
|
||||
player.getOpenInventory().get();
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public PlotItemStack getItem(final ItemStack item)
|
||||
{
|
||||
if (item == null) { return null; }
|
||||
|
||||
public PlotItemStack getItem(final ItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
final ItemType type = item.getItem();
|
||||
final String id = type.getId();
|
||||
final int amount = item.getQuantity();
|
||||
// TODO name / lore
|
||||
return new PlotItemStack(id, amount, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotItemStack[] getItems(final PlotPlayer player)
|
||||
{
|
||||
public PlotItemStack[] getItems(final PlotPlayer player) {
|
||||
final SpongePlayer sp = (SpongePlayer) player;
|
||||
sp.player.getInventory();
|
||||
new ArrayList<PlotItemStack>();
|
||||
|
||||
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
|
||||
|
||||
// return list.toArray();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isOpen(final PlotInventory inv)
|
||||
{
|
||||
if (!inv.isOpen()) { return false; }
|
||||
public boolean isOpen(final PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
final Player player = sp.player;
|
||||
if (player.isViewingInventory())
|
||||
{
|
||||
if (player.isViewingInventory()) {
|
||||
final CarriedInventory<? extends Carrier> inventory = player.getInventory();
|
||||
return inv.getTitle().equals(inventory.getName().getTranslation().get(Locale.ENGLISH));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -56,121 +56,114 @@ import org.spongepowered.api.service.scheduler.TaskBuilder;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
|
||||
public class SpongeMetrics
|
||||
{
|
||||
|
||||
public class SpongeMetrics {
|
||||
|
||||
/**
|
||||
* The current revision number
|
||||
*/
|
||||
private final static int REVISION = 7;
|
||||
|
||||
|
||||
/**
|
||||
* The base url of the metrics domain
|
||||
*/
|
||||
private static final String BASE_URL = "http://report.mcstats.org";
|
||||
|
||||
|
||||
/**
|
||||
* The url used to report a server's status
|
||||
*/
|
||||
private static final String REPORT_URL = "/plugin/%s";
|
||||
|
||||
|
||||
/**
|
||||
* Interval of time to ping (in minutes)
|
||||
*/
|
||||
private static final int PING_INTERVAL = 15;
|
||||
|
||||
|
||||
/**
|
||||
* The game data is being sent for
|
||||
*/
|
||||
private final Game game;
|
||||
|
||||
|
||||
/**
|
||||
* The plugin this metrics submits for
|
||||
*/
|
||||
private final PluginContainer plugin;
|
||||
|
||||
|
||||
/**
|
||||
* The plugin configuration file
|
||||
*/
|
||||
private CommentedConfigurationNode config;
|
||||
|
||||
|
||||
/**
|
||||
* The configuration loader
|
||||
*/
|
||||
private ConfigurationLoader<CommentedConfigurationNode> configurationLoader;
|
||||
|
||||
|
||||
/**
|
||||
* The plugin configuration file
|
||||
*/
|
||||
private File configurationFile;
|
||||
|
||||
|
||||
/**
|
||||
* Unique server id
|
||||
*/
|
||||
private String guid;
|
||||
|
||||
|
||||
/**
|
||||
* Debug mode
|
||||
*/
|
||||
private boolean debug;
|
||||
|
||||
|
||||
/**
|
||||
* Lock for synchronization
|
||||
*/
|
||||
private final Object optOutLock = new Object();
|
||||
|
||||
|
||||
/**
|
||||
* The scheduled task
|
||||
*/
|
||||
private volatile Task task = null;
|
||||
|
||||
|
||||
@Inject
|
||||
public SpongeMetrics(final Game game, final PluginContainer plugin) throws IOException
|
||||
{
|
||||
if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); }
|
||||
|
||||
public SpongeMetrics(final Game game, final PluginContainer plugin) throws IOException {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null");
|
||||
}
|
||||
|
||||
this.game = game;
|
||||
this.plugin = plugin;
|
||||
|
||||
|
||||
loadConfiguration();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the configuration
|
||||
*/
|
||||
private void loadConfiguration()
|
||||
{
|
||||
private void loadConfiguration() {
|
||||
configurationFile = getConfigFile();
|
||||
configurationLoader = HoconConfigurationLoader.builder().setFile(configurationFile).build();
|
||||
|
||||
try
|
||||
{
|
||||
if (!configurationFile.exists())
|
||||
{
|
||||
|
||||
try {
|
||||
if (!configurationFile.exists()) {
|
||||
configurationFile.createNewFile();
|
||||
config = configurationLoader.load();
|
||||
|
||||
|
||||
config.setComment("This contains settings for MCStats: http://mcstats.org");
|
||||
config.getNode("mcstats.guid").setValue(UUID.randomUUID().toString());
|
||||
config.getNode("mcstats.opt-out").setValue(false);
|
||||
config.getNode("mcstats.debug").setValue(false);
|
||||
|
||||
|
||||
configurationLoader.save(config);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
config = configurationLoader.load();
|
||||
}
|
||||
|
||||
|
||||
guid = config.getNode("mcstats.guid").getString();
|
||||
debug = config.getNode("mcstats.debug").getBoolean();
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the
|
||||
* initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200
|
||||
@ -178,54 +171,46 @@ public class SpongeMetrics
|
||||
*
|
||||
* @return True if statistics measuring is running, otherwise false.
|
||||
*/
|
||||
public boolean start()
|
||||
{
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
public boolean start() {
|
||||
synchronized (optOutLock) {
|
||||
// Did we opt out?
|
||||
if (isOptOut()) { return false; }
|
||||
|
||||
if (isOptOut()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is metrics already running?
|
||||
if (task != null) { return true; }
|
||||
|
||||
if (task != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Begin hitting the server with glorious data
|
||||
final TaskBuilder builder = game.getScheduler().createTaskBuilder();
|
||||
builder.async()
|
||||
.interval(TimeUnit.MINUTES.toMillis(PING_INTERVAL))
|
||||
.execute(new Runnable()
|
||||
{
|
||||
|
||||
builder.async().interval(TimeUnit.MINUTES.toMillis(PING_INTERVAL)).execute(new Runnable() {
|
||||
|
||||
private boolean firstPost = true;
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
public void run() {
|
||||
try {
|
||||
// This has to be synchronized or it can collide with the disable method.
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
synchronized (optOutLock) {
|
||||
// Disable Task, if it is running and the server owner decided to opt-out
|
||||
if (isOptOut() && (task != null))
|
||||
{
|
||||
if (isOptOut() && (task != null)) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// We use the inverse of firstPost because if it is the first time we are posting,
|
||||
// it is not a interval ping, so it evaluates to FALSE
|
||||
// Each time thereafter it will evaluate to TRUE, i.e PING!
|
||||
postPlugin(!firstPost);
|
||||
|
||||
|
||||
// After the first post we set firstPost to false
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
} catch (final IOException e) {
|
||||
if (debug) {
|
||||
PS.debug("[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -234,92 +219,80 @@ public class SpongeMetrics
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Has the server owner denied plugin metrics?
|
||||
*
|
||||
* @return true if metrics should be opted out of it
|
||||
*/
|
||||
public boolean isOptOut()
|
||||
{
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
public boolean isOptOut() {
|
||||
synchronized (optOutLock) {
|
||||
loadConfiguration();
|
||||
|
||||
|
||||
return config.getNode("mcstats.opt-out").getBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void enable() throws IOException
|
||||
{
|
||||
public void enable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut())
|
||||
{
|
||||
if (isOptOut()) {
|
||||
config.getNode("mcstats.opt-out").setValue(false);
|
||||
configurationLoader.save(config);
|
||||
}
|
||||
|
||||
|
||||
// Enable Task, if it is not running
|
||||
if (task == null)
|
||||
{
|
||||
if (task == null) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void disable() throws IOException
|
||||
{
|
||||
public void disable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (!isOptOut())
|
||||
{
|
||||
if (!isOptOut()) {
|
||||
config.getNode("mcstats.opt-out").setValue(true);
|
||||
configurationLoader.save(config);
|
||||
}
|
||||
|
||||
|
||||
// Disable Task, if it is running
|
||||
if (task != null)
|
||||
{
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
|
||||
*
|
||||
* @return the File object for the config file
|
||||
*/
|
||||
public File getConfigFile()
|
||||
{
|
||||
public File getConfigFile() {
|
||||
// TODO configDir
|
||||
final File configFolder = new File("config");
|
||||
|
||||
|
||||
return new File(configFolder, "PluginMetrics.conf");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generic method that posts a plugin to the metrics website
|
||||
*
|
||||
*/
|
||||
private void postPlugin(final boolean isPing) throws IOException
|
||||
{
|
||||
private void postPlugin(final boolean isPing) throws IOException {
|
||||
// Server software specific section
|
||||
final String pluginName = plugin.getName();
|
||||
final boolean onlineMode = game.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||
@ -328,68 +301,63 @@ public class SpongeMetrics
|
||||
// TODO added by game.getPlatform().getMinecraftVersion() -- impl in 2.1
|
||||
final String serverVersion = String.format("%s %s", "Sponge", game.getPlatform().getMinecraftVersion());
|
||||
final int playersOnline = game.getServer().getOnlinePlayers().size();
|
||||
|
||||
|
||||
// END server software specific section -- all code below does not use any code outside of this class / Java
|
||||
|
||||
|
||||
// Construct the post data
|
||||
final StringBuilder json = new StringBuilder(1024);
|
||||
json.append('{');
|
||||
|
||||
|
||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||
appendJSONPair(json, "guid", guid);
|
||||
appendJSONPair(json, "plugin_version", pluginVersion);
|
||||
appendJSONPair(json, "server_version", serverVersion);
|
||||
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
||||
|
||||
|
||||
// New data as of R6
|
||||
final String osname = System.getProperty("os.name");
|
||||
String osarch = System.getProperty("os.arch");
|
||||
final String osversion = System.getProperty("os.version");
|
||||
final String java_version = System.getProperty("java.version");
|
||||
final int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
|
||||
// normalize os arch .. amd64 -> x86_64
|
||||
if (osarch.equals("amd64"))
|
||||
{
|
||||
if (osarch.equals("amd64")) {
|
||||
osarch = "x86_64";
|
||||
}
|
||||
|
||||
|
||||
appendJSONPair(json, "osname", osname);
|
||||
appendJSONPair(json, "osarch", osarch);
|
||||
appendJSONPair(json, "osversion", osversion);
|
||||
appendJSONPair(json, "cores", Integer.toString(coreCount));
|
||||
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
|
||||
appendJSONPair(json, "java_version", java_version);
|
||||
|
||||
|
||||
// If we're pinging, append it
|
||||
if (isPing)
|
||||
{
|
||||
if (isPing) {
|
||||
appendJSONPair(json, "ping", "1");
|
||||
}
|
||||
|
||||
|
||||
// close json
|
||||
json.append('}');
|
||||
|
||||
|
||||
// Create the url
|
||||
final URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
|
||||
|
||||
|
||||
// Connect to the website
|
||||
URLConnection connection;
|
||||
|
||||
|
||||
// Mineshafter creates a socks proxy, so we can safely bypass it
|
||||
// It does not reroute POST requests so we need to go around it
|
||||
if (isMineshafterPresent())
|
||||
{
|
||||
if (isMineshafterPresent()) {
|
||||
connection = url.openConnection(Proxy.NO_PROXY);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
connection = url.openConnection();
|
||||
}
|
||||
|
||||
|
||||
final byte[] uncompressed = json.toString().getBytes();
|
||||
final byte[] compressed = gzip(json.toString());
|
||||
|
||||
|
||||
// Headers
|
||||
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
|
||||
connection.addRequestProperty("Content-Type", "application/json");
|
||||
@ -397,96 +365,77 @@ public class SpongeMetrics
|
||||
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
|
||||
|
||||
connection.setDoOutput(true);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
|
||||
if (debug) {
|
||||
PS.debug("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
||||
}
|
||||
|
||||
|
||||
// Write the data
|
||||
final OutputStream os = connection.getOutputStream();
|
||||
os.write(compressed);
|
||||
os.flush();
|
||||
|
||||
|
||||
// Now read the response
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String response = reader.readLine();
|
||||
|
||||
|
||||
// close resources
|
||||
os.close();
|
||||
reader.close();
|
||||
|
||||
if ((response == null) || response.startsWith("ERR") || response.startsWith("7"))
|
||||
{
|
||||
if (response == null)
|
||||
{
|
||||
|
||||
if ((response == null) || response.startsWith("ERR") || response.startsWith("7")) {
|
||||
if (response == null) {
|
||||
response = "null";
|
||||
}
|
||||
else if (response.startsWith("7"))
|
||||
{
|
||||
} else if (response.startsWith("7")) {
|
||||
response = response.substring(response.startsWith("7,") ? 2 : 1);
|
||||
}
|
||||
|
||||
|
||||
throw new IOException(response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* GZip compress a string of bytes
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static byte[] gzip(final String input)
|
||||
{
|
||||
public static byte[] gzip(final String input) {
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzos = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
try {
|
||||
gzos = new GZIPOutputStream(baos);
|
||||
gzos.write(input.getBytes("UTF-8"));
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gzos != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
} finally {
|
||||
if (gzos != null) {
|
||||
try {
|
||||
gzos.close();
|
||||
}
|
||||
catch (final IOException ignore)
|
||||
{}
|
||||
} catch (final IOException ignore) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
||||
*
|
||||
* @return true if mineshafter is installed on the server
|
||||
*/
|
||||
private boolean isMineshafterPresent()
|
||||
{
|
||||
try
|
||||
{
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Appends a json encoded key/value pair to the given string builder.
|
||||
*
|
||||
@ -495,58 +444,46 @@ public class SpongeMetrics
|
||||
* @param value
|
||||
* @throws java.io.UnsupportedEncodingException
|
||||
*/
|
||||
private static void appendJSONPair(final StringBuilder json, final String key, final String value) throws UnsupportedEncodingException
|
||||
{
|
||||
private static void appendJSONPair(final StringBuilder json, final String key, final String value) throws UnsupportedEncodingException {
|
||||
boolean isValueNumeric = false;
|
||||
|
||||
try
|
||||
{
|
||||
if (value.equals("0") || !value.endsWith("0"))
|
||||
{
|
||||
|
||||
try {
|
||||
if (value.equals("0") || !value.endsWith("0")) {
|
||||
Double.parseDouble(value);
|
||||
isValueNumeric = true;
|
||||
}
|
||||
}
|
||||
catch (final NumberFormatException e)
|
||||
{
|
||||
} catch (final NumberFormatException e) {
|
||||
isValueNumeric = false;
|
||||
}
|
||||
|
||||
if (json.charAt(json.length() - 1) != '{')
|
||||
{
|
||||
|
||||
if (json.charAt(json.length() - 1) != '{') {
|
||||
json.append(',');
|
||||
}
|
||||
|
||||
|
||||
json.append(escapeJSON(key));
|
||||
json.append(':');
|
||||
|
||||
if (isValueNumeric)
|
||||
{
|
||||
|
||||
if (isValueNumeric) {
|
||||
json.append(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
json.append(escapeJSON(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Escape a string to create a valid JSON string
|
||||
*
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
private static String escapeJSON(final String text)
|
||||
{
|
||||
private static String escapeJSON(final String text) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
|
||||
builder.append('"');
|
||||
for (int index = 0; index < text.length(); index++)
|
||||
{
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
final char chr = text.charAt(index);
|
||||
|
||||
switch (chr)
|
||||
{
|
||||
|
||||
switch (chr) {
|
||||
case '"':
|
||||
case '\\':
|
||||
builder.append('\\');
|
||||
@ -565,32 +502,28 @@ public class SpongeMetrics
|
||||
builder.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ')
|
||||
{
|
||||
if (chr < ' ') {
|
||||
final String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u" + t.substring(t.length() - 4));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
builder.append(chr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
builder.append('"');
|
||||
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode text as UTF-8
|
||||
*
|
||||
* @param text the text to encode
|
||||
* @return the encoded text, as UTF-8
|
||||
*/
|
||||
private static String urlEncode(final String text) throws UnsupportedEncodingException
|
||||
{
|
||||
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(text, "UTF-8");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,16 +9,14 @@ import org.spongepowered.api.service.scheduler.TaskBuilder;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeTaskManager extends TaskManager
|
||||
{
|
||||
|
||||
public class SpongeTaskManager extends TaskManager {
|
||||
|
||||
private final AtomicInteger i = new AtomicInteger();
|
||||
|
||||
|
||||
private final HashMap<Integer, Task> tasks = new HashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public int taskRepeat(final Runnable r, final int interval)
|
||||
{
|
||||
public int taskRepeat(final Runnable r, final int interval) {
|
||||
final int val = i.incrementAndGet();
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
final TaskBuilder built = builder.delay(interval).interval(interval).execute(r);
|
||||
@ -26,10 +24,9 @@ public class SpongeTaskManager extends TaskManager
|
||||
tasks.put(val, task);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int taskRepeatAsync(final Runnable r, final int interval)
|
||||
{
|
||||
public int taskRepeatAsync(final Runnable r, final int interval) {
|
||||
final int val = i.incrementAndGet();
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
final TaskBuilder built = builder.delay(interval).async().interval(interval).execute(r);
|
||||
@ -37,43 +34,37 @@ public class SpongeTaskManager extends TaskManager
|
||||
tasks.put(val, task);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void taskAsync(final Runnable r)
|
||||
{
|
||||
public void taskAsync(final Runnable r) {
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.async().execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void task(final Runnable r)
|
||||
{
|
||||
public void task(final Runnable r) {
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void taskLater(final Runnable r, final int delay)
|
||||
{
|
||||
public void taskLater(final Runnable r, final int delay) {
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.delay(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void taskLaterAsync(final Runnable r, final int delay)
|
||||
{
|
||||
public void taskLaterAsync(final Runnable r, final int delay) {
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.async().delay(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void cancelTask(final int i)
|
||||
{
|
||||
public void cancelTask(final int i) {
|
||||
final Task task = tasks.remove(i);
|
||||
if (task != null)
|
||||
{
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,19 +8,11 @@ import com.intellectualcrafters.plot.util.AbstractTitle;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeTitleManager extends AbstractTitle
|
||||
{
|
||||
|
||||
public class SpongeTitleManager extends AbstractTitle {
|
||||
|
||||
@Override
|
||||
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out)
|
||||
{
|
||||
final Title title = new TitleBuilder()
|
||||
.title(SpongeMain.THIS.getText(head))
|
||||
.subtitle(SpongeMain.THIS.getText(sub))
|
||||
.fadeIn(in * 20)
|
||||
.stay(delay * 20)
|
||||
.fadeOut(out * 20)
|
||||
.build();
|
||||
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) {
|
||||
final Title title = new TitleBuilder().title(SpongeMain.THIS.getText(head)).subtitle(SpongeMain.THIS.getText(sub)).fadeIn(in * 20).stay(delay * 20).fadeOut(out * 20).build();
|
||||
((SpongePlayer) player).player.sendTitle(title);
|
||||
}
|
||||
}
|
||||
|
@ -15,26 +15,24 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeUtil
|
||||
{
|
||||
|
||||
public static Location getLocation(final Entity player)
|
||||
{
|
||||
public class SpongeUtil {
|
||||
|
||||
public static Location getLocation(final Entity player) {
|
||||
final String world = player.getWorld().getName();
|
||||
final org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
final Vector3i pos = loc.getBlockPosition();
|
||||
return new Location(world, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public static Location getLocation(final org.spongepowered.api.world.Location block)
|
||||
{
|
||||
|
||||
public static Location getLocation(final org.spongepowered.api.world.Location block) {
|
||||
final Extent extent = block.getExtent();
|
||||
if (extent instanceof World) { return getLocation(((World) extent).getName(), block); }
|
||||
if (extent instanceof World) {
|
||||
return getLocation(((World) extent).getName(), block);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Location getLocationFull(final Entity player)
|
||||
{
|
||||
|
||||
public static Location getLocationFull(final Entity player) {
|
||||
final String world = player.getWorld().getName();
|
||||
final Vector3d rot = player.getRotation();
|
||||
final float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ());
|
||||
@ -42,68 +40,74 @@ public class SpongeUtil
|
||||
final 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(final Player player)
|
||||
{
|
||||
if (player == lastPlayer) { return lastPlotPlayer; }
|
||||
|
||||
public static PlotPlayer getPlayer(final Player player) {
|
||||
if (player == lastPlayer) {
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
final String name = player.getName();
|
||||
final PlotPlayer pp = UUIDHandler.getPlayers().get(name);
|
||||
if (pp != null) { return pp; }
|
||||
if (pp != null) {
|
||||
return pp;
|
||||
}
|
||||
lastPlotPlayer = new SpongePlayer(player);
|
||||
UUIDHandler.getPlayers().put(name, lastPlotPlayer);
|
||||
lastPlayer = player;
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
|
||||
public static Player getPlayer(final PlotPlayer player)
|
||||
{
|
||||
if (player instanceof SpongePlayer) { return ((SpongePlayer) player).player; }
|
||||
|
||||
public static Player getPlayer(final PlotPlayer player) {
|
||||
if (player instanceof SpongePlayer) {
|
||||
return ((SpongePlayer) player).player;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static World lastWorld;
|
||||
private static String last;
|
||||
|
||||
public static World getWorld(final String world)
|
||||
{
|
||||
if (world == last) { return lastWorld; }
|
||||
|
||||
public static World getWorld(final String world) {
|
||||
if (world == last) {
|
||||
return lastWorld;
|
||||
}
|
||||
final Optional<World> optional = SpongeMain.THIS.getServer().getWorld(world);
|
||||
if (!optional.isPresent()) { return null; }
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
return optional.get();
|
||||
}
|
||||
|
||||
public static void removePlayer(final String player)
|
||||
{
|
||||
|
||||
public static void removePlayer(final String player) {
|
||||
lastPlayer = null;
|
||||
lastPlotPlayer = null;
|
||||
UUIDHandler.getPlayers().remove(player);
|
||||
}
|
||||
|
||||
public static Location getLocation(final String world, final org.spongepowered.api.world.Location spawn)
|
||||
{
|
||||
|
||||
public static Location getLocation(final String world, final org.spongepowered.api.world.Location spawn) {
|
||||
return new Location(world, spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ());
|
||||
}
|
||||
|
||||
public static String getWorldName(final org.spongepowered.api.world.Location origin)
|
||||
{
|
||||
|
||||
public static String getWorldName(final org.spongepowered.api.world.Location origin) {
|
||||
final Extent extent = origin.getExtent();
|
||||
if (extent == lastWorld) { return last; }
|
||||
if (extent instanceof World)
|
||||
{
|
||||
if (extent == lastWorld) {
|
||||
return last;
|
||||
}
|
||||
if (extent instanceof World) {
|
||||
lastWorld = (World) extent;
|
||||
last = ((World) extent).getName();
|
||||
return last;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static org.spongepowered.api.world.Location getLocation(final Location loc)
|
||||
{
|
||||
|
||||
public static org.spongepowered.api.world.Location getLocation(final Location loc) {
|
||||
final Optional<World> world = SpongeMain.THIS.getServer().getWorld(loc.getWorld());
|
||||
if (!world.isPresent()) { return null; }
|
||||
if (!world.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
return new org.spongepowered.api.world.Location(world.get(), loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
}
|
||||
|
@ -12,100 +12,79 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper
|
||||
{
|
||||
|
||||
public SpongeLowerOfflineUUIDWrapper()
|
||||
{
|
||||
public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
public SpongeLowerOfflineUUIDWrapper() {
|
||||
// Anything?
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final PlotPlayer player)
|
||||
{
|
||||
public UUID getUUID(final PlotPlayer player) {
|
||||
return getUUID(player.getName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final OfflinePlotPlayer player)
|
||||
{
|
||||
public UUID getUUID(final OfflinePlotPlayer player) {
|
||||
return getUUID(player.getName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid)
|
||||
{
|
||||
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
|
||||
String name = UUIDHandler.getName(uuid);
|
||||
if (name == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (name == null) {
|
||||
try {
|
||||
final GameProfile profile = SpongeMain.THIS.getResolver().get(uuid).get();
|
||||
if (profile != null)
|
||||
{
|
||||
if (profile != null) {
|
||||
name = profile.getName();
|
||||
}
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (name == null)
|
||||
{
|
||||
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles())
|
||||
{
|
||||
if (getUUID(profile.getName()).equals(uuid))
|
||||
{
|
||||
if (name == null) {
|
||||
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) {
|
||||
if (getUUID(profile.getName()).equals(uuid)) {
|
||||
name = profile.getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
final String username = name;
|
||||
return new OfflinePlotPlayer()
|
||||
{
|
||||
return new OfflinePlotPlayer() {
|
||||
@Override
|
||||
public boolean isOnline()
|
||||
{
|
||||
public boolean isOnline() {
|
||||
return UUIDHandler.getPlayer(uuid) != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID()
|
||||
{
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
return username;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getLastPlayed()
|
||||
{
|
||||
public long getLastPlayed() {
|
||||
// TODO FIXME
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Player[] getOnlinePlayers()
|
||||
{
|
||||
|
||||
public Player[] getOnlinePlayers() {
|
||||
return SpongeMain.THIS.getServer().getOnlinePlayers().toArray(new Player[0]);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final String name)
|
||||
{
|
||||
public UUID getUUID(final String name) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer[] getOfflinePlayers()
|
||||
{
|
||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||
// TODO FIXME
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
@ -9,81 +9,64 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeOnlineUUIDWrapper extends UUIDWrapper
|
||||
{
|
||||
|
||||
public class SpongeOnlineUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final PlotPlayer player)
|
||||
{
|
||||
public UUID getUUID(final PlotPlayer player) {
|
||||
return ((SpongePlayer) player).player.getUniqueId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final OfflinePlotPlayer player)
|
||||
{
|
||||
public UUID getUUID(final OfflinePlotPlayer player) {
|
||||
return player.getUUID();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID(final String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
public UUID getUUID(final String name) {
|
||||
try {
|
||||
return SpongeMain.THIS.getResolver().get(name, true).get().getUniqueId();
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid)
|
||||
{
|
||||
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
|
||||
String name;
|
||||
try
|
||||
{
|
||||
try {
|
||||
name = SpongeMain.THIS.getResolver().get(uuid, true).get().getName();
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
name = null;
|
||||
}
|
||||
final String username = name;
|
||||
return new OfflinePlotPlayer()
|
||||
{
|
||||
return new OfflinePlotPlayer() {
|
||||
@Override
|
||||
public boolean isOnline()
|
||||
{
|
||||
public boolean isOnline() {
|
||||
return UUIDHandler.getPlayer(uuid) != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getUUID()
|
||||
{
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
return username;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getLastPlayed()
|
||||
{
|
||||
public long getLastPlayed() {
|
||||
// TODO FIXME
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer[] getOfflinePlayers()
|
||||
{
|
||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -12,43 +12,37 @@ import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeUUIDHandler extends UUIDHandlerImplementation
|
||||
{
|
||||
|
||||
public SpongeUUIDHandler(final UUIDWrapper wrapper)
|
||||
{
|
||||
public class SpongeUUIDHandler extends UUIDHandlerImplementation {
|
||||
|
||||
public SpongeUUIDHandler(final UUIDWrapper wrapper) {
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean startCaching(final Runnable whenDone)
|
||||
{
|
||||
if (!super.startCaching(whenDone)) { return false; }
|
||||
public boolean startCaching(final Runnable whenDone) {
|
||||
if (!super.startCaching(whenDone)) {
|
||||
return false;
|
||||
}
|
||||
return cache(whenDone);
|
||||
}
|
||||
|
||||
public boolean cache(final Runnable whenDone)
|
||||
{
|
||||
|
||||
public boolean cache(final Runnable whenDone) {
|
||||
add(new StringWrapper("*"), DBFunc.everyone);
|
||||
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles())
|
||||
{
|
||||
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) {
|
||||
add(new StringWrapper(profile.getName()), profile.getUniqueId());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch)
|
||||
{
|
||||
TaskManager.runTaskAsync(new Runnable()
|
||||
{
|
||||
public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
ifFetch.value = uuidWrapper.getUUID(name);
|
||||
TaskManager.runTask(ifFetch);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user