PlotSquared/src/main/java/com/intellectualcrafters/plot/util/CmdConfirm.java
2015-07-16 16:16:16 +02:00

45 lines
1.2 KiB
Java

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(PlotPlayer player) {
if (player == null) {
return pending.get("__CONSOLE__");
}
return pending.get(player.getName());
}
public static void removePending(PlotPlayer player) {
if (player == null) {
pending.remove("__CONSOLE__");
}
else {
pending.remove(player.getName());
}
}
public static void removePending(String name) {
pending.remove(name);
}
public static void addPending(PlotPlayer player, String commandStr, Runnable runnable) {
MainUtil.sendMessage(player, C.REQUIRES_CONFIRM, commandStr);
CmdInstance cmd = new CmdInstance(runnable);
String name;
if (player == null) {
name = "__CONSOLE__";
}
else {
name = player.getName();
}
pending.put(name, cmd);
}
}