mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-01-06 19:18:07 +01:00
Some more adjustments for MC 1.20.1
This commit is contained in:
parent
cf7a6c0617
commit
a87b198632
@ -121,14 +121,14 @@ public void close()
|
||||
catch(IllegalStateException ignored) {}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to initialize database.", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void backup(@NotNull Backpack backpack)
|
||||
{
|
||||
writeBackup(backpack.getOwner().getName(), getPlayerFormattedUUID(backpack.getOwner()), itsSerializer.getUsedSerializer(), itsSerializer.serialize(backpack.getInventory()));
|
||||
writeBackup(backpack.getOwner().getName(), getPlayerFormattedUUID(backpack.getOwnerId()), itsSerializer.getUsedSerializer(), itsSerializer.serialize(backpack.getInventory()));
|
||||
}
|
||||
|
||||
protected void writeBackup(@Nullable String userName, @NotNull String userIdentifier, final int usedSerializer, final byte[] data)
|
||||
@ -172,7 +172,12 @@ public ArrayList<String> getBackups()
|
||||
|
||||
protected String getPlayerFormattedUUID(OfflinePlayer player)
|
||||
{
|
||||
return (useUUIDSeparators) ? player.getUniqueId().toString() : player.getUniqueId().toString().replace("-", "");
|
||||
return getPlayerFormattedUUID(player.getUniqueId());
|
||||
}
|
||||
|
||||
protected String getPlayerFormattedUUID(UUID uuid)
|
||||
{
|
||||
return (useUUIDSeparators) ? uuid.toString() : uuid.toString().replace("-", "");
|
||||
}
|
||||
|
||||
public @NotNull Collection<Backpack> getLoadedBackpacks()
|
||||
@ -238,7 +243,6 @@ public void getBackpack(final OfflinePlayer player, final Callback<at.pcgamingfr
|
||||
|
||||
public void unloadBackpack(Backpack backpack)
|
||||
{
|
||||
plugin.getLogger().log(Level.INFO, "Unloading backpack of {0} ({1})", new Object[] {backpack.getOwner().getName(), backpack.getOwner().getUniqueId()});
|
||||
if (forceSaveOnUnload)
|
||||
{
|
||||
backpack.forceSave();
|
||||
@ -247,7 +251,7 @@ public void unloadBackpack(Backpack backpack)
|
||||
{
|
||||
backpack.save();
|
||||
}
|
||||
backpacks.remove(backpack.getOwner().getUniqueId());
|
||||
backpacks.remove(backpack.getOwnerId());
|
||||
}
|
||||
|
||||
public void asyncLoadBackpack(final OfflinePlayer player)
|
||||
|
@ -30,6 +30,8 @@
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Files extends Database
|
||||
@ -68,13 +70,13 @@ private void checkFiles()
|
||||
if(allFiles == null) return;
|
||||
for (File file : allFiles)
|
||||
{
|
||||
if(maxAge > 0 && System.currentTimeMillis() - file.lastModified() > maxAge) // Check if the file is older then x days
|
||||
if(maxAge > 0 && System.currentTimeMillis() - file.lastModified() > maxAge) // Check if the file is older than x days
|
||||
{
|
||||
if(!file.delete())
|
||||
{
|
||||
plugin.getLogger().warning("Failed to delete file (" + file.getAbsolutePath() + ").");
|
||||
}
|
||||
continue; // We don't have to check if the file name is correct cause we have the deleted the file
|
||||
continue; // We don't have to check if the file name is correct because we have the deleted the file
|
||||
}
|
||||
int len = file.getName().length() - EXT.length();
|
||||
if(len <= 16) // It's a player name
|
||||
@ -110,16 +112,16 @@ private void checkFiles()
|
||||
}
|
||||
}
|
||||
|
||||
private String getFileName(OfflinePlayer player)
|
||||
private String getFileName(UUID uuid)
|
||||
{
|
||||
return getPlayerFormattedUUID(player) + EXT;
|
||||
return getPlayerFormattedUUID(uuid) + EXT;
|
||||
}
|
||||
|
||||
// DB Functions
|
||||
@Override
|
||||
public void saveBackpack(Backpack backpack)
|
||||
{
|
||||
File save = new File(saveFolder, getFileName(backpack.getOwner()));
|
||||
File save = new File(saveFolder, getFileName(backpack.getOwnerId()));
|
||||
try(FileOutputStream fos = new FileOutputStream(save))
|
||||
{
|
||||
fos.write(itsSerializer.getUsedSerializer());
|
||||
@ -128,7 +130,7 @@ public void saveBackpack(Backpack backpack)
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to save backpack.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,7 +163,7 @@ protected void loadBackpack(final OfflinePlayer player, final Callback<Backpack>
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
logger.log(Level.WARNING, "Failed to read backpack.", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -203,7 +203,7 @@ public void saveBackpack(final Backpack backpack)
|
||||
{
|
||||
final byte[] data = itsSerializer.serialize(backpack.getInventory());
|
||||
final int id = backpack.getOwnerDatabaseId(), usedSerializer = itsSerializer.getUsedSerializer();
|
||||
final String nameOrUUID = getPlayerFormattedUUID(backpack.getOwner()), name = backpack.getOwner().getName();
|
||||
final String nameOrUUID = getPlayerFormattedUUID(backpack.getOwnerId()), name = backpack.getOwner().getName();
|
||||
|
||||
Runnable runnable = () -> {
|
||||
try(Connection connection = getConnection())
|
||||
|
@ -37,7 +37,7 @@ public void run()
|
||||
{
|
||||
for(Backpack backpack : cache.getLoadedBackpacks())
|
||||
{
|
||||
if(!backpack.getOwner().isOnline() && !backpack.isOpen())
|
||||
if(backpack.getOwnerPlayer() == null && !backpack.isOpen())
|
||||
{
|
||||
this.cache.unloadBackpack(backpack);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class IntervalChecked extends UnCacheStrategy implements Runnable
|
||||
{
|
||||
@ -42,7 +43,8 @@ public void run()
|
||||
long currentTime = System.currentTimeMillis() - delay;
|
||||
for(Backpack backpack : cache.getLoadedBackpacks())
|
||||
{
|
||||
if(!backpack.getOwner().isOnline() && backpack.getOwner().getLastPlayed() < currentTime && !backpack.isOpen())
|
||||
OfflinePlayer owner = backpack.getOwner();
|
||||
if(!owner.isOnline() && owner.getLastPlayed() < currentTime && !backpack.isOpen())
|
||||
{
|
||||
this.cache.unloadBackpack(backpack);
|
||||
}
|
||||
|
@ -55,14 +55,13 @@ public void onClose(InventoryCloseEvent event)
|
||||
backpack.save();
|
||||
}
|
||||
backpack.close(closer);
|
||||
if(event.getPlayer().getUniqueId().equals(backpack.getOwner().getUniqueId()))
|
||||
if(event.getPlayer().getUniqueId().equals(backpack.getOwnerId()))
|
||||
{
|
||||
messageOwnBackpackClose.send(closer);
|
||||
}
|
||||
else
|
||||
{
|
||||
OfflinePlayer owner = backpack.getOwner();
|
||||
messageOtherBackpackClose.send(closer, owner);
|
||||
messageOtherBackpackClose.send(closer, backpack.getOwner());
|
||||
}
|
||||
if(closeSound != null)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user