Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. #
  2. #
  3. #
  4. #
  5. #
  6. #
  7. #
  8. #
  9. #
  10.  
  11. import:
  12. org.bukkit.block.Chest
  13.  
  14. function loot_config(p: sender):
  15. set {_ms} to ms
  16.  
  17. clear {-lootconfig::*}
  18.  
  19. load yaml "plugins/Skript/loot/loots.yml" as "loot"
  20.  
  21. loop yaml node keys "loots" from "loot":
  22.  
  23. set {-lootconfig::name::%loop-value%} to (yaml value "loots.%loop-value%.name" from "loot") ? "Nameless"
  24. set {-lootconfig::cooldown::%loop-value%} to (yaml value "loots.%loop-value%.cooldown" from "loot" to seconds) ? 0
  25.  
  26. loop yaml list "loots.%loop-value%.loot" from "loot":
  27.  
  28. set {_match} to matcher "(.+) ([0-9]+)%% (.+)" of "%loop-value-2%"
  29.  
  30. add 1 to {_i}
  31.  
  32. set {_amount} to 1st element of groups 1 of {_match}
  33. set {_i::*} to (split {_amount} at "-") ? {_amount}
  34. if {_i::2} is not set:
  35. set {-lootconfig::loot::%loop-value-1%::%{_i}%::min} to {_i::1} parsed as number
  36. set {-lootconfig::loot::%loop-value-1%::%{_i}%::max} to {-lootconfig::loot::%loop-value-1%::%{_i}%::min}
  37. else:
  38. set {-lootconfig::loot::%loop-value-1%::%{_i}%::min} to {_i::1} parsed as number
  39. set {-lootconfig::loot::%loop-value-1%::%{_i}%::max} to {_i::2} parsed as number
  40.  
  41. set {_chance} to 1st element of groups 2 of {_match}
  42. set {-lootconfig::loot::%loop-value-1%::%{_i}%::chance} to ({_chance} parsed as number) / 100
  43.  
  44. set {_item} to 1st element of groups 3 of {_match}
  45. set {-lootconfig::loot::%loop-value-1%::%{_i}%} to {_item} parsed as item
  46.  
  47. if {-lootconfig::loot::%loop-value-1%::%{_i}%} is not set:
  48. clear {-lootconfig::loot::%loop-value-1%::%{_i}%::*}
  49. send "&3[Loots] &7Failed to load the item &c%loop-value-2%&7." to {_p}
  50.  
  51. unload yaml "loot"
  52. send "&3[Loots] &fConfig loaded in &a%ms - {_ms}%ms &fwith a total of &a%{_i} ? 0% &fitems." to {_p}
  53.  
  54. on load:
  55. loot_config(console)
  56.  
  57. command /loot [<text>] [<text>] [<text>]:
  58. trigger:
  59.  
  60. if player doesn't have permission "loot.admin":
  61. send "&3[Loots] &cYou do not have the required permission."
  62.  
  63. else if arg 1 = "reload":
  64. loot_config(sender)
  65.  
  66. function loot_getfromname(name: text) :: text:
  67. loop {-lootconfig::name::*}:
  68. {_name} = loop-value
  69. return loop-index
  70.  
  71. on inventory open:
  72. event-inventory.getHolder() is instance of Chest
  73. set {_b} to event-inventory.getHolder().getBlock()
  74. set {_l} to location of {_b}
  75.  
  76. if {loot::cooldown::%{_l}%} > unix timestamp of now:
  77. set {_format} to regex replace "00[a-zA-Z]+" with "" in (format ({loot::cooldown::%{_l}%} - unix timestamp of now) into "yy'y'MM'mo'dd'd'HH'h'mm'm'ss's'")
  78. send "&3[Loots] &7This chest will refill in &c%{_format}%&7."
  79. else:
  80. set {_name} to loot_getfromname({_b}.getState().getCustomName())
  81. {_name} is set
  82. send "&3[Loots] &7You opened a &a%{_b}.getState().getCustomName()% &7chest."
  83. set {loot::cooldown::%{_l}%} to unix timestamp of now + {-lootconfig::cooldown::%{_name}%}
  84. loop {-lootconfig::loot::%{_name}%::*}:
  85. chance of {-lootconfig::loot::%{_name}%::%loop-index%::chance}:
  86. set {_i} to random integer between {-lootconfig::loot::%{_name}%::%loop-index%::min} and {-lootconfig::loot::%{_name}%::%loop-index%::max} of loop-value
  87. set slot (random integer between 0 and 26) of {_b} to {_i}
  88.  
  89. on break:
  90. event-block = chest
  91. event is not cancelled
  92. {loot::cooldown::%event-location%} is set
  93. clear {loot::cooldown::%event-location%}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement