From 3c10663c4107c31437e838c60d69d638475055ad Mon Sep 17 00:00:00 2001 From: filoghost Date: Fri, 13 Aug 2021 07:41:05 +0200 Subject: [PATCH] Fix create command --- .../plugin/commands/InternalHologramEditor.java | 7 ++++++- .../plugin/commands/subs/AddlineCommand.java | 2 +- .../plugin/commands/subs/AlignCommand.java | 4 ++-- .../plugin/commands/subs/CopyCommand.java | 4 ++-- .../plugin/commands/subs/CreateCommand.java | 3 +-- .../plugin/commands/subs/DeleteCommand.java | 2 +- .../plugin/commands/subs/EditCommand.java | 2 +- .../plugin/commands/subs/InfoCommand.java | 2 +- .../plugin/commands/subs/InsertlineCommand.java | 2 +- .../plugin/commands/subs/MovehereCommand.java | 2 +- .../plugin/commands/subs/ReadimageCommand.java | 2 +- .../plugin/commands/subs/ReadtextCommand.java | 2 +- .../plugin/commands/subs/RemovelineCommand.java | 2 +- .../plugin/commands/subs/SetlineCommand.java | 2 +- .../plugin/commands/subs/TeleportCommand.java | 2 +- 15 files changed, 22 insertions(+), 18 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/InternalHologramEditor.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/InternalHologramEditor.java index d0fffb68..d9b1f777 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/InternalHologramEditor.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/InternalHologramEditor.java @@ -22,6 +22,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; +import org.jetbrains.annotations.NotNull; import java.nio.file.Files; import java.nio.file.Path; @@ -58,7 +59,11 @@ public class InternalHologramEditor { return message; } - public InternalHologram getHologram(String hologramName) throws CommandException { + public boolean hologramExists(String hologramName) { + return internalHologramManager.getHologramByName(hologramName) != null; + } + + public @NotNull InternalHologram getExistingHologram(String hologramName) throws CommandException { InternalHologram hologram = internalHologramManager.getHologramByName(hologramName); CommandValidate.notNull(hologram, "Cannot find a hologram named \"" + hologramName + "\"."); return hologram; diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/AddlineCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/AddlineCommand.java index 3e23bcce..76dc36b4 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/AddlineCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/AddlineCommand.java @@ -33,7 +33,7 @@ public class AddlineCommand extends LineEditingCommand implements QuickEditComma @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { - InternalHologram hologram = hologramEditor.getHologram(args[0]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); String serializedLine = Strings.joinFrom(" ", args, 1); InternalHologramLine line = hologramEditor.parseHologramLine(hologram, serializedLine); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/AlignCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/AlignCommand.java index 6bd4d565..03e6514b 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/AlignCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/AlignCommand.java @@ -31,8 +31,8 @@ public class AlignCommand extends HologramSubCommand { @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { - InternalHologram hologram = hologramEditor.getHologram(args[1]); - InternalHologram referenceHologram = hologramEditor.getHologram(args[2]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[1]); + InternalHologram referenceHologram = hologramEditor.getExistingHologram(args[2]); CommandValidate.check(hologram != referenceHologram, "The holograms must not be the same."); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/CopyCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/CopyCommand.java index 20d86d9e..21ce6617 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/CopyCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/CopyCommand.java @@ -33,8 +33,8 @@ public class CopyCommand extends HologramSubCommand { @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { - InternalHologram fromHologram = hologramEditor.getHologram(args[0]); - InternalHologram toHologram = hologramEditor.getHologram(args[1]); + InternalHologram fromHologram = hologramEditor.getExistingHologram(args[0]); + InternalHologram toHologram = hologramEditor.getExistingHologram(args[1]); List clonedLines = new ArrayList<>(); for (InternalHologramLine line : fromHologram.getLines()) { diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/CreateCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/CreateCommand.java index dccf214a..e0f084d3 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/CreateCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/CreateCommand.java @@ -44,8 +44,7 @@ public class CreateCommand extends HologramSubCommand { CommandValidate.check(hologramName.matches("[a-zA-Z0-9_\\-]+"), "The name must contain only alphanumeric chars, underscores and hyphens."); - CommandValidate.check(hologramEditor.getHologram(hologramName) == null, - "A hologram with that name already exists."); + CommandValidate.check(!hologramEditor.hologramExists(hologramName), "A hologram with that name already exists."); BaseHologramPosition spawnPosition = new BaseHologramPosition(player.getLocation()); boolean moveUp = player.isOnGround(); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/DeleteCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/DeleteCommand.java index 070d35b4..d8bf20bb 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/DeleteCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/DeleteCommand.java @@ -29,7 +29,7 @@ public class DeleteCommand extends HologramSubCommand { @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { - InternalHologram hologram = hologramEditor.getHologram(args[0]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); hologramEditor.delete(hologram); hologramEditor.saveChanges(hologram, ChangeType.DELETE); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/EditCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/EditCommand.java index ef8c3aba..34f3d6f3 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/EditCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/EditCommand.java @@ -41,7 +41,7 @@ public class EditCommand extends HologramSubCommand { @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { - InternalHologram hologram = hologramEditor.getHologram(args[0]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); sender.sendMessage(""); DisplayFormat.sendTitle(sender, "How to edit the hologram '" + hologram.getName() + "'"); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/InfoCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/InfoCommand.java index 50895292..47347c84 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/InfoCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/InfoCommand.java @@ -32,7 +32,7 @@ public class InfoCommand extends LineEditingCommand implements QuickEditCommand @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { - InternalHologram hologram = hologramEditor.getHologram(args[0]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); sender.sendMessage(""); DisplayFormat.sendTitle(sender, "Lines of the hologram '" + hologram.getName() + "'"); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/InsertlineCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/InsertlineCommand.java index b16de8c3..e0311eb6 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/InsertlineCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/InsertlineCommand.java @@ -38,7 +38,7 @@ public class InsertlineCommand extends LineEditingCommand implements QuickEditCo @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { - InternalHologram hologram = hologramEditor.getHologram(args[0]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); int insertAfterIndex = CommandValidate.parseInteger(args[1]); String serializedLine = Strings.joinFrom(" ", args, 2); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/MovehereCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/MovehereCommand.java index 72fc6bdc..aabd5d2c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/MovehereCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/MovehereCommand.java @@ -32,7 +32,7 @@ public class MovehereCommand extends HologramSubCommand { @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { Player player = CommandValidate.getPlayerSender(sender); - InternalHologram hologram = hologramEditor.getHologram(args[0]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); hologram.setPosition(player.getLocation()); hologramEditor.saveChanges(hologram, ChangeType.EDIT_POSITION); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/ReadimageCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/ReadimageCommand.java index 3ee3605d..a0a6b4bb 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/ReadimageCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/ReadimageCommand.java @@ -70,7 +70,7 @@ public class ReadimageCommand extends LineEditingCommand { boolean append = extractAppendFlag(newArgs); args = newArgs.toArray(new String[0]); - InternalHologram hologram = hologramEditor.getHologram(args[0]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); int width = CommandValidate.parseInteger(args[2]); CommandValidate.check(width >= 2, "The width of the image must be 2 or greater."); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/ReadtextCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/ReadtextCommand.java index e41eff0d..ce1bea8a 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/ReadtextCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/ReadtextCommand.java @@ -55,7 +55,7 @@ public class ReadtextCommand extends LineEditingCommand { @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { - InternalHologram hologram = hologramEditor.getHologram(args[0]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); String fileName = args[1]; Path fileToRead = hologramEditor.getUserReadableFile(fileName); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/RemovelineCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/RemovelineCommand.java index bbbc2188..75403c2f 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/RemovelineCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/RemovelineCommand.java @@ -32,7 +32,7 @@ public class RemovelineCommand extends LineEditingCommand implements QuickEditCo @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { - InternalHologram hologram = hologramEditor.getHologram(args[0]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); int lineNumber = CommandValidate.parseInteger(args[1]); int linesAmount = hologram.getLines().size(); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/SetlineCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/SetlineCommand.java index 36ac070a..567f2bd5 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/SetlineCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/SetlineCommand.java @@ -34,7 +34,7 @@ public class SetlineCommand extends LineEditingCommand implements QuickEditComma @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { - InternalHologram hologram = hologramEditor.getHologram(args[0]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); String serializedLine = Strings.joinFrom(" ", args, 2); int lineNumber = CommandValidate.parseInteger(args[1]); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/TeleportCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/TeleportCommand.java index 744dfaba..72d10a7c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/TeleportCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/commands/subs/TeleportCommand.java @@ -32,7 +32,7 @@ public class TeleportCommand extends HologramSubCommand { @Override public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException { Player player = CommandValidate.getPlayerSender(sender); - InternalHologram hologram = hologramEditor.getHologram(args[0]); + InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); hologramEditor.teleportLookingDown(player, hologram.getBasePosition().toLocation()); player.sendMessage(ColorScheme.PRIMARY + "You were teleported to the hologram named '" + hologram.getName() + "'.");