Allow upper case letters for hologram names

This commit is contained in:
filoghost 2019-06-26 20:30:17 +02:00
parent 644d58c80e
commit be96a5c5fd
16 changed files with 30 additions and 54 deletions

View File

@ -17,9 +17,17 @@ package com.gmail.filoghost.holographicdisplays.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
public class CommandValidator {
public static NamedHologram getNamedHologram(String hologramName) throws CommandException {
NamedHologram hologram = NamedHologramManager.getHologram(hologramName);
notNull(hologram, Strings.noSuchHologram(hologramName));
return hologram;
}
public static void notNull(Object obj, String string) throws CommandException {
if (obj == null) {
throw new CommandException(string);

View File

@ -29,7 +29,6 @@ import com.gmail.filoghost.holographicdisplays.disk.HologramDatabase;
import com.gmail.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
import com.gmail.filoghost.holographicdisplays.util.ItemUtils;
import com.gmail.filoghost.holographicdisplays.util.Utils;
@ -52,8 +51,7 @@ public class AddlineCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
NamedHologram hologram = NamedHologramManager.getHologram(args[0].toLowerCase());
CommandValidator.notNull(hologram, Strings.noSuchHologram(args[0].toLowerCase()));
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
String line = Utils.join(args, " ", 1, args.length);
// Check material validity

View File

@ -27,7 +27,6 @@ import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand;
import com.gmail.filoghost.holographicdisplays.disk.HologramDatabase;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
public class AlignCommand extends HologramSubCommand {
@ -48,11 +47,8 @@ public class AlignCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
NamedHologram hologram = NamedHologramManager.getHologram(args[1].toLowerCase());
NamedHologram referenceHologram = NamedHologramManager.getHologram(args[2].toLowerCase());
CommandValidator.notNull(hologram, Strings.noSuchHologram(args[1].toLowerCase()));
CommandValidator.notNull(referenceHologram, Strings.noSuchHologram(args[2].toLowerCase()));
NamedHologram hologram = CommandValidator.getNamedHologram(args[1]);
NamedHologram referenceHologram = CommandValidator.getNamedHologram(args[2]);
CommandValidator.isTrue(hologram != referenceHologram, "The hologram must not be the same!");

View File

@ -26,7 +26,6 @@ import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand;
import com.gmail.filoghost.holographicdisplays.disk.HologramDatabase;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
import com.gmail.filoghost.holographicdisplays.object.line.CraftHologramLine;
public class CopyCommand extends HologramSubCommand {
@ -48,12 +47,8 @@ public class CopyCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
NamedHologram fromHologram = NamedHologramManager.getHologram(args[0].toLowerCase());
NamedHologram toHologram = NamedHologramManager.getHologram(args[1].toLowerCase());
CommandValidator.notNull(fromHologram, Strings.noSuchHologram(args[0].toLowerCase()));
CommandValidator.notNull(toHologram, Strings.noSuchHologram(args[1].toLowerCase()));
NamedHologram fromHologram = CommandValidator.getNamedHologram(args[0]);
NamedHologram toHologram = CommandValidator.getNamedHologram(args[1]);
toHologram.clearLines();
for (CraftHologramLine line : fromHologram.getLinesUnsafe()) {

View File

@ -53,13 +53,13 @@ public class CreateCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
Player player = CommandValidator.getPlayerSender(sender);
String name = args[0].toLowerCase();
String hologramName = args[0];
if (!name.matches("[a-zA-Z0-9_\\-]+")) {
if (!hologramName.matches("[a-zA-Z0-9_\\-]+")) {
throw new CommandException("The name must contain only alphanumeric chars, underscores and hyphens.");
}
CommandValidator.isTrue(!NamedHologramManager.isExistingHologram(name), "A hologram with that name already exists.");
CommandValidator.isTrue(!NamedHologramManager.isExistingHologram(hologramName), "A hologram with that name already exists.");
Location spawnLoc = player.getLocation();
boolean moveUp = player.isOnGround();
@ -68,7 +68,7 @@ public class CreateCommand extends HologramSubCommand {
spawnLoc.add(0.0, 1.2, 0.0);
}
NamedHologram hologram = new NamedHologram(spawnLoc, name);
NamedHologram hologram = new NamedHologram(spawnLoc, hologramName);
NamedHologramManager.addHologram(hologram);
if (args.length > 1) {

View File

@ -49,8 +49,7 @@ public class DeleteCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
NamedHologram hologram = NamedHologramManager.getHologram(args[0].toLowerCase());
CommandValidator.notNull(hologram, Strings.noSuchHologram(args[0].toLowerCase()));
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
hologram.delete();
NamedHologramManager.removeHologram(hologram);

View File

@ -29,7 +29,6 @@ import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand;
import com.gmail.filoghost.holographicdisplays.disk.Configuration;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
import com.google.common.collect.Lists;
import net.md_5.bungee.api.ChatColor;
@ -67,12 +66,10 @@ public class EditCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
String name = args[0].toLowerCase();
NamedHologram hologram = NamedHologramManager.getHologram(name);
CommandValidator.notNull(hologram, Strings.noSuchHologram(name));
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
sender.sendMessage("");
sender.sendMessage(Strings.formatTitle("How to edit the hologram '" + name + "'"));
sender.sendMessage(Strings.formatTitle("How to edit the hologram '" + hologram.getName() + "'"));
for (HologramSubCommand subCommand : HolographicDisplays.getCommandHandler().getSubCommands()) {
if (subCommand.getType() == SubCommandType.EDIT_LINES) {
String usage = "/" + label + " " + subCommand.getName() + (subCommand.getPossibleArguments().length() > 0 ? " " + subCommand.getPossibleArguments().replace("<hologramName>", hologram.getName()).replace("<hologram>", hologram.getName()) : "");

View File

@ -25,7 +25,6 @@ import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand;
import com.gmail.filoghost.holographicdisplays.disk.HologramDatabase;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
import com.gmail.filoghost.holographicdisplays.object.line.CraftHologramLine;
import com.gmail.filoghost.holographicdisplays.object.line.CraftTextLine;
@ -49,12 +48,10 @@ public class InfoCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
String name = args[0].toLowerCase();
NamedHologram hologram = NamedHologramManager.getHologram(name);
CommandValidator.notNull(hologram, Strings.noSuchHologram(name));
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
sender.sendMessage("");
sender.sendMessage(Strings.formatTitle("Lines of the hologram '" + name + "'"));
sender.sendMessage(Strings.formatTitle("Lines of the hologram '" + hologram.getName() + "'"));
int index = 0;
for (CraftHologramLine line : hologram.getLinesUnsafe()) {

View File

@ -28,7 +28,6 @@ import com.gmail.filoghost.holographicdisplays.disk.HologramDatabase;
import com.gmail.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
import com.gmail.filoghost.holographicdisplays.util.Utils;
public class InsertlineCommand extends HologramSubCommand {
@ -52,8 +51,7 @@ public class InsertlineCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
NamedHologram hologram = NamedHologramManager.getHologram(args[0].toLowerCase());
CommandValidator.notNull(hologram, Strings.noSuchHologram(args[0].toLowerCase()));
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
int insertAfter = CommandValidator.getInteger(args[1]);
int oldLinesAmount = hologram.size();

View File

@ -29,7 +29,6 @@ import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand;
import com.gmail.filoghost.holographicdisplays.disk.HologramDatabase;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
public class MovehereCommand extends HologramSubCommand {
@ -53,8 +52,7 @@ public class MovehereCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
Player player = CommandValidator.getPlayerSender(sender);
NamedHologram hologram = NamedHologramManager.getHologram(args[0].toLowerCase());
CommandValidator.notNull(hologram, Strings.noSuchHologram(args[0].toLowerCase()));
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
hologram.teleport(player.getWorld(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
hologram.despawnEntities();

View File

@ -40,7 +40,6 @@ import com.gmail.filoghost.holographicdisplays.exception.TooWideException;
import com.gmail.filoghost.holographicdisplays.exception.UnreadableImageException;
import com.gmail.filoghost.holographicdisplays.image.ImageMessage;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
import com.gmail.filoghost.holographicdisplays.util.FileUtils;
public class ReadimageCommand extends HologramSubCommand {
@ -79,8 +78,7 @@ public class ReadimageCommand extends HologramSubCommand {
args = newArgs.toArray(new String[0]);
NamedHologram hologram = NamedHologramManager.getHologram(args[0].toLowerCase());
CommandValidator.notNull(hologram, Strings.noSuchHologram(args[0].toLowerCase()));
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
int width = CommandValidator.getInteger(args[2]);

View File

@ -34,7 +34,6 @@ import com.gmail.filoghost.holographicdisplays.disk.StringConverter;
import com.gmail.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
import com.gmail.filoghost.holographicdisplays.util.FileUtils;
public class ReadtextCommand extends HologramSubCommand {
@ -56,8 +55,7 @@ public class ReadtextCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
NamedHologram hologram = NamedHologramManager.getHologram(args[0].toLowerCase());
CommandValidator.notNull(hologram, Strings.noSuchHologram(args[0].toLowerCase()));
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
try {
String fileName = args[1];

View File

@ -28,7 +28,6 @@ import com.gmail.filoghost.holographicdisplays.disk.HologramDatabase;
import com.gmail.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
public class RemovelineCommand extends HologramSubCommand {
@ -50,8 +49,7 @@ public class RemovelineCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
NamedHologram hologram = NamedHologramManager.getHologram(args[0].toLowerCase());
CommandValidator.notNull(hologram, Strings.noSuchHologram(args[0].toLowerCase()));
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
int lineNumber = CommandValidator.getInteger(args[1]);

View File

@ -29,7 +29,6 @@ import com.gmail.filoghost.holographicdisplays.disk.HologramDatabase;
import com.gmail.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
import com.gmail.filoghost.holographicdisplays.util.ItemUtils;
import com.gmail.filoghost.holographicdisplays.util.Utils;
@ -53,8 +52,7 @@ public class SetlineCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
NamedHologram hologram = NamedHologramManager.getHologram(args[0].toLowerCase());
CommandValidator.notNull(hologram, Strings.noSuchHologram(args[0].toLowerCase()));
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
String line = Utils.join(args, " ", 2, args.length);
// Check material validity

View File

@ -28,7 +28,6 @@ import com.gmail.filoghost.holographicdisplays.commands.Strings;
import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand;
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
public class TeleportCommand extends HologramSubCommand {
@ -51,8 +50,7 @@ public class TeleportCommand extends HologramSubCommand {
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
Player player = CommandValidator.getPlayerSender(sender);
NamedHologram hologram = NamedHologramManager.getHologram(args[0].toLowerCase());
CommandValidator.notNull(hologram, Strings.noSuchHologram(args[0].toLowerCase()));
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
Location loc = hologram.getLocation();
loc.setPitch(90);

View File

@ -43,7 +43,7 @@ public class NamedHologramManager {
public static NamedHologram getHologram(String name) {
for (NamedHologram hologram : pluginHolograms) {
if (hologram.getName().equals(name)) {
if (hologram.getName().equalsIgnoreCase(name)) {
return hologram;
}
}