Bugfix for not saved backpack

This commit is contained in:
Georg 2015-03-26 18:23:11 +01:00
parent 995a6cf362
commit 761c25f0fc
4 changed files with 9 additions and 14 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>MinePacks</artifactId>
<version>1.4.3</version>
<version>1.5</version>
<repositories>
<repository>
<id>in-project</id>

View File

@ -346,15 +346,12 @@ public void SaveBackpack(Backpack backpack)
}
rs.close();
ps.close();
ps = GetConnection().prepareStatement(Query_InsertBP, Statement.RETURN_GENERATED_KEYS);
ps = GetConnection().prepareStatement(Query_InsertBP);
ps.setInt(1, backpack.getID());
ps.setBytes(2, itsSerializer.Serialize(backpack.getBackpack()));
ps.setInt(3, itsSerializer.getUsedVersion());
ps.executeUpdate();
rs = ps.getGeneratedKeys();
backpack.setID(rs.getInt(1));
ps.execute();
ps.close();
rs.close();
return;
}
else

View File

@ -214,15 +214,12 @@ public void SaveBackpack(Backpack backpack)
}
rs.close();
ps.close();
ps = GetConnection().prepareStatement("INSERT INTO `" + Table_Backpacks + "` (`owner`, `itemstacks`, `version`) VALUES (?,?,?);", Statement.RETURN_GENERATED_KEYS);
ps = GetConnection().prepareStatement("INSERT INTO `" + Table_Backpacks + "` (`owner`, `itemstacks`, `version`) VALUES (?,?,?);");
ps.setInt(1, backpack.getID());
ps.setBytes(2, itsSerializer.Serialize(backpack.getBackpack()));
ps.setInt(3, itsSerializer.getUsedVersion());
ps.executeUpdate();
rs = ps.getGeneratedKeys();
backpack.setID(rs.getInt(1));
ps.execute();
ps.close();
rs.close();
return;
}
else

View File

@ -6,13 +6,14 @@
public class ItemStackSerializer
{
Base serializer;
Base serializer, base;
int usedVersion = 1;
public ItemStackSerializer()
{
String name = Bukkit.getServer().getClass().getPackage().getName();
String[] version = name.substring(name.lastIndexOf('.') + 2).split("_");
base = new Base();
try
{
if(version[0].equals("1"))
@ -34,7 +35,7 @@ else if(version[2].equals("R2"))
if(serializer == null)
{
usedVersion = 0;
serializer = new Base();
serializer = base;
}
}
@ -52,7 +53,7 @@ public ItemStack[] Deserialize(byte[] data, int version)
{
if(version == 0)
{
(new Base()).toItemStack(data);
base.toItemStack(data);
}
return serializer.toItemStack(data);
}