Fix create command

This commit is contained in:
filoghost 2021-08-13 07:41:05 +02:00
parent 8ca4108d4c
commit 3c10663c41
15 changed files with 22 additions and 18 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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.");

View File

@ -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<InternalHologramLine> clonedLines = new ArrayList<>();
for (InternalHologramLine line : fromHologram.getLines()) {

View File

@ -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();

View File

@ -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);

View File

@ -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() + "'");

View File

@ -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() + "'");

View File

@ -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);

View File

@ -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);

View File

@ -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.");

View File

@ -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);

View File

@ -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();

View File

@ -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]);

View File

@ -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() + "'.");