Add BungeeCordMode option

Remove unused code
This commit is contained in:
GeorgH93 2017-11-04 17:14:07 +01:00
parent 1117c667c6
commit 86aa0e5630
5 changed files with 27 additions and 64 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016, 2017 GeorgH93
* Copyright (C) 2016-2017 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
@ -179,7 +179,12 @@ public int getBackpackMaxSize()
public boolean getAutoUpdate()
{
return config.getBoolean("auto-update", true);
return config.getBoolean("Misc.AutoUpdate", true);
}
public boolean isBungeeCordModeEnabled()
{
return config.getBoolean("Misc.UseBungeeCord", false);
}
public long getCommandCooldown()

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 GeorgH93
* Copyright (C) 2016-2017 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.Minepacks.Bukkit.API.Callback;
import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.UnCacheStrategies.OnDisconnect;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.UnCacheStrategies.UnCacheStrategie;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
@ -41,7 +42,7 @@ public abstract class Database implements Listener
protected final Minepacks plugin;
protected final InventorySerializer itsSerializer = new InventorySerializer();
protected final boolean useUUIDs;
protected final boolean useUUIDs, bungeeCordMode;
protected boolean useUUIDSeparators;
protected long maxAge;
private final Map<OfflinePlayer, Backpack> backpacks = new ConcurrentHashMap<>();
@ -52,8 +53,9 @@ public Database(Minepacks mp)
plugin = mp;
useUUIDSeparators = plugin.config.getUseUUIDSeparators();
useUUIDs = plugin.config.getUseUUIDs();
bungeeCordMode = plugin.config.isBungeeCordModeEnabled();
maxAge = plugin.config.getAutoCleanupMaxInactiveDays();
unCacheStrategie = UnCacheStrategie.getUnCacheStrategie(this);
unCacheStrategie = bungeeCordMode ? new OnDisconnect(this) : UnCacheStrategie.getUnCacheStrategie(this);
}
public void init()
@ -112,30 +114,17 @@ protected String getPlayerFormattedUUID(OfflinePlayer player)
return backpacks.values();
}
/**
* Gets a backpack for a player. This only includes backpacks that are cached! Do not use it unless you are sure that you only want to use cached data!
*
* @param player The player who's backpack should be retrieved.
* @return The backpack for the player. null if the backpack is not in the cache.
*/
public @Nullable Backpack getBackpack(@Nullable OfflinePlayer player)
{
return (player == null) ? null : backpacks.get(player);
}
public Backpack getBackpack(OfflinePlayer player, boolean loadedOnly)
{
if(player == null)
{
return null;
}
Backpack lbp = backpacks.get(player);
if(lbp == null && !loadedOnly)
{
lbp = loadBackpack(player);
if(lbp == null)
{
lbp = new Backpack(player);
}
backpacks.put(player, lbp);
}
return lbp;
}
public void getBackpack(final OfflinePlayer player, final Callback<Backpack> callback)
{
if(player == null)
@ -205,7 +194,7 @@ public void onPlayerLoginEvent(PlayerJoinEvent event)
public void updatePlayerAndLoadBackpack(Player player)
{
updatePlayer(player);
asyncLoadBackpack(player);
if(!bungeeCordMode) asyncLoadBackpack(player);
}
public abstract void updatePlayer(Player player);
@ -214,18 +203,5 @@ public void updatePlayerAndLoadBackpack(Player player)
public abstract void syncCooldown(Player player, long time);
protected abstract Backpack loadBackpack(OfflinePlayer player);
protected void loadBackpack(final OfflinePlayer player, final Callback<Backpack> callback)
{
Backpack loadedBackpack = loadBackpack(player);
if(loadedBackpack == null)
{
callback.onFail();
}
else
{
callback.onResult(loadedBackpack);
}
}
protected abstract void loadBackpack(final OfflinePlayer player, final Callback<Backpack> callback);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 GeorgH93
* Copyright (C) 2016-2017 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
@ -24,6 +24,7 @@
import javax.swing.filechooser.FileFilter;
import at.pcgamingfreaks.Minepacks.Bukkit.API.Callback;
import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import at.pcgamingfreaks.UUIDConverter;
@ -149,7 +150,7 @@ public void syncCooldown(Player player, long time)
}
@Override
public Backpack loadBackpack(OfflinePlayer player)
protected void loadBackpack(final OfflinePlayer player, final Callback<Backpack> callback)
{
File save = new File(saveFolder, getFileName(player));
try
@ -165,7 +166,7 @@ public Backpack loadBackpack(OfflinePlayer player)
{
plugin.getLogger().warning("Problem reading file, only read " + c + " of " + v + " bytes.");
}
return new Backpack(player, itsSerializer.deserialize(out, v), -1);
callback.onResult(new Backpack(player, itsSerializer.deserialize(out, v), -1));
}
}
}
@ -173,7 +174,7 @@ public Backpack loadBackpack(OfflinePlayer player)
{
e.printStackTrace();
}
return null;
callback.onFail();
}
private static class BackpackFileFilter extends FileFilter implements FilenameFilter

View File

@ -379,27 +379,6 @@ protected void loadBackpack(final OfflinePlayer player, final Callback<Backpack>
}
});
}
@Override
public Backpack loadBackpack(OfflinePlayer player) // The sync function shouldn't be called at all
{
try(Connection connection = getConnection(); PreparedStatement ps = connection.prepareStatement(queryGetBP))
{
ps.setString(1, getPlayerNameOrUUID(player));
try(ResultSet rs = ps.executeQuery())
{
if(rs.next())
{
return new Backpack(player, itsSerializer.deserialize(rs.getBytes(2), rs.getInt(3)), rs.getInt(1));
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
@Override
public void syncCooldown(Player player, long cooldownTime)

View File

@ -89,5 +89,7 @@ public void onPlayerLeaveEvent(PlayerQuitEvent event)
{
plugin.cooldowns.remove(event.getPlayer().getUniqueId());
}
Backpack backpack = plugin.getDb().getBackpack(event.getPlayer());
if(backpack != null) backpack.save();
}
}