mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-25 02:07:36 +01:00
Add a chat message to quickly edit a hologram after modifying its lines
This commit is contained in:
parent
0f0d709abe
commit
c0da957d6c
@ -20,6 +20,7 @@ public enum ConfigNode {
|
||||
|
||||
SPACE_BETWEEN_LINES("space-between-lines", 0.02),
|
||||
PRECISE_HOLOGRAM_MOVEMENT("precise-hologram-movement", true),
|
||||
QUICK_EDIT_COMMANDS("quick-edit-commands", true),
|
||||
IMAGES_SYMBOL("images.symbol", "[x]"),
|
||||
TRANSPARENCY_SPACE("images.transparency.space", " [|] "),
|
||||
TRANSPARENCY_COLOR("images.transparency.color", "&7"),
|
||||
|
@ -39,6 +39,7 @@ public class Configuration {
|
||||
|
||||
public static double spaceBetweenLines;
|
||||
public static boolean preciseHologramMovement;
|
||||
public static boolean quickEditCommands;
|
||||
public static String imageSymbol;
|
||||
public static String transparencySymbol;
|
||||
public static boolean updateNotification;
|
||||
@ -129,6 +130,7 @@ public class Configuration {
|
||||
|
||||
spaceBetweenLines = config.getDouble(ConfigNode.SPACE_BETWEEN_LINES.getPath());
|
||||
preciseHologramMovement = config.getBoolean(ConfigNode.PRECISE_HOLOGRAM_MOVEMENT.getPath());
|
||||
quickEditCommands = config.getBoolean(ConfigNode.QUICK_EDIT_COMMANDS.getPath());
|
||||
|
||||
updateNotification = config.getBoolean(ConfigNode.UPDATE_NOTIFICATION.getPath());
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class HolographicDisplays extends JavaPlugin {
|
||||
private static MainListener mainListener;
|
||||
|
||||
// The command handler, just in case a plugin wants to register more commands.
|
||||
private HologramsCommandHandler commandHandler;
|
||||
private static HologramsCommandHandler commandHandler;
|
||||
|
||||
// The new version found by the updater, null if there is no new version.
|
||||
private static String newVersion;
|
||||
@ -201,7 +201,7 @@ public class HolographicDisplays extends JavaPlugin {
|
||||
return mainListener;
|
||||
}
|
||||
|
||||
public HologramsCommandHandler getCommandHandler() {
|
||||
public static HologramsCommandHandler getCommandHandler() {
|
||||
return commandHandler;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ public class Strings {
|
||||
|
||||
public static final String BASE_PERM = "holograms.";
|
||||
|
||||
public static final String TIP_PREFIX = "" + ChatColor.YELLOW + ChatColor.BOLD + "TIP" + Colors.SECONDARY_SHADOW + " ";
|
||||
public static final String TIP_PREFIX = "" + ChatColor.YELLOW + ChatColor.BOLD + "TIP:" + Colors.SECONDARY_SHADOW + " ";
|
||||
|
||||
|
||||
public static String formatTitle(String input) {
|
||||
|
@ -17,6 +17,7 @@ package com.gmail.filoghost.holographicdisplays.commands.main;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -49,14 +50,16 @@ import com.gmail.filoghost.holographicdisplays.util.Utils;
|
||||
public class HologramsCommandHandler implements CommandExecutor {
|
||||
|
||||
private List<HologramSubCommand> subCommands;
|
||||
|
||||
private Map<Class<? extends HologramSubCommand>, HologramSubCommand> subCommandsByClass;
|
||||
|
||||
public HologramsCommandHandler() {
|
||||
subCommands = Utils.newList();
|
||||
subCommandsByClass = Utils.newMap();
|
||||
|
||||
registerSubCommand(new AddlineCommand());
|
||||
registerSubCommand(new CreateCommand());
|
||||
registerSubCommand(new DeleteCommand());
|
||||
registerSubCommand(new EditCommand(this));
|
||||
registerSubCommand(new EditCommand());
|
||||
registerSubCommand(new ListCommand());
|
||||
registerSubCommand(new NearCommand());
|
||||
registerSubCommand(new TeleportCommand());
|
||||
@ -72,17 +75,22 @@ public class HologramsCommandHandler implements CommandExecutor {
|
||||
registerSubCommand(new ReadimageCommand());
|
||||
registerSubCommand(new InfoCommand());
|
||||
|
||||
registerSubCommand(new HelpCommand(this));
|
||||
registerSubCommand(new HelpCommand());
|
||||
}
|
||||
|
||||
public void registerSubCommand(HologramSubCommand subCommand) {
|
||||
subCommands.add(subCommand);
|
||||
subCommandsByClass.put(subCommand.getClass(), subCommand);
|
||||
}
|
||||
|
||||
public List<HologramSubCommand> getSubCommands() {
|
||||
return new ArrayList<HologramSubCommand>(subCommands);
|
||||
}
|
||||
|
||||
public HologramSubCommand getSubCommand(Class<? extends HologramSubCommand> subCommandClass) {
|
||||
return subCommandsByClass.get(subCommandClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
|
@ -73,8 +73,10 @@ public class AddlineCommand extends HologramSubCommand {
|
||||
|
||||
HologramDatabase.saveHologram(hologram);
|
||||
HologramDatabase.trySaveToDisk();
|
||||
sender.sendMessage(Colors.PRIMARY + "Line added!");
|
||||
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
||||
|
||||
sender.sendMessage(Colors.PRIMARY + "Line added!");
|
||||
EditCommand.sendQuickEditCommands(sender, label, hologram.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,15 +20,17 @@ import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.Colors;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.CommandValidator;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.Strings;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.main.HologramsCommandHandler;
|
||||
import com.gmail.filoghost.holographicdisplays.disk.Configuration;
|
||||
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
|
||||
import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
|
||||
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Utils;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
@ -39,12 +41,17 @@ import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention;
|
||||
|
||||
public class EditCommand extends HologramSubCommand {
|
||||
|
||||
private HologramsCommandHandler mainCommandHandler;
|
||||
|
||||
public EditCommand(HologramsCommandHandler mainCommandHandler) {
|
||||
private static final List<QuickCommandInfo> QUICK_EDIT_COMMANDS = Lists.newArrayList(
|
||||
new QuickCommandInfo("Add", AddlineCommand.class),
|
||||
new QuickCommandInfo("Remove", RemovelineCommand.class),
|
||||
new QuickCommandInfo("Set", SetlineCommand.class),
|
||||
new QuickCommandInfo("Insert", InsertlineCommand.class),
|
||||
new QuickCommandInfo("View", InfoCommand.class)
|
||||
);
|
||||
|
||||
public EditCommand() {
|
||||
super("edit");
|
||||
setPermission(Strings.BASE_PERM + "edit");
|
||||
this.mainCommandHandler = mainCommandHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,7 +73,7 @@ public class EditCommand extends HologramSubCommand {
|
||||
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Strings.formatTitle("How to edit the hologram '" + name + "'"));
|
||||
for (HologramSubCommand subCommand : mainCommandHandler.getSubCommands()) {
|
||||
for (HologramSubCommand subCommand : HolographicDisplays.getCommandHandler().getSubCommands()) {
|
||||
if (subCommand.getType() == SubCommandType.EDIT_LINES) {
|
||||
String usage = "/" + label + " " + subCommand.getName() + (subCommand.getPossibleArguments().length() > 0 ? " " + subCommand.getPossibleArguments().replace("<hologramName>", hologram.getName()).replace("<hologram>", hologram.getName()) : "");
|
||||
|
||||
@ -95,17 +102,37 @@ public class EditCommand extends HologramSubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendQuickEditCommands(Player player, String hologramName) {
|
||||
player.spigot().sendMessage(new ComponentBuilder("[Quick Edit]").color(ChatColor.YELLOW).bold(true)
|
||||
.append(" ", FormatRetention.NONE)
|
||||
.append("[Add Line]").event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/"))
|
||||
.append("hover").color(ChatColor.WHITE).italic(true).underlined(true)
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + "Hover on the commands to get info about them.")))
|
||||
.append(" or ", FormatRetention.NONE).color(ChatColor.GRAY)
|
||||
.append("click").color(ChatColor.WHITE).italic(true).underlined(true)
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + "Click on the commands to insert them in the chat.")))
|
||||
.append(" on the commands!", FormatRetention.NONE).color(ChatColor.GRAY)
|
||||
.create());
|
||||
public static void sendQuickEditCommands(CommandSender sender, String label, String hologramName) {
|
||||
if (!Configuration.quickEditCommands) {
|
||||
return;
|
||||
}
|
||||
if (!(sender instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ComponentBuilder message = new ComponentBuilder("EDIT LINES:").color(ChatColor.GRAY).bold(true).append(" ", FormatRetention.NONE);
|
||||
|
||||
for (QuickCommandInfo quickEditCommand : QUICK_EDIT_COMMANDS) {
|
||||
HologramSubCommand subCommand = HolographicDisplays.getCommandHandler().getSubCommand(quickEditCommand.commandClass);
|
||||
|
||||
// Assume first argument is always "<hologram>" and remove it
|
||||
String arguments = subCommand.getPossibleArguments();
|
||||
if (arguments.contains(" ")) {
|
||||
arguments = arguments.substring(arguments.indexOf(" ") + 1);
|
||||
} else {
|
||||
arguments = "";
|
||||
}
|
||||
|
||||
String usage = "/" + label + " " + subCommand.getName() + " " + hologramName + " ";
|
||||
message.append("[" + quickEditCommand.chatName + "]").color(ChatColor.DARK_AQUA)
|
||||
.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage))
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(
|
||||
ChatColor.GRAY + "Click to insert in chat the highlighted part of the command:\n" +
|
||||
ChatColor.YELLOW + usage + ChatColor.DARK_GRAY + arguments)));
|
||||
message.append(" ", FormatRetention.NONE);
|
||||
}
|
||||
|
||||
((Player) sender).spigot().sendMessage(message.create());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -117,5 +144,19 @@ public class EditCommand extends HologramSubCommand {
|
||||
public SubCommandType getType() {
|
||||
return SubCommandType.GENERIC;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class QuickCommandInfo {
|
||||
|
||||
private final String chatName;
|
||||
private final Class<? extends HologramSubCommand> commandClass;
|
||||
|
||||
public QuickCommandInfo(String chatName, Class<? extends HologramSubCommand> command) {
|
||||
this.chatName = chatName;
|
||||
this.commandClass = command;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,11 +19,11 @@ import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.Colors;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.CommandValidator;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.Strings;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.main.HologramsCommandHandler;
|
||||
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Utils;
|
||||
|
||||
@ -35,13 +35,10 @@ import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention;
|
||||
|
||||
public class HelpCommand extends HologramSubCommand {
|
||||
|
||||
private HologramsCommandHandler mainCommandHandler;
|
||||
|
||||
public HelpCommand(HologramsCommandHandler mainCommandHandler) {
|
||||
public HelpCommand() {
|
||||
super("help");
|
||||
setPermission(Strings.BASE_PERM + "help");
|
||||
this.mainCommandHandler = mainCommandHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,7 +56,7 @@ public class HelpCommand extends HologramSubCommand {
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Strings.formatTitle("Holographic Displays Commands"));
|
||||
for (HologramSubCommand subCommand : mainCommandHandler.getSubCommands()) {
|
||||
for (HologramSubCommand subCommand : HolographicDisplays.getCommandHandler().getSubCommands()) {
|
||||
if (subCommand.getType() == SubCommandType.GENERIC) {
|
||||
String usage = "/" + label + " " + subCommand.getName() + (subCommand.getPossibleArguments().length() > 0 ? " " + subCommand.getPossibleArguments() : "");
|
||||
|
||||
@ -90,12 +87,12 @@ public class HelpCommand extends HologramSubCommand {
|
||||
|
||||
public static void sendHoverTip(Player player) {
|
||||
player.sendMessage("");
|
||||
player.spigot().sendMessage(new ComponentBuilder("TIP").color(ChatColor.YELLOW).bold(true)
|
||||
player.spigot().sendMessage(new ComponentBuilder("TIP:").color(ChatColor.YELLOW).bold(true)
|
||||
.append(" Try to ", FormatRetention.NONE).color(ChatColor.GRAY)
|
||||
.append("hover").color(ChatColor.WHITE).italic(true).underlined(true)
|
||||
.append("hover").color(ChatColor.WHITE).underlined(true)
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + "Hover on the commands to get info about them.")))
|
||||
.append(" or ", FormatRetention.NONE).color(ChatColor.GRAY)
|
||||
.append("click").color(ChatColor.WHITE).italic(true).underlined(true)
|
||||
.append("click").color(ChatColor.WHITE).underlined(true)
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + "Click on the commands to insert them in the chat.")))
|
||||
.append(" on the commands!", FormatRetention.NONE).color(ChatColor.GRAY)
|
||||
.create());
|
||||
|
@ -60,6 +60,7 @@ public class InfoCommand extends HologramSubCommand {
|
||||
for (CraftHologramLine line : hologram.getLinesUnsafe()) {
|
||||
sender.sendMessage(Colors.SECONDARY + Colors.BOLD + (++index) + Colors.SECONDARY_SHADOW + ". " + Colors.SECONDARY + (line instanceof CraftTextLine ? ((CraftTextLine) line).getText() : HologramDatabase.saveLineToString(line)));
|
||||
}
|
||||
EditCommand.sendQuickEditCommands(sender, label, hologram.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,15 +66,17 @@ public class InsertlineCommand extends HologramSubCommand {
|
||||
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!");
|
||||
sender.sendMessage(Strings.TIP_PREFIX + "Next time use /" + label + " addline to add a line at the end.");
|
||||
sender.sendMessage(Strings.TIP_PREFIX + "Next time use \"/" + label + " addline\" to add a line at the end.");
|
||||
} else {
|
||||
sender.sendMessage(Colors.PRIMARY + "Line inserted between lines " + insertAfter + " and " + (insertAfter + 1) + "!");
|
||||
}
|
||||
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
||||
EditCommand.sendQuickEditCommands(sender, label, hologram.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,8 +65,10 @@ public class RemovelineCommand extends HologramSubCommand {
|
||||
|
||||
HologramDatabase.saveHologram(hologram);
|
||||
HologramDatabase.trySaveToDisk();
|
||||
sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " removed!");
|
||||
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
||||
|
||||
sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " removed!");
|
||||
EditCommand.sendQuickEditCommands(sender, label, hologram.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,9 +79,11 @@ public class SetlineCommand extends HologramSubCommand {
|
||||
|
||||
HologramDatabase.saveHologram(hologram);
|
||||
HologramDatabase.trySaveToDisk();
|
||||
sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " changed!");
|
||||
Bukkit.getPluginManager().callEvent(new NamedHologramEditedEvent(hologram));
|
||||
|
||||
sender.sendMessage(Colors.PRIMARY + "Line " + lineNumber + " changed!");
|
||||
EditCommand.sendQuickEditCommands(sender, label, hologram.getName());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,6 +5,7 @@
|
||||
#.
|
||||
space-between-lines: 0.02
|
||||
precise-hologram-movement: true
|
||||
quick-edit-commands: true
|
||||
images:
|
||||
symbol: '[x]'
|
||||
transparency:
|
||||
|
Loading…
Reference in New Issue
Block a user