-
Notifications
You must be signed in to change notification settings - Fork 1
Config examples
Sven Rahn edited this page Jun 13, 2018
·
22 revisions
Just try them out and learn. If you need help, contact me at my discord.
If you want to use a " quote in other quotes, you have to 'escape' it using a \ backslash: \"
OR
You can use triple quotes around a string and then you don't have to escape the inner quotes:
string = "A cool string with \"these\" cool quotes!"
string = """A cool string with "these" cool quotes!"""
aliases {
"wealth {0}" {
commands=[
"*cu execute if \"*cu has money {0} 12\" \"internal_wealth_1 {0}\"",
"*cu execute if not \"*cu has money {0} 12\" \"*say {0} is broke!\""
]
permission=""
}
"internal_wealth_1 {0}" {
commands=[
"*say {0} has a little money",
"*cu execute if \"*cu has money {0} 25\" \"*say and even a bit more!\""
]
permission=admin
}
}
aliases {
"buy basic" {
commands=[
"""*cu execute if not "*cu has money %player% 300" "*msg %player% You need at least 300$!"""",
"""*cu execute if "*cu has payed %player% 300" "*give %player% minecraft:cookie 50" "*give %player% minecraft:apple 20" "*msg %player You bought the basic pack!" """
]
permission=""
cooldown="1h"
}
}
Context: The player won the lottery/a reward. The winner is not online.
The reward command is
/give %player% minecraft:cookie 5
You delay the command until the player joins the next time
/cu execute whenOnline %player% *give %player% minecraft:cookie 5
This works fine. But you want to make the player only get their reward if they join in the next 3 days. So you use the /cu execute before ... command:
/cu execute before <timestamp> *cu execute whenOnline %player% *give %player% minecraft:cookie 5
But where do we get the from? We can use a JavaScript Placeholder. Here is an example for our use-case:
function isEmpty(string) {
return (!string || 0 === string.length());
}
function toNumberOrZero(string) {
return isEmpty(string) ? 0 : parseInt(string);
}
with(new JavaImporter(java.lang, java.time, java.time.temporal, java.util, java.util.regex, java.text)) {
var duration = args[0];
var now = Instant.now();
var durationRegex = Pattern.compile("(?:(\\d+)d)?(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?(?:(\\d+)ms)?");
var matcher = durationRegex.matcher(duration);
if (!matcher.find()) {
throw new IllegalArgumentException("'" + duration + "' isn't a valid duration! Use something like '3d2h12m30s800ms'")
}
var days = toNumberOrZero(matcher.group(1));
var hours = toNumberOrZero(matcher.group(2));
var minutes = toNumberOrZero(matcher.group(3));
var seconds = toNumberOrZero(matcher.group(4));
var milliseconds = toNumberOrZero(matcher.group(5));
var time = now
.plus(days, ChronoUnit.DAYS)
.plus(hours, ChronoUnit.HOURS)
.plus(minutes, ChronoUnit.MINUTES)
.plus(seconds, ChronoUnit.SECONDS)
.plus(milliseconds, ChronoUnit.MILLIS);
var format = new SimpleDateFormat("HH:mm:ss.SSS-dd.MM.yyyy");
out = format.format(java.util.Date.from(time));
}