mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-18 05:14:42 +02:00
cleanup
This commit is contained in:
@ -12,35 +12,45 @@ 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(Plot plot, 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(String worldname, int x1, int x2, int y1, int y2, int z1, int z2, 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++) {
|
||||
BlockState state = world.getBlock(x, y, z);
|
||||
PlotBlock block = SpongeMain.THIS.getPlotBlock(state);
|
||||
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++;
|
||||
}
|
||||
}
|
||||
@ -48,17 +58,23 @@ public class SpongeHybridUtils extends HybridUtils {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int get_ey(String worldname, int sx, int ex, int sz, int ez, 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) {
|
||||
BlockState state = world.getBlock(x, y, z);
|
||||
if (state != null && state.getType() != BlockTypes.AIR) {
|
||||
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))
|
||||
{
|
||||
ey = y;
|
||||
}
|
||||
}
|
||||
@ -67,5 +83,5 @@ public class SpongeHybridUtils extends HybridUtils {
|
||||
}
|
||||
return ey;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -80,189 +80,225 @@ import com.plotsquared.sponge.util.SpongeUtil;
|
||||
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
|
||||
import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper;
|
||||
import com.plotsquared.sponge.uuid.SpongeUUIDHandler;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
|
||||
/**
|
||||
* Created by robin on 01/11/2014
|
||||
*/
|
||||
|
||||
@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.0.0", dependencies="before:WorldEdit")
|
||||
public class SpongeMain implements IPlotMain, PluginContainer {
|
||||
@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.0.0", dependencies = "before:WorldEdit")
|
||||
public class SpongeMain implements IPlotMain, PluginContainer
|
||||
{
|
||||
public static SpongeMain THIS;
|
||||
|
||||
@Inject private Logger logger;
|
||||
@Inject private Game game;
|
||||
|
||||
@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(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(Locale l, Object... args) {
|
||||
public String get(final Locale l, final Object... args)
|
||||
{
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String get(Locale l) {
|
||||
public String get(final Locale l)
|
||||
{
|
||||
return m;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private PlotBlock NULL_BLOCK = new PlotBlock((short) 0, (byte) 0);
|
||||
|
||||
private final PlotBlock NULL_BLOCK = new PlotBlock((short) 0, (byte) 0);
|
||||
private BlockState[][] blockMap;
|
||||
private Map<BlockState, PlotBlock> blockMapReverse;
|
||||
|
||||
public BlockState getBlockState(PlotBlock block) {
|
||||
if (blockMap[block.id] == null) {
|
||||
|
||||
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(int id) {
|
||||
|
||||
public BlockState getBlockState(final int id)
|
||||
{
|
||||
return blockMap[id][0];
|
||||
}
|
||||
|
||||
public Collection<BlockState> getAllStates() {
|
||||
return this.blockMapReverse.keySet();
|
||||
public Collection<BlockState> getAllStates()
|
||||
{
|
||||
return blockMapReverse.keySet();
|
||||
}
|
||||
|
||||
public PlotBlock getPlotBlock(BlockState state) {
|
||||
PlotBlock val = blockMapReverse.get(state);
|
||||
if (val == null) {
|
||||
return NULL_BLOCK;
|
||||
}
|
||||
|
||||
public PlotBlock getPlotBlock(final BlockState state)
|
||||
{
|
||||
final PlotBlock val = blockMapReverse.get(state);
|
||||
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() {
|
||||
int[] version = PS.get().getVersion();
|
||||
public String getVersion()
|
||||
{
|
||||
final int[] version = PS.get().getVersion();
|
||||
String result = "";
|
||||
String prefix = "";
|
||||
for (int i : version) {
|
||||
for (final int i : version)
|
||||
{
|
||||
result += prefix + i;
|
||||
prefix = ".";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////// ON ENABLE /////////////////////
|
||||
@Subscribe
|
||||
public void init(InitializationEvent event) {
|
||||
public void init(final InitializationEvent event)
|
||||
{
|
||||
log("INIT");
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onInit(PreInitializationEvent event) {
|
||||
public void onInit(final PreInitializationEvent event)
|
||||
{
|
||||
log("PRE INIT");
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onServerAboutToStart(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();
|
||||
|
||||
ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
|
||||
if (worldSection != null) {
|
||||
for (String world : worldSection.getKeys(false)) {
|
||||
|
||||
final ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
|
||||
if (worldSection != null)
|
||||
{
|
||||
for (final String world : worldSection.getKeys(false))
|
||||
{
|
||||
createWorldFromConfig(world);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public World createWorldFromConfig(String world) {
|
||||
SpongeBasicGen generator = new SpongeBasicGen(world);
|
||||
PlotWorld plotworld = generator.getNewPlotWorld(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: {
|
||||
this.modify = new WorldModify(generator, false);
|
||||
switch (plotworld.TYPE)
|
||||
{
|
||||
// Normal
|
||||
case 0:
|
||||
{
|
||||
modify = new WorldModify(generator, false);
|
||||
game.getRegistry().registerWorldGeneratorModifier(modify);
|
||||
Optional<World> builder = game.getRegistry().createWorldBuilder()
|
||||
final Optional<World> builder = game.getRegistry().createWorldBuilder()
|
||||
.name(world)
|
||||
.enabled(true)
|
||||
.loadsOnStartup(true)
|
||||
@ -275,10 +311,11 @@ public class SpongeMain implements IPlotMain, PluginContainer {
|
||||
return builder.get();
|
||||
}
|
||||
// Augmented
|
||||
default: {
|
||||
this.modify = new WorldModify(generator, true);
|
||||
default:
|
||||
{
|
||||
modify = new WorldModify(generator, true);
|
||||
game.getRegistry().registerWorldGeneratorModifier(modify);
|
||||
Optional<World> builder = game.getRegistry().createWorldBuilder()
|
||||
final Optional<World> builder = game.getRegistry().createWorldBuilder()
|
||||
.name(world)
|
||||
.enabled(true)
|
||||
.loadsOnStartup(true)
|
||||
@ -292,100 +329,119 @@ public class SpongeMain implements IPlotMain, PluginContainer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerBlock(PlotBlock block, BlockState state) {
|
||||
BlockState[] val = blockMap[block.id];
|
||||
if (val == null) {
|
||||
|
||||
public void registerBlock(final PlotBlock block, final BlockState state)
|
||||
{
|
||||
final BlockState[] val = blockMap[block.id];
|
||||
if (val == null)
|
||||
{
|
||||
blockMap[block.id] = new BlockState[block.data + 1];
|
||||
}
|
||||
else if (val.length <= block.data) {
|
||||
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(BlockState state) {
|
||||
PlotBlock val = blockMapReverse.get(state);
|
||||
if (val != null) {
|
||||
return val;
|
||||
}
|
||||
|
||||
public PlotBlock registerBlock(final BlockState state)
|
||||
{
|
||||
final PlotBlock val = blockMapReverse.get(state);
|
||||
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);
|
||||
}
|
||||
PlotBlock block = new PlotBlock((short) 0, data);
|
||||
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>();
|
||||
HashMap<String, BlockState> states = new HashMap<>();
|
||||
|
||||
final HashMap<String, BlockState> states = new HashMap<>();
|
||||
|
||||
PS.get().copyFile("ids.txt", "config");
|
||||
PS.get().copyFile("data.txt", "config");
|
||||
|
||||
try {
|
||||
|
||||
File id_file = new File(getDirectory(), "config" + File.separator + "ids.txt");
|
||||
List<String> id_lines = Files.readAllLines(id_file.toPath(), StandardCharsets.UTF_8);
|
||||
|
||||
File data_file = new File(getDirectory(), "config" + File.separator + "data.txt");
|
||||
List<String> data_lines = Files.readAllLines(data_file.toPath(), StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
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 (Field field : fields) {
|
||||
BlockType type = (BlockType) field.get(null);
|
||||
BlockState state = type.getDefaultState();
|
||||
if (state != null) {
|
||||
try {
|
||||
for (final Field field : fields)
|
||||
{
|
||||
final BlockType type = (BlockType) field.get(null);
|
||||
final BlockState state = type.getDefaultState();
|
||||
if (state != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
states.put(type.getId() + ":" + 0, state);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
catch (final Exception e)
|
||||
{}
|
||||
}
|
||||
}
|
||||
String packaze = "org.spongepowered.api.data.type.";
|
||||
for (int i = 0; i < data_lines.size(); i++) {
|
||||
String classname = packaze + data_lines.get(i).trim();
|
||||
try {
|
||||
Class<?> clazz = Class.forName(classname);
|
||||
final String packaze = "org.spongepowered.api.data.type.";
|
||||
for (int i = 0; i < data_lines.size(); i++)
|
||||
{
|
||||
final String classname = packaze + data_lines.get(i).trim();
|
||||
try
|
||||
{
|
||||
final Class<?> clazz = Class.forName(classname);
|
||||
fields = clazz.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
CatalogType type = (CatalogType) field.get(null);
|
||||
String minecraft_id = type.getId();
|
||||
BlockState state = states.get(minecraft_id + ":" + 0);
|
||||
if (state == null) {
|
||||
for (final Field field : fields)
|
||||
{
|
||||
final CatalogType type = (CatalogType) field.get(null);
|
||||
final String minecraft_id = type.getId();
|
||||
final BlockState state = states.get(minecraft_id + ":" + 0);
|
||||
if (state == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {}
|
||||
catch (final Throwable e)
|
||||
{}
|
||||
}
|
||||
|
||||
|
||||
PlotBlock block = null;
|
||||
for (int i = 0; i < id_lines.size(); i++) {
|
||||
String line = id_lines.get(i).trim();
|
||||
switch(i%3) {
|
||||
case 0: {
|
||||
for (int i = 0; i < id_lines.size(); i++)
|
||||
{
|
||||
final String line = id_lines.get(i).trim();
|
||||
switch (i % 3)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
block = Configuration.BLOCK.parseString(line);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
case 1:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
String minecraft_id = line;
|
||||
BlockState state = states.remove(minecraft_id + ":" + block.data);
|
||||
if (state == null) {
|
||||
case 2:
|
||||
{
|
||||
final String minecraft_id = line;
|
||||
final BlockState state = states.remove(minecraft_id + ":" + block.data);
|
||||
if (state == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
registerBlock(block, state);
|
||||
@ -393,29 +449,35 @@ public class SpongeMain implements IPlotMain, PluginContainer {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Entry<String, BlockState> state : states.entrySet()) {
|
||||
for (final Entry<String, BlockState> state : states.entrySet())
|
||||
{
|
||||
log("REGISTERING: " + registerBlock(state.getValue()) + " | " + state.getValue().getType());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (final Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
public void onPlayerChat(final PlayerChatEvent event)
|
||||
{
|
||||
// This is how events sort of work?
|
||||
Player player = event.getUser();
|
||||
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;
|
||||
}
|
||||
@ -423,53 +485,60 @@ public class SpongeMain implements IPlotMain, PluginContainer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDirectory() {
|
||||
public File getDirectory()
|
||||
{
|
||||
return new File("mods/PlotSquared");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
public void disable()
|
||||
{
|
||||
PS.get().disable();
|
||||
THIS = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getPluginVersion() {
|
||||
PluginContainer plugin = game.getPluginManager().getPlugin("PlotSquared").get();
|
||||
String version = plugin.getVersion();
|
||||
public int[] getPluginVersion()
|
||||
{
|
||||
final PluginContainer plugin = game.getPluginManager().getPlugin("PlotSquared").get();
|
||||
final String version = plugin.getVersion();
|
||||
log("Checking plugin version: PlotSquared: ");
|
||||
String[] split = version.split("\\.");
|
||||
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: ");
|
||||
String version = game.getPlatform().getMinecraftVersion().getName();
|
||||
String[] split = version.split("\\.");
|
||||
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(String world, String name) {
|
||||
if (name == null) {
|
||||
return new SpongeGeneratorWrapper(world, null);
|
||||
}
|
||||
if (name.equals("PlotSquared")) {
|
||||
public SpongeGeneratorWrapper getGenerator(final String world, final String name)
|
||||
{
|
||||
if (name == null) { return new SpongeGeneratorWrapper(world, null); }
|
||||
if (name.equals("PlotSquared"))
|
||||
{
|
||||
return new SpongeGeneratorWrapper(world, new SpongeBasicGen(world));
|
||||
}
|
||||
else {
|
||||
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");
|
||||
@ -477,179 +546,212 @@ public class SpongeMain implements IPlotMain, PluginContainer {
|
||||
}
|
||||
|
||||
@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() {
|
||||
getGame().getCommandDispatcher().register(plugin, new SpongeCommand(), new String[] {"plots", "p", "plot", "ps", "plotsquared", "p2", "2"});
|
||||
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 (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(this.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(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(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(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 OfflinePlayer) {
|
||||
// return BukkitUtil.getPlayer((OfflinePlayer) obj);
|
||||
// }
|
||||
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,16 +22,20 @@ 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();
|
||||
@ -69,64 +73,79 @@ public class SpongeSchematicHandler extends SchematicHandler {
|
||||
|
||||
// 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() {
|
||||
long start = System.currentTimeMillis();
|
||||
while (chunks.size() > 0 && System.currentTimeMillis() - start < 20) {
|
||||
public void run()
|
||||
{
|
||||
final long start = System.currentTimeMillis();
|
||||
while ((chunks.size() > 0) && ((System.currentTimeMillis() - start) < 20))
|
||||
{
|
||||
// save schematics
|
||||
ChunkLoc chunk = chunks.remove(0);
|
||||
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;
|
||||
}
|
||||
|
||||
int X = chunk.x;
|
||||
int Z = chunk.z;
|
||||
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++) {
|
||||
int ry = y - sy;
|
||||
int i1 = (ry * width * length);
|
||||
for (int z = zzb; z <= zzt; z++) {
|
||||
int rz = z - p1z;
|
||||
int i2 = i1 + (rz * width);
|
||||
for (int x = xxb; x <= xxt; x++) {
|
||||
int rx = x - p1x;
|
||||
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++)
|
||||
{
|
||||
final int rz = z - p1z;
|
||||
final int i2 = i1 + (rz * width);
|
||||
for (int x = xxb; x <= xxt; x++)
|
||||
{
|
||||
final int rx = x - p1x;
|
||||
final int index = i2 + rx;
|
||||
|
||||
BlockState state = worldObj.getBlock(x, y, z);
|
||||
|
||||
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);
|
||||
}
|
||||
int id = block.id;
|
||||
switch (id) {
|
||||
final int id = block.id;
|
||||
switch (id)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
case 4:
|
||||
@ -197,7 +216,8 @@ public class SpongeSchematicHandler extends SchematicHandler {
|
||||
case 189:
|
||||
case 190:
|
||||
case 191:
|
||||
case 192: {
|
||||
case 192:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case 54:
|
||||
@ -234,11 +254,13 @@ 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;
|
||||
}
|
||||
}
|
||||
@ -248,12 +270,17 @@ 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>()));
|
||||
@ -270,5 +297,5 @@ public class SpongeSchematicHandler extends SchematicHandler {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,62 +19,67 @@ 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(PlotWorld plotworld) {
|
||||
if (SetupUtils.generators.size() == 0) {
|
||||
public String getGenerator(final PlotWorld plotworld)
|
||||
{
|
||||
if (SetupUtils.generators.size() == 0)
|
||||
{
|
||||
updateGenerators();
|
||||
}
|
||||
World world = SpongeUtil.getWorld(plotworld.worldname);
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
WorldGenerator generator = world.getWorldGenerator();
|
||||
if (!(generator instanceof SpongePlotGenerator)) {
|
||||
return null;
|
||||
}
|
||||
for (Entry<String, PlotGenerator<?>> entry : generators.entrySet()) {
|
||||
if (entry.getValue().generator.getClass().getName().equals(generator.getClass().getName())) {
|
||||
return entry.getKey();
|
||||
}
|
||||
final World world = SpongeUtil.getWorld(plotworld.worldname);
|
||||
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(); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String setupWorld(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);
|
||||
}
|
||||
PlotGenerator<WorldGenerator> gen = (PlotGenerator<WorldGenerator>) generators.get(object.setupGenerator);
|
||||
if (gen != null && gen.generator instanceof SpongePlotGenerator) {
|
||||
final PlotGenerator<WorldGenerator> gen = (PlotGenerator<WorldGenerator>) generators.get(object.setupGenerator);
|
||||
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);
|
||||
@ -82,7 +87,8 @@ public class SpongeSetupUtils extends SetupUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePopulator(String world, PlotCluster cluster) {
|
||||
public void removePopulator(final String world, final PlotCluster cluster)
|
||||
{
|
||||
AugmentedPopulator.removePopulator(world, cluster);
|
||||
}
|
||||
}
|
||||
|
@ -6,24 +6,27 @@ 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() {
|
||||
return this.cluster;
|
||||
public PlotCluster getCluster()
|
||||
{
|
||||
return cluster;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,17 +34,20 @@ public class ClusterFlagRemoveEvent extends AbstractEvent implements Cancellable
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag() {
|
||||
return this.flag;
|
||||
public Flag getFlag()
|
||||
{
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,47 +5,53 @@ 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() {
|
||||
return this.plot;
|
||||
public Plot getPlot()
|
||||
{
|
||||
return plot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if it was an automated claim, else false
|
||||
*/
|
||||
public boolean wasAuto() {
|
||||
return this.auto;
|
||||
public boolean wasAuto()
|
||||
{
|
||||
return auto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,28 +4,30 @@ 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;
|
||||
private boolean cancelled;
|
||||
|
||||
|
||||
/**
|
||||
* PlayerEnterPlotEvent: Called when a player leaves a plot
|
||||
*
|
||||
* @param player Player that entered the plot
|
||||
* @param plot Plot that was entered
|
||||
*/
|
||||
public PlayerEnterPlotEvent(final Player player, final Plot plot) {
|
||||
public PlayerEnterPlotEvent(final Player player, final Plot plot)
|
||||
{
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
public Plot getPlot()
|
||||
{
|
||||
return plot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,19 @@ 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(Player player) {
|
||||
public PlayerEvent(final Player player)
|
||||
{
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,28 +4,30 @@ 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;
|
||||
private boolean cancelled;
|
||||
|
||||
|
||||
/**
|
||||
* PlayerLeavePlotEvent: Called when a player leaves a plot
|
||||
*
|
||||
* @param player Player that left the plot
|
||||
* @param plot Plot that was left
|
||||
*/
|
||||
public PlayerLeavePlotEvent(final Player player, final Plot plot) {
|
||||
public PlayerLeavePlotEvent(final Player player, final Plot plot)
|
||||
{
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
public Plot getPlot()
|
||||
{
|
||||
return plot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,13 @@ 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
|
||||
*
|
||||
@ -20,20 +21,22 @@ 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() {
|
||||
return this.added;
|
||||
public boolean wasAdded()
|
||||
{
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,8 +44,9 @@ public class PlayerPlotDeniedEvent extends PlotEvent {
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return this.player;
|
||||
public UUID getPlayer()
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +54,8 @@ public class PlayerPlotDeniedEvent extends PlotEvent {
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return this.initiator;
|
||||
public Player getInitiator()
|
||||
{
|
||||
return initiator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,13 @@ 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
|
||||
*
|
||||
@ -20,20 +21,22 @@ 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() {
|
||||
return this.added;
|
||||
public boolean wasAdded()
|
||||
{
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,8 +44,9 @@ public class PlayerPlotHelperEvent extends PlotEvent {
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return this.player;
|
||||
public UUID getPlayer()
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +54,8 @@ public class PlayerPlotHelperEvent extends PlotEvent {
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return this.initiator;
|
||||
public Player getInitiator()
|
||||
{
|
||||
return initiator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,13 @@ 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
|
||||
*
|
||||
@ -20,20 +21,22 @@ 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() {
|
||||
return this.added;
|
||||
public boolean wasAdded()
|
||||
{
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,8 +44,9 @@ public class PlayerPlotTrustedEvent extends PlotEvent {
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return this.player;
|
||||
public UUID getPlayer()
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +54,8 @@ public class PlayerPlotTrustedEvent extends PlotEvent {
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return this.initiator;
|
||||
public Player getInitiator()
|
||||
{
|
||||
return initiator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,13 @@ 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
|
||||
*
|
||||
@ -19,19 +20,21 @@ 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() {
|
||||
return this.from;
|
||||
public Location getFrom()
|
||||
{
|
||||
return from;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,17 +42,20 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
public Plot getPlot()
|
||||
{
|
||||
return plot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ 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;
|
||||
@ -16,18 +17,20 @@ public class PlotClearEvent extends AbstractEvent implements Cancellable {
|
||||
* @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() {
|
||||
return this.id;
|
||||
public PlotId getPlotId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,17 +38,20 @@ public class PlotClearEvent extends AbstractEvent implements Cancellable {
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getWorld() {
|
||||
return this.world;
|
||||
public String getWorld()
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ 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;
|
||||
|
||||
@ -14,18 +15,20 @@ public class PlotDeleteEvent extends AbstractEvent {
|
||||
* @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() {
|
||||
return this.id;
|
||||
public PlotId getPlotId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,7 +36,8 @@ public class PlotDeleteEvent extends AbstractEvent {
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getWorld() {
|
||||
return this.world;
|
||||
public String getWorld()
|
||||
{
|
||||
return world;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,19 @@ 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() {
|
||||
return this.plot;
|
||||
public final Plot getPlot()
|
||||
{
|
||||
return plot;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ 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;
|
||||
|
||||
@ -15,27 +16,31 @@ public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
||||
* @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() {
|
||||
return this.flag;
|
||||
public Flag getFlag()
|
||||
{
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ 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;
|
||||
|
||||
@ -15,27 +16,31 @@ public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
|
||||
* @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() {
|
||||
return this.flag;
|
||||
public Flag getFlag()
|
||||
{
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ 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;
|
||||
@ -22,17 +23,19 @@ 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() {
|
||||
return this.plots;
|
||||
public ArrayList<PlotId> getPlots()
|
||||
{
|
||||
return plots;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,21 +43,25 @@ public class PlotMergeEvent extends AbstractEvent implements Cancellable {
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
public Plot getPlot()
|
||||
{
|
||||
return plot;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return this.world;
|
||||
public World getWorld()
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,25 +4,30 @@ 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() {
|
||||
return this.rater;
|
||||
|
||||
public PlotPlayer getRater()
|
||||
{
|
||||
return rater;
|
||||
}
|
||||
|
||||
public void setRating(Rating rating) {
|
||||
public void setRating(final Rating rating)
|
||||
{
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
public Rating getRating() {
|
||||
return this.rating;
|
||||
public Rating getRating()
|
||||
{
|
||||
return rating;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,8 @@ 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;
|
||||
@ -19,7 +20,8 @@ public class PlotUnlinkEvent extends AbstractEvent implements Cancellable {
|
||||
* @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;
|
||||
}
|
||||
@ -29,21 +31,25 @@ public class PlotUnlinkEvent extends AbstractEvent implements Cancellable {
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
public ArrayList<PlotId> getPlots() {
|
||||
return this.plots;
|
||||
public ArrayList<PlotId> getPlots()
|
||||
{
|
||||
return plots;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return this.world;
|
||||
public World getWorld()
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
public void setCancelled(final boolean cancel)
|
||||
{
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +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;
|
||||
@ -49,55 +50,67 @@ public class AugmentedPopulator implements Populator {
|
||||
private final int tx;
|
||||
private final int tz;
|
||||
|
||||
public AugmentedPopulator(String worldname, WorldGenerator gen, final SpongePlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b) {
|
||||
// MainUtil.initCache();
|
||||
public AugmentedPopulator(final String worldname, final WorldGenerator gen, final SpongePlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b)
|
||||
{
|
||||
// MainUtil.initCache();
|
||||
// Initialize any chach that's needed
|
||||
this.cluster = cluster;
|
||||
this.generator = generator;
|
||||
this.populator = generator.getBaseGeneratorPopulator();
|
||||
this.plotworld = generator.getNewPlotWorld(worldname);
|
||||
this.manager = generator.getPlotManager();
|
||||
populator = generator.getBaseGeneratorPopulator();
|
||||
plotworld = generator.getNewPlotWorld(worldname);
|
||||
manager = generator.getPlotManager();
|
||||
this.p = p;
|
||||
this.b = b;
|
||||
this.o = (this.plotworld.TERRAIN == 1) || (this.plotworld.TERRAIN == 2);
|
||||
if (cluster != null) {
|
||||
final Location bl = this.manager.getPlotBottomLocAbs(this.plotworld, cluster.getP1());
|
||||
final Location tl = this.manager.getPlotTopLocAbs(this.plotworld, cluster.getP2()).add(1, 0, 1);
|
||||
this.bx = bl.getX();
|
||||
this.bz = bl.getZ();
|
||||
this.tx = tl.getX();
|
||||
this.tz = tl.getZ();
|
||||
} else {
|
||||
this.bx = Integer.MIN_VALUE;
|
||||
this.bz = Integer.MIN_VALUE;
|
||||
this.tx = Integer.MAX_VALUE;
|
||||
this.tz = Integer.MAX_VALUE;
|
||||
o = (plotworld.TERRAIN == 1) || (plotworld.TERRAIN == 2);
|
||||
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
|
||||
{
|
||||
bx = Integer.MIN_VALUE;
|
||||
bz = Integer.MIN_VALUE;
|
||||
tx = Integer.MAX_VALUE;
|
||||
tz = Integer.MAX_VALUE;
|
||||
}
|
||||
// Add the populator
|
||||
List<Populator> populators = gen.getPopulators();
|
||||
if (this.o) {
|
||||
final List<Populator> populators = gen.getPopulators();
|
||||
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);
|
||||
List<Populator> populators = world.getWorldGenerator().getPopulators();
|
||||
for (final Iterator<Populator> iterator = populators.iterator(); iterator.hasNext();) {
|
||||
final List<Populator> populators = world.getWorldGenerator().getPopulators();
|
||||
for (final Iterator<Populator> iterator = populators.iterator(); iterator.hasNext();)
|
||||
{
|
||||
final Populator populator = iterator.next();
|
||||
if (populator instanceof AugmentedPopulator) {
|
||||
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
|
||||
if (populator instanceof AugmentedPopulator)
|
||||
{
|
||||
if (((AugmentedPopulator) populator).cluster.equals(cluster))
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void populate(final Chunk chunk, Random r_unused) {
|
||||
Vector3i min = chunk.getBlockMin();
|
||||
public void populate(final Chunk chunk, final Random r_unused)
|
||||
{
|
||||
final Vector3i min = chunk.getBlockMin();
|
||||
final World worldObj = chunk.getWorld();
|
||||
final String world = worldObj.getName();
|
||||
final int cx = min.getX() >> 4;
|
||||
@ -112,24 +125,29 @@ 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 (this.plotworld.TERRAIN == 3) {
|
||||
int X = min.getX();
|
||||
int Z = min.getZ();
|
||||
if (ChunkManager.FORCE_PASTE) {
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
if (!inX || !inZ) { return; }
|
||||
if (plotworld.TERRAIN == 3)
|
||||
{
|
||||
final int X = min.getX();
|
||||
final int Z = min.getZ();
|
||||
if (ChunkManager.FORCE_PASTE)
|
||||
{
|
||||
for (short x = 0; x < 16; x++)
|
||||
{
|
||||
for (short z = 0; z < 16; z++)
|
||||
{
|
||||
final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z));
|
||||
final HashMap<Short, Short> blocks = ChunkManager.GENERATE_BLOCKS.get(loc);
|
||||
HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(loc);
|
||||
for (final Entry<Short, Short> entry : blocks.entrySet()) {
|
||||
int y = entry.getKey();
|
||||
if (datas != null) {
|
||||
final HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(loc);
|
||||
for (final Entry<Short, Short> entry : blocks.entrySet())
|
||||
{
|
||||
final int y = entry.getKey();
|
||||
if (datas != null)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
@ -137,24 +155,31 @@ public class AugmentedPopulator implements Populator {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null)
|
||||
{
|
||||
PlotLoc loc;
|
||||
for (Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet()) {
|
||||
HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(entry.getKey());
|
||||
for (Entry<Short, Byte> entry2 : entry.getValue().entrySet()) {
|
||||
Short y = entry2.getKey();
|
||||
for (final Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet())
|
||||
{
|
||||
final HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(entry.getKey());
|
||||
for (final Entry<Short, Byte> entry2 : entry.getValue().entrySet())
|
||||
{
|
||||
final Short y = entry2.getKey();
|
||||
byte data;
|
||||
if (datas != null) {
|
||||
if (datas != null)
|
||||
{
|
||||
data = datas.get(y);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
data = 0;
|
||||
}
|
||||
loc = entry.getKey();
|
||||
int xx = loc.x - X;
|
||||
int zz = loc.z - Z;
|
||||
if (xx >= 0 && xx < 16) {
|
||||
if (zz >= 0 && zz < 16) {
|
||||
final int xx = loc.x - X;
|
||||
final int zz = loc.z - Z;
|
||||
if ((xx >= 0) && (xx < 16))
|
||||
{
|
||||
if ((zz >= 0) && (zz < 16))
|
||||
{
|
||||
SetBlockQueue.setBlock(world, xx, y, zz, new PlotBlock(entry2.getValue(), data));
|
||||
}
|
||||
}
|
||||
@ -165,172 +190,208 @@ public class AugmentedPopulator implements Populator {
|
||||
}
|
||||
final boolean check;
|
||||
check = !inX1 || !inX2 || !inZ1 || !inZ2;
|
||||
if (this.plotworld.TERRAIN > 1) {
|
||||
final PlotId plot1 = this.manager.getPlotIdAbs(this.plotworld, bx, 0, bz);
|
||||
final PlotId plot2 = this.manager.getPlotIdAbs(this.plotworld, tx, 0, tz);
|
||||
if ((plot1 != null) && (plot2 != null) && plot1.equals(plot2)) {
|
||||
return;
|
||||
}
|
||||
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 (this.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();
|
||||
MutableBlockVolume blocks = new MutableBlockVolume() {
|
||||
final MutableBlockVolume blocks = new MutableBlockVolume()
|
||||
{
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, 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;
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (manager.getPlotIdAbs(plotworld, x, 0, z) != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
PlotBlock block = SpongeMain.THIS.getPlotBlock(t);
|
||||
if (block != null) {
|
||||
final PlotBlock block = SpongeMain.THIS.getPlotBlock(t);
|
||||
if (block != null)
|
||||
{
|
||||
SetBlockQueue.setBlock(worldname, x, y, z, block);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBlock(Vector3i v, BlockState t) {
|
||||
public void setBlock(final Vector3i v, final BlockState t)
|
||||
{
|
||||
setBlock(v.getX(), v.getY(), v.getZ(), t);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockType getBlockType(int x, int y, int z) {
|
||||
public BlockType getBlockType(final int x, final int y, final int z)
|
||||
{
|
||||
return world.getBlockType(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockType getBlockType(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(int x, int y, int z) {
|
||||
public BlockState getBlock(final int x, final int y, final int z)
|
||||
{
|
||||
return world.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(Vector3i v) {
|
||||
public BlockState getBlock(final Vector3i v)
|
||||
{
|
||||
return getBlock(v.getX(), v.getY(), v.getZ());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean containsBlock(int x, int y, 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(Vector3i v) {
|
||||
public boolean containsBlock(final Vector3i v)
|
||||
{
|
||||
return containsBlock(v.getX(), v.getY(), v.getZ());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBlockType(int x, int y, int z, 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;
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (manager.getPlotIdAbs(plotworld, x, 0, z) != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
PlotBlock block = SpongeMain.THIS.getPlotBlock(t.getDefaultState());
|
||||
if (block != null) {
|
||||
final PlotBlock block = SpongeMain.THIS.getPlotBlock(t.getDefaultState());
|
||||
if (block != null)
|
||||
{
|
||||
SetBlockQueue.setBlock(worldname, x, y, z, block);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBlockType(Vector3i v, BlockType t) {
|
||||
public void setBlockType(final Vector3i v, final BlockType t)
|
||||
{
|
||||
setBlockType(v.getX(), v.getY(), v.getZ(), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableBlockVolume getBlockCopy() {
|
||||
// TODO Auto-generated method stub
|
||||
public MutableBlockVolume getBlockCopy()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableBlockVolume getBlockCopy(StorageType arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
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(DiscreteTransform3 arg0) {
|
||||
public MutableBlockVolume getBlockView(final DiscreteTransform3 arg0)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableBlockVolume getBlockView(Vector3i arg0, 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;
|
||||
}
|
||||
};
|
||||
this.populator.populate(world, blocks , null);
|
||||
populator.populate(world, blocks, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,31 +8,38 @@ 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 PlotWorld plotworld;
|
||||
private final PlotWorld plotworld;
|
||||
|
||||
public SpongeBasicBiomeProvider(PlotWorld plotworld) {
|
||||
public SpongeBasicBiomeProvider(final PlotWorld plotworld)
|
||||
{
|
||||
this.plotworld = plotworld;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateBiomes(MutableBiomeArea biomeBase) {
|
||||
Vector2i min = biomeBase.getBiomeMin();
|
||||
int bx = min.getX();
|
||||
int bz = min.getY();
|
||||
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 (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,22 +14,24 @@ 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(String world) {
|
||||
public SpongeBasicGen(final String world)
|
||||
{
|
||||
super(world);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Some generator specific variables (implementation dependent)
|
||||
*
|
||||
*
|
||||
* TODO USE THESE
|
||||
*
|
||||
*
|
||||
*/
|
||||
public int plotsize;
|
||||
public int pathsize;
|
||||
@ -40,7 +42,7 @@ public class SpongeBasicGen extends SpongePlotGenerator {
|
||||
public short pathWidthLower;
|
||||
public short pathWidthUpper;
|
||||
public boolean doState = false;
|
||||
|
||||
|
||||
BlockState wall;
|
||||
BlockState wallfilling;
|
||||
BlockState roadblock;
|
||||
@ -48,88 +50,108 @@ public class SpongeBasicGen extends SpongePlotGenerator {
|
||||
BlockState[] filling;
|
||||
|
||||
@Override
|
||||
public void init(PlotWorld plotworld) {
|
||||
if (plotworld != null) {
|
||||
public void init(final PlotWorld plotworld)
|
||||
{
|
||||
if (plotworld != null)
|
||||
{
|
||||
this.plotworld = (HybridPlotWorld) plotworld;
|
||||
}
|
||||
this.plotsize = this.plotworld.PLOT_WIDTH;
|
||||
this.pathsize = this.plotworld.ROAD_WIDTH;
|
||||
this.size = this.pathsize + this.plotsize;
|
||||
this.wallheight = this.plotworld.WALL_HEIGHT;
|
||||
this.roadheight = this.plotworld.ROAD_HEIGHT;
|
||||
this.plotheight = this.plotworld.PLOT_HEIGHT;
|
||||
if (this.pathsize == 0) {
|
||||
this.pathWidthLower = (short) -1;
|
||||
this.pathWidthUpper = (short) (this.plotsize + 1);
|
||||
plotsize = this.plotworld.PLOT_WIDTH;
|
||||
pathsize = this.plotworld.ROAD_WIDTH;
|
||||
size = pathsize + plotsize;
|
||||
wallheight = this.plotworld.WALL_HEIGHT;
|
||||
roadheight = this.plotworld.ROAD_HEIGHT;
|
||||
plotheight = this.plotworld.PLOT_HEIGHT;
|
||||
if (pathsize == 0)
|
||||
{
|
||||
pathWidthLower = (short) -1;
|
||||
pathWidthUpper = (short) (plotsize + 1);
|
||||
}
|
||||
else {
|
||||
if ((this.pathsize % 2) == 0) {
|
||||
this.pathWidthLower = (short) (Math.floor(this.pathsize / 2) - 1);
|
||||
} else {
|
||||
this.pathWidthLower = (short) (Math.floor(this.pathsize / 2));
|
||||
else
|
||||
{
|
||||
if ((pathsize % 2) == 0)
|
||||
{
|
||||
pathWidthLower = (short) (Math.floor(pathsize / 2) - 1);
|
||||
}
|
||||
this.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1);
|
||||
else
|
||||
{
|
||||
pathWidthLower = (short) (Math.floor(pathsize / 2));
|
||||
}
|
||||
pathWidthUpper = (short) (pathWidthLower + plotsize + 1);
|
||||
}
|
||||
|
||||
this.roadblock = SpongeMain.THIS.getBlockState(this.plotworld.ROAD_BLOCK);
|
||||
this.wallfilling = SpongeMain.THIS.getBlockState(this.plotworld.WALL_FILLING);
|
||||
this.wall = SpongeMain.THIS.getBlockState(this.plotworld.WALL_BLOCK);
|
||||
this.plotfloors = new BlockState[this.plotworld.TOP_BLOCK.length];
|
||||
for (int i = 0; i < this.plotworld.TOP_BLOCK.length; i++) {
|
||||
this.plotfloors[i] = SpongeMain.THIS.getBlockState(this.plotworld.TOP_BLOCK[i]);
|
||||
|
||||
roadblock = SpongeMain.THIS.getBlockState(this.plotworld.ROAD_BLOCK);
|
||||
wallfilling = SpongeMain.THIS.getBlockState(this.plotworld.WALL_FILLING);
|
||||
wall = SpongeMain.THIS.getBlockState(this.plotworld.WALL_BLOCK);
|
||||
plotfloors = new BlockState[this.plotworld.TOP_BLOCK.length];
|
||||
for (int i = 0; i < this.plotworld.TOP_BLOCK.length; i++)
|
||||
{
|
||||
plotfloors[i] = SpongeMain.THIS.getBlockState(this.plotworld.TOP_BLOCK[i]);
|
||||
}
|
||||
this.filling = new BlockState[this.plotworld.MAIN_BLOCK.length];
|
||||
for (int i = 0; i < this.plotworld.MAIN_BLOCK.length; i++) {
|
||||
this.filling[i] = SpongeMain.THIS.getBlockState(this.plotworld.MAIN_BLOCK[i]);
|
||||
filling = new BlockState[this.plotworld.MAIN_BLOCK.length];
|
||||
for (int i = 0; i < this.plotworld.MAIN_BLOCK.length; i++)
|
||||
{
|
||||
filling[i] = SpongeMain.THIS.getBlockState(this.plotworld.MAIN_BLOCK[i]);
|
||||
}
|
||||
if ((this.filling.length > 1) || (this.plotfloors.length > 1)) {
|
||||
this.doState = true;
|
||||
if ((filling.length > 1) || (plotfloors.length > 1))
|
||||
{
|
||||
doState = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotWorld getNewPlotWorld(String world) {
|
||||
if (this.plotworld == null) {
|
||||
this.plotworld = (HybridPlotWorld) PS.get().getPlotWorld(world);
|
||||
if (this.plotworld == null) {
|
||||
this.plotworld = new HybridPlotWorld(world);
|
||||
public PlotWorld getNewPlotWorld(final String world)
|
||||
{
|
||||
if (plotworld == null)
|
||||
{
|
||||
plotworld = (HybridPlotWorld) PS.get().getPlotWorld(world);
|
||||
if (plotworld == null)
|
||||
{
|
||||
plotworld = new HybridPlotWorld(world);
|
||||
}
|
||||
}
|
||||
return this.plotworld;
|
||||
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,24 +13,31 @@ 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 class SpongeBasicPop extends SpongePlotPopulator<SpongeBasicGen>
|
||||
{
|
||||
|
||||
public SpongeBasicPop(SpongeBasicGen generator) {
|
||||
public SpongeBasicPop(final SpongeBasicGen generator)
|
||||
{
|
||||
super(generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz) {
|
||||
int sx = (short) ((this.X - generator.plotworld.ROAD_OFFSET_X) % generator.size);
|
||||
int sz = (short) ((this.Z - generator.plotworld.ROAD_OFFSET_Z) % generator.size);
|
||||
if (sx < 0) {
|
||||
public void populate(final World world, final RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz)
|
||||
{
|
||||
int sx = (short) ((X - generator.plotworld.ROAD_OFFSET_X) % generator.size);
|
||||
int sz = (short) ((Z - generator.plotworld.ROAD_OFFSET_Z) % generator.size);
|
||||
if (sx < 0)
|
||||
{
|
||||
sx += generator.size;
|
||||
}
|
||||
if (sz < 0) {
|
||||
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;
|
||||
@ -38,83 +45,113 @@ 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()) {
|
||||
Byte data = datas.get(y);
|
||||
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) {
|
||||
HashSet<PlotItem> states = generator.plotworld.G_SCH_STATE.get(loc);
|
||||
if (states != null) {
|
||||
for (PlotItem items : states) {
|
||||
items.x = this.X + x;
|
||||
items.z = this.Z + z;
|
||||
if (generator.plotworld.G_SCH_STATE != null)
|
||||
{
|
||||
final HashSet<PlotItem> states = generator.plotworld.G_SCH_STATE.get(loc);
|
||||
if (states != null)
|
||||
{
|
||||
for (final PlotItem items : states)
|
||||
{
|
||||
items.x = X + x;
|
||||
items.z = Z + z;
|
||||
BlockManager.manager.addItems(generator.plotworld.worldname, items);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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()) {
|
||||
Byte data = datas.get(y);
|
||||
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,32 +11,41 @@ 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(String world, WorldGenerator generator) {
|
||||
|
||||
public SpongeGeneratorWrapper(final String world, final WorldGenerator generator)
|
||||
{
|
||||
super(world, generator);
|
||||
full = (generator instanceof SpongePlotGenerator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PlotWorld plotworld) {
|
||||
if (generator instanceof SpongePlotGenerator) {
|
||||
public void initialize(final PlotWorld plotworld)
|
||||
{
|
||||
if (generator instanceof SpongePlotGenerator)
|
||||
{
|
||||
((SpongePlotGenerator) generator).init(plotworld);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void augment(PlotCluster cluster, PlotWorld plotworld) {
|
||||
if (generator instanceof SpongePlotGenerator) {
|
||||
SpongePlotGenerator plotgen = (SpongePlotGenerator) generator;
|
||||
World worldObj = SpongeUtil.getWorld(world);
|
||||
if (worldObj != null) {
|
||||
if (cluster != null) {
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -44,51 +53,56 @@ public class SpongeGeneratorWrapper extends PlotGenerator<WorldGenerator>{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenerator(String gen_string) {
|
||||
if (gen_string == null) {
|
||||
public void setGenerator(final String gen_string)
|
||||
{
|
||||
if (gen_string == null)
|
||||
{
|
||||
generator = new SpongeBasicGen(world);
|
||||
} else {
|
||||
PlotGenerator<WorldGenerator> gen_wrapper = (PlotGenerator<WorldGenerator>) PS.get().IMP.getGenerator(world, gen_string);
|
||||
if (gen_wrapper != null) {
|
||||
}
|
||||
else
|
||||
{
|
||||
final PlotGenerator<WorldGenerator> gen_wrapper = (PlotGenerator<WorldGenerator>) PS.get().IMP.getGenerator(world, gen_string);
|
||||
if (gen_wrapper != null)
|
||||
{
|
||||
generator = gen_wrapper.generator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotWorld getNewPlotWorld(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(SetupObject object) {
|
||||
if (generator instanceof SpongePlotGenerator) {
|
||||
public void processSetup(final SetupObject object)
|
||||
{
|
||||
if (generator instanceof SpongePlotGenerator)
|
||||
{
|
||||
((SpongePlotGenerator) generator).processSetup(object);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -12,64 +12,72 @@ 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(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() {
|
||||
List<GeneratorPopulator> pops = new ArrayList<>();
|
||||
pops.addAll(this.getPlotPopulators());
|
||||
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(GeneratorPopulator arg0) {
|
||||
public void setBaseGeneratorPopulator(final GeneratorPopulator arg0)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiomeGenerator(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.
|
||||
* This is called when the generator is initialized.
|
||||
* You don't need to do anything with it necessarily.
|
||||
* @param plotworld
|
||||
*/
|
||||
public abstract void init(PlotWorld plotworld);
|
||||
|
||||
public abstract void init(final PlotWorld plotworld);
|
||||
|
||||
/**
|
||||
* Return a new instance of the PlotWorld for a world
|
||||
* Return a new instance of the PlotWorld for a world
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
@ -80,12 +88,13 @@ public abstract class SpongePlotGenerator implements WorldGenerator {
|
||||
* @return
|
||||
*/
|
||||
public abstract PlotManager getPlotManager();
|
||||
|
||||
|
||||
/**
|
||||
* If you need to do anything fancy for /plot setup<br>
|
||||
* - Otherwise it will just use the PlotWorld configuration<br>
|
||||
* Feel free to extend BukkitSetupUtils and customize world creation
|
||||
* @param object
|
||||
*/
|
||||
public void processSetup(SetupObject object) {}
|
||||
public void processSetup(final SetupObject object)
|
||||
{}
|
||||
}
|
||||
|
@ -11,55 +11,59 @@ 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 World world;
|
||||
private PseudoRandom random = new PseudoRandom();
|
||||
private final PseudoRandom random = new PseudoRandom();
|
||||
private MutableBlockVolume buffer;
|
||||
public final T generator;
|
||||
|
||||
public SpongePlotPopulator(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();
|
||||
|
||||
// }
|
||||
|
||||
public void populate(World world, MutableBlockVolume buffer, ImmutableBiomeArea biomeBase) {
|
||||
try {
|
||||
this.world = world;
|
||||
// @Override
|
||||
// public void populate(Chunk chunk, Random random) {
|
||||
// this.world = chunk.getWorld();
|
||||
// this.worldname = world.getName();
|
||||
// Vector3i min = chunk.getBlockMin();
|
||||
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void populate(final World world, final MutableBlockVolume buffer, final ImmutableBiomeArea biomeBase)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.worldname = world.getName();
|
||||
this.buffer = buffer;
|
||||
Vector3i min = buffer.getBlockMin();
|
||||
final Vector3i min = buffer.getBlockMin();
|
||||
this.X = min.getX();
|
||||
this.Z = min.getZ();
|
||||
int cx = X >> 4;
|
||||
int cz = Z >> 4;
|
||||
final int cx = X >> 4;
|
||||
final int cz = Z >> 4;
|
||||
int h = 1;
|
||||
final int prime = 13;
|
||||
h = (prime * h) + cx;
|
||||
h = (prime * h) + cz;
|
||||
this.random.state = h;
|
||||
|
||||
|
||||
// TODO plot clearing stuff
|
||||
|
||||
|
||||
populate(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (final Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
};
|
||||
|
||||
public abstract void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz);
|
||||
|
||||
|
||||
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
|
||||
@ -68,17 +72,20 @@ public abstract class SpongePlotPopulator<T extends SpongePlotGenerator> impleme
|
||||
* @param id
|
||||
* @param data
|
||||
*/
|
||||
public void setBlock(int x, int y, int z, 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(int x, int y, int z, BlockState[] states) {
|
||||
if (states.length == 1) {
|
||||
setBlock(x,y,z,states[0]);
|
||||
|
||||
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)]);
|
||||
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
|
||||
@ -86,10 +93,11 @@ public abstract class SpongePlotPopulator<T extends SpongePlotGenerator> impleme
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(final RegionWrapper plot, final int x, final int z) {
|
||||
int xx = X + x;
|
||||
int zz = Z + 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,45 +9,55 @@ 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 SpongePlotGenerator plotgen;
|
||||
private boolean augment;
|
||||
private final SpongePlotGenerator plotgen;
|
||||
private final boolean augment;
|
||||
|
||||
public WorldModify(SpongePlotGenerator plotgen, boolean augment) {
|
||||
public WorldModify(final SpongePlotGenerator plotgen, final boolean augment)
|
||||
{
|
||||
this.plotgen = plotgen;
|
||||
this.augment = augment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyWorldGenerator(WorldCreationSettings world, DataContainer settings, WorldGenerator gen) {
|
||||
if (augment) {
|
||||
String worldname = plotgen.world;
|
||||
PlotWorld plotworld = plotgen.getNewPlotWorld(worldname);
|
||||
if (plotworld.TYPE == 2) {
|
||||
for (PlotCluster cluster : ClusterManager.getClusters(worldname)) {
|
||||
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))
|
||||
{
|
||||
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
@ -10,9 +10,7 @@ import org.spongepowered.api.data.value.mutable.Value;
|
||||
import org.spongepowered.api.entity.player.Player;
|
||||
import org.spongepowered.api.entity.player.gamemode.GameMode;
|
||||
import org.spongepowered.api.entity.player.gamemode.GameModes;
|
||||
import org.spongepowered.api.text.TextBuilder;
|
||||
import org.spongepowered.api.text.Texts;
|
||||
import org.spongepowered.api.text.action.HoverAction;
|
||||
import org.spongepowered.api.text.chat.ChatTypes;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
@ -21,7 +19,6 @@ import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlotGamemode;
|
||||
import com.intellectualcrafters.plot.util.PlotWeather;
|
||||
@ -29,7 +26,8 @@ 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;
|
||||
@ -38,84 +36,91 @@ public class SpongePlayer extends PlotPlayer {
|
||||
public HashSet<String> hasPerm = new HashSet<>();
|
||||
public HashSet<String> noPerm = new HashSet<>();
|
||||
|
||||
public SpongePlayer(Player player) {
|
||||
public SpongePlayer(final Player player)
|
||||
{
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendMessage(C c, 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() {
|
||||
Value<Date> data = player.getJoinData().lastPlayed();
|
||||
if (data.exists()) {
|
||||
return last = data.get().getSeconds() * 1000;
|
||||
}
|
||||
public long getPreviousLogin()
|
||||
{
|
||||
final Value<Date> data = player.getJoinData().lastPlayed();
|
||||
if (data.exists()) { return last = data.get().getSeconds() * 1000; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
Location loc = super.getLocation();
|
||||
return loc == null ? SpongeUtil.getLocation(this.player) : loc;
|
||||
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 (this.uuid == null) {
|
||||
this.uuid = UUIDHandler.getUUID(this);
|
||||
public UUID getUUID()
|
||||
{
|
||||
if (uuid == null)
|
||||
{
|
||||
uuid = UUIDHandler.getUUID(this);
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String perm) {
|
||||
if (Settings.PERMISSION_CACHING) {
|
||||
if (this.noPerm.contains(perm)) {
|
||||
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)
|
||||
{
|
||||
noPerm.add(perm);
|
||||
return false;
|
||||
}
|
||||
if (this.hasPerm.contains(perm)) {
|
||||
return true;
|
||||
}
|
||||
final boolean result = this.player.hasPermission(perm);
|
||||
if (!result) {
|
||||
this.noPerm.add(perm);
|
||||
return false;
|
||||
}
|
||||
this.hasPerm.add(perm);
|
||||
hasPerm.add(perm);
|
||||
return true;
|
||||
}
|
||||
boolean value = this.player.hasPermission(perm);
|
||||
final boolean value = player.hasPermission(perm);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
public void sendMessage(final String message)
|
||||
{
|
||||
player.sendMessage(ChatTypes.CHAT, Texts.of(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(Location loc) {
|
||||
if (Math.abs(loc.getX()) >= 30000000 || Math.abs(loc.getZ()) >= 30000000) {
|
||||
return;
|
||||
}
|
||||
String world = player.getWorld().getName();
|
||||
if (!world.equals(loc.getWorld())) {
|
||||
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()));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
org.spongepowered.api.world.Location current = player.getLocation();
|
||||
current = current.setPosition(new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
|
||||
player.setLocation(current);
|
||||
@ -123,120 +128,128 @@ public class SpongePlayer extends PlotPlayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
public boolean isOnline()
|
||||
{
|
||||
return player.isOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (this.name == null) {
|
||||
this.name = this.player.getName();
|
||||
public String getName()
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
name = player.getName();
|
||||
}
|
||||
return this.name;
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompassTarget(Location loc) {
|
||||
TargetedLocationData target = player.getOrCreate(TargetedLocationData.class).get();
|
||||
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);
|
||||
// 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);
|
||||
// EconHandler.manager.setPermission(getName(), key, false);
|
||||
deleteMeta(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeather(PlotWeather weather) {
|
||||
public void setWeather(final PlotWeather weather)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotGamemode getGamemode() {
|
||||
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;
|
||||
}
|
||||
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; }
|
||||
throw new UnsupportedOperationException("INVALID GAMEMODE");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGamemode(PlotGamemode gamemode) {
|
||||
public void setGamemode(final PlotGamemode gamemode)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
// switch (gamemode) {
|
||||
// case ADVENTURE:
|
||||
// player.offer(Keys.GAME_MODE, GameModes.ADVENTURE);
|
||||
// return;
|
||||
// case CREATIVE:
|
||||
// player.offer(Keys.GAME_MODE, GameModes.CREATIVE);
|
||||
// return;
|
||||
// case SPECTATOR:
|
||||
// player.offer(Keys.GAME_MODE, GameModes.SPECTATOR);
|
||||
// return;
|
||||
// case SURVIVAL:
|
||||
// player.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
|
||||
// return;
|
||||
// }
|
||||
// switch (gamemode) {
|
||||
// case ADVENTURE:
|
||||
// player.offer(Keys.GAME_MODE, GameModes.ADVENTURE);
|
||||
// return;
|
||||
// case CREATIVE:
|
||||
// player.offer(Keys.GAME_MODE, GameModes.CREATIVE);
|
||||
// return;
|
||||
// case SPECTATOR:
|
||||
// player.offer(Keys.GAME_MODE, GameModes.SPECTATOR);
|
||||
// return;
|
||||
// case SURVIVAL:
|
||||
// player.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTime(long time) {
|
||||
public void setTime(final long time)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlight(boolean fly) {
|
||||
public void setFlight(final boolean fly)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playMusic(Location loc, 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(String message) {
|
||||
public void kick(final String message)
|
||||
{
|
||||
player.kick(SpongeMain.THIS.getText(message));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
public class KillRoadMobs {
|
||||
public void run() {
|
||||
public class KillRoadMobs
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
// TODO kill road mobs
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import org.spongepowered.api.block.BlockType;
|
||||
import org.spongepowered.api.block.BlockTypes;
|
||||
import org.spongepowered.api.block.tileentity.Sign;
|
||||
import org.spongepowered.api.block.tileentity.TileEntity;
|
||||
import org.spongepowered.api.data.key.Keys;
|
||||
import org.spongepowered.api.data.manipulator.mutable.tileentity.SignData;
|
||||
import org.spongepowered.api.data.value.mutable.ListValue;
|
||||
import org.spongepowered.api.text.Text;
|
||||
@ -25,177 +24,195 @@ 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(PlotBlock block) {
|
||||
BlockState state = SpongeMain.THIS.getBlockState(block);
|
||||
BlockType type = state.getType();
|
||||
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;
|
||||
String[] split = name.split(":");
|
||||
if (split.length == 2) {
|
||||
final String[] split = name.split(":");
|
||||
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 {
|
||||
StringComparison<BlockState>.ComparisonResult comparison = new StringComparison<BlockState>(name, SpongeMain.THIS.getAllStates()) {
|
||||
public String getString(BlockState o) {
|
||||
else
|
||||
{
|
||||
final StringComparison<BlockState>.ComparisonResult comparison = new StringComparison<BlockState>(name, SpongeMain.THIS.getAllStates())
|
||||
{
|
||||
@Override
|
||||
public String getString(final BlockState o)
|
||||
{
|
||||
return o.getType().getId();
|
||||
};
|
||||
}.getBestMatchAdvanced();
|
||||
match = comparison.match;
|
||||
id = SpongeMain.THIS.getPlotBlock(comparison.best).id;
|
||||
}
|
||||
PlotBlock block = new PlotBlock(id, data);
|
||||
StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
||||
final PlotBlock block = new PlotBlock(id, data);
|
||||
final StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
||||
return outer.new ComparisonResult(match, block);
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e) {}
|
||||
catch (final Exception e)
|
||||
{}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getClosestMatchingName(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(String world, PlotItem items) {
|
||||
public boolean addItems(final String world, final PlotItem items)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getBiomeFromString(String biome) {
|
||||
public int getBiomeFromString(final String biome)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotBlock getPlotBlockFromString(String block) {
|
||||
public PlotBlock getPlotBlockFromString(final String block)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getHeighestBlock(String worldname, int x, int z) {
|
||||
World world = SpongeUtil.getWorld(worldname);
|
||||
if (world == null) {
|
||||
return 64;
|
||||
}
|
||||
for (int y = 255; y > 0; y--) {
|
||||
BlockState block = world.getBlock(x, y, z);
|
||||
if (block != null && block.getType() != BlockTypes.AIR) {
|
||||
return y+1;
|
||||
}
|
||||
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--)
|
||||
{
|
||||
final BlockState block = world.getBlock(x, y, z);
|
||||
if ((block != null) && (block.getType() != BlockTypes.AIR)) { return y + 1; }
|
||||
}
|
||||
return 64;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getBiome(String world, int x, int z) {
|
||||
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(Location loc) {
|
||||
BlockState state = SpongeUtil.getWorld(loc.getWorld()).getBlock(loc.getX(), loc.getY(), loc.getZ());
|
||||
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(String world) {
|
||||
World worldObj = SpongeUtil.getWorld(world);
|
||||
org.spongepowered.api.world.Location loc = worldObj.getSpawnLocation();
|
||||
Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
|
||||
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(Location loc) {
|
||||
World world = SpongeUtil.getWorld(loc.getWorld());
|
||||
Optional<TileEntity> block = world.getTileEntity(loc.getX(), loc.getY(), loc.getZ());
|
||||
if (!block.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) {
|
||||
return null;
|
||||
}
|
||||
Sign sign = (Sign) tile;
|
||||
Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
String[] result = new String[4];
|
||||
ListValue<Text> lines = optional.get().lines();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
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; }
|
||||
final TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) { return null; }
|
||||
final Sign sign = (Sign) tile;
|
||||
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||
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++)
|
||||
{
|
||||
result[i] = lines.get(i).toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isWorld(String world) {
|
||||
public boolean isWorld(final String world)
|
||||
{
|
||||
return SpongeUtil.getWorld(world) != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void functionSetBlocks(String worldname, int[] xv, int[] yv, int[] zv, int[] id, byte[] data) {
|
||||
for (int i = 0; i < xv.length; i++) {
|
||||
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(String worldname, int x, int y, int z, String[] lines) {
|
||||
World world = SpongeUtil.getWorld(worldname);
|
||||
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());
|
||||
Optional<TileEntity> block = world.getTileEntity(x, y, z);
|
||||
if (!block.isPresent()) {
|
||||
return;
|
||||
}
|
||||
TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) {
|
||||
return;
|
||||
}
|
||||
Sign sign = (Sign) tile;
|
||||
List<Text> text = new ArrayList<>(4);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
final Optional<TileEntity> block = world.getTileEntity(x, y, z);
|
||||
if (!block.isPresent()) { return; }
|
||||
final TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) { return; }
|
||||
final Sign sign = (Sign) tile;
|
||||
final List<Text> text = new ArrayList<>(4);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
text.add(SpongeMain.THIS.getText(lines[i]));
|
||||
}
|
||||
try {
|
||||
Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||
if(optional.isPresent()) {
|
||||
SignData offering = optional.get();
|
||||
try
|
||||
{
|
||||
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||
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]));
|
||||
offering.lines().set(2, SpongeMain.THIS.getText(lines[2]));
|
||||
@ -203,43 +220,51 @@ public class SpongeBlockManager extends BlockManager {
|
||||
sign.offer(offering);
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e) {
|
||||
catch (final NullPointerException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void functionSetBlock(String worldname, int x, int y, int z, int id, 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;
|
||||
}
|
||||
World world = SpongeUtil.getWorld(worldname);
|
||||
BlockState block = world.getBlock(x, y, z);
|
||||
if (block != state) {
|
||||
if (state == null) { return; }
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final BlockState block = world.getBlock(x, y, z);
|
||||
if (block != state)
|
||||
{
|
||||
world.setBlock(x, y, z, state);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void functionSetBiomes(String worldname, int[] xv, int[] zv, 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 (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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
|
||||
import org.spongepowered.api.text.TextBuilder;
|
||||
import org.spongepowered.api.text.Texts;
|
||||
import org.spongepowered.api.text.action.TextActions;
|
||||
@ -11,56 +10,68 @@ 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(PlotMessage m, String color) {
|
||||
public void color(final PlotMessage m, final String color)
|
||||
{
|
||||
m.$(this).color(Texts.of(color).getColor());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tooltip(PlotMessage m, PlotMessage... tooltips) {
|
||||
TextBuilder builder = Texts.builder();
|
||||
public void tooltip(final PlotMessage m, final PlotMessage... tooltips)
|
||||
{
|
||||
final TextBuilder builder = Texts.builder();
|
||||
boolean lb = false;
|
||||
for (PlotMessage tooltip : tooltips) {
|
||||
if (lb) {
|
||||
for (final PlotMessage tooltip : tooltips)
|
||||
{
|
||||
if (lb)
|
||||
{
|
||||
builder.append(Texts.of("\n"));
|
||||
}
|
||||
builder.append(tooltip.$(this).build());
|
||||
lb = true;
|
||||
}
|
||||
// AchievementBuilder builder = SpongeMain.THIS.getGame().getRegistry().createAchievementBuilder();
|
||||
// AchievementBuilder builder = SpongeMain.THIS.getGame().getRegistry().createAchievementBuilder();
|
||||
m.$(this).onHover(TextActions.showText(builder.toText()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void command(PlotMessage m, String command) {
|
||||
public void command(final PlotMessage m, final String command)
|
||||
{
|
||||
m.$(this).onClick(TextActions.runCommand(command));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void text(PlotMessage m, String text) {
|
||||
public void text(final PlotMessage m, final String text)
|
||||
{
|
||||
m.$(this).append(Texts.of(text));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void send(PlotMessage m, 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(PlotMessage m, String command) {
|
||||
public void suggest(final PlotMessage m, final String command)
|
||||
{
|
||||
m.$(this).onClick(TextActions.suggestCommand(command));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.plotsquared.sponge.util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.api.data.DataContainer;
|
||||
import org.spongepowered.api.entity.Entity;
|
||||
import org.spongepowered.api.entity.living.Living;
|
||||
import org.spongepowered.api.entity.living.animal.Animal;
|
||||
@ -23,43 +22,56 @@ 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(ChunkWrapper loc, PlotBlock[][] result) {
|
||||
public void setChunk(final ChunkWrapper loc, final PlotBlock[][] result)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] countEntities(Plot plot) {
|
||||
Location pos1 = plot.getBottom();
|
||||
Location pos2 = plot.getTop();
|
||||
|
||||
String worldname = pos1.getWorld();
|
||||
World world = SpongeUtil.getWorld(worldname);
|
||||
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();
|
||||
final int bz = pos1.getZ();
|
||||
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(Entity entity) {
|
||||
org.spongepowered.api.world.Location loc = entity.getLocation();
|
||||
int x = loc.getBlockX();
|
||||
if (x >= bx && x <= tx) {
|
||||
int z = loc.getBlockZ();
|
||||
if (z >= bz && z <= tz) {
|
||||
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))
|
||||
{
|
||||
final int z = loc.getBlockZ();
|
||||
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]++;
|
||||
}
|
||||
}
|
||||
@ -67,108 +79,124 @@ public class SpongeChunkManager extends ChunkManager {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
|
||||
World worldObj = SpongeUtil.getWorld(world);
|
||||
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(String world, ChunkLoc loc, boolean save, boolean safe) {
|
||||
World worldObj = SpongeUtil.getWorld(world);
|
||||
Optional<Chunk> chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4);
|
||||
if (chunk.isPresent()) {
|
||||
return worldObj.unloadChunk(chunk.get());
|
||||
}
|
||||
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()); }
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ChunkLoc> getChunkChunks(String world) {
|
||||
ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
|
||||
World worldObj = SpongeUtil.getWorld(world);
|
||||
ChunkDataStream storage = worldObj.getWorldStorage().getGeneratedChunks();
|
||||
while (storage.hasNext()) {
|
||||
DataContainer data = storage.next();
|
||||
|
||||
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())
|
||||
{
|
||||
storage.next();
|
||||
|
||||
// TODO get chunk from DataContainer
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void regenerateChunk(String world, ChunkLoc loc) {
|
||||
World worldObj = SpongeUtil.getWorld(world);
|
||||
Optional<Chunk> chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4);
|
||||
if (chunk.isPresent()) {
|
||||
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())
|
||||
{
|
||||
// TODO regenerate chunk
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteRegionFile(String world, ChunkLoc loc) {
|
||||
public void deleteRegionFile(final String world, final ChunkLoc loc)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRegionFiles(String world, List<ChunkLoc> chunks) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plot hasPlot(String world, ChunkLoc chunk) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean copyRegion(Location pos1, Location pos2, Location newPos, Runnable whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
TaskManager.runTask(whenDone);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean regenerateRegion(Location pos1, Location pos2, Runnable whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
TaskManager.runTask(whenDone);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swap(String world, PlotId id, PlotId plotid) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swap(String worldname, Location bot1, Location top1, Location bot2, Location top2) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllEntities(Location pos1, Location pos2) {
|
||||
String worldname = pos1.getWorld();
|
||||
World world = SpongeUtil.getWorld(worldname);
|
||||
public void deleteRegionFiles(final String world, final List<ChunkLoc> chunks)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
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)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
TaskManager.runTask(whenDone);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
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)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
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)
|
||||
{
|
||||
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(Entity entity) {
|
||||
org.spongepowered.api.world.Location loc = entity.getLocation();
|
||||
int x = loc.getBlockX();
|
||||
if (x >= bx && x <= tx) {
|
||||
int z = loc.getBlockZ();
|
||||
if (z >= bz && z <= tz) {
|
||||
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))
|
||||
{
|
||||
final int z = loc.getBlockZ();
|
||||
if ((z >= bz) && (z <= tz))
|
||||
{
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
@ -176,5 +204,5 @@ public class SpongeChunkManager extends ChunkManager {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,52 +19,63 @@ 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(CommandSource cmd, String string) throws CommandException {
|
||||
String id = cmd.getIdentifier();
|
||||
public CommandResult process(final CommandSource cmd, final String string) throws CommandException
|
||||
{
|
||||
final String id = cmd.getIdentifier();
|
||||
PlotPlayer pp;
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get();
|
||||
try
|
||||
{
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get();
|
||||
pp = SpongeUtil.getPlayer(player);
|
||||
}
|
||||
catch (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(CommandSource cmd, 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(CommandSource cmd) {
|
||||
public boolean testPermission(final CommandSource cmd)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getShortDescription(CommandSource cmd) {
|
||||
public Optional<? extends Text> getShortDescription(final CommandSource cmd)
|
||||
{
|
||||
return Optional.of(Texts.of("Shows plot help"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getHelp(CommandSource cmd) {
|
||||
public Optional<? extends Text> getHelp(final CommandSource cmd)
|
||||
{
|
||||
return Optional.of(Texts.of("/plot help"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getUsage(CommandSource cmd) {
|
||||
public Text getUsage(final CommandSource cmd)
|
||||
{
|
||||
return Texts.of("/plot <command>");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -32,97 +32,113 @@ 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() {
|
||||
this.events = SpongeMain.THIS.getGame().getEventManager();
|
||||
public SpongeEventUtil()
|
||||
{
|
||||
events = SpongeMain.THIS.getGame().getEventManager();
|
||||
}
|
||||
|
||||
public boolean callEvent(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(PlotPlayer player, Plot plot, 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(PlotPlayer player, Location from, 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(String world, PlotId id) {
|
||||
public boolean callClear(final String world, final PlotId id)
|
||||
{
|
||||
return callEvent(new PlotClearEvent(world, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callDelete(String world, PlotId id) {
|
||||
public void callDelete(final String world, final PlotId id)
|
||||
{
|
||||
callEvent(new PlotDeleteEvent(world, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagAdd(Flag flag, Plot plot) {
|
||||
public boolean callFlagAdd(final Flag flag, final Plot plot)
|
||||
{
|
||||
return callEvent(new PlotFlagAddEvent(flag, plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(Flag flag, Plot plot) {
|
||||
public boolean callFlagRemove(final Flag flag, final Plot plot)
|
||||
{
|
||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callMerge(String world, Plot plot, 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(String world, 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(PlotPlayer player, Plot plot) {
|
||||
public void callEntry(final PlotPlayer player, final Plot plot)
|
||||
{
|
||||
callEvent(new PlayerEnterPlotEvent(SpongeUtil.getPlayer(player), plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callLeave(PlotPlayer player, Plot plot) {
|
||||
public void callLeave(final PlotPlayer player, final Plot plot)
|
||||
{
|
||||
callEvent(new PlayerLeavePlotEvent(SpongeUtil.getPlayer(player), plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callDenied(PlotPlayer initiator, Plot plot, UUID player, 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(PlotPlayer initiator, Plot plot, UUID player, 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(PlotPlayer initiator, Plot plot, UUID player, 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(Flag flag, PlotCluster cluster) {
|
||||
public boolean callFlagRemove(final Flag flag, final PlotCluster cluster)
|
||||
{
|
||||
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
|
||||
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import org.spongepowered.api.item.ItemType;
|
||||
import org.spongepowered.api.item.ItemTypes;
|
||||
import org.spongepowered.api.item.inventory.Carrier;
|
||||
import org.spongepowered.api.item.inventory.Inventories;
|
||||
import org.spongepowered.api.item.inventory.Inventory;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
import org.spongepowered.api.item.inventory.ItemStackBuilder;
|
||||
import org.spongepowered.api.item.inventory.custom.CustomInventory;
|
||||
@ -22,95 +21,97 @@ 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() {
|
||||
this.builder = SpongeMain.THIS.getGame().getRegistry().createItemBuilder();
|
||||
public SpongeInventoryUtil()
|
||||
{
|
||||
builder = SpongeMain.THIS.getGame().getRegistry().createItemBuilder();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void open(PlotInventory inv) {
|
||||
public void open(final PlotInventory inv)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
Player player = sp.player;
|
||||
|
||||
CustomInventory inventory = Inventories.customInventoryBuilder().name(SpongeMain.THIS.getTranslation(inv.getTitle())).size(inv.size).build();
|
||||
PlotItemStack[] items = inv.getItems();
|
||||
for (int i = 0; i < inv.size * 9; i++) {
|
||||
PlotItemStack item = items[i];
|
||||
if (item != null) {
|
||||
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++)
|
||||
{
|
||||
final PlotItemStack item = items[i];
|
||||
if (item != null)
|
||||
{
|
||||
inventory.set(new SlotIndex(i), getItem(item));
|
||||
}
|
||||
}
|
||||
inv.player.setMeta("inventory", inv);
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
|
||||
public ItemStack getItem(PlotItemStack item) {
|
||||
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(PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
public void close(final PlotInventory inv)
|
||||
{
|
||||
if (!inv.isOpen()) { return; }
|
||||
inv.player.deleteMeta("inventory");
|
||||
SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
sp.player.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
Player player = sp.player;
|
||||
Inventory inventory = player.getOpenInventory().get();
|
||||
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(ItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
ItemType type = item.getItem();
|
||||
String id = type.getId();
|
||||
int amount = item.getQuantity();
|
||||
|
||||
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(PlotPlayer player) {
|
||||
SpongePlayer sp = (SpongePlayer) player;
|
||||
CarriedInventory<? extends Carrier> inv = sp.player.getInventory();
|
||||
ArrayList<PlotItemStack> list = new ArrayList<PlotItemStack>();
|
||||
|
||||
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();
|
||||
|
||||
// return list.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
Player player = sp.player;
|
||||
if (player.isViewingInventory()) {
|
||||
CarriedInventory<? extends Carrier> inventory = player.getInventory();
|
||||
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())
|
||||
{
|
||||
final CarriedInventory<? extends Carrier> inventory = player.getInventory();
|
||||
return inv.getTitle().equals(inventory.getName().getTranslation().get(Locale.ENGLISH));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -56,7 +56,8 @@ import org.spongepowered.api.service.scheduler.TaskBuilder;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
|
||||
public class SpongeMetrics {
|
||||
public class SpongeMetrics
|
||||
{
|
||||
|
||||
/**
|
||||
* The current revision number
|
||||
@ -124,10 +125,9 @@ public class SpongeMetrics {
|
||||
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;
|
||||
@ -138,12 +138,15 @@ public class SpongeMetrics {
|
||||
/**
|
||||
* 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();
|
||||
|
||||
@ -153,13 +156,17 @@ public class SpongeMetrics {
|
||||
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 (IOException e) {
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -171,33 +178,36 @@ 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
|
||||
TaskBuilder builder = game.getScheduler().createTaskBuilder();
|
||||
final TaskBuilder builder = game.getScheduler().createTaskBuilder();
|
||||
builder.async()
|
||||
.interval(TimeUnit.MINUTES.toMillis(PING_INTERVAL))
|
||||
.execute(new Runnable() {
|
||||
|
||||
.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;
|
||||
}
|
||||
@ -211,8 +221,11 @@ public class SpongeMetrics {
|
||||
// After the first post we set firstPost to false
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
} catch (IOException e) {
|
||||
if (debug) {
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
PS.debug("[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -227,8 +240,10 @@ public class SpongeMetrics {
|
||||
*
|
||||
* @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();
|
||||
@ -240,17 +255,21 @@ public class SpongeMetrics {
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
@ -261,17 +280,21 @@ public class SpongeMetrics {
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
@ -283,9 +306,10 @@ public class SpongeMetrics {
|
||||
*
|
||||
* @return the File object for the config file
|
||||
*/
|
||||
public File getConfigFile() {
|
||||
public File getConfigFile()
|
||||
{
|
||||
// TODO configDir
|
||||
File configFolder = new File("config");
|
||||
final File configFolder = new File("config");
|
||||
|
||||
return new File(configFolder, "PluginMetrics.conf");
|
||||
}
|
||||
@ -294,20 +318,21 @@ public class SpongeMetrics {
|
||||
* 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
|
||||
String pluginName = plugin.getName();
|
||||
boolean onlineMode = game.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||
String pluginVersion = plugin.getVersion();
|
||||
final String pluginName = plugin.getName();
|
||||
final boolean onlineMode = game.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||
final String pluginVersion = plugin.getVersion();
|
||||
// TODO no visible way to get MC version at the moment
|
||||
// TODO added by game.getPlatform().getMinecraftVersion() -- impl in 2.1
|
||||
String serverVersion = String.format("%s %s", "Sponge", game.getPlatform().getMinecraftVersion());
|
||||
int playersOnline = game.getServer().getOnlinePlayers().size();
|
||||
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
|
||||
StringBuilder json = new StringBuilder(1024);
|
||||
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
|
||||
@ -317,14 +342,15 @@ public class SpongeMetrics {
|
||||
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
||||
|
||||
// New data as of R6
|
||||
String osname = System.getProperty("os.name");
|
||||
final String osname = System.getProperty("os.name");
|
||||
String osarch = System.getProperty("os.arch");
|
||||
String osversion = System.getProperty("os.version");
|
||||
String java_version = System.getProperty("java.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
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";
|
||||
}
|
||||
|
||||
@ -336,7 +362,8 @@ public class SpongeMetrics {
|
||||
appendJSONPair(json, "java_version", java_version);
|
||||
|
||||
// If we're pinging, append it
|
||||
if (isPing) {
|
||||
if (isPing)
|
||||
{
|
||||
appendJSONPair(json, "ping", "1");
|
||||
}
|
||||
|
||||
@ -344,22 +371,24 @@ public class SpongeMetrics {
|
||||
json.append('}');
|
||||
|
||||
// Create the url
|
||||
URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
byte[] uncompressed = json.toString().getBytes();
|
||||
byte[] compressed = gzip(json.toString());
|
||||
final byte[] uncompressed = json.toString().getBytes();
|
||||
final byte[] compressed = gzip(json.toString());
|
||||
|
||||
// Headers
|
||||
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
|
||||
@ -371,12 +400,13 @@ public class SpongeMetrics {
|
||||
|
||||
connection.setDoOutput(true);
|
||||
|
||||
if (debug) {
|
||||
if (debug)
|
||||
{
|
||||
PS.debug("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
||||
}
|
||||
|
||||
// Write the data
|
||||
OutputStream os = connection.getOutputStream();
|
||||
final OutputStream os = connection.getOutputStream();
|
||||
os.write(compressed);
|
||||
os.flush();
|
||||
|
||||
@ -388,10 +418,14 @@ public class SpongeMetrics {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -405,19 +439,30 @@ public class SpongeMetrics {
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static byte[] gzip(String input) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
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 (IOException e) {
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (gzos != null) try {
|
||||
gzos.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gzos != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
gzos.close();
|
||||
}
|
||||
catch (final IOException ignore)
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
@ -429,11 +474,15 @@ public class SpongeMetrics {
|
||||
*
|
||||
* @return true if mineshafter is installed on the server
|
||||
*/
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
private boolean isMineshafterPresent()
|
||||
{
|
||||
try
|
||||
{
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -446,28 +495,37 @@ public class SpongeMetrics {
|
||||
* @param value
|
||||
* @throws java.io.UnsupportedEncodingException
|
||||
*/
|
||||
private static void appendJSONPair(StringBuilder json, String key, 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 (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));
|
||||
}
|
||||
}
|
||||
@ -478,14 +536,17 @@ public class SpongeMetrics {
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
private static String escapeJSON(String text) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
private static String escapeJSON(final String text)
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append('"');
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
char chr = text.charAt(index);
|
||||
for (int index = 0; index < text.length(); index++)
|
||||
{
|
||||
final char chr = text.charAt(index);
|
||||
|
||||
switch (chr) {
|
||||
switch (chr)
|
||||
{
|
||||
case '"':
|
||||
case '\\':
|
||||
builder.append('\\');
|
||||
@ -504,10 +565,13 @@ public class SpongeMetrics {
|
||||
builder.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ') {
|
||||
String t = "000" + Integer.toHexString(chr);
|
||||
if (chr < ' ')
|
||||
{
|
||||
final String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u" + t.substring(t.length() - 4));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.append(chr);
|
||||
}
|
||||
break;
|
||||
@ -524,7 +588,8 @@ public class SpongeMetrics {
|
||||
* @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,62 +9,71 @@ 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<>();
|
||||
|
||||
private AtomicInteger i = new AtomicInteger();
|
||||
|
||||
private HashMap<Integer, Task> tasks = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public int taskRepeat(Runnable r, int interval) {
|
||||
int val = i.incrementAndGet();
|
||||
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
TaskBuilder built = builder.delay(interval).interval(interval).execute(r);
|
||||
Task task = built.submit(SpongeMain.THIS.getPlugin());
|
||||
tasks.put(val, task);
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int taskRepeatAsync(Runnable r, int interval) {
|
||||
int val = i.incrementAndGet();
|
||||
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
TaskBuilder built = builder.delay(interval).async().interval(interval).execute(r);
|
||||
Task task = built.submit(SpongeMain.THIS.getPlugin());
|
||||
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);
|
||||
final Task task = built.submit(SpongeMain.THIS.getPlugin());
|
||||
tasks.put(val, task);
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskAsync(Runnable r) {
|
||||
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
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);
|
||||
final Task task = built.submit(SpongeMain.THIS.getPlugin());
|
||||
tasks.put(val, task);
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
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(Runnable r) {
|
||||
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
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(Runnable r, int delay) {
|
||||
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
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(Runnable r, int delay) {
|
||||
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
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(int i) {
|
||||
Task task = tasks.remove(i);
|
||||
if (task != null) {
|
||||
public void cancelTask(final int i)
|
||||
{
|
||||
final Task task = tasks.remove(i);
|
||||
if (task != null)
|
||||
{
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
|
||||
import javax.swing.border.Border;
|
||||
|
||||
import org.spongepowered.api.text.title.Title;
|
||||
import org.spongepowered.api.text.title.TitleBuilder;
|
||||
|
||||
@ -11,11 +8,13 @@ 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(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
||||
Title title = new TitleBuilder()
|
||||
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)
|
||||
@ -25,4 +24,3 @@ public class SpongeTitleManager extends AbstractTitle {
|
||||
((SpongePlayer) player).player.sendTitle(title);
|
||||
}
|
||||
}
|
||||
|
@ -15,87 +15,84 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeUtil {
|
||||
public class SpongeUtil
|
||||
{
|
||||
|
||||
public static Location getLocation(Entity player) {
|
||||
String world = player.getWorld().getName();
|
||||
org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
Vector3i pos = loc.getBlockPosition();
|
||||
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(org.spongepowered.api.world.Location block) {
|
||||
Extent extent = block.getExtent();
|
||||
if (extent instanceof World) {
|
||||
return getLocation(((World) extent).getName(), 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); }
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Location getLocationFull(Entity player) {
|
||||
String world = player.getWorld().getName();
|
||||
Vector3d rot = player.getRotation();
|
||||
float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ());
|
||||
org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
Vector3i pos = loc.getBlockPosition();
|
||||
|
||||
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());
|
||||
final org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
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(Player player) {
|
||||
if (player == lastPlayer) {
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
String name = player.getName();
|
||||
PlotPlayer pp = UUIDHandler.getPlayers().get(name);
|
||||
if (pp != null) {
|
||||
return pp;
|
||||
}
|
||||
|
||||
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; }
|
||||
lastPlotPlayer = new SpongePlayer(player);
|
||||
UUIDHandler.getPlayers().put(name, lastPlotPlayer);
|
||||
lastPlayer = player;
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
|
||||
public static Player getPlayer(PlotPlayer player) {
|
||||
if (player instanceof SpongePlayer) {
|
||||
return ((SpongePlayer) player).player;
|
||||
}
|
||||
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(String world) {
|
||||
if (world == last) {
|
||||
return lastWorld;
|
||||
}
|
||||
Optional<World> optional = SpongeMain.THIS.getServer().getWorld(world);
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
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; }
|
||||
return optional.get();
|
||||
}
|
||||
|
||||
public static void removePlayer(String player) {
|
||||
public static void removePlayer(final String player)
|
||||
{
|
||||
lastPlayer = null;
|
||||
lastPlotPlayer = null;
|
||||
UUIDHandler.getPlayers().remove(player);
|
||||
}
|
||||
|
||||
public static Location getLocation(String world, 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(org.spongepowered.api.world.Location origin) {
|
||||
Extent extent = origin.getExtent();
|
||||
if (extent == lastWorld) {
|
||||
return last;
|
||||
}
|
||||
if (extent instanceof World) {
|
||||
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)
|
||||
{
|
||||
lastWorld = (World) extent;
|
||||
last = ((World) extent).getName();
|
||||
return last;
|
||||
@ -103,11 +100,10 @@ public class SpongeUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static org.spongepowered.api.world.Location getLocation(Location loc) {
|
||||
Optional<World> world = SpongeMain.THIS.getServer().getWorld(loc.getWorld());
|
||||
if (!world.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
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; }
|
||||
return new org.spongepowered.api.world.Location(world.get(), loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
}
|
||||
|
@ -12,80 +12,101 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper {
|
||||
public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper
|
||||
{
|
||||
|
||||
public SpongeLowerOfflineUUIDWrapper() {
|
||||
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 {
|
||||
GameProfile profile = SpongeMain.THIS.getResolver().get(uuid).get();
|
||||
if (profile != null) {
|
||||
if (name == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
final GameProfile profile = SpongeMain.THIS.getResolver().get(uuid).get();
|
||||
if (profile != null)
|
||||
{
|
||||
name = profile.getName();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
for (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() {
|
||||
// TODO FIXME
|
||||
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() {
|
||||
// TODO FIXME
|
||||
public OfflinePlotPlayer[] getOfflinePlayers()
|
||||
{
|
||||
// TODO FIXME
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
}
|
||||
|
@ -9,56 +9,71 @@ 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(PlotPlayer player) {
|
||||
public UUID getUUID(final PlotPlayer player)
|
||||
{
|
||||
return ((SpongePlayer) player).player.getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(OfflinePlotPlayer player) {
|
||||
public UUID getUUID(final OfflinePlotPlayer player)
|
||||
{
|
||||
return player.getUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(String name) {
|
||||
try {
|
||||
public UUID getUUID(final String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return SpongeMain.THIS.getResolver().get(name, true).get().getUniqueId();
|
||||
} catch (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 (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");
|
||||
}
|
||||
@ -66,8 +81,9 @@ public class SpongeOnlineUUIDWrapper extends UUIDWrapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||
public OfflinePlotPlayer[] getOfflinePlayers()
|
||||
{
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -12,37 +12,43 @@ import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeUUIDHandler extends UUIDHandlerImplementation {
|
||||
public class SpongeUUIDHandler extends UUIDHandlerImplementation
|
||||
{
|
||||
|
||||
public SpongeUUIDHandler(UUIDWrapper wrapper) {
|
||||
public SpongeUUIDHandler(final UUIDWrapper wrapper)
|
||||
{
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean startCaching(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(Runnable whenDone) {
|
||||
public boolean cache(final Runnable whenDone)
|
||||
{
|
||||
add(new StringWrapper("*"), DBFunc.everyone);
|
||||
for (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