Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- options:
- Permission-EditShop: shopping.editshop
- Shopping-Command-Aliases: shop
- GUI-Name: "Shopping &7[Page {page}]"
- GUI-Info: "&aLeft click to buy items.||&cRight click to sell items.||&8SHIFT + LMB/RMB to buy/sell stacks of items.||||&7Shopping by CreeperOverLord7"
- CostPrice-Prefix: "&a[LMB] Cost Price: &f"
- SellingPrice-Prefix: "&c[RMB] Selling Price: &f"
- Lore-NotPurchasable: "&8This item is not purchasable."
- Lore-NotSaleable: "&8This item is not saleable."
- NextPage-Prefix: "&aNext Page: &f"
- PreviousPage-Prefix: "&aPrevious Page: &f"
- CurrentPage-Prefix: "&8Current Page: &7"
- Message-Invalid-Page: "&cThe page you are trying to access is invalid and cannot be opened."
- Message-Not-Enough-Money: "&cYou do not have enough money to purchase this item."
- Message-Unpurchasable-Item: "&cYou cannot purchase this item."
- Message-Unsaleable-Item: "&cYou cannot sell this item."
- Message-No-Space: "&cYou do not have enough space in your inventory to purchase this item."
- Message-No-Item-To-Sell: "&cYou do not have the required item to sell."
- Message-Buy-Item: "&aYou bought &f{item} &afor &f${price}&a."
- Message-Sell-Item: "&aYou sold &f{item} &afor &f${price}&a."
- Ver: 1.0
- # {shopping.item::*} is a list of all the shop items
- # elements of {shopping.items::*} are of type item
- #
- # {shopping.itemDetails::*} is a list of all details needed for shop
- # elements of {shopping.itemDetails::*} are of type string,
- # formatted "%costprice%|%sellingprice%"
- #
- # if cost price or selling price is negative; then the item will not be purchasable/sellable.
- function shopping_getDetail(detail: string, from: string) :: number:
- set {_parser::*} to {_from} parsed as "%number%\|%number%"
- if {_detail} = "CostPrice":
- return {_parser::1}
- else if {_detail} = "SellingPrice":
- return {_parser::2}
- #return null
- function shopping_getLore(detail: string, from: item) :: number:
- set {_costPricePrefix} to {@CostPrice-Prefix}
- set {_sellingPricePrefix} to {@SellingPrice-Prefix}
- set {_lore::*} to lore of {_from} split by "||"
- loop {_lore::*}:
- if {_detail} = "CostPrice":
- if first (length of {_costPricePrefix}) characters of loop-value = {_costPricePrefix}:
- return (substring of loop-value from (length of {_costPricePrefix} + 1) to (length of loop-value)) parsed as number
- else if {_detail} = "SellingPrice":
- if first (length of {_sellingPricePrefix}) characters of loop-value = {_sellingPricePrefix}:
- return (substring of loop-value from (length of {_sellingPricePrefix} + 1) to (length of loop-value)) parsed as number
- else if {_detail} = "Index":
- if first (length of "&0i") characters of loop-value = "&0i":
- return (substring of loop-value from (length of "&0i" + 1) to (length of loop-value)) parsed as number
- #return null
- function shopping_getItemName(item: item) :: string:
- if name of {_item} is set:
- return name of {_item}
- return "%{_item}%"
- function shopping_getNextAutoIndex() :: number:
- set {_max} to 0
- loop {shopping.item::*}:
- if (loop-index parsed as number) > {_max}:
- set {_max} to loop-index parsed as number
- return {_max} + 1
- function shopping_gui(player: player, page: number):
- if {_page} <= 0:
- send {@Message-Invalid-Page} to {_player}
- exit trigger
- if {_filter} is not set:
- set {_filter} to ""
- set {_guiName} to {@GUI-Name}
- replace "{page}" in {_guiName} with "%{_page}%"
- set {_chest} to chest inventory with 6 rows named {_guiName}
- loop 9 times:
- set slot (5 * 9 - 1 + loop-number) of {_chest} to stained_glass_pane:8 named "&0"
- set {_startIndex} to 45 * ({_page} - 1)
- set {_costPricePrefix} to {@CostPrice-Prefix}
- set {_sellingPricePrefix} to {@SellingPrice-Prefix}
- set {_notPurchasable} to {@Lore-NotPurchasable}
- set {_notSaleable} to {@Lore-NotSaleable}
- loop 45 times:
- set {_index} to {_startIndex} + loop-number
- set {_costPrice} to shopping_getDetail("CostPrice", {shopping.itemDetails::%{_index}%})
- set {_sellingPrice} to shopping_getDetail("SellingPrice", {shopping.itemDetails::%{_index}%})
- set {_lore} to lore of {shopping.item::%{_index}%}
- set {_lore} to ({_costPrice} >= 0) ? "%{_lore}%||%{_costPricePrefix}%%{_costPrice}%" : "%{_lore}%||%{_notPurchasable}%"
- set {_lore} to ({_sellingPrice} >= 0) ? "%{_lore}%||%{_sellingPricePrefix}%%{_sellingPrice}%" : "%{_lore}%||%{_notSaleable}%"
- set {_lore} to "%{_lore}%||&0i%{_index}%"
- set slot (loop-number - 1) of {_chest} to {shopping.item::%{_index}%} with lore {_lore}
- set {_nextPagePrefix} to {@NextPage-Prefix}
- set {_previousPagePrefix} to {@PreviousPage-Prefix}
- set {_currentPagePrefix} to {@CurrentPage-Prefix}
- set {_temp} to 45 * {_page} + 1
- if {shopping.item::%{_temp}%} is set:
- set slot (6 * 9 - 1) of {_chest} to arrow named "%{_nextPagePrefix}%%{_page} + 1%" with lore "%{_currentPagePrefix}%%{_page}%"
- if {_page} - 1 > 0:
- set slot (6 * 9 - 9) of {_chest} to arrow named "%{_previousPagePrefix}%%{_page} - 1%" with lore "%{_currentPagePrefix}%%{_page}%"
- set slot (6 * 9 - 5) of {_chest} to sign named "&8---&cINFO&8---" with lore {@GUI-Info}
- open {_chest} to {_player}
- on inventory click:
- cancel event
- set {_startsWith} to ""
- set {_splitString::*} to ({@GUI-Name}) split by ""
- loop {_splitString::*}:
- if loop-value = "{":
- exit loop
- set {_startsWith} to "%{_startsWith}%%loop-value%"
- if first (length of {_startsWith}) characters of (name of current inventory of event-player) != {_startsWith}:
- uncancel event
- exit trigger
- if first (length of {_startsWith}) characters of (name of clicked inventory) != {_startsWith}:
- exit trigger
- if type of clicked item = arrow:
- if first (length of {@NextPage-Prefix}) characters of (name of clicked item) = {@NextPage-Prefix}:
- set {_nextPageNumber} to (subtext of name of clicked item from (length of {@NextPage-Prefix} + 1) to (length of name of clicked item)) parsed as number
- shopping_gui(event-player, {_nextPageNumber})
- exit trigger
- if first (length of {@PreviousPage-Prefix}) characters of (name of clicked item) = {@PreviousPage-Prefix}:
- set {_lastPageNumber} to (subtext of name of clicked item from (length of {@PreviousPage-Prefix} + 1) to (length of name of clicked item)) parsed as number
- shopping_gui(event-player, {_lastPageNumber})
- exit trigger
- if type of clicked item = air:
- exit trigger
- if clicked slot >= 45:
- exit trigger
- set {_index} to shopping_getLore("Index", clicked item)
- set {_costPrice} to shopping_getDetail("CostPrice", {shopping.itemDetails::%{_index}%})
- set {_sellingPrice} to shopping_getDetail("SellingPrice", {shopping.itemDetails::%{_index}%})
- if click type = left mouse button or left mouse button with shift:
- if check [{_costPrice} is not set] or check [{_costPrice} < 0]:
- send {@Message-Unpurchasable-Item} to event-player
- play sound "entity.villager.no" at event-player for event-player
- exit trigger
- set {_item} to 1 of {shopping.item::%{_index}%}
- if click type = left mouse button with shift:
- set {_pricefor1} to {_costPrice}
- set {_costPrice} to {_costPrice} * 64
- set {_item} to 64 of {_item}
- if !check [event-player has space for {_item}]:
- send {@Message-No-Space}
- play sound "entity.villager.no" at event-player for event-player
- exit trigger
- if player's balance < {_costPrice}:
- send {@Message-Not-Enough-Money} to event-player
- play sound "entity.villager.no" at event-player for event-player
- exit trigger
- remove {_costPrice} from event-player's balance
- give {_item} to event-player
- play sound "entity.item.pickup" at event-player for event-player
- set {_message} to {@Message-Buy-Item}
- replace "{item}" in {_message} with shopping_getItemName({_item})
- replace "{price}" in {_message} with "%{_costPrice}%"
- send {_message} to event-player
- log "%event-player% bought %{_item}% for %{_costPrice}% [$%{_pricefor1}%/item]"
- else if click type = right mouse button or right mouse button with shift:
- if check [{_sellingPrice} is not set] or check [{_sellingPrice} < 0]:
- send {@Message-Unsaleable-Item} to event-player
- play sound "entity.villager.no" at event-player for event-player
- exit trigger
- set {_item} to 1 of {shopping.item::%{_index}%}
- if click type = right mouse button with shift:
- set {_pricefor1} to {_sellingPrice}
- set {_sellingPrice} to {_sellingPrice} * 64
- set {_item} to 64 of {_item}
- if !check [player has {_item}'s item amount of {_item}]:
- send {@Message-No-Item-To-Sell} to event-player
- play sound "entity.villager.no" at event-player for event-player
- exit trigger
- add {_sellingPrice} to event-player's balance
- remove {_item} from event-player's inventory
- play sound "entity.item.pickup" at event-player for event-player
- set {_message} to {@Message-Sell-Item}
- replace "{item}" in {_message} with shopping_getItemName({_item})
- replace "{price}" in {_message} with "%{_sellingPrice}%"
- send {_message} to event-player
- log "%event-player% sold %{_item}% for %{_sellingPrice}% [$%{_pricefor1}%/item]" to "shopping-purchase"
- command /shopping [<text>] [<text>] [<number>] [<number>]:
- aliases: shop
- usage: /shopping help
- trigger:
- if check [executor does not have permission "{@Permission-EditShop}"] or check [arg-1 is not set]:
- shopping_gui(executor, 1)
- play sound "block.note.pling" at executor for executor
- exit trigger
- if arg-1 = "setitem":
- set {_arg2} to arg-2 parsed as integer
- if check [arg-2 is not set] or check [{_arg2} <= 0]:
- send "&cUsage: /shopping %arg-1% <id> [costprice] [sellingprice]" to executor
- send "&c(ID must be an integer greater than 0 or 'auto')" to executor
- exit trigger
- if check [{_arg2} is not set] -> [arg-2 != "auto"]:
- send "&cUsage: /shopping %arg-1% <id> [costprice] [sellingprice]" to executor
- send "&c(ID must be an integer greater than 0 or 'auto')" to executor
- exit trigger
- if player's tool = air:
- send "&cCan't add air to shop." to executor
- exit trigger
- set {_index} to {_arg2}
- if arg-2 = "auto":
- set {_index} to shopping_getNextAutoIndex()
- set {_arg3} to check [arg-3 is set] ? arg-3 : -1
- set {_arg4} to check [arg-4 is set] ? arg-4 : -1
- set {shopping.item::%{_index}%} to 1 of executor's tool
- set {shopping.itemDetails::%{_index}%} to "%{_arg3}%|%{_arg4}%"
- send "&2[SHOPPING] &f%executor% &aset item index &f%{_index}% &ato <show text:&f%shopping_getItemName({shopping.item::%{_index}%})%>&f[HOVER]<reset>&a; <show text:Cost Price: %{_arg3}%, Selling Price: %{_arg4}%>&f[PRICE]&a." to all players where [player input has permission "{@Permission-EditShop}"]
- log "%executor% set item index %{_index}% to %shopping_getItemName({shopping.item::%{_index}%})%; cost price: %{_arg3}%, selling price: %{_arg4}%" to "shopping-edit"
- else if arg-1 = "setcost" or "setcostprice":
- set {_arg2} to arg-2 parsed as integer
- if check [arg-2 is not set] or check [{_arg2} <= 0]:
- send "&cUsage: /shopping %arg-1% <id> <costprice>" to executor
- send "&c(ID must be an integer greater than 0)" to executor
- exit trigger
- if {_arg2} is not set:
- send "&cUsage: /shopping %arg-1% <id> <costprice>" to executor
- send "&c(ID must be an integer greater than 0)" to executor
- exit trigger
- if arg-3 is not set:
- send "&cUsage: /shopping %arg-1% %arg-2% <costprice>" to executor
- exit trigger
- if {shopping.itemDetails::%arg-2%} is not set:
- set {shopping.itemDetails::%arg-2%} to "-1|-1"
- set {_split::*} to {shopping.itemDetails::%arg-2%} split by "|"
- set {_split::1} to "%arg-3%"
- set {_str} to ""
- loop {_split::*}:
- set {_str} to "%{_str}%%loop-value%|"
- set {_str} to substring of {_str} from 1 to (length of {_str} - 1)
- set {shopping.itemDetails::%arg-2%} to {_str}
- send "&2[SHOPPING] &f%executor% &aset cost price of item index &f%arg-2% <show text:&f%shopping_getItemName({shopping.item::%arg-2%})%>&7[HOVER]<reset> &ato &f%arg-3%&a." to all players where [player input has permission "{@Permission-EditShop}"]
- log "%executor% set cost price of item index %arg-2% [%shopping_getItemName({shopping.item::%arg-2%})%] to %arg-3%" to "shopping-edit"
- else if arg-1 = "setsell" or "setsellingprice":
- set {_arg2} to arg-2 parsed as integer
- if check [arg-2 is not set] or check [{_arg2} <= 0]:
- send "&cUsage: /shopping %arg-1% <id> <sellingprice>" to executor
- send "&c(ID must be an integer greater than 0)" to executor
- exit trigger
- if {_arg2} is not set:
- send "&cUsage: /shopping %arg-1% <id> <sellingprice>" to executor
- send "&c(ID must be an integer greater than 0)" to executor
- exit trigger
- if arg-3 is not set:
- send "&cUsage: /shopping %arg-1% %arg-2% <sellingprice>" to executor
- exit trigger
- if {shopping.itemDetails::%arg-2%} is not set:
- set {shopping.itemDetails::%arg-2%} to "-1|-1"
- set {_split::*} to {shopping.itemDetails::%arg-2%} split by "|"
- set {_split::2} to "%arg-3%"
- set {_str} to ""
- loop {_split::*}:
- set {_str} to "%{_str}%%loop-value%|"
- set {_str} to substring of {_str} from 1 to (length of {_str} - 1)
- set {shopping.itemDetails::%arg-2%} to {_str}
- send "&2[SHOPPING] &f%executor% &aset selling price of item index &f%arg-2% <show text:&f%shopping_getItemName({shopping.item::%arg-2%})%>&7[HOVER]<reset> &ato &f%arg-3%&a." to all players where [player input has permission "{@Permission-EditShop}"]
- log "%executor% set selling price of item index %arg-2% [%shopping_getItemName({shopping.item::%arg-2%})%] to %arg-3%" to "shopping-edit"
- else if arg-1 = "removeitem" or "clearitem":
- set {_arg2} to arg-2 parsed as integer
- if check [arg-2 is not set] or check [{_arg2} <= 0]:
- send "&cUsage: /shopping %arg-1% <id> <sellingprice>" to executor
- send "&c(ID must be an integer greater than 0)" to executor
- exit trigger
- if {_arg2} is not set:
- send "&cUsage: /shopping %arg-1% <id> <sellingprice>" to executor
- send "&c(ID must be an integer greater than 0)" to executor
- exit trigger
- set {_item} to {shopping.item::%arg-2%}
- delete {shopping.item::%arg-2%}
- delete {shopping.itemDetails::%arg-2%}
- send "&2[SHOPPING] &f%executor% &adeleted item index &f%arg-2% <show text:&f%shopping_getItemName({_item})%>&7[HOVER]<reset>&a."
- log "%executor% deleted item index %arg-2% [%shopping_getItemName({_item})%]."
- else if arg-1 = "help":
- send "" to executor
- send "&2SHOPPING &aVersion &f{@Ver} by &fCreeperOverLord7" to executor
- send "&7Hover over commands to view use." to executor
- send "<suggest command:/shop><show text:&fOpens the shop menu.>&b/shop<reset>" to executor
- send "<suggest command:/shop setitem <id>><show text:&fSets the item at position ID in the shop.>&b/shop setitem <id> [costprice] [sellingprice]<reset>" to executor
- send "<suggest command:/shop <setcost|setcostprice> <id> <costprice>><show text:&fSets the cost price of the item at position ID in the shop.>&b/shop <setcost|setcostprice> <id> <costprice><reset>" to executor
- send "<suggest command:/shop <setsell|setsellingprice> <id> <sellingprice>><show text:&fSets the selling price of the item at position ID in the shop.>&b/shop <setsell|setsellingprice> <id> <sellingprice><reset>" to executor
- send "" to executor
- play sound "entity.villager.yes" at executor for executor
- else:
- send "&cUsage: /shop help" to executor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement