use of com.bencodez.advancedcore.api.rewards.editbuttons.RewardEditAdvancedPriority in project AdvancedCore by BenCodez.
the class RewardHandler method loadInjectedRewards.
public void loadInjectedRewards() {
injectedRewards.add(new RewardInjectDouble("Money", 0) {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, double num, HashMap<String, String> placeholders) {
user.giveMoney(num);
return "" + (int) num;
}
}.asPlaceholder("Money").priority(100).addEditButton(new EditGUIButton(new ItemBuilder(Material.DIAMOND), new EditGUIValueInventory("Money") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditMoney() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Money to execute, may not work on some economy plugins").addLore("Supports random amounts"))).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.getDouble(inject.getPath(), -1) == 0) {
warning(reward, inject, "Money can not be 0");
}
}
}));
injectedRewards.add(new RewardInjectConfigurationSection("Money") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
double minMoney = section.getDouble("Min", 0);
double maxMoney = section.getDouble("Max", 0);
double value = ThreadLocalRandom.current().nextDouble(minMoney, maxMoney);
user.giveMoney(value);
DecimalFormat f = new DecimalFormat("##.00");
return "" + f.format(value);
}
}.asPlaceholder("Money").priority(100).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.getDouble("Money.Max", -1) == 0) {
warning(reward, inject, "Maxium money can not be 0");
}
}
}));
injectedRewards.add(new RewardInjectInt("EXP", 0) {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, int num, HashMap<String, String> placeholders) {
user.giveExp(num);
return null;
}
}.asPlaceholder("EXP").priority(100).addEditButton(new EditGUIButton(new ItemBuilder("EXPERIENCE_BOTTLE"), new EditGUIValueInventory("EXP") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditEXP() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("EXP to give"))).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.getDouble(inject.getPath(), -1) == 0) {
warning(reward, inject, "EXP can not be 0");
}
}
}));
injectedRewards.add(new RewardInjectInt("EXPLevels", 0) {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, int num, HashMap<String, String> placeholders) {
user.giveExpLevels(num);
return null;
}
}.asPlaceholder("EXP").priority(100).addEditButton(new EditGUIButton(new ItemBuilder("EXPERIENCE_BOTTLE"), new EditGUIValueInventory("EXPLevels") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditEXPLevels() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("EXPLevels to give"))).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.getDouble(inject.getPath(), -1) == 0) {
warning(reward, inject, "EXP can not be 0");
}
}
}));
injectedRewards.add(new RewardInjectConfigurationSection("EXP") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
int minEXP = section.getInt("Min", 0);
int maxEXP = section.getInt("Max", 0);
int value = ThreadLocalRandom.current().nextInt(minEXP, maxEXP);
user.giveExp(value);
return "" + value;
}
}.asPlaceholder("EXP").priority(100).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.getDouble("EXP.Max", -1) == 0) {
warning(reward, inject, "Max EXP can not be 0");
}
}
}));
injectedRewards.add(new RewardInjectConfigurationSection("EXPLevels") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
int minEXP = section.getInt("Min", 0);
int maxEXP = section.getInt("Max", 0);
int value = ThreadLocalRandom.current().nextInt(minEXP, maxEXP);
user.giveExpLevels(value);
return "" + value;
}
}.asPlaceholder("EXP").priority(100).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.getDouble("EXP.Max", -1) == 0) {
warning(reward, inject, "Max EXP can not be 0");
}
}
}));
injectedRewards.add(new RewardInjectString("Message") {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, String value, HashMap<String, String> placeholders) {
user.sendMessage(value, placeholders);
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder("OAK_SIGN"), new EditGUIValueInventory("Messages") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditMessages() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addCheckKey("Message"))).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.getString(inject.getPath()).isEmpty()) {
warning(reward, inject, "No player message set");
}
}
}));
injectedRewards.add(new RewardInjectStringList("Messages.Player") {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, ArrayList<String> value, HashMap<String, String> placeholders) {
user.sendMessage(value, placeholders);
return null;
}
});
injectedRewards.add(new RewardInjectStringList("Message") {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, ArrayList<String> value, HashMap<String, String> placeholders) {
user.sendMessage(value, placeholders);
return null;
}
});
injectedRewards.add(new RewardInjectString("Messages.Player") {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, String value, HashMap<String, String> placeholders) {
user.sendMessage(value, placeholders);
return null;
}
}.validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.isString(inject.getPath()) && data.getString(inject.getPath()).isEmpty()) {
warning(reward, inject, "No player message set");
}
}
}));
injectedRewards.add(new RewardInjectStringList("Messages.Broadcast") {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, ArrayList<String> value, HashMap<String, String> placeholders) {
String playerName = user.getPlayerName();
if (plugin.getOptions().getBroadcastBlacklist().contains(playerName)) {
debug("Not broadcasting for " + playerName + ", in blacklist");
return null;
}
for (String str : value) {
MiscUtils.getInstance().broadcast(StringParser.getInstance().replacePlaceHolders(user.getPlayer(), StringParser.getInstance().replacePlaceHolder(str, placeholders)));
}
return null;
}
}.validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
}
}));
injectedRewards.add(new RewardInjectString("Messages.Broadcast") {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, String value, HashMap<String, String> placeholders) {
String playerName = user.getPlayerName();
if (plugin.getOptions().getBroadcastBlacklist().contains(playerName)) {
debug("Not broadcasting for " + playerName + ", in blacklist");
return null;
}
MiscUtils.getInstance().broadcast(StringParser.getInstance().replacePlaceHolders(user.getPlayer(), StringParser.getInstance().replacePlaceHolder(value, placeholders)));
return null;
}
}.validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (!data.isList(inject.getPath())) {
if (data.getString(inject.getPath(), "Empty").isEmpty()) {
warning(reward, inject, "No broadcast was set");
}
}
}
}));
injectedRewards.add(new RewardInjectString("Command") {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, String value, HashMap<String, String> placeholders) {
MiscUtils.getInstance().executeConsoleCommands(user.getPlayer(), value, placeholders);
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder("COMMAND_BLOCK"), new EditGUIValueString("Command", null) {
@Override
public void setValue(Player player, String value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(getKey(), value);
plugin.reloadAdvancedCore(false);
reward.reOpenEditGUI(player);
}
}.addLore("Execute single console command"))).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.getString(inject.getPath()).startsWith("/")) {
warning(reward, inject, "Can't start command with /");
}
}
}));
injectedRewards.add(new RewardInjectConfigurationSection("ActionBar") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
user.sendActionBar(StringParser.getInstance().replacePlaceHolder(section.getString("Message", ""), placeholders), section.getInt("Delay", 30));
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueInventory("ActionBar") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditActionBar() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Actionbar configuration"))).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
String str = data.getString("ActionBar.Message");
int delay = data.getInt("ActionBar.Delay", -1);
if (str != null && str.isEmpty()) {
warning(reward, inject, "No actionbar message set");
}
if (delay == -1) {
warning(reward, inject, "No actionbar delay set");
} else if (delay == 0) {
warning(reward, inject, "Actionbar delay can not be 0");
}
}
}));
injectedRewards.add(new RewardInjectStringList("Commands") {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, ArrayList<String> list, HashMap<String, String> placeholders) {
if (!list.isEmpty()) {
MiscUtils.getInstance().executeConsoleCommands(user.getPlayerName(), list, placeholders);
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder("COMMAND_BLOCK"), new EditGUIValueList("Commands", null) {
@Override
public void setValue(Player player, ArrayList<String> value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(getKey(), value);
plugin.reloadAdvancedCore(false);
reward.reOpenEditGUI(player);
}
}.addLore("List of console commands"))).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.isList(inject.getPath()) && !data.isConfigurationSection(inject.getPath())) {
List<String> list = data.getStringList(inject.getPath());
if (list != null) {
if (list.isEmpty()) {
warning(reward, inject, "No commands listed");
}
for (String str : list) {
if (str.startsWith("/")) {
warning(reward, inject, "Commands can not start with /");
}
}
}
}
}
}));
injectedRewards.add(new RewardInjectConfigurationSection("Commands") {
@SuppressWarnings("unchecked")
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
ArrayList<String> consoleCommands = (ArrayList<String>) section.getList("Console", new ArrayList<String>());
ArrayList<String> userCommands = (ArrayList<String>) section.getList("Player", new ArrayList<String>());
if (!consoleCommands.isEmpty()) {
MiscUtils.getInstance().executeConsoleCommands(user.getPlayerName(), consoleCommands, placeholders);
}
if (!userCommands.isEmpty()) {
user.preformCommand(userCommands, placeholders);
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueList("Commands.Console", null) {
@Override
public void setValue(Player player, ArrayList<String> value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(getKey(), value);
plugin.reloadAdvancedCore(false);
reward.reOpenEditGUI(player);
}
}.addLore("Old style for console commands"))).addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueList("Commands.Player", null) {
@Override
public void setValue(Player player, ArrayList<String> value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(getKey(), value);
plugin.reloadAdvancedCore(false);
reward.reOpenEditGUI(player);
}
}.addLore("Execute commands as player"))));
injectedRewards.add(new RewardInjectStringList("Javascripts") {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, ArrayList<String> list, HashMap<String, String> placeholders) {
if (!list.isEmpty()) {
JavascriptEngine engine = new JavascriptEngine().addPlayer(user.getOfflinePlayer());
for (String str : list) {
engine.execute(StringParser.getInstance().replacePlaceHolder(str, placeholders));
}
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueList("Javascripts", null) {
@Override
public void setValue(Player player, ArrayList<String> value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(getKey(), value);
plugin.reloadAdvancedCore(false);
reward.reOpenEditGUI(player);
}
}.addLore("Javascript expressions to run"))));
injectedRewards.add(new RewardInjectConfigurationSection("Javascript") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
if (section.getBoolean("Enabled")) {
if (new JavascriptEngine().addPlayer(user.getOfflinePlayer()).getBooleanValue(StringParser.getInstance().replacePlaceHolder(section.getString("Expression"), placeholders))) {
new RewardBuilder(section, "TrueRewards").withPrefix(reward.getName()).send(user);
} else {
new RewardBuilder(section, "FalseRewards").withPrefix(reward.getName()).send(user);
}
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueInventory("Javascript") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditJavascript() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Run javascript to run rewards based on expression return value of true/false"))));
injectedRewards.add(new RewardInjectConfigurationSection("Lucky") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
HashMap<Integer, String> luckyRewards = new HashMap<Integer, String>();
for (String str : section.getKeys(false)) {
if (StringParser.getInstance().isInt(str)) {
int num = Integer.parseInt(str);
if (num > 0) {
String path = "Lucky." + num;
luckyRewards.put(num, path);
}
}
}
HashMap<String, Integer> map = new LinkedHashMap<String, Integer>();
for (Entry<Integer, String> entry : luckyRewards.entrySet()) {
if (MiscUtils.getInstance().checkChance(1, entry.getKey())) {
map.put(entry.getValue(), entry.getKey());
}
}
map = ArrayUtils.getInstance().sortByValuesStr(map, false);
if (map.size() > 0) {
if (reward.getConfig().getConfigData().getBoolean("OnlyOneLucky", false)) {
for (Entry<String, Integer> entry : map.entrySet()) {
new RewardBuilder(reward.getConfig().getConfigData(), entry.getKey()).withPlaceHolder(placeholders).send(user);
return null;
}
} else {
for (Entry<String, Integer> entry : map.entrySet()) {
new RewardBuilder(reward.getConfig().getConfigData(), entry.getKey()).withPlaceHolder(placeholders).send(user);
}
}
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueInventory("Lucky") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditLucky() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(getKey(), value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
})).priority(10).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
}
}.addPath("OnlyOneLucky")));
injectedRewards.add(new RewardInjectConfigurationSection("Random") {
@SuppressWarnings("unchecked")
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
if (MiscUtils.getInstance().checkChance(section.getDouble("Chance", 100), 100)) {
if (section.getBoolean("PickRandom", true)) {
ArrayList<String> rewards = (ArrayList<String>) section.getList("Rewards", new ArrayList<String>());
if (rewards != null) {
if (rewards.size() > 0) {
String reward1 = rewards.get(ThreadLocalRandom.current().nextInt(rewards.size()));
if (!reward1.equals("")) {
RewardHandler.getInstance().giveReward(user, reward1, new RewardOptions().setPlaceholders(placeholders));
}
}
}
} else {
new RewardBuilder(reward.getConfig().getConfigData(), "Random.Rewards").withPrefix(reward.getName()).withPlaceHolder(placeholders).send(user);
}
} else {
new RewardBuilder(reward.getConfig().getConfigData(), "Random.FallBack").withPrefix(reward.getName()).withPlaceHolder(placeholders).send(user);
}
return null;
}
}.priority(10));
injectedRewards.add(new RewardInjectConfigurationSection("Rewards") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
new RewardBuilder(reward.getConfig().getConfigData(), "Rewards").withPrefix(reward.getName()).withPlaceHolder(placeholders).send(user);
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.DISPENSER), new EditGUIValueInventory("Rewards") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
openSubReward(clickEvent.getPlayer(), "Rewards", reward);
}
}.addLore("Sub rewards"))).priority(5).alwaysForce().postReward());
injectedRewards.add(new RewardInjectStringList("RandomCommand") {
@Override
public String onRewardRequest(Reward r, AdvancedCoreUser user, ArrayList<String> list, HashMap<String, String> placeholders) {
if (list.size() > 0) {
MiscUtils.getInstance().executeConsoleCommands(user.getPlayer(), list.get(ThreadLocalRandom.current().nextInt(list.size())), placeholders);
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueList("RandomCommand", null) {
@Override
public void setValue(Player player, ArrayList<String> value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(getKey(), value);
plugin.reloadAdvancedCore(false);
reward.reOpenEditGUI(player);
}
}.addLore("Execute random command"))).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
List<String> list = data.getStringList(inject.getPath());
if (list.size() == 0) {
warning(reward, inject, "No rewards listed for random reward");
} else if (list.size() == 1) {
warning(reward, inject, "Only one reward listed for random reward");
}
}
}));
injectedRewards.add(new RewardInjectStringList("RandomReward") {
@Override
public String onRewardRequest(Reward r, AdvancedCoreUser user, ArrayList<String> list, HashMap<String, String> placeholders) {
if (list.size() > 0) {
String reward = list.get(ThreadLocalRandom.current().nextInt(list.size()));
giveReward(user, reward, new RewardOptions().setPlaceholders(placeholders));
return reward;
}
return null;
}
}.asPlaceholder("RandomReward").priority(90).addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueList("RandomReward", null) {
@Override
public void setValue(Player player, ArrayList<String> value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(getKey(), value);
plugin.reloadAdvancedCore(false);
}
}.addLore("Execute random reward"))).postReward());
injectedRewards.add(new RewardInjectConfigurationSection("TempPermission") {
@Override
public String onRewardRequested(Reward r, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
String perm = section.getString("Permission", "");
int time = section.getInt("Expiration");
if (!perm.isEmpty()) {
if (time > 0) {
user.addPermission(perm, time);
} else {
extraDebug("Time is 0");
}
} else {
extraDebug("Permission is empty");
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueInventory("TempPermission") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditTempPermission() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Give temporary permission"))).priority(90).postReward());
injectedRewards.add(new RewardInjectConfigurationSection("AdvancedRandomReward") {
@Override
public String onRewardRequested(Reward r, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
Set<String> keys = section.getKeys(false);
ArrayList<String> rewards = ArrayUtils.getInstance().convert(keys);
if (rewards.size() > 0) {
String reward = rewards.get(ThreadLocalRandom.current().nextInt(rewards.size()));
giveReward(user, section, reward, new RewardOptions().setPlaceholders(placeholders).setPrefix(r.getRewardName() + "_AdvancedRandomReward_"));
return reward;
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueInventory("AdvancedRandomReward") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditAdvancedRandomReward() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Execute random reward"))).asPlaceholder("RandomReward").priority(90).postReward());
injectedRewards.add(new RewardInjectStringList("Priority") {
@Override
public String onRewardRequest(Reward r, AdvancedCoreUser user, ArrayList<String> list, HashMap<String, String> placeholders) {
for (String str : list) {
Reward reward = RewardHandler.getInstance().getReward(str);
if (reward.canGiveReward(user, new RewardOptions())) {
new RewardBuilder(reward).withPlaceHolder(placeholders).setIgnoreChance(true).setIgnoreRequirements(true).send(user);
return reward.getName();
}
}
return null;
}
}.asPlaceholder("Priority").addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueList("Priority", null) {
@Override
public void setValue(Player player, ArrayList<String> value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(getKey(), value);
plugin.reloadAdvancedCore(false);
reward.reOpenEditGUI(player);
}
}.addLore("Execute first reward file that can be executed"))).postReward());
injectedRewards.add(new RewardInjectConfigurationSection("Potions") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
for (String potion : section.getKeys(false)) {
user.givePotionEffect(potion, section.getInt(potion + ".Duration", 1), section.getInt(potion + ".Amplifier", 1));
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAINTING), new EditGUIValueInventory("Potions") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditPotions() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Configure Potion Effects"))));
injectedRewards.add(new RewardInjectConfigurationSection("Title") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
if (section.getBoolean("Enabled")) {
user.sendTitle(StringParser.getInstance().replacePlaceHolder(section.getString("Title"), placeholders), StringParser.getInstance().replacePlaceHolder(section.getString("SubTitle"), placeholders), section.getInt("FadeIn", 10), section.getInt("ShowTime", 50), section.getInt("FadeOut", 10));
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAINTING), new EditGUIValueInventory("Title") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditTitle() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Configure Title & SubTitle"))));
injectedRewards.add(new RewardInjectConfigurationSection("BossBar") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
if (section.getBoolean("Enabled")) {
user.sendBossBar(StringParser.getInstance().replacePlaceHolder(section.getString("Message", ""), placeholders), section.getString("Color", "BLUE"), section.getString("Style", "SOLID"), section.getDouble("Progress", .5), section.getInt("Delay", 30));
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder("DRAGON_HEAD"), new EditGUIValueInventory("BossBar") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditBossBar() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Configure bossbar"))));
injectedRewards.add(new RewardInjectConfigurationSection("Sound") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
if (section.getBoolean("Enabled")) {
try {
user.playSound(section.getString("Sound"), (float) section.getDouble("Volume", 1.0), (float) section.getDouble("Pitch", 1.0));
} catch (Exception ex) {
ex.printStackTrace();
}
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.NOTE_BLOCK), new EditGUIValueInventory("Sound") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditSound() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Configure sound"))));
injectedRewards.add(new RewardInjectConfigurationSection("Effect") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
if (section.getBoolean("Enabled")) {
user.playParticle(section.getString("Effect"), section.getInt("Data", 1), section.getInt("Particles", 1), section.getInt("Radius", 5));
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.DIAMOND), new EditGUIValueInventory("Effect") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditEffect() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Configure particle effect"))));
injectedRewards.add(new RewardInjectConfigurationSection("Firework") {
@SuppressWarnings("unchecked")
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
if (section.getBoolean("Enabled")) {
FireworkHandler.getInstance().launchFirework(user.getPlayer().getLocation(), section.getInt("Power", 1), (ArrayList<String>) section.getList("Colors", new ArrayList<String>()), (ArrayList<String>) section.getList("FadeOutColor", new ArrayList<String>()), section.getBoolean("Trail"), section.getBoolean("Flicker"), (ArrayList<String>) section.getList("Types", new ArrayList<String>()));
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder("FIREWORK_ROCKET"), new EditGUIValueInventory("Firework") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditFirework() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Configure firework effect"))));
injectedRewards.add(new RewardInjectConfigurationSection("Item") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
ItemBuilder builder = new ItemBuilder(section);
builder.setCheckLoreLength(false);
user.giveItem(builder);
return null;
}
}.validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
String material = data.getString("Item.Material", "");
if (material.isEmpty()) {
warning(reward, inject, "No material is set on item");
} else {
try {
Material m = Material.matchMaterial(material.toUpperCase());
// change legacy item
if (m == null) {
m = Material.matchMaterial(material, true);
if (material != null) {
warning(reward, inject, "Found legacy material: " + material + ", please update material");
}
}
} catch (NoSuchMethodError e) {
}
}
}
}));
injectedRewards.add(new RewardInjectConfigurationSection("AdvancedPriority") {
@Override
public String onRewardRequested(Reward reward1, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
for (String keys : section.getKeys(false)) {
Reward reward = RewardHandler.getInstance().getReward(section, keys, new RewardOptions());
if (reward != null && reward.canGiveReward(user, new RewardOptions())) {
plugin.extraDebug("AdvancedPriority: Giving reward " + reward.getName());
reward.giveReward(user, new RewardOptions().withPlaceHolder(placeholders).setIgnoreChance(true).setIgnoreRequirements(true).setPrefix(reward1.getName() + "_AdvancedPriority"));
return reward.getName();
} else {
plugin.extraDebug("AdvancedPriority: Can't give reward " + keys);
}
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueInventory("AdvancedPriority") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditAdvancedPriority() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("AdvancedPriority will run first sub reward that it can, then ignore the rest of the sub rewards").addLore("Can be used for permission based rewards or chance based rewards"))).priority(10).postReward());
injectedRewards.add(new RewardInjectConfigurationSection("AdvancedWorld") {
@Override
public String onRewardRequested(Reward reward1, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
for (String keys : section.getKeys(false)) {
plugin.extraDebug("AdvancedWorld: Giving reward " + reward1.getName() + "_AdvancedWorld");
section.set(keys + ".Worlds", ArrayUtils.getInstance().convert(new String[] { keys }));
giveReward(user, section, keys, new RewardOptions().withPlaceHolder(placeholders).setPrefix(reward1.getName() + "_AdvancedWorld"));
}
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueInventory("AdvancedWorld") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditAdvancedWorld() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("AdvancedReward will run rewards based worlds specified"))).priority(10).postReward());
injectedRewards.add(new RewardInjectConfigurationSection("SpecialChance") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
double totalChance = 0;
LinkedHashMap<Double, String> map = new LinkedHashMap<Double, String>();
for (String key : section.getKeys(false)) {
String path = key;
key = key.replaceAll("_", ".");
if (StringParser.getInstance().isDouble(key)) {
double chance = Double.valueOf(key);
totalChance += chance;
map.put(chance, path);
}
}
Set<Entry<Double, String>> copy = new HashSet<Entry<Double, String>>(map.entrySet());
double currentNum = 0;
map.clear();
for (Entry<Double, String> entry : copy) {
currentNum += entry.getKey();
map.put(currentNum, entry.getValue());
}
double randomNum = ThreadLocalRandom.current().nextDouble(totalChance);
for (Entry<Double, String> entry : map.entrySet()) {
if (randomNum <= entry.getKey()) {
new RewardBuilder(section, entry.getValue()).withPrefix(reward.getName()).withPlaceHolder(placeholders).withPlaceHolder("chance", "" + entry.getKey()).send(user);
AdvancedCorePlugin.getInstance().debug("Giving special chance: " + entry.getValue() + ", Random numuber: " + randomNum + ", Total chance: " + totalChance);
return null;
}
}
AdvancedCorePlugin.getInstance().debug("Failed to give special chance");
return null;
}
}.addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueInventory("SpecialChance") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditSpecialChance() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Rewards based on chance"))).priority(10).postReward());
injectedRewards.add(new RewardInjectKeys("RandomItem") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, Set<String> section, ConfigurationSection data, HashMap<String, String> placeholders) {
if (section.size() > 0) {
String item = ArrayUtils.getInstance().pickRandom(ArrayUtils.getInstance().convert(section));
ItemBuilder builder = new ItemBuilder(data.getConfigurationSection(item));
builder.setCheckLoreLength(false);
user.giveItem(builder);
return item;
}
return null;
}
}.asPlaceholder("RandomItem").priority(90).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
for (String item : data.getConfigurationSection("RandomItem").getKeys(false)) {
String material = data.getString("RandomItem." + item + ".Material", "");
if (material.isEmpty()) {
warning(reward, inject, "No material is set on item: " + item);
} else {
try {
Material m = Material.matchMaterial(material.toUpperCase());
// change legacy item
if (m == null) {
m = Material.matchMaterial(material.toUpperCase(), true);
if (material != null) {
warning(reward, inject, "Found legacy material: " + material + ", please update material on RandomItem." + item);
}
}
} catch (NoSuchMethodError e) {
}
}
}
}
}));
injectedRewards.add(new RewardInjectBoolean("EnableChoices") {
@Override
public String onRewardRequest(Reward reward, AdvancedCoreUser user, boolean value, HashMap<String, String> placeholders) {
if (value) {
debug("Checking choice rewards");
reward.checkRewardFile();
String choice = user.getChoicePreference(reward.getName());
if (choice.isEmpty() || choice.equalsIgnoreCase("none")) {
debug("No choice specified");
user.addUnClaimedChoiceReward(reward.getName());
} else {
giveChoicesReward(reward, user, choice);
}
}
return null;
}
}.priority(10).synchronize().validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.getBoolean("EnableChoices")) {
if (data.getConfigurationSection("Choices").getKeys(false).size() <= 1) {
warning(reward, inject, "Not enough choices for choice rewards, 1 or less is not a choice");
}
}
}
}.addPath("Choices")).addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueInventory("Choices") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditChoices() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addCheckKey("EnableChoices").addLore("Give users a choice on the reward"))));
injectedRewards.add(new RewardInjectKeys("Items") {
@Override
public String onRewardRequested(Reward reward, AdvancedCoreUser user, Set<String> section, ConfigurationSection data, HashMap<String, String> placeholders) {
boolean oneChance = reward.getConfig().getConfigData().getBoolean("OnlyOneItemChance", false);
if (section.size() > 0) {
for (String str : section) {
ItemBuilder builder = new ItemBuilder(data.getConfigurationSection(str));
builder.setCheckLoreLength(false);
user.giveItem(builder.setPlaceholders(placeholders));
debug("Giving item " + str + ":" + builder.toString());
if (builder.isChancePass() && oneChance) {
return str;
}
}
}
return "";
}
}.priority(90).asPlaceholder("Item").validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.isConfigurationSection("Items")) {
for (String item : data.getConfigurationSection("Items").getKeys(false)) {
String material = data.getString("Items." + item + ".Material", "");
if (material.isEmpty()) {
try {
Material.valueOf(item);
} catch (Exception e) {
warning(reward, inject, "No material is set on item: " + item);
}
} else {
try {
Material m = Material.matchMaterial(material.toUpperCase());
// check legacy
if (m == null) {
m = Material.matchMaterial(material, true);
if (m != null) {
warning(reward, inject, "Found legacy material: " + material + ", please update material");
} else {
warning(reward, inject, "Invalid material set: " + material);
}
}
} catch (NoSuchMethodError e) {
}
}
if (data.getInt("Items." + item + ".Amount", 0) == 0) {
if (data.getInt("Items." + item + ".MinAmount", 0) == 0 && data.getInt("Items." + item + ".MaxAmount") == 0) {
warning(reward, inject, "No amount on item: " + item);
}
}
}
} else {
warning(reward, inject, "Invalid item section");
}
}
}.addPath("OnlyOneItemChance")).addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueInventory("Items") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
new RewardEditItems() {
@Override
public void setVal(String key, Object value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue(key, value);
plugin.reloadAdvancedCore(false);
}
}.open(clickEvent.getPlayer(), reward);
}
}.addLore("Edit items"))));
for (RewardInject reward : injectedRewards) {
reward.setInternalReward(true);
}
sortInjectedRewards();
}
Aggregations