knugi

kKits 1.3.1

Jan 6th, 2019
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.00 KB | None | 0 0
  1. #Version: 1.3.1
  2. #Skript 2.2
  3. #SkQuery
  4. #Skript-Mirror 0.9
  5. function Kits_getPath(t: text = "config") :: string:
  6. if "%skquery version%" is "3.21.4":
  7. return "../../Kits/%{_t}%.yml"
  8. return "plugins/Kits/%{_t}%.yml"
  9. function getItemByText(t: text) :: item:
  10. if "%{_t}%" contains "named":
  11. set {_item} to subtext of {_t} between index 0 to index of "named" in {_t} - 2
  12. set {_item} to {_item} parsed as item type
  13. if {_item} is not item type:
  14. return air
  15. if "%{_t}%" contains "with lore":
  16. set {_name} to subtext of {_t} between index index of "named" in {_t} + 7 to index of "with lore" in {_t} - 3
  17. set {_lore} to subtext of {_t} between index index of "with lore" in {_t} + 11 to length of {_t} - 1
  18. return ("%{_item}%" parsed as item) named coloured {_name} with lore coloured {_lore}
  19. else:
  20. set {_name} to subtext of {_t} between index index of "named" in {_t} + 7 to length of {_t} - 1
  21. return ("%{_item}%" parsed as item) named coloured {_name}
  22. if "%{_t}%" contains "with lore":
  23. set {_item} to subtext of {_t} between index 0 to index of "with lore" in {_t} - 2
  24. set {_lore} to subtext of {_t} between index length of "%{_item}%" + 13 to index length of {_t} - 1
  25. set {_item} to {_item} parsed as item type
  26. if {_item} is item type:
  27. return {_item} with lore coloured {_lore}
  28. return air
  29. set {_item} to {_t} parsed as item type
  30. if {_item} is item type:
  31. return {_item}
  32. return air
  33.  
  34. function getIdFromItem(t: text) :: object:
  35. set {_kits::*} to yaml nodes "kits" from Kits_getPath()
  36. loop {_kits::*}:
  37. set {_item} to yaml value "kits.%loop-value%.displayItem" from Kits_getPath()
  38. if getItemByText({_item})'s name is {_t}:
  39. return "%loop-value%"
  40. return null
  41. function getAllItemsFromKit(ID: text) :: item types:
  42. set {_items::*} to yaml list "kits.%{_ID}%.items" from Kits_getPath()
  43. loop {_items::*}:
  44. add getItemByText("%loop-value%") to {_repairItems::*}
  45. return {_repairItems::*}
  46.  
  47. function getTime(id: text, p: player) :: string:
  48. set {_sec} to 1000
  49. set {_min} to 60 * {_sec}
  50. set {_hour} to 60 * {_min}
  51. set {_day} to 24 * {_hour}
  52. set {_conf} to yaml value "kits.%{_id}%.%{_p}%" from Kits_getPath("players")
  53. set {_ms} to {System}.currentTimeMillis() - {_conf}
  54. if "%{_ms}%" contains "-":
  55. set {_ms} to "%{_ms}%"
  56. replace all "-" with "" in {_ms}
  57. set {_ms} to {_ms} parsed as number
  58. set {_res} to ""
  59. if {_ms} > {_day}:
  60. set {_res} to "%{_res}% %floor({_ms} / {_day})% dni "
  61. set {_ms} to {Math}.floorMod({_ms} and {_day})
  62. if {_ms} > {_hour}:
  63. set {_res} to "%{_res}%%floor({_ms} / {_hour})% godz. "
  64. set {_ms} to {Math}.floorMod({_ms} and {_hour})
  65. if {_ms} > {_min}:
  66. set {_res} to "%{_res}%%floor({_ms} / {_min})% min. "
  67. set {_ms} to {Math}.floorMod({_ms} and {_min})
  68. if {_ms} > {_sec}:
  69. set {_res} to "%{_res}%%floor({_ms} / {_sec})% sek."
  70. set {_ms} to {Math}.floorMod({_ms} and {_sec})
  71. return {_res}
  72. return "&aTeraz"
  73. function getInventory(t: text, p: player, action: text = "PPM") :: inventory:
  74. #Enums:
  75. #MAIN
  76. #ID
  77. if {_t} is "MAIN":
  78. set {_kits::*} to yaml nodes "kits" from Kits_getPath()
  79. set {_rows} to ceil("%size of {_kits::*}%" parsed as integer / 9)
  80. set {_x} to chest with {_rows} rows named "&eZestawy"
  81. loop {_kits::*}:
  82. set {_pex} to yaml value "kits.%loop-value%.permission" from Kits_getPath()
  83. if {_pex} is not "<none>":
  84. if {_p} has permission "%{_pex}%":
  85. set {_hasPermission} to "&aTAK"
  86. else:
  87. set {_hasPermission} to "&cNIE"
  88. else:
  89. set {_hasPermission} to "&aTAK"
  90. set {_lore::1} to " &7Posiadasz uprawnienia: %{_hasPermission}%"
  91. set {_lore::2} to " &7Dostepny za: %getTime(loop-value, {_p})%"
  92. set {_timespan} to yaml value "kits.%loop-value%.time" from Kits_getPath()
  93. replace all "minutes" and "minute" with "min." in {_timespan}
  94. replace all "seconds" and "second" with "sek." in {_timespan}
  95. replace all "days" and "day" with "dni." in {_timespan}
  96. replace all "hours" and "hour" with "godz." in {_timespan}
  97. replace all " and " with " " in {_timespan}
  98. set {_lore::3} to " &7Zestaw mozna brac raz na: &a%{_timespan}%"
  99. if yaml value "kits.%loop-value%.activate" from Kits_getPath() is true:
  100. set {_activate} to "&awlaczony"
  101. else:
  102. set {_activate} to "&cwylaczony"
  103. set {_lore::4} to " &7Zestaw jest w tej chwili: %{_activate}%"
  104. set {_guiReceive} to yaml value "kits.%loop-value%.guiReceive" from Kits_getPath()
  105. set {_guiReceive} to {_guiReceive} ? "&awlaczone" : "&cwylaczone"
  106. set {_lore::5} to " &7Branie z skrzynki: %{_guiReceive}%"
  107. set {_lore::6} to ""
  108. set {_lore} to "%{_lore::*}%"
  109. replace all ", " and " and " with "||" in {_lore}
  110. set {_lore} to "%{_lore}%|| &eKliknij LPM, aby wziac zestaw.|| &eKliknij PPM, aby obejrzec zestaw."
  111. set {_yaml} to yaml value "kits.%loop-value%.displayItem" from Kits_getPath()
  112. set {_item} to getItemByText({_yaml})
  113. set slot loop-index parsed as integer - 1 of {_x} to ("%{_item}%" parsed as item) named " &eZestaw: %coloured name of {_item}%" with lore {_lore}
  114. clear {_pex}, {_lore::*}, {_timespan}, {_activate}, {_lore}, {_yaml} and {_item}
  115. return {_x}
  116. if yaml value "kits.%{_t}%.displayItem" from Kits_getPath() is set:
  117. if {_action} is "PPM":
  118. set {_yaml} to yaml value "kits.%{_t}%.displayItem" from Kits_getPath()
  119. set {_item} to getItemByText({_yaml})
  120. set {_items::*} to getAllItemsFromKit({_t})
  121. set {_rows} to ceil("%size of {_items::*}%" parsed as integer / 9)
  122. set {_x} to chest with {_rows} rows named "&eZestaw: %coloured name of {_item}%"
  123. loop {_items::*}:
  124. set slot loop-index parsed as integer - 1 of {_x} to loop-value
  125. return {_x}
  126. if {_action} is "LPM":
  127. set {_yaml} to yaml value "kits.%{_t}%.displayItem" from Kits_getPath()
  128. set {_item} to getItemByText({_yaml})
  129. set {_rows} to ceil("%size of {kKits::%{_p}%::%{_id}%::*}%" parsed as integer / 9)
  130. set {_x} to chest with {_rows} rows named "&eZestaw: %coloured name of {_item}%"
  131. loop {kKits::%{_p}%::%{_id}%::*}:
  132. set slot loop-index parsed as integer - 1 of {_x} to loop-value
  133. return {_x}
  134. on script load:
  135. import "java.lang.Math"
  136. import "java.lang.Long"
  137. import "java.lang.System"
  138. import "org.bukkit.event.inventory.InventoryClickEvent"
  139. if yaml value "autoRefreshInGUI" from Kits_getPath() is not set:
  140. set yaml value "autoRefreshInGUI" from Kits_getPath() to true
  141. if yaml nodes "kits" from Kits_getPath() is not set:
  142. set yaml value "kits.test.displayItem" from Kits_getPath() to "64 steak named ""&8Moj test &r&lKit"""
  143. set yaml value "kits.test.permission" from Kits_getPath() to "<none>"
  144. set yaml value "kits.test.time" from Kits_getPath() to "5 hour"
  145. set yaml value "kits.test.activate" from Kits_getPath() to true
  146. set yaml value "kits.test.guiReceive" from Kits_getPath() to true
  147. add "64 steak named ""&7Start"" with lore ""&eTwoje startowe miesko||||&c&lSMACZNEGO!""" to yaml list "kits.test.items" from Kits_getPath()
  148. add "diamond pickaxe of efficiency 10 and unbreaking 3 named ""&6Super kox"" with lore ""&6Kopie 3x3||||&cSerdecznie polecam||&3&l&nKnugi""" to yaml list "kits.test.items" from Kits_getPath()
  149.  
  150. set yaml value "kits.drugi.displayItem" from Kits_getPath() to "wooden sword named ""&cKit &lVIP"""
  151. set yaml value "kits.drugi.permission" from Kits_getPath() to "easyhc.vip"
  152. set yaml value "kits.drugi.time" from Kits_getPath() to "2 days and 32 minutes"
  153. set yaml value "kits.drugi.activate" from Kits_getPath() to false
  154. set yaml value "kits.test.guiReceive" from Kits_getPath() to false
  155. add "diamond helmet of protection 4 and unbreaking 3 named ""&6Helm VIP'a""" to yaml list "kits.drugi.items" from Kits_getPath()
  156. add "diamond chestplate of protection 4 and unbreaking 3 named ""&6Zbroja VIP'a""" to yaml list "kits.drugi.items" from Kits_getPath()
  157. add "diamond leggings of protection 4 and unbreaking 3 named ""&6Spodnie VIP'a""" to yaml list "kits.drugi.items" from Kits_getPath()
  158. add "diamond boots of protection 4 and unbreaking 3 named ""&6Buty VIP'a""" to yaml list "kits.drugi.items" from Kits_getPath()
  159. add "diamond sword of sharpness 5 and unbreaking 3 named ""&6Miecz VIP'a""" to yaml list "kits.drugi.items" from Kits_getPath()
  160.  
  161. on "org.bukkit.event.inventory.InventoryClickEvent":
  162. set {_name} to event.getWhoClicked().getOpenInventory().getTopInventory().getName()
  163. if "%{_name}%" contains "&eZestaw:":
  164. set {_p} to event.getWhoClicked()
  165. set {_id} to {_name}
  166. replace all "&eZestaw: " in {_id} with ""
  167. set {_id} to getIdFromItem({_id})
  168. if {kKits::%{_p}%::%{_id}%} is set:
  169. stop
  170. cancel event
  171. if event.isRightClick() is true:
  172. set {_p} to event.getWhoClicked()
  173. close {_p}'s inventory
  174. wait 2 tick
  175. open getInventory("MAIN", {_p}) to {_p}
  176. stop
  177. if "%{_name}%" is "&eZestawy":
  178. cancel event
  179. if "%event.getCurrentItem()%" is "0 air":
  180. stop
  181. set {_p} to event.getWhoClicked()
  182. set {_id} to getIdFromItem(event.getCurrentItem().getItemMeta().getDisplayName().substring(11))
  183. if yaml value "kits.%{_id}%.displayItem" from Kits_getPath() is set:
  184. if event.isShiftClick() is true:
  185. stop
  186. if event.isLeftClick() is true:
  187. set {_lore::*} to split "%lore of event.getCurrentItem()%" by "||"
  188. if "%{_lore::4}%" contains "wylaczony":
  189. stop
  190. if "%{_lore::5}%" contains "wlaczone":
  191. if "%{_lore::2}%" contains "&aTeraz":
  192. set {kKits::%{_p}%::%{_id}%::*} to getAllItemsFromKit({_id})
  193. set {_timespan} to yaml value "kits.%{_id}%.time" from Kits_getPath()
  194. set {_timespan} to {_timespan} parsed as timespan
  195. set {_time} to now
  196. add {_timespan} to {_time}
  197. set yaml value "kits.%{_id}%.%{_p}%" from Kits_getPath("players") to {_time}.getTimestamp()
  198. set {_broadcast} to yaml value "kits.%{_id}%.broadcast" from Kits_getPath()
  199. if {_broadcast} is true:
  200. broadcast "&c* &7Gracz %{_p}% wzial kit: %event.getCurrentItem().getItemMeta().getDisplayName().substring(11)%"
  201. if size of {kKits::%{_p}%::%{_id}%::*} is larger than 0:
  202. set {_rows} to ceil("%size of {kKits::%{_p}%::%{_id}%::*}%" parsed as integer / 9)
  203. set {_yaml} to yaml value "kits.%{_id}%.displayItem" from Kits_getPath()
  204. set {_name} to getItemByText({_yaml})
  205. set {_x} to chest with {_rows} rows named "&eZestaw: %coloured name of {_name}%"
  206. loop {kKits::%{_p}%::%{_id}%::*}:
  207. set slot loop-index parsed as integer - 1 of {_x} to loop-value
  208. close {_p}'s inventory
  209. wait 2 tick
  210. open {_x} to {_p}
  211. set {kKits::%{_p}%::%{_id}%} to true
  212. stop
  213. if "%{_lore::2}%" doesn't contain "&aTeraz":
  214. stop
  215.  
  216. set {_lore::1} to 3 last characters of {_lore::1}
  217. if "%{_lore::1}%" is "NIE":
  218. stop
  219. set {_items::*} to getAllItemsFromKit({_id})
  220. if {_p} has enough space for {_items::*}:
  221. give {_p} {_items::*}
  222. else:
  223. send "&c* &7Nie posiadasz tyle miejsca w ekwipunku." to {_p}
  224. stop
  225. set {_timespan} to yaml value "kits.%{_id}%.time" from Kits_getPath()
  226. set {_broadcast} to yaml value "kits.%{_id}%.broadcast" from Kits_getPath()
  227. if {_broadcast} is true:
  228. broadcast "&c* &7Gracz %{_p}% wzial kit: %event.getCurrentItem().getItemMeta().getDisplayName().substring(11)%"
  229. close {_p}'s inventory
  230. set {_timespan} to {_timespan} parsed as timespan
  231. set {_time} to now
  232. add {_timespan} to {_time}
  233. set yaml value "kits.%{_id}%.%{_p}%" from Kits_getPath("players") to {_time}.getTimestamp()
  234. stop
  235. if event.isRightClick() is true:
  236. close {_p}'s inventory
  237. wait 2 tick
  238. open getInventory({_id}, {_p}) to {_p}
  239. stop
  240. on inventory close:
  241. if inventory name of player's current inventory contains "&eZestaw:":
  242. set {_name} to inventory name of player's current inventory
  243. replace all "&eZestaw: " in {_name} with ""
  244. set {_id} to getIdFromItem({_name})
  245. if yaml value "kits.%{_id}%.guiReceive" from Kits_getPath() is true:
  246. if {kKits::%player%::%{_id}%} is set:
  247. clear {kKits::%player%::%{_id}%::*}
  248. set {kKits::%player%::%{_id}%::*} to all items in player's current inventory
  249. clear {kKits::%player%::%{_id}%}
  250.  
  251. command /kit [<text>]:
  252. aliases: kits
  253. trigger:
  254. open getInventory("MAIN", player) to player
  255. every 2 second:
  256. if yaml value "autoRefreshInGUI" from Kits_getPath() is true:
  257. loop all players:
  258. if "%inventory name of loop-player's current inventory%" is "&eZestawy":
  259. set {_items::*} to all items in loop-player's current inventory
  260. loop {_items::*}:
  261. if "%lore of loop-value-2%" doesn't contain "&7Dostepny za: &aTeraz":
  262. set {_lore} to lore of loop-value-2
  263. set {_name} to subtext of name of loop-value-2 between index 12 and length of name of loop-value-2
  264. set {_id} to getIdFromItem({_name})
  265. set {_oldTime} to subtext of {_lore} between index index of "Dostepny za:" in {_lore} + 13 and index index of "Zestaw mozna" in {_lore} - 6
  266. set {_newTime} to getTime({_id}, loop-player)
  267. replace all {_oldTime} with "&7%{_newTime}%" in {_lore}
  268. set loop-player's current inventory's slot loop-index parsed as integer - 1 to loop-value-2 with lore {_lore}
  269. clear {_lore}
Advertisement
Add Comment
Please, Sign In to add comment