Sponge stuff

Added entity / mob / vehicle / animal / monster caps + entity clearing
on plot clear.
This commit is contained in:
boy0001
2015-08-12 04:04:17 +10:00
parent b40c464da9
commit 7d3de207aa
8 changed files with 223 additions and 16 deletions

View File

@@ -10,10 +10,13 @@ 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.immutable.ImmutableListValue;
import org.spongepowered.api.data.value.mutable.ListValue;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.biome.BiomeType;
import org.spongepowered.api.world.biome.BiomeTypes;
import org.spongepowered.common.data.value.mutable.SpongeListValue;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.object.Location;
@@ -191,7 +194,13 @@ public class SpongeBlockManager extends BlockManager {
for (int i = 0; i < 4; i++) {
text.add(SpongeMain.THIS.getText(lines[i]));
}
sign.offer(Keys.SIGN_LINES, text);
try {
SpongeListValue<Text> offering = new SpongeListValue<Text>(Keys.SIGN_LINES, text);
sign.offer(offering);
}
catch (NullPointerException e) {
e.printStackTrace();
}
}
@Override

View File

@@ -4,11 +4,16 @@ 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;
import org.spongepowered.api.entity.living.monster.Monster;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.storage.ChunkDataStream;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
@@ -28,8 +33,42 @@ public class SpongeChunkManager extends ChunkManager {
@Override
public int[] countEntities(Plot plot) {
// TODO Auto-generated method stub
return new int[5];
Location pos1 = plot.getBottom().add(1, 0, 1);
Location pos2 = plot.getTop();
String worldname = pos1.getWorld();
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>() {
@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) {
count[0]++;
if (entity instanceof Living) {
count[3]++;
if (entity instanceof Animal) {
count[1]++;
} else if (entity instanceof Monster){
count[2]++;
}
} else {
count[4]++;
}
}
}
return false;
}
});
return count;
}
@Override
@@ -116,8 +155,26 @@ public class SpongeChunkManager extends ChunkManager {
@Override
public void clearAllEntities(Location pos1, Location pos2) {
// TODO Auto-generated method stub
String worldname = pos1.getWorld();
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>() {
@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) {
entity.remove();
}
}
return false;
}
});
}
}

View File

@@ -89,4 +89,17 @@ public class SpongeUtil {
public static Location getLocation(String world, 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) {
lastWorld = (World) extent;
last = ((World) extent).getName();
return last;
}
return null;
}
}