import:
org.bukkit.event.inventory.InventoryDragEvent
org.bukkit.event.inventory.InventoryClickEvent
function getWorthOfFish(i: item) :: number:
if name of {_i} contains "&7Common Herring":
return 10
else if name of {_i} contains "&7Common Crab":
return 100
else:
return 0
#Bonus money u get wenn a fish has a bigger size than 1.
# Example:
# Inc value = 1$:
# size = 1 = 1$
# size = 1.5 = 1.5$
# size = 3 = 3$
# Inc value = 2.5$:
# size = 1 = 2.5$
# size = 1.5 = 3.75$
# size = 3 = 7.5$
function getSizeIncrease(i: item, s: number) :: number:
if name of {_i} contains "&7Common Herring":
return (1 * {_s})
else if name of {_i} contains "&7Common Crab":
return (10 * {_s})
else:
return 0
function getSize(i: item) :: number:
set {_s} to line 1 of lore of {_i}
set {_s::*} to {_s} split at "&8* &aSize: "
set {_s} to {_s::2}
replace every "cm" with "" in {_s}
set {_s} to {_s} parsed as a number
return {_s}
function getPriceOfFish(i: items) :: number:
set {_t} to 0
loop {_i::*}:
delete {_p::*}
set {_p::w} to getWorthOfFish(loop-value)
set {_p::s} to getSize(loop-value)
set {_p::i} to getSizeIncrease(loop-value,{_p::s})
set {_p::p} to {_p::w} + {_p::i}
set {_p::a} to item amount of loop-value
set {_p::t} to {_p::a} * {_p::p}
add {_p::t} to {_t}
return {_t}
function getFish(p: player) :: items:
loop all items in {_p}'s current inventory:
if loop-value is raw cod, raw salmon or pufferfish:
if name of loop-value contains "&7Common Herring" or "&7Common Crab":
add loop-value to {_fish::*}
return {_fish::*}
function getLatestPrice(i: item) :: number:
set {_p} to name of {_i}
replace every "&aSell for: &a$&a" with "" in {_p}
set {_p} to {_p} parsed as a number
return {_p}
function fishAmount(i: items) :: number:
set {_t} to 0
loop {_i::*}:
add item amount of loop-value to {_t}
return {_t}
function updateFishPrice(p: player):
wait 1 tick
set {_fish::*} to getFish({_p})
set {_fishamount} to fishAmount({_fish::*})
set {_totalprice} to getPriceOfFish({_fish::*})
set name of slot 31 of {_p}'s current inventory to "&aSell for: &a$&a%{_totalprice}%"
set line 1 of lore of slot 31 of {_p}'s current inventory to "&bAmount of fish: %{_fishamount}%"
function sellFish(p: player, i: item):
set {_fish::*} to getFish({_p})
set {_fishamount} to fishAmount({_fish::*})
set {_totalprice} to getPriceOfFish({_fish::*})
set {_latestprice} to getLatestPrice({_i})
if {_latestprice} = {_totalprice}:
if {_totalprice} = 0:
send "&b[Mr. Boatwright] &cNothing to sell" to {_p}
stop
close {_p}'s inventory
add {_totalprice} to balance of {_p}
send "&b[Mr. Boatwright] &7You sold all your fish for &a$%{_totalprice}%" to {_p}
else:
send "&b[Mr. Boatwright] &cOops something went wrong. ##001 Price Not Matching" to {_p}
send "&b[Mr. Boatwright] &7Updating Price..." to {_p}
updateFishPrice({_p})
send "&b[Mr. Boatwright] &7##001 Pls try again." to {_p}
function openfish(p: player):
open virtual chest with size 4 named "&bMr. Boatwright" to {_p}
format gui slot 27, 28, 29, 30, 32, 33, 34 and 35 of {_p} with green stained glass pane named "" to do nothing
format gui slot 31 of {_p} with diamond to run function sellFish({_p}, gui-clicked-item)
updateFishPrice({_p})
on InventoryClickEvent:
if "%event.getView().getTitle()%" = "&bMr. Boatwright":
updateFishPrice(event.getWhoClicked())
on InventoryDragEvent:
if "%event.getView().getTitle()%" = "&bMr. Boatwright":
updateFishPrice(event.getWhoClicked())
on right click on entity:
if name of clicked entity contains "&bMr. Boatwright":
openfish(player)