Paper/patches/server/0593-Added-PlayerLoomPatternSelectEvent.patch

35 lines
1.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 25 Nov 2020 16:33:27 -0800
Subject: [PATCH] Added PlayerLoomPatternSelectEvent
diff --git a/src/main/java/net/minecraft/world/inventory/LoomMenu.java b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
index 9bcab01324612a905b21623a09109d404f8dadf7..fbe481faa504e9504bde5ed7b5098eaf847f647a 100644
--- a/src/main/java/net/minecraft/world/inventory/LoomMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
@@ -166,7 +166,22 @@ public class LoomMenu extends AbstractContainerMenu {
@Override
public boolean clickMenuButton(net.minecraft.world.entity.player.Player player, int id) {
if (id > 0 && id <= BannerPattern.AVAILABLE_PATTERNS) {
- this.selectedBannerPatternIndex.set(id);
+ // Paper start
+ int enumBannerPatternTypeOrdinal = id;
+ io.papermc.paper.event.player.PlayerLoomPatternSelectEvent event = new io.papermc.paper.event.player.PlayerLoomPatternSelectEvent((Player) player.getBukkitEntity(), ((CraftInventoryLoom) getBukkitView().getTopInventory()), org.bukkit.block.banner.PatternType.getByIdentifier(BannerPattern.values()[id].getHashname()));
+ if (!event.callEvent()) {
+ ((Player) player.getBukkitEntity()).updateInventory();
+ return false;
+ }
+ for (BannerPattern nms : BannerPattern.values()) {
+ if (event.getPatternType().getIdentifier().equals(nms.getHashname())) {
+ enumBannerPatternTypeOrdinal = nms.ordinal();
+ break;
+ }
+ }
+ ((Player) player.getBukkitEntity()).updateInventory();
+ this.selectedBannerPatternIndex.set(enumBannerPatternTypeOrdinal);
+ // Paper end
this.setupResultSlot();
return true;
} else {