mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-19 23:37:33 +01:00
Refactor internal hologram editing
This commit is contained in:
parent
0b649ff612
commit
4399fd90a7
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.common;
|
||||
|
||||
import me.filoghost.fcommons.Strings;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static double distanceSquared(double locX1, double locX2, double locZ1, double locZ2) {
|
||||
return square(locX1 - locX2) + square(locZ1 - locZ2);
|
||||
}
|
||||
|
||||
public static double square(double num) {
|
||||
return num * num;
|
||||
}
|
||||
|
||||
public static String formatExceptionMessage(Throwable t) {
|
||||
return formatExceptionMessage(t.getMessage());
|
||||
}
|
||||
|
||||
public static String formatExceptionMessage(String message) {
|
||||
if (Strings.isEmpty(message)) {
|
||||
return message;
|
||||
}
|
||||
|
||||
message = Strings.capitalizeFirst(message);
|
||||
char lastChar = message.charAt(message.length() - 1);
|
||||
if (Character.isLetterOrDigit(lastChar)) {
|
||||
message = message + ".";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,6 @@ package me.filoghost.holographicdisplays.plugin.bridge.protocollib;
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.logging.ErrorCollector;
|
||||
import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.common.hologram.StandardHologram;
|
||||
import me.filoghost.holographicdisplays.common.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.common.nms.ProtocolPacketSettings;
|
||||
@ -97,12 +96,18 @@ public class ProtocolLibHook {
|
||||
}
|
||||
|
||||
Location playerLocation = player.getLocation();
|
||||
double distanceSquared = Utils.distanceSquared(playerLocation.getX(), hologram.getX(), playerLocation.getZ(), hologram.getZ());
|
||||
double distanceSquared = distanceSquared(playerLocation.getX(), hologram.getX(), playerLocation.getZ(), hologram.getZ());
|
||||
|
||||
// Approximate, more checks are done for single entities
|
||||
return distanceSquared < 128 * 128;
|
||||
}
|
||||
|
||||
private static double distanceSquared(double locX1, double locX2, double locZ1, double locZ2) {
|
||||
double xDiff = locX1 - locX2;
|
||||
double zDiff = locZ1 - locZ2;
|
||||
return xDiff * xDiff + zDiff * zDiff;
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
@ -9,9 +9,7 @@ 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.common.Utils;
|
||||
import me.filoghost.holographicdisplays.common.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.HolographicDisplays;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.subs.AddlineCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.subs.AlignCommand;
|
||||
@ -35,6 +33,7 @@ import me.filoghost.holographicdisplays.plugin.commands.subs.SetlineCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.subs.TeleportCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.Settings;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
@ -58,27 +57,28 @@ public class HologramCommandManager extends SubCommandManager {
|
||||
|
||||
public HologramCommandManager(ConfigManager configManager, InternalHologramManager internalHologramManager, NMSManager nmsManager) {
|
||||
setName("holograms");
|
||||
InternalHologramEditor hologramEditor = new InternalHologramEditor(internalHologramManager, configManager);
|
||||
this.helpCommand = new HelpCommand(this);
|
||||
this.subCommands = new ArrayList<>();
|
||||
|
||||
subCommands.add(new AddlineCommand(this, internalHologramManager, configManager));
|
||||
subCommands.add(new CreateCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new DeleteCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new EditCommand(this, internalHologramManager));
|
||||
subCommands.add(new ListCommand(internalHologramManager));
|
||||
subCommands.add(new NearCommand(internalHologramManager));
|
||||
subCommands.add(new TeleportCommand(internalHologramManager));
|
||||
subCommands.add(new MovehereCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new AlignCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new CopyCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new AddlineCommand(this, hologramEditor));
|
||||
subCommands.add(new CreateCommand(hologramEditor));
|
||||
subCommands.add(new DeleteCommand(hologramEditor));
|
||||
subCommands.add(new EditCommand(this, hologramEditor));
|
||||
subCommands.add(new ListCommand(hologramEditor));
|
||||
subCommands.add(new NearCommand(hologramEditor));
|
||||
subCommands.add(new TeleportCommand(hologramEditor));
|
||||
subCommands.add(new MovehereCommand(hologramEditor));
|
||||
subCommands.add(new AlignCommand(hologramEditor));
|
||||
subCommands.add(new CopyCommand(hologramEditor));
|
||||
subCommands.add(new ReloadCommand());
|
||||
|
||||
subCommands.add(new RemovelineCommand(this, internalHologramManager, configManager));
|
||||
subCommands.add(new SetlineCommand(this, internalHologramManager, configManager));
|
||||
subCommands.add(new InsertlineCommand(this, internalHologramManager, configManager));
|
||||
subCommands.add(new ReadtextCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new ReadimageCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new InfoCommand(this, internalHologramManager));
|
||||
subCommands.add(new RemovelineCommand(this, hologramEditor));
|
||||
subCommands.add(new SetlineCommand(this, hologramEditor));
|
||||
subCommands.add(new InsertlineCommand(this, hologramEditor));
|
||||
subCommands.add(new ReadtextCommand(hologramEditor));
|
||||
subCommands.add(new ReadimageCommand(hologramEditor));
|
||||
subCommands.add(new InfoCommand(this, hologramEditor));
|
||||
|
||||
subCommands.add(new DebugCommand(nmsManager));
|
||||
subCommands.add(helpCommand);
|
||||
@ -175,7 +175,7 @@ public class HologramCommandManager extends SubCommandManager {
|
||||
|
||||
@Override
|
||||
protected void sendExecutionErrorMessage(CommandContext context, String errorMessage) {
|
||||
context.getSender().sendMessage(ColorScheme.ERROR + Utils.formatExceptionMessage(errorMessage));
|
||||
context.getSender().sendMessage(ColorScheme.ERROR + errorMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.plugin.commands;
|
||||
|
||||
import me.filoghost.fcommons.command.validation.CommandException;
|
||||
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.HologramLineParser;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.HologramLoadException;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.plugin.util.FileUtils;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class HologramCommandValidate {
|
||||
|
||||
public static InternalHologramLine parseHologramLine(InternalHologram hologram, String serializedLine) throws CommandException {
|
||||
try {
|
||||
return HologramLineParser.parseLine(hologram, serializedLine);
|
||||
} catch (HologramLoadException e) {
|
||||
throw new CommandException(Utils.formatExceptionMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
public static InternalHologram getInternalHologram(InternalHologramManager internalHologramManager, String hologramName)
|
||||
throws CommandException {
|
||||
InternalHologram hologram = internalHologramManager.getHologramByName(hologramName);
|
||||
CommandValidate.notNull(hologram, "Cannot find a hologram named \"" + hologramName + "\".");
|
||||
return hologram;
|
||||
}
|
||||
|
||||
public static Path getUserReadableFile(Path dataFolder, String fileName) throws CommandException {
|
||||
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,106 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.plugin.commands;
|
||||
|
||||
import me.filoghost.fcommons.Strings;
|
||||
import me.filoghost.fcommons.command.validation.CommandException;
|
||||
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.HologramLineParser;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.HologramLoadException;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.plugin.util.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public class InternalHologramEditor {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public InternalHologramEditor(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
public InternalHologramLine parseHologramLine(InternalHologram hologram, String serializedLine) throws CommandException {
|
||||
try {
|
||||
return HologramLineParser.parseLine(hologram, serializedLine);
|
||||
} catch (HologramLoadException e) {
|
||||
throw new CommandException(formatExceptionMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
private String formatExceptionMessage(Throwable throwable) {
|
||||
String message = throwable.getMessage();
|
||||
if (Strings.isEmpty(message)) {
|
||||
return message;
|
||||
}
|
||||
|
||||
message = Strings.capitalizeFirst(message);
|
||||
char lastChar = message.charAt(message.length() - 1);
|
||||
if (Character.isLetterOrDigit(lastChar)) {
|
||||
message = message + ".";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public InternalHologram getHologram(String hologramName) throws CommandException {
|
||||
InternalHologram hologram = internalHologramManager.getHologramByName(hologramName);
|
||||
CommandValidate.notNull(hologram, "Cannot find a hologram named \"" + hologramName + "\".");
|
||||
return hologram;
|
||||
}
|
||||
|
||||
public List<InternalHologram> getHolograms() {
|
||||
return internalHologramManager.getHolograms();
|
||||
}
|
||||
|
||||
public InternalHologram create(Location spawnLocation, String hologramName) {
|
||||
return internalHologramManager.createHologram(spawnLocation, hologramName);
|
||||
}
|
||||
|
||||
public void delete(InternalHologram hologram) {
|
||||
internalHologramManager.deleteHologram(hologram);
|
||||
}
|
||||
|
||||
public void saveChanges(InternalHologram hologram, ChangeType changeType) {
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
Bukkit.getPluginManager().callEvent(new InternalHologramChangeEvent(hologram, changeType));
|
||||
}
|
||||
|
||||
public void teleportLookingDown(Player player, Location location) {
|
||||
location.setPitch(90); // Look down
|
||||
player.teleport(location, TeleportCause.PLUGIN);
|
||||
}
|
||||
|
||||
public Path getUserReadableFile(String fileName) throws CommandException {
|
||||
Path dataFolder = configManager.getRootDataFolder();
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
@ -8,47 +8,38 @@ package me.filoghost.holographicdisplays.plugin.commands.subs;
|
||||
import me.filoghost.fcommons.Strings;
|
||||
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.fcommons.command.validation.CommandException;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class AddlineCommand extends LineEditingCommand implements QuickEditCommand {
|
||||
|
||||
private final HologramCommandManager commandManager;
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public AddlineCommand(
|
||||
HologramCommandManager commandManager,
|
||||
InternalHologramManager internalHologramManager,
|
||||
ConfigManager configManager) {
|
||||
public AddlineCommand(HologramCommandManager commandManager, InternalHologramEditor hologramEditor) {
|
||||
super("addline");
|
||||
setMinArgs(2);
|
||||
setUsageArgs("<hologram> <text>");
|
||||
setDescription("Adds a line to an existing hologram.");
|
||||
|
||||
this.commandManager = commandManager;
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[0]);
|
||||
String serializedLine = Strings.joinFrom(" ", args, 1);
|
||||
|
||||
InternalHologramLine line = HologramCommandValidate.parseHologramLine(hologram, serializedLine);
|
||||
hologram.addLine(line);
|
||||
InternalHologramLine line = hologramEditor.parseHologramLine(hologram, serializedLine);
|
||||
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
Bukkit.getPluginManager().callEvent(new InternalHologramEditEvent(hologram));
|
||||
hologram.addLine(line);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "Line added.");
|
||||
commandManager.sendQuickEditCommands(context, hologram);
|
||||
|
@ -8,56 +8,53 @@ package me.filoghost.holographicdisplays.plugin.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.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class AlignCommand extends HologramSubCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public AlignCommand(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
public AlignCommand(InternalHologramEditor hologramEditor) {
|
||||
super("align");
|
||||
setMinArgs(3);
|
||||
setUsageArgs("<X | Y | Z | XZ> <hologram> <referenceHologram>");
|
||||
setDescription("Aligns the first hologram to the second, in the specified axis.");
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[1]);
|
||||
InternalHologram referenceHologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[2]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[1]);
|
||||
InternalHologram referenceHologram = hologramEditor.getHologram(args[2]);
|
||||
|
||||
CommandValidate.check(hologram != referenceHologram, "The holograms must not be the same.");
|
||||
|
||||
Location loc = hologram.getLocation();
|
||||
Location newLocation = hologram.getLocation();
|
||||
|
||||
String axis = args[0];
|
||||
if (axis.equalsIgnoreCase("x")) {
|
||||
loc.setX(referenceHologram.getX());
|
||||
newLocation.setX(referenceHologram.getX());
|
||||
} else if (axis.equalsIgnoreCase("y")) {
|
||||
loc.setY(referenceHologram.getY());
|
||||
newLocation.setY(referenceHologram.getY());
|
||||
} else if (axis.equalsIgnoreCase("z")) {
|
||||
loc.setZ(referenceHologram.getZ());
|
||||
newLocation.setZ(referenceHologram.getZ());
|
||||
} else if (axis.equalsIgnoreCase("xz")) {
|
||||
loc.setX(referenceHologram.getX());
|
||||
loc.setZ(referenceHologram.getZ());
|
||||
newLocation.setX(referenceHologram.getX());
|
||||
newLocation.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);
|
||||
hologram.teleport(newLocation);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LOCATION);
|
||||
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "Hologram \"" + hologram.getName() + "\""
|
||||
+ " aligned to the hologram \"" + referenceHologram.getName() + "\""
|
||||
+ " on the " + axis.toUpperCase() + " axis.");
|
||||
|
@ -7,13 +7,12 @@ package me.filoghost.holographicdisplays.plugin.commands.subs;
|
||||
|
||||
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.fcommons.command.validation.CommandException;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -21,32 +20,29 @@ import java.util.List;
|
||||
|
||||
public class CopyCommand extends HologramSubCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public CopyCommand(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
public CopyCommand(InternalHologramEditor hologramEditor) {
|
||||
super("copy");
|
||||
setMinArgs(2);
|
||||
setUsageArgs("<fromHologram> <toHologram>");
|
||||
setDescription("Copies the contents of a hologram into another one.");
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
InternalHologram fromHologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram toHologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[1]);
|
||||
InternalHologram fromHologram = hologramEditor.getHologram(args[0]);
|
||||
InternalHologram toHologram = hologramEditor.getHologram(args[1]);
|
||||
|
||||
List<InternalHologramLine> clonedLines = new ArrayList<>();
|
||||
for (InternalHologramLine line : fromHologram.getLines()) {
|
||||
clonedLines.add(HologramCommandValidate.parseHologramLine(toHologram, line.getSerializedConfigValue()));
|
||||
clonedLines.add(hologramEditor.parseHologramLine(toHologram, line.getSerializedConfigValue()));
|
||||
}
|
||||
|
||||
toHologram.setLines(clonedLines);
|
||||
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
hologramEditor.saveChanges(toHologram, ChangeType.EDIT_LINES);
|
||||
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "Hologram \"" + fromHologram.getName() + "\""
|
||||
+ " copied into hologram \"" + toHologram.getName() + "\".");
|
||||
|
@ -9,25 +9,22 @@ import me.filoghost.fcommons.Strings;
|
||||
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.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
public class CreateCommand extends HologramSubCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public CreateCommand(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
public CreateCommand(InternalHologramEditor hologramEditor) {
|
||||
super("create");
|
||||
setMinArgs(1);
|
||||
setUsageArgs("<hologramName> [text]");
|
||||
@ -36,8 +33,7 @@ public class CreateCommand extends HologramSubCommand {
|
||||
"be alphanumeric. The name will be used as reference to",
|
||||
"that hologram for editing commands.");
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -48,24 +44,24 @@ public class CreateCommand extends HologramSubCommand {
|
||||
|
||||
CommandValidate.check(hologramName.matches("[a-zA-Z0-9_\\-]+"),
|
||||
"The name must contain only alphanumeric chars, underscores and hyphens.");
|
||||
CommandValidate.check(!internalHologramManager.isExistingHologram(hologramName),
|
||||
CommandValidate.check(hologramEditor.getHologram(hologramName) == null,
|
||||
"A hologram with that name already exists.");
|
||||
|
||||
Location spawnLoc = player.getLocation();
|
||||
Location spawnLocation = player.getLocation();
|
||||
boolean moveUp = player.isOnGround();
|
||||
|
||||
if (moveUp) {
|
||||
spawnLoc.add(0.0, 1.2, 0.0);
|
||||
spawnLocation.add(0.0, 1.2, 0.0);
|
||||
}
|
||||
|
||||
InternalHologram hologram = internalHologramManager.createHologram(spawnLoc, hologramName);
|
||||
InternalHologram hologram = hologramEditor.create(spawnLocation, hologramName);
|
||||
InternalHologramLine line;
|
||||
|
||||
if (args.length > 1) {
|
||||
String text = Strings.joinFrom(" ", args, 1);
|
||||
CommandValidate.check(!text.equalsIgnoreCase("{empty}"), "The first line should not be empty.");
|
||||
|
||||
line = HologramCommandValidate.parseHologramLine(hologram, text);
|
||||
line = hologramEditor.parseHologramLine(hologram, text);
|
||||
player.sendMessage(ColorScheme.SECONDARY_DARKER + "(Change the lines with /" + context.getRootLabel()
|
||||
+ " edit " + hologram.getName() + ")");
|
||||
} else {
|
||||
@ -75,11 +71,9 @@ public class CreateCommand extends HologramSubCommand {
|
||||
}
|
||||
|
||||
hologram.addLine(line);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.CREATE);
|
||||
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
Location look = player.getLocation();
|
||||
look.setPitch(90);
|
||||
player.teleport(look, TeleportCause.PLUGIN);
|
||||
hologramEditor.teleportLookingDown(player, player.getLocation());
|
||||
player.sendMessage(ColorScheme.PRIMARY + "You created a hologram named '" + hologram.getName() + "'.");
|
||||
|
||||
if (moveUp) {
|
||||
|
@ -9,8 +9,8 @@ import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.holographicdisplays.common.hologram.StandardHologram;
|
||||
import me.filoghost.holographicdisplays.common.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.common.nms.entity.NMSEntity;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
|
@ -7,36 +7,32 @@ package me.filoghost.holographicdisplays.plugin.commands.subs;
|
||||
|
||||
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.fcommons.command.validation.CommandException;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class DeleteCommand extends HologramSubCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public DeleteCommand(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
public DeleteCommand(InternalHologramEditor hologramEditor) {
|
||||
super("delete", "remove");
|
||||
setMinArgs(1);
|
||||
setUsageArgs("<hologram>");
|
||||
setDescription("Deletes a hologram. Cannot be undone.");
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[0]);
|
||||
|
||||
internalHologramManager.deleteHologram(hologram);
|
||||
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
hologramEditor.delete(hologram);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.DELETE);
|
||||
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "You deleted the hologram '" + hologram.getName() + "'.");
|
||||
}
|
||||
|
@ -7,13 +7,12 @@ package me.filoghost.holographicdisplays.plugin.commands.subs;
|
||||
|
||||
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.fcommons.command.validation.CommandException;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.format.DisplayFormat;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
@ -28,21 +27,21 @@ import java.util.List;
|
||||
public class EditCommand extends HologramSubCommand {
|
||||
|
||||
private final HologramCommandManager commandManager;
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public EditCommand(HologramCommandManager commandManager, InternalHologramManager internalHologramManager) {
|
||||
public EditCommand(HologramCommandManager commandManager, InternalHologramEditor hologramEditor) {
|
||||
super("edit");
|
||||
setMinArgs(1);
|
||||
setUsageArgs("<hologram>");
|
||||
setDescription("Shows the commands to manipulate an existing hologram.");
|
||||
|
||||
this.commandManager = commandManager;
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[0]);
|
||||
|
||||
sender.sendMessage("");
|
||||
DisplayFormat.sendTitle(sender, "How to edit the hologram '" + hologram.getName() + "'");
|
||||
|
@ -6,9 +6,9 @@
|
||||
package me.filoghost.holographicdisplays.plugin.commands.subs;
|
||||
|
||||
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.format.DisplayFormat;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
|
@ -8,32 +8,31 @@ package me.filoghost.holographicdisplays.plugin.commands.subs;
|
||||
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.fcommons.command.validation.CommandException;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.format.DisplayFormat;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class InfoCommand extends LineEditingCommand implements QuickEditCommand {
|
||||
|
||||
private final HologramCommandManager commandManager;
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public InfoCommand(HologramCommandManager commandManager, InternalHologramManager internalHologramManager) {
|
||||
public InfoCommand(HologramCommandManager commandManager, InternalHologramEditor hologramEditor) {
|
||||
super("info", "details");
|
||||
setMinArgs(1);
|
||||
setUsageArgs("<hologram>");
|
||||
setDescription("Shows the lines of a hologram.");
|
||||
|
||||
this.commandManager = commandManager;
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[0]);
|
||||
|
||||
sender.sendMessage("");
|
||||
DisplayFormat.sendTitle(sender, "Lines of the hologram '" + hologram.getName() + "'");
|
||||
|
@ -9,28 +9,21 @@ import me.filoghost.fcommons.Strings;
|
||||
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.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.format.DisplayFormat;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class InsertlineCommand extends LineEditingCommand implements QuickEditCommand {
|
||||
|
||||
private final HologramCommandManager commandManager;
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public InsertlineCommand(
|
||||
HologramCommandManager commandManager,
|
||||
InternalHologramManager internalHologramManager,
|
||||
ConfigManager configManager) {
|
||||
public InsertlineCommand(HologramCommandManager commandManager, InternalHologramEditor hologramEditor) {
|
||||
super("insertline");
|
||||
setMinArgs(3);
|
||||
setUsageArgs("<hologram> <lineNumber> <text>");
|
||||
@ -40,13 +33,12 @@ public class InsertlineCommand extends LineEditingCommand implements QuickEditCo
|
||||
"the first line of the hologram.");
|
||||
|
||||
this.commandManager = commandManager;
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[0]);
|
||||
int insertAfterIndex = CommandValidate.parseInteger(args[1]);
|
||||
String serializedLine = Strings.joinFrom(" ", args, 2);
|
||||
|
||||
@ -55,12 +47,10 @@ public class InsertlineCommand extends LineEditingCommand implements QuickEditCo
|
||||
CommandValidate.check(insertAfterIndex >= 0 && insertAfterIndex <= oldLinesAmount,
|
||||
"The number must be between 0 and " + hologram.getLineCount() + "(amount of lines of the hologram).");
|
||||
|
||||
InternalHologramLine line = HologramCommandValidate.parseHologramLine(hologram, serializedLine);
|
||||
InternalHologramLine line = hologramEditor.parseHologramLine(hologram, serializedLine);
|
||||
|
||||
hologram.insertLine(insertAfterIndex, line);
|
||||
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new InternalHologramEditEvent(hologram));
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
if (insertAfterIndex == 0) {
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "Line inserted before first line.");
|
||||
|
@ -8,11 +8,11 @@ package me.filoghost.holographicdisplays.plugin.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.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.format.DisplayFormat;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
@ -21,15 +21,15 @@ public class ListCommand extends HologramSubCommand {
|
||||
|
||||
private static final int HOLOGRAMS_PER_PAGE = 10;
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public ListCommand(InternalHologramManager internalHologramManager) {
|
||||
public ListCommand(InternalHologramEditor hologramEditor) {
|
||||
super("list");
|
||||
setMinArgs(0);
|
||||
setUsageArgs("[page]");
|
||||
setDescription("Lists all the existing holograms.");
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,7 +37,7 @@ public class ListCommand extends HologramSubCommand {
|
||||
int page = args.length > 0 ? CommandValidate.parseInteger(args[0]) : 1;
|
||||
CommandValidate.check(page >= 1, "Page number must be 1 or greater.");
|
||||
|
||||
List<InternalHologram> holograms = internalHologramManager.getHolograms();
|
||||
List<InternalHologram> holograms = hologramEditor.getHolograms();
|
||||
int totalPages = holograms.size() / HOLOGRAMS_PER_PAGE;
|
||||
if (holograms.size() % HOLOGRAMS_PER_PAGE != 0) {
|
||||
totalPages++;
|
||||
|
@ -8,43 +8,36 @@ package me.filoghost.holographicdisplays.plugin.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.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
public class MovehereCommand extends HologramSubCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public MovehereCommand(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
public MovehereCommand(InternalHologramEditor hologramEditor) {
|
||||
super("movehere");
|
||||
setMinArgs(1);
|
||||
setUsageArgs("<hologram>");
|
||||
setDescription("Moves a hologram to your location.");
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
Player player = CommandValidate.getPlayerSender(sender);
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[0]);
|
||||
|
||||
hologram.teleport(player.getLocation());
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LOCATION);
|
||||
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
Location to = player.getLocation();
|
||||
to.setPitch(90);
|
||||
player.teleport(to, TeleportCause.PLUGIN);
|
||||
hologramEditor.teleportLookingDown(player, player.getLocation());
|
||||
player.sendMessage(ColorScheme.PRIMARY + "You moved the hologram '" + hologram.getName() + "' near to you.");
|
||||
}
|
||||
|
||||
|
@ -8,11 +8,11 @@ package me.filoghost.holographicdisplays.plugin.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.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.format.DisplayFormat;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -22,15 +22,15 @@ import java.util.List;
|
||||
|
||||
public class NearCommand extends HologramSubCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public NearCommand(InternalHologramManager internalHologramManager) {
|
||||
public NearCommand(InternalHologramEditor hologramEditor) {
|
||||
super("near");
|
||||
setMinArgs(1);
|
||||
setUsageArgs("<radius>");
|
||||
setDescription("Get a list of near holograms.");
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,7 +43,7 @@ public class NearCommand extends HologramSubCommand {
|
||||
int radiusSquared = radius * radius;
|
||||
List<InternalHologram> nearHolograms = new ArrayList<>();
|
||||
|
||||
for (InternalHologram hologram : internalHologramManager.getHolograms()) {
|
||||
for (InternalHologram hologram : hologramEditor.getHolograms()) {
|
||||
if (hologram.getWorld().equals(world) && hologram.getLocation().distanceSquared(player.getLocation()) <= radiusSquared) {
|
||||
nearHolograms.add(hologram);
|
||||
}
|
||||
|
@ -10,18 +10,15 @@ import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.fcommons.command.validation.CommandException;
|
||||
import me.filoghost.fcommons.command.validation.CommandValidate;
|
||||
import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.format.DisplayFormat;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalTextLine;
|
||||
import me.filoghost.holographicdisplays.plugin.image.ImageMessage;
|
||||
import me.filoghost.holographicdisplays.plugin.image.ImageReadException;
|
||||
import me.filoghost.holographicdisplays.plugin.image.ImageReader;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -32,20 +29,19 @@ import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ReadimageCommand extends LineEditingCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public ReadimageCommand(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
public ReadimageCommand(InternalHologramEditor hologramEditor) {
|
||||
super("readimage", "image");
|
||||
setMinArgs(3);
|
||||
setUsageArgs("<hologram> <imageWithExtension> <width>");
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,20 +65,11 @@ public class ReadimageCommand extends LineEditingCommand {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
boolean append = false;
|
||||
List<String> newArgs = new ArrayList<>();
|
||||
|
||||
for (String arg : args) {
|
||||
if (arg.equalsIgnoreCase("-a") || arg.equalsIgnoreCase("-append")) {
|
||||
append = true;
|
||||
} else {
|
||||
newArgs.add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> newArgs = new ArrayList<>(Arrays.asList(args));
|
||||
boolean append = extractAppendFlag(newArgs);
|
||||
args = newArgs.toArray(new String[0]);
|
||||
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[0]);
|
||||
|
||||
int width = CommandValidate.parseInteger(args[2]);
|
||||
CommandValidate.check(width >= 2, "The width of the image must be 2 or greater.");
|
||||
@ -90,48 +77,21 @@ public class ReadimageCommand extends LineEditingCommand {
|
||||
|
||||
boolean isUrl = false;
|
||||
|
||||
try {
|
||||
String fileName = args[1];
|
||||
BufferedImage image;
|
||||
String fileName = args[1];
|
||||
BufferedImage image;
|
||||
|
||||
try {
|
||||
if (fileName.startsWith("http://") || fileName.startsWith("https://")) {
|
||||
isUrl = true;
|
||||
image = ImageReader.readImage(new URL(fileName));
|
||||
} else {
|
||||
|
||||
if (fileName.matches(".*[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-]{1,4}/.+")) {
|
||||
DisplayFormat.sendWarning(sender, "The image path seems to be an URL. If so, please use http:// or https:// in the path.");
|
||||
}
|
||||
|
||||
Path targetImage = HologramCommandValidate.getUserReadableFile(configManager.getRootDataFolder(), fileName);
|
||||
Path targetImage = hologramEditor.getUserReadableFile(fileName);
|
||||
image = ImageReader.readImage(targetImage);
|
||||
}
|
||||
|
||||
ImageMessage imageMessage = new ImageMessage(image, width);
|
||||
List<InternalTextLine> newLines = new ArrayList<>();
|
||||
for (String newLine : imageMessage.getLines()) {
|
||||
newLines.add(hologram.createTextLine(newLine, newLine));
|
||||
}
|
||||
|
||||
if (!append) {
|
||||
hologram.clearLines();
|
||||
}
|
||||
hologram.addLines(newLines);
|
||||
|
||||
if (newLines.size() < 5) {
|
||||
DisplayFormat.sendTip(sender, "The image has a very low height."
|
||||
+ " You can increase it by increasing the width, it will scale automatically.");
|
||||
}
|
||||
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
|
||||
if (append) {
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "The image was appended int the end of the hologram.");
|
||||
} else {
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "The image was drawn in the hologram.");
|
||||
}
|
||||
Bukkit.getPluginManager().callEvent(new InternalHologramEditEvent(hologram));
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
throw new CommandException("The provided URL was not valid.");
|
||||
} catch (ImageReadException e) {
|
||||
@ -140,6 +100,43 @@ public class ReadimageCommand extends LineEditingCommand {
|
||||
Log.warning("Error while reading an image", e);
|
||||
throw new CommandException("I/O exception while reading the image. " + (isUrl ? "Is the URL valid?" : "Is it in use?"));
|
||||
}
|
||||
|
||||
ImageMessage imageMessage = new ImageMessage(image, width);
|
||||
List<InternalTextLine> newLines = new ArrayList<>();
|
||||
for (String newLine : imageMessage.getLines()) {
|
||||
newLines.add(hologram.createTextLine(newLine, newLine));
|
||||
}
|
||||
|
||||
if (newLines.size() < 5) {
|
||||
DisplayFormat.sendTip(sender, "The image has a very low height."
|
||||
+ " You can increase it by increasing the width, it will scale automatically.");
|
||||
}
|
||||
|
||||
if (!append) {
|
||||
hologram.clearLines();
|
||||
}
|
||||
hologram.addLines(newLines);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
if (append) {
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "The image was appended int the end of the hologram.");
|
||||
} else {
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "The image was drawn in the hologram.");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean extractAppendFlag(List<String> args) {
|
||||
Iterator<String> iterator = args.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
String arg = iterator.next();
|
||||
if (arg.equalsIgnoreCase("-a") || arg.equalsIgnoreCase("-append")) {
|
||||
iterator.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,18 +8,15 @@ package me.filoghost.holographicdisplays.plugin.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.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.HologramLineParser;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.HologramLoadException;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.format.DisplayFormat;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.plugin.util.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -32,16 +29,14 @@ import java.util.List;
|
||||
|
||||
public class ReadtextCommand extends LineEditingCommand {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public ReadtextCommand(InternalHologramManager internalHologramManager, ConfigManager configManager) {
|
||||
public ReadtextCommand(InternalHologramEditor hologramEditor) {
|
||||
super("readtext", "readlines");
|
||||
setMinArgs(2);
|
||||
setUsageArgs("<hologram> <fileWithExtension>");
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,47 +55,46 @@ public class ReadtextCommand extends LineEditingCommand {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[0]);
|
||||
String fileName = args[1];
|
||||
|
||||
Path fileToRead = hologramEditor.getUserReadableFile(fileName);
|
||||
List<String> serializedLines;
|
||||
|
||||
try {
|
||||
Path targetFile = HologramCommandValidate.getUserReadableFile(configManager.getRootDataFolder(), fileName);
|
||||
List<String> serializedLines = Files.readAllLines(targetFile);
|
||||
|
||||
int linesAmount = serializedLines.size();
|
||||
if (linesAmount > 40) {
|
||||
DisplayFormat.sendWarning(sender, "The file contained more than 40 lines, that have been limited.");
|
||||
linesAmount = 40;
|
||||
}
|
||||
|
||||
List<InternalHologramLine> linesToAdd = new ArrayList<>();
|
||||
for (int i = 0; i < linesAmount; i++) {
|
||||
try {
|
||||
InternalHologramLine line = HologramLineParser.parseLine(hologram, serializedLines.get(i));
|
||||
linesToAdd.add(line);
|
||||
} catch (HologramLoadException e) {
|
||||
throw new CommandException("Error at line " + (i + 1) + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
hologram.setLines(linesToAdd);
|
||||
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
|
||||
if (isImageExtension(FileUtils.getExtension(fileName))) {
|
||||
DisplayFormat.sendWarning(sender, "The read file has an image's extension."
|
||||
+ " If it is an image, you should use /" + context.getRootLabel() + " readimage.");
|
||||
}
|
||||
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "The lines were pasted into the hologram.");
|
||||
Bukkit.getPluginManager().callEvent(new InternalHologramEditEvent(hologram));
|
||||
|
||||
serializedLines = Files.readAllLines(fileToRead);
|
||||
} catch (IOException e) {
|
||||
throw new CommandException("I/O exception while reading the file. Is it in use?");
|
||||
}
|
||||
|
||||
int linesAmount = serializedLines.size();
|
||||
if (linesAmount > 40) {
|
||||
DisplayFormat.sendWarning(sender, "The file contained more than 40 lines, that have been limited.");
|
||||
linesAmount = 40;
|
||||
}
|
||||
|
||||
List<InternalHologramLine> newLines = new ArrayList<>();
|
||||
for (int i = 0; i < linesAmount; i++) {
|
||||
try {
|
||||
InternalHologramLine line = HologramLineParser.parseLine(hologram, serializedLines.get(i));
|
||||
newLines.add(line);
|
||||
} catch (HologramLoadException e) {
|
||||
throw new CommandException("Error at line " + (i + 1) + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
hologram.setLines(newLines);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
if (isSupportedImageExtension(FileUtils.getExtension(fileToRead))) {
|
||||
DisplayFormat.sendWarning(sender, "The read file has an image's extension."
|
||||
+ " If it is an image, you should use /" + context.getRootLabel() + " readimage.");
|
||||
}
|
||||
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "The lines were pasted into the hologram.");
|
||||
}
|
||||
|
||||
private boolean isImageExtension(String extension) {
|
||||
private boolean isSupportedImageExtension(String extension) {
|
||||
return Arrays.asList("jpg", "png", "jpeg", "gif").contains(extension.toLowerCase());
|
||||
}
|
||||
|
||||
|
@ -6,10 +6,10 @@
|
||||
package me.filoghost.holographicdisplays.plugin.commands.subs;
|
||||
|
||||
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.HolographicDisplays;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.event.HolographicDisplaysReloadEvent;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.log.PrintableErrorCollector;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -8,39 +8,31 @@ package me.filoghost.holographicdisplays.plugin.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.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class RemovelineCommand extends LineEditingCommand implements QuickEditCommand {
|
||||
|
||||
private final HologramCommandManager commandManager;
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public RemovelineCommand(
|
||||
HologramCommandManager commandManager,
|
||||
InternalHologramManager internalHologramManager,
|
||||
ConfigManager configManager) {
|
||||
public RemovelineCommand(HologramCommandManager commandManager, InternalHologramEditor hologramEditor) {
|
||||
super("removeline");
|
||||
setMinArgs(2);
|
||||
setUsageArgs("<hologram> <lineNumber>");
|
||||
setDescription("Removes a line from a hologram.");
|
||||
|
||||
this.commandManager = commandManager;
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[0]);
|
||||
|
||||
int lineNumber = CommandValidate.parseInteger(args[1]);
|
||||
|
||||
@ -52,9 +44,7 @@ public class RemovelineCommand extends LineEditingCommand implements QuickEditCo
|
||||
"The hologram should have at least 1 line. If you want to delete it, use /" + context.getRootLabel() + " delete.");
|
||||
|
||||
hologram.removeLine(index);
|
||||
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
Bukkit.getPluginManager().callEvent(new InternalHologramEditEvent(hologram));
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "Line " + lineNumber + " removed.");
|
||||
commandManager.sendQuickEditCommands(context, hologram);
|
||||
|
@ -9,40 +9,32 @@ import me.filoghost.fcommons.Strings;
|
||||
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.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramEditEvent;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class SetlineCommand extends LineEditingCommand implements QuickEditCommand {
|
||||
|
||||
private final HologramCommandManager commandManager;
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public SetlineCommand(
|
||||
HologramCommandManager commandManager,
|
||||
InternalHologramManager internalHologramManager,
|
||||
ConfigManager configManager) {
|
||||
public SetlineCommand(HologramCommandManager commandManager, InternalHologramEditor hologramEditor) {
|
||||
super("setline");
|
||||
setMinArgs(3);
|
||||
setUsageArgs("<hologram> <lineNumber> <newText>");
|
||||
setDescription("Changes a line of a hologram.");
|
||||
|
||||
this.commandManager = commandManager;
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.configManager = configManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[0]);
|
||||
String serializedLine = Strings.joinFrom(" ", args, 2);
|
||||
|
||||
int lineNumber = CommandValidate.parseInteger(args[1]);
|
||||
@ -50,12 +42,10 @@ public class SetlineCommand extends LineEditingCommand implements QuickEditComma
|
||||
"The line number must be between 1 and " + hologram.getLineCount() + ".");
|
||||
int index = lineNumber - 1;
|
||||
|
||||
InternalHologramLine line = HologramCommandValidate.parseHologramLine(hologram, serializedLine);
|
||||
InternalHologramLine line = hologramEditor.parseHologramLine(hologram, serializedLine);
|
||||
|
||||
hologram.setLine(index, line);
|
||||
|
||||
configManager.saveHologramDatabase(internalHologramManager);
|
||||
Bukkit.getPluginManager().callEvent(new InternalHologramEditEvent(hologram));
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "Line " + lineNumber + " changed.");
|
||||
commandManager.sendQuickEditCommands(context, hologram);
|
||||
|
@ -8,38 +8,33 @@ package me.filoghost.holographicdisplays.plugin.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.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandValidate;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
|
||||
import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
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 {
|
||||
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
private final InternalHologramEditor hologramEditor;
|
||||
|
||||
public TeleportCommand(InternalHologramManager internalHologramManager) {
|
||||
public TeleportCommand(InternalHologramEditor hologramEditor) {
|
||||
super("teleport", "tp");
|
||||
setMinArgs(1);
|
||||
setUsageArgs("<hologram>");
|
||||
setDescription("Teleports you to the given hologram.");
|
||||
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
this.hologramEditor = hologramEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) throws CommandException {
|
||||
Player player = CommandValidate.getPlayerSender(sender);
|
||||
InternalHologram hologram = HologramCommandValidate.getInternalHologram(internalHologramManager, args[0]);
|
||||
InternalHologram hologram = hologramEditor.getHologram(args[0]);
|
||||
|
||||
Location loc = hologram.getLocation();
|
||||
loc.setPitch(90);
|
||||
player.teleport(loc, TeleportCause.PLUGIN);
|
||||
hologramEditor.teleportLookingDown(player, hologram.getLocation());
|
||||
player.sendMessage(ColorScheme.PRIMARY + "You were teleported to the hologram named '" + hologram.getName() + "'.");
|
||||
}
|
||||
|
||||
|
@ -9,20 +9,26 @@ import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologra
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class InternalHologramEditEvent extends Event {
|
||||
public class InternalHologramChangeEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final InternalHologram hologram;
|
||||
private final ChangeType changeType;
|
||||
|
||||
public InternalHologramEditEvent(InternalHologram hologram) {
|
||||
public InternalHologramChangeEvent(InternalHologram hologram, ChangeType changeType) {
|
||||
this.hologram = hologram;
|
||||
this.changeType = changeType;
|
||||
}
|
||||
|
||||
public InternalHologram getHologram() {
|
||||
return hologram;
|
||||
}
|
||||
|
||||
public ChangeType getChangeType() {
|
||||
return changeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
@ -32,4 +38,14 @@ public class InternalHologramEditEvent extends Event {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
||||
public enum ChangeType {
|
||||
|
||||
CREATE,
|
||||
EDIT_LINES,
|
||||
EDIT_LOCATION,
|
||||
DELETE
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -10,7 +10,8 @@ import java.nio.file.Path;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static String getExtension(String fileName) {
|
||||
public static String getExtension(Path file) {
|
||||
String fileName = file.getFileName().toString();
|
||||
int lastFullStop = fileName.lastIndexOf('.');
|
||||
if (lastFullStop >= 0) {
|
||||
return fileName.substring(lastFullStop + 1);
|
||||
|
Loading…
Reference in New Issue
Block a user