* Fixed - player data glitch and online/offline events #41
@@ -51,7 +51,6 @@ public class SpecialEnderChest extends InventorySubcontainer {
|
|||||||
private void saveOnExit() {
|
private void saveOnExit() {
|
||||||
if (transaction.isEmpty() && !playerOnline) {
|
if (transaction.isEmpty() && !playerOnline) {
|
||||||
owner.saveData();
|
owner.saveData();
|
||||||
OpenInv.enderChests.remove(owner.getUniqueId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +81,7 @@ public class SpecialEnderChest extends InventorySubcontainer {
|
|||||||
public void onClose(CraftHumanEntity who) {
|
public void onClose(CraftHumanEntity who) {
|
||||||
super.onClose(who);
|
super.onClose(who);
|
||||||
saveOnExit();
|
saveOnExit();
|
||||||
|
OpenInv.enderChests.remove(owner.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -33,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory {
|
|||||||
|
|
||||||
private final CraftInventory inventory = new CraftInventory(this);
|
private final CraftInventory inventory = new CraftInventory(this);
|
||||||
private final ItemStack[] extra = new ItemStack[4];
|
private final ItemStack[] extra = new ItemStack[4];
|
||||||
private final ItemStack[][] arrays;
|
private ItemStack[][] arrays;
|
||||||
private final CraftPlayer owner;
|
private final CraftPlayer owner;
|
||||||
private boolean playerOnline;
|
private boolean playerOnline;
|
||||||
|
|
||||||
@@ -41,7 +41,6 @@ public class SpecialPlayerInventory extends PlayerInventory {
|
|||||||
super(((CraftPlayer) p).getHandle());
|
super(((CraftPlayer) p).getHandle());
|
||||||
this.owner = (CraftPlayer) p;
|
this.owner = (CraftPlayer) p;
|
||||||
reflectContents(getClass().getSuperclass(), player.inventory, this);
|
reflectContents(getClass().getSuperclass(), player.inventory, this);
|
||||||
this.arrays = new ItemStack[][] { this.items, this.armor, this.extraSlots, this.extra };
|
|
||||||
this.playerOnline = online;
|
this.playerOnline = online;
|
||||||
OpenInv.inventories.put(owner.getUniqueId(), this);
|
OpenInv.inventories.put(owner.getUniqueId(), this);
|
||||||
}
|
}
|
||||||
@@ -68,6 +67,7 @@ public class SpecialPlayerInventory extends PlayerInventory {
|
|||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
arrays = new ItemStack[][] { this.items, this.armor, this.extraSlots, this.extra };
|
||||||
}
|
}
|
||||||
|
|
||||||
public Inventory getBukkitInventory() {
|
public Inventory getBukkitInventory() {
|
||||||
@@ -77,7 +77,6 @@ public class SpecialPlayerInventory extends PlayerInventory {
|
|||||||
private void saveOnExit() {
|
private void saveOnExit() {
|
||||||
if (transaction.isEmpty() && !playerOnline) {
|
if (transaction.isEmpty() && !playerOnline) {
|
||||||
owner.saveData();
|
owner.saveData();
|
||||||
OpenInv.inventories.remove(owner.getUniqueId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +104,7 @@ public class SpecialPlayerInventory extends PlayerInventory {
|
|||||||
public void onClose(CraftHumanEntity who) {
|
public void onClose(CraftHumanEntity who) {
|
||||||
super.onClose(who);
|
super.onClose(who);
|
||||||
this.saveOnExit();
|
this.saveOnExit();
|
||||||
|
OpenInv.inventories.remove(owner.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -30,6 +30,7 @@ import org.bukkit.event.block.Action;
|
|||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
import com.lishid.openinv.OpenInv;
|
||||||
import com.lishid.openinv.Permissions;
|
import com.lishid.openinv.Permissions;
|
||||||
@@ -40,7 +41,7 @@ public class OpenInvPlayerListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
SpecialPlayerInventory inventory = OpenInv.inventories.get(player.getUniqueId());
|
SpecialPlayerInventory inventory = OpenInv.inventories.get(player.getUniqueId());
|
||||||
if (inventory != null) {
|
if (inventory != null) {
|
||||||
inventory.playerOnline(event.getPlayer());
|
inventory.playerOnline(event.getPlayer());
|
||||||
@@ -52,18 +53,28 @@ public class OpenInvPlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
SpecialPlayerInventory inventory = OpenInv.inventories.get(player.getUniqueId());
|
final SpecialPlayerInventory inventory = OpenInv.inventories.get(player.getUniqueId());
|
||||||
if (inventory != null) {
|
if (inventory != null) {
|
||||||
inventory.playerOffline();
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
inventory.playerOffline();
|
||||||
|
}
|
||||||
|
}.runTaskLater(OpenInv.mainPlugin, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpecialEnderChest chest = OpenInv.enderChests.get(player.getUniqueId());
|
final SpecialEnderChest chest = OpenInv.enderChests.get(player.getUniqueId());
|
||||||
if (chest != null) {
|
if (chest != null) {
|
||||||
chest.playerOffline();
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
chest.playerOffline();
|
||||||
|
}
|
||||||
|
}.runTaskLater(OpenInv.mainPlugin, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user