allow spaces in warp names

make warp names only alphanumeric
This commit is contained in:
Taah 2022-05-08 16:59:03 -07:00
parent 2b3f146dbb
commit 1e43e49604
3 changed files with 21 additions and 8 deletions

View File

@ -65,6 +65,7 @@ public class Guilds extends PlexModule
this.addDefaultMessage("guildNotOwner", "<red>You're not the owner of this guild!");
this.addDefaultMessage("guildPrefixSet", "<green>You have changed the guild prefix to '<gold>{0}</gold><green>'", "0 - The new prefix");
this.addDefaultMessage("guildPrefixCleared", "<green>Your guild's prefix has been cleared.");
this.addDefaultMessage("guildWarpAlphanumeric", "<red>Warp names may only contain alphabetical and/or numerical characters.");
this.addDefaultMessage("guildWarpExists", "<red>'<gold>{0}</gold>'<red> is already an existing warp!", "0 - The warp name");
this.addDefaultMessage("guildWarpNotFound", "<red>'<gold>{0}</gold>'<red> is not a valid warp!", "0 - The warp name");
this.addDefaultMessage("guildWarpCreated", "<green>You have created a warp called '<dark_green>{0}</dark_green><green>'", "0 - The warp name");

View File

@ -15,10 +15,14 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
import java.util.regex.Pattern;
@CommandParameters(name = "setwarp", aliases = "makewarp,createwarp", usage = "/guild <command> <name>")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.setwarp")
public class SetWarpSubCommand extends PlexCommand
{
public SetWarpSubCommand()
{
super(false);
@ -37,18 +41,24 @@ public class SetWarpSubCommand extends PlexCommand
send(player, messageComponent("guildNotOwner"));
return;
}
if (args[0].length() > 16)
String warpName = StringUtils.join(args, " ");
if (warpName.length() > 16)
{
send(player, mmString("<red>The max length of a warp name is 16 characters!"));
return;
}
if (guild.getWarps().containsKey(args[0].toLowerCase()))
if (guild.getWarps().containsKey(warpName.toLowerCase()))
{
send(player, messageComponent("guildWarpExists", args[0]));
send(player, messageComponent("guildWarpExists", warpName));
return;
}
guild.getWarps().put(args[0].toLowerCase(), CustomLocation.fromLocation(player.getLocation()));
send(player, messageComponent("guildWarpCreated", args[0]));
if (!StringUtils.isAlphanumericSpace(warpName.toLowerCase(Locale.ROOT)))
{
send(player, messageComponent("guildWarpAlphanumeric"));
return;
}
guild.getWarps().put(warpName.toLowerCase(), CustomLocation.fromLocation(player.getLocation()));
send(player, messageComponent("guildWarpCreated", warpName));
}, () -> send(player, messageComponent("guildNotFound")));
return null;
}

View File

@ -8,6 +8,7 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.CustomLocation;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -30,12 +31,13 @@ public class WarpSubCommand extends PlexCommand
}
assert player != null;
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> {
if (!guild.getWarps().containsKey(args[0].toLowerCase()))
String warpName = StringUtils.join(args, " ");
if (!guild.getWarps().containsKey(warpName.toLowerCase()))
{
send(player, messageComponent("guildWarpNotFound", args[0]));
send(player, messageComponent("guildWarpNotFound", warpName));
return;
}
player.teleportAsync(guild.getWarps().get(args[0].toLowerCase()).toLocation());
player.teleportAsync(guild.getWarps().get(warpName.toLowerCase()).toLocation());
}, () -> send(player, messageComponent("guildNotFound")));
return null;
}