mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-11-19 17:05:17 +01:00
Fix create command
This commit is contained in:
parent
8ca4108d4c
commit
3c10663c41
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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.");
|
||||
|
||||
|
@ -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()) {
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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() + "'");
|
||||
|
@ -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() + "'");
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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.");
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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]);
|
||||
|
@ -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() + "'.");
|
||||
|
Loading…
Reference in New Issue
Block a user