mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-23 07:40:28 +02:00
cleanup
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user