mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 23:26:45 +01:00
Remove FlagManager
This commit is contained in:
parent
baa52580cc
commit
5fb8530d0e
@ -6,8 +6,9 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
|
||||
import com.github.intellectualsites.plotsquared.plot.listener.WEManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer;
|
||||
@ -219,10 +220,10 @@ import java.util.concurrent.CompletableFuture;
|
||||
return false;
|
||||
}
|
||||
String flag = args[1];
|
||||
final PlotFlag<?, ?> flagInstance = GlobalFlagContainer.getInstance().getFlagFromString(flag);
|
||||
if (flagInstance != null) {
|
||||
for (Plot plot : PlotSquared.get().getBasePlots()) {
|
||||
Flag<?> flag1 = FlagManager.getFlag(flag);
|
||||
if (plot.getFlag(flag1).isPresent()) {
|
||||
plot.removeFlag(flag1);
|
||||
plot.removeFlag(flagInstance);
|
||||
}
|
||||
}
|
||||
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
|
||||
|
@ -8,6 +8,7 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.InternalFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.types.IntegerFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.types.ListFlag;
|
||||
@ -133,7 +134,7 @@ import java.util.Map;
|
||||
@NotNull final String arg) {
|
||||
if (arg != null && arg.length() > 0) {
|
||||
final PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(arg);
|
||||
if (flag == null) {
|
||||
if (flag instanceof InternalFlag || flag == null) {
|
||||
boolean suggested = false;
|
||||
try {
|
||||
final StringComparison<PlotFlag<?, ?>> stringComparison =
|
||||
|
@ -2,6 +2,8 @@ package com.github.intellectualsites.plotsquared.plot.commands;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotInventory;
|
||||
@ -38,10 +40,10 @@ public class Music extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
if (item.getType() == ItemTypes.BEDROCK) {
|
||||
plot.removeFlag(Flags.MUSIC);
|
||||
plot.removeFlag(MusicFlag.class);
|
||||
Captions.FLAG_REMOVED.send(player);
|
||||
} else if (item.name.toLowerCase(Locale.ENGLISH).contains("disc")) {
|
||||
plot.setFlag(Flags.MUSIC, item.getType().getId());
|
||||
plot.setFlag(GlobalFlagContainer.getInstance().getFlag(MusicFlag.class).createFlagInstance(item.getType()));
|
||||
Captions.FLAG_ADDED.send(player);
|
||||
} else {
|
||||
Captions.FLAG_NOT_ADDED.send(player);
|
||||
|
@ -4,8 +4,6 @@ import com.github.intellectualsites.plotsquared.commands.Command;
|
||||
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
@ -19,15 +17,13 @@ import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@CommandDeclaration(command = "set", description = "Set a plot value", aliases = {
|
||||
"s"}, usage = "/plot set <biome|alias|home|flag> <value...>", permission = "plots.set", category = CommandCategory.APPEARANCE, requiredType = RequiredType.NONE)
|
||||
public class Set extends SubCommand {
|
||||
|
||||
public static final String[] values = new String[] {"biome", "alias", "home", "flag"};
|
||||
public static final String[] aliases = new String[] {"b", "w", "wf", "f", "a", "h", "fl"};
|
||||
public static final String[] values = new String[] {"biome", "alias", "home"};
|
||||
public static final String[] aliases = new String[] {"b", "w", "wf", "a", "h"};
|
||||
|
||||
private final SetCommand component;
|
||||
|
||||
@ -83,7 +79,7 @@ public class Set extends SubCommand {
|
||||
|
||||
public boolean noArgs(PlotPlayer player) {
|
||||
ArrayList<String> newValues =
|
||||
new ArrayList<>(Arrays.asList("biome", "alias", "home", "flag"));
|
||||
new ArrayList<>(Arrays.asList("biome", "alias", "home"));
|
||||
Plot plot = player.getCurrentPlot();
|
||||
if (plot != null) {
|
||||
newValues.addAll(Arrays.asList(plot.getManager().getPlotComponents(plot.getId())));
|
||||
@ -118,17 +114,6 @@ public class Set extends SubCommand {
|
||||
if (components.contains(args[0].toLowerCase())) {
|
||||
return this.component.onCommand(player, Arrays.copyOfRange(args, 0, args.length));
|
||||
}
|
||||
// flag
|
||||
Flag<?> flag = FlagManager.getFlag(args[0].toLowerCase());
|
||||
if (Flags.getFlags().contains(flag)) {
|
||||
String a = "";
|
||||
if (args.length > 1) {
|
||||
a = IntStream.range(1, args.length).mapToObj(x -> " " + args[x])
|
||||
.collect(Collectors.joining());
|
||||
}
|
||||
MainCommand.onCommand(player, ("flag set " + args[0] + a).split(" "));
|
||||
return true;
|
||||
}
|
||||
return noArgs(player);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.database;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotCluster;
|
||||
@ -11,6 +11,7 @@ import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -303,7 +304,7 @@ public class DBFunc {
|
||||
DBFunc.dbManager.setMerged(plot, merged);
|
||||
}
|
||||
|
||||
public static void setFlags(Plot plot, HashMap<Flag<?>, Object> flags) {
|
||||
public static void setFlags(Plot plot, Collection<PlotFlag<?, ?>> flags) {
|
||||
if (plot.temp == -1 || dbManager == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,296 +0,0 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.flag;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.FlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.InternalFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotSettings;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Flag Manager Utility.
|
||||
*/
|
||||
public class FlagManager {
|
||||
|
||||
public static <V> Optional<V> getPlotFlag(Plot plot, Flag<V> key) {
|
||||
V value = FlagManager.getPlotFlagRaw(plot, key);
|
||||
return Optional.ofNullable(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve a flag so that it cannot be set by players.
|
||||
*
|
||||
* @param flag the flag to reserve
|
||||
* @return false if the flag was already reserved, otherwise true
|
||||
*/
|
||||
public static boolean reserveFlag(Flag<?> flag) {
|
||||
if (flag.isReserved()) {
|
||||
return false;
|
||||
}
|
||||
flag.reserve();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a flag is reserved.
|
||||
*
|
||||
* @param flag the flag to check
|
||||
* @return true if the flag is reserved, false otherwise
|
||||
*/
|
||||
public static boolean isReserved(Flag<?> flag) {
|
||||
return flag.isReserved();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an immutable set of reserved flags.
|
||||
*
|
||||
* @return a set of reserved flags
|
||||
*/
|
||||
public static Set<Flag<?>> getReservedFlags() {
|
||||
ImmutableSet.Builder<Flag<?>> reserved = ImmutableSet.builder();
|
||||
for (Flag flag : Flags.getFlags()) {
|
||||
if (flag.isReserved()) {
|
||||
reserved.add(flag);
|
||||
}
|
||||
}
|
||||
return reserved.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unreserve a flag.
|
||||
*
|
||||
* @param flag the flag to unreserve
|
||||
* @return true if the flag was unreserved
|
||||
*/
|
||||
public static boolean unreserveFlag(Flag<?> flag) {
|
||||
if (flag.isReserved()) {
|
||||
flag.unreserve();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String toString(HashMap<Flag<?>, Object> flags) {
|
||||
StringBuilder flag_string = new StringBuilder();
|
||||
int i = 0;
|
||||
for (Map.Entry<Flag<?>, Object> entry : flags.entrySet()) {
|
||||
try {
|
||||
Flag flag = entry.getKey();
|
||||
if (i != 0) {
|
||||
flag_string.append(',');
|
||||
}
|
||||
flag_string.append(
|
||||
flag.getName() + ':' + flag.valueToString(entry.getValue()).replaceAll(":", "¯")
|
||||
.replaceAll(",", "´"));
|
||||
i++;
|
||||
} catch (Exception e) {
|
||||
PlotSquared
|
||||
.debug("Failed to parse flag: " + entry.getKey() + "->" + entry.getValue());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return flag_string.toString();
|
||||
}
|
||||
|
||||
public static <V> V getSettingFlag(PlotArea area, PlotSettings settings, Flag<V> id) {
|
||||
Object value;
|
||||
if (settings.flags.isEmpty() || ((value = settings.flags.get(id)) == null)) {
|
||||
if (area == null || area.DEFAULT_FLAGS.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return (V) area.DEFAULT_FLAGS.get(id);
|
||||
}
|
||||
return (V) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw flag<br>
|
||||
* - Faster
|
||||
* - You should not modify the flag
|
||||
*
|
||||
* @param plot
|
||||
* @param flag
|
||||
* @return
|
||||
*/
|
||||
public static <V> V getPlotFlagRaw(Plot plot, Flag<V> flag) {
|
||||
if (plot.owner == null) {
|
||||
return null;
|
||||
}
|
||||
return getSettingFlag(plot.getArea(), plot.getSettings(), flag);
|
||||
}
|
||||
|
||||
public static <V> boolean addPlotFlag(Plot origin, PlotFlag<V, ?> flag, Object value) {
|
||||
// TODO: Implement this
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a flag to a plot.
|
||||
*
|
||||
* @param origin
|
||||
* @param flag
|
||||
* @param value
|
||||
*/
|
||||
public static <V> boolean addPlotFlag(Plot origin, Flag<V> flag, Object value) {
|
||||
boolean result = EventUtil.manager.callFlagAdd(flag, origin);
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
for (Plot plot : origin.getConnectedPlots()) {
|
||||
plot.getFlags().put(flag, value);
|
||||
plot.reEnter(); //TODO fix this so FlagTest will run during compile
|
||||
DBFunc.setFlags(plot, plot.getFlags());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the {@link Flag}s and their values for the specified plot.
|
||||
*
|
||||
* @param plot the plot
|
||||
* @return a map of the flags and values for the plot, returns an empty map for unowned plots
|
||||
*/
|
||||
public static Map<Flag<?>, Object> getPlotFlags(Plot plot) {
|
||||
if (!plot.hasOwner()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return getSettingFlags(plot.getArea(), plot.getSettings());
|
||||
}
|
||||
|
||||
public static Collection<PlotFlag<?, ?>> getPlotFlags(final Plot plot, final boolean ignorePluginFlags) {
|
||||
final Map<Class<?>, PlotFlag<?, ?>> flags = new HashMap<>();
|
||||
if (plot.getArea() != null && !plot.getArea().getFlagContainer().getFlagMap().isEmpty()) {
|
||||
final Map<Class<?>, PlotFlag<?, ?>> flagMap = plot.getArea().getFlagContainer().getFlagMap();
|
||||
flags.putAll(flagMap);
|
||||
}
|
||||
final Map<Class<?>, PlotFlag<?, ?>> flagMap = plot.getFlagContainer().getFlagMap();
|
||||
if (ignorePluginFlags) {
|
||||
for (final PlotFlag<?, ?> flag : flagMap.values()) {
|
||||
if (flag instanceof InternalFlag) {
|
||||
continue;
|
||||
}
|
||||
flags.put(flag.getClass(), flag);
|
||||
}
|
||||
} else {
|
||||
flags.putAll(flagMap);
|
||||
}
|
||||
return flagMap.values();
|
||||
}
|
||||
|
||||
public static Map<Flag<?>, Object> getSettingFlags(PlotArea area, PlotSettings settings) {
|
||||
return getPlotFlags(area, settings, false);
|
||||
}
|
||||
|
||||
public static boolean removePlotFlag(Plot origin, PlotFlag<?, ?> flag) {
|
||||
// TODO: Implement
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a flag from a certain plot.
|
||||
*
|
||||
* @param origin the plot to remove the flag from
|
||||
* @param id the flag to remove
|
||||
* @return true if the plot contained the flag and was removed successfully
|
||||
*/
|
||||
public static boolean removePlotFlag(Plot origin, Flag<?> id) {
|
||||
for (Plot plot : origin.getConnectedPlots()) {
|
||||
Object value = plot.getFlags().remove(id);
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
if (plot == origin) {
|
||||
boolean result = EventUtil.manager.callFlagRemove(id, plot, value);
|
||||
if (!result) {
|
||||
plot.getFlags().put(id, value);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
plot.reEnter();
|
||||
DBFunc.setFlags(plot, plot.getFlags());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void setPlotFlags(Plot origin, FlagContainer flagContainer) {
|
||||
for (Plot plot : origin.getConnectedPlots()) {
|
||||
if (flags != null && !flags.isEmpty()) {
|
||||
plot.getFlags().clear();
|
||||
for (Map.Entry<Flag<?>, Object> flag : flags.entrySet()) {
|
||||
plot.getFlags().put(flag.getKey(), flag.getValue());
|
||||
}
|
||||
} else if (plot.getFlags().isEmpty()) {
|
||||
return;
|
||||
} else {
|
||||
plot.getFlags().clear();
|
||||
}
|
||||
plot.reEnter();
|
||||
DBFunc.setFlags(plot, plot.getFlags());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of registered {@link Flag} objects based on player permissions.
|
||||
*
|
||||
* @param player the player
|
||||
* @return a list of flags the specified player can use
|
||||
*/
|
||||
public static List<Flag> getFlags(PlotPlayer player) {
|
||||
List<Flag> returnFlags = Flags.getFlags().stream().filter(flag -> Permissions
|
||||
.hasPermission(player, "plots.set.flag." + flag.getName().toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
return returnFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link Flag} specified by the specified {@code String}.
|
||||
*
|
||||
* @param string the flag name
|
||||
* @return the {@code Flag} object defined by the {@code String}
|
||||
*/
|
||||
public static Flag<?> getFlag(String string) {
|
||||
return Flags.getFlag(string);
|
||||
}
|
||||
|
||||
public static Flag<?> getFlag(String string, boolean ignoreReserved) {
|
||||
Flag<?> flag = Flags.getFlag(string);
|
||||
if (!ignoreReserved && flag != null && flag.isReserved()) {
|
||||
return null;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
public static Map<Flag<?>, Object> parseFlags(List<String> flagStrings) {
|
||||
HashMap<Flag<?>, Object> map = new HashMap<>();
|
||||
|
||||
for (String key : flagStrings) {
|
||||
String[] split;
|
||||
if (key.contains(";")) {
|
||||
split = key.split(";");
|
||||
} else {
|
||||
split = key.split(":");
|
||||
}
|
||||
Flag<?> flag = getOrCreateFlag(split[0]);
|
||||
Object value = flag.parseValue(split[1]);
|
||||
map.put(flag, value);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
@ -72,11 +72,16 @@ import java.util.Map;
|
||||
*
|
||||
* @param flag Flag to remove
|
||||
*/
|
||||
public <V, T extends PlotFlag<V, ?>> void removeFlag(final T flag) {
|
||||
this.flagMap.remove(flag.getClass());
|
||||
public <V, T extends PlotFlag<V, ?>> V removeFlag(final T flag) {
|
||||
final Object value = this.flagMap.remove(flag.getClass());
|
||||
if (this.plotFlagUpdateHandler != null) {
|
||||
this.plotFlagUpdateHandler.handle(flag, PlotFlagUpdateType.FLAG_REMOVED);
|
||||
}
|
||||
if (value == null) {
|
||||
return null;
|
||||
} else {
|
||||
return (V) flag;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,4 +100,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
protected abstract F flagOf(@NotNull T value);
|
||||
|
||||
public final F createFlagInstance(@NotNull final T value) {
|
||||
return flagOf(Preconditions.checkNotNull(value));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyExitFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FarewellFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag;
|
||||
@ -36,6 +37,7 @@ import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -57,7 +59,8 @@ public class PlotListener {
|
||||
player.setMeta(PlotPlayer.META_LAST_PLOT, plot);
|
||||
EventUtil.manager.callEntry(player, plot);
|
||||
if (plot.hasOwner()) {
|
||||
Map<Flag<?>, Object> flags = FlagManager.getPlotFlags(plot);
|
||||
|
||||
final Collection<PlotFlag<?, ?>> plotFlags = plot.getApplicableFlags(false);
|
||||
|
||||
boolean titles;
|
||||
if (!plot.getArea().DEFAULT_FLAGS.isEmpty()) {
|
||||
|
@ -5,10 +5,10 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.FlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.InternalFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.KeepFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.SquarePlotWorld;
|
||||
@ -39,6 +39,7 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -155,7 +156,7 @@ public class Plot {
|
||||
/**
|
||||
* Plot flag container
|
||||
*/
|
||||
@Getter private FlagContainer flagContainer;
|
||||
@Getter(AccessLevel.PROTECTED) private FlagContainer flagContainer;
|
||||
|
||||
/**
|
||||
* Constructor for a new plot.
|
||||
@ -1092,17 +1093,29 @@ public class Plot {
|
||||
* Sets a flag for this plot
|
||||
*
|
||||
* @param flag Flag to set
|
||||
* @param value Flag value
|
||||
*/
|
||||
public <V> boolean setFlag(PlotFlag<V, ?> flag, V value) {
|
||||
public <V> boolean setFlag(PlotFlag<V, ?> flag) {
|
||||
if (flag instanceof KeepFlag && ExpireManager.IMP != null) {
|
||||
ExpireManager.IMP.updateExpired(this);
|
||||
}
|
||||
return FlagManager.addPlotFlag(this, flag, value);
|
||||
if (!EventUtil.manager.callFlagAdd(flag, origin)) {
|
||||
return false;
|
||||
}
|
||||
for (final Plot plot : this.getConnectedPlots()) {
|
||||
plot.getFlagContainer().addFlag(flag);
|
||||
plot.reEnter();
|
||||
DBFunc.setFlags(plot, plot.getFlagContainer().getFlagMap().values());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public <V> boolean setFlag(Class<? extends PlotFlag<V, ?>> flag, V value) {
|
||||
return this.setFlag(GlobalFlagContainer.getInstance().getFlag(flag), value);
|
||||
public <V> boolean setFlag(Class<? extends PlotFlag<V, ?>> flag, String value) {
|
||||
try {
|
||||
this.setFlag(GlobalFlagContainer.getInstance().getFlag(flag).parse(value));
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1111,8 +1124,31 @@ public class Plot {
|
||||
* @param flag the flag to remove
|
||||
* @return success
|
||||
*/
|
||||
public boolean removeFlag(Class<? extends PlotFlag> flag) {
|
||||
return FlagManager.removePlotFlag(this, flag);
|
||||
public boolean removeFlag(Class<? extends PlotFlag<?, ?>> flag) {
|
||||
return this.removeFlag(getFlagContainer().queryLocal(flag));
|
||||
}
|
||||
|
||||
public Collection<PlotFlag<?, ?>> getApplicableFlags(final boolean ignorePluginFlags) {
|
||||
if (!hasOwner()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final Map<Class<?>, PlotFlag<?, ?>> flags = new HashMap<>();
|
||||
if (getArea() != null && !getArea().getFlagContainer().getFlagMap().isEmpty()) {
|
||||
final Map<Class<?>, PlotFlag<?, ?>> flagMap = plot.getArea().getFlagContainer().getFlagMap();
|
||||
flags.putAll(flagMap);
|
||||
}
|
||||
final Map<Class<?>, PlotFlag<?, ?>> flagMap = getFlagContainer().getFlagMap();
|
||||
if (ignorePluginFlags) {
|
||||
for (final PlotFlag<?, ?> flag : flagMap.values()) {
|
||||
if (flag instanceof InternalFlag) {
|
||||
continue;
|
||||
}
|
||||
flags.put(flag.getClass(), flag);
|
||||
}
|
||||
} else {
|
||||
flags.putAll(flagMap);
|
||||
}
|
||||
return flagMap.values();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1122,7 +1158,24 @@ public class Plot {
|
||||
* @return success
|
||||
*/
|
||||
public boolean removeFlag(PlotFlag<?, ?> flag) {
|
||||
return this.removeFlag(flag.getClass());
|
||||
boolean removed = false;
|
||||
for (final Plot plot : origin.getConnectedPlots()) {
|
||||
final Object value = plot.getFlagContainer().removeFlag(flag);
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
if (plot == origin) {
|
||||
boolean result = EventUtil.manager.callFlagRemove(flag, plot, value);
|
||||
if (!result) {
|
||||
plot.getFlagContainer().addFlag(flag);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
plot.reEnter();
|
||||
DBFunc.setFlags(plot, plot.getFlagContainer().getFlagMap().values());
|
||||
removed = true;
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2020,15 +2073,6 @@ public class Plot {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a flag for this plot.
|
||||
*
|
||||
* @param flags
|
||||
*/
|
||||
public void setFlags(HashMap<Flag<?>, Object> flags) {
|
||||
FlagManager.setPlotFlags(this, flags);
|
||||
}
|
||||
|
||||
public void setFlagContainer(final FlagContainer flagContainer) {
|
||||
this.flagContainer = flagContainer;
|
||||
}
|
||||
@ -3187,8 +3231,4 @@ public class Plot {
|
||||
return FlagContainer.<T, V>castUnsafe(flagInstance).getValue();
|
||||
}
|
||||
|
||||
public boolean setFlag(PlotFlag<?, ?> plotFlag) {
|
||||
flagContainer.addFlag(plotFlag);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,15 @@ package com.github.intellectualsites.plotsquared.plot.object;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.FlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.GridPlotWorld;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator;
|
||||
@ -318,7 +321,7 @@ public abstract class PlotArea {
|
||||
}
|
||||
}
|
||||
try {
|
||||
this.DEFAULT_FLAGS = FlagManager.parseFlags(flags);
|
||||
this.DEFAULT_FLAGS = parseFlags(flags);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
PlotSquared.debug("&cInvalid default flags for " + this.worldname + ": " + StringMan
|
||||
@ -954,4 +957,26 @@ public abstract class PlotArea {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Collection<PlotFlag<?, ?>> parseFlags(List<String> flagStrings) {
|
||||
final Collection<PlotFlag<?, ?>> flags = new ArrayList<>();
|
||||
for (final String key : flagStrings) {
|
||||
final String[] split;
|
||||
if (key.contains(";")) {
|
||||
split = key.split(";");
|
||||
} else {
|
||||
split = key.split(":");
|
||||
}
|
||||
final PlotFlag<?, ?> flagInstance = GlobalFlagContainer.getInstance().getFlagFromString(split[0]);
|
||||
if (flagInstance != null) {
|
||||
try {
|
||||
flags.add(flagInstance.parse(split[1]));
|
||||
} catch (final FlagParseException e) {
|
||||
Captions.FLAG_PARSE_EXCEPTION
|
||||
.send(ConsolePlayer.getConsole(), e.getFlag().getName(), e.getValue(), e.getErrorMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DeviceInteractFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscPlaceFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MobPlaceFlag;
|
||||
@ -52,9 +52,9 @@ public abstract class EventUtil {
|
||||
|
||||
public abstract boolean callDelete(Plot plot);
|
||||
|
||||
public abstract boolean callFlagAdd(Flag flag, Plot plot);
|
||||
public abstract boolean callFlagAdd(PlotFlag<?, ?> flag, Plot plot);
|
||||
|
||||
public abstract boolean callFlagRemove(Flag<?> flag, Plot plot, Object value);
|
||||
public abstract boolean callFlagRemove(PlotFlag<?, ?> flag, Plot plot, Object value);
|
||||
|
||||
public abstract boolean callMerge(Plot plot, int dir, int max);
|
||||
|
||||
|
@ -8,7 +8,6 @@ import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ServerPlotFlag;
|
||||
@ -784,7 +783,7 @@ public class MainUtil {
|
||||
}
|
||||
|
||||
StringBuilder flags = new StringBuilder();
|
||||
Collection<PlotFlag<?, ?>> flagCollection = FlagManager.getPlotFlags(plot, true);
|
||||
Collection<PlotFlag<?, ?>> flagCollection = plot.getApplicableFlags(true);
|
||||
if (flagCollection.isEmpty()) {
|
||||
flags.append(Captions.NONE.getTranslated());
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user