Skip to content

Commit

Permalink
Reduce duplicate saves and fix for owner coming online for all versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Apr 11, 2016
1 parent 0ebe6fe commit eeb28b4
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface ISpecialPlayerInventory {

public Inventory getBukkitInventory();

public boolean inventoryRemovalCheck();
public boolean inventoryRemovalCheck(boolean save);

public void setPlayerOnline(Player player);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,35 @@ public Inventory getBukkitInventory() {
}

@Override
public boolean inventoryRemovalCheck() {
owner.saveData();
return transaction.isEmpty() && !playerOnline;
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save) {
owner.saveData();
}
return offline;
}

@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
}
}

@Override
public boolean setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck();
return this.inventoryRemovalCheck(false);
}

@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck();
this.inventoryRemovalCheck(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,35 @@ public Inventory getBukkitInventory() {
}

@Override
public boolean inventoryRemovalCheck() {
owner.saveData();
return transaction.isEmpty() && !playerOnline;
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save) {
owner.saveData();
}
return offline;
}

@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
}
}

@Override
public boolean setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck();
return this.inventoryRemovalCheck(false);
}

@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck();
this.inventoryRemovalCheck(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,35 @@ public Inventory getBukkitInventory() {
}

@Override
public boolean inventoryRemovalCheck() {
owner.saveData();
return transaction.isEmpty() && !playerOnline;
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save) {
owner.saveData();
}
return offline;
}

@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
}
}

@Override
public boolean setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck();
return this.inventoryRemovalCheck(false);
}

@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck();
this.inventoryRemovalCheck(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,35 @@ public Inventory getBukkitInventory() {
}

@Override
public boolean inventoryRemovalCheck() {
owner.saveData();
return transaction.isEmpty() && !playerOnline;
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save) {
owner.saveData();
}
return offline;
}

@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
}
}

@Override
public boolean setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck();
return this.inventoryRemovalCheck(false);
}

@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck();
this.inventoryRemovalCheck(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,35 @@ public Inventory getBukkitInventory() {
}

@Override
public boolean inventoryRemovalCheck() {
owner.saveData();
return transaction.isEmpty() && !playerOnline;
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save) {
owner.saveData();
}
return offline;
}

@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
}
}

@Override
public boolean setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck();
return this.inventoryRemovalCheck(false);
}

@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck();
this.inventoryRemovalCheck(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,35 @@ public Inventory getBukkitInventory() {
}

@Override
public boolean inventoryRemovalCheck() {
owner.saveData();
return transaction.isEmpty() && !playerOnline;
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save) {
owner.saveData();
}
return offline;
}

@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
}
}

@Override
public boolean setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck();
return this.inventoryRemovalCheck(false);
}

@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck();
this.inventoryRemovalCheck(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,35 @@ public Inventory getBukkitInventory() {
}

@Override
public boolean inventoryRemovalCheck() {
owner.saveData();
return transaction.isEmpty() && !playerOnline;
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save) {
owner.saveData();
}
return offline;
}

@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
}
}

@Override
public boolean setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck();
return this.inventoryRemovalCheck(false);
}

@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck();
this.inventoryRemovalCheck(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,35 @@ public Inventory getBukkitInventory() {
}

@Override
public boolean inventoryRemovalCheck() {
owner.saveData();
return transaction.isEmpty() && !playerOnline;
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save) {
owner.saveData();
}
return offline;
}

@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
CraftPlayer p = (CraftPlayer) player;
p.getHandle().inventory.items = this.items;
p.getHandle().inventory.armor = this.armor;
p.saveData();
owner = (CraftPlayer) player;
this.player = owner.getHandle();
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;
}
}

@Override
public boolean setPlayerOffline() {
playerOnline = false;
return this.inventoryRemovalCheck();
return this.inventoryRemovalCheck(false);
}

@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
this.inventoryRemovalCheck();
this.inventoryRemovalCheck(true);
}

@Override
Expand Down
Loading

0 comments on commit eeb28b4

Please sign in to comment.