mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-24 08:05:26 +02:00
Hows this?
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
public class KillRoadMobs
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
public class KillRoadMobs {
|
||||
public void run() {
|
||||
// TODO kill road mobs
|
||||
}
|
||||
}
|
||||
|
@@ -24,47 +24,35 @@ import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeBlockManager extends BlockManager
|
||||
{
|
||||
|
||||
public class SpongeBlockManager extends BlockManager {
|
||||
|
||||
@Override
|
||||
public boolean isBlockSolid(final PlotBlock block)
|
||||
{
|
||||
public boolean isBlockSolid(final PlotBlock block) {
|
||||
final BlockState state = SpongeMain.THIS.getBlockState(block);
|
||||
final BlockType type = state.getType();
|
||||
return type.isSolidCube() && !type.isAffectedByGravity();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
||||
try {
|
||||
double match;
|
||||
short id;
|
||||
byte data;
|
||||
final String[] split = name.split(":");
|
||||
if (split.length == 2)
|
||||
{
|
||||
if (split.length == 2) {
|
||||
data = Byte.parseByte(split[1]);
|
||||
name = split[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
data = 0;
|
||||
}
|
||||
if (MathMan.isInteger(split[0]))
|
||||
{
|
||||
if (MathMan.isInteger(split[0])) {
|
||||
id = Short.parseShort(split[0]);
|
||||
match = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
final StringComparison<BlockState>.ComparisonResult comparison = new StringComparison<BlockState>(name, SpongeMain.THIS.getAllStates())
|
||||
{
|
||||
} else {
|
||||
final StringComparison<BlockState>.ComparisonResult comparison = new StringComparison<BlockState>(name, SpongeMain.THIS.getAllStates()) {
|
||||
@Override
|
||||
public String getString(final BlockState o)
|
||||
{
|
||||
public String getString(final BlockState o) {
|
||||
return o.getType().getId();
|
||||
};
|
||||
}.getBestMatchAdvanced();
|
||||
@@ -74,144 +62,136 @@ public class SpongeBlockManager extends BlockManager
|
||||
final PlotBlock block = new PlotBlock(id, data);
|
||||
final StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
||||
return outer.new ComparisonResult(match, block);
|
||||
|
||||
}
|
||||
catch (final Exception e)
|
||||
{}
|
||||
|
||||
} catch (final Exception e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getClosestMatchingName(final PlotBlock block)
|
||||
{
|
||||
public String getClosestMatchingName(final PlotBlock block) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getBiomeList()
|
||||
{
|
||||
public String[] getBiomeList() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean addItems(final String world, final PlotItem items)
|
||||
{
|
||||
public boolean addItems(final String world, final PlotItem items) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getBiomeFromString(final String biome)
|
||||
{
|
||||
public int getBiomeFromString(final String biome) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotBlock getPlotBlockFromString(final String block)
|
||||
{
|
||||
public PlotBlock getPlotBlockFromString(final String block) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getHeighestBlock(final String worldname, final int x, final int z)
|
||||
{
|
||||
public int getHeighestBlock(final String worldname, final int x, final int z) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
if (world == null) { return 64; }
|
||||
for (int y = 255; y > 0; y--)
|
||||
{
|
||||
if (world == null) {
|
||||
return 64;
|
||||
}
|
||||
for (int y = 255; y > 0; y--) {
|
||||
final BlockState block = world.getBlock(x, y, z);
|
||||
if ((block != null) && (block.getType() != BlockTypes.AIR)) { return y + 1; }
|
||||
if ((block != null) && (block.getType() != BlockTypes.AIR)) {
|
||||
return y + 1;
|
||||
}
|
||||
}
|
||||
return 64;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getBiome(final String world, final int x, final int z)
|
||||
{
|
||||
public String getBiome(final String world, final int x, final int z) {
|
||||
return SpongeUtil.getWorld(world).getBiome(x, z).getName().toUpperCase();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotBlock getBlock(final Location loc)
|
||||
{
|
||||
public PlotBlock getBlock(final Location loc) {
|
||||
final BlockState state = SpongeUtil.getWorld(loc.getWorld()).getBlock(loc.getX(), loc.getY(), loc.getZ());
|
||||
PlotBlock block = SpongeMain.THIS.getPlotBlock(state);
|
||||
if (block == null)
|
||||
{
|
||||
if (block == null) {
|
||||
block = SpongeMain.THIS.registerBlock(state);
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Location getSpawn(final String world)
|
||||
{
|
||||
public Location getSpawn(final String world) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
worldObj.getSpawnLocation();
|
||||
final Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
|
||||
result.setY(getHeighestBlock(world, result.getX(), result.getZ()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getSign(final Location loc)
|
||||
{
|
||||
public String[] getSign(final Location loc) {
|
||||
final World world = SpongeUtil.getWorld(loc.getWorld());
|
||||
final Optional<TileEntity> block = world.getTileEntity(loc.getX(), loc.getY(), loc.getZ());
|
||||
if (!block.isPresent()) { return null; }
|
||||
if (!block.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
final TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) { return null; }
|
||||
if (!(tile instanceof Sign)) {
|
||||
return null;
|
||||
}
|
||||
final Sign sign = (Sign) tile;
|
||||
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||
if (!optional.isPresent()) { return null; }
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
final String[] result = new String[4];
|
||||
final ListValue<Text> lines = optional.get().lines();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
result[i] = lines.get(i).toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isWorld(final String world)
|
||||
{
|
||||
public boolean isWorld(final String world) {
|
||||
return SpongeUtil.getWorld(world) != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void functionSetBlocks(final String worldname, final int[] xv, final int[] yv, final int[] zv, final int[] id, final byte[] data)
|
||||
{
|
||||
for (int i = 0; i < xv.length; i++)
|
||||
{
|
||||
public void functionSetBlocks(final String worldname, final int[] xv, final int[] yv, final int[] zv, final int[] id, final byte[] data) {
|
||||
for (int i = 0; i < xv.length; i++) {
|
||||
functionSetBlock(worldname, xv[i], yv[i], zv[i], id[i], data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void functionSetSign(final String worldname, final int x, final int y, final int z, final String[] lines)
|
||||
{
|
||||
public void functionSetSign(final String worldname, final int x, final int y, final int z, final String[] lines) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
world.setBlock(x, y, z, BlockTypes.WALL_SIGN.getDefaultState());
|
||||
final Optional<TileEntity> block = world.getTileEntity(x, y, z);
|
||||
if (!block.isPresent()) { return; }
|
||||
if (!block.isPresent()) {
|
||||
return;
|
||||
}
|
||||
final TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) { return; }
|
||||
if (!(tile instanceof Sign)) {
|
||||
return;
|
||||
}
|
||||
final Sign sign = (Sign) tile;
|
||||
final List<Text> text = new ArrayList<>(4);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
text.add(SpongeMain.THIS.getText(lines[i]));
|
||||
}
|
||||
try
|
||||
{
|
||||
try {
|
||||
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
||||
if (optional.isPresent())
|
||||
{
|
||||
if (optional.isPresent()) {
|
||||
final SignData offering = optional.get();
|
||||
offering.lines().set(0, SpongeMain.THIS.getText(lines[0]));
|
||||
offering.lines().set(1, SpongeMain.THIS.getText(lines[1]));
|
||||
@@ -219,52 +199,42 @@ public class SpongeBlockManager extends BlockManager
|
||||
offering.lines().set(3, SpongeMain.THIS.getText(lines[3]));
|
||||
sign.offer(offering);
|
||||
}
|
||||
}
|
||||
catch (final NullPointerException e)
|
||||
{
|
||||
} catch (final NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void functionSetBlock(final String worldname, final int x, final int y, final int z, final int id, final byte data)
|
||||
{
|
||||
public void functionSetBlock(final String worldname, final int x, final int y, final int z, final int id, final byte data) {
|
||||
BlockState state;
|
||||
if (data == 0)
|
||||
{
|
||||
if (data == 0) {
|
||||
state = SpongeMain.THIS.getBlockState(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
state = SpongeMain.THIS.getBlockState(new PlotBlock((short) id, data));
|
||||
}
|
||||
if (state == null) { return; }
|
||||
if (state == null) {
|
||||
return;
|
||||
}
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final BlockState block = world.getBlock(x, y, z);
|
||||
if (block != state)
|
||||
{
|
||||
if (block != state) {
|
||||
world.setBlock(x, y, z, state);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void functionSetBiomes(final String worldname, final int[] xv, final int[] zv, final String biomeName)
|
||||
{
|
||||
public void functionSetBiomes(final String worldname, final int[] xv, final int[] zv, final String biomeName) {
|
||||
BiomeType biome;
|
||||
try
|
||||
{
|
||||
try {
|
||||
biome = (BiomeType) BiomeTypes.class.getField(biomeName.toUpperCase()).get(null);
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
biome = BiomeTypes.FOREST;
|
||||
}
|
||||
for (int i = 0; i < xv.length; i++)
|
||||
{
|
||||
for (int i = 0; i < xv.length; i++) {
|
||||
SpongeUtil.getWorld(worldname).setBiome(xv[i], zv[i], biome);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -10,30 +10,24 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ChatManager;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeChatManager extends ChatManager<TextBuilder>
|
||||
{
|
||||
|
||||
public class SpongeChatManager extends ChatManager<TextBuilder> {
|
||||
|
||||
@Override
|
||||
public TextBuilder builder()
|
||||
{
|
||||
public TextBuilder builder() {
|
||||
return Texts.builder();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void color(final PlotMessage m, final String color)
|
||||
{
|
||||
public void color(final PlotMessage m, final String color) {
|
||||
m.$(this).color(Texts.of(color).getColor());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tooltip(final PlotMessage m, final PlotMessage... tooltips)
|
||||
{
|
||||
public void tooltip(final PlotMessage m, final PlotMessage... tooltips) {
|
||||
final TextBuilder builder = Texts.builder();
|
||||
boolean lb = false;
|
||||
for (final PlotMessage tooltip : tooltips)
|
||||
{
|
||||
if (lb)
|
||||
{
|
||||
for (final PlotMessage tooltip : tooltips) {
|
||||
if (lb) {
|
||||
builder.append(Texts.of("\n"));
|
||||
}
|
||||
builder.append(tooltip.$(this).build());
|
||||
@@ -42,36 +36,29 @@ public class SpongeChatManager extends ChatManager<TextBuilder>
|
||||
// AchievementBuilder builder = SpongeMain.THIS.getGame().getRegistry().createAchievementBuilder();
|
||||
m.$(this).onHover(TextActions.showText(builder.toText()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void command(final PlotMessage m, final String command)
|
||||
{
|
||||
public void command(final PlotMessage m, final String command) {
|
||||
m.$(this).onClick(TextActions.runCommand(command));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void text(final PlotMessage m, final String text)
|
||||
{
|
||||
public void text(final PlotMessage m, final String text) {
|
||||
m.$(this).append(Texts.of(text));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void send(final PlotMessage m, final PlotPlayer player)
|
||||
{
|
||||
if (ConsolePlayer.isConsole(player))
|
||||
{
|
||||
public void send(final PlotMessage m, final PlotPlayer player) {
|
||||
if (ConsolePlayer.isConsole(player)) {
|
||||
player.sendMessage(Texts.legacy().to(m.$(this).build()));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
((SpongePlayer) player).player.sendMessage(m.$(this).build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void suggest(final PlotMessage m, final String command)
|
||||
{
|
||||
public void suggest(final PlotMessage m, final String command) {
|
||||
m.$(this).onClick(TextActions.suggestCommand(command));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -22,22 +22,19 @@ import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.SetBlockQueue.ChunkWrapper;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class SpongeChunkManager extends ChunkManager
|
||||
{
|
||||
|
||||
public class SpongeChunkManager extends ChunkManager {
|
||||
|
||||
@Override
|
||||
public void setChunk(final ChunkWrapper loc, final PlotBlock[][] result)
|
||||
{
|
||||
public void setChunk(final ChunkWrapper loc, final PlotBlock[][] result) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] countEntities(final Plot plot)
|
||||
{
|
||||
public int[] countEntities(final Plot plot) {
|
||||
final Location pos1 = plot.getBottom();
|
||||
final Location pos2 = plot.getTop();
|
||||
|
||||
|
||||
final String worldname = pos1.getWorld();
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final int bx = pos1.getX();
|
||||
@@ -45,33 +42,23 @@ public class SpongeChunkManager extends ChunkManager
|
||||
final int tx = pos2.getX();
|
||||
final int tz = pos2.getZ();
|
||||
final int[] count = new int[5];
|
||||
world.getEntities(new Predicate<Entity>()
|
||||
{
|
||||
world.getEntities(new Predicate<Entity>() {
|
||||
@Override
|
||||
public boolean apply(final Entity entity)
|
||||
{
|
||||
public boolean apply(final Entity entity) {
|
||||
final org.spongepowered.api.world.Location loc = entity.getLocation();
|
||||
final int x = loc.getBlockX();
|
||||
if ((x >= bx) && (x <= tx))
|
||||
{
|
||||
if ((x >= bx) && (x <= tx)) {
|
||||
final int z = loc.getBlockZ();
|
||||
if ((z >= bz) && (z <= tz))
|
||||
{
|
||||
if ((z >= bz) && (z <= tz)) {
|
||||
count[0]++;
|
||||
if (entity instanceof Living)
|
||||
{
|
||||
if (entity instanceof Living) {
|
||||
count[3]++;
|
||||
if (entity instanceof Animal)
|
||||
{
|
||||
if (entity instanceof Animal) {
|
||||
count[1]++;
|
||||
}
|
||||
else if (entity instanceof Monster)
|
||||
{
|
||||
} else if (entity instanceof Monster) {
|
||||
count[2]++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
count[4]++;
|
||||
}
|
||||
}
|
||||
@@ -79,129 +66,113 @@ public class SpongeChunkManager extends ChunkManager
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean loadChunk(final String world, final ChunkLoc loc, final boolean force)
|
||||
{
|
||||
public boolean loadChunk(final String world, final ChunkLoc loc, final boolean force) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
return worldObj.loadChunk(loc.x << 4, 0, loc.z << 4, force).isPresent();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean unloadChunk(final String world, final ChunkLoc loc, final boolean save, final boolean safe)
|
||||
{
|
||||
public boolean unloadChunk(final String world, final ChunkLoc loc, final boolean save, final boolean safe) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
final Optional<Chunk> chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4);
|
||||
if (chunk.isPresent()) { return worldObj.unloadChunk(chunk.get()); }
|
||||
if (chunk.isPresent()) {
|
||||
return worldObj.unloadChunk(chunk.get());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ChunkLoc> getChunkChunks(final String world)
|
||||
{
|
||||
public List<ChunkLoc> getChunkChunks(final String world) {
|
||||
final ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
final ChunkDataStream storage = worldObj.getWorldStorage().getGeneratedChunks();
|
||||
while (storage.hasNext())
|
||||
{
|
||||
while (storage.hasNext()) {
|
||||
storage.next();
|
||||
|
||||
|
||||
// TODO get chunk from DataContainer
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void regenerateChunk(final String world, final ChunkLoc loc)
|
||||
{
|
||||
public void regenerateChunk(final String world, final ChunkLoc loc) {
|
||||
final World worldObj = SpongeUtil.getWorld(world);
|
||||
final Optional<Chunk> chunk = worldObj.getChunk(loc.x << 4, 0, loc.z << 4);
|
||||
if (chunk.isPresent())
|
||||
{
|
||||
if (chunk.isPresent()) {
|
||||
// TODO regenerate chunk
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteRegionFile(final String world, final ChunkLoc loc)
|
||||
{
|
||||
public void deleteRegionFile(final String world, final ChunkLoc loc) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteRegionFiles(final String world, final List<ChunkLoc> chunks)
|
||||
{
|
||||
public void deleteRegionFiles(final String world, final List<ChunkLoc> chunks) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteRegionFiles(String world, List<ChunkLoc> chunks, Runnable whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Plot hasPlot(final String world, final ChunkLoc chunk)
|
||||
{
|
||||
public Plot hasPlot(final String world, final ChunkLoc chunk) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone)
|
||||
{
|
||||
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
TaskManager.runTask(whenDone);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone)
|
||||
{
|
||||
public boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
TaskManager.runTask(whenDone);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void swap(final String world, final PlotId id, final PlotId plotid)
|
||||
{
|
||||
public void swap(final String world, final PlotId id, final PlotId plotid) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void swap(final String worldname, final Location bot1, final Location top1, final Location bot2, final Location top2)
|
||||
{
|
||||
public void swap(final String worldname, final Location bot1, final Location top1, final Location bot2, final Location top2) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clearAllEntities(final Location pos1, final Location pos2)
|
||||
{
|
||||
public void clearAllEntities(final Location pos1, final Location pos2) {
|
||||
final String worldname = pos1.getWorld();
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final int bx = pos1.getX();
|
||||
final int bz = pos1.getZ();
|
||||
final int tx = pos2.getX();
|
||||
final int tz = pos2.getZ();
|
||||
world.getEntities(new Predicate<Entity>()
|
||||
{
|
||||
world.getEntities(new Predicate<Entity>() {
|
||||
@Override
|
||||
public boolean apply(final Entity entity)
|
||||
{
|
||||
public boolean apply(final Entity entity) {
|
||||
final org.spongepowered.api.world.Location loc = entity.getLocation();
|
||||
final int x = loc.getBlockX();
|
||||
if ((x >= bx) && (x <= tx))
|
||||
{
|
||||
if ((x >= bx) && (x <= tx)) {
|
||||
final int z = loc.getBlockZ();
|
||||
if ((z >= bz) && (z <= tz))
|
||||
{
|
||||
if ((z >= bz) && (z <= tz)) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
@@ -209,5 +180,5 @@ public class SpongeChunkManager extends ChunkManager
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -19,63 +19,50 @@ import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeCommand implements CommandCallable
|
||||
{
|
||||
|
||||
public class SpongeCommand implements CommandCallable {
|
||||
|
||||
@Override
|
||||
public CommandResult process(final CommandSource cmd, final String string) throws CommandException
|
||||
{
|
||||
public CommandResult process(final CommandSource cmd, final String string) throws CommandException {
|
||||
final String id = cmd.getIdentifier();
|
||||
PlotPlayer pp;
|
||||
try
|
||||
{
|
||||
try {
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get();
|
||||
pp = SpongeUtil.getPlayer(player);
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
pp = ConsolePlayer.getConsole();
|
||||
}
|
||||
if (MainCommand.onCommand(pp, cmd.getName(), string.length() == 0 ? new String[] {} : string.split(" ")))
|
||||
{
|
||||
if (MainCommand.onCommand(pp, cmd.getName(), string.length() == 0 ? new String[] {} : string.split(" "))) {
|
||||
return CommandResult.success();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return CommandResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(final CommandSource cmd, final String string) throws CommandException
|
||||
{
|
||||
public List<String> getSuggestions(final CommandSource cmd, final String string) throws CommandException {
|
||||
// TODO Auto-generated method stub
|
||||
return new ArrayList<>(Arrays.asList("TEST"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean testPermission(final CommandSource cmd)
|
||||
{
|
||||
public boolean testPermission(final CommandSource cmd) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getShortDescription(final CommandSource cmd)
|
||||
{
|
||||
public Optional<? extends Text> getShortDescription(final CommandSource cmd) {
|
||||
return Optional.of(Texts.of("Shows plot help"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getHelp(final CommandSource cmd)
|
||||
{
|
||||
public Optional<? extends Text> getHelp(final CommandSource cmd) {
|
||||
return Optional.of(Texts.of("/plot help"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Text getUsage(final CommandSource cmd)
|
||||
{
|
||||
public Text getUsage(final CommandSource cmd) {
|
||||
return Texts.of("/plot <command>");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -32,113 +32,97 @@ import com.plotsquared.sponge.events.PlotMergeEvent;
|
||||
import com.plotsquared.sponge.events.PlotRateEvent;
|
||||
import com.plotsquared.sponge.events.PlotUnlinkEvent;
|
||||
|
||||
public class SpongeEventUtil extends EventUtil
|
||||
{
|
||||
|
||||
public class SpongeEventUtil extends EventUtil {
|
||||
|
||||
public EventManager events;
|
||||
|
||||
public SpongeEventUtil()
|
||||
{
|
||||
|
||||
public SpongeEventUtil() {
|
||||
events = SpongeMain.THIS.getGame().getEventManager();
|
||||
}
|
||||
|
||||
public boolean callEvent(final Event event)
|
||||
{
|
||||
|
||||
public boolean callEvent(final Event event) {
|
||||
events.post(event);
|
||||
if (event instanceof Cancellable) { return !((Cancellable) event).isCancelled(); }
|
||||
if (event instanceof Cancellable) {
|
||||
return !((Cancellable) event).isCancelled();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto)
|
||||
{
|
||||
public boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto) {
|
||||
return callEvent(new PlayerClaimPlotEvent(SpongeUtil.getPlayer(player), plot, auto));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callTeleport(final PlotPlayer player, final Location from, final Plot plot)
|
||||
{
|
||||
public boolean callTeleport(final PlotPlayer player, final Location from, final Plot plot) {
|
||||
return callEvent(new PlayerTeleportToPlotEvent(SpongeUtil.getPlayer(player), from, plot));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callClear(final String world, final PlotId id)
|
||||
{
|
||||
public boolean callClear(final String world, final PlotId id) {
|
||||
return callEvent(new PlotClearEvent(world, id));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callDelete(final String world, final PlotId id)
|
||||
{
|
||||
public void callDelete(final String world, final PlotId id) {
|
||||
callEvent(new PlotDeleteEvent(world, id));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callFlagAdd(final Flag flag, final Plot plot)
|
||||
{
|
||||
public boolean callFlagAdd(final Flag flag, final Plot plot) {
|
||||
return callEvent(new PlotFlagAddEvent(flag, plot));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(final Flag flag, final Plot plot)
|
||||
{
|
||||
public boolean callFlagRemove(final Flag flag, final Plot plot) {
|
||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callMerge(final String world, final Plot plot, final ArrayList<PlotId> plots)
|
||||
{
|
||||
public boolean callMerge(final String world, final Plot plot, final ArrayList<PlotId> plots) {
|
||||
return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(world), plot, plots));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callUnlink(final String world, final ArrayList<PlotId> plots)
|
||||
{
|
||||
public boolean callUnlink(final String world, final ArrayList<PlotId> plots) {
|
||||
return callEvent(new PlotUnlinkEvent(SpongeUtil.getWorld(world), plots));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callEntry(final PlotPlayer player, final Plot plot)
|
||||
{
|
||||
public void callEntry(final PlotPlayer player, final Plot plot) {
|
||||
callEvent(new PlayerEnterPlotEvent(SpongeUtil.getPlayer(player), plot));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callLeave(final PlotPlayer player, final Plot plot)
|
||||
{
|
||||
public void callLeave(final PlotPlayer player, final Plot plot) {
|
||||
callEvent(new PlayerLeavePlotEvent(SpongeUtil.getPlayer(player), plot));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callDenied(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added)
|
||||
{
|
||||
public void callDenied(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
callEvent(new PlayerPlotDeniedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callTrusted(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added)
|
||||
{
|
||||
public void callTrusted(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
callEvent(new PlayerPlotHelperEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callMember(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added)
|
||||
{
|
||||
public void callMember(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
callEvent(new PlayerPlotTrustedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(final Flag flag, final PlotCluster cluster)
|
||||
{
|
||||
public boolean callFlagRemove(final Flag flag, final PlotCluster cluster) {
|
||||
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rating callRating(final PlotPlayer player, final Plot plot, final Rating rating)
|
||||
{
|
||||
public Rating callRating(final PlotPlayer player, final Plot plot, final Rating rating) {
|
||||
final PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||
events.post(event);
|
||||
return event.getRating();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -21,97 +21,93 @@ import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeInventoryUtil extends InventoryUtil
|
||||
{
|
||||
|
||||
public class SpongeInventoryUtil extends InventoryUtil {
|
||||
|
||||
public ItemStackBuilder builder;
|
||||
|
||||
public SpongeInventoryUtil()
|
||||
{
|
||||
|
||||
public SpongeInventoryUtil() {
|
||||
builder = SpongeMain.THIS.getGame().getRegistry().createItemBuilder();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void open(final PlotInventory inv)
|
||||
{
|
||||
public void open(final PlotInventory inv) {
|
||||
// TODO Auto-generated method stub
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
final Player player = sp.player;
|
||||
|
||||
|
||||
final CustomInventory inventory = Inventories.customInventoryBuilder().name(SpongeMain.THIS.getTranslation(inv.getTitle())).size(inv.size).build();
|
||||
final PlotItemStack[] items = inv.getItems();
|
||||
for (int i = 0; i < (inv.size * 9); i++)
|
||||
{
|
||||
for (int i = 0; i < (inv.size * 9); i++) {
|
||||
final PlotItemStack item = items[i];
|
||||
if (item != null)
|
||||
{
|
||||
if (item != null) {
|
||||
inventory.set(new SlotIndex(i), getItem(item));
|
||||
}
|
||||
}
|
||||
inv.player.setMeta("inventory", inv);
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public ItemStack getItem(final PlotItemStack item)
|
||||
{
|
||||
|
||||
public ItemStack getItem(final PlotItemStack item) {
|
||||
// FIXME item type, item data, item name, item lore
|
||||
return builder.itemType(ItemTypes.SPONGE).quantity(item.amount).build();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void close(final PlotInventory inv)
|
||||
{
|
||||
if (!inv.isOpen()) { return; }
|
||||
public void close(final PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
inv.player.deleteMeta("inventory");
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
sp.player.closeInventory();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setItem(final PlotInventory inv, final int index, final PlotItemStack item)
|
||||
{
|
||||
if (!inv.isOpen()) { return; }
|
||||
public void setItem(final PlotInventory inv, final int index, final PlotItemStack item) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
final Player player = sp.player;
|
||||
player.getOpenInventory().get();
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public PlotItemStack getItem(final ItemStack item)
|
||||
{
|
||||
if (item == null) { return null; }
|
||||
|
||||
public PlotItemStack getItem(final ItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
final ItemType type = item.getItem();
|
||||
final String id = type.getId();
|
||||
final int amount = item.getQuantity();
|
||||
// TODO name / lore
|
||||
return new PlotItemStack(id, amount, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlotItemStack[] getItems(final PlotPlayer player)
|
||||
{
|
||||
public PlotItemStack[] getItems(final PlotPlayer player) {
|
||||
final SpongePlayer sp = (SpongePlayer) player;
|
||||
sp.player.getInventory();
|
||||
new ArrayList<PlotItemStack>();
|
||||
|
||||
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
|
||||
|
||||
// return list.toArray();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isOpen(final PlotInventory inv)
|
||||
{
|
||||
if (!inv.isOpen()) { return false; }
|
||||
public boolean isOpen(final PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
final SpongePlayer sp = (SpongePlayer) inv.player;
|
||||
final Player player = sp.player;
|
||||
if (player.isViewingInventory())
|
||||
{
|
||||
if (player.isViewingInventory()) {
|
||||
final CarriedInventory<? extends Carrier> inventory = player.getInventory();
|
||||
return inv.getTitle().equals(inventory.getName().getTranslation().get(Locale.ENGLISH));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -56,121 +56,114 @@ import org.spongepowered.api.service.scheduler.TaskBuilder;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
|
||||
public class SpongeMetrics
|
||||
{
|
||||
|
||||
public class SpongeMetrics {
|
||||
|
||||
/**
|
||||
* The current revision number
|
||||
*/
|
||||
private final static int REVISION = 7;
|
||||
|
||||
|
||||
/**
|
||||
* The base url of the metrics domain
|
||||
*/
|
||||
private static final String BASE_URL = "http://report.mcstats.org";
|
||||
|
||||
|
||||
/**
|
||||
* The url used to report a server's status
|
||||
*/
|
||||
private static final String REPORT_URL = "/plugin/%s";
|
||||
|
||||
|
||||
/**
|
||||
* Interval of time to ping (in minutes)
|
||||
*/
|
||||
private static final int PING_INTERVAL = 15;
|
||||
|
||||
|
||||
/**
|
||||
* The game data is being sent for
|
||||
*/
|
||||
private final Game game;
|
||||
|
||||
|
||||
/**
|
||||
* The plugin this metrics submits for
|
||||
*/
|
||||
private final PluginContainer plugin;
|
||||
|
||||
|
||||
/**
|
||||
* The plugin configuration file
|
||||
*/
|
||||
private CommentedConfigurationNode config;
|
||||
|
||||
|
||||
/**
|
||||
* The configuration loader
|
||||
*/
|
||||
private ConfigurationLoader<CommentedConfigurationNode> configurationLoader;
|
||||
|
||||
|
||||
/**
|
||||
* The plugin configuration file
|
||||
*/
|
||||
private File configurationFile;
|
||||
|
||||
|
||||
/**
|
||||
* Unique server id
|
||||
*/
|
||||
private String guid;
|
||||
|
||||
|
||||
/**
|
||||
* Debug mode
|
||||
*/
|
||||
private boolean debug;
|
||||
|
||||
|
||||
/**
|
||||
* Lock for synchronization
|
||||
*/
|
||||
private final Object optOutLock = new Object();
|
||||
|
||||
|
||||
/**
|
||||
* The scheduled task
|
||||
*/
|
||||
private volatile Task task = null;
|
||||
|
||||
|
||||
@Inject
|
||||
public SpongeMetrics(final Game game, final PluginContainer plugin) throws IOException
|
||||
{
|
||||
if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); }
|
||||
|
||||
public SpongeMetrics(final Game game, final PluginContainer plugin) throws IOException {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null");
|
||||
}
|
||||
|
||||
this.game = game;
|
||||
this.plugin = plugin;
|
||||
|
||||
|
||||
loadConfiguration();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the configuration
|
||||
*/
|
||||
private void loadConfiguration()
|
||||
{
|
||||
private void loadConfiguration() {
|
||||
configurationFile = getConfigFile();
|
||||
configurationLoader = HoconConfigurationLoader.builder().setFile(configurationFile).build();
|
||||
|
||||
try
|
||||
{
|
||||
if (!configurationFile.exists())
|
||||
{
|
||||
|
||||
try {
|
||||
if (!configurationFile.exists()) {
|
||||
configurationFile.createNewFile();
|
||||
config = configurationLoader.load();
|
||||
|
||||
|
||||
config.setComment("This contains settings for MCStats: http://mcstats.org");
|
||||
config.getNode("mcstats.guid").setValue(UUID.randomUUID().toString());
|
||||
config.getNode("mcstats.opt-out").setValue(false);
|
||||
config.getNode("mcstats.debug").setValue(false);
|
||||
|
||||
|
||||
configurationLoader.save(config);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
config = configurationLoader.load();
|
||||
}
|
||||
|
||||
|
||||
guid = config.getNode("mcstats.guid").getString();
|
||||
debug = config.getNode("mcstats.debug").getBoolean();
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the
|
||||
* initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200
|
||||
@@ -178,54 +171,46 @@ public class SpongeMetrics
|
||||
*
|
||||
* @return True if statistics measuring is running, otherwise false.
|
||||
*/
|
||||
public boolean start()
|
||||
{
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
public boolean start() {
|
||||
synchronized (optOutLock) {
|
||||
// Did we opt out?
|
||||
if (isOptOut()) { return false; }
|
||||
|
||||
if (isOptOut()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is metrics already running?
|
||||
if (task != null) { return true; }
|
||||
|
||||
if (task != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Begin hitting the server with glorious data
|
||||
final TaskBuilder builder = game.getScheduler().createTaskBuilder();
|
||||
builder.async()
|
||||
.interval(TimeUnit.MINUTES.toMillis(PING_INTERVAL))
|
||||
.execute(new Runnable()
|
||||
{
|
||||
|
||||
builder.async().interval(TimeUnit.MINUTES.toMillis(PING_INTERVAL)).execute(new Runnable() {
|
||||
|
||||
private boolean firstPost = true;
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
public void run() {
|
||||
try {
|
||||
// This has to be synchronized or it can collide with the disable method.
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
synchronized (optOutLock) {
|
||||
// Disable Task, if it is running and the server owner decided to opt-out
|
||||
if (isOptOut() && (task != null))
|
||||
{
|
||||
if (isOptOut() && (task != null)) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// We use the inverse of firstPost because if it is the first time we are posting,
|
||||
// it is not a interval ping, so it evaluates to FALSE
|
||||
// Each time thereafter it will evaluate to TRUE, i.e PING!
|
||||
postPlugin(!firstPost);
|
||||
|
||||
|
||||
// After the first post we set firstPost to false
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
} catch (final IOException e) {
|
||||
if (debug) {
|
||||
PS.debug("[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -234,92 +219,80 @@ public class SpongeMetrics
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Has the server owner denied plugin metrics?
|
||||
*
|
||||
* @return true if metrics should be opted out of it
|
||||
*/
|
||||
public boolean isOptOut()
|
||||
{
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
public boolean isOptOut() {
|
||||
synchronized (optOutLock) {
|
||||
loadConfiguration();
|
||||
|
||||
|
||||
return config.getNode("mcstats.opt-out").getBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void enable() throws IOException
|
||||
{
|
||||
public void enable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut())
|
||||
{
|
||||
if (isOptOut()) {
|
||||
config.getNode("mcstats.opt-out").setValue(false);
|
||||
configurationLoader.save(config);
|
||||
}
|
||||
|
||||
|
||||
// Enable Task, if it is not running
|
||||
if (task == null)
|
||||
{
|
||||
if (task == null) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void disable() throws IOException
|
||||
{
|
||||
public void disable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (!isOptOut())
|
||||
{
|
||||
if (!isOptOut()) {
|
||||
config.getNode("mcstats.opt-out").setValue(true);
|
||||
configurationLoader.save(config);
|
||||
}
|
||||
|
||||
|
||||
// Disable Task, if it is running
|
||||
if (task != null)
|
||||
{
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
|
||||
*
|
||||
* @return the File object for the config file
|
||||
*/
|
||||
public File getConfigFile()
|
||||
{
|
||||
public File getConfigFile() {
|
||||
// TODO configDir
|
||||
final File configFolder = new File("config");
|
||||
|
||||
|
||||
return new File(configFolder, "PluginMetrics.conf");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generic method that posts a plugin to the metrics website
|
||||
*
|
||||
*/
|
||||
private void postPlugin(final boolean isPing) throws IOException
|
||||
{
|
||||
private void postPlugin(final boolean isPing) throws IOException {
|
||||
// Server software specific section
|
||||
final String pluginName = plugin.getName();
|
||||
final boolean onlineMode = game.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||
@@ -328,68 +301,63 @@ public class SpongeMetrics
|
||||
// TODO added by game.getPlatform().getMinecraftVersion() -- impl in 2.1
|
||||
final String serverVersion = String.format("%s %s", "Sponge", game.getPlatform().getMinecraftVersion());
|
||||
final int playersOnline = game.getServer().getOnlinePlayers().size();
|
||||
|
||||
|
||||
// END server software specific section -- all code below does not use any code outside of this class / Java
|
||||
|
||||
|
||||
// Construct the post data
|
||||
final StringBuilder json = new StringBuilder(1024);
|
||||
json.append('{');
|
||||
|
||||
|
||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||
appendJSONPair(json, "guid", guid);
|
||||
appendJSONPair(json, "plugin_version", pluginVersion);
|
||||
appendJSONPair(json, "server_version", serverVersion);
|
||||
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
||||
|
||||
|
||||
// New data as of R6
|
||||
final String osname = System.getProperty("os.name");
|
||||
String osarch = System.getProperty("os.arch");
|
||||
final String osversion = System.getProperty("os.version");
|
||||
final String java_version = System.getProperty("java.version");
|
||||
final int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
|
||||
// normalize os arch .. amd64 -> x86_64
|
||||
if (osarch.equals("amd64"))
|
||||
{
|
||||
if (osarch.equals("amd64")) {
|
||||
osarch = "x86_64";
|
||||
}
|
||||
|
||||
|
||||
appendJSONPair(json, "osname", osname);
|
||||
appendJSONPair(json, "osarch", osarch);
|
||||
appendJSONPair(json, "osversion", osversion);
|
||||
appendJSONPair(json, "cores", Integer.toString(coreCount));
|
||||
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
|
||||
appendJSONPair(json, "java_version", java_version);
|
||||
|
||||
|
||||
// If we're pinging, append it
|
||||
if (isPing)
|
||||
{
|
||||
if (isPing) {
|
||||
appendJSONPair(json, "ping", "1");
|
||||
}
|
||||
|
||||
|
||||
// close json
|
||||
json.append('}');
|
||||
|
||||
|
||||
// Create the url
|
||||
final URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
|
||||
|
||||
|
||||
// Connect to the website
|
||||
URLConnection connection;
|
||||
|
||||
|
||||
// Mineshafter creates a socks proxy, so we can safely bypass it
|
||||
// It does not reroute POST requests so we need to go around it
|
||||
if (isMineshafterPresent())
|
||||
{
|
||||
if (isMineshafterPresent()) {
|
||||
connection = url.openConnection(Proxy.NO_PROXY);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
connection = url.openConnection();
|
||||
}
|
||||
|
||||
|
||||
final byte[] uncompressed = json.toString().getBytes();
|
||||
final byte[] compressed = gzip(json.toString());
|
||||
|
||||
|
||||
// Headers
|
||||
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
|
||||
connection.addRequestProperty("Content-Type", "application/json");
|
||||
@@ -397,96 +365,77 @@ public class SpongeMetrics
|
||||
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
|
||||
|
||||
connection.setDoOutput(true);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
|
||||
if (debug) {
|
||||
PS.debug("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
||||
}
|
||||
|
||||
|
||||
// Write the data
|
||||
final OutputStream os = connection.getOutputStream();
|
||||
os.write(compressed);
|
||||
os.flush();
|
||||
|
||||
|
||||
// Now read the response
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String response = reader.readLine();
|
||||
|
||||
|
||||
// close resources
|
||||
os.close();
|
||||
reader.close();
|
||||
|
||||
if ((response == null) || response.startsWith("ERR") || response.startsWith("7"))
|
||||
{
|
||||
if (response == null)
|
||||
{
|
||||
|
||||
if ((response == null) || response.startsWith("ERR") || response.startsWith("7")) {
|
||||
if (response == null) {
|
||||
response = "null";
|
||||
}
|
||||
else if (response.startsWith("7"))
|
||||
{
|
||||
} else if (response.startsWith("7")) {
|
||||
response = response.substring(response.startsWith("7,") ? 2 : 1);
|
||||
}
|
||||
|
||||
|
||||
throw new IOException(response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* GZip compress a string of bytes
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static byte[] gzip(final String input)
|
||||
{
|
||||
public static byte[] gzip(final String input) {
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzos = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
try {
|
||||
gzos = new GZIPOutputStream(baos);
|
||||
gzos.write(input.getBytes("UTF-8"));
|
||||
}
|
||||
catch (final IOException e)
|
||||
{
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gzos != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
} finally {
|
||||
if (gzos != null) {
|
||||
try {
|
||||
gzos.close();
|
||||
}
|
||||
catch (final IOException ignore)
|
||||
{}
|
||||
} catch (final IOException ignore) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
||||
*
|
||||
* @return true if mineshafter is installed on the server
|
||||
*/
|
||||
private boolean isMineshafterPresent()
|
||||
{
|
||||
try
|
||||
{
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Appends a json encoded key/value pair to the given string builder.
|
||||
*
|
||||
@@ -495,58 +444,46 @@ public class SpongeMetrics
|
||||
* @param value
|
||||
* @throws java.io.UnsupportedEncodingException
|
||||
*/
|
||||
private static void appendJSONPair(final StringBuilder json, final String key, final String value) throws UnsupportedEncodingException
|
||||
{
|
||||
private static void appendJSONPair(final StringBuilder json, final String key, final String value) throws UnsupportedEncodingException {
|
||||
boolean isValueNumeric = false;
|
||||
|
||||
try
|
||||
{
|
||||
if (value.equals("0") || !value.endsWith("0"))
|
||||
{
|
||||
|
||||
try {
|
||||
if (value.equals("0") || !value.endsWith("0")) {
|
||||
Double.parseDouble(value);
|
||||
isValueNumeric = true;
|
||||
}
|
||||
}
|
||||
catch (final NumberFormatException e)
|
||||
{
|
||||
} catch (final NumberFormatException e) {
|
||||
isValueNumeric = false;
|
||||
}
|
||||
|
||||
if (json.charAt(json.length() - 1) != '{')
|
||||
{
|
||||
|
||||
if (json.charAt(json.length() - 1) != '{') {
|
||||
json.append(',');
|
||||
}
|
||||
|
||||
|
||||
json.append(escapeJSON(key));
|
||||
json.append(':');
|
||||
|
||||
if (isValueNumeric)
|
||||
{
|
||||
|
||||
if (isValueNumeric) {
|
||||
json.append(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
json.append(escapeJSON(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Escape a string to create a valid JSON string
|
||||
*
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
private static String escapeJSON(final String text)
|
||||
{
|
||||
private static String escapeJSON(final String text) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
|
||||
builder.append('"');
|
||||
for (int index = 0; index < text.length(); index++)
|
||||
{
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
final char chr = text.charAt(index);
|
||||
|
||||
switch (chr)
|
||||
{
|
||||
|
||||
switch (chr) {
|
||||
case '"':
|
||||
case '\\':
|
||||
builder.append('\\');
|
||||
@@ -565,32 +502,28 @@ public class SpongeMetrics
|
||||
builder.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ')
|
||||
{
|
||||
if (chr < ' ') {
|
||||
final String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u" + t.substring(t.length() - 4));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
builder.append(chr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
builder.append('"');
|
||||
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode text as UTF-8
|
||||
*
|
||||
* @param text the text to encode
|
||||
* @return the encoded text, as UTF-8
|
||||
*/
|
||||
private static String urlEncode(final String text) throws UnsupportedEncodingException
|
||||
{
|
||||
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(text, "UTF-8");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -9,16 +9,14 @@ import org.spongepowered.api.service.scheduler.TaskBuilder;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
|
||||
public class SpongeTaskManager extends TaskManager
|
||||
{
|
||||
|
||||
public class SpongeTaskManager extends TaskManager {
|
||||
|
||||
private final AtomicInteger i = new AtomicInteger();
|
||||
|
||||
|
||||
private final HashMap<Integer, Task> tasks = new HashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public int taskRepeat(final Runnable r, final int interval)
|
||||
{
|
||||
public int taskRepeat(final Runnable r, final int interval) {
|
||||
final int val = i.incrementAndGet();
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
final TaskBuilder built = builder.delay(interval).interval(interval).execute(r);
|
||||
@@ -26,10 +24,9 @@ public class SpongeTaskManager extends TaskManager
|
||||
tasks.put(val, task);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int taskRepeatAsync(final Runnable r, final int interval)
|
||||
{
|
||||
public int taskRepeatAsync(final Runnable r, final int interval) {
|
||||
final int val = i.incrementAndGet();
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
final TaskBuilder built = builder.delay(interval).async().interval(interval).execute(r);
|
||||
@@ -37,43 +34,37 @@ public class SpongeTaskManager extends TaskManager
|
||||
tasks.put(val, task);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void taskAsync(final Runnable r)
|
||||
{
|
||||
public void taskAsync(final Runnable r) {
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.async().execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void task(final Runnable r)
|
||||
{
|
||||
public void task(final Runnable r) {
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void taskLater(final Runnable r, final int delay)
|
||||
{
|
||||
public void taskLater(final Runnable r, final int delay) {
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.delay(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void taskLaterAsync(final Runnable r, final int delay)
|
||||
{
|
||||
public void taskLaterAsync(final Runnable r, final int delay) {
|
||||
final TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder();
|
||||
builder.async().delay(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void cancelTask(final int i)
|
||||
{
|
||||
public void cancelTask(final int i) {
|
||||
final Task task = tasks.remove(i);
|
||||
if (task != null)
|
||||
{
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -8,19 +8,11 @@ import com.intellectualcrafters.plot.util.AbstractTitle;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeTitleManager extends AbstractTitle
|
||||
{
|
||||
|
||||
public class SpongeTitleManager extends AbstractTitle {
|
||||
|
||||
@Override
|
||||
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out)
|
||||
{
|
||||
final Title title = new TitleBuilder()
|
||||
.title(SpongeMain.THIS.getText(head))
|
||||
.subtitle(SpongeMain.THIS.getText(sub))
|
||||
.fadeIn(in * 20)
|
||||
.stay(delay * 20)
|
||||
.fadeOut(out * 20)
|
||||
.build();
|
||||
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) {
|
||||
final Title title = new TitleBuilder().title(SpongeMain.THIS.getText(head)).subtitle(SpongeMain.THIS.getText(sub)).fadeIn(in * 20).stay(delay * 20).fadeOut(out * 20).build();
|
||||
((SpongePlayer) player).player.sendTitle(title);
|
||||
}
|
||||
}
|
||||
|
@@ -15,26 +15,24 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
import com.plotsquared.sponge.object.SpongePlayer;
|
||||
|
||||
public class SpongeUtil
|
||||
{
|
||||
|
||||
public static Location getLocation(final Entity player)
|
||||
{
|
||||
public class SpongeUtil {
|
||||
|
||||
public static Location getLocation(final Entity player) {
|
||||
final String world = player.getWorld().getName();
|
||||
final org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
final Vector3i pos = loc.getBlockPosition();
|
||||
return new Location(world, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public static Location getLocation(final org.spongepowered.api.world.Location block)
|
||||
{
|
||||
|
||||
public static Location getLocation(final org.spongepowered.api.world.Location block) {
|
||||
final Extent extent = block.getExtent();
|
||||
if (extent instanceof World) { return getLocation(((World) extent).getName(), block); }
|
||||
if (extent instanceof World) {
|
||||
return getLocation(((World) extent).getName(), block);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Location getLocationFull(final Entity player)
|
||||
{
|
||||
|
||||
public static Location getLocationFull(final Entity player) {
|
||||
final String world = player.getWorld().getName();
|
||||
final Vector3d rot = player.getRotation();
|
||||
final float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ());
|
||||
@@ -42,68 +40,74 @@ public class SpongeUtil
|
||||
final Vector3i pos = loc.getBlockPosition();
|
||||
return new Location(world, pos.getX(), pos.getY(), pos.getZ(), pitchYaw[1], pitchYaw[0]);
|
||||
}
|
||||
|
||||
|
||||
private static Player lastPlayer = null;
|
||||
private static PlotPlayer lastPlotPlayer = null;
|
||||
|
||||
public static PlotPlayer getPlayer(final Player player)
|
||||
{
|
||||
if (player == lastPlayer) { return lastPlotPlayer; }
|
||||
|
||||
public static PlotPlayer getPlayer(final Player player) {
|
||||
if (player == lastPlayer) {
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
final String name = player.getName();
|
||||
final PlotPlayer pp = UUIDHandler.getPlayers().get(name);
|
||||
if (pp != null) { return pp; }
|
||||
if (pp != null) {
|
||||
return pp;
|
||||
}
|
||||
lastPlotPlayer = new SpongePlayer(player);
|
||||
UUIDHandler.getPlayers().put(name, lastPlotPlayer);
|
||||
lastPlayer = player;
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
|
||||
public static Player getPlayer(final PlotPlayer player)
|
||||
{
|
||||
if (player instanceof SpongePlayer) { return ((SpongePlayer) player).player; }
|
||||
|
||||
public static Player getPlayer(final PlotPlayer player) {
|
||||
if (player instanceof SpongePlayer) {
|
||||
return ((SpongePlayer) player).player;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static World lastWorld;
|
||||
private static String last;
|
||||
|
||||
public static World getWorld(final String world)
|
||||
{
|
||||
if (world == last) { return lastWorld; }
|
||||
|
||||
public static World getWorld(final String world) {
|
||||
if (world == last) {
|
||||
return lastWorld;
|
||||
}
|
||||
final Optional<World> optional = SpongeMain.THIS.getServer().getWorld(world);
|
||||
if (!optional.isPresent()) { return null; }
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
return optional.get();
|
||||
}
|
||||
|
||||
public static void removePlayer(final String player)
|
||||
{
|
||||
|
||||
public static void removePlayer(final String player) {
|
||||
lastPlayer = null;
|
||||
lastPlotPlayer = null;
|
||||
UUIDHandler.getPlayers().remove(player);
|
||||
}
|
||||
|
||||
public static Location getLocation(final String world, final org.spongepowered.api.world.Location spawn)
|
||||
{
|
||||
|
||||
public static Location getLocation(final String world, final org.spongepowered.api.world.Location spawn) {
|
||||
return new Location(world, spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ());
|
||||
}
|
||||
|
||||
public static String getWorldName(final org.spongepowered.api.world.Location origin)
|
||||
{
|
||||
|
||||
public static String getWorldName(final org.spongepowered.api.world.Location origin) {
|
||||
final Extent extent = origin.getExtent();
|
||||
if (extent == lastWorld) { return last; }
|
||||
if (extent instanceof World)
|
||||
{
|
||||
if (extent == lastWorld) {
|
||||
return last;
|
||||
}
|
||||
if (extent instanceof World) {
|
||||
lastWorld = (World) extent;
|
||||
last = ((World) extent).getName();
|
||||
return last;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static org.spongepowered.api.world.Location getLocation(final Location loc)
|
||||
{
|
||||
|
||||
public static org.spongepowered.api.world.Location getLocation(final Location loc) {
|
||||
final Optional<World> world = SpongeMain.THIS.getServer().getWorld(loc.getWorld());
|
||||
if (!world.isPresent()) { return null; }
|
||||
if (!world.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
return new org.spongepowered.api.world.Location(world.get(), loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user