From 393a85c1bc8fe20a9742a65ee946b5dfe47fad57 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 14 Aug 2015 03:22:32 +1000 Subject: [PATCH] Done flag --- pom.xml | 2 +- .../com/intellectualcrafters/plot/PS.java | 1 + .../plot/commands/Clear.java | 8 ++ .../plot/commands/Done.java | 85 +++++++++++++++++++ .../plot/commands/MainCommand.java | 1 + .../plot/commands/Rate.java | 85 +++++++++++-------- .../intellectualcrafters/plot/config/C.java | 13 ++- .../plot/config/Settings.java | 1 + .../bukkit/listeners/PlayerEvents.java | 19 ++++- .../bukkit/listeners/worldedit/WEManager.java | 3 +- .../general/commands/CommandManager.java | 4 + 11 files changed, 180 insertions(+), 42 deletions(-) create mode 100644 src/main/java/com/intellectualcrafters/plot/commands/Done.java diff --git a/pom.xml b/pom.xml index 68832ea1b..1ec715a8b 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 3.0.15 + 3.0.16 PlotSquared jar diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index 9f0006906..0c75a0a16 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1633,6 +1633,7 @@ public class PS { for (final String flag : intFlags) { FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue())); } + FlagManager.addFlag(new AbstractFlag("done", new FlagValue.StringValue()), true); FlagManager.addFlag(new AbstractFlag("analysis", new FlagValue.IntegerListValue()), true); FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue())); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index 256f25a0e..f92661fa8 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -25,6 +25,7 @@ import java.util.Set; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; @@ -94,6 +95,13 @@ public class Clear extends SubCommand { final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable() { @Override public void run() { + // If the state changes, then mark it as no longer done + if (FlagManager.isPlotFlagTrue(plot, "done" )) { + FlagManager.removePlotFlag(plot, "done"); + } + if (FlagManager.getPlotFlag(plot, "analysis") != null) { + FlagManager.removePlotFlag(plot, "analysis"); + } MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start)); } }); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Done.java b/src/main/java/com/intellectualcrafters/plot/commands/Done.java new file mode 100644 index 000000000..8a47a296b --- /dev/null +++ b/src/main/java/com/intellectualcrafters/plot/commands/Done.java @@ -0,0 +1,85 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////// +// PlotSquared - A plot manager and world generator for the Bukkit API / +// Copyright (c) 2014 IntellectualSites/IntellectualCrafters / +// / +// This program is free software; you can redistribute it and/or modify / +// it under the terms of the GNU General Public License as published by / +// the Free Software Foundation; either version 3 of the License, or / +// (at your option) any later version. / +// / +// This program is distributed in the hope that it will be useful, / +// but WITHOUT ANY WARRANTY; without even the implied warranty of / +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the / +// GNU General Public License for more details. / +// / +// You should have received a copy of the GNU General Public License / +// along with this program; if not, write to the Free Software Foundation, / +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA / +// / +// You can contact us via: support@intellectualsites.com / +//////////////////////////////////////////////////////////////////////////////////////////////////// +package com.intellectualcrafters.plot.commands; + +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.generator.HybridUtils; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotAnalysis; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.util.BlockManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.plotsquared.general.commands.CommandDeclaration; + +@CommandDeclaration( + command = "done", + aliases = {"submit"}, + description = "Mark a plot as done", + permission = "plots.done", + category = CommandCategory.ACTIONS, + requiredType = RequiredType.NONE +) +public class Done extends SubCommand { + + @Override + public boolean onCommand(final PlotPlayer plr, final String[] args) { + final Location loc = plr.getLocation(); + final Plot plot = MainUtil.getPlot(loc); + if (plot == null || !plot.hasOwner()) { + return !sendMessage(plr, C.NOT_IN_PLOT); + } + if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.kick")) { + MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); + return false; + } + if (plot.getSettings().flags.containsKey("done")) { + MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE); + return false; + } + if (MainUtil.runners.containsKey(plot)) { + MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); + return false; + } + MainUtil.runners.put(plot, 1); + HybridUtils.manager.analyzePlot(plot, new RunnableVal() { + @Override + public void run() { + MainUtil.runners.remove(plot); + if (value == null || value.getComplexity() >= Settings.CLEAR_THRESHOLD) { + Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000)); + FlagManager.addPlotFlag(plot, flag); + MainUtil.sendMessage(plr, C.DONE_SUCCESS); + } + else { + MainUtil.sendMessage(plr, C.DONE_INSUFFICIENT_COMPLEXITY); + } + } + }); + return true; + } +} diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 4848da78e..b93581b10 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -127,6 +127,7 @@ public class MainCommand extends CommandManager { createCommand(new Copy()); createCommand(new Chat()); createCommand(new Trim()); + createCommand(new Done()); if (Settings.ENABLE_CLUSTERS) { MainCommand.getInstance().addCommand(new Cluster()); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index 61710e920..bc0331fd1 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -34,6 +34,7 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotInventory; @@ -43,8 +44,10 @@ import com.intellectualcrafters.plot.object.Rating; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan; +import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.bukkit.events.PlotRateEvent; +import com.plotsquared.general.commands.Command; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( @@ -83,7 +86,7 @@ public class Rate extends SubCommand { }); UUID uuid = player.getUUID(); for (Plot p : plots) { - if (p.isBasePlot() && (p.getSettings().ratings == null || !p.getSettings().ratings.containsKey(uuid)) && !p.isAdded(uuid)) { + if ((!Settings.REQUIRE_DONE || p.getSettings().flags.containsKey("done")) && p.isBasePlot() && (p.getSettings().ratings == null || !p.getSettings().ratings.containsKey(uuid)) && !p.isAdded(uuid)) { MainUtil.teleportPlayer(player, player.getLocation(), p); MainUtil.sendMessage(player, C.RATE_THIS); return true; @@ -100,51 +103,61 @@ public class Rate extends SubCommand { } if (!plot.hasOwner()) { sendMessage(player, C.RATING_NOT_OWNED); - return true; + return false; } if (plot.isOwner(player.getUUID())) { sendMessage(player, C.RATING_NOT_YOUR_OWN); - return true; + return false; + } + if (Settings.REQUIRE_DONE && !plot.getSettings().flags.containsKey("done")) { + sendMessage(player, C.RATING_NOT_DONE); + return false; } if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() != 0) { final Runnable run = new Runnable() { @Override public void run() { - if (plot.getSettings().ratings.containsKey(player.getUUID())) { - sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); - return; - } - final MutableInt index = new MutableInt(0); - final MutableInt rating = new MutableInt(0); - String title = Settings.RATING_CATEGORIES.get(0); - PlotInventory inventory = new PlotInventory(player, 1, title) { - public boolean onClick(int i) { - rating.add((i + 1) * Math.pow(10, index.intValue())); - index.increment(); - if (index.intValue() >= Settings.RATING_CATEGORIES.size()) { - close(); - int rV = rating.intValue(); - Rating result = EventUtil.manager.callRating(player, plot, new Rating(rV)); - plot.getSettings().ratings.put(player.getUUID(), result.getAggregate()); - DBFunc.setRating(plot, player.getUUID(), rV); - sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); - sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); + if (plot.getSettings().ratings.containsKey(player.getUUID())) { + sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); + return; + } + final MutableInt index = new MutableInt(0); + final MutableInt rating = new MutableInt(0); + String title = Settings.RATING_CATEGORIES.get(0); + PlotInventory inventory = new PlotInventory(player, 1, title) { + public boolean onClick(int i) { + rating.add((i + 1) * Math.pow(10, index.intValue())); + index.increment(); + if (index.intValue() >= Settings.RATING_CATEGORIES.size()) { + close(); + int rV = rating.intValue(); + Rating result = EventUtil.manager.callRating(player, plot, new Rating(rV)); + plot.getSettings().ratings.put(player.getUUID(), result.getAggregate()); + DBFunc.setRating(plot, player.getUUID(), rV); + sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); + sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); + return false; + } + setTitle(Settings.RATING_CATEGORIES.get(index.intValue())); + if (Permissions.hasPermission(player, "plots.comment")) { + Command command = MainCommand.getInstance().getCommand("comment"); + if (command != null) { + MainUtil.sendMessage(player, C.COMMENT_THIS, command.getUsage().replaceAll("{label}", "plot")); + } + } return false; } - setTitle(Settings.RATING_CATEGORIES.get(index.intValue())); - return false; - } - }; - inventory.setItem(0, new PlotItemStack(35, (short) 12, 0, "0/8")); - inventory.setItem(1, new PlotItemStack(35, (short) 14, 1, "1/8")); - inventory.setItem(2, new PlotItemStack(35, (short) 1, 2, "2/8")); - inventory.setItem(3, new PlotItemStack(35, (short) 4, 3, "3/8")); - inventory.setItem(4, new PlotItemStack(35, (short) 5, 4, "4/8")); - inventory.setItem(5, new PlotItemStack(35, (short) 9, 5, "5/8")); - inventory.setItem(6, new PlotItemStack(35, (short) 11, 6, "6/8")); - inventory.setItem(7, new PlotItemStack(35, (short) 10, 7, "7/8")); - inventory.setItem(8, new PlotItemStack(35, (short) 2, 8, "8/8")); - inventory.openInventory(); + }; + inventory.setItem(0, new PlotItemStack(35, (short) 12, 0, "0/8")); + inventory.setItem(1, new PlotItemStack(35, (short) 14, 1, "1/8")); + inventory.setItem(2, new PlotItemStack(35, (short) 1, 2, "2/8")); + inventory.setItem(3, new PlotItemStack(35, (short) 4, 3, "3/8")); + inventory.setItem(4, new PlotItemStack(35, (short) 5, 4, "4/8")); + inventory.setItem(5, new PlotItemStack(35, (short) 9, 5, "5/8")); + inventory.setItem(6, new PlotItemStack(35, (short) 11, 6, "6/8")); + inventory.setItem(7, new PlotItemStack(35, (short) 10, 7, "7/8")); + inventory.setItem(8, new PlotItemStack(35, (short) 2, 8, "8/8")); + inventory.openInventory(); } }; if (plot.getSettings().ratings == null) { diff --git a/src/main/java/com/intellectualcrafters/plot/config/C.java b/src/main/java/com/intellectualcrafters/plot/config/C.java index 1282fdc6b..3c4bc9a6e 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -170,15 +170,26 @@ public enum C { TOGGLE_DISABLED("$2Disabled setting: %s", "Toggle"), COMMAND_BLOCKED("$2That command is not allowed in this plot", "Blocked Command"), + /* + * Done + */ + DONE_ALREADY_DONE("$2This plot is already marked as done.","Done"), + DONE_INSUFFICIENT_COMPLEXITY("$2This plot is too simple. Please add more detail before using this command.","Done"), + DONE_SUCCESS("$1Successfully marked this plot as done.","Done"), /* * Ratings */ - RATE_THIS("$2Rate this plot!", "Ratings"), RATING_NOT_VALID("$2You need to specify a number between 1 and 10", "Ratings"), RATING_ALREADY_EXISTS("$2You have already rated plot $2%s", "Ratings"), RATING_APPLIED("$4You successfully rated plot $2%s", "Ratings"), RATING_NOT_YOUR_OWN("$2You cannot rate your own plot", "Ratings"), + RATING_NOT_DONE("$2You can only rate finished plots.", "Ratings"), RATING_NOT_OWNED("$2You cannot rate a plot that is not claimed by anyone", "Ratings"), + /* + * Tutorial + */ + RATE_THIS("$2Rate this plot!", "Tutorial"), + COMMENT_THIS("$2Leave some feedback on this plot: %s", "Tutorial"), /* * Economy Stuff */ diff --git a/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 044d53b7c..86c6e836f 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -51,6 +51,7 @@ public class Settings { * Ratings */ public static List RATING_CATEGORIES = null; + public static boolean REQUIRE_DONE = false; /** * PlotMe settings */ diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 69a2e006b..f550c2848 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -657,8 +657,8 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen event.setCancelled(true); return; } + final PlotPlayer pp = BukkitUtil.getPlayer(player); if (!plot.hasOwner()) { - final PlotPlayer pp = BukkitUtil.getPlayer(player); if (Permissions.hasPermission(pp, PERMISSION_ADMIN_DESTROY_UNOWNED)) { return; } @@ -666,8 +666,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen event.setCancelled(true); return; } - final PlotPlayer pp = BukkitUtil.getPlayer(player); - if (!plot.isAdded(pp.getUUID())) { + else if (!plot.isAdded(pp.getUUID())) { final Flag destroy = FlagManager.getPlotFlag(plot, "break"); final Block block = event.getBlock(); if ((destroy != null) && ((HashSet) destroy.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData()))) { @@ -679,6 +678,13 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, PERMISSION_ADMIN_DESTROY_OTHER); event.setCancelled(true); } + else if (FlagManager.isPlotFlagTrue(plot, "done")) { + if (!Permissions.hasPermission(pp, PERMISSION_ADMIN_BUILD_OTHER)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, PERMISSION_ADMIN_BUILD_OTHER); + event.setCancelled(true); + return; + } + } return; } final PlotPlayer pp = BukkitUtil.getPlayer(player); @@ -2071,6 +2077,13 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen return; } } + else if (FlagManager.isPlotFlagTrue(plot, "done")) { + if (!Permissions.hasPermission(pp, PERMISSION_ADMIN_BUILD_OTHER)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, PERMISSION_ADMIN_BUILD_OTHER); + event.setCancelled(true); + return; + } + } if (FlagManager.isPlotFlagTrue(plot, FLAG_DISABLE_PHYSICS)) { Block block = event.getBlockPlaced(); if (block.getType().hasGravity()) { diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java index 925888b8f..bbe1e7608 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java @@ -5,6 +5,7 @@ import java.util.UUID; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -27,7 +28,7 @@ public class WEManager { HashSet regions = new HashSet<>(); UUID uuid = player.getUUID(); for (Plot plot : PS.get().getPlotsInWorld(player.getLocation().getWorld())) { - if (!plot.getMerged(0) && !plot.getMerged(3)) { + if (plot.isBasePlot() && !FlagManager.isPlotFlagTrue(plot, "done")) { if (Settings.WE_ALLOW_HELPER ? plot.isAdded(uuid) : (plot.isOwner(uuid) || plot.getTrusted().contains(uuid))) { Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id); diff --git a/src/main/java/com/plotsquared/general/commands/CommandManager.java b/src/main/java/com/plotsquared/general/commands/CommandManager.java index 3b5a83c7c..2d4f33168 100644 --- a/src/main/java/com/plotsquared/general/commands/CommandManager.java +++ b/src/main/java/com/plotsquared/general/commands/CommandManager.java @@ -36,6 +36,10 @@ public class CommandManager { this.commands.put(alias.toLowerCase(), command); } } + + final public Command getCommand(String command) { + return commands.get(command); + } final public boolean createCommand(final Command command) { try {