Skip to content

Commit

Permalink
Added on-drop commands
Browse files Browse the repository at this point in the history
  • Loading branch information
RockinChaos committed Mar 16, 2024
1 parent 39af3a3 commit 6137712
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ public enum Action {
ON_HIT(".on-hit", "ON_HIT", "HIT"),
ON_FIRE(".on-fire", "ON_FIRE", "FIRE"),
ON_CONSUME(".on-consume", "ON_CONSUME", "CONSUME"),
ON_DROP(".on-drop", "ON_DROP", "DROP"),
ON_RECEIVE(".on-receive", "ON_RECEIVE", "RECEIVED"),
PHYSICAL(".physical", "PHYSICAL", "INTERACTED");

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/me/RockinChaos/itemjoin/item/ItemMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -5695,6 +5695,7 @@ private void parseData_2(final FileConfiguration itemData) {
Map<String, List<String>> onHit = new HashMap<>();
Map<String, List<String>> onFire = new HashMap<>();
Map<String, List<String>> onConsume = new HashMap<>();
Map<String, List<String>> onDrop = new HashMap<>();
Map<String, List<String>> onReceive = new HashMap<>();
Map<String, List<String>> physical = new HashMap<>();
for (ItemCommand command : this.commands) {
Expand Down Expand Up @@ -5750,6 +5751,8 @@ private void parseData_2(final FileConfiguration itemData) {
onFire = this.addMapCommand(onFire, command);
} else if (command.matchAction(ItemCommand.Action.ON_CONSUME)) {
onConsume = this.addMapCommand(onConsume, command);
} else if (command.matchAction(ItemCommand.Action.ON_DROP)) {
onDrop = this.addMapCommand(onDrop, command);
} else if (command.matchAction(ItemCommand.Action.ON_RECEIVE)) {
onReceive = this.addMapCommand(onReceive, command);
} else if (command.matchAction(ItemCommand.Action.PHYSICAL)) {
Expand Down Expand Up @@ -5836,6 +5839,9 @@ private void parseData_2(final FileConfiguration itemData) {
if (!onConsume.isEmpty()) {
this.setMapCommand(itemData, onConsume, "on-consume");
}
if (!onDrop.isEmpty()) {
this.setMapCommand(itemData, onDrop, "on-drop");
}
if (!onReceive.isEmpty()) {
this.setMapCommand(itemData, onReceive, "on-receive");
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/me/RockinChaos/itemjoin/listeners/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ private void onDeath(PlayerDeathEvent event) {
}
}

/**
* Runs the on_drops commands for the custom item upon item drop.
*
* @param event - PlayerDropItemEvent.
*/
@EventHandler(priority = EventPriority.LOW)
private void onDrop(PlayerDropItemEvent event) {
final ItemStack item = event.getItemDrop().getItemStack();
this.runCommands(event.getPlayer(), null, item, "ON_DROP", "DROP", String.valueOf(event.getPlayer().getInventory().getHeldItemSlot()));
}

/**
* Runs the on_consume commands for the custom item upon item consumption.
*
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/me/RockinChaos/itemjoin/utils/menus/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3630,8 +3630,9 @@ private static void actionPane(final Player player, final ItemMap itemMap) {
listCommands(itemMap, Action.ON_HOLD)), event -> commandListPane(player, itemMap, Action.ON_HOLD)));
clickPane.addButton(new Button(ItemHandler.getItem("ARROW", 1, false, false, "&e&lOn-Fire", "&7", "&7*Commands that will execute only", "&7when an arrow or bow is fired.", "&7", "&9&lCommands: &a" +
listCommands(itemMap, Action.ON_FIRE)), event -> commandListPane(player, itemMap, Action.ON_FIRE)));
clickPane.addButton(new Button(fillerPaneGItem));
clickPane.addButton(new Button(ItemHandler.getItem("POTION", 1, false, false, "&e&lOn-Consume", "&7", "&7*Commands that will execute only", "&7when you consume an the item.", "&7", "&9&lCommands: &a" +
clickPane.addButton(new Button(ItemHandler.getItem("HOPPER", 1, false, false, "&e&lOn-Drop", "&7", "&7*Commands that will execute only", "&7when you drop the item.", "&7", "&9&lCommands: &a" +
listCommands(itemMap, Action.ON_DROP)), event -> commandListPane(player, itemMap, Action.ON_DROP)));
clickPane.addButton(new Button(ItemHandler.getItem("POTION", 1, false, false, "&e&lOn-Consume", "&7", "&7*Commands that will execute only", "&7when you consume the item.", "&7", "&9&lCommands: &a" +
listCommands(itemMap, Action.ON_CONSUME)), event -> commandListPane(player, itemMap, Action.ON_CONSUME)));
clickPane.addButton(new Button(ItemHandler.getItem("EMERALD", 1, false, false, "&e&lOn-Receive", "&7", "&7*Commands that will execute only", "&7when you are given the item.", "&7", "&9&lCommands: &a" +
listCommands(itemMap, Action.ON_RECEIVE)), event -> commandListPane(player, itemMap, Action.ON_RECEIVE)));
Expand Down Expand Up @@ -6902,7 +6903,8 @@ private static void commandActionPane(final Player player, final ItemMap itemMap
"&7", "&9&lENABLED: &a" + (!StringUtils.nullCheck(itemMap.getCommandConditions().get(Action.ON_HOLD.config()) + "").equals("NONE") ? "YES" : "NO")), event -> commandCPane(player, itemMap, Action.ON_HOLD)));
commandPane.addButton(new Button(ItemHandler.getItem("ARROW", 1, false, false, "&e&lOn-Fire", "&7", "&7*Condition(s) that must be met", "&7in order to execute item commands.",
"&7", "&9&lENABLED: &a" + (!StringUtils.nullCheck(itemMap.getCommandConditions().get(Action.ON_FIRE.config()) + "").equals("NONE") ? "YES" : "NO")), event -> commandCPane(player, itemMap, Action.ON_FIRE)));
commandPane.addButton(new Button(fillerPaneGItem));
commandPane.addButton(new Button(ItemHandler.getItem("HOPPER", 1, false, false, "&e&lOn-Drop", "&7", "&7*Condition(s) that must be met", "&7in order to execute item commands.",
"&7", "&9&lENABLED: &a" + (!StringUtils.nullCheck(itemMap.getCommandConditions().get(Action.ON_DROP.config()) + "").equals("NONE") ? "YES" : "NO")), event -> commandCPane(player, itemMap, Action.ON_DROP)));
commandPane.addButton(new Button(ItemHandler.getItem("POTION", 1, false, false, "&e&lOn-Consume", "&7", "&7*Condition(s) that must be met", "&7in order to execute item commands.",
"&7", "&9&lENABLED: &a" + (!StringUtils.nullCheck(itemMap.getCommandConditions().get(Action.ON_CONSUME.config()) + "").equals("NONE") ? "YES" : "NO")), event -> commandCPane(player, itemMap, Action.ON_CONSUME)));
commandPane.addButton(new Button(ItemHandler.getItem("EMERALD", 1, false, false, "&e&lOn-Receive", "&7", "&7*Condition(s) that must be met", "&7in order to execute item commands.",
Expand Down

0 comments on commit 6137712

Please sign in to comment.