Done flag

This commit is contained in:
boy0001 2015-08-14 03:22:32 +10:00
parent b7fe6ea749
commit 393a85c1bc
11 changed files with 180 additions and 42 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<artifactId>PlotSquared</artifactId> <artifactId>PlotSquared</artifactId>
<version>3.0.15</version> <version>3.0.16</version>
<name>PlotSquared</name> <name>PlotSquared</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>

View File

@ -1633,6 +1633,7 @@ public class PS {
for (final String flag : intFlags) { for (final String flag : intFlags) {
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue())); 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("analysis", new FlagValue.IntegerListValue()), true);
FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue()));

View File

@ -25,6 +25,7 @@ import java.util.Set;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; 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() { final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable() {
@Override @Override
public void run() { 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)); MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
} }
}); });

View File

@ -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<PlotAnalysis>() {
@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;
}
}

View File

@ -127,6 +127,7 @@ public class MainCommand extends CommandManager<PlotPlayer> {
createCommand(new Copy()); createCommand(new Copy());
createCommand(new Chat()); createCommand(new Chat());
createCommand(new Trim()); createCommand(new Trim());
createCommand(new Done());
if (Settings.ENABLE_CLUSTERS) { if (Settings.ENABLE_CLUSTERS) {
MainCommand.getInstance().addCommand(new Cluster()); MainCommand.getInstance().addCommand(new Cluster());
} }

View File

@ -34,6 +34,7 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotInventory; 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.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.events.PlotRateEvent; import com.plotsquared.bukkit.events.PlotRateEvent;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration( @CommandDeclaration(
@ -83,7 +86,7 @@ public class Rate extends SubCommand {
}); });
UUID uuid = player.getUUID(); UUID uuid = player.getUUID();
for (Plot p : plots) { 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.teleportPlayer(player, player.getLocation(), p);
MainUtil.sendMessage(player, C.RATE_THIS); MainUtil.sendMessage(player, C.RATE_THIS);
return true; return true;
@ -100,11 +103,15 @@ public class Rate extends SubCommand {
} }
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
sendMessage(player, C.RATING_NOT_OWNED); sendMessage(player, C.RATING_NOT_OWNED);
return true; return false;
} }
if (plot.isOwner(player.getUUID())) { if (plot.isOwner(player.getUUID())) {
sendMessage(player, C.RATING_NOT_YOUR_OWN); 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) { if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() != 0) {
final Runnable run = new Runnable() { final Runnable run = new Runnable() {
@ -132,6 +139,12 @@ public class Rate extends SubCommand {
return false; return false;
} }
setTitle(Settings.RATING_CATEGORIES.get(index.intValue())); setTitle(Settings.RATING_CATEGORIES.get(index.intValue()));
if (Permissions.hasPermission(player, "plots.comment")) {
Command<PlotPlayer> command = MainCommand.getInstance().getCommand("comment");
if (command != null) {
MainUtil.sendMessage(player, C.COMMENT_THIS, command.getUsage().replaceAll("{label}", "plot"));
}
}
return false; return false;
} }
}; };

View File

@ -170,15 +170,26 @@ public enum C {
TOGGLE_DISABLED("$2Disabled setting: %s", "Toggle"), TOGGLE_DISABLED("$2Disabled setting: %s", "Toggle"),
COMMAND_BLOCKED("$2That command is not allowed in this plot", "Blocked Command"), 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 * Ratings
*/ */
RATE_THIS("$2Rate this plot!", "Ratings"),
RATING_NOT_VALID("$2You need to specify a number between 1 and 10", "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_ALREADY_EXISTS("$2You have already rated plot $2%s", "Ratings"),
RATING_APPLIED("$4You successfully 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_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"), 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 * Economy Stuff
*/ */

View File

@ -51,6 +51,7 @@ public class Settings {
* Ratings * Ratings
*/ */
public static List<String> RATING_CATEGORIES = null; public static List<String> RATING_CATEGORIES = null;
public static boolean REQUIRE_DONE = false;
/** /**
* PlotMe settings * PlotMe settings
*/ */

View File

@ -657,8 +657,8 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (!plot.hasOwner()) {
final PlotPlayer pp = BukkitUtil.getPlayer(player); final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (!plot.hasOwner()) {
if (Permissions.hasPermission(pp, PERMISSION_ADMIN_DESTROY_UNOWNED)) { if (Permissions.hasPermission(pp, PERMISSION_ADMIN_DESTROY_UNOWNED)) {
return; return;
} }
@ -666,8 +666,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
final PlotPlayer pp = BukkitUtil.getPlayer(player); else if (!plot.isAdded(pp.getUUID())) {
if (!plot.isAdded(pp.getUUID())) {
final Flag destroy = FlagManager.getPlotFlag(plot, "break"); final Flag destroy = FlagManager.getPlotFlag(plot, "break");
final Block block = event.getBlock(); final Block block = event.getBlock();
if ((destroy != null) && ((HashSet<PlotBlock>) destroy.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData()))) { if ((destroy != null) && ((HashSet<PlotBlock>) 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); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, PERMISSION_ADMIN_DESTROY_OTHER);
event.setCancelled(true); 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; return;
} }
final PlotPlayer pp = BukkitUtil.getPlayer(player); final PlotPlayer pp = BukkitUtil.getPlayer(player);
@ -2071,6 +2077,13 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return; 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)) { if (FlagManager.isPlotFlagTrue(plot, FLAG_DISABLE_PHYSICS)) {
Block block = event.getBlockPlaced(); Block block = event.getBlockPlaced();
if (block.getType().hasGravity()) { if (block.getType().hasGravity()) {

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
@ -27,7 +28,7 @@ public class WEManager {
HashSet<RegionWrapper> regions = new HashSet<>(); HashSet<RegionWrapper> regions = new HashSet<>();
UUID uuid = player.getUUID(); UUID uuid = player.getUUID();
for (Plot plot : PS.get().getPlotsInWorld(player.getLocation().getWorld())) { 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))) { 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 pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id); Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);

View File

@ -37,6 +37,10 @@ public class CommandManager<T extends CommandCaller> {
} }
} }
final public Command<T> getCommand(String command) {
return commands.get(command);
}
final public boolean createCommand(final Command<T> command) { final public boolean createCommand(final Command<T> command) {
try { try {
command.create(); command.create();