Skip to content

Commit

Permalink
add success commands
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXiaoM committed Aug 17, 2024
1 parent ddd8add commit 98aa1a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/think/rpgitems/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,7 @@ public void onStoneApply(InventoryClickEvent e) {
Utils.runCommands(player, stone.getFailCommands());
return;
}
Utils.runCommands(player, stone.getSuccessCommands());
player.sendMessage(I18n.getFormatted(player, "message.stone.rate.success"));
map.put(stone, trigger);
ItemManager.fromRPGStoneList(item, map);
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/think/rpgitems/item/RPGStone.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class RPGStone implements RPGBaseHolder {
@Getter @Setter private List<String> allowTriggersArmour = new ArrayList<>();

@Getter @Setter private double successRate = 1;
@Getter @Setter private List<String> successCommands = new ArrayList<>();
@Getter @Setter private List<String> failCommands = new ArrayList<>(); // TODO: Allow users to edit them in StoneCommands

@Getter @Setter private String author = plugin.cfg.defaultAuthor;
Expand Down Expand Up @@ -131,6 +132,7 @@ private void restore(ConfigurationSection s) throws UnknownPowerException {

String display = s.getString("display");
setDisplayName(display);
setCustomItemModel(s.getBoolean("customItemModel", false));
setCustomModelData(s.getInt("customModelData", -1));
String materialName = s.getString("item");
setItem(MaterialUtils.getMaterial(materialName, Bukkit.getConsoleSender()));
Expand All @@ -147,6 +149,7 @@ private void restore(ConfigurationSection s) throws UnknownPowerException {
setAllowTriggersArmour(s.getStringList("allowTriggersArmour"));

setSuccessRate(s.getDouble("successRate"));
setSuccessCommands(s.getStringList("successCommands"));
setFailCommands(s.getStringList("failCommands"));

// Powers
Expand Down Expand Up @@ -194,12 +197,14 @@ public void save(ConfigurationSection s) {
s.set("extraDescription", descriptionConv);

s.set("item", getItem().toString());
s.set("customItemModel", isCustomItemModel());
s.set("customModelData", getCustomModelData());

s.set("allowTriggers", getAllowTriggers());
s.set("allowTriggersArmour", getAllowTriggersArmour());

s.set("successRate", getSuccessRate());
s.set("successCommands", getSuccessCommands());
s.set("failCommands", getFailCommands());

ConfigurationSection powerConfigs = s.createSection("powers");
Expand Down Expand Up @@ -343,7 +348,9 @@ public void updateItem(ItemStack item, boolean loreOnly) {
return;
}

meta.setCustomModelData(getCustomModelData());
if (isCustomItemModel()) {
meta.setCustomModelData(getCustomModelData());
}
rpgitemsTagContainer.commit();
item.setItemMeta(meta);

Expand Down

0 comments on commit 98aa1a9

Please sign in to comment.