Code cleanup

This commit is contained in:
GeorgH93 2017-01-28 23:26:02 +01:00
parent 3b99fb9150
commit 9ae1909200
5 changed files with 21 additions and 13 deletions

View File

@ -19,7 +19,6 @@
import at.pcgamingfreaks.Bukkit.Configuration;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.plugin.java.JavaPlugin;

View File

@ -41,7 +41,8 @@ public abstract class Database implements Listener
protected final Minepacks plugin;
protected final InventorySerializer itsSerializer = new InventorySerializer();
protected boolean useUUIDs, useUUIDSeparators;
protected final boolean useUUIDs;
protected boolean useUUIDSeparators;
protected long maxAge;
private final Map<OfflinePlayer, Backpack> backpacks = new ConcurrentHashMap<>();
private final UnCacheStrategie unCacheStrategie;

View File

@ -21,7 +21,6 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.util.Date;
import javax.swing.filechooser.FileFilter;
@ -82,7 +81,10 @@ private void checkFiles()
{
if(len <= 16) // It's a player name
{
file.renameTo(new File(saveFolder, UUIDConverter.getUUIDFromName(file.getName().substring(0, len), true, useUUIDSeparators) + EXT));
if(!file.renameTo(new File(saveFolder, UUIDConverter.getUUIDFromName(file.getName().substring(0, len), true, useUUIDSeparators) + EXT)))
{
plugin.getLogger().warning("Failed to rename file (" + file.getAbsolutePath() + ").");
}
}
else // It's an UUID
{
@ -90,14 +92,20 @@ private void checkFiles()
{
if(!useUUIDSeparators)
{
file.renameTo(new File(saveFolder, file.getName().replaceAll("-", "")));
if(!file.renameTo(new File(saveFolder, file.getName().replaceAll("-", ""))))
{
plugin.getLogger().warning("Failed to rename file (" + file.getAbsolutePath() + ").");
}
}
}
else
{
if(useUUIDSeparators)
{
file.renameTo(new File(saveFolder, file.getName().replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})" + EXT_REGEX, "$1-$2-$3-$4-$5" + EXT)));
if(!file.renameTo(new File(saveFolder, file.getName().replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})" + EXT_REGEX, "$1-$2-$3-$4-$5" + EXT))))
{
plugin.getLogger().warning("Failed to rename file (" + file.getAbsolutePath() + ").");
}
}
}
}
@ -170,7 +178,7 @@ public Backpack loadBackpack(OfflinePlayer player)
private static class BackpackFileFilter extends FileFilter implements FilenameFilter
{
String description, extension;
final String description, extension;
public BackpackFileFilter()
{

View File

@ -27,7 +27,8 @@
public class InventorySerializer
{
private ItemStackSerializer serializer, baseItemStackSerializer = new BukkitItemStackSerializer();
private static final ItemStackSerializer BUKKIT_ITEM_STACK_SERIALIZER = new BukkitItemStackSerializer();
private ItemStackSerializer serializer;
private int usedSerializer = 1;
public InventorySerializer()
@ -48,7 +49,7 @@ public InventorySerializer()
if(serializer == null)
{
usedSerializer = 0;
serializer = baseItemStackSerializer;
serializer = BUKKIT_ITEM_STACK_SERIALIZER;
}
}
@ -68,7 +69,7 @@ public ItemStack[] deserialize(byte[] data, int usedSerializer)
if(data == null) return null;
switch(usedSerializer)
{
case 0: return baseItemStackSerializer.deserialize(data);
case 0: return BUKKIT_ITEM_STACK_SERIALIZER.deserialize(data);
default: return serializer.deserialize(data);
}
}

View File

@ -33,9 +33,8 @@
public class EventListener implements Listener
{
private Minepacks plugin;
private Message messageOwnBackpackClose, messageOtherBackpackClose;
private final Minepacks plugin;
private final Message messageOwnBackpackClose, messageOtherBackpackClose;
public EventListener(Minepacks mp)
{