Implement cbarber's player data glitch and online/offline event changes
This commit is contained in:
		
							
								
								
									
										4
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								pom.xml
									
									
									
									
									
								
							@@ -23,14 +23,14 @@
 | 
				
			|||||||
        <dependency>
 | 
					        <dependency>
 | 
				
			||||||
            <groupId>org.bukkit</groupId>
 | 
					            <groupId>org.bukkit</groupId>
 | 
				
			||||||
            <artifactId>bukkit</artifactId>
 | 
					            <artifactId>bukkit</artifactId>
 | 
				
			||||||
            <version>1.9-R0.1-SNAPSHOT</version>
 | 
					            <version>1.9.2-R0.1-SNAPSHOT</version>
 | 
				
			||||||
            <scope>provided</scope>
 | 
					            <scope>provided</scope>
 | 
				
			||||||
        </dependency>
 | 
					        </dependency>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <dependency>
 | 
					        <dependency>
 | 
				
			||||||
            <groupId>org.bukkit</groupId>
 | 
					            <groupId>org.bukkit</groupId>
 | 
				
			||||||
            <artifactId>craftbukkit</artifactId>
 | 
					            <artifactId>craftbukkit</artifactId>
 | 
				
			||||||
            <version>1.9-R0.1-SNAPSHOT</version>
 | 
					            <version>1.9.2-R0.1-SNAPSHOT</version>
 | 
				
			||||||
            <scope>provided</scope>
 | 
					            <scope>provided</scope>
 | 
				
			||||||
        </dependency>
 | 
					        </dependency>
 | 
				
			||||||
    </dependencies>
 | 
					    </dependencies>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -106,6 +106,7 @@ public class OpenInvCommand implements CommandExecutor {
 | 
				
			|||||||
                                if (player == null) {
 | 
					                                if (player == null) {
 | 
				
			||||||
                                    return;
 | 
					                                    return;
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                openInventory(player, target);
 | 
					                                openInventory(player, target);
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        });
 | 
					                        });
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,15 +35,14 @@ 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 final CraftPlayer owner;
 | 
					    private final CraftPlayer owner;
 | 
				
			||||||
 | 
					    private ItemStack[][] arrays;
 | 
				
			||||||
    private boolean playerOnline;
 | 
					    private boolean playerOnline;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public SpecialPlayerInventory(Player p, boolean online) {
 | 
					    public SpecialPlayerInventory(Player p, boolean online) {
 | 
				
			||||||
        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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -70,6 +69,8 @@ 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() {
 | 
				
			||||||
@@ -79,7 +80,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());
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -107,6 +107,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;
 | 
				
			||||||
@@ -62,19 +63,29 @@ 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) {
 | 
				
			||||||
 | 
					            new BukkitRunnable() {
 | 
				
			||||||
 | 
					                @Override
 | 
				
			||||||
 | 
					                public void run() {
 | 
				
			||||||
                    inventory.playerOffline();
 | 
					                    inventory.playerOffline();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					            }.runTaskLater(plugin, 1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        SpecialEnderChest enderChest = OpenInv.enderChests.get(player.getUniqueId());
 | 
					        final SpecialEnderChest enderChest = OpenInv.enderChests.get(player.getUniqueId());
 | 
				
			||||||
        if (enderChest != null) {
 | 
					        if (enderChest != null) {
 | 
				
			||||||
 | 
					            new BukkitRunnable() {
 | 
				
			||||||
 | 
					                @Override
 | 
				
			||||||
 | 
					                public void run() {
 | 
				
			||||||
                    enderChest.playerOffline();
 | 
					                    enderChest.playerOffline();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					            }.runTaskLater(plugin, 1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @EventHandler
 | 
					    @EventHandler
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user