mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-11-15 10:55:20 +01:00
Add backup command
This commit is contained in:
parent
f3ea7f3fee
commit
01375de1a7
@ -29,6 +29,9 @@ Language:
|
|||||||
UpdateFail: "[\"\",{\"text\":\"Es ist ein fehler aufgetreten!\",\"color\":\"red\"}]"
|
UpdateFail: "[\"\",{\"text\":\"Es ist ein fehler aufgetreten!\",\"color\":\"red\"}]"
|
||||||
# You can change this message if you like to, but don't cry if the link isn't linking to the plugin anymore!
|
# You can change this message if you like to, but don't cry if the link isn't linking to the plugin anymore!
|
||||||
UpdateAvailable: "[{\"text\":\"Es ist ein update verfügbar! Bitte downloade es von: \\\"\",\"color\":\"green\"},{\"text\":\"https://www.spigotmc.org/resources/19286/\",\"color\":\"yellow\",\"underlined\":true,\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.spigotmc.org/resources/19286/\"}},{\"text\":\"\\\"\"}]"
|
UpdateAvailable: "[{\"text\":\"Es ist ein update verfügbar! Bitte downloade es von: \\\"\",\"color\":\"green\"},{\"text\":\"https://www.spigotmc.org/resources/19286/\",\"color\":\"yellow\",\"underlined\":true,\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.spigotmc.org/resources/19286/\"}},{\"text\":\"\\\"\"}]"
|
||||||
|
Backup:
|
||||||
|
Created: "Rucksack wurder gesichert."
|
||||||
|
NoBackpack: "Der Spieler hat keinen Rucksack oder keine Items in seinem Rucksack."
|
||||||
Commands:
|
Commands:
|
||||||
HelpFormat: "[\"\",{\"text\":\"/{MainCommand} {SubCommand} {Parameters}\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/{MainCommand} {SubCommand}\"}},{\"text\":\" - \",\"color\":\"white\"},{\"text\":\"{Description}\",\"color\":\"aqua\"}]"
|
HelpFormat: "[\"\",{\"text\":\"/{MainCommand} {SubCommand} {Parameters}\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/{MainCommand} {SubCommand}\"}},{\"text\":\" - \",\"color\":\"white\"},{\"text\":\"{Description}\",\"color\":\"aqua\"}]"
|
||||||
PlayerNameVariable: "player_name"
|
PlayerNameVariable: "player_name"
|
||||||
@ -39,6 +42,7 @@ Language:
|
|||||||
OpenOthers: "Öffnet den Rucksack eines anderen Spielers."
|
OpenOthers: "Öffnet den Rucksack eines anderen Spielers."
|
||||||
Reload: "Lädt die konfigurations Datei neu."
|
Reload: "Lädt die konfigurations Datei neu."
|
||||||
Update: "Prüft auf neue plugin updates."
|
Update: "Prüft auf neue plugin updates."
|
||||||
|
Backup: "Erstellt eine Sicherungskopie eines Rucksackes."
|
||||||
Help: "Zeigt die verfügbaren Befehle an."
|
Help: "Zeigt die verfügbaren Befehle an."
|
||||||
|
|
||||||
Command:
|
Command:
|
||||||
@ -60,6 +64,8 @@ Command:
|
|||||||
- restart
|
- restart
|
||||||
Update:
|
Update:
|
||||||
- update
|
- update
|
||||||
|
Backup:
|
||||||
|
- backup
|
||||||
Help:
|
Help:
|
||||||
- help
|
- help
|
||||||
- hilfe
|
- hilfe
|
||||||
|
@ -30,6 +30,9 @@ Language:
|
|||||||
UpdateFail: "[\"\",{\"text\":\"There was a problem looking for updates! Please check the console!\",\"color\":\"red\"}]"
|
UpdateFail: "[\"\",{\"text\":\"There was a problem looking for updates! Please check the console!\",\"color\":\"red\"}]"
|
||||||
# You can change this message if you like to, but don't cry if the link isn't linking to the plugin anymore!
|
# You can change this message if you like to, but don't cry if the link isn't linking to the plugin anymore!
|
||||||
UpdateAvailable: "[{\"text\":\"There is an update available! Please go to \\\"\",\"color\":\"green\"},{\"text\":\"https://www.spigotmc.org/resources/19286/\",\"color\":\"yellow\",\"underlined\":true,\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.spigotmc.org/resources/19286/\"}},{\"text\":\"\\\" to download it!\"}]"
|
UpdateAvailable: "[{\"text\":\"There is an update available! Please go to \\\"\",\"color\":\"green\"},{\"text\":\"https://www.spigotmc.org/resources/19286/\",\"color\":\"yellow\",\"underlined\":true,\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.spigotmc.org/resources/19286/\"}},{\"text\":\"\\\" to download it!\"}]"
|
||||||
|
Backup:
|
||||||
|
Created: "The backpack has been backed up successful."
|
||||||
|
NoBackpack: "The player doesn't have a backpack or his backpack is empty."
|
||||||
Commands:
|
Commands:
|
||||||
HelpFormat: "[\"\",{\"text\":\"/{MainCommand} {SubCommand} {Parameters}\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/{MainCommand} {SubCommand}\"}},{\"text\":\" - \",\"color\":\"white\"},{\"text\":\"{Description}\",\"color\":\"aqua\"}]"
|
HelpFormat: "[\"\",{\"text\":\"/{MainCommand} {SubCommand} {Parameters}\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/{MainCommand} {SubCommand}\"}},{\"text\":\" - \",\"color\":\"white\"},{\"text\":\"{Description}\",\"color\":\"aqua\"}]"
|
||||||
PlayerNameVariable: "player_name"
|
PlayerNameVariable: "player_name"
|
||||||
@ -40,6 +43,7 @@ Language:
|
|||||||
OpenOthers: "Shows the backpack of another player."
|
OpenOthers: "Shows the backpack of another player."
|
||||||
Reload: "Reloads the config of the plugin."
|
Reload: "Reloads the config of the plugin."
|
||||||
Update: "Checks for new plugin updates."
|
Update: "Checks for new plugin updates."
|
||||||
|
Backup: "Creates a backup of a players backpack."
|
||||||
Help: "Shows all available commands and their description."
|
Help: "Shows all available commands and their description."
|
||||||
|
|
||||||
Command:
|
Command:
|
||||||
@ -57,6 +61,8 @@ Command:
|
|||||||
- restart
|
- restart
|
||||||
Update:
|
Update:
|
||||||
- update
|
- update
|
||||||
|
Backup:
|
||||||
|
- backup
|
||||||
Help:
|
Help:
|
||||||
- help
|
- help
|
||||||
|
|
||||||
@ -64,4 +70,4 @@ LanguageName: "English"
|
|||||||
Author: "GeorgH03"
|
Author: "GeorgH03"
|
||||||
|
|
||||||
# Language file version. Don't touch it!
|
# Language file version. Don't touch it!
|
||||||
Version: 12
|
Version: 13
|
@ -244,6 +244,11 @@ public void save()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void backup()
|
||||||
|
{
|
||||||
|
Minepacks.getInstance().getDatabase().backup(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear()
|
public void clear()
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package at.pcgamingfreaks.Minepacks.Bukkit.Command;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.Bukkit.Message.Message;
|
||||||
|
import at.pcgamingfreaks.Command.HelpData;
|
||||||
|
import at.pcgamingfreaks.Minepacks.Bukkit.API.Callback;
|
||||||
|
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksCommand;
|
||||||
|
import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
|
||||||
|
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BackupCommand extends MinepacksCommand
|
||||||
|
{
|
||||||
|
private final Message messageCreated, messageNoBackpack;
|
||||||
|
private final String helpParam;
|
||||||
|
|
||||||
|
public BackupCommand(Minepacks plugin)
|
||||||
|
{
|
||||||
|
super(plugin, "backup", plugin.getLanguage().getTranslated("Commands.Description.Backup"), "backpack.backup", plugin.getLanguage().getCommandAliases("backup"));
|
||||||
|
helpParam = "<" + plugin.getLanguage().get("Commands.PlayerNameVariable") + ">";
|
||||||
|
messageCreated = plugin.getLanguage().getMessage("Ingame.Backup.Created");
|
||||||
|
messageNoBackpack = plugin.getLanguage().getMessage("Ingame.Backup.NoBackpack");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(final @NotNull CommandSender sender, final @NotNull String mainCommandAlias, final @NotNull String alias, final @NotNull String[] args)
|
||||||
|
{
|
||||||
|
if(args.length == 1)
|
||||||
|
{
|
||||||
|
//noinspection deprecation
|
||||||
|
getMinepacksPlugin().getBackpack(plugin.getServer().getOfflinePlayer(args[0]), new Callback<Backpack>() {
|
||||||
|
@Override
|
||||||
|
public void onResult(Backpack backpack)
|
||||||
|
{
|
||||||
|
backpack.backup();
|
||||||
|
messageCreated.send(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFail()
|
||||||
|
{
|
||||||
|
messageNoBackpack.send(sender);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
showHelp(sender, mainCommandAlias);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> tabComplete(final @NotNull CommandSender sender, final @NotNull String mainCommandAlias, final @NotNull String alias, final @NotNull String[] args)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<HelpData> getHelp(final @NotNull CommandSender requester)
|
||||||
|
{
|
||||||
|
List<HelpData> help = new LinkedList<>();
|
||||||
|
help.add(new HelpData(getTranslatedName(), helpParam, getDescription()));
|
||||||
|
return help;
|
||||||
|
}
|
||||||
|
}
|
@ -73,6 +73,7 @@ public CommandManager(Minepacks plugin)
|
|||||||
registerSubCommand(new ClearCommand(plugin));
|
registerSubCommand(new ClearCommand(plugin));
|
||||||
registerSubCommand(new ReloadCommand(plugin));
|
registerSubCommand(new ReloadCommand(plugin));
|
||||||
registerSubCommand(new UpdateCommand(plugin));
|
registerSubCommand(new UpdateCommand(plugin));
|
||||||
|
registerSubCommand(new BackupCommand(plugin));
|
||||||
registerSubCommand(new HelpCommand(plugin, commands));
|
registerSubCommand(new HelpCommand(plugin, commands));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ public void execute(@NotNull CommandSender sender, @NotNull String main, @NotNul
|
|||||||
{
|
{
|
||||||
if(player.hasPermission("backpack.others"))
|
if(player.hasPermission("backpack.others"))
|
||||||
{
|
{
|
||||||
|
//noinspection deprecation
|
||||||
plugin.openBackpack(player, Bukkit.getOfflinePlayer(args[0]), player.hasPermission("backpack.others.edit"));
|
plugin.openBackpack(player, Bukkit.getOfflinePlayer(args[0]), player.hasPermission("backpack.others.edit"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@ -50,6 +52,7 @@ public abstract class Database implements Listener
|
|||||||
protected long maxAge;
|
protected long maxAge;
|
||||||
private final Map<OfflinePlayer, Backpack> backpacks = new ConcurrentHashMap<>();
|
private final Map<OfflinePlayer, Backpack> backpacks = new ConcurrentHashMap<>();
|
||||||
private final UnCacheStrategie unCacheStrategie;
|
private final UnCacheStrategie unCacheStrategie;
|
||||||
|
private final File backupFolder;
|
||||||
|
|
||||||
public Database(Minepacks mp)
|
public Database(Minepacks mp)
|
||||||
{
|
{
|
||||||
@ -59,6 +62,8 @@ public Database(Minepacks mp)
|
|||||||
bungeeCordMode = plugin.getConfiguration().isBungeeCordModeEnabled();
|
bungeeCordMode = plugin.getConfiguration().isBungeeCordModeEnabled();
|
||||||
maxAge = plugin.getConfiguration().getAutoCleanupMaxInactiveDays();
|
maxAge = plugin.getConfiguration().getAutoCleanupMaxInactiveDays();
|
||||||
unCacheStrategie = bungeeCordMode ? new OnDisconnect(this) : UnCacheStrategie.getUnCacheStrategie(this);
|
unCacheStrategie = bungeeCordMode ? new OnDisconnect(this) : UnCacheStrategie.getUnCacheStrategie(this);
|
||||||
|
|
||||||
|
backupFolder = new File(this.plugin.getDataFolder(), "backups");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init()
|
public void init()
|
||||||
@ -109,6 +114,26 @@ public static Database getDatabase(Minepacks plugin)
|
|||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void backup(Backpack backpack)
|
||||||
|
{
|
||||||
|
writeBackup(getPlayerNameOrUUID(backpack.getOwner()), itsSerializer.getUsedSerializer(), itsSerializer.serialize(backpack.getInventory()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeBackup(final String userIdentifier, final int usedSerializer, final byte[] data)
|
||||||
|
{
|
||||||
|
File save = new File(backupFolder, userIdentifier + "_" + System.currentTimeMillis() + Files.EXT);
|
||||||
|
try(FileOutputStream fos = new FileOutputStream(save))
|
||||||
|
{
|
||||||
|
fos.write(usedSerializer);
|
||||||
|
fos.write(data);
|
||||||
|
plugin.getLogger().info("Backup of the backpack has been created: " + save.getAbsolutePath());
|
||||||
|
}
|
||||||
|
catch(Exception e2)
|
||||||
|
{
|
||||||
|
plugin.getLogger().warning("Failed to write backup! Error: " + e2.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected String getPlayerNameOrUUID(OfflinePlayer player)
|
protected String getPlayerNameOrUUID(OfflinePlayer player)
|
||||||
{
|
{
|
||||||
if(useUUIDs)
|
if(useUUIDs)
|
||||||
|
@ -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 = 12, UPGRADE_THRESHOLD = 12;
|
private static final int LANG_VERSION = 13, UPGRADE_THRESHOLD = 13;
|
||||||
|
|
||||||
public Language(JavaPlugin plugin)
|
public Language(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
|
@ -34,8 +34,6 @@
|
|||||||
import org.intellij.lang.annotations.Language;
|
import org.intellij.lang.annotations.Language;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -48,7 +46,6 @@ public abstract class SQL extends Database
|
|||||||
@Language("SQL") protected String queryUpdatePlayerAdd, queryGetPlayerID, queryInsertBp, queryUpdateBp, queryGetBP, queryDeleteOldBackpacks, queryGetUnsetOrInvalidUUIDs, queryFixUUIDs; // DB Querys
|
@Language("SQL") protected String queryUpdatePlayerAdd, queryGetPlayerID, queryInsertBp, queryUpdateBp, queryGetBP, queryDeleteOldBackpacks, queryGetUnsetOrInvalidUUIDs, queryFixUUIDs; // DB Querys
|
||||||
@Language("SQL") protected String queryDeleteOldCooldowns, querySyncCooldown, queryGetCooldown; // DB Querys
|
@Language("SQL") protected String queryDeleteOldCooldowns, querySyncCooldown, queryGetCooldown; // DB Querys
|
||||||
protected boolean updatePlayer, syncCooldown;
|
protected boolean updatePlayer, syncCooldown;
|
||||||
private final File backupFolder;
|
|
||||||
|
|
||||||
public SQL(Minepacks mp)
|
public SQL(Minepacks mp)
|
||||||
{
|
{
|
||||||
@ -94,8 +91,6 @@ public SQL(Minepacks mp)
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
backupFolder = new File(this.plugin.getDataFolder(), "backups");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract @Nullable HikariConfig getPoolConfig();
|
protected abstract @Nullable HikariConfig getPoolConfig();
|
||||||
@ -349,21 +344,6 @@ public void saveBackpack(final Backpack backpack)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeBackup(final String userIdentifier, final int usedSerializer, final byte[] data)
|
|
||||||
{
|
|
||||||
File save = new File(backupFolder, userIdentifier + "_" + System.currentTimeMillis() + Files.EXT);
|
|
||||||
try(FileOutputStream fos = new FileOutputStream(save))
|
|
||||||
{
|
|
||||||
fos.write(usedSerializer);
|
|
||||||
fos.write(data);
|
|
||||||
plugin.getLogger().info("Backup of the backpack has been created: " + save.getAbsolutePath());
|
|
||||||
}
|
|
||||||
catch(Exception e2)
|
|
||||||
{
|
|
||||||
plugin.getLogger().warning("Failed to write backup! Error: " + e2.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadBackpack(final OfflinePlayer player, final Callback<Backpack> callback)
|
protected void loadBackpack(final OfflinePlayer player, final Callback<Backpack> callback)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user