mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-24 01:37:35 +01:00
Refactor commands using FCommons
This commit is contained in:
parent
b5852116d4
commit
d71df75036
@ -12,7 +12,7 @@ import me.filoghost.holographicdisplays.api.internal.BackendAPI;
|
|||||||
import me.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerTracker;
|
import me.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerTracker;
|
||||||
import me.filoghost.holographicdisplays.bridge.protocollib.ProtocolLibHook;
|
import me.filoghost.holographicdisplays.bridge.protocollib.ProtocolLibHook;
|
||||||
import me.filoghost.holographicdisplays.bridge.protocollib.current.ProtocolLibHookImpl;
|
import me.filoghost.holographicdisplays.bridge.protocollib.current.ProtocolLibHookImpl;
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramsCommandHandler;
|
import me.filoghost.holographicdisplays.commands.HologramCommandManager;
|
||||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
import me.filoghost.holographicdisplays.disk.UnicodeSymbols;
|
import me.filoghost.holographicdisplays.disk.UnicodeSymbols;
|
||||||
@ -51,7 +51,7 @@ public class HolographicDisplays extends BaseJavaPlugin {
|
|||||||
private static MainListener mainListener;
|
private static MainListener mainListener;
|
||||||
|
|
||||||
// The command handler, just in case a plugin wants to register more commands.
|
// The command handler, just in case a plugin wants to register more commands.
|
||||||
private static HologramsCommandHandler commandHandler;
|
private static HologramCommandManager commandManager;
|
||||||
|
|
||||||
// The new version found by the updater, null if there is no new version.
|
// The new version found by the updater, null if there is no new version.
|
||||||
private static String newVersion;
|
private static String newVersion;
|
||||||
@ -132,8 +132,11 @@ public class HolographicDisplays extends BaseJavaPlugin {
|
|||||||
"This can be caused by edits to plugin.yml or other plugins.");
|
"This can be caused by edits to plugin.yml or other plugins.");
|
||||||
}
|
}
|
||||||
|
|
||||||
getCommand("holograms").setExecutor(commandHandler = new HologramsCommandHandler());
|
commandManager = new HologramCommandManager();
|
||||||
Bukkit.getPluginManager().registerEvents(mainListener = new MainListener(nmsManager), this);
|
commandManager.register(this);
|
||||||
|
|
||||||
|
mainListener = new MainListener(nmsManager);
|
||||||
|
Bukkit.getPluginManager().registerEvents(mainListener, this);
|
||||||
|
|
||||||
// Register bStats metrics
|
// Register bStats metrics
|
||||||
int pluginID = 3123;
|
int pluginID = 3123;
|
||||||
@ -165,8 +168,8 @@ public class HolographicDisplays extends BaseJavaPlugin {
|
|||||||
return mainListener;
|
return mainListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HologramsCommandHandler getCommandHandler() {
|
public static HologramCommandManager getCommandManager() {
|
||||||
return commandHandler;
|
return commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HolographicDisplays getInstance() {
|
public static HolographicDisplays getInstance() {
|
||||||
|
@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
|
||||||
import me.filoghost.holographicdisplays.disk.HologramLineParser;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.exception.HologramLineParseException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
|
||||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
|
||||||
import me.filoghost.holographicdisplays.util.FileUtils;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public class CommandValidator {
|
|
||||||
|
|
||||||
public static CraftHologramLine parseHologramLine(NamedHologram hologram, String serializedLine, boolean validateMaterial) throws CommandException {
|
|
||||||
try {
|
|
||||||
return HologramLineParser.parseLine(hologram, serializedLine, validateMaterial);
|
|
||||||
} catch (HologramLineParseException e) {
|
|
||||||
throw new CommandException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static NamedHologram getNamedHologram(String hologramName) throws CommandException {
|
|
||||||
NamedHologram hologram = NamedHologramManager.getHologram(hologramName);
|
|
||||||
notNull(hologram, "Cannot find a hologram named \"" + hologramName + "\".");
|
|
||||||
return hologram;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void notNull(Object obj, String string) throws CommandException {
|
|
||||||
if (obj == null) {
|
|
||||||
throw new CommandException(string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void isTrue(boolean b, String string) throws CommandException {
|
|
||||||
if (!b) {
|
|
||||||
throw new CommandException(string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getInteger(String integer) throws CommandException {
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(integer);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
throw new CommandException("Invalid number: '" + integer + "'.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Player getPlayerSender(CommandSender sender) throws CommandException {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
return (Player) sender;
|
|
||||||
} else {
|
|
||||||
throw new CommandException("You must be a player to use this command.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Path getUserReadableFile(String fileName) throws CommandException, IOException {
|
|
||||||
Path dataFolder = HolographicDisplays.getDataFolderPath();
|
|
||||||
Path targetFile = dataFolder.resolve(fileName);
|
|
||||||
CommandValidator.isTrue(FileUtils.isInsideDirectory(targetFile, dataFolder), "The specified file must be inside HolographicDisplays' folder.");
|
|
||||||
CommandValidator.isTrue(Files.exists(targetFile), "The specified file \"" + fileName + "\" does not exist inside HolographicDisplays' folder.");
|
|
||||||
CommandValidator.isTrue(!Files.isDirectory(targetFile), "The file cannot be a folder.");
|
|
||||||
CommandValidator.isTrue(!isConfigFile(targetFile), "Cannot read YML configuration files.");
|
|
||||||
return targetFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isConfigFile(Path file) {
|
|
||||||
return Files.isRegularFile(file) && file.getFileName().toString().toLowerCase().endsWith(".yml");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.CommandContext;
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommand;
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandManager;
|
||||||
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
|
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.AddlineCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.AlignCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.CopyCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.CreateCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.DebugCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.DeleteCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.EditCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.HelpCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.InfoCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.InsertlineCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.ListCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.MovehereCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.NearCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.ReadimageCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.ReadtextCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.ReloadCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.RemovelineCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.SetlineCommand;
|
||||||
|
import me.filoghost.holographicdisplays.commands.subs.TeleportCommand;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class HologramCommandManager extends SubCommandManager {
|
||||||
|
|
||||||
|
private final List<HologramSubCommand> subCommands;
|
||||||
|
private final Map<Class<? extends HologramSubCommand>, HologramSubCommand> subCommandsByClass;
|
||||||
|
|
||||||
|
private final HelpCommand helpCommand;
|
||||||
|
|
||||||
|
public HologramCommandManager() {
|
||||||
|
setName("holograms");
|
||||||
|
subCommands = new ArrayList<>();
|
||||||
|
subCommandsByClass = new HashMap<>();
|
||||||
|
|
||||||
|
registerSubCommand(new AddlineCommand());
|
||||||
|
registerSubCommand(new CreateCommand());
|
||||||
|
registerSubCommand(new DeleteCommand());
|
||||||
|
registerSubCommand(new EditCommand());
|
||||||
|
registerSubCommand(new ListCommand());
|
||||||
|
registerSubCommand(new NearCommand());
|
||||||
|
registerSubCommand(new TeleportCommand());
|
||||||
|
registerSubCommand(new MovehereCommand());
|
||||||
|
registerSubCommand(new AlignCommand());
|
||||||
|
registerSubCommand(new CopyCommand());
|
||||||
|
registerSubCommand(new ReloadCommand());
|
||||||
|
|
||||||
|
registerSubCommand(new RemovelineCommand());
|
||||||
|
registerSubCommand(new SetlineCommand());
|
||||||
|
registerSubCommand(new InsertlineCommand());
|
||||||
|
registerSubCommand(new ReadtextCommand());
|
||||||
|
registerSubCommand(new ReadimageCommand());
|
||||||
|
registerSubCommand(new InfoCommand());
|
||||||
|
|
||||||
|
registerSubCommand(new DebugCommand());
|
||||||
|
registerSubCommand(helpCommand = new HelpCommand());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SubCommand getSubCommandByName(String name) {
|
||||||
|
for (HologramSubCommand subCommand : subCommands) {
|
||||||
|
if (subCommand.getName().equalsIgnoreCase(name)) {
|
||||||
|
return subCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subCommand.getAliases() != null) {
|
||||||
|
for (String alias : subCommand.getAliases()) {
|
||||||
|
if (alias.equalsIgnoreCase(name)) {
|
||||||
|
return subCommand;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<HologramSubCommand> getSubCommands() {
|
||||||
|
return subCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerSubCommand(HologramSubCommand subCommand) {
|
||||||
|
subCommands.add(subCommand);
|
||||||
|
subCommandsByClass.put(subCommand.getClass(), subCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HologramSubCommand getSubCommand(Class<? extends HologramSubCommand> subCommandClass) {
|
||||||
|
return subCommandsByClass.get(subCommandClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void sendNoArgsMessage(CommandContext context) {
|
||||||
|
CommandSender sender = context.getSender();
|
||||||
|
sender.sendMessage(Colors.PRIMARY_SHADOW + "Server is running " + Colors.PRIMARY + "Holographic Displays " + Colors.PRIMARY_SHADOW + "v" + HolographicDisplays.getInstance().getDescription().getVersion() + " by " + Colors.PRIMARY + "filoghost");
|
||||||
|
if (helpCommand.hasPermission(sender)) {
|
||||||
|
sender.sendMessage(Colors.PRIMARY_SHADOW + "Commands: " + Colors.PRIMARY + helpCommand.getFullUsageText(context));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void sendSubCommandDefaultPermissionMessage(SubCommandContext context) {
|
||||||
|
context.getSender().sendMessage(Colors.ERROR + "You don't have permission for this sub-command.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void sendUnknownSubCommandMessage(SubCommandContext context) {
|
||||||
|
context.getSender().sendMessage(Colors.ERROR + "Unknown sub-command."
|
||||||
|
+ " Type \"" + helpCommand.getFullUsageText(context) + "\" for a list of commands.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void sendSubCommandUsage(SubCommandContext context) {
|
||||||
|
context.getSender().sendMessage(Colors.ERROR + "Usage: /" + context.getRootLabel() + " "
|
||||||
|
+ context.getSubLabel() + " " + context.getSubCommand().getUsageArgs());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUnexpectedException(CommandContext context, Throwable t) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Unhandled exception while executing /" + context.getRootLabel(), t);
|
||||||
|
context.getSender().sendMessage(Colors.ERROR + "Internal error while executing command."
|
||||||
|
+ " Please look on the console for more details.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||||
|
import me.filoghost.holographicdisplays.disk.HologramLineParser;
|
||||||
|
import me.filoghost.holographicdisplays.exception.HologramLineParseException;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||||
|
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||||
|
import me.filoghost.holographicdisplays.util.FileUtils;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class HologramCommandValidate {
|
||||||
|
|
||||||
|
public static CraftHologramLine parseHologramLine(NamedHologram hologram, String serializedLine, boolean validateMaterial) throws CommandException {
|
||||||
|
try {
|
||||||
|
return HologramLineParser.parseLine(hologram, serializedLine, validateMaterial);
|
||||||
|
} catch (HologramLineParseException e) {
|
||||||
|
throw new CommandException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NamedHologram getNamedHologram(String hologramName) throws CommandException {
|
||||||
|
NamedHologram hologram = NamedHologramManager.getHologram(hologramName);
|
||||||
|
CommandValidate.notNull(hologram, "Cannot find a hologram named \"" + hologramName + "\".");
|
||||||
|
return hologram;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Path getUserReadableFile(String fileName) throws CommandException {
|
||||||
|
Path dataFolder = HolographicDisplays.getDataFolderPath();
|
||||||
|
Path targetFile = dataFolder.resolve(fileName);
|
||||||
|
CommandValidate.check(FileUtils.isInsideDirectory(targetFile, dataFolder), "The specified file must be inside HolographicDisplays' folder.");
|
||||||
|
CommandValidate.check(Files.exists(targetFile), "The specified file \"" + fileName + "\" does not exist inside HolographicDisplays' folder.");
|
||||||
|
CommandValidate.check(!Files.isDirectory(targetFile), "The file cannot be a folder.");
|
||||||
|
CommandValidate.check(!isConfigFile(targetFile), "Cannot read YML configuration files.");
|
||||||
|
return targetFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isConfigFile(Path file) {
|
||||||
|
return Files.isRegularFile(file) && file.getFileName().toString().toLowerCase().endsWith(".yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.CommandContext;
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommand;
|
||||||
|
import me.filoghost.holographicdisplays.Permissions;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class HologramSubCommand implements SubCommand {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final List<String> aliases;
|
||||||
|
private final String permission;
|
||||||
|
|
||||||
|
private String usageArgs;
|
||||||
|
private int minArgs;
|
||||||
|
|
||||||
|
private List<String> description;
|
||||||
|
private boolean showInHelpCommand;
|
||||||
|
|
||||||
|
protected HologramSubCommand(String name, String... aliases) {
|
||||||
|
this.name = name;
|
||||||
|
this.aliases = aliases != null ? Arrays.asList(aliases) : Collections.emptyList();
|
||||||
|
this.permission = Permissions.COMMAND_BASE + name.toLowerCase();
|
||||||
|
|
||||||
|
this.showInHelpCommand = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getFullUsageText(CommandContext context) {
|
||||||
|
return "/" + context.getRootLabel() + " " + name + (usageArgs != null ? " " + usageArgs : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String getPermission() {
|
||||||
|
return permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String getPermissionMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String getUsageArgs() {
|
||||||
|
return usageArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setUsageArgs(String usageArgs) {
|
||||||
|
this.usageArgs = usageArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int getMinArgs() {
|
||||||
|
return minArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setMinArgs(int minArgs) {
|
||||||
|
this.minArgs = minArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final List<String> getAliases() {
|
||||||
|
return aliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setDescription(String... description) {
|
||||||
|
this.description = Arrays.asList(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getDescription(CommandContext context) {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setShowInHelpCommand(boolean show) {
|
||||||
|
this.showInHelpCommand = show;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean isShowInHelpCommand() {
|
||||||
|
return showInHelpCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands.main;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class HologramSubCommand {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private String permission;
|
|
||||||
private String[] aliases;
|
|
||||||
|
|
||||||
public HologramSubCommand(String name) {
|
|
||||||
this(name, new String[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public HologramSubCommand(String name, String... aliases) {
|
|
||||||
this.name = name;
|
|
||||||
this.aliases = aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPermission(String permission) {
|
|
||||||
this.permission = permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPermission() {
|
|
||||||
return permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean hasPermission(CommandSender sender) {
|
|
||||||
if (permission == null) return true;
|
|
||||||
return sender.hasPermission(permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract String getPossibleArguments();
|
|
||||||
|
|
||||||
public abstract int getMinimumArguments();
|
|
||||||
|
|
||||||
public abstract void execute(CommandSender sender, String label, String[] args) throws CommandException;
|
|
||||||
|
|
||||||
public abstract List<String> getTutorial();
|
|
||||||
|
|
||||||
public abstract SubCommandType getType();
|
|
||||||
|
|
||||||
public enum SubCommandType {
|
|
||||||
GENERIC, EDIT_LINES, HIDDEN
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public final boolean isValidTrigger(String name) {
|
|
||||||
if (this.name.equalsIgnoreCase(name)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aliases != null) {
|
|
||||||
for (String alias : aliases) {
|
|
||||||
if (alias.equalsIgnoreCase(name)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands.main;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.AddlineCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.AlignCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.CopyCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.CreateCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.DebugCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.DeleteCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.EditCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.HelpCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.InfoCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.InsertlineCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.ListCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.MovehereCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.NearCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.ReadimageCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.ReadtextCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.ReloadCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.RemovelineCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.SetlineCommand;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.subs.TeleportCommand;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class HologramsCommandHandler implements CommandExecutor {
|
|
||||||
|
|
||||||
private List<HologramSubCommand> subCommands;
|
|
||||||
private Map<Class<? extends HologramSubCommand>, HologramSubCommand> subCommandsByClass;
|
|
||||||
|
|
||||||
public HologramsCommandHandler() {
|
|
||||||
subCommands = new ArrayList<>();
|
|
||||||
subCommandsByClass = new HashMap<>();
|
|
||||||
|
|
||||||
registerSubCommand(new AddlineCommand());
|
|
||||||
registerSubCommand(new CreateCommand());
|
|
||||||
registerSubCommand(new DeleteCommand());
|
|
||||||
registerSubCommand(new EditCommand());
|
|
||||||
registerSubCommand(new ListCommand());
|
|
||||||
registerSubCommand(new NearCommand());
|
|
||||||
registerSubCommand(new TeleportCommand());
|
|
||||||
registerSubCommand(new MovehereCommand());
|
|
||||||
registerSubCommand(new AlignCommand());
|
|
||||||
registerSubCommand(new CopyCommand());
|
|
||||||
registerSubCommand(new ReloadCommand());
|
|
||||||
|
|
||||||
registerSubCommand(new RemovelineCommand());
|
|
||||||
registerSubCommand(new SetlineCommand());
|
|
||||||
registerSubCommand(new InsertlineCommand());
|
|
||||||
registerSubCommand(new ReadtextCommand());
|
|
||||||
registerSubCommand(new ReadimageCommand());
|
|
||||||
registerSubCommand(new InfoCommand());
|
|
||||||
|
|
||||||
registerSubCommand(new DebugCommand());
|
|
||||||
registerSubCommand(new HelpCommand());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerSubCommand(HologramSubCommand subCommand) {
|
|
||||||
subCommands.add(subCommand);
|
|
||||||
subCommandsByClass.put(subCommand.getClass(), subCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<HologramSubCommand> getSubCommands() {
|
|
||||||
return new ArrayList<>(subCommands);
|
|
||||||
}
|
|
||||||
|
|
||||||
public HologramSubCommand getSubCommand(Class<? extends HologramSubCommand> subCommandClass) {
|
|
||||||
return subCommandsByClass.get(subCommandClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (args.length == 0) {
|
|
||||||
sender.sendMessage(Colors.PRIMARY_SHADOW + "Server is running " + Colors.PRIMARY + "Holographic Displays " + Colors.PRIMARY_SHADOW + "v" + HolographicDisplays.getInstance().getDescription().getVersion() + " by " + Colors.PRIMARY + "filoghost");
|
|
||||||
if (sender.hasPermission(Permissions.COMMAND_BASE + "help")) {
|
|
||||||
sender.sendMessage(Colors.PRIMARY_SHADOW + "Commands: " + Colors.PRIMARY + "/" + label + " help");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (HologramSubCommand subCommand : subCommands) {
|
|
||||||
if (subCommand.isValidTrigger(args[0])) {
|
|
||||||
|
|
||||||
if (!subCommand.hasPermission(sender)) {
|
|
||||||
sender.sendMessage(Colors.ERROR + "You don't have permission.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length - 1 >= subCommand.getMinimumArguments()) {
|
|
||||||
try {
|
|
||||||
subCommand.execute(sender, label, Arrays.copyOfRange(args, 1, args.length));
|
|
||||||
} catch (CommandException e) {
|
|
||||||
sender.sendMessage(Colors.ERROR + e.getMessage());
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
sender.sendMessage(Colors.ERROR + "Unhandled exception while executing command. Please look on the console for more details.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Colors.ERROR + "Usage: /" + label + " " + subCommand.getName() + " " + subCommand.getPossibleArguments());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(Colors.ERROR + "Unknown sub-command. Type \"/" + label + " help\" for a list of commands.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.common.Utils;
|
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
|
||||||
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
|
||||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AddlineCommand extends HologramSubCommand {
|
|
||||||
|
|
||||||
public AddlineCommand() {
|
|
||||||
super("addline");
|
|
||||||
setPermission(Permissions.COMMAND_BASE + "addline");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPossibleArguments() {
|
|
||||||
return "<hologramName> <text>";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
|
|
||||||
String serializedLine = Utils.join(args, " ", 1, args.length);
|
|
||||||
|
|
||||||
CraftHologramLine line = CommandValidator.parseHologramLine(hologram, serializedLine, true);
|
|
||||||
hologram.getLinesUnsafe().add(line);
|
|
||||||
hologram.refreshAll();
|
|
||||||
|
|
||||||
HologramDatabase.saveHologram(hologram);
|
|
||||||
HologramDatabase.trySaveToDisk();
|
|
||||||
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
|
||||||
|
|
||||||
sender.sendMessage(Colors.PRIMARY + "Line added!");
|
|
||||||
EditCommand.sendQuickEditCommands(sender, label, hologram.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Adds a line to an existing hologram.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.EDIT_LINES;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AlignCommand extends HologramSubCommand {
|
|
||||||
|
|
||||||
public AlignCommand() {
|
|
||||||
super("align");
|
|
||||||
setPermission(Permissions.COMMAND_BASE + "align");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPossibleArguments() {
|
|
||||||
return "<X | Y | Z | XZ> <hologram> <referenceHologram>";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[1]);
|
|
||||||
NamedHologram referenceHologram = CommandValidator.getNamedHologram(args[2]);
|
|
||||||
|
|
||||||
CommandValidator.isTrue(hologram != referenceHologram, "The hologram must not be the same!");
|
|
||||||
|
|
||||||
Location loc = hologram.getLocation();
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("x")) {
|
|
||||||
loc.setX(referenceHologram.getX());
|
|
||||||
} else if (args[0].equalsIgnoreCase("y")) {
|
|
||||||
loc.setY(referenceHologram.getY());
|
|
||||||
} else if (args[0].equalsIgnoreCase("z")) {
|
|
||||||
loc.setZ(referenceHologram.getZ());
|
|
||||||
} else if (args[0].equalsIgnoreCase("xz")) {
|
|
||||||
loc.setX(referenceHologram.getX());
|
|
||||||
loc.setZ(referenceHologram.getZ());
|
|
||||||
} else {
|
|
||||||
throw new CommandException("You must specify either X, Y, Z or XZ, " + args[0] + " is not a valid axis.");
|
|
||||||
}
|
|
||||||
|
|
||||||
hologram.teleport(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ());
|
|
||||||
hologram.despawnEntities();
|
|
||||||
hologram.refreshAll();
|
|
||||||
|
|
||||||
HologramDatabase.saveHologram(hologram);
|
|
||||||
HologramDatabase.trySaveToDisk();
|
|
||||||
sender.sendMessage(Colors.PRIMARY + "Hologram \"" + hologram.getName() + "\" aligned to the hologram \"" + referenceHologram.getName() + "\" on the " + args[0].toUpperCase() + " axis.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Aligns the first hologram to the second, in the specified axis.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
|
||||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CopyCommand extends HologramSubCommand {
|
|
||||||
|
|
||||||
public CopyCommand() {
|
|
||||||
super("copy");
|
|
||||||
setPermission(Permissions.COMMAND_BASE + "copy");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPossibleArguments() {
|
|
||||||
return "<fromHologram> <toHologram>";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
NamedHologram fromHologram = CommandValidator.getNamedHologram(args[0]);
|
|
||||||
NamedHologram toHologram = CommandValidator.getNamedHologram(args[1]);
|
|
||||||
|
|
||||||
toHologram.clearLines();
|
|
||||||
for (CraftHologramLine line : fromHologram.getLinesUnsafe()) {
|
|
||||||
CraftHologramLine clonedLine = CommandValidator.parseHologramLine(toHologram, HologramDatabase.serializeHologramLine(line), false);
|
|
||||||
toHologram.getLinesUnsafe().add(clonedLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
toHologram.refreshAll();
|
|
||||||
|
|
||||||
HologramDatabase.saveHologram(toHologram);
|
|
||||||
HologramDatabase.trySaveToDisk();
|
|
||||||
|
|
||||||
sender.sendMessage(Colors.PRIMARY + "Hologram \"" + fromHologram.getName() + "\" copied into hologram \"" + toHologram.getName() + "\"!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList(
|
|
||||||
"Copies the contents of a hologram into another one.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DeleteCommand extends HologramSubCommand {
|
|
||||||
|
|
||||||
public DeleteCommand() {
|
|
||||||
super("delete", "remove");
|
|
||||||
setPermission(Permissions.COMMAND_BASE + "delete");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPossibleArguments() {
|
|
||||||
return "<hologramName>";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
|
|
||||||
|
|
||||||
hologram.delete();
|
|
||||||
NamedHologramManager.removeHologram(hologram);
|
|
||||||
HologramDatabase.deleteHologram(hologram.getName());
|
|
||||||
|
|
||||||
HologramDatabase.trySaveToDisk();
|
|
||||||
sender.sendMessage(Colors.PRIMARY + "You deleted the hologram '" + hologram.getName() + "'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Deletes a hologram. Cannot be undone.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
|
||||||
import me.filoghost.holographicdisplays.commands.Messages;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
|
||||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class InfoCommand extends HologramSubCommand {
|
|
||||||
|
|
||||||
public InfoCommand() {
|
|
||||||
super("info", "details");
|
|
||||||
setPermission(Permissions.COMMAND_BASE + "info");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPossibleArguments() {
|
|
||||||
return "<hologramName>";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
|
|
||||||
|
|
||||||
sender.sendMessage("");
|
|
||||||
Messages.sendTitle(sender, "Lines of the hologram '" + hologram.getName() + "'");
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
for (CraftHologramLine line : hologram.getLinesUnsafe()) {
|
|
||||||
sender.sendMessage(Colors.SECONDARY + Colors.BOLD + (++index) + Colors.SECONDARY_SHADOW + ". " + Colors.SECONDARY + HologramDatabase.serializeHologramLine(line));
|
|
||||||
}
|
|
||||||
EditCommand.sendQuickEditCommands(sender, label, hologram.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Shows the lines of a hologram.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.EDIT_LINES;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
|
||||||
import me.filoghost.holographicdisplays.commands.Messages;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
|
||||||
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
|
||||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
|
||||||
import me.filoghost.holographicdisplays.common.Utils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class InsertlineCommand extends HologramSubCommand {
|
|
||||||
|
|
||||||
|
|
||||||
public InsertlineCommand() {
|
|
||||||
super("insertline");
|
|
||||||
setPermission(Permissions.COMMAND_BASE + "insertline");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPossibleArguments() {
|
|
||||||
return "<hologramName> <lineNumber> <text>";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
|
|
||||||
int insertAfter = CommandValidator.getInteger(args[1]);
|
|
||||||
String serializedLine = Utils.join(args, " ", 2, args.length);
|
|
||||||
|
|
||||||
int oldLinesAmount = hologram.size();
|
|
||||||
|
|
||||||
CommandValidator.isTrue(insertAfter >= 0 && insertAfter <= oldLinesAmount, "The number must be between 0 and " + hologram.size() + "(amount of lines of the hologram).");
|
|
||||||
|
|
||||||
CraftHologramLine line = CommandValidator.parseHologramLine(hologram, serializedLine, true);
|
|
||||||
hologram.getLinesUnsafe().add(insertAfter, line);
|
|
||||||
hologram.refreshAll();
|
|
||||||
|
|
||||||
HologramDatabase.saveHologram(hologram);
|
|
||||||
HologramDatabase.trySaveToDisk();
|
|
||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
|
||||||
|
|
||||||
if (insertAfter == 0) {
|
|
||||||
sender.sendMessage(Colors.PRIMARY + "Line inserted before line n.1!");
|
|
||||||
} else if (insertAfter == oldLinesAmount) {
|
|
||||||
sender.sendMessage(Colors.PRIMARY + "Line appended at the end!");
|
|
||||||
Messages.sendTip(sender, "You can use \"/" + label + " addline\" to add a line at the end.");
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Colors.PRIMARY + "Line inserted between lines " + insertAfter + " and " + (insertAfter + 1) + "!");
|
|
||||||
}
|
|
||||||
EditCommand.sendQuickEditCommands(sender, label, hologram.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Inserts a line after the specified index.",
|
|
||||||
"If the index is 0, the line will be put before",
|
|
||||||
"the first line of the hologram.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.EDIT_LINES;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
|
||||||
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class RemovelineCommand extends HologramSubCommand {
|
|
||||||
|
|
||||||
public RemovelineCommand() {
|
|
||||||
super("removeline");
|
|
||||||
setPermission(Permissions.COMMAND_BASE + "removeline");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPossibleArguments() {
|
|
||||||
return "<hologramName> <lineNumber>";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
|
|
||||||
|
|
||||||
int lineNumber = CommandValidator.getInteger(args[1]);
|
|
||||||
|
|
||||||
CommandValidator.isTrue(lineNumber >= 1 && lineNumber <= hologram.size(), "The line number must be between 1 and " + hologram.size() + ".");
|
|
||||||
int index = lineNumber - 1;
|
|
||||||
|
|
||||||
CommandValidator.isTrue(hologram.size() > 1, "The hologram should have at least 1 line. If you want to delete it, use /" + label + " delete.");
|
|
||||||
|
|
||||||
hologram.removeLine(index);
|
|
||||||
hologram.refreshAll();
|
|
||||||
|
|
||||||
HologramDatabase.saveHologram(hologram);
|
|
||||||
HologramDatabase.trySaveToDisk();
|
|
||||||
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
|
||||||
|
|
||||||
sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " removed!");
|
|
||||||
EditCommand.sendQuickEditCommands(sender, label, hologram.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Removes a line from a hologram.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.EDIT_LINES;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
|
||||||
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
|
||||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
|
||||||
import me.filoghost.holographicdisplays.common.Utils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SetlineCommand extends HologramSubCommand {
|
|
||||||
|
|
||||||
public SetlineCommand() {
|
|
||||||
super("setline");
|
|
||||||
setPermission(Permissions.COMMAND_BASE + "setline");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPossibleArguments() {
|
|
||||||
return "<hologramName> <lineNumber> <newText>";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
|
|
||||||
String serializedLine = Utils.join(args, " ", 2, args.length);
|
|
||||||
|
|
||||||
int lineNumber = CommandValidator.getInteger(args[1]);
|
|
||||||
CommandValidator.isTrue(lineNumber >= 1 && lineNumber <= hologram.size(), "The line number must be between 1 and " + hologram.size() + ".");
|
|
||||||
int index = lineNumber - 1;
|
|
||||||
|
|
||||||
CraftHologramLine line = CommandValidator.parseHologramLine(hologram, serializedLine, true);
|
|
||||||
|
|
||||||
hologram.getLinesUnsafe().get(index).despawn();
|
|
||||||
hologram.getLinesUnsafe().set(index, line);
|
|
||||||
hologram.refreshAll();
|
|
||||||
|
|
||||||
HologramDatabase.saveHologram(hologram);
|
|
||||||
HologramDatabase.trySaveToDisk();
|
|
||||||
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
|
||||||
|
|
||||||
sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " changed!");
|
|
||||||
EditCommand.sendQuickEditCommands(sender, label, hologram.getName());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Changes a line of a hologram.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.EDIT_LINES;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
|
||||||
|
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class TeleportCommand extends HologramSubCommand {
|
|
||||||
|
|
||||||
public TeleportCommand() {
|
|
||||||
super("teleport", "tp");
|
|
||||||
setPermission(Permissions.COMMAND_BASE + "teleport");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPossibleArguments() {
|
|
||||||
return "<hologramName>";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
Player player = CommandValidator.getPlayerSender(sender);
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
|
|
||||||
|
|
||||||
Location loc = hologram.getLocation();
|
|
||||||
loc.setPitch(90);
|
|
||||||
player.teleport(loc, TeleportCause.PLUGIN);
|
|
||||||
player.sendMessage(Colors.PRIMARY + "You were teleported to the hologram named '" + hologram.getName() + "'.");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Teleports you to the given hologram.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.common.Utils;
|
||||||
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
|
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
|
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class AddlineCommand extends LineEditingCommand {
|
||||||
|
|
||||||
|
public AddlineCommand() {
|
||||||
|
super("addline");
|
||||||
|
setMinArgs(2);
|
||||||
|
setUsageArgs("<hologram> <text>");
|
||||||
|
setDescription("Adds a line to an existing hologram.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
|
String serializedLine = Utils.join(args, " ", 1, args.length);
|
||||||
|
|
||||||
|
CraftHologramLine line = HologramCommandValidate.parseHologramLine(hologram, serializedLine, true);
|
||||||
|
hologram.getLinesUnsafe().add(line);
|
||||||
|
hologram.refreshAll();
|
||||||
|
|
||||||
|
HologramDatabase.saveHologram(hologram);
|
||||||
|
HologramDatabase.trySaveToDisk();
|
||||||
|
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
||||||
|
|
||||||
|
sender.sendMessage(Colors.PRIMARY + "Line added!");
|
||||||
|
EditCommand.sendQuickEditCommands(context, hologram);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class AlignCommand extends HologramSubCommand {
|
||||||
|
|
||||||
|
public AlignCommand() {
|
||||||
|
super("align");
|
||||||
|
setMinArgs(3);
|
||||||
|
setUsageArgs("<X | Y | Z | XZ> <hologram> <referenceHologram>");
|
||||||
|
setDescription("Aligns the first hologram to the second, in the specified axis.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[1]);
|
||||||
|
NamedHologram referenceHologram = HologramCommandValidate.getNamedHologram(args[2]);
|
||||||
|
|
||||||
|
CommandValidate.check(hologram != referenceHologram, "The hologram must not be the same!");
|
||||||
|
|
||||||
|
Location loc = hologram.getLocation();
|
||||||
|
|
||||||
|
String axis = args[0];
|
||||||
|
if (axis.equalsIgnoreCase("x")) {
|
||||||
|
loc.setX(referenceHologram.getX());
|
||||||
|
} else if (axis.equalsIgnoreCase("y")) {
|
||||||
|
loc.setY(referenceHologram.getY());
|
||||||
|
} else if (axis.equalsIgnoreCase("z")) {
|
||||||
|
loc.setZ(referenceHologram.getZ());
|
||||||
|
} else if (axis.equalsIgnoreCase("xz")) {
|
||||||
|
loc.setX(referenceHologram.getX());
|
||||||
|
loc.setZ(referenceHologram.getZ());
|
||||||
|
} else {
|
||||||
|
throw new CommandException("You must specify either X, Y, Z or XZ, " + axis + " is not a valid axis.");
|
||||||
|
}
|
||||||
|
|
||||||
|
hologram.teleport(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ());
|
||||||
|
hologram.despawnEntities();
|
||||||
|
hologram.refreshAll();
|
||||||
|
|
||||||
|
HologramDatabase.saveHologram(hologram);
|
||||||
|
HologramDatabase.trySaveToDisk();
|
||||||
|
sender.sendMessage(Colors.PRIMARY + "Hologram \"" + hologram.getName() + "\" aligned to the hologram \"" + referenceHologram.getName() + "\" on the " + axis.toUpperCase() + " axis.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
|
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class CopyCommand extends HologramSubCommand {
|
||||||
|
|
||||||
|
public CopyCommand() {
|
||||||
|
super("copy");
|
||||||
|
setMinArgs(2);
|
||||||
|
setUsageArgs("<fromHologram> <toHologram>");
|
||||||
|
setDescription("Copies the contents of a hologram into another one.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
|
NamedHologram fromHologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
|
NamedHologram toHologram = HologramCommandValidate.getNamedHologram(args[1]);
|
||||||
|
|
||||||
|
toHologram.clearLines();
|
||||||
|
for (CraftHologramLine line : fromHologram.getLinesUnsafe()) {
|
||||||
|
CraftHologramLine clonedLine = HologramCommandValidate.parseHologramLine(toHologram, HologramDatabase.serializeHologramLine(line), false);
|
||||||
|
toHologram.getLinesUnsafe().add(clonedLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
toHologram.refreshAll();
|
||||||
|
|
||||||
|
HologramDatabase.saveHologram(toHologram);
|
||||||
|
HologramDatabase.trySaveToDisk();
|
||||||
|
|
||||||
|
sender.sendMessage(Colors.PRIMARY + "Hologram \"" + fromHologram.getName() + "\" copied into hologram \"" + toHologram.getName() + "\"!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,54 +3,47 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
import me.filoghost.holographicdisplays.common.Utils;
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||||
import me.filoghost.holographicdisplays.common.Utils;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CreateCommand extends HologramSubCommand {
|
public class CreateCommand extends HologramSubCommand {
|
||||||
|
|
||||||
public CreateCommand() {
|
public CreateCommand() {
|
||||||
super("create");
|
super("create");
|
||||||
setPermission(Permissions.COMMAND_BASE + "create");
|
setMinArgs(1);
|
||||||
}
|
setUsageArgs("<hologramName> [text]");
|
||||||
|
setDescription(
|
||||||
@Override
|
"Creates a new hologram with the given name, that must",
|
||||||
public String getPossibleArguments() {
|
"be alphanumeric. The name will be used as reference to",
|
||||||
return "<hologramName> [text]";
|
"that hologram for editing commands.");
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
Player player = CommandValidator.getPlayerSender(sender);
|
Player player = CommandValidate.getPlayerSender(sender);
|
||||||
String hologramName = args[0];
|
String hologramName = args[0];
|
||||||
|
|
||||||
if (!hologramName.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.");
|
throw new CommandException("The name must contain only alphanumeric chars, underscores and hyphens.");
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandValidator.isTrue(!NamedHologramManager.isExistingHologram(hologramName), "A hologram with that name already exists.");
|
CommandValidate.check(!NamedHologramManager.isExistingHologram(hologramName), "A hologram with that name already exists.");
|
||||||
|
|
||||||
Location spawnLoc = player.getLocation();
|
Location spawnLoc = player.getLocation();
|
||||||
boolean moveUp = player.isOnGround();
|
boolean moveUp = player.isOnGround();
|
||||||
@ -63,13 +56,13 @@ public class CreateCommand extends HologramSubCommand {
|
|||||||
|
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
String text = Utils.join(args, " ", 1, args.length);
|
String text = Utils.join(args, " ", 1, args.length);
|
||||||
CommandValidator.isTrue(!text.equalsIgnoreCase("{empty}"), "The first line should not be empty.");
|
CommandValidate.check(!text.equalsIgnoreCase("{empty}"), "The first line should not be empty.");
|
||||||
|
|
||||||
CraftHologramLine line = CommandValidator.parseHologramLine(hologram, text, true);
|
CraftHologramLine line = HologramCommandValidate.parseHologramLine(hologram, text, true);
|
||||||
hologram.getLinesUnsafe().add(line);
|
hologram.getLinesUnsafe().add(line);
|
||||||
player.sendMessage(Colors.SECONDARY_SHADOW + "(Change the lines with /" + label + " edit " + hologram.getName() + ")");
|
player.sendMessage(Colors.SECONDARY_SHADOW + "(Change the lines with /" + context.getRootLabel() + " edit " + hologram.getName() + ")");
|
||||||
} else {
|
} else {
|
||||||
hologram.appendTextLine("Default hologram. Change it with " + Colors.PRIMARY + "/" + label + " edit " + hologram.getName());
|
hologram.appendTextLine("Default hologram. Change it with " + Colors.PRIMARY + "/" + context.getRootLabel() + " edit " + hologram.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
NamedHologramManager.addHologram(hologram);
|
NamedHologramManager.addHologram(hologram);
|
||||||
@ -83,21 +76,8 @@ public class CreateCommand extends HologramSubCommand {
|
|||||||
player.sendMessage(Colors.PRIMARY + "You created a hologram named '" + hologram.getName() + "'.");
|
player.sendMessage(Colors.PRIMARY + "You created a hologram named '" + hologram.getName() + "'.");
|
||||||
|
|
||||||
if (moveUp) {
|
if (moveUp) {
|
||||||
player.sendMessage(Colors.SECONDARY_SHADOW + "(You were on the ground, the hologram was automatically moved up. If you use /" + label + " movehere " + hologram.getName() + ", the hologram will be moved to your feet)");
|
player.sendMessage(Colors.SECONDARY_SHADOW + "(You were on the ground, the hologram was automatically moved up. If you use /" + context.getRootLabel() + " movehere " + hologram.getName() + ", the hologram will be moved to your feet)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList(
|
|
||||||
"Creates a new hologram with the given name, that must",
|
|
||||||
"be alphanumeric. The name will be used as reference to",
|
|
||||||
"that hologram for editing commands.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -3,13 +3,13 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.api.Hologram;
|
import me.filoghost.holographicdisplays.api.Hologram;
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
import me.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
import me.filoghost.holographicdisplays.object.PluginHologram;
|
import me.filoghost.holographicdisplays.object.PluginHologram;
|
||||||
@ -19,9 +19,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@ -29,21 +27,12 @@ public class DebugCommand extends HologramSubCommand {
|
|||||||
|
|
||||||
public DebugCommand() {
|
public DebugCommand() {
|
||||||
super("debug");
|
super("debug");
|
||||||
setPermission(Permissions.COMMAND_BASE + "debug");
|
setShowInHelpCommand(false);
|
||||||
|
setDescription("Displays information useful for debugging.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPossibleArguments() {
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) {
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) {
|
|
||||||
boolean foundAnyHologram = false;
|
boolean foundAnyHologram = false;
|
||||||
|
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
@ -98,17 +87,6 @@ public class DebugCommand extends HologramSubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Displays information useful for debugging.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.HIDDEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static class HologramDebugInfo {
|
private static class HologramDebugInfo {
|
||||||
|
|
||||||
private int aliveEntities;
|
private int aliveEntities;
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class DeleteCommand extends HologramSubCommand {
|
||||||
|
|
||||||
|
public DeleteCommand() {
|
||||||
|
super("delete", "remove");
|
||||||
|
setMinArgs(1);
|
||||||
|
setUsageArgs("<hologram>");
|
||||||
|
setDescription("Deletes a hologram. Cannot be undone.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
|
|
||||||
|
hologram.delete();
|
||||||
|
NamedHologramManager.removeHologram(hologram);
|
||||||
|
HologramDatabase.deleteHologram(hologram.getName());
|
||||||
|
|
||||||
|
HologramDatabase.trySaveToDisk();
|
||||||
|
sender.sendMessage(Colors.PRIMARY + "You deleted the hologram '" + hologram.getName() + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,17 +3,17 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
import me.filoghost.holographicdisplays.commands.Messages;
|
import me.filoghost.holographicdisplays.commands.Messages;
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
@ -25,7 +25,6 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class EditCommand extends HologramSubCommand {
|
public class EditCommand extends HologramSubCommand {
|
||||||
@ -40,35 +39,25 @@ public class EditCommand extends HologramSubCommand {
|
|||||||
|
|
||||||
public EditCommand() {
|
public EditCommand() {
|
||||||
super("edit");
|
super("edit");
|
||||||
setPermission(Permissions.COMMAND_BASE + "edit");
|
setMinArgs(1);
|
||||||
|
setUsageArgs("<hologram>");
|
||||||
|
setDescription("Shows the commands to manipulate an existing hologram.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPossibleArguments() {
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
return "<hologramName>";
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
|
|
||||||
|
|
||||||
sender.sendMessage("");
|
sender.sendMessage("");
|
||||||
Messages.sendTitle(sender, "How to edit the hologram '" + hologram.getName() + "'");
|
Messages.sendTitle(sender, "How to edit the hologram '" + hologram.getName() + "'");
|
||||||
for (HologramSubCommand subCommand : HolographicDisplays.getCommandHandler().getSubCommands()) {
|
for (HologramSubCommand subCommand : HolographicDisplays.getCommandManager().getSubCommands()) {
|
||||||
if (subCommand.getType() == SubCommandType.EDIT_LINES) {
|
if (subCommand instanceof LineEditingCommand) {
|
||||||
String usage = "/" + label + " " + subCommand.getName() + (subCommand.getPossibleArguments().length() > 0 ? " " + subCommand.getPossibleArguments().replace("<hologramName>", hologram.getName()).replace("<hologram>", hologram.getName()) : "");
|
String usage = subCommand.getFullUsageText(context).replace("<hologram>", hologram.getName());
|
||||||
|
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
|
|
||||||
List<String> help = new ArrayList<>();
|
List<String> help = new ArrayList<>();
|
||||||
help.add(Colors.PRIMARY + usage);
|
help.add(Colors.PRIMARY + usage);
|
||||||
for (String tutLine : subCommand.getTutorial()) {
|
for (String tutLine : subCommand.getDescription(context)) {
|
||||||
help.add(Colors.SECONDARY_SHADOW + tutLine);
|
help.add(Colors.SECONDARY_SHADOW + tutLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,50 +78,39 @@ public class EditCommand extends HologramSubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendQuickEditCommands(CommandSender sender, String label, String hologramName) {
|
public static void sendQuickEditCommands(SubCommandContext commandContext, NamedHologram hologram) {
|
||||||
if (!Configuration.quickEditCommands) {
|
if (!Configuration.quickEditCommands) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(sender instanceof Player)) {
|
if (!(commandContext.getSender() instanceof Player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComponentBuilder message = new ComponentBuilder("EDIT LINES:").color(ChatColor.GRAY).bold(true).append(" ", FormatRetention.NONE);
|
ComponentBuilder message = new ComponentBuilder("EDIT LINES:").color(ChatColor.GRAY).bold(true).append(" ", FormatRetention.NONE);
|
||||||
|
|
||||||
for (QuickCommandInfo quickEditCommand : QUICK_EDIT_COMMANDS) {
|
for (QuickCommandInfo quickEditCommand : QUICK_EDIT_COMMANDS) {
|
||||||
HologramSubCommand subCommand = HolographicDisplays.getCommandHandler().getSubCommand(quickEditCommand.commandClass);
|
HologramSubCommand subCommand = HolographicDisplays.getCommandManager().getSubCommand(quickEditCommand.commandClass);
|
||||||
|
|
||||||
// Assume first argument is always "<hologram>" and remove it
|
// Assume first argument is always "<hologram>" and remove it
|
||||||
String arguments = subCommand.getPossibleArguments();
|
String usageArgs = subCommand.getUsageArgs();
|
||||||
if (arguments.contains(" ")) {
|
if (usageArgs != null && usageArgs.contains(" ")) {
|
||||||
arguments = arguments.substring(arguments.indexOf(" ") + 1);
|
usageArgs = usageArgs.substring(usageArgs.indexOf(" ") + 1);
|
||||||
} else {
|
} else {
|
||||||
arguments = "";
|
usageArgs = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
String usage = "/" + label + " " + subCommand.getName() + " " + hologramName + " ";
|
String usage = "/" + commandContext.getRootLabel() + " " + subCommand.getName() + " " + hologram + " ";
|
||||||
message.append("[" + quickEditCommand.chatName + "]").color(ChatColor.DARK_AQUA)
|
message.append("[" + quickEditCommand.chatName + "]").color(ChatColor.DARK_AQUA)
|
||||||
.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage))
|
.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage))
|
||||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(
|
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(
|
||||||
ChatColor.GRAY + "Click to insert in chat the highlighted part of the command:\n" +
|
ChatColor.GRAY + "Click to insert in chat the highlighted part of the command:\n" +
|
||||||
ChatColor.YELLOW + usage + ChatColor.DARK_GRAY + arguments)));
|
ChatColor.YELLOW + usage + ChatColor.DARK_GRAY + usageArgs)));
|
||||||
message.append(" ", FormatRetention.NONE);
|
message.append(" ", FormatRetention.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
((Player) sender).spigot().sendMessage(message.create());
|
((Player) commandContext.getSender()).spigot().sendMessage(message.create());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Shows the commands to manipulate an existing hologram.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static class QuickCommandInfo {
|
private static class QuickCommandInfo {
|
||||||
|
|
@ -3,13 +3,13 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
import me.filoghost.holographicdisplays.commands.Messages;
|
import me.filoghost.holographicdisplays.commands.Messages;
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
@ -26,33 +26,23 @@ public class HelpCommand extends HologramSubCommand {
|
|||||||
|
|
||||||
public HelpCommand() {
|
public HelpCommand() {
|
||||||
super("help");
|
super("help");
|
||||||
setPermission(Permissions.COMMAND_BASE + "help");
|
setShowInHelpCommand(false);
|
||||||
|
setDescription("Show the list of commands.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPossibleArguments() {
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) {
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) {
|
|
||||||
sender.sendMessage("");
|
sender.sendMessage("");
|
||||||
Messages.sendTitle(sender, "Holographic Displays Commands");
|
Messages.sendTitle(sender, "Holographic Displays Commands");
|
||||||
for (HologramSubCommand subCommand : HolographicDisplays.getCommandHandler().getSubCommands()) {
|
for (HologramSubCommand subCommand : HolographicDisplays.getCommandManager().getSubCommands()) {
|
||||||
if (subCommand.getType() == SubCommandType.GENERIC) {
|
if (subCommand.isShowInHelpCommand()) {
|
||||||
String usage = "/" + label + " " + subCommand.getName() + (subCommand.getPossibleArguments().length() > 0 ? " " + subCommand.getPossibleArguments() : "");
|
String usage = subCommand.getFullUsageText(context);
|
||||||
|
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
|
|
||||||
List<String> help = new ArrayList<>();
|
List<String> help = new ArrayList<>();
|
||||||
help.add(Colors.PRIMARY + usage);
|
help.add(Colors.PRIMARY + usage);
|
||||||
for (String tutLine : subCommand.getTutorial()) {
|
for (String tutLine : subCommand.getDescription(context)) {
|
||||||
help.add(Colors.SECONDARY_SHADOW + tutLine);
|
help.add(Colors.SECONDARY_SHADOW + tutLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,15 +76,4 @@ public class HelpCommand extends HologramSubCommand {
|
|||||||
.create());
|
.create());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.HIDDEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.commands.Messages;
|
||||||
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
|
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class InfoCommand extends LineEditingCommand {
|
||||||
|
|
||||||
|
public InfoCommand() {
|
||||||
|
super("info", "details");
|
||||||
|
setMinArgs(1);
|
||||||
|
setUsageArgs("<hologram>");
|
||||||
|
setDescription("Shows the lines of a hologram.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
|
|
||||||
|
sender.sendMessage("");
|
||||||
|
Messages.sendTitle(sender, "Lines of the hologram '" + hologram.getName() + "'");
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for (CraftHologramLine line : hologram.getLinesUnsafe()) {
|
||||||
|
sender.sendMessage(Colors.SECONDARY + Colors.BOLD + (++index) + Colors.SECONDARY_SHADOW + ". " + Colors.SECONDARY + HologramDatabase.serializeHologramLine(line));
|
||||||
|
}
|
||||||
|
EditCommand.sendQuickEditCommands(context, hologram);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.commands.Messages;
|
||||||
|
import me.filoghost.holographicdisplays.common.Utils;
|
||||||
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
|
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
|
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class InsertlineCommand extends LineEditingCommand {
|
||||||
|
|
||||||
|
public InsertlineCommand() {
|
||||||
|
super("insertline");
|
||||||
|
setMinArgs(3);
|
||||||
|
setUsageArgs("<hologram> <lineNumber> <text>");
|
||||||
|
setDescription(
|
||||||
|
"Inserts a line after the specified index.",
|
||||||
|
"If the index is 0, the line will be put before",
|
||||||
|
"the first line of the hologram.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
|
int insertAfter = CommandValidate.parseInteger(args[1]);
|
||||||
|
String serializedLine = Utils.join(args, " ", 2, args.length);
|
||||||
|
|
||||||
|
int oldLinesAmount = hologram.size();
|
||||||
|
|
||||||
|
CommandValidate.check(insertAfter >= 0 && insertAfter <= oldLinesAmount, "The number must be between 0 and " + hologram.size() + "(amount of lines of the hologram).");
|
||||||
|
|
||||||
|
CraftHologramLine line = HologramCommandValidate.parseHologramLine(hologram, serializedLine, true);
|
||||||
|
hologram.getLinesUnsafe().add(insertAfter, line);
|
||||||
|
hologram.refreshAll();
|
||||||
|
|
||||||
|
HologramDatabase.saveHologram(hologram);
|
||||||
|
HologramDatabase.trySaveToDisk();
|
||||||
|
|
||||||
|
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
||||||
|
|
||||||
|
if (insertAfter == 0) {
|
||||||
|
sender.sendMessage(Colors.PRIMARY + "Line inserted before line n.1!");
|
||||||
|
} else if (insertAfter == oldLinesAmount) {
|
||||||
|
sender.sendMessage(Colors.PRIMARY + "Line appended at the end!");
|
||||||
|
Messages.sendTip(sender, "You can use \"/" + context.getRootLabel() + " addline\" to add a line at the end.");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(Colors.PRIMARY + "Line inserted between lines " + insertAfter + " and " + (insertAfter + 1) + "!");
|
||||||
|
}
|
||||||
|
EditCommand.sendQuickEditCommands(context, hologram);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
|
|
||||||
|
public abstract class LineEditingCommand extends HologramSubCommand {
|
||||||
|
|
||||||
|
protected LineEditingCommand(String name, String... aliases) {
|
||||||
|
super(name, aliases);
|
||||||
|
setShowInHelpCommand(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,44 +3,33 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
import me.filoghost.holographicdisplays.commands.Messages;
|
import me.filoghost.holographicdisplays.commands.Messages;
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ListCommand extends HologramSubCommand {
|
public class ListCommand extends HologramSubCommand {
|
||||||
|
|
||||||
private static final int HOLOGRAMS_PER_PAGE = 10;
|
private static final int HOLOGRAMS_PER_PAGE = 10;
|
||||||
|
|
||||||
public ListCommand() {
|
public ListCommand() {
|
||||||
super("list");
|
super("list");
|
||||||
setPermission(Permissions.COMMAND_BASE + "list");
|
setMinArgs(0);
|
||||||
|
setUsageArgs("[page]");
|
||||||
|
setDescription("Lists all the existing holograms.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPossibleArguments() {
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
return "[page]";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
int page = args.length > 0 ? CommandValidate.parseInteger(args[0]) : 1;
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
|
|
||||||
int page = args.length > 0 ? CommandValidator.getInteger(args[0]) : 1;
|
|
||||||
|
|
||||||
if (page < 1) {
|
if (page < 1) {
|
||||||
throw new CommandException("Page number must be 1 or greater.");
|
throw new CommandException("Page number must be 1 or greater.");
|
||||||
@ -51,9 +40,8 @@ public class ListCommand extends HologramSubCommand {
|
|||||||
totalPages++;
|
totalPages++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (NamedHologramManager.size() == 0) {
|
if (NamedHologramManager.size() == 0) {
|
||||||
throw new CommandException("There are no holograms yet. Create one with /" + label + " create.");
|
throw new CommandException("There are no holograms yet. Create one with /" + context.getRootLabel() + " create.");
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage("");
|
sender.sendMessage("");
|
||||||
@ -68,19 +56,9 @@ public class ListCommand extends HologramSubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (page < totalPages) {
|
if (page < totalPages) {
|
||||||
Messages.sendTip(sender, "See the next page with /" + label + " list " + (page + 1));
|
Messages.sendTip(sender, "See the next page with /" + context.getRootLabel() + " list " + (page + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Lists all the existing holograms.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -3,46 +3,35 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MovehereCommand extends HologramSubCommand {
|
public class MovehereCommand extends HologramSubCommand {
|
||||||
|
|
||||||
|
|
||||||
public MovehereCommand() {
|
public MovehereCommand() {
|
||||||
super("movehere");
|
super("movehere");
|
||||||
setPermission(Permissions.COMMAND_BASE + "movehere");
|
setMinArgs(1);
|
||||||
|
setUsageArgs("<hologram>");
|
||||||
|
setDescription("Moves a hologram to your location.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPossibleArguments() {
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
return "<hologramName>";
|
Player player = CommandValidate.getPlayerSender(sender);
|
||||||
}
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
Player player = CommandValidator.getPlayerSender(sender);
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
|
|
||||||
|
|
||||||
hologram.teleport(player.getWorld(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
|
hologram.teleport(player.getWorld(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
|
||||||
hologram.despawnEntities();
|
hologram.despawnEntities();
|
||||||
@ -56,14 +45,4 @@ public class MovehereCommand extends HologramSubCommand {
|
|||||||
player.sendMessage(Colors.PRIMARY + "You moved the hologram '" + hologram.getName() + "' near to you.");
|
player.sendMessage(Colors.PRIMARY + "You moved the hologram '" + hologram.getName() + "' near to you.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Moves a hologram to your location.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -3,14 +3,14 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
import me.filoghost.holographicdisplays.commands.Messages;
|
import me.filoghost.holographicdisplays.commands.Messages;
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
import me.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -18,31 +18,22 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NearCommand extends HologramSubCommand {
|
public class NearCommand extends HologramSubCommand {
|
||||||
|
|
||||||
public NearCommand() {
|
public NearCommand() {
|
||||||
super("near");
|
super("near");
|
||||||
setPermission(Permissions.COMMAND_BASE + "near");
|
setMinArgs(1);
|
||||||
|
setUsageArgs("<radius>");
|
||||||
|
setDescription("Get a list of near holograms.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPossibleArguments() {
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
return "<radius>";
|
Player player = CommandValidate.getPlayerSender(sender);
|
||||||
}
|
int radius = CommandValidate.parseInteger(args[0]);
|
||||||
|
CommandValidate.check(radius > 0, "Radius must be at least 1.");
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
Player player = CommandValidator.getPlayerSender(sender);
|
|
||||||
int radius = CommandValidator.getInteger(args[0]);
|
|
||||||
CommandValidator.isTrue(radius > 0, "Radius must be at least 1.");
|
|
||||||
|
|
||||||
World world = player.getWorld();
|
World world = player.getWorld();
|
||||||
int radiusSquared = radius * radius;
|
int radiusSquared = radius * radius;
|
||||||
@ -54,7 +45,7 @@ public class NearCommand extends HologramSubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandValidator.isTrue(!nearHolograms.isEmpty(), "There are no holograms in the given radius.");
|
CommandValidate.check(!nearHolograms.isEmpty(), "There are no holograms in the given radius.");
|
||||||
|
|
||||||
Messages.sendTitle(player, "Near holograms");
|
Messages.sendTitle(player, "Near holograms");
|
||||||
for (NamedHologram nearHologram : nearHolograms) {
|
for (NamedHologram nearHologram : nearHolograms) {
|
||||||
@ -62,14 +53,4 @@ public class NearCommand extends HologramSubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Get a list of near holograms.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -3,16 +3,17 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.CommandContext;
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
|
||||||
import me.filoghost.holographicdisplays.commands.Messages;
|
import me.filoghost.holographicdisplays.commands.Messages;
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.exception.TooWideException;
|
import me.filoghost.holographicdisplays.exception.TooWideException;
|
||||||
import me.filoghost.holographicdisplays.exception.UnreadableImageException;
|
import me.filoghost.holographicdisplays.exception.UnreadableImageException;
|
||||||
import me.filoghost.holographicdisplays.image.ImageMessage;
|
import me.filoghost.holographicdisplays.image.ImageMessage;
|
||||||
@ -32,27 +33,35 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ReadimageCommand extends HologramSubCommand {
|
public class ReadimageCommand extends LineEditingCommand {
|
||||||
|
|
||||||
|
|
||||||
public ReadimageCommand() {
|
public ReadimageCommand() {
|
||||||
super("readimage", "image");
|
super("readimage", "image");
|
||||||
setPermission(Permissions.COMMAND_BASE + "readimage");
|
setMinArgs(3);
|
||||||
|
setUsageArgs("<hologram> <imageWithExtension> <width>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPossibleArguments() {
|
public List<String> getDescription(CommandContext context) {
|
||||||
return "<hologram> <imageWithExtension> <width>";
|
return Arrays.asList(
|
||||||
|
"Reads an image from a file. Tutorial:",
|
||||||
|
"1) Move the image in the plugin's folder",
|
||||||
|
"2) Do not use spaces in the name",
|
||||||
|
"3) Do " + getFullUsageText(context),
|
||||||
|
"4) Choose <width> to automatically resize the image",
|
||||||
|
"5) (Optional) Use the flag '-a' if you only want to append",
|
||||||
|
" the image to the hologram without clearing the lines",
|
||||||
|
"",
|
||||||
|
"Example: you have an image named 'logo.png', you want to append",
|
||||||
|
"it to the lines of the hologram named 'test', with a width of",
|
||||||
|
"50 pixels. In this case you would execute the following command:",
|
||||||
|
ChatColor.YELLOW + "/" + context.getRootLabel() + " " + getName() + " test logo.png 50 -a",
|
||||||
|
"",
|
||||||
|
"The symbols used to create the image are taken from the config.yml.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMinimumArguments() {
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
|
|
||||||
boolean append = false;
|
boolean append = false;
|
||||||
|
|
||||||
@ -68,11 +77,11 @@ public class ReadimageCommand extends HologramSubCommand {
|
|||||||
|
|
||||||
args = newArgs.toArray(new String[0]);
|
args = newArgs.toArray(new String[0]);
|
||||||
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
|
|
||||||
int width = CommandValidator.getInteger(args[2]);
|
int width = CommandValidate.parseInteger(args[2]);
|
||||||
|
|
||||||
CommandValidator.isTrue(width >= 2, "The width of the image must be 2 or greater.");
|
CommandValidate.check(width >= 2, "The width of the image must be 2 or greater.");
|
||||||
|
|
||||||
boolean isUrl = false;
|
boolean isUrl = false;
|
||||||
|
|
||||||
@ -89,7 +98,7 @@ public class ReadimageCommand extends HologramSubCommand {
|
|||||||
Messages.sendWarning(sender, "The image path seems to be an URL. If so, please use http:// or https:// in the path.");
|
Messages.sendWarning(sender, "The image path seems to be an URL. If so, please use http:// or https:// in the path.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Path targetImage = CommandValidator.getUserReadableFile(fileName);
|
Path targetImage = HologramCommandValidate.getUserReadableFile(fileName);
|
||||||
image = FileUtils.readImage(targetImage);
|
image = FileUtils.readImage(targetImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,27 +142,4 @@ public class ReadimageCommand extends HologramSubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Reads an image from a file. Tutorial:",
|
|
||||||
"1) Move the image in the plugin's folder",
|
|
||||||
"2) Do not use spaces in the name",
|
|
||||||
"3) Do /holograms read <hologram> <image> <width>",
|
|
||||||
"4) Choose <width> to automatically resize the image",
|
|
||||||
"5) (Optional) Use the flag '-a' if you only want to append",
|
|
||||||
" the image to the hologram without clearing the lines",
|
|
||||||
"",
|
|
||||||
"Example: you have an image named 'logo.png', you want to append",
|
|
||||||
"it to the lines of the hologram named 'test', with a width of",
|
|
||||||
"50 pixels. In this case you would execute the following command:",
|
|
||||||
ChatColor.YELLOW + "/holograms readimage test logo.png 50 -a",
|
|
||||||
"",
|
|
||||||
"The symbols used to create the image are taken from the config.yml.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.EDIT_LINES;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -3,18 +3,18 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.CommandContext;
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
import me.filoghost.holographicdisplays.commands.CommandValidator;
|
|
||||||
import me.filoghost.holographicdisplays.commands.Messages;
|
import me.filoghost.holographicdisplays.commands.Messages;
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.common.Utils;
|
import me.filoghost.holographicdisplays.common.Utils;
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
import me.filoghost.holographicdisplays.disk.HologramLineParser;
|
import me.filoghost.holographicdisplays.disk.HologramLineParser;
|
||||||
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
||||||
import me.filoghost.holographicdisplays.exception.CommandException;
|
|
||||||
import me.filoghost.holographicdisplays.exception.HologramLineParseException;
|
import me.filoghost.holographicdisplays.exception.HologramLineParseException;
|
||||||
import me.filoghost.holographicdisplays.object.NamedHologram;
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||||
@ -29,30 +29,35 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ReadtextCommand extends HologramSubCommand {
|
public class ReadtextCommand extends LineEditingCommand {
|
||||||
|
|
||||||
public ReadtextCommand() {
|
public ReadtextCommand() {
|
||||||
super("readtext", "readlines");
|
super("readtext", "readlines");
|
||||||
setPermission(Permissions.COMMAND_BASE + "readtext");
|
setMinArgs(2);
|
||||||
|
setUsageArgs("<hologram> <fileWithExtension>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPossibleArguments() {
|
public List<String> getDescription(CommandContext context) {
|
||||||
return "<hologramName> <fileWithExtension>";
|
return Arrays.asList(
|
||||||
|
"Reads the lines from a text file. Tutorial:",
|
||||||
|
"1) Create a new text file in the plugin's folder",
|
||||||
|
"2) Do not use spaces in the name",
|
||||||
|
"3) Each line will be a line in the hologram",
|
||||||
|
"4) Do " + getFullUsageText(context),
|
||||||
|
"",
|
||||||
|
"Example: you have a file named 'info.txt', and you want",
|
||||||
|
"to paste it in the hologram named 'test'. In this case you",
|
||||||
|
"would execute " + ChatColor.YELLOW + "/" + context.getRootLabel() + " " + getName() + " test info.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMinimumArguments() {
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
return 2;
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
|
||||||
NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
|
|
||||||
String fileName = args[1];
|
String fileName = args[1];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Path targetFile = CommandValidator.getUserReadableFile(fileName);
|
Path targetFile = HologramCommandValidate.getUserReadableFile(fileName);
|
||||||
List<String> serializedLines = Files.readAllLines(targetFile);
|
List<String> serializedLines = Files.readAllLines(targetFile);
|
||||||
|
|
||||||
int linesAmount = serializedLines.size();
|
int linesAmount = serializedLines.size();
|
||||||
@ -78,9 +83,9 @@ public class ReadtextCommand extends HologramSubCommand {
|
|||||||
HologramDatabase.saveHologram(hologram);
|
HologramDatabase.saveHologram(hologram);
|
||||||
HologramDatabase.trySaveToDisk();
|
HologramDatabase.trySaveToDisk();
|
||||||
|
|
||||||
if (args[1].contains(".")) {
|
if (fileName.contains(".")) {
|
||||||
if (isImageExtension(args[1].substring(args[1].lastIndexOf('.') + 1))) {
|
if (isImageExtension(fileName.substring(fileName.lastIndexOf('.') + 1))) {
|
||||||
Messages.sendWarning(sender, "The read file has an image's extension. If it is an image, you should use /" + label + " readimage.");
|
Messages.sendWarning(sender, "The read file has an image's extension. If it is an image, you should use /" + context.getRootLabel() + " readimage.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,24 +97,6 @@ public class ReadtextCommand extends HologramSubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Reads the lines from a text file. Tutorial:",
|
|
||||||
"1) Create a new text file in the plugin's folder",
|
|
||||||
"2) Do not use spaces in the name",
|
|
||||||
"3) Each line will be a line in the hologram",
|
|
||||||
"4) Do /holograms readlines <hologramName> <fileWithExtension>",
|
|
||||||
"",
|
|
||||||
"Example: you have a file named 'info.txt', and you want",
|
|
||||||
"to paste it in the hologram named 'test'. In this case you",
|
|
||||||
"would execute "+ ChatColor.YELLOW + "/holograms readlines test info.txt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.EDIT_LINES;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isImageExtension(String input) {
|
private boolean isImageExtension(String input) {
|
||||||
return Arrays.asList("jpg", "png", "jpeg", "gif").contains(input.toLowerCase());
|
return Arrays.asList("jpg", "png", "jpeg", "gif").contains(input.toLowerCase());
|
||||||
}
|
}
|
@ -3,15 +3,15 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
package me.filoghost.holographicdisplays.commands.main.subs;
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
import me.filoghost.fcommons.logging.Log;
|
import me.filoghost.fcommons.logging.Log;
|
||||||
import me.filoghost.holographicdisplays.Colors;
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||||
import me.filoghost.holographicdisplays.Permissions;
|
|
||||||
import me.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerTracker;
|
import me.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerTracker;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
import me.filoghost.holographicdisplays.commands.Messages;
|
import me.filoghost.holographicdisplays.commands.Messages;
|
||||||
import me.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
|
||||||
import me.filoghost.holographicdisplays.common.Utils;
|
import me.filoghost.holographicdisplays.common.Utils;
|
||||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
@ -29,29 +29,17 @@ import me.filoghost.holographicdisplays.placeholder.PlaceholdersManager;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ReloadCommand extends HologramSubCommand {
|
public class ReloadCommand extends HologramSubCommand {
|
||||||
|
|
||||||
public ReloadCommand() {
|
public ReloadCommand() {
|
||||||
super("reload");
|
super("reload");
|
||||||
setPermission(Permissions.COMMAND_BASE + "reload");
|
setDescription("Reloads the holograms from the database.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPossibleArguments() {
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) {
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMinimumArguments() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String label, String[] args) {
|
|
||||||
long startMillis = System.currentTimeMillis();
|
long startMillis = System.currentTimeMillis();
|
||||||
|
|
||||||
UnicodeSymbols.load(HolographicDisplays.getInstance());
|
UnicodeSymbols.load(HolographicDisplays.getInstance());
|
||||||
@ -99,14 +87,4 @@ public class ReloadCommand extends HologramSubCommand {
|
|||||||
Bukkit.getPluginManager().callEvent(new HolographicDisplaysReloadEvent());
|
Bukkit.getPluginManager().callEvent(new HolographicDisplaysReloadEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTutorial() {
|
|
||||||
return Arrays.asList("Reloads the holograms from the database.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubCommandType getType() {
|
|
||||||
return SubCommandType.GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
|
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class RemovelineCommand extends LineEditingCommand {
|
||||||
|
|
||||||
|
public RemovelineCommand() {
|
||||||
|
super("removeline");
|
||||||
|
setMinArgs(2);
|
||||||
|
setUsageArgs("<hologram> <lineNumber>");
|
||||||
|
setDescription("Removes a line from a hologram.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
|
|
||||||
|
int lineNumber = CommandValidate.parseInteger(args[1]);
|
||||||
|
|
||||||
|
CommandValidate.check(lineNumber >= 1 && lineNumber <= hologram.size(), "The line number must be between 1 and " + hologram.size() + ".");
|
||||||
|
int index = lineNumber - 1;
|
||||||
|
|
||||||
|
CommandValidate.check(hologram.size() > 1, "The hologram should have at least 1 line. If you want to delete it, use /" + context.getRootLabel() + " delete.");
|
||||||
|
|
||||||
|
hologram.removeLine(index);
|
||||||
|
hologram.refreshAll();
|
||||||
|
|
||||||
|
HologramDatabase.saveHologram(hologram);
|
||||||
|
HologramDatabase.trySaveToDisk();
|
||||||
|
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
||||||
|
|
||||||
|
sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " removed!");
|
||||||
|
EditCommand.sendQuickEditCommands(context, hologram);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.common.Utils;
|
||||||
|
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||||
|
import me.filoghost.holographicdisplays.event.NamedHologramEditedEvent;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
|
import me.filoghost.holographicdisplays.object.line.CraftHologramLine;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class SetlineCommand extends LineEditingCommand {
|
||||||
|
|
||||||
|
public SetlineCommand() {
|
||||||
|
super("setline");
|
||||||
|
setMinArgs(3);
|
||||||
|
setUsageArgs("<hologram> <lineNumber> <newText>");
|
||||||
|
setDescription("Changes a line of a hologram.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
|
String serializedLine = Utils.join(args, " ", 2, args.length);
|
||||||
|
|
||||||
|
int lineNumber = CommandValidate.parseInteger(args[1]);
|
||||||
|
CommandValidate.check(lineNumber >= 1 && lineNumber <= hologram.size(), "The line number must be between 1 and " + hologram.size() + ".");
|
||||||
|
int index = lineNumber - 1;
|
||||||
|
|
||||||
|
CraftHologramLine line = HologramCommandValidate.parseHologramLine(hologram, serializedLine, true);
|
||||||
|
|
||||||
|
hologram.getLinesUnsafe().get(index).despawn();
|
||||||
|
hologram.getLinesUnsafe().set(index, line);
|
||||||
|
hologram.refreshAll();
|
||||||
|
|
||||||
|
HologramDatabase.saveHologram(hologram);
|
||||||
|
HologramDatabase.trySaveToDisk();
|
||||||
|
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
||||||
|
|
||||||
|
sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " changed!");
|
||||||
|
EditCommand.sendQuickEditCommands(context, hologram);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) filoghost and contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package me.filoghost.holographicdisplays.commands.subs;
|
||||||
|
|
||||||
|
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandException;
|
||||||
|
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.Colors;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramCommandValidate;
|
||||||
|
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||||
|
import me.filoghost.holographicdisplays.object.NamedHologram;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
|
||||||
|
|
||||||
|
public class TeleportCommand extends HologramSubCommand {
|
||||||
|
|
||||||
|
public TeleportCommand() {
|
||||||
|
super("teleport", "tp");
|
||||||
|
setMinArgs(1);
|
||||||
|
setUsageArgs("<hologram>");
|
||||||
|
setDescription("Teleports you to the given hologram.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||||
|
Player player = CommandValidate.getPlayerSender(sender);
|
||||||
|
NamedHologram hologram = HologramCommandValidate.getNamedHologram(args[0]);
|
||||||
|
|
||||||
|
Location loc = hologram.getLocation();
|
||||||
|
loc.setPitch(90);
|
||||||
|
player.teleport(loc, TeleportCause.PLUGIN);
|
||||||
|
player.sendMessage(Colors.PRIMARY + "You were teleported to the hologram named '" + hologram.getName() + "'.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,13 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) filoghost and contributors
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package me.filoghost.holographicdisplays.exception;
|
|
||||||
|
|
||||||
public class CommandException extends Exception {
|
|
||||||
|
|
||||||
public CommandException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user