inventorystacking
unknown
plain_text
2 years ago
23 kB
2
Indexable
Never
import: org.bukkit.event.inventory.InventoryClickEvent org.bukkit.event.inventory.InventoryMoveItemEvent org.bukkit.event.inventory.InventoryDragEvent org.bukkit.event.inventory.ClickType org.bukkit.event.player.PlayerDropItemEvent org.bukkit.Material org.bukkit.inventory.Inventory org.bukkit.inventory.ItemStack org.bukkit.plugin.java.JavaPlugin java.util.List java.util.ArrayList java.util.Collection aliases: notstackable = wooden shovel, stone shovel, golden shovel, iron shovel, diamond shovel, netherite shovel, wooden pickaxe, stone pickaxe, golden pickaxe, iron pickaxe, diamond pickaxe, netherite pickaxe, wooden sword, stone sword, iron sword, golden sword, diamond sword, netherite sword, wooden axe, stone axe, golden axe, iron axe, diamond axe, netherite axe, wooden hoe, stone hoe, golden hoe, iron hoe, diamond hoe, netherite hoe, fishing rod, spyglass, shears, enchanted book, ender pearl, lava bucket, water bucket, bucket, powder snow bucket, snowball, milk bucket, bucket of pufferfish, bucket of salmon, bucket of cod, bucket of tropical fish, bucket of axolotl, book, egg, book and quill, music disc, iron horse armor, golden horse armor, diamond horse armor, leather horse armor, any bed, leather armour, golden armour, chainmail armour, diamond armour, netherite armour, beetroot soup, boat, bow, bundle, carrot on a stick, crossbow, debug stick, elytra, flint and steel, lingering potion, map, minecart, minecart with chest, minecart with command block, minecart with furnace, minecart with hopper, minecart with tnt, mushroom stew, potion, rabbit stew, saddle, shield, any shulker box, splash potion, suspicious stew, totem of undying, trident, warped fungus on a stick function itemStack(p:player,item:item): if "value" tag of nbt of {_item} is not set: add {_item} to inventory of {_p} stop if {_item} is notstackable: add {_item} to inventory of {_p} stop set {_originalitem} to {_item} set {_amount} to item amount of {_item} set {_name1} to name of {_item} set {_value1} to "value" tag of nbt of {_item} set {_lore::*} to lore of {_item} set {_temp::*} to {_lore::*} set {_sellable} to true if "notsellable" tag of nbt of {_item} is set: set {_sellable} to false loop {_lore::*}: add 1 to {_loopindex} if uncolored loop-value contains "Value": if {_loopindex} is 1: remove {_loopindex}nd element of {_lore::*} from {_temp::*} else if {_loopindex} is 2: remove {_loopindex}-1nd element of {_lore::*} from {_temp::*} remove {_loopindex}nd element of {_lore::*} from {_temp::*} else if uncolored loop-value contains "Sellable": remove {_loopindex}-1nd element of {_lore::*} from {_temp::*} remove {_loopindex}nd element of {_lore::*} from {_temp::*} else if uncolored loop-value contains "Tier": remove {_loopindex}nd element of {_lore::*} from {_temp::*} set {_skullowner} to "SkullOwner" tag of nbt of {_item} delete lore of {_item} set nbt of {_item} to "{}" if {_skullowner} is set: add "{SkullOwner:%{_skullowner}%}" to nbt of {_item} set name of {_item} to {_name1} loop inventory of {_p}: if name of loop-value = {_name1}: if "notsellable" tag of nbt of loop-value is set: set {_sellable} to false if item amount of loop-value + {_amount} < 65: set {_pog} to true set {_item2} to loop-value set {_value2} to "value" tag of nbt of {_item2} set {_amount2} to item amount of {_item2} set {_newitem} to {_amount2} + {_amount} of {_originalitem} add "{value:%{_value1}+{_value2}%}" to nbt of {_newitem} set {_newitem} to setItemLore2({_newitem},{_sellable},false) set slot index of loop-value of inventory of {_p} to {_newitem} stop else: if item amount of loop-value != 64: set {_item2} to loop-value set {_amount2} to item amount of {_item2} set {_total.amount} to {_amount} + {_amount2} set {_value2} to "value" tag of nbt of {_item2} set {_newamount} to {_total.amount} - 64 set {_addedamount} to 64 - {_amount2} set {_newitem} to {_amount2} + {_addedamount} of {_originalitem} add "{value:%{_value2} + {_addedamount}/{_amount} * {_value1}%}" to nbt of {_newitem} set {_newitem} to setItemLore2({_newitem},{_sellable},false) set slot index of loop-value of inventory of {_p} to {_newitem} exit 1 loop if {_pog} is not set: if {_newamount} is set: set {_item.amount} to {_newamount} else: set {_item.amount} to {_amount} add "{value:%{_item.amount}/{_amount} * {_value1}%}" to nbt of {_originalitem} set {_originalitem} to setItemLore2({_originalitem},{_sellable},false) add {_item.amount} of {_originalitem} to inventory of {_p} on place: set {_tool} to tool of player set {_amount} to item amount of {_tool} set {_value} to "value" tag of nbt of {_tool} {_value} is set add "{value:%({_amount}-1)/{_amount} * {_value}%}" to nbt of {_tool} set {_tool} to setItemLore({_tool},false,true) set {_tool} to {_amount}-1 of {_tool} set tool of player to {_tool} on item spawn: wait 1 tick if metadata value "item" of last spawned entity is not set: set metadata value "item" of last spawned entity to event-item on pickup: set {_item} to metadata value "item" of event-dropped item set {_value} to "value" tag of nbt of {_item} set {_sellable} to true if "notsellable" tag of nbt of {_item} is set: set {_sellable} to false if {_value} is set: add "{value:%{_value}%}" to nbt of {_item} set {_item} to setItemLore({_item},{_sellable},true,{_sellable}) cancel event play sound "entity.item.pickup" for player kill event-dropped item itemStack(event-entity,{_item}) on drop: set {_item} to event-item set {_tool} to tool of player set {_amount1} to item amount of {_item} set {_amount2} to amount of tool of player set {_totalamount} to {_amount1} + {_amount2} set {_value} to "value" tag of nbt of {_tool} if {_value} is not set: set {_value} to "value" tag of nbt of {_item} add "{value:%{_value}*{_amount1}/{_totalamount}%}" to nbt of {_item} add "{value:%{_value}*{_amount2}/{_totalamount}%}" to nbt of {_tool} set {_sellable} to true if "notsellable" tag of nbt of {_tool} is set: set {_sellable} to false set {_tool} to setItemLore({_tool},{_sellable},false,{_sellable}) set tool of player to {_tool} set metadata value "item" of event-dropped item to {_item} on item merge: cancel event set {_item1} to metadata value "item" of event-dropped item set {_item2} to metadata value "item" of event-entity kill event-dropped item kill event-entity {_item1} is not notstackable {_item2} is not notstackable set {_amount1} to item amount of {_item1} set {_amount2} to item amount of {_item2} set {_value1} to "value" tag of nbt of {_item1} set {_value2} to "value" tag of nbt of {_item2} set {_item} to {_amount1}+{_amount2} of {_item1} add "{value:%{_value1}+{_value2}%}" to nbt of {_item} drop {_item} at event-location set metadata value "item" of last dropped item to {_item} on inventory close: if metadata value "cooldown" of player is set: delete metadata value "cooldown" of player if metadata value "cooldown2" of player is set: delete metadata value "cooldown2" of player if metadata value "shopopen" of player is set: delete metadata value "shopopen" of player on InventoryDragEvent with priority highest: set {_p} to event.getWhoClicked() "%{_p}.getGameMode()%" is not "creative" if metadata value "cooldown" of {_p} is set: cancel event stop set metadata value "cooldown" of {_p} to true set {_slots::*} to ...event.getRawSlots() set {_olditem} to event.getOldCursor() set {_sellable} to "notsellable" tag of nbt of {_olditem} if {_sellable} is set: set {_sellable} to false else: set {_sellable} to true set {_olditemamount} to item amount of {_olditem} set {_totalvalue} to "value" tag of nbt of {_olditem} set {_slots::*} to ...event.getRawSlots() loop {_slots::*}: set {_loopvalue} to loop-value set {_item} to {_p}.getOpenInventory().getItem({_loopvalue}) if {_item} is notstackable: delete metadata value "cooldown" of {_p} stop if {_totalvalue} is set: set {_slots::*} to ...event.getRawSlots() if "%event.getType()%" is "EVEN": cancel event set {_amount} to event.getRawSlots().size() set {_amounteach} to floor({_olditemamount}/{_amount}) loop {_slots::*}: set {_loopvalue} to loop-value set {_item} to {_p}.getOpenInventory().getItem({_loopvalue}) set {_amountold} to item amount of {_item} set {_valueold} to "value" tag of nbt of {_item} set {_item} to {_amounteach}+{_amountold} of {_olditem} add "{value:%{_amounteach}/{_olditemamount}*{_totalvalue}+{_valueold}%}" to nbt of {_item} set {_item} to setItemLore({_item},{_sellable},true,{_sellable}) {_p}.getOpenInventory().setItem({_loopvalue},{_item}) set {_remainder} to mod({_olditemamount}, {_amount}) set {_item} to {_remainder} of {_olditem} add "{value:%{_remainder}/{_olditemamount}*{_totalvalue}%}" to nbt of {_item} set {_item} to setItemLore({_item},{_sellable},true,{_sellable}) wait 1 tick {_p}.setItemOnCursor({_item}) else if "%event.getType()%" is "SINGLE": cancel event set {_amount} to event.getRawSlots().size() set {_amounteach} to 1 loop {_slots::*}: set {_loopvalue} to loop-value set {_item} to {_p}.getOpenInventory().getItem({_loopvalue}) set {_amountold} to item amount of {_item} set {_valueold} to "value" tag of nbt of {_item} set {_item} to {_amounteach}+{_amountold} of {_olditem} add "{value:%{_amounteach}/{_olditemamount}*{_totalvalue}+{_valueold}%}" to nbt of {_item} set {_item} to setItemLore({_item},{_sellable},true,{_sellable}) {_p}.getOpenInventory().setItem({_loopvalue},{_item}) set {_remainder} to {_olditemamount} - {_amount}*{_amounteach} set {_item} to {_remainder} of {_olditem} add "{value:%{_remainder}/{_olditemamount}*{_totalvalue}%}" to nbt of {_item} set {_item} to setItemLore({_item},{_sellable},true,{_sellable}) wait 1 tick {_p}.setItemOnCursor({_item}) delete metadata value "cooldown" of {_p} on InventoryClickEvent: set {_p} to event.getWhoClicked() delete {_loop} "%{_p}.getGameMode()%" is not "creative" if metadata value "cooldown" of {_p} is set: send "Cooldown1" to {_p} cancel event stop set metadata value "cooldown" of {_p} to true if {_p}'s gamemode is creative: delete metadata value "cooldown" of {_p} stop set {_clicked.item} to event.getCurrentItem() if {_clicked.item} is notstackable: delete metadata value "cooldown" of {_p} stop set {_cursor} to event.getCursor() set {_slot} to event.getRawSlot() set {_sellable1} to "notsellable" tag of nbt of {_cursor} set {_sellable2} to "notsellable" tag of nbt of {_clicked.item} loop 2 times: if {_sellable%loop-number%} is set: set {_sellable%loop-number%} to false else: set {_sellable%loop-number%} to true if {_slot} is -999: cancel event delete metadata value "cooldown" of {_p} stop loop ...event.getInventory(): add 1 to {_slots} if "damage" tag of nbt of {_clicked.item} is set: delete metadata value "cooldown" of {_p} stop if "damage" tag of nbt of {_cursor} is set: delete metadata value "cooldown" of {_p} stop set {_name1} to name of {_clicked.item} set {_name2} to name of {_cursor} set {_amount1} to item amount of {_clicked.item} set {_amount2} to item amount of {_cursor} set {_value1} to "value" tag of nbt of {_clicked.item} set {_value2} to "value" tag of nbt of {_cursor} if {_value1} is not set: if {_value2} is not set: delete metadata value "cooldown" of {_p} stop if event.getClick().equals(ClickType.RIGHT) is true: if {_cursor} is air: if {_amount1} > 1: if "value" tag of nbt of {_clicked.item} is not set: delete metadata value "cooldown" of {_p} stop cancel event set {_amount.item2} to round({_amount1}/2) set {_item2} to {_amount.item2} of {_clicked.item} set {_amount.item1} to {_amount1}-{_amount.item2} set {_item1} to {_amount.item1} of {_clicked.item} add "{value:%{_value1}/{_amount1}* {_amount.item1}%}" to nbt of {_item1} add "{value:%{_value1}/{_amount1}* {_amount.item2}%}" to nbt of {_item2} set {_item1} to setItemLore({_item1},{_sellable2},false) set {_item2} to setItemLore({_item2},{_sellable2},false) {_p}.getOpenInventory().setItem({_slot},{_item1}) event.setCursor({_item2}) else: if {_amount2} > 1: if {_clicked.item} is not set: cancel event if {_amount1} >= 64: delete metadata value "cooldown" of {_p} stop set {_amount.item2} to 1 set {_item2} to {_amount.item2} of {_cursor} set {_amount.item1} to {_amount2}-1 set {_item1} to {_amount.item1} of {_cursor} add "{value:%{_amount.item1}/{_amount2} * {_value2}%}" to nbt of {_item1} add "{value:%1/{_amount2} * {_value2}%}" to nbt of {_item2} set {_item1} to setItemLore({_item1},{_sellable1},false) set {_item2} to setItemLore({_item2},{_sellable1},false) wait 1 tick {_p}.getOpenInventory().setItem({_slot},{_item2}) event.setCursor({_item1}) if {_clicked.item} is air: cancel event if {_amount1} >= 64: delete metadata value "cooldown" of {_p} stop set {_amount.item2} to 1 set {_item2} to {_amount.item2} of {_cursor} set {_amount.item1} to {_amount2}-1 set {_item1} to {_amount.item1} of {_cursor} add "{value:%{_amount.item1}/{_amount2} * {_value2}%}" to nbt of {_item1} add "{value:%1/{_amount2} * {_value2}%}" to nbt of {_item2} set {_item1} to setItemLore({_item1},{_sellable1},false) set {_item2} to setItemLore({_item2},{_sellable1},false) wait 1 tick {_p}.getOpenInventory().setItem({_slot},{_item2}) event.setCursor({_item1}) else: if "value" tag of nbt of {_clicked.item} is not set: delete metadata value "cooldown" of {_p} stop {_name1} is {_name2} cancel event if {_amount1} >= 64: delete metadata value "cooldown" of {_p} stop set {_amount.item2} to {_amount1} + 1 set {_item2} to {_amount.item2} of {_cursor} set {_amount.item1} to {_amount2}-1 set {_item1} to {_amount.item1} of {_cursor} add "{value:%{_amount.item1}/{_amount2} * {_value2}%}" to nbt of {_item1} add "{value:%{_value1} + 1/{_amount2}*{_value2}%}" to nbt of {_item2} set {_item1} to setItemLore({_item1},{_sellable2},false) set {_item2} to setItemLore({_item2},{_sellable2},false) {_p}.getOpenInventory().setItem({_slot},{_item2}) event.setCursor({_item1}) else: if {_clicked.item} is air: cancel event event.setCursor(air) {_p}.getOpenInventory().setItem({_slot},{_cursor}) else: if "value" tag of nbt of {_clicked.item} is not set: delete metadata value "cooldown" of {_p} stop if {_name1} is not {_name2}: delete metadata value "cooldown" of {_p} stop cancel event set {_amount.item2} to {_amount1} + 1 set {_item2} to {_amount.item2} of {_clicked.item} add "{value:%{_value1} + 1/{_amount2}*{_value2}%}" to nbt of {_item2} set {_item2} to setItemLore({_item2},{_sellable2},false) {_p}.getOpenInventory().setItem({_slot},{_item2}) event.setCursor(air) else if event.getClick().equals(ClickType.LEFT) is true: if {_cursor} is not air: if {_name1} is {_name2}: cancel event set {_amount.item2} to {_amount1} + {_amount2} set {_item2} to {_amount.item2} of {_clicked.item} set {_newamount} to item amount of {_item2} set {_newvalue} to {_value1}+{_value2} set {_oldamount} to {_newamount} if {_newamount} >= 65: set {_cursor.amount} to {_newamount}-64 set {_newamount} to 64 set {_newvalue} to ({_value1}+{_value2})*(64/{_oldamount}) set {_cursorvalue} to ({_value1}+{_value2})*({_cursor.amount}/{_oldamount}) set {_cursoritem} to {_cursor.amount} of {_item2} add "{value:%{_cursorvalue}%}" to nbt of {_cursoritem} set {_cursoritem} to setItemLore({_cursoritem},{_sellable2},false) add "{value:%{_newvalue}%}" to nbt of {_item2} set {_item2} to setItemLore({_item2},{_sellable2},false) {_p}.getOpenInventory().setItem({_slot},{_newamount} of {_item2}) add "{value:%{_cursorvalue}%}" to nbt of {_item2} event.setCursor({_cursoritem}) else if "%event.getClick()%" is "double click using mouse": if metadata value "shopopen" of {_p} is set: cancel event delete metadata value "cooldown" of {_p} stop cancel event loop 100 times: add {_p}.getOpenInventory().getItem(loop-number) to {_items::*} loop {_items::*}: add 1 to {_loopindex} set {_amount} to item amount of loop-value set {_value} to "value" tag of nbt of loop-value if name of loop-value is name of {_cursor}: if {_amount2} + {_amount} < 65: add {_amount} to {_amount2} {_p}.getOpenInventory().setItem({_loopindex}, air) add "{value:%{_value2}+{_value}%}" to nbt of {_cursor} set {_value2} to "value" tag of nbt of {_cursor} else: set {_amountadded} to 64 - {_amount2} set {_newamountoriginal} to {_amount} - {_amountadded} set {_amount2} to 64 add "{value:%{_value2}+{_value}*({_amountadded}/{_amount})%}" to nbt of {_cursor} set {_newitem} to {_p}.getOpenInventory().getItem({_loopindex}) set {_newitem} to {_newamountoriginal} of {_newitem} add "{value:%{_value} - {_value}*({_amountadded}/{_amount})%}" to nbt of {_newitem} set {_newitem} to setItemLore({_newitem},{_sellable1},false) {_p}.getOpenInventory().setItem({_loopindex}, {_newitem}) if {_amount2} is 64: exit 1 loop set {_newitem} to {_amount2} of {_cursor} set {_newitem} to setItemLore({_newitem},{_sellable1},false) wait 1 tick event.setCursor({_newitem}) else if "%event.getClick()%" is "left mouse button with shift": if metadata value "shopopen" of {_p} is set: delete metadata value "cooldown" of {_p} stop loop 100 times: add {_p}.getOpenInventory().getItem(loop-number) to {_items::*} loop {_items::*}: add 1 to {_loopindex} delete {_sellable} {_loopindex} is not {_slot} if item amount of {_p}.getOpenInventory().getItem({_loopindex}) is 64: continue set {_newitem} to loop-value loop-value is set set {_sellable} to "notsellable" tag of nbt of {_newitem} if {_sellable} is set: set {_sellable} to false else: set {_sellable} to true set {_amount} to item amount of {_newitem} set {_value} to "value" tag of nbt of {_newitem} if name of {_newitem} is name of {_clicked.item}: if {_amount} >= 64: continue cancel event set {_yes} to true {_p}.getOpenInventory().setItem({_slot}, air) if {_amount1} + {_amount} < 65: add {_amount1} to {_amount} add "{value:%{_value1}+{_value}%}" to nbt of {_newitem} set {_value} to "value" tag of nbt of {_newitem} else: set {_amountadded} to 64 - {_amount} set {_newamountoriginal} to {_amount1} - {_amountadded} set {_amount} to 64 add "{value:%{_value} + {_value1}*({_amountadded}/{_amount1})%}" to nbt of {_newitem} set {_newitem2} to {_p}.getOpenInventory().getItem({_loopindex}) set {_newitem2} to {_newamountoriginal} of {_newitem2} add "{value:%{_value1} - {_value1}*({_amountadded}/{_amount1})%}" to nbt of {_newitem2} set {_newitem2} to setItemLore({_newitem2},{_sellable},false) set {_loopindex2} to 0 loop {_items::*}: if {_loopindex} > 0: if {_p}.getOpenInventory().getItem({_loopindex2}-1) is not set: delete metadata value "cooldown" of {_p} stop if {_p}.getOpenInventory().getItem({_loopindex2}-1) is air: delete metadata value "cooldown" of {_p} stop {_loopindex2} is not {_slot} if {_loopindex2} > {_loopindex}: if loop-value-2 is air: set {_set} to true {_p}.getOpenInventory().setItem({_loopindex2}, {_newitem2}) exit 1 loop add 1 to {_loopindex2} if {_set} is not set: cancel event delete metadata value "cooldown" of {_p} stop set {_newitem} to {_amount} of {_newitem} set {_newitem} to setItemLore({_newitem},{_sellable},false) {_p}.getOpenInventory().setItem({_loopindex}, {_newitem}) exit 1 loop else if "%event.getClick()%" is "right mouse button with shift": if metadata value "shopopen" of {_p} is set: delete metadata value "cooldown" of {_p} stop cancel event loop 100 times: add {_p}.getOpenInventory().getItem(loop-number) to {_items::*} loop {_items::*}: add 1 to {_loopindex} delete {_sellable} {_loopindex} is not {_slot} if item amount of {_p}.getOpenInventory().getItem({_loopindex}) is 64: continue set {_newitem} to loop-value loop-value is set set {_sellable} to "notsellable" tag of nbt of {_newitem} if {_sellable} is set: set {_sellable} to false else: set {_sellable} to true set {_amount} to item amount of {_newitem} set {_value} to "value" tag of nbt of {_newitem} if name of {_newitem} is name of {_clicked.item}: if {_amount} >= 64: continue set {_yes} to true {_p}.getOpenInventory().setItem({_slot}, air) if {_amount1} + {_amount} < 65: add {_amount1} to {_amount} add "{value:%{_value1}+{_value}%}" to nbt of {_newitem} set {_value} to "value" tag of nbt of {_newitem} else: set {_amountadded} to 64 - {_amount} set {_newamountoriginal} to {_amount1} - {_amountadded} set {_amount} to 64 add "{value:%{_value} + {_value1}*({_amountadded}/{_amount1})%}" to nbt of {_newitem} set {_newitem2} to {_p}.getOpenInventory().getItem({_loopindex}) set {_newitem2} to {_newamountoriginal} of {_newitem2} add "{value:%{_value1} - {_value1}*({_amountadded}/{_amount1})%}" to nbt of {_newitem2} set {_newitem2} to setItemLore({_newitem2},{_sellable},false) set {_loopindex2} to 0 loop {_items::*}: if {_loopindex} > 0: if {_p}.getOpenInventory().getItem({_loopindex2}-1) is not set: delete metadata value "cooldown" of {_p} stop if {_p}.getOpenInventory().getItem({_loopindex2}-1) is air: delete metadata value "cooldown" of {_p} stop {_loopindex2} is not {_slot} if {_loopindex2} > {_loopindex}: if loop-value-2 is air: set {_set} to true {_p}.getOpenInventory().setItem({_loopindex2}, {_newitem2}) exit 1 loop add 1 to {_loopindex2} if {_set} is not set: cancel event delete metadata value "cooldown" of {_p} stop set {_newitem} to {_amount} of {_newitem} set {_newitem} to setItemLore({_newitem},{_sellable},false) {_p}.getOpenInventory().setItem({_loopindex}, {_newitem}) exit 1 loop else if "%event.getClick()%" is "drop key": if "value" tag of nbt of {_clicked.item} is not set: delete metadata value "cooldown" of {_p} stop cancel event delete metadata value "cooldown" of {_p} command /deleteee: permission:op trigger: loop all players: delete metadata value "cooldown" of loop-player