diff --git a/pom.xml b/pom.xml index b61301194..830ed10f8 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 3.2.15 + 3.2.16 PlotSquared jar diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index 2ee43fe0e..c3914e8ae 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1607,7 +1607,7 @@ public class PS { "no-worldedit", "redstone", "keep"); final List intervalFlags = Arrays.asList("feed", "heal"); final List stringFlags = Arrays.asList("greeting", "farewell"); - final List intFlags = Arrays.asList("entity-cap", "mob-cap", "animal-cap", "hostile-cap", "vehicle-cap", "music"); + final List intFlags = Arrays.asList("misc-cap", "entity-cap", "mob-cap", "animal-cap", "hostile-cap", "vehicle-cap", "music"); for (final String flag : stringFlags) { FlagManager.addFlag(new AbstractFlag(flag)); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 247a7fb2b..0d515cf6b 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -80,8 +80,8 @@ public class MainCommand extends CommandManager { createCommand(new RegenAllRoads()); createCommand(new Claim()); createCommand(new Auto()); - createCommand(new Home()); createCommand(new Visit()); + createCommand(new Home()); createCommand(new TP()); createCommand(new Set()); createCommand(new Toggle()); @@ -171,47 +171,6 @@ public class MainCommand extends CommandManager { return commands; } - //// public static List helpMenu(final PlotPlayer player, final CommandCategory category, int page) { - // List> commands; - // // commands = getCommands(category, player); - // // final int totalPages = ((int) Math.ceil(12 * (commands.size()) / - // // 100)); - // final int perPage = 5; - // // final int totalPages = (commands.size() / perPage) + (commands.size() % perPage == 0 ? 0 : 1); - // // if (page > totalPages) { - // // page = totalPages; - // // } - // int max = (page * perPage) + perPage; - // // if (max > commands.size()) { - // // max = commands.size(); - // // } - // final List help = new ArrayList<>(); - // help.add(C.HELP_HEADER.s()); - // // HELP_PAGE_HEADER("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"), - // // help.add(C.HELP_PAGE_HEADER.s().replace("%category%", category == null ? "All" : category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages)).replace("%dis%", "" + perPage).replace("%total%", "" + commands.size())); - // Command cmd; - // // HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"), - // // help.add(C.HELP_CATEGORY.s().replace("%category%", category == null ? "All" : category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages)).replace("%dis%", "" + perPage).replace("%total%", "" + commands.size())); - // // Command cmd; - // final int start = page * perPage; - // for (int x = start; x < max; x++) { - // // cmd = commands.get(x); - // String s = C.HELP_ITEM.s(); - // if (cmd.getAliases().size() > 0) { - // s = s.replace("%alias%", StringMan.join(cmd.getAliases(), "|")); - // } - // else { - // s = s.replace("%alias%", ""); - // } - // s = s.replace("%usage%", cmd.getUsage().contains("plot") ? cmd.getUsage() : "/plot " + cmd.getUsage()).replace("%cmd%", cmd.getCommand()).replace("%desc%", cmd.getDescription()).replace("[]", ""); - // help.add(s); - // } - // if (help.size() < 2) { - // help.add(C.NO_COMMANDS.s()); - // } - // return help; - // } - // public static void displayHelp(final PlotPlayer player, String cat, int page, final String label) { CommandCategory catEnum = null; if (cat != null) { @@ -322,6 +281,11 @@ public class MainCommand extends CommandManager { int count = 0; String perm = cmd.getPermission(); HashSet desc = new HashSet(); + for (String alias : cmd.getAliases()) { + if (alias.startsWith(args[0])) { + count += 5; + } + } for (String word : cmd.getDescription().split(" ")) { desc.add(word); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index 0e8148183..41eae2a02 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -61,7 +61,7 @@ public class Rate extends SubCommand { public boolean onCommand(final PlotPlayer player, final String[] args) { if (args.length == 1) { if (args[0].equalsIgnoreCase("next")) { - final ArrayList plots = new ArrayList<>(PS.get().getPlots()); + final ArrayList plots = new ArrayList<>(PS.get().getBasePlots()); Collections.sort(plots, new Comparator() { @Override public int compare(final Plot p1, final Plot p2) { @@ -96,7 +96,7 @@ public class Rate extends SubCommand { } } final Location loc = player.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = MainUtil.getPlot(loc); if (plot == null) { return !sendMessage(player, C.NOT_IN_PLOT); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index 884f634e4..1544a652d 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -26,11 +26,9 @@ import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Set; import java.util.UUID; import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.PS.SortType; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -45,7 +43,7 @@ import com.plotsquared.general.commands.CommandDeclaration; command = "visit", permission = "plots.visit", description = "Visit someones plot", -usage = "/plot visit [#]", +usage = "/plot visit [player|alias|world|id] [#]", aliases = { "v" }, requiredType = RequiredType.NONE, category = CommandCategory.TELEPORT) diff --git a/src/main/java/com/intellectualcrafters/plot/commands/list.java b/src/main/java/com/intellectualcrafters/plot/commands/list.java index 30d2ddda7..5398b7499 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -46,7 +46,13 @@ import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; -@CommandDeclaration(command = "list", aliases = { "l" }, description = "List plots", permission = "plots.list", category = CommandCategory.INFO) +@CommandDeclaration( +command = "list", +aliases = { "l" }, +description = "List plots", +permission = "plots.list", +category = CommandCategory.INFO, +usage = "/plot list [#]") public class list extends SubCommand { private String[] getArgumentList(final PlotPlayer player) { diff --git a/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index 6604e548e..7759eaecb 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -84,6 +84,18 @@ public interface AbstractDB { */ void delete(final Plot plot); + void deleteSettings(Plot plot); + + void deleteHelpers(Plot plot); + + void deleteTrusted(Plot plot); + + void deleteDenied(Plot plot); + + void deleteComments(Plot plot); + + void deleteRatings(Plot plot); + void delete(final PlotCluster cluster); /** diff --git a/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index 796d16172..1149cb949 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -40,8 +40,8 @@ import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.PlotComment; /** - * DB Functions - * + * Database Functions + * - These functions do not update the local plot objects and only make changes to the DB */ public class DBFunc { /** @@ -154,6 +154,76 @@ public class DBFunc { plot.temp = -1; } + /** + * Delete the ratings for a plot + * @param plot + */ + public static void deleteRatings(final Plot plot) { + if (plot.temp == -1) { + return; + } + dbManager.deleteRatings(plot); + } + + /** + * Delete the trusted list for a plot + * @param plot + */ + public static void deleteTrusted(final Plot plot) { + if (plot.temp == -1) { + return; + } + dbManager.deleteHelpers(plot); + } + + /** + * Delete the members list for a plot + * @param plot + */ + public static void deleteMembers(final Plot plot) { + if (plot.temp == -1) { + return; + } + dbManager.deleteTrusted(plot); + } + + /** + * Delete the denied list for a plot + * @param plot + */ + public static void deleteDenied(final Plot plot) { + if (plot.temp == -1) { + return; + } + dbManager.deleteDenied(plot); + } + + /** + * Delete the comments in a plot + * @param plot + */ + public static void deleteComments(final Plot plot) { + if (plot.temp == -1) { + return; + } + dbManager.deleteComments(plot); + } + + /** + * Deleting settings will + * 1) Delete any settings (flags and such) associated with the plot + * 2) Prevent any local changes to the plot from saving properly to the db + * + * This shouldn't ever be needed + * @param plot + */ + public static void deleteSettings(final Plot plot) { + if (plot.temp == -1) { + return; + } + dbManager.deleteSettings(plot); + } + public static void delete(final PlotCluster toDelete) { dbManager.delete(toDelete); } diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 23df3ce2e..208298ce0 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -1191,14 +1191,8 @@ public class SQLManager implements AbstractDB { stmt.close(); } - /** - * Delete a plot - * - * @param plot - */ @Override - public void delete(final Plot plot) { - PS.get().removePlot(plot.world, plot.id, false); + public void deleteSettings(final Plot plot) { addPlotTask(plot, new UniqueStatement("delete_plot_settings") { @Override public void set(final PreparedStatement stmt) throws SQLException { @@ -1210,6 +1204,13 @@ public class SQLManager implements AbstractDB { return connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = ?"); } }); + } + + @Override + public void deleteHelpers(final Plot plot) { + if (plot.getTrusted().size() == 0) { + return; + } addPlotTask(plot, new UniqueStatement("delete_plot_helpers") { @Override public void set(final PreparedStatement stmt) throws SQLException { @@ -1221,6 +1222,13 @@ public class SQLManager implements AbstractDB { return connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = ?"); } }); + } + + @Override + public void deleteTrusted(final Plot plot) { + if (plot.getMembers().size() == 0) { + return; + } addPlotTask(plot, new UniqueStatement("delete_plot_trusted") { @Override public void set(final PreparedStatement stmt) throws SQLException { @@ -1232,6 +1240,13 @@ public class SQLManager implements AbstractDB { return connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = ?"); } }); + } + + @Override + public void deleteDenied(final Plot plot) { + if (plot.getDenied().size() == 0) { + return; + } addPlotTask(plot, new UniqueStatement("delete_plot_denied") { @Override public void set(final PreparedStatement stmt) throws SQLException { @@ -1243,6 +1258,10 @@ public class SQLManager implements AbstractDB { return connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = ?"); } }); + } + + @Override + public void deleteComments(final Plot plot) { addPlotTask(plot, new UniqueStatement("delete_plot_comments") { @Override public void set(final PreparedStatement stmt) throws SQLException { @@ -1255,6 +1274,40 @@ public class SQLManager implements AbstractDB { return connection.prepareStatement("DELETE FROM `" + prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ?"); } }); + } + + @Override + public void deleteRatings(final Plot plot) { + if (Settings.CACHE_RATINGS && plot.getSettings().getRatings().size() == 0) { + return; + } + addPlotTask(plot, new UniqueStatement("delete_plot_ratings") { + @Override + public void set(final PreparedStatement stmt) throws SQLException { + stmt.setInt(1, getId(plot)); + } + + @Override + public PreparedStatement get() throws SQLException { + return connection.prepareStatement("DELETE FROM `" + prefix + "plot_rating` WHERE `plot_plot_id` = ?"); + } + }); + } + + /** + * Delete a plot + * + * @param plot + */ + @Override + public void delete(final Plot plot) { + PS.get().removePlot(plot.world, plot.id, false); + deleteSettings(plot); + deleteDenied(plot); + deleteHelpers(plot); + deleteTrusted(plot); + deleteComments(plot); + deleteRatings(plot); addPlotTask(plot, new UniqueStatement("delete_plot") { @Override public void set(final PreparedStatement stmt) throws SQLException { diff --git a/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 3abcb433c..9ac9d13d0 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -721,24 +721,55 @@ public class Plot { */ public double getAverageRating() { double sum = 0; - final Collection ratings = getRatings().values(); + final Collection ratings = getBasePlot(false).getRatings().values(); for (final Rating rating : ratings) { sum += rating.getAverageRating(); } return (sum / ratings.size()); } + /** + * Set a rating for a user
+ * - If the user has already rated, the following will return false + * @param uuid + * @param rating + * @return + */ + public boolean addRating(UUID uuid, Rating rating) { + Plot base = getBasePlot(false); + PlotSettings baseSettings = base.getSettings(); + if (baseSettings.getRatings().containsKey(uuid)) { + return false; + } + baseSettings.getRatings().put(uuid, rating.getAggregate()); + DBFunc.setRating(base, uuid, temp); + return true; + } + + /** + * Clear the ratings for this plot + */ + public void clearRatings() { + Plot base = getBasePlot(false); + PlotSettings baseSettings = base.getSettings(); + if (baseSettings.ratings != null && baseSettings.ratings.size() > 0) { + DBFunc.deleteRatings(base); + baseSettings.ratings = null; + } + } + /** * Get the ratings associated with a plot
* - The rating object may contain multiple categories * @return Map of user who rated to the rating */ public HashMap getRatings() { + Plot base = getBasePlot(false); final HashMap map = new HashMap(); - if (getSettings().ratings == null) { + if (base.getSettings().ratings == null) { return map; } - for (final Entry entry : getSettings().ratings.entrySet()) { + for (final Entry entry : base.getSettings().ratings.entrySet()) { map.put(entry.getKey(), new Rating(entry.getValue())); } return map; @@ -980,6 +1011,13 @@ public class Plot { * @param uuid */ public boolean removeDenied(final UUID uuid) { + if (uuid == DBFunc.everyone) { + boolean result = false; + for (UUID other : getDenied()) { + result = result || PlotHandler.removeDenied(this, other); + } + return result; + } return PlotHandler.removeDenied(this, uuid); } @@ -989,6 +1027,13 @@ public class Plot { * @param uuid */ public boolean removeTrusted(final UUID uuid) { + if (uuid == DBFunc.everyone) { + boolean result = false; + for (UUID other : getTrusted()) { + result = result || PlotHandler.removeTrusted(this, other); + } + return result; + } return PlotHandler.removeTrusted(this, uuid); } @@ -998,6 +1043,13 @@ public class Plot { * @param uuid */ public boolean removeMember(final UUID uuid) { + if (uuid == DBFunc.everyone) { + boolean result = false; + for (UUID other : getMembers()) { + result = result || PlotHandler.removeMember(this, other); + } + return result; + } return PlotHandler.removeMember(this, uuid); } diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java b/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java index b0270a8cd..32008bd9a 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java @@ -23,6 +23,7 @@ package com.intellectualcrafters.plot.object; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import com.intellectualcrafters.plot.flag.Flag; @@ -30,35 +31,48 @@ import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.comment.PlotComment; /** - * plot settings - * + * Generic settings class + * - Does not keep a reference to a parent class + * - Direct changes here will not occur in the db (Use the parent plot object for that) */ public class PlotSettings { /** * merged plots + * @deprecated Raw access */ + @Deprecated public boolean[] merged = new boolean[] { false, false, false, false }; /** * plot alias + * @deprecated Raw access */ + @Deprecated public String alias = ""; /** * Comments + * @deprecated Raw access */ + @Deprecated public List comments = null; /** * The ratings for a plot + * @deprecated Raw access */ + @Deprecated public HashMap ratings; /** * Flags + * @deprecated Raw access */ + @Deprecated public HashMap flags; /** * Home Position + * @deprecated Raw access */ + @Deprecated private BlockLoc position; /** @@ -96,6 +110,10 @@ public class PlotSettings { this.merged = merged; } + public Map getRatings() { + return ratings == null ? new HashMap() : ratings; + } + public boolean setMerged(final int direction, final boolean merged) { if (this.merged[direction] != merged) { this.merged[direction] = merged; diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 0118776ef..ade54281a 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -524,6 +524,7 @@ public class MainUtil { if (!result) { return false; } + plot.clearRatings(); if (createSign) { plot.removeSign(); } @@ -1010,6 +1011,8 @@ public class MainUtil { greaterPlot = tmp; } if (!lesserPlot.getMerged(2)) { + lesserPlot.clearRatings(); + greaterPlot.clearRatings(); lesserPlot.setMerged(2, true); greaterPlot.setMerged(0, true); mergeData(lesserPlot, greaterPlot); @@ -1032,6 +1035,8 @@ public class MainUtil { greaterPlot = tmp; } if (!lesserPlot.getMerged(1)) { + lesserPlot.clearRatings(); + greaterPlot.clearRatings(); lesserPlot.setMerged(1, true); greaterPlot.setMerged(3, true); mergeData(lesserPlot, greaterPlot); @@ -1379,7 +1384,7 @@ public class MainUtil { } public static int[] countEntities(Plot plot) { - int[] count = new int[5]; + int[] count = new int[6]; for (Plot current : getConnectedPlots(plot)) { int[] result = ChunkManager.manager.countEntities(current); count[0] += result[0]; @@ -1387,6 +1392,7 @@ public class MainUtil { count[2] += result[2]; count[3] += result[3]; count[4] += result[4]; + count[5] += result[5]; } return count; } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 8b519b79d..082b4b8d9 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -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 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); - if (mobs[0] >= cap) { - return true; + 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) { - return true; - } + 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: { + return false; } - 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; - } - } + 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 } - } 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); - } - if (mobs[4] >= cap) { - return true; + 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); } } } diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index f4da14105..3572f4d3c 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -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]++; } } diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java b/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java index 3140d3ecd..2b7a9823f 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java @@ -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 tabOptions = new HashSet<>(); - final ArrayList> commands = MainCommand.getInstance().getCommands(); - final String best = new StringComparison(strings[0], commands).getBestMatch(); - tabOptions.add(best); final String arg = strings[0].toLowerCase(); + ArrayList labels = new ArrayList<>(); for (final Command cmd : MainCommand.getInstance().getCommands()) { final String label = cmd.getCommand(); - if (!label.equalsIgnoreCase(best)) { - if (label.startsWith(arg)) { + HashSet 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; - } - } + tabOptions.add(label); + } else { + break; } } } } + String best = new StringComparison<>(arg, labels).getBestMatch(); + tabOptions.add(best); if (tabOptions.size() > 0) { return new ArrayList<>(tabOptions); } diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java index a9a373667..f59a4ce41 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java @@ -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() { @Override public boolean test(final Entity entity) { diff --git a/target/PlotSquared-Bukkit.jar b/target/PlotSquared-Bukkit.jar index 63f56c536..d7ee4a0b7 100644 Binary files a/target/PlotSquared-Bukkit.jar and b/target/PlotSquared-Bukkit.jar differ diff --git a/target/PlotSquared-Sponge.jar b/target/PlotSquared-Sponge.jar index fc04c0d8a..092d86ab5 100644 Binary files a/target/PlotSquared-Sponge.jar and b/target/PlotSquared-Sponge.jar differ