Add password protected warps

This commit is contained in:
Trent Hensler 2017-12-19 02:10:52 -08:00
parent 18749dcb06
commit ce132ed033
5 changed files with 41 additions and 4 deletions

View File

@ -23,6 +23,12 @@ public interface Faction extends EconomyParticipator {
public boolean isWarp(String name); public boolean isWarp(String name);
public boolean hasWarpPassword(String warp);
public boolean isWarpPassword(String warp, String password);
public void setWarpPassword(String warp, String password);
public boolean removeWarp(String name); public boolean removeWarp(String name);
public void clearWarps(); public void clearWarps();

View File

@ -22,6 +22,7 @@ public class CmdFWarp extends FCommand {
this.aliases.add("warp"); this.aliases.add("warp");
this.aliases.add("warps"); this.aliases.add("warps");
this.optionalArgs.put("warpname", "warpname"); this.optionalArgs.put("warpname", "warpname");
this.optionalArgs.put("password", "password");
this.permission = Permission.WARP.node; this.permission = Permission.WARP.node;
this.senderMustBeMember = true; this.senderMustBeMember = true;
@ -38,11 +39,21 @@ public class CmdFWarp extends FCommand {
msg.then(s + " ").tooltip(TL.COMMAND_FWARP_CLICKTOWARP.toString()).command("/" + Conf.baseCommandAliases.get(0) + " warp " + s).color(ChatColor.WHITE); msg.then(s + " ").tooltip(TL.COMMAND_FWARP_CLICKTOWARP.toString()).command("/" + Conf.baseCommandAliases.get(0) + " warp " + s).color(ChatColor.WHITE);
} }
sendFancyMessage(msg); sendFancyMessage(msg);
} else if (args.size() > 1) { } else if (args.size() > 2) {
fme.msg(TL.COMMAND_FWARP_COMMANDFORMAT); fme.msg(TL.COMMAND_FWARP_COMMANDFORMAT);
} else { } else {
final String warpName = argAsString(0); final String warpName = argAsString(0);
final String passwordAttempt = argAsString(1);
if (myFaction.isWarp(argAsString(0))) { if (myFaction.isWarp(argAsString(0))) {
// Check if requires password and if so, check if valid. CASE SENSITIVE
if (myFaction.hasWarpPassword(warpName) && !myFaction.isWarpPassword(warpName, passwordAttempt)) {
fme.msg(TL.COMMAND_FWARP_INVALID_PASSWORD);
return;
}
// Check transaction AFTER password check.
if (!transact(fme)) { if (!transact(fme)) {
return; return;
} }

View File

@ -14,6 +14,7 @@ public class CmdSetFWarp extends FCommand {
this.aliases.add("setwarp"); this.aliases.add("setwarp");
this.aliases.add("sw"); this.aliases.add("sw");
this.requiredArgs.add("warp name"); this.requiredArgs.add("warp name");
this.optionalArgs.put("password", "password");
this.senderMustBeMember = true; this.senderMustBeMember = true;
this.senderMustBeModerator = true; this.senderMustBeModerator = true;
this.senderMustBePlayer = true; this.senderMustBePlayer = true;
@ -38,9 +39,14 @@ public class CmdSetFWarp extends FCommand {
} }
String warp = argAsString(0); String warp = argAsString(0);
String password = argAsString(1);
LazyLocation loc = new LazyLocation(fme.getPlayer().getLocation()); LazyLocation loc = new LazyLocation(fme.getPlayer().getLocation());
myFaction.setWarp(warp, loc); myFaction.setWarp(warp, loc);
fme.msg(TL.COMMAND_SETFWARP_SET, warp); if (password != null) {
myFaction.setWarpPassword(warp, password);
}
fme.msg(TL.COMMAND_SETFWARP_SET, warp, password != null ? password : "");
} }
private boolean transact(FPlayer player) { private boolean transact(FPlayer player) {

View File

@ -41,6 +41,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
protected Set<String> invites = new HashSet<String>(); protected Set<String> invites = new HashSet<String>();
protected HashMap<String, List<String>> announcements = new HashMap<String, List<String>>(); protected HashMap<String, List<String>> announcements = new HashMap<String, List<String>>();
protected ConcurrentHashMap<String, LazyLocation> warps = new ConcurrentHashMap<String, LazyLocation>(); protected ConcurrentHashMap<String, LazyLocation> warps = new ConcurrentHashMap<String, LazyLocation>();
protected ConcurrentHashMap<String, String> warpPasswords = new ConcurrentHashMap<String, String>();
private long lastDeath; private long lastDeath;
protected int maxVaults; protected int maxVaults;
@ -92,6 +93,18 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
return warps.remove(name) != null; return warps.remove(name) != null;
} }
public boolean isWarpPassword(String warp, String password) {
return hasWarpPassword(warp) && warpPasswords.get(warp.toLowerCase()).equals(password);
}
public boolean hasWarpPassword(String warp) {
return warpPasswords.containsKey(warp.toLowerCase());
}
public void setWarpPassword(String warp, String password) {
warpPasswords.put(warp.toLowerCase(), password);
}
public void clearWarps() { public void clearWarps() {
warps.clear(); warps.clear();
} }

View File

@ -177,13 +177,14 @@ public enum TL {
COMMAND_DISBAND_DESCRIPTION("Disband a faction"), COMMAND_DISBAND_DESCRIPTION("Disband a faction"),
COMMAND_FWARP_CLICKTOWARP("Click to warp!"), COMMAND_FWARP_CLICKTOWARP("Click to warp!"),
COMMAND_FWARP_COMMANDFORMAT("<i>/f warp <warpname>"), COMMAND_FWARP_COMMANDFORMAT("<i>/f warp <warpname> [password]"),
COMMAND_FWARP_WARPED("<i>Warped to <a>%1$s"), COMMAND_FWARP_WARPED("<i>Warped to <a>%1$s"),
COMMAND_FWARP_INVALID("<i>Couldn't find warp <a>%1$s"), COMMAND_FWARP_INVALID("<i>Couldn't find warp <a>%1$s"),
COMMAND_FWARP_TOWARP("to warp"), COMMAND_FWARP_TOWARP("to warp"),
COMMAND_FWARP_FORWARPING("for warping"), COMMAND_FWARP_FORWARPING("for warping"),
COMMAND_FWARP_WARPS("Warps: "), COMMAND_FWARP_WARPS("Warps: "),
COMMAND_FWARP_DESCRIPTION("Teleport to a faction warp"), COMMAND_FWARP_DESCRIPTION("Teleport to a faction warp"),
COMMAND_FWARP_INVALID_PASSWORD("&4Invalid password!"),
COMMAND_HELP_404("<b>This page does not exist"), COMMAND_HELP_404("<b>This page does not exist"),
COMMAND_HELP_NEXTCREATE("<i>Learn how to create a faction on the next page."), COMMAND_HELP_NEXTCREATE("<i>Learn how to create a faction on the next page."),
@ -421,7 +422,7 @@ public enum TL {
COMMAND_SETFWARP_NOTCLAIMED("<i>You can only set warps in your faction territory."), COMMAND_SETFWARP_NOTCLAIMED("<i>You can only set warps in your faction territory."),
COMMAND_SETFWARP_LIMIT("<i>Your Faction already has the max amount of warps set <a>(%1$d)."), COMMAND_SETFWARP_LIMIT("<i>Your Faction already has the max amount of warps set <a>(%1$d)."),
COMMAND_SETFWARP_SET("<i>Set warp <a>%1$s <i>to your location."), COMMAND_SETFWARP_SET("<i>Set warp <a>%1$s and password <c>'%2$s' <i>to your location."),
COMMAND_SETFWARP_TOSET("to set warp"), COMMAND_SETFWARP_TOSET("to set warp"),
COMMAND_SETFWARP_FORSET("for setting warp"), COMMAND_SETFWARP_FORSET("for setting warp"),
COMMAND_SETFWARP_DESCRIPTION("Set a faction warp"), COMMAND_SETFWARP_DESCRIPTION("Set a faction warp"),