From 571013cf559ab19d0849ec078667d509958a39d9 Mon Sep 17 00:00:00 2001 From: Jacob Date: Fri, 25 Oct 2024 16:00:37 -0400 Subject: [PATCH] add causingPlayer to McMMOReplaceVanillaTreasureEvent and update Fish Event to use it (#5104) * add causingPlayer to McMMOReplaceVanillaTreasureEvent and update Fishing Event to use it * make requested changes --------- Co-authored-by: Jacob Cuomo --- .../events/McMMOReplaceVanillaTreasureEvent.java | 12 ++++++++++++ .../com/gmail/nossr50/listeners/PlayerListener.java | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/events/McMMOReplaceVanillaTreasureEvent.java b/src/main/java/com/gmail/nossr50/events/McMMOReplaceVanillaTreasureEvent.java index 6553bf1c1..dfbbe7348 100644 --- a/src/main/java/com/gmail/nossr50/events/McMMOReplaceVanillaTreasureEvent.java +++ b/src/main/java/com/gmail/nossr50/events/McMMOReplaceVanillaTreasureEvent.java @@ -1,18 +1,26 @@ package com.gmail.nossr50.events; import org.bukkit.entity.Item; +import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class McMMOReplaceVanillaTreasureEvent extends Event { private @NotNull ItemStack replacementItemStack; private final @NotNull Item originalItem; + private final @Nullable Player causingPlayer; public McMMOReplaceVanillaTreasureEvent(@NotNull Item originalItem, @NotNull ItemStack replacementItemStack) { + this(originalItem, replacementItemStack, null); + } + + public McMMOReplaceVanillaTreasureEvent(@NotNull Item originalItem, @NotNull ItemStack replacementItemStack, @Nullable Player causingPlayer) { this.originalItem = originalItem; this.replacementItemStack = replacementItemStack; + this.causingPlayer = causingPlayer; } /** Rest of file is required boilerplate for custom events **/ @@ -31,6 +39,10 @@ public class McMMOReplaceVanillaTreasureEvent extends Event { return replacementItemStack; } + public @Nullable Player getCausingPlayer() { + return causingPlayer; + } + public void setReplacementItemStack(@NotNull ItemStack replacementItemStack) { this.replacementItemStack = replacementItemStack; } diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 74f262289..e76696ae7 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -312,7 +312,7 @@ public class PlayerListener implements Listener { ItemStack replacementCatch = new ItemStack(Material.SALMON, 1); - McMMOReplaceVanillaTreasureEvent replaceVanillaTreasureEvent = new McMMOReplaceVanillaTreasureEvent(fishingCatch, replacementCatch); + McMMOReplaceVanillaTreasureEvent replaceVanillaTreasureEvent = new McMMOReplaceVanillaTreasureEvent(fishingCatch, replacementCatch, player); Bukkit.getPluginManager().callEvent(replaceVanillaTreasureEvent); //Replace