mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-12-28 17:48:22 +01:00
Improvements for restore command
[Added] Missing success message [Added] Missing tooltip for backups [Bugfix] Message not found for backup entries [Bugfix] Wrong/Missing help messages
This commit is contained in:
parent
e618eca69a
commit
33830de83e
@ -37,9 +37,14 @@ Language:
|
||||
BackupsPerPage: 10
|
||||
Headline: "[\"\",{\"text\":\"Backups\",\"color\":\"yellow\"},{\"text\":\" - \",\"color\":\"white\"},{\"text\":\"Seite {CurrentPage}/{MaxPage}\",\"color\":\"gold\"}]"
|
||||
Footer: "[{\"text\":\"<<< Vorherige <<<\",\"color\":\"gray\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/{MainCommand} {SubCommand} {CurrentPage}--\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"/{MainCommand} {SubCommand} {CurrentPage}--\"}},{\"text\":\" Seite {CurrentPage}/{MaxPage} \",\"color\":\"gold\"},{\"text\":\">>> Nächste >>>\",\"color\":\"gray\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/{MainCommand} {SubCommand} {CurrentPage}++\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"/{MainCommand} {SubCommand} {CurrentPage}++\"}}]"
|
||||
BackupsEntry: "{BackupIdentifier}"
|
||||
BackupEntry: "[\"\",{\"text\":\"{BackupIdentifier}\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/{MainCommand} {SubCommand} {BackupIdentifier}\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"User: {BackupPlayerName} ({BackupPlayerUUID})\\nErstellt: {BackupDate}\"}}]"
|
||||
NoValidBackup: "{BackupIdentifier} ist kein gültiges Backup"
|
||||
NoUserToRestoreToFound: "Kein gültiger Nutzer zum Wiederherstellen gefunden"
|
||||
# NoJSON
|
||||
ParameterBackupName: "backup_name"
|
||||
# No Json!!!
|
||||
DateFormat: "dd.MM.yyyy HH:mm:ss"
|
||||
Restored: "Backup wurde erfolgreich wiederhergestellt."
|
||||
Commands:
|
||||
HelpFormat: "[\"\",{\"text\":\"/{MainCommand} {SubCommand} {Parameters}\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/{MainCommand} {SubCommand}\"}},{\"text\":\" - \",\"color\":\"white\"},{\"text\":\"{Description}\",\"color\":\"aqua\"}]"
|
||||
PlayerNameVariable: "player_name"
|
||||
@ -51,6 +56,8 @@ Language:
|
||||
Reload: "Lädt die konfigurations Datei neu."
|
||||
Update: "Prüft auf neue plugin updates."
|
||||
Backup: "Erstellt eine Sicherungskopie eines Rucksackes."
|
||||
Restore: "Stellt eine Sicherungskopie eines Rucksackes wieder her."
|
||||
RestoreList: "Listet alle verfügbaren Sicherungskopien von Rucksäcken auf."
|
||||
Help: "Zeigt die verfügbaren Befehle an."
|
||||
|
||||
Command:
|
||||
@ -86,4 +93,4 @@ LanguageName: "German"
|
||||
Author: "GeorgH93"
|
||||
|
||||
# Language file version. Don't touch it!
|
||||
Version: 14
|
||||
Version: 15
|
@ -38,9 +38,14 @@ Language:
|
||||
BackupsPerPage: 10
|
||||
Headline: "[\"\",{\"text\":\"Backups\",\"color\":\"yellow\"},{\"text\":\" - \",\"color\":\"white\"},{\"text\":\"showing page {CurrentPage}/{MaxPage}\",\"color\":\"gold\"}]"
|
||||
Footer: "[{\"text\":\"<<< Previous <<<\",\"color\":\"gray\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/{MainCommand} {SubCommand} {CurrentPage}--\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"/{MainCommand} {SubCommand} {CurrentPage}--\"}},{\"text\":\" Showing page {CurrentPage}/{MaxPage} \",\"color\":\"gold\"},{\"text\":\">>> Next >>>\",\"color\":\"gray\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/{MainCommand} {SubCommand} {CurrentPage}++\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"/{MainCommand} {SubCommand} {CurrentPage}++\"}}]"
|
||||
BackupsEntry: "{BackupIdentifier}"
|
||||
BackupEntry: "[\"\",{\"text\":\"{BackupIdentifier}\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/{MainCommand} {SubCommand} {BackupIdentifier}\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"User: {BackupPlayerName} ({BackupPlayerUUID})\\nCreated: {BackupDate}\"}}]"
|
||||
NoValidBackup: "No backup matching {BackupIdentifier} found"
|
||||
NoUserToRestoreToFound: "No valid user to restore backup to found"
|
||||
# No Json!!!
|
||||
ParameterBackupName: "backup_name"
|
||||
# No Json!!!
|
||||
DateFormat: "yyyy.MM.dd HH:mm:ss"
|
||||
Restored: "Backup has been successful restored."
|
||||
Commands:
|
||||
HelpFormat: "[\"\",{\"text\":\"/{MainCommand} {SubCommand} {Parameters}\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/{MainCommand} {SubCommand}\"}},{\"text\":\" - \",\"color\":\"white\"},{\"text\":\"{Description}\",\"color\":\"aqua\"}]"
|
||||
PlayerNameVariable: "player_name"
|
||||
@ -52,7 +57,8 @@ Language:
|
||||
Reload: "Reloads the config of the plugin."
|
||||
Update: "Checks for new plugin updates."
|
||||
Backup: "Creates a backup of a players backpack."
|
||||
Restore: "Restores a backup to a chest."
|
||||
Restore: "Restores a backup."
|
||||
RestoreList: "Lists all available backups."
|
||||
Help: "Shows all available commands and their description."
|
||||
|
||||
Command:
|
||||
@ -83,4 +89,4 @@ LanguageName: "English"
|
||||
Author: "GeorgH93"
|
||||
|
||||
# Language file version. Don't touch it!
|
||||
Version: 14
|
||||
Version: 15
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 GeorgH93
|
||||
* Copyright (C) 2019 GeorgH93
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -19,6 +19,7 @@
|
||||
|
||||
import at.pcgamingfreaks.Bukkit.Message.Message;
|
||||
import at.pcgamingfreaks.Command.HelpData;
|
||||
import at.pcgamingfreaks.Message.MessageClickEvent;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.API.Callback;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksCommand;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
|
||||
@ -32,30 +33,32 @@
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class RestoreCommand extends MinepacksCommand
|
||||
{
|
||||
private final Message messageBackupsHeader, messageBackupsFooter, messageBackupsEntry, messageUnableToLoadBackup, messageNoUserFound;
|
||||
private final Message messageBackupsHeader, messageBackupsFooter, messageBackupEntry, messageUnableToLoadBackup, messageNoUserFound, messageRestored;
|
||||
private final String helpParam;
|
||||
private final SimpleDateFormat dateFormat;
|
||||
private final String[] listCommands;
|
||||
private final int elementsPerPage;
|
||||
|
||||
public RestoreCommand(Minepacks plugin)
|
||||
{
|
||||
super(plugin, "restore", plugin.getLanguage().getTranslated("Commands.Description.Restore"), "backpack.restore", plugin.getLanguage().getCommandAliases("Restore"));
|
||||
helpParam = "<" + plugin.getLanguage().get("Commands.PlayerNameVariable") + ">";
|
||||
helpParam = "<" + plugin.getLanguage().get("Ingame.Restore.ParameterBackupName") + "> (" + plugin.getLanguage().get("Commands.PlayerNameVariable") + ")";
|
||||
messageBackupsHeader = plugin.getLanguage().getMessage("Ingame.Restore.Headline").replaceAll("\\{CurrentPage}", "%1\\$d").replaceAll("\\{MaxPage}", "%2\\$d").replaceAll("\\{MainCommand}", "%3\\$s").replaceAll("\\{SubCommand}", "%4\\$s");
|
||||
messageBackupsFooter = plugin.getLanguage().getMessage("Ingame.Restore.Footer").replaceAll("\\{CurrentPage}", "%1\\$d").replaceAll("\\{MaxPage}", "%2\\$d").replaceAll("\\{MainCommand}", "%3\\$s").replaceAll("\\{SubCommand}", "%4\\$s");
|
||||
messageBackupsEntry = plugin.getLanguage().getMessage("Ingame.Restore.BackupEntry").replaceAll("\\{BackupIdentifier}", "%1\\$s");
|
||||
messageBackupEntry = plugin.getLanguage().getMessage("Ingame.Restore.BackupEntry").replaceAll("\\{BackupIdentifier}", "%1\\$s").replaceAll("\\{BackupDate}", "%2\\$s")
|
||||
.replaceAll("\\{BackupPlayerName}", "%3\\$s").replaceAll("\\{BackupPlayerUUID}", "%4\\$s").replaceAll("\\{MainCommand}", "%5\\$s").replaceAll("\\{SubCommand}", "%6\\$s");
|
||||
messageUnableToLoadBackup = plugin.getLanguage().getMessage("Ingame.Restore.NoValidBackup").replaceAll("\\{BackupIdentifier}", "%1\\$s");
|
||||
messageNoUserFound = plugin.getLanguage().getMessage("Ingame.Restore.NoUserToRestoreToFound");
|
||||
listCommands = plugin.getLanguage().getCommandAliases("ListBackups");
|
||||
messageRestored = plugin.getLanguage().getMessage("Ingame.Restore.Restored");
|
||||
listCommands = plugin.getLanguage().getCommandAliases("ListBackups", "list");
|
||||
//noinspection ConstantConditions
|
||||
elementsPerPage = plugin.getLanguage().getYaml().getInt("Ingame.Restore.BackupsPerPage", 10);
|
||||
dateFormat = (plugin.getLanguage().get("Ingame.Restore.BackupEntry").contains("{BackupDate}")) ? new SimpleDateFormat(plugin.getLanguage().get("Ingame.Restore.DateFormat")) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,12 +113,13 @@ else if(components.length == 3)
|
||||
messageNoUserFound.send(sender);
|
||||
return;
|
||||
}
|
||||
getMinepacksPlugin().getBackpack(plugin.getServer().getOfflinePlayer(args[0]), new Callback<Backpack>() {
|
||||
getMinepacksPlugin().getBackpack(target, new Callback<Backpack>() {
|
||||
@Override
|
||||
public void onResult(Backpack backpack)
|
||||
{
|
||||
backpack.getInventory().setContents(items);
|
||||
backpack.setChanged();
|
||||
messageRestored.send(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -147,12 +151,23 @@ private void listBackups(final @NotNull CommandSender sender, final @NotNull Str
|
||||
int pages = backups.size() / elementsPerPage + 1;
|
||||
page = Math.min(page, pages - 1);
|
||||
int offset = page * elementsPerPage, end = Math.min(offset + elementsPerPage, backups.size());
|
||||
messageBackupsHeader.send(sender, page + 1, pages, mainCommandAlias, alias);
|
||||
messageBackupsHeader.send(sender, page + 1, pages, mainCommandAlias, alias + ' ' + args[0]);
|
||||
while(offset < end)
|
||||
{
|
||||
messageBackupsEntry.send(sender, backups.get(offset++));
|
||||
String backup = backups.get(offset++), uuid = "No UUID", date = "Unknown";
|
||||
String[] components = backup.split("_");
|
||||
if(components.length == 3) uuid = (components[1].contains("-")) ? components[1] : components[1].replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5");
|
||||
if(dateFormat != null && (components.length == 2 || components.length == 3))
|
||||
{
|
||||
try
|
||||
{
|
||||
date = dateFormat.format(new Date(Long.parseLong(components[components.length - 1])));
|
||||
}
|
||||
catch(NumberFormatException ignored) {}
|
||||
}
|
||||
messageBackupEntry.send(sender, backup, date, components[0], uuid, mainCommandAlias, alias);
|
||||
}
|
||||
messageBackupsFooter.send(sender, page + 1, pages, mainCommandAlias, alias);
|
||||
messageBackupsFooter.send(sender, page + 1, pages, mainCommandAlias, alias + ' ' + args[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -175,12 +190,10 @@ public List<String> tabComplete(final @NotNull CommandSender sender, final @NotN
|
||||
}
|
||||
else if(args.length == 2)
|
||||
{
|
||||
String name;
|
||||
autoComplete = new LinkedList<>();
|
||||
for(Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
name = player.getName().toLowerCase();
|
||||
if(name.startsWith(arg)) autoComplete.add(name);
|
||||
if(player.getName().toLowerCase().startsWith(arg)) autoComplete.add(player.getName());
|
||||
}
|
||||
}
|
||||
return autoComplete;
|
||||
@ -190,7 +203,8 @@ else if(args.length == 2)
|
||||
public List<HelpData> getHelp(final @NotNull CommandSender requester)
|
||||
{
|
||||
List<HelpData> help = new LinkedList<>();
|
||||
help.add(new HelpData(getTranslatedName(), helpParam, getDescription()));
|
||||
help.add(new HelpData(getTranslatedName() + " " + listCommands[0], null, ((Minepacks) getMinepacksPlugin()).getLanguage().getTranslated("Commands.Description.RestoreList"), MessageClickEvent.ClickEventAction.RUN_COMMAND));
|
||||
help.add(new HelpData(getTranslatedName(), helpParam, getDescription(), MessageClickEvent.ClickEventAction.SUGGEST_COMMAND));
|
||||
return help;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2018 GeorgH93
|
||||
* Copyright (C) 2019 GeorgH93
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
public class Language extends at.pcgamingfreaks.Bukkit.Language
|
||||
{
|
||||
private static final int LANG_VERSION = 14, UPGRADE_THRESHOLD = 14;
|
||||
private static final int LANG_VERSION = 15, UPGRADE_THRESHOLD = 15;
|
||||
|
||||
public Language(JavaPlugin plugin)
|
||||
{
|
||||
@ -56,7 +56,7 @@ public String[] getCommandAliases(final String command)
|
||||
return getCommandAliases(command, new String[0]);
|
||||
}
|
||||
|
||||
public String[] getCommandAliases(final String command, final @NotNull String[] defaults)
|
||||
public String[] getCommandAliases(final String command, final @NotNull String... defaults)
|
||||
{
|
||||
List<String> aliases = getLang().getStringList("Command." + command, new LinkedList<>());
|
||||
return (aliases.size() > 0) ? aliases.toArray(new String[0]) : defaults;
|
||||
|
Loading…
Reference in New Issue
Block a user