|
|
|
@ -7,6 +7,7 @@ import org.bukkit.block.Chest; |
|
|
|
import org.bukkit.inventory.Inventory; |
|
|
|
import org.bukkit.inventory.Inventory; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.DaoRegistry; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.DaoRegistry; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.Converter; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.Converter; |
|
|
|
|
|
|
|
import xyz.soukup.ecoCraftCore.utilities.PDC; |
|
|
|
|
|
|
|
|
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
|
|
|
|
|
|
|
|
@ -17,7 +18,7 @@ public class VirtualChest { |
|
|
|
private int id; |
|
|
|
private int id; |
|
|
|
|
|
|
|
|
|
|
|
@DatabaseField(columnName = "inventory", dataType = DataType.LONG_STRING) |
|
|
|
@DatabaseField(columnName = "inventory", dataType = DataType.LONG_STRING) |
|
|
|
private String inventoryJson; |
|
|
|
private String inventoryString; |
|
|
|
|
|
|
|
|
|
|
|
@DatabaseField(columnName = "active_on_server") |
|
|
|
@DatabaseField(columnName = "active_on_server") |
|
|
|
private String activeServer; |
|
|
|
private String activeServer; |
|
|
|
@ -32,10 +33,27 @@ public class VirtualChest { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public VirtualChest(Chest chest){ |
|
|
|
public VirtualChest(Chest chest){ |
|
|
|
Inventory inventory = chest.getSnapshotInventory(); |
|
|
|
Inventory inventory = chest.getSnapshotInventory(); |
|
|
|
this.inventoryJson = Converter.toString(inventory); |
|
|
|
this.inventoryString = Converter.toString(inventory); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static VirtualChest getOrCreate(Chest chest){ |
|
|
|
|
|
|
|
Integer id = PDC.getInteger(chest, "virtual"); |
|
|
|
|
|
|
|
if (id == null){ |
|
|
|
|
|
|
|
return new VirtualChest(chest); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VirtualChest virtualChest = findById(id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (virtualChest == null){ |
|
|
|
|
|
|
|
return new VirtualChest(chest); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return virtualChest; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static VirtualChest findById(int id) { |
|
|
|
public static VirtualChest findById(int id) { |
|
|
|
@ -48,7 +66,7 @@ public class VirtualChest { |
|
|
|
|
|
|
|
|
|
|
|
public void save(){ |
|
|
|
public void save(){ |
|
|
|
if (this.inventory != null){ |
|
|
|
if (this.inventory != null){ |
|
|
|
this.inventoryJson = Converter.toString(this.inventory); |
|
|
|
this.inventoryString = Converter.toString(this.inventory); |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
DaoRegistry.getVirtualChestDao().createOrUpdate(this); |
|
|
|
DaoRegistry.getVirtualChestDao().createOrUpdate(this); |
|
|
|
@ -59,7 +77,7 @@ public class VirtualChest { |
|
|
|
|
|
|
|
|
|
|
|
public Inventory getInventory(){ |
|
|
|
public Inventory getInventory(){ |
|
|
|
if (this.inventory == null){ |
|
|
|
if (this.inventory == null){ |
|
|
|
this.inventory = Converter.inventoryFromString(this.inventoryJson); |
|
|
|
this.inventory = Converter.inventoryFromString(this.inventoryString); |
|
|
|
} |
|
|
|
} |
|
|
|
return this.inventory; |
|
|
|
return this.inventory; |
|
|
|
} |
|
|
|
} |
|
|
|
|