diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/CommandValidator.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/CommandValidator.java index a6f88d80..23b73fb5 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/CommandValidator.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/CommandValidator.java @@ -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); diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/AddlineCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/AddlineCommand.java index e1ab5911..8c4f61e0 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/AddlineCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/AddlineCommand.java @@ -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 diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/AlignCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/AlignCommand.java index c18c14f4..c168e304 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/AlignCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/AlignCommand.java @@ -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!"); diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/CopyCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/CopyCommand.java index 815d5ed5..54ea09cf 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/CopyCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/CopyCommand.java @@ -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()) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/CreateCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/CreateCommand.java index b25fb416..40a8ddc1 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/CreateCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/CreateCommand.java @@ -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) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/DeleteCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/DeleteCommand.java index a03aa14b..f8cf60f7 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/DeleteCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/DeleteCommand.java @@ -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); diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/EditCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/EditCommand.java index c6c74746..68502786 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/EditCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/EditCommand.java @@ -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("", hologram.getName()).replace("", hologram.getName()) : ""); diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/InfoCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/InfoCommand.java index 9cb244a3..c72cc539 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/InfoCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/InfoCommand.java @@ -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()) { diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/InsertlineCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/InsertlineCommand.java index ea872cf9..536248d4 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/InsertlineCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/InsertlineCommand.java @@ -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(); diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/MovehereCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/MovehereCommand.java index 2e4accb0..68e3bd9a 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/MovehereCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/MovehereCommand.java @@ -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(); diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/ReadimageCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/ReadimageCommand.java index f7a7d9e5..9e79b2a0 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/ReadimageCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/ReadimageCommand.java @@ -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]); diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/ReadtextCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/ReadtextCommand.java index 54f4c6ca..1020e92a 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/ReadtextCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/ReadtextCommand.java @@ -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]; diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/RemovelineCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/RemovelineCommand.java index f0c496eb..5e2cadb8 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/RemovelineCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/RemovelineCommand.java @@ -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]); diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/SetlineCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/SetlineCommand.java index cad88104..0673c476 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/SetlineCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/SetlineCommand.java @@ -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 diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/TeleportCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/TeleportCommand.java index b4f76f7d..8cb7e9a1 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/TeleportCommand.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/TeleportCommand.java @@ -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); diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/NamedHologramManager.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/NamedHologramManager.java index 2acf7046..9057765d 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/NamedHologramManager.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/object/NamedHologramManager.java @@ -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; } }