diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java index 0709c06c4..03fa21b42 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java @@ -9,7 +9,7 @@ import java.util.Map; * The {@code TAG_Compound} tag. */ public final class CompoundTag extends Tag { - private final Map value; + private Map value; /** * Creates the tag with an empty name. @@ -56,7 +56,13 @@ public final class CompoundTag extends Tag { * @return the new compound tag */ public CompoundTag setValue(final Map value) { - return new CompoundTag(getName(), value); + if (value == null) { + this.value = Collections.unmodifiableMap(new HashMap()); + } + else { + this.value = Collections.unmodifiableMap(value); + } + return this; } /** diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index ecd84d490..697c2f734 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -2007,6 +2007,7 @@ public class PS { final Map options = new HashMap<>(); // Command confirmation + options.put("confirmation.setowner", Settings.CONFIRM_SETOWNER); options.put("confirmation.clear", Settings.CONFIRM_CLEAR); options.put("confirmation.delete", Settings.CONFIRM_DELETE); options.put("confirmation.unlink", Settings.CONFIRM_UNLINK); @@ -2136,6 +2137,7 @@ public class PS { } // Command confirmation + Settings.CONFIRM_SETOWNER = config.getBoolean("confirmation.setowner"); Settings.CONFIRM_CLEAR = config.getBoolean("confirmation.clear"); Settings.CONFIRM_DELETE = config.getBoolean("confirmation.delete"); Settings.CONFIRM_UNLINK = config.getBoolean("confirmation.unlink"); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java index 4a8e9a9ef..07303e630 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java @@ -24,9 +24,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.*; import com.plotsquared.general.commands.CommandDeclaration; import java.util.HashSet; @@ -43,7 +41,7 @@ requiredType = RequiredType.NONE) public class Owner extends SetCommand { @Override - public boolean set(PlotPlayer plr, Plot plot, String value) { + public boolean set(final PlotPlayer plr, final Plot plot, String value) { HashSet plots = plot.getConnectedPlots(); UUID uuid = null; String name = null; @@ -75,7 +73,7 @@ public class Owner extends SetCommand { C.ALREADY_OWNER.send(plr); return false; } - PlotPlayer other = UUIDHandler.getPlayer(uuid); + final PlotPlayer other = UUIDHandler.getPlayer(uuid); if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) { if (other == null) { C.INVALID_PLAYER_OFFLINE.send(plr, value); @@ -88,12 +86,23 @@ public class Owner extends SetCommand { return false; } } - - plot.setOwner(uuid); - plot.setSign(name); - MainUtil.sendMessage(plr, C.SET_OWNER); - if (other != null) { - MainUtil.sendMessage(other, C.NOW_OWNER, plot.getArea() + ";" + plot.getId()); + final String finalName = name; + final UUID finalUUID = uuid; + Runnable run = new Runnable() { + @Override + public void run() { + plot.setOwner(finalUUID); + plot.setSign(finalName); + MainUtil.sendMessage(plr, C.SET_OWNER); + if (other != null) { + MainUtil.sendMessage(other, C.NOW_OWNER, plot.getArea() + ";" + plot.getId()); + } + } + }; + if (Settings.CONFIRM_SETOWNER && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) { + CmdConfirm.addPending(plr, "/plot set owner " + value, run); + } else { + TaskManager.runTask(run); } return true; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 18994df08..1f6fbb05f 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -187,6 +187,7 @@ public class Settings { /** * Command confirmation */ + public static boolean CONFIRM_SETOWNER = true; public static boolean CONFIRM_CLEAR = true; public static boolean CONFIRM_DELETE = true; public static boolean CONFIRM_UNLINK = true; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 770e7b63b..bc9af0cad 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -1954,19 +1954,11 @@ public class SQLManager implements AbstractDB { @Override public void setFlags(final Plot plot, final Collection flags) { - final StringBuilder flag_string = new StringBuilder(); - int i = 0; - for (final Flag flag : flags) { - if (i != 0) { - flag_string.append(","); - } - flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); - i++; - } + final String flag_string = FlagManager.toString(flags); addPlotTask(plot, new UniqueStatement("setFlags") { @Override public void set(final PreparedStatement stmt) throws SQLException { - stmt.setString(1, flag_string.toString()); + stmt.setString(1, flag_string); stmt.setInt(2, getId(plot)); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java index 44da17dfe..d2ed6107c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java @@ -20,11 +20,11 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.flag; +import com.intellectualcrafters.plot.util.StringMan; + import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import com.intellectualcrafters.plot.util.StringMan; - public class Flag implements Cloneable { private AbstractFlag key; private Object value; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index a60a74ef2..79c96d406 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -23,21 +23,11 @@ package com.intellectualcrafters.plot.flag; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotArea; -import com.intellectualcrafters.plot.object.PlotCluster; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotSettings; -import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.Permissions; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * Flag Manager Utility @@ -124,6 +114,19 @@ public class FlagManager { } return false; } + + public static String toString(Collection flags) { + final StringBuilder flag_string = new StringBuilder(); + int i = 0; + for (final Flag flag : flags) { + if (i != 0) { + flag_string.append(","); + } + flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); + i++; + } + return flag_string.toString(); + } public static Flag getSettingFlag(final PlotArea area, final PlotSettings settings, final String id) { Flag flag; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index 7a5a13d64..953a66c15 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -4,20 +4,10 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.util.CmdConfirm; -import com.intellectualcrafters.plot.util.EventUtil; -import com.intellectualcrafters.plot.util.ExpireManager; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.PlotGamemode; -import com.intellectualcrafters.plot.util.PlotWeather; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.*; import com.plotsquared.general.commands.CommandCaller; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; @@ -393,7 +383,6 @@ public abstract class PlotPlayer implements CommandCaller { } String name = getName(); ExpireManager.dates.put(getUUID(), System.currentTimeMillis()); - CmdConfirm.removePending(name); UUIDHandler.getPlayers().remove(name); PS.get().IMP.unregister(this); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/CmdConfirm.java b/Core/src/main/java/com/intellectualcrafters/plot/util/CmdConfirm.java index f491884b3..aad301155 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/CmdConfirm.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/CmdConfirm.java @@ -1,42 +1,27 @@ package com.intellectualcrafters.plot.util; -import java.util.HashMap; - import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.CmdInstance; import com.intellectualcrafters.plot.object.PlotPlayer; public class CmdConfirm { - private static HashMap pending = new HashMap<>(); - public static CmdInstance getPending(final PlotPlayer player) { - if (player == null) { - return pending.get("__CONSOLE__"); - } - return pending.get(player.getName()); + return player.getMeta("cmdConfirm"); } public static void removePending(final PlotPlayer player) { - if (player == null) { - pending.remove("__CONSOLE__"); - } else { - pending.remove(player.getName()); - } - } - - public static void removePending(final String name) { - pending.remove(name); + player.deleteMeta("cmdConfirm"); } public static void addPending(final PlotPlayer player, final String commandStr, final Runnable runnable) { + removePending(player); MainUtil.sendMessage(player, C.REQUIRES_CONFIRM, commandStr); - final CmdInstance cmd = new CmdInstance(runnable); - String name; - if (player == null) { - name = "__CONSOLE__"; - } else { - name = player.getName(); - } - pending.put(name, cmd); + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + final CmdInstance cmd = new CmdInstance(runnable); + player.setMeta("cmdConfirm", cmd); + } + }, 1); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index eb19ba4b8..c0a487b81 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -6,6 +6,7 @@ import com.intellectualcrafters.json.JSONArray; import com.intellectualcrafters.json.JSONException; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.generator.ClassicPlotWorld; import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.object.schematic.PlotItem; @@ -119,6 +120,17 @@ public abstract class SchematicHandler { return; } try { + // Set flags + if (plot.hasOwner()) { + Map flags = schematic.getFlags(); + if (!flags.isEmpty()) { + for (Map.Entry entry : flags.entrySet()) { + plot.setFlag(entry.getKey(), StringTag.class.cast(entry.getValue()).getValue()); + } + + } + } + final Dimension demensions = schematic.getSchematicDimension(); final int WIDTH = demensions.getX(); final int LENGTH = demensions.getZ(); @@ -362,6 +374,12 @@ public abstract class SchematicHandler { final short height = ShortTag.class.cast(tagMap.get("Height")).getValue(); final byte[] block_sml = ByteArrayTag.class.cast(tagMap.get("Blocks")).getValue(); final byte[] data = ByteArrayTag.class.cast(tagMap.get("Data")).getValue(); + final Map flags; + if (tagMap.containsKey("Flags")) { + flags = CompoundTag.class.cast(tagMap.get("Flags")).getValue(); + } else { + flags = null; + } final short[] block = new short[block_sml.length]; for (int i = 0; i < block.length; i++) { @@ -392,7 +410,7 @@ public abstract class SchematicHandler { // Schematic schem = new Schematic(collection, dimension, file); final Dimension dimensions = new Dimension(width, height, length); - final Schematic schem = new Schematic(block, data, dimensions); + final Schematic schem = new Schematic(block, data, dimensions, flags); // Slow try { @@ -632,8 +650,24 @@ public abstract class SchematicHandler { public abstract void getCompoundTag(final String world, Set regions, final RunnableVal whenDone); - public void getCompoundTag(Plot plot, final RunnableVal whenDone) { - getCompoundTag(plot.getArea().worldname, plot.getRegions(), whenDone); + public void getCompoundTag(final Plot plot, final RunnableVal whenDone) { + getCompoundTag(plot.getArea().worldname, plot.getRegions(), new RunnableVal() { + @Override + public void run(CompoundTag value) { + if (plot.getFlags().size() > 0) { + HashMap flagMap = new HashMap<>(); + for (Map.Entry entry : plot.getFlags().entrySet()) { + String key = entry.getKey(); + flagMap.put(key, new StringTag(key, entry.getValue().getValueString())); + } + CompoundTag tag = new CompoundTag("Flags", flagMap); + HashMap map = new HashMap(value.getValue()); + map.put("Flags", tag); + value.setValue(map); + whenDone.run(value); + } + } + }); } /** @@ -675,14 +709,24 @@ public abstract class SchematicHandler { // Lossy but fast private final short[] ids; private final byte[] datas; + private Map flags; private final Dimension schematicDimension; private HashSet items; - public Schematic(final short[] i, final byte[] b, final Dimension d) { + public Schematic(final short[] i, final byte[] b, final Dimension d, Map flags) { ids = i; datas = b; schematicDimension = d; + setFlags(flags); + } + + public Map getFlags() { + return flags; + } + + public void setFlags(Map flags) { + this.flags = flags == null ? new HashMap() : flags; } /** @@ -767,7 +811,7 @@ public abstract class SchematicHandler { } } } - return new Schematic(ids2, datas2, new Dimension(width, height, length)); + return new Schematic(ids2, datas2, new Dimension(width, height, length), null); } public void save(final File file) {