Skip to content

Commit b11edb3

Browse files
committed
Add NumberCommand reward type
1 parent bffdb97 commit b11edb3

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/RewardHandler.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,28 @@ public void onValidate(Reward reward, RewardInject inject, ConfigurationSection
12041204
}
12051205
}));
12061206

1207+
injectedRewards.add(new RewardInjectConfigurationSection("NumberCommand") {
1208+
1209+
@Override
1210+
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section,
1211+
HashMap<String, String> placeholders) {
1212+
int min = section.getInt("Min", 0);
1213+
int max = section.getInt("Max", 100);
1214+
int number = ThreadLocalRandom.current().nextInt(min, max + 1);
1215+
String command = section.getString("Command", "").replace("%number%", String.valueOf(number));
1216+
MiscUtils.getInstance().executeConsoleCommands(user.getPlayerName(), command, placeholders);
1217+
return String.valueOf(number);
1218+
}
1219+
}.asPlaceholder("Number").priority(100).validator(new RewardInjectValidator() {
1220+
1221+
@Override
1222+
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
1223+
if (!data.isInt("Min") || !data.isInt("Max") || !data.isString("Command")) {
1224+
warning(reward, inject, "NumberCommand requires Min, Max, and Command to be set");
1225+
}
1226+
}
1227+
}));
1228+
12071229
injectedRewards.add(new RewardInjectInt("EXP", 0) {
12081230

12091231
@Override
@@ -1442,7 +1464,7 @@ public void onValidate(Reward reward, RewardInject inject, ConfigurationSection
14421464
@Override
14431465
public String onRewardRequest(Reward reward, AdvancedCoreUser user, String value,
14441466
HashMap<String, String> placeholders) {
1445-
MiscUtils.getInstance().executeConsoleCommands(user.getPlayer(), value, placeholders);
1467+
MiscUtils.getInstance().executeConsoleCommands(user.getPlayerName(), value, placeholders);
14461468
return null;
14471469
}
14481470
}.addEditButton(new EditGUIButton(new ItemBuilder("COMMAND_BLOCK"), new EditGUIValueString("Command", null) {
@@ -1833,7 +1855,7 @@ public void openInventory(ClickEvent clickEvent) {
18331855
public String onRewardRequest(Reward r, AdvancedCoreUser user, ArrayList<String> list,
18341856
HashMap<String, String> placeholders) {
18351857
if (list.size() > 0) {
1836-
MiscUtils.getInstance().executeConsoleCommands(user.getPlayer(),
1858+
MiscUtils.getInstance().executeConsoleCommands(user.getPlayerName(),
18371859
list.get(ThreadLocalRandom.current().nextInt(list.size())), placeholders);
18381860
}
18391861
return null;

AdvancedCore/src/main/resources/Rewards/ExampleAdvanced.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ RandomCommand: []
6666
# Will give one reward from the list of rewards
6767
RandomReward: []
6868

69+
# Picks a random number and uses that within the command
70+
NumberCommand:
71+
Min: 1
72+
Max: 10
73+
Command: "say The random number is %number%"
74+
6975
# Works similar to RandomReward above, just avoids reward files
7076
# Similar style to AdvancedPriority
7177
AdvancedRandomReward:

0 commit comments

Comments
 (0)