Code cleanup

This commit is contained in:
GeorgH93 2018-07-25 23:55:28 +02:00
parent 7c1db6199e
commit 86ced09103
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
3 changed files with 6 additions and 14 deletions

View File

@ -35,7 +35,7 @@
public class Files extends Database
{
protected static final String EXT = ".backpack", EXT_REGEX = "\\.backpack";
public static final String EXT = ".backpack", EXT_REGEX = "\\.backpack", FOLDER_NAME = "backpacks";
private final File saveFolder;
@ -43,7 +43,7 @@ public Files(Minepacks plugin)
{
super(plugin);
maxAge *= 24 * 3600000L;
saveFolder = new File(this.plugin.getDataFolder(), "backpacks");
saveFolder = new File(this.plugin.getDataFolder(), FOLDER_NAME);
if(!saveFolder.exists())
{
if(!saveFolder.mkdirs())

View File

@ -55,12 +55,6 @@ public byte[] serialize(Inventory inv)
return serializer.serialize(inv.getContents());
}
@SuppressWarnings("unused")
public ItemStack[] deserialize(byte[] data)
{
return deserialize(data, usedSerializer);
}
public ItemStack[] deserialize(byte[] data, int usedSerializer)
{
if(data == null) return null;

View File

@ -18,6 +18,7 @@
package at.pcgamingfreaks.Minepacks.Bukkit.Database.Migration;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Database;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Files;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.SQL;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import at.pcgamingfreaks.Reflection;
@ -43,11 +44,8 @@ protected SQLtoFilesMigration(@NotNull Minepacks plugin, @NotNull Database oldDb
super(plugin, oldDb);
@Language("SQL") String query = "SELECT " + (plugin.getConfiguration().getUseUUIDs() ? "{FieldUUID}" : "{FieldName}") + ",{FieldBPITS},{FieldBPVersion} FROM {TablePlayers} INNER JOIN {TableBackpacks} ON {FieldPlayerID}={FieldBPOwner};";
sqlQuery = (String) Reflection.getMethod(SQL.class, "replacePlaceholders", String.class).invoke(plugin.getDatabase(), query);
saveFolder = new File(this.plugin.getDataFolder(), "backpacks");
if(!saveFolder.exists() && !saveFolder.mkdirs())
{
plugin.getLogger().warning("Failed to create save folder (" + saveFolder.getAbsolutePath() + ").");
}
saveFolder = new File(this.plugin.getDataFolder(), Files.FOLDER_NAME);
if(!saveFolder.exists() && !saveFolder.mkdirs()) plugin.getLogger().warning("Failed to create save folder (" + saveFolder.getAbsolutePath() + ").");
}
@Override
@ -58,7 +56,7 @@ protected SQLtoFilesMigration(@NotNull Minepacks plugin, @NotNull Database oldDb
{
while(rs.next())
{
try(FileOutputStream fos = new FileOutputStream(new File(saveFolder, rs.getString(1) + ".backpack")))
try(FileOutputStream fos = new FileOutputStream(new File(saveFolder, rs.getString(1) + Files.EXT)))
{
fos.write(rs.getInt(3));
fos.write(rs.getBytes(2));