Skip to content

Commit

Permalink
inventory patches
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 23, 2018
1 parent 11e593d commit b72b161
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public String getSaveObject() {
return "in@" + idType + PropertyParser.getPropertiesString(this);
}

public String notableColors = null;

public void makeUnique(String id) {
String title = inventory.getTitle();
if (title == null || title.startsWith("container.")) {
Expand All @@ -114,9 +116,16 @@ public void makeUnique(String id) {
title = title.substring(0, title.charAt(25) == '§' ? 25 : 26);
}
String colors;
int x = 0;
while (true) {
x++;
if (x > 5000) {
dB.echoError("Inventory note failed - too many notes already!");
return;
}
colors = Utilities.generateRandomColors(3);
if (!InventoryScriptHelper.notableInventories.containsKey(title + colors)) {
notableColors = colors;
ItemStack[] contents = inventory.getContents();
if (getInventoryType() == InventoryType.CHEST) {
inventory = Bukkit.getServer().createInventory(null, inventory.getSize(), title + colors);
Expand All @@ -136,6 +145,7 @@ public void makeUnique(String id) {
}

public void forget() {
notableColors = null;
NotableManager.remove(idHolder);
}

Expand Down Expand Up @@ -410,6 +420,12 @@ public void setTitle(String title) {
if (!(getIdType().equals("generic") || getIdType().equals("script")) || title == null) {
return;
}
if (inventory.getTitle().equals(title)) {
return;
}
if (notableColors != null) {
title += notableColors;
}
else if (inventory == null) {
inventory = Bukkit.getServer().createInventory(null, maxSlots, title);
loadIdentifiers();
Expand Down Expand Up @@ -572,7 +588,7 @@ else if (holder instanceof Entity) {
}
else if (getIdType().equals("player")) {
// Iterate through offline player inventories
for (Map.Entry<UUID, PlayerInventory> inv : ImprovedOfflinePlayer.offlineInventories.entrySet()) {
for (Map.Entry<UUID, PlayerInventory> inv : ImprovedOfflinePlayer.offlineInventories.entrySet()) { // TODO: Less weird lookup?
if (inv.getValue().equals(inventory)) {
idHolder = new dPlayer(inv.getKey()).identify();
return;
Expand All @@ -581,7 +597,7 @@ else if (getIdType().equals("player")) {
}
else if (getIdType().equals("enderchest")) {
// Iterate through offline player enderchests
for (Map.Entry<UUID, Inventory> inv : ImprovedOfflinePlayer.offlineEnderChests.entrySet()) {
for (Map.Entry<UUID, Inventory> inv : ImprovedOfflinePlayer.offlineEnderChests.entrySet()) { // TODO: Less weird lookup?
if (inv.getValue().equals(inventory)) {
idHolder = new dPlayer(inv.getKey()).identify();
return;
Expand Down

0 comments on commit b72b161

Please sign in to comment.