Add command to create a backup of all online players

This commit is contained in:
GeorgH93 2021-10-30 15:34:32 +02:00
parent 04bf7da6ff
commit 1ad83c7173
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
5 changed files with 42 additions and 20 deletions

View File

@ -71,6 +71,7 @@ Language:
Reload: "Lädt die Konfigurationsdatei neu." Reload: "Lädt die Konfigurationsdatei neu."
Update: "Prüft auf neue Plugin-Updates." Update: "Prüft auf neue Plugin-Updates."
Backup: "Erstellt eine Sicherungskopie eines Rucksacks." Backup: "Erstellt eine Sicherungskopie eines Rucksacks."
BackupEveryone: "Erstellt eine Sicherungskopie der Rucksäcke aller verbundenen Spieler."
Restore: "Stellt eine Sicherungskopie eines Rucksacks wieder her." Restore: "Stellt eine Sicherungskopie eines Rucksacks wieder her."
RestoreList: "Listet alle verfügbaren Sicherungskopien von Rucksäcken auf." RestoreList: "Listet alle verfügbaren Sicherungskopien von Rucksäcken auf."
Version: "Gibt die Versionsdetails über das Plugin und seine Abhängigkeiten aus." Version: "Gibt die Versionsdetails über das Plugin und seine Abhängigkeiten aus."
@ -120,4 +121,4 @@ LanguageName: "german"
Author: "GeorgH93" Author: "GeorgH93"
# Language file version. Don't touch it! # Language file version. Don't touch it!
Version: 18 Version: 19

View File

@ -73,6 +73,7 @@ Language:
Update: "Checks for new plugin updates." Update: "Checks for new plugin updates."
Version: "Prints the version details about the plugin and it's dependencies." Version: "Prints the version details about the plugin and it's dependencies."
Backup: "Creates a backup of a players backpack." Backup: "Creates a backup of a players backpack."
BackupEveryone: "Creates a backup of everyone currently online."
Restore: "Restores a backup." Restore: "Restores a backup."
RestoreList: "Lists all available backups." RestoreList: "Lists all available backups."
Help: "Shows all available commands and their description." Help: "Shows all available commands and their description."
@ -115,4 +116,4 @@ LanguageName: "english"
Author: "GeorgH93" Author: "GeorgH93"
# Language file version. Don't touch it! # Language file version. Don't touch it!
Version: 18 Version: 19

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020 GeorgH93 * Copyright (C) 2021 GeorgH93
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -26,7 +26,9 @@
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks; import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import at.pcgamingfreaks.Minepacks.Bukkit.Permissions; import at.pcgamingfreaks.Minepacks.Bukkit.Permissions;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
@ -35,12 +37,14 @@
public class BackupCommand extends MinepacksCommand public class BackupCommand extends MinepacksCommand
{ {
private final Message messageCreated, messageNoBackpack; private final Message messageCreated, messageNoBackpack;
private final String helpParam; private final String helpParam, helpParamEveryone, descriptionEveryone;
public BackupCommand(Minepacks plugin) public BackupCommand(Minepacks plugin)
{ {
super(plugin, "backup", plugin.getLanguage().getTranslated("Commands.Description.Backup"), Permissions.BACKUP, plugin.getLanguage().getCommandAliases("Backup")); super(plugin, "backup", plugin.getLanguage().getTranslated("Commands.Description.Backup"), Permissions.BACKUP, plugin.getLanguage().getCommandAliases("Backup"));
helpParam = "<" + plugin.getLanguage().get("Commands.PlayerNameVariable") + ">"; helpParam = "<" + plugin.getLanguage().get("Commands.PlayerNameVariable") + ">";
helpParamEveryone = "!everyone!";
descriptionEveryone = plugin.getLanguage().getTranslated("Commands.Description.BackupEveryone");
messageCreated = plugin.getLanguage().getMessage("Ingame.Backup.Created"); messageCreated = plugin.getLanguage().getMessage("Ingame.Backup.Created");
messageNoBackpack = plugin.getLanguage().getMessage("Ingame.Backup.NoBackpack"); messageNoBackpack = plugin.getLanguage().getMessage("Ingame.Backup.NoBackpack");
} }
@ -49,9 +53,29 @@ public BackupCommand(Minepacks plugin)
public void execute(final @NotNull CommandSender sender, final @NotNull String mainCommandAlias, final @NotNull String alias, final @NotNull String[] args) public void execute(final @NotNull CommandSender sender, final @NotNull String mainCommandAlias, final @NotNull String alias, final @NotNull String[] args)
{ {
if(args.length == 1) if(args.length == 1)
{
if(args[0].equalsIgnoreCase("!everyone!"))
{
for(Player player : plugin.getServer().getOnlinePlayers())
{
backup(sender, player);
}
}
else
{ {
//noinspection deprecation //noinspection deprecation
getMinepacksPlugin().getBackpack(plugin.getServer().getOfflinePlayer(args[0]), new Callback<Backpack>() { backup(sender, plugin.getServer().getOfflinePlayer(args[0]));
}
}
else
{
showHelp(sender, mainCommandAlias);
}
}
private void backup(final @NotNull CommandSender sender, final @NotNull OfflinePlayer offlinePlayer)
{
getMinepacksPlugin().getBackpack(offlinePlayer, new Callback<Backpack>() {
@Override @Override
public void onResult(Backpack backpack) public void onResult(Backpack backpack)
{ {
@ -66,11 +90,6 @@ public void onFail()
} }
}, false); }, false);
} }
else
{
showHelp(sender, mainCommandAlias);
}
}
@Override @Override
public List<String> tabComplete(final @NotNull CommandSender sender, final @NotNull String mainCommandAlias, final @NotNull String alias, final @NotNull String[] args) public List<String> tabComplete(final @NotNull CommandSender sender, final @NotNull String mainCommandAlias, final @NotNull String alias, final @NotNull String[] args)
@ -83,6 +102,7 @@ public List<HelpData> getHelp(final @NotNull CommandSender requester)
{ {
List<HelpData> help = new ArrayList<>(1); List<HelpData> help = new ArrayList<>(1);
help.add(new HelpData(getTranslatedName(), helpParam, getDescription())); help.add(new HelpData(getTranslatedName(), helpParam, getDescription()));
help.add(new HelpData(getTranslatedName(), helpParamEveryone, descriptionEveryone));
return help; return help;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020 GeorgH93 * Copyright (C) 2021 GeorgH93
* *
* This program is free software: you can redistribute it and/or modify * 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 * 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 public class Language extends at.pcgamingfreaks.Bukkit.Language
{ {
private static final int LANG_VERSION = 18, UPGRADE_THRESHOLD = LANG_VERSION; private static final int LANG_VERSION = 19, UPGRADE_THRESHOLD = LANG_VERSION;
public Language(JavaPlugin plugin) public Language(JavaPlugin plugin)
{ {

View File

@ -7,7 +7,7 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<properties> <properties>
<revision>2.4.3-RC1</revision> <revision>2.4.3-RC2</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties> </properties>