mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 12:25:46 +01:00
Various
Closes #906 Add command confirmation for setowner Require confirmation delayed by 1 tick
This commit is contained in:
parent
43b7a7aba8
commit
841809b93d
@ -9,7 +9,7 @@ import java.util.Map;
|
||||
* The {@code TAG_Compound} tag.
|
||||
*/
|
||||
public final class CompoundTag extends Tag {
|
||||
private final Map<String, Tag> value;
|
||||
private Map<String, Tag> 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<String, Tag> value) {
|
||||
return new CompoundTag(getName(), value);
|
||||
if (value == null) {
|
||||
this.value = Collections.unmodifiableMap(new HashMap<String, Tag>());
|
||||
}
|
||||
else {
|
||||
this.value = Collections.unmodifiableMap(value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2007,6 +2007,7 @@ public class PS {
|
||||
|
||||
final Map<String, Object> 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");
|
||||
|
@ -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<Plot> 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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -1954,19 +1954,11 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void setFlags(final Plot plot, final Collection<Flag> 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));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<Flag> 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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<String, CmdInstance> pending = new HashMap<>();
|
||||
|
||||
public static CmdInstance getPending(final PlotPlayer player) {
|
||||
if (player == null) {
|
||||
return pending.get("__CONSOLE__");
|
||||
}
|
||||
return pending.get(player.getName());
|
||||
return player.<CmdInstance>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);
|
||||
}
|
||||
}
|
||||
|
@ -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<String, Tag> flags = schematic.getFlags();
|
||||
if (!flags.isEmpty()) {
|
||||
for (Map.Entry<String, Tag> 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<String, Tag> 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<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone);
|
||||
|
||||
public void getCompoundTag(Plot plot, final RunnableVal<CompoundTag> whenDone) {
|
||||
getCompoundTag(plot.getArea().worldname, plot.getRegions(), whenDone);
|
||||
public void getCompoundTag(final Plot plot, final RunnableVal<CompoundTag> whenDone) {
|
||||
getCompoundTag(plot.getArea().worldname, plot.getRegions(), new RunnableVal<CompoundTag>() {
|
||||
@Override
|
||||
public void run(CompoundTag value) {
|
||||
if (plot.getFlags().size() > 0) {
|
||||
HashMap<String, Tag> flagMap = new HashMap<>();
|
||||
for (Map.Entry<String, Flag> entry : plot.getFlags().entrySet()) {
|
||||
String key = entry.getKey();
|
||||
flagMap.put(key, new StringTag(key, entry.getValue().getValueString()));
|
||||
}
|
||||
CompoundTag tag = new CompoundTag("Flags", flagMap);
|
||||
HashMap<String, Tag> map = new HashMap<String, Tag>(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<String, Tag> flags;
|
||||
|
||||
private final Dimension schematicDimension;
|
||||
private HashSet<PlotItem> items;
|
||||
|
||||
public Schematic(final short[] i, final byte[] b, final Dimension d) {
|
||||
public Schematic(final short[] i, final byte[] b, final Dimension d, Map<String, Tag> flags) {
|
||||
ids = i;
|
||||
datas = b;
|
||||
schematicDimension = d;
|
||||
setFlags(flags);
|
||||
}
|
||||
|
||||
public Map<String, Tag> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void setFlags(Map<String, Tag> flags) {
|
||||
this.flags = flags == null ? new HashMap<String, Tag>() : 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user