Skip to content

Commit

Permalink
add causingPlayer to McMMOReplaceVanillaTreasureEvent and update Fish…
Browse files Browse the repository at this point in the history
… Event to use it (mcMMO-Dev#5104)

* add causingPlayer to McMMOReplaceVanillaTreasureEvent and update Fishing Event to use it

* make requested changes

---------

Co-authored-by: Jacob Cuomo <[email protected]>
  • Loading branch information
bobcat4848 and Jacob Cuomo authored Oct 25, 2024
1 parent 8087d5f commit 571013c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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 **/
Expand All @@ -31,6 +39,10 @@ public McMMOReplaceVanillaTreasureEvent(@NotNull Item originalItem, @NotNull Ite
return replacementItemStack;
}

public @Nullable Player getCausingPlayer() {
return causingPlayer;
}

public void setReplacementItemStack(@NotNull ItemStack replacementItemStack) {
this.replacementItemStack = replacementItemStack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public void onPlayerFishHighest(PlayerFishEvent event) {

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
Expand Down

0 comments on commit 571013c

Please sign in to comment.