MCPcopy Create free account
hub / github.com/boxbeam/RedLib / destroy

Method destroy

src/redempt/redlib/inventorygui/InventoryGUI.java:373–389  ·  view source on GitHub ↗

Remove this inventory as a listener and clean everything up to prevent memory leaks. Call this when the GUI is no longer being used. @param lastViewer The last Player who was viewing this GUI, to have the items returned to them.

(Player lastViewer)

Source from the content-addressed store, hash-verified

371 * @param lastViewer The last Player who was viewing this GUI, to have the items returned to them.
372 */
373 public void destroy(Player lastViewer) {
374 if (onDestroy != null) {
375 onDestroy.run();
376 }
377 HandlerList.unregisterAll(this);
378 if (returnItems && lastViewer != null) {
379 for (int slot : openSlots) {
380 ItemStack item = inventory.getItem(slot);
381 if (item == null) {
382 continue;
383 }
384 lastViewer.getInventory().addItem(item).values().forEach(i -> lastViewer.getWorld().dropItem(lastViewer.getLocation(), i));
385 }
386 }
387 inventory.clear();
388 buttons.clear();
389 }
390
391 /**
392 * Remove this inventory as a listener and clean everything up to prevent memory leaks.

Callers 1

onCloseMethod · 0.95

Calls 7

forEachMethod · 0.80
addItemMethod · 0.80
getInventoryMethod · 0.80
getItemMethod · 0.45
getWorldMethod · 0.45
getLocationMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected