mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 03:03:43 +01:00 
			
		
		
		
	Add plot descriptions & hide reserved flags from /plot info
This commit is contained in:
		@@ -1120,6 +1120,7 @@ public class PS {
 | 
			
		||||
        FlagManager.addFlag(new AbstractFlag("break", new FlagValue.PlotBlockListValue()));
 | 
			
		||||
        FlagManager.addFlag(new AbstractFlag("use", new FlagValue.PlotBlockListValue()));
 | 
			
		||||
        FlagManager.addFlag(new AbstractFlag("blocked-cmds", new FlagValue.StringListValue()));
 | 
			
		||||
        FlagManager.addFlag(new AbstractFlag("ice-met", new FlagValue.BooleanValue()));
 | 
			
		||||
        FlagManager.addFlag(new AbstractFlag("gamemode") {
 | 
			
		||||
 | 
			
		||||
            public String parseValueRaw(final String value) {
 | 
			
		||||
@@ -1173,6 +1174,7 @@ public class PS {
 | 
			
		||||
                return "Flag value must be weather type: 'clear' or 'rain'";
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
        FlagManager.addFlag(new AbstractFlag("description", new FlagValue.StringValue()), true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -25,6 +25,7 @@ import java.util.Collection;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import java.util.regex.Matcher;
 | 
			
		||||
 | 
			
		||||
import com.intellectualcrafters.plot.flag.Flag;
 | 
			
		||||
import org.apache.commons.lang.StringUtils;
 | 
			
		||||
 | 
			
		||||
import com.intellectualcrafters.plot.config.C;
 | 
			
		||||
@@ -199,13 +200,16 @@ public class Info extends SubCommand {
 | 
			
		||||
        final int num = MainUtil.getPlotSelectionIds(id, id2).size();
 | 
			
		||||
        final String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : C.NONE.s();
 | 
			
		||||
        Location top = MainUtil.getPlotTopLoc(world, plot.id);
 | 
			
		||||
        Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1,0,1);
 | 
			
		||||
        Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
 | 
			
		||||
        final String biome = BlockManager.manager.getBiome(bot.add((top.getX() - bot.getX()) / 2, 0, (top.getX() - bot.getX()) / 2));
 | 
			
		||||
        final String trusted = getPlayerList(plot.trusted);
 | 
			
		||||
        final String members = getPlayerList(plot.members);
 | 
			
		||||
        final String denied = getPlayerList(plot.denied);
 | 
			
		||||
 | 
			
		||||
        final String flags = StringMan.replaceFromMap("$2" + (StringUtils.join(FlagManager.getPlotFlags(plot).values(), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot).values(), "$1, $2") : C.NONE.s()), C.replacements);
 | 
			
		||||
        Flag descriptionFlag = FlagManager.getPlotFlag(plot, "description");
 | 
			
		||||
        final String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString();
 | 
			
		||||
 | 
			
		||||
        final String flags = StringMan.replaceFromMap("$2" + (StringUtils.join(FlagManager.getPlotFlags(plot.world, plot.settings, true).values(), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot.world, plot.settings, true).values(), "$1, $2") : C.NONE.s()), C.replacements);
 | 
			
		||||
        final boolean build = (player == null) || plot.isAdded(player.getUUID());
 | 
			
		||||
 | 
			
		||||
        String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());
 | 
			
		||||
@@ -214,6 +218,7 @@ public class Info extends SubCommand {
 | 
			
		||||
        info = info.replaceAll("%id%", id.toString());
 | 
			
		||||
        info = info.replaceAll("%id2%", id2.toString());
 | 
			
		||||
        info = info.replaceAll("%num%", num + "");
 | 
			
		||||
        info = info.replaceAll("%desc%", description);
 | 
			
		||||
        info = info.replaceAll("%biome%", biome);
 | 
			
		||||
        info = info.replaceAll("%owner%", owner);
 | 
			
		||||
        info = info.replaceAll("%members%", members);
 | 
			
		||||
 
 | 
			
		||||
@@ -168,6 +168,30 @@ public class Set extends SubCommand {
 | 
			
		||||
            plot.setHome(blockloc);
 | 
			
		||||
            return MainUtil.sendMessage(plr, C.POSITION_SET);
 | 
			
		||||
        }
 | 
			
		||||
        if (args[0].equalsIgnoreCase("desc")) {
 | 
			
		||||
            if (!Permissions.hasPermission(plr, "plots.set.desc")) {
 | 
			
		||||
                MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.desc");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            if (args.length < 2) {
 | 
			
		||||
                MainUtil.sendMessage(plr, C.MISSING_DESC);
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            final StringBuilder desc = new StringBuilder();
 | 
			
		||||
            for (int i = 1; i < args.length; i++) {
 | 
			
		||||
                desc.append(args[i]).append(" ");
 | 
			
		||||
            }
 | 
			
		||||
            String descValue = desc.substring(0, desc.length() - 1);
 | 
			
		||||
 | 
			
		||||
            Flag flag = new Flag(FlagManager.getFlag("description"), descValue);
 | 
			
		||||
            final boolean result = FlagManager.addPlotFlag(plot, flag);
 | 
			
		||||
            if (!result) {
 | 
			
		||||
                MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED);
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            MainUtil.sendMessage(plr, C.DESC_SET);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (args[0].equalsIgnoreCase("alias")) {
 | 
			
		||||
            if (!Permissions.hasPermission(plr, "plots.set.alias")) {
 | 
			
		||||
                MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.alias");
 | 
			
		||||
 
 | 
			
		||||
@@ -227,6 +227,10 @@ public enum C {
 | 
			
		||||
     * BarAPI
 | 
			
		||||
     */
 | 
			
		||||
    BOSSBAR_CLEARING("$2Clearing plot: $1%id%", "Bar API"),
 | 
			
		||||
 | 
			
		||||
    DESC_SET("$2Plot description set", "Desc"),
 | 
			
		||||
    MISSING_DESC("$2You need to specify a description", "Desc"),
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * Alias
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -20,11 +20,7 @@
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
package com.intellectualcrafters.plot.flag;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
import com.intellectualcrafters.plot.PS;
 | 
			
		||||
import com.intellectualcrafters.plot.config.C;
 | 
			
		||||
@@ -237,16 +233,28 @@ public class FlagManager {
 | 
			
		||||
        return getSettingFlags(plot.world, plot.settings);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static HashMap<String, Flag> getPlotFlags(final String world, final PlotSettings settings, final boolean ignorePluginflags) {
 | 
			
		||||
        HashMap<String, Flag> flags = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
        PlotWorld plotWorld = PS.get().getPlotWorld(world);
 | 
			
		||||
        if (plotWorld != null && plotWorld.DEFAULT_FLAGS.size() != 0) {
 | 
			
		||||
            flags.putAll(plotWorld.DEFAULT_FLAGS);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (ignorePluginflags) {
 | 
			
		||||
            for (final Map.Entry<String, Flag> flag : settings.flags.entrySet()) {
 | 
			
		||||
                if (isReserved(flag.getValue().getAbstractFlag().getKey())) continue;
 | 
			
		||||
                flags.put(flag.getKey(), flag.getValue());
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            flags.putAll(settings.flags);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return flags;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static HashMap<String, Flag> getSettingFlags(final String world, final PlotSettings settings) {
 | 
			
		||||
        PlotWorld plotworld = PS.get().getPlotWorld(world);
 | 
			
		||||
        if (plotworld == null || plotworld.DEFAULT_FLAGS.size() == 0) {
 | 
			
		||||
            return settings.flags;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            HashMap<String, Flag> map = (HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone();
 | 
			
		||||
            map.putAll(settings.flags);
 | 
			
		||||
            return map;
 | 
			
		||||
        }
 | 
			
		||||
        return getPlotFlags(world, settings, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean removePlotFlag(final Plot plot, final String id) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user