mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 03:03:43 +01:00 
			
		
		
		
	Done flag
This commit is contained in:
		@@ -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()));
 | 
			
		||||
 
 | 
			
		||||
@@ -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));
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -127,6 +127,7 @@ public class MainCommand extends CommandManager<PlotPlayer> {
 | 
			
		||||
        createCommand(new Copy());
 | 
			
		||||
        createCommand(new Chat());
 | 
			
		||||
        createCommand(new Trim());
 | 
			
		||||
        createCommand(new Done());
 | 
			
		||||
        if (Settings.ENABLE_CLUSTERS) {
 | 
			
		||||
            MainCommand.getInstance().addCommand(new Cluster());
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -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<PlotPlayer> 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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -51,6 +51,7 @@ public class Settings {
 | 
			
		||||
     * Ratings
 | 
			
		||||
     */
 | 
			
		||||
    public static List<String> RATING_CATEGORIES = null;
 | 
			
		||||
    public static boolean REQUIRE_DONE = false;
 | 
			
		||||
    /**
 | 
			
		||||
     * PlotMe settings
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user