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 (#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

1 comment on commit 571013c

@IAISI
Copy link
Contributor

@IAISI IAISI commented on 571013c Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to cause...

com.destroystokyo.paper.exception.ServerEventException: Could not pass event BlockBreakEvent to mcMMO v2.2.023-SNAPSHOT
	at io.papermc.paper.plugin.manager.PaperEventManager.callEvent(PaperEventManager.java:71)
	at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent(PaperPluginManagerImpl.java:131)
	at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:628)
	at net.minecraft.server.level.ServerPlayerGameMode.destroyBlock(ServerPlayerGameMode.java:383)
	at net.minecraft.server.level.ServerPlayerGameMode.destroyAndAck(ServerPlayerGameMode.java:342)
	at net.minecraft.server.level.ServerPlayerGameMode.handleBlockBreakAction(ServerPlayerGameMode.java:306)
	at net.minecraft.server.network.ServerGamePacketListenerImpl.handlePlayerAction(ServerGamePacketListenerImpl.java:1856)
	at net.minecraft.network.protocol.game.ServerboundPlayerActionPacket.handle(ServerboundPlayerActionPacket.java:51)
	at net.minecraft.network.protocol.game.ServerboundPlayerActionPacket.handle(ServerboundPlayerActionPacket.java:20)
	at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$0(PacketUtils.java:55)
	at net.minecraft.server.TickTask.run(TickTask.java:18)
	at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:151)
	at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24)
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1538)
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:198)
	at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:125)
	at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1515)
	at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1508)
	at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:135)
	at net.minecraft.server.MinecraftServer.managedBlock(MinecraftServer.java:1468)
	at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1474)
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1320)
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:327)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.AbstractMethodError: Method com/gmail/nossr50/mcmmo/kyori/adventure/platform/bukkit/BukkitFacet$Chat.sendMessage(Ljava/lang/Object;Lcom/gmail/nossr50/mcmmo/kyori/adventure/identity/Identity;Ljava/lang/Object;Ljava/lang/Object;)V is abstract
	at mcMMO.jar//com.gmail.nossr50.mcmmo.kyori.adventure.platform.bukkit.BukkitFacet$Chat.sendMessage(BukkitFacet.java)
	at mcMMO.jar//com.gmail.nossr50.mcmmo.kyori.adventure.platform.facet.FacetAudience.sendMessage(FacetAudience.java:195)
	at mcMMO.jar//com.gmail.nossr50.mcmmo.kyori.adventure.audience.Audience.sendMessage(Audience.java:253)
	at mcMMO.jar//com.gmail.nossr50.mcmmo.kyori.adventure.audience.Audience.sendMessage(Audience.java:217)
	at mcMMO.jar//com.gmail.nossr50.util.player.NotificationManager.sendNotification(NotificationManager.java:126)
	at mcMMO.jar//com.gmail.nossr50.util.player.NotificationManager.sendPlayerLevelUpNotification(NotificationManager.java:169)
	at mcMMO.jar//com.gmail.nossr50.datatypes.player.McMMOPlayer.checkXp(McMMOPlayer.java:746)
	at mcMMO.jar//com.gmail.nossr50.datatypes.player.McMMOPlayer.applyXpGain(McMMOPlayer.java:704)
	at mcMMO.jar//com.gmail.nossr50.datatypes.player.McMMOPlayer.beginUnsharedXpGain(McMMOPlayer.java:663)
	at mcMMO.jar//com.gmail.nossr50.datatypes.player.McMMOPlayer.beginXpGain(McMMOPlayer.java:650)
	at mcMMO.jar//com.gmail.nossr50.skills.SkillManager.applyXpGain(SkillManager.java:36)
	at mcMMO.jar//com.gmail.nossr50.skills.woodcutting.WoodcuttingManager.processWoodcuttingBlockXP(WoodcuttingManager.java:129)
	at mcMMO.jar//com.gmail.nossr50.listeners.BlockListener.onBlockBreak(BlockListener.java:410)
	at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor581.execute(Unknown Source)
	at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:77)
	at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70)
	at io.papermc.paper.plugin.manager.PaperEventManager.callEvent(PaperEventManager.java:53)
	... 23 more

On paper 1.21.1

Please sign in to comment.