ratings api
misc-cap
other tweakes
This commit is contained in:
Jesse Boyd
2015-10-27 10:57:34 +11:00
parent 2e79f3d0f8
commit 95feaed870
18 changed files with 504 additions and 163 deletions

View File

@ -92,6 +92,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
import org.spongepowered.api.entity.living.animal.Animal;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
@ -1304,76 +1305,154 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
@EventHandler
public void onPrime(final ExplosionPrimeEvent event) {
lastRadius = event.getRadius() + 1;
}
public boolean checkEntity(final Entity entity, final Plot plot) {
if ((plot != null) && (plot.owner != null)) {
final Flag entityFlag = FlagManager.getPlotFlagRaw(plot, "entity-cap");
int[] mobs = null;
if (entityFlag != null) {
final int cap = ((Integer) entityFlag.getValue());
if (cap == 0) {
return true;
}
mobs = MainUtil.countEntities(plot);
}
public boolean checkEntity(Plot plot, String... flags) {
int[] mobs = null;
for (String flag : flags) {
int i;
switch (flag) {
case "entity-cap":
i = 0;
break;
case "mob-cap":
i = 3;
break;
case "hostile-cap":
i = 2;
break;
case "animal-cap":
i = 1;
break;
case "vehicle-cap":
i = 4;
break;
case "misc-cap":
i = 5;
break;
default: {
i = 0;
}
}
if (entity instanceof Creature) {
final Flag mobFlag = FlagManager.getPlotFlagRaw(plot, "mob-cap");
if (mobFlag != null) {
final int cap = ((Integer) mobFlag.getValue());
if (cap == 0) {
return true;
}
if (mobs == null) {
mobs = MainUtil.countEntities(plot);
}
if (mobs[3] >= cap) {
}
}
final Flag plotFlag = FlagManager.getPlotFlagRaw(plot, flag);
if (plotFlag == null) {
continue;
}
if (mobs == null) {
mobs = MainUtil.countEntities(plot);
}
if (mobs[i] >= ((Integer) plotFlag.getValue())) {
return true;
}
}
return false;
}
public boolean checkEntity(final Entity entity, final Plot plot) {
if ((plot != null) && (plot.owner != null)) {
switch (entity.getType()) {
case PLAYER: {
}
}
if (entity instanceof Animals) {
final Flag animalFlag = FlagManager.getPlotFlagRaw(plot, "animal-cap");
if (animalFlag != null) {
final int cap = ((Integer) animalFlag.getValue());
if (cap == 0) {
return true;
}
if (mobs == null) {
mobs = MainUtil.countEntities(plot);
}
if (mobs[1] >= cap) {
return true;
}
}
} else if (entity instanceof Monster) {
final Flag monsterFlag = FlagManager.getPlotFlagRaw(plot, "hostile-cap");
if (monsterFlag != null) {
final int cap = ((Integer) monsterFlag.getValue());
if (cap == 0) {
return true;
}
if (mobs == null) {
mobs = MainUtil.countEntities(plot);
}
if (mobs[2] >= cap) {
return true;
return false;
}
case SMALL_FIREBALL:
case FIREBALL:
case DROPPED_ITEM:
case EGG:
case THROWN_EXP_BOTTLE:
case SPLASH_POTION:
case SNOWBALL:
case ENDER_PEARL:
case ARROW: {
}
}
} else if (entity instanceof Vehicle) {
final Flag vehicleFlag = FlagManager.getPlotFlagRaw(plot, "vehicle-cap");
if (vehicleFlag != null) {
final int cap = ((Integer) vehicleFlag.getValue());
if (cap == 0) {
return true;
}
if (mobs == null) {
mobs = MainUtil.countEntities(plot);
}
// projectile
}
case PRIMED_TNT:
case FALLING_BLOCK: {
// Block entities
}
case ENDER_CRYSTAL:
case COMPLEX_PART:
case FISHING_HOOK:
case ENDER_SIGNAL:
case EXPERIENCE_ORB:
case LEASH_HITCH:
case FIREWORK:
case WEATHER:
case LIGHTNING:
case WITHER_SKULL:
case UNKNOWN: {
// non moving / unremovable
return checkEntity(plot, "entity-cap");
}
case ITEM_FRAME:
case PAINTING:
case ARMOR_STAND: {
return checkEntity(plot, "entity-cap", "misc-cap");
// misc
}
case MINECART:
case MINECART_CHEST:
case MINECART_COMMAND:
case MINECART_FURNACE:
case MINECART_HOPPER:
case MINECART_MOB_SPAWNER:
case MINECART_TNT:
case BOAT: {
return checkEntity(plot, "entity-cap", "vehicle-cap");
}
case RABBIT:
case SHEEP:
case MUSHROOM_COW:
case OCELOT:
case PIG:
case HORSE:
case SQUID:
case VILLAGER:
case IRON_GOLEM:
case WOLF:
case CHICKEN:
case COW:
case SNOWMAN:
case BAT: {
// animal
return checkEntity(plot, "entity-cap", "mob-cap", "animal-cap");
}
case BLAZE:
case CAVE_SPIDER:
case CREEPER:
case ENDERMAN:
case ENDERMITE:
case ENDER_DRAGON:
case GHAST:
case GIANT:
case GUARDIAN:
case MAGMA_CUBE:
case PIG_ZOMBIE:
case SILVERFISH:
case SKELETON:
case SLIME:
case SPIDER:
case WITCH:
case WITHER:
case ZOMBIE: {
// monster
return checkEntity(plot, "entity-cap", "mob-cap", "hostile-cap");
}
default: {
String[] types;
if (entity instanceof LivingEntity) {
if (entity instanceof Animal) {
types = new String[] { "entity-cap", "mob-cap", "animal-cap" };
} else if (entity instanceof Monster) {
types = new String[] { "entity-cap", "mob-cap", "hostile-cap" };
} else {
types = new String[] { "entity-cap", "mob-cap" };
}
} else if (entity instanceof Vehicle) {
types = new String[] { "entity-cap", "vehicle-cap" };
} else if (entity instanceof Hanging) {
types = new String[] { "entity-cap", "misc-cap" };
} else {
types = new String[] { "entity-cap" };
}
return checkEntity(plot, types);
}

View File

@ -39,7 +39,6 @@ import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
@ -946,7 +945,7 @@ public class BukkitChunkManager extends ChunkManager {
@Override
public int[] countEntities(final Plot plot) {
final int[] count = new int[5];
final int[] count = new int[6];
final World world = BukkitUtil.getWorld(plot.world);
final Location bot = MainUtil.getPlotBottomLocAbs(plot.world, plot.id);
@ -977,9 +976,6 @@ public class BukkitChunkManager extends ChunkManager {
if (doWhole) {
for (final Entity entity : entities) {
if (!((entity instanceof Creature) || (entity instanceof Vehicle))) {
continue;
}
final org.bukkit.Location loc = entity.getLocation();
final Chunk chunk = loc.getChunk();
if (chunks.contains(chunk)) {
@ -1001,9 +997,6 @@ public class BukkitChunkManager extends ChunkManager {
final int Z = chunk.getX();
final Entity[] ents = chunk.getEntities();
for (final Entity entity : ents) {
if (!((entity instanceof Creature) || (entity instanceof Vehicle))) {
continue;
}
if ((X == bx) || (X == tx) || (Z == bz) || (Z == tz)) {
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(entity));
if (plot.id.equals(id)) {
@ -1020,15 +1013,110 @@ public class BukkitChunkManager extends ChunkManager {
private void count(final int[] count, final Entity entity) {
count[0]++;
if (entity instanceof Creature) {
count[3]++;
if (entity instanceof Animals) {
count[1]++;
} else {
count[2]++;
switch (entity.getType()) {
case PLAYER: {
// not valid
}
case SMALL_FIREBALL:
case FIREBALL:
case DROPPED_ITEM:
case EGG:
case THROWN_EXP_BOTTLE:
case SPLASH_POTION:
case SNOWBALL:
case ENDER_PEARL:
case ARROW: {
// projectile
}
case PRIMED_TNT:
case FALLING_BLOCK: {
// Block entities
}
case ENDER_CRYSTAL:
case COMPLEX_PART:
case FISHING_HOOK:
case ENDER_SIGNAL:
case EXPERIENCE_ORB:
case LEASH_HITCH:
case FIREWORK:
case WEATHER:
case LIGHTNING:
case WITHER_SKULL:
case UNKNOWN: {
// non moving / unremovable
break;
}
case ITEM_FRAME:
case PAINTING:
case ARMOR_STAND: {
count[5]++;
// misc
}
case MINECART:
case MINECART_CHEST:
case MINECART_COMMAND:
case MINECART_FURNACE:
case MINECART_HOPPER:
case MINECART_MOB_SPAWNER:
case MINECART_TNT:
case BOAT: {
count[4]++;
break;
}
case RABBIT:
case SHEEP:
case MUSHROOM_COW:
case OCELOT:
case PIG:
case HORSE:
case SQUID:
case VILLAGER:
case IRON_GOLEM:
case WOLF:
case CHICKEN:
case COW:
case SNOWMAN:
case BAT: {
// animal
count[3]++;
count[1]++;
break;
}
case BLAZE:
case CAVE_SPIDER:
case CREEPER:
case ENDERMAN:
case ENDERMITE:
case ENDER_DRAGON:
case GHAST:
case GIANT:
case GUARDIAN:
case MAGMA_CUBE:
case PIG_ZOMBIE:
case SILVERFISH:
case SKELETON:
case SLIME:
case SPIDER:
case WITCH:
case WITHER:
case ZOMBIE: {
// monster
count[3]++;
count[2]++;
break;
}
default: {
if (entity instanceof Creature) {
count[3]++;
if (entity instanceof Animals) {
count[1]++;
} else {
count[2]++;
}
} else {
count[4]++;
}
}
} else {
count[4]++;
}
}

View File

@ -78,31 +78,26 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
}
if (strings.length > 1) {
return null;
}
if (!command.getLabel().equalsIgnoreCase("plots")) {
return null;
}
final Set<String> tabOptions = new HashSet<>();
final ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands();
final String best = new StringComparison(strings[0], commands).getBestMatch();
final Set<String> tabOptions = new HashSet<>();
final String arg = strings[0].toLowerCase();
ArrayList<String> labels = new ArrayList<>();
for (final Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) {
final String label = cmd.getCommand();
if (!label.equalsIgnoreCase(best)) {
final String label = cmd.getCommand();
HashSet<String> aliases = new HashSet<>(cmd.getAliases());
aliases.add(label);
for (String alias : aliases) {
labels.add(alias);
if (alias.startsWith(arg)) {
if (Permissions.hasPermission(player, cmd.getPermission())) {
tabOptions.add(cmd.getCommand());
} else if (cmd.getAliases().size() > 0) {
for (final String alias : cmd.getAliases()) {
if (alias.startsWith(arg)) {
tabOptions.add(label);
break;
}
if (Permissions.hasPermission(player, cmd.getPermission())) {
tabOptions.add(label);
} else {
break;
}
}
}
}
String best = new StringComparison<>(arg, labels).getBestMatch();
tabOptions.add(best);
if (tabOptions.size() > 0) {
return new ArrayList<>(tabOptions);

View File

@ -37,7 +37,7 @@ public class SpongeChunkManager extends ChunkManager {
final int bz = pos1.getZ();
final int tx = pos2.getX();
final int tz = pos2.getZ();
final int[] count = new int[5];
final int[] count = new int[6];
world.getEntities(new Predicate<Entity>() {
@Override
public boolean test(final Entity entity) {