Skip to content

Commit

Permalink
Improve handling of old backpacks on MC 1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgH93 committed Apr 27, 2019
1 parent e5045dc commit 636acc2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>MinePacks</artifactId>
<version>1.19</version>
<version>1.19.1</version>

<scm>
<connection>scm:git:[email protected]:GeorgH93/Minepacks.git</connection>
Expand Down
4 changes: 4 additions & 0 deletions src/at/pcgamingfreaks/MinePacks/Database/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import javax.swing.filechooser.FileFilter;

import at.pcgamingfreaks.Bukkit.MCVersion;
import at.pcgamingfreaks.ConsoleColor;
import at.pcgamingfreaks.UUIDConverter;
import org.bukkit.OfflinePlayer;

Expand Down Expand Up @@ -51,6 +53,8 @@ public Files(MinePacks mp)
CheckFiles();
rewrite(); // Make convert all old backpacks into the new format
}

if(MCVersion.isAny(MCVersion.MC_1_14)) plugin.getLogger().warning(ConsoleColor.RED + "The used storage backend might has a negative performance impact on MC 1.14!" + ConsoleColor.RESET);
}

@SuppressWarnings("ResultOfMethodCallIgnored")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2018 GeorgH93
* Copyright (C) 2014-2019 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
Expand Down Expand Up @@ -34,7 +34,7 @@ public class InventorySerializer
{
private ItemStackSerializer serializer, serializerGen1, serializerGen2, bukkitItemStackSerializer = new BukkitItemStackSerializer();
private int usedSerializer = 2;
private Logger logger;
private final Logger logger;

public InventorySerializer(Logger logger)
{
Expand Down Expand Up @@ -87,10 +87,12 @@ public byte[] serialize(ItemStack[] inv)

public ItemStack[] deserialize(byte[] data, int usedSerializer)
{
if(usedSerializer > this.usedSerializer) logger.warning(ConsoleColor.RED + "The backpack was written using a newer version than the currently used one! It might cause problems." + ConsoleColor.RESET);
switch(usedSerializer)
{
case 0: return bukkitItemStackSerializer.deserialize(data);
case 1: return serializerGen1.deserialize(data);
case 1: if(serializerGen1 != null) return serializerGen1.deserialize(data);
else if(MCVersion.isNewerOrEqualThan(MCVersion.MC_1_14)) logger.warning(ConsoleColor.RED + "This backpack was saved with an older version of MC! Some items may be lost!" + ConsoleColor.RESET);
case 2: return serializerGen2.deserialize(data);
default: logger.warning(ConsoleColor.RED + "No compatible serializer for item format available!" + ConsoleColor.RESET);
}
Expand Down

0 comments on commit 636acc2

Please sign in to comment.