Forked from Pikachu920/gist:9a89d97d3aa92c5a03de0577af1e5aff
Created
May 23, 2018 07:40
-
-
Save Draww/342547f5a383c8ae5e0f98ae590e1928 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import: | |
ch.njol.skript.log.SkriptLogger | |
ch.njol.skript.ScriptLoader | |
ch.njol.skript.config.SectionNode | |
ch.njol.skript.lang.Condition | |
ch.njol.skript.Skript | |
ch.njol.skript.config.validate.SectionValidator | |
ch.njol.skript.lang.SkriptParser | |
com.btk5h.skriptmirror.Util as MirrorUtil | |
java.util.Arrays | |
effect add [(1¦optional)] entr(y|ies) %strings% to %_entries%: | |
trigger: | |
loop expressions 2: | |
loop expressions 1: | |
if parse mark is 1: | |
loop-value-1.addEntry(loop-value-2 and true); | |
else: | |
loop-value-1.addEntry(loop-value-2 and false); | |
on script load: | |
set {shop validator} to new SectionValidator() | |
add entries "buy price", "sell price" and "item" to {shop validator} | |
expression current node: | |
get: | |
return SkriptLogger.getNode() | |
set: | |
SkriptLogger.setNode(change value); | |
effect nuke node[s] %_nodes%: | |
trigger: | |
loop expressions 1: | |
loop-value is an instance of SectionNode | |
delete {_nodes::*} | |
set {_i} to 1 | |
loop ...loop-value.iterator(): | |
set {_nodes::%{_i}%} to loop-value-2 | |
add 1 to {_i} | |
loop {_nodes::*}: | |
loop-value-1.remove(loop-value-2); | |
effect convert %_nodes% to [%-number%] entries: | |
trigger: | |
loop expressions 1: | |
if raw expression 2 is set: | |
loop-value.convertToEntries(expr 2); | |
else: | |
loop-value.convertToEntries(0); | |
condition node (starts|1¦does not start) with if: | |
check: | |
if parse mark is 1: | |
negate the condition | |
if SkriptLogger.getNode().getKey().startsWith("if") is true: | |
continue | |
else if SkriptLogger.getNode().getKey().startsWith("else if") is true: | |
continue | |
expression option replaced %string%: | |
get: | |
return ScriptLoader.replaceOptions(expr 1) | |
expression %javatype% expression %string%: | |
get: | |
set {_parser} to new SkriptParser(expr 2) | |
return {_parser}.parseExpression(MirrorUtil.toClass(expr 1)) | |
object property entry %string%: | |
get: | |
if expr-1 is not a text: | |
return expr-1.get(expr-2).getValue() | |
return expr-2.get(expr-1).getValue() | |
effect do nothing: | |
trigger: | |
stop | |
condition sell: | |
parse: | |
if {shop::parsing} is set: | |
if node does not start with if: | |
convert {current sell node} to entries | |
if {shop validator}.validate({current sell node}) is true: | |
set {_item} to item expression (option replaced (entry "item" of {current sell node})) | |
set {_sell price} to (option replaced (entry "sell price" of {current sell node})) parsed as a number | |
set {_buy price} to (option replaced (entry "buy price" of {current sell node})) parsed as a number | |
set {_i} to size of {shop::categories::%{shop::parsing}%::*} | |
set {shop::categories::%{shop::parsing}%::%{_i}%} to true | |
set {shop::categories::%{shop::parsing}%::%{_i}%::item} to {_item}.getSingle(event) | |
set {shop::categories::%{shop::parsing}%::%{_i}%::buy price} to {_buy price} | |
set {shop::categories::%{shop::parsing}%::%{_i}%::sell price} to {_sell price} | |
continue | |
check: | |
do nothing | |
condition category <(.+)>: | |
parse: | |
set {_node} to current node | |
if node does not start with if: | |
set {shop::parsing} to "%regex 1%" | |
delete {shop::categories::%{shop::parsing}%} | |
delete {shop::categories::%{shop::parsing}%::*} | |
set {shop::categories::%{shop::parsing}%} to true | |
loop ...{_node}.iterator(): | |
set {_exists} to true | |
if loop-value is an instance of SectionNode: | |
if loop-value.getKey() is "sell": | |
set {current sell node} to loop-value | |
set {_cond} to Condition.parse(loop-value.getKey() and "Can't understand this scope %loop-value.getKey()%") | |
else: | |
Skript.error("Only sell scopes are allowed in categories!"); | |
set {_error} to true | |
else: | |
Skript.error("Only sections are allowed in categories!"); | |
set {_error} to true | |
if {_exists} is not true: | |
Skript.error("A category must have at least one item!"); | |
set {_error} to true | |
if {_error} is not set: | |
if {sell error} is not set: | |
nuke node {_node} | |
continue | |
delete {sell error} | |
delete {category::parsing} | |
check: | |
do nothing | |
item property custom lore: | |
get: | |
return join ...expr-1.getItemMeta().getLore() with "||" | |
set: | |
loop expressions 1: | |
set {_meta} to loop-value.getItemMeta() | |
{_meta}.setLore(Arrays.asList(split change value at "||")); | |
loop-value.setItemMeta({_meta}); | |
on script load: | |
category Raid: | |
sell: | |
item: tnt | |
buy price: 250 | |
sell price: 300 | |
sell: | |
item: dirt | |
buy price: 300 | |
sell price: 250 | |
category Wood: | |
sell: | |
item: wooden axe | |
buy price: 1000 | |
sell price: 50 | |
command shop: | |
trigger: | |
create a gui with virtual chest with 6 rows named "Categories": | |
loop {shop::categories::*}: | |
set {_index} to loop-index | |
make next gui with diamond named colored "%{_index}%": | |
create a gui with virtual chest with 6 rows named colored "%{_index}%": | |
loop {shop::categories::%{_index}%::*}: | |
set {_item} to {shop::categories::%{_index}%::%loop-index-2%::item} | |
set custom lore of {_item} to "<red>Buy: %{shop::categories::%{_index}%::%loop-index-2%::buy price}%||Sell: %{shop::categories::%{_index}%::%loop-index-2%::sell price}%" | |
make next gui with {_item} | |
open last gui to player | |
open last gui to player |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment