mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-03 09:19:38 +01:00
Implement PlayerRecipeDiscoverEvent and methods to (un/)discover recipes
This commit is contained in:
parent
1cf8b5dc1b
commit
7a2f486768
19
nms-patches/RecipeBookServer.patch
Normal file
19
nms-patches/RecipeBookServer.patch
Normal file
@ -0,0 +1,19 @@
|
||||
--- a/net/minecraft/server/RecipeBookServer.java
|
||||
+++ b/net/minecraft/server/RecipeBookServer.java
|
||||
@@ -8,6 +8,7 @@
|
||||
import java.util.List;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
|
||||
|
||||
public class RecipeBookServer extends RecipeBook {
|
||||
|
||||
@@ -27,7 +28,7 @@
|
||||
IRecipe irecipe = (IRecipe) iterator.next();
|
||||
MinecraftKey minecraftkey = irecipe.getKey();
|
||||
|
||||
- if (!this.a.contains(minecraftkey) && !irecipe.c()) {
|
||||
+ if (!this.a.contains(minecraftkey) && !irecipe.c() && CraftEventFactory.handlePlayerRecipeListUpdateEvent(entityplayer, minecraftkey)) { // CraftBukkit
|
||||
this.a(minecraftkey);
|
||||
this.c(minecraftkey);
|
||||
arraylist.add(minecraftkey);
|
@ -1,6 +1,9 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.server.*;
|
||||
@ -10,6 +13,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.inventory.MainHand;
|
||||
import org.bukkit.inventory.Merchant;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
@ -27,6 +31,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.inventory.CraftMerchant;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.permissions.PermissibleBase;
|
||||
import org.bukkit.permissions.Permission;
|
||||
@ -455,6 +460,42 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
getHandle().getCooldownTracker().a(CraftMagicNumbers.getItem(material), ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean discoverRecipe(NamespacedKey recipe) {
|
||||
return discoverRecipes(Arrays.asList(recipe)) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int discoverRecipes(Collection<NamespacedKey> recipes) {
|
||||
return getHandle().a(bukkitKeysToMinecraftRecipes(recipes)); // PAIL rename discoverRecipes
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean undiscoverRecipe(NamespacedKey recipe) {
|
||||
return undiscoverRecipes(Arrays.asList(recipe)) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int undiscoverRecipes(Collection<NamespacedKey> recipes) {
|
||||
return getHandle().b(bukkitKeysToMinecraftRecipes(recipes)); // PAIL rename undiscoverRecipes
|
||||
}
|
||||
|
||||
private Collection<IRecipe> bukkitKeysToMinecraftRecipes(Collection<NamespacedKey> recipeKeys) {
|
||||
Collection<IRecipe> recipes = new ArrayList<>();
|
||||
CraftingManager manager = getHandle().world.getMinecraftServer().getCraftingManager();
|
||||
|
||||
for (NamespacedKey recipeKey : recipeKeys) {
|
||||
IRecipe recipe = manager.a(CraftNamespacedKey.toMinecraft(recipeKey));
|
||||
if (recipe == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
return recipes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getShoulderEntityLeft() {
|
||||
if (!getHandle().getShoulderEntityLeft().isEmpty()) {
|
||||
|
@ -34,6 +34,7 @@ import org.bukkit.craftbukkit.inventory.CraftMetaBook;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
|
||||
import org.bukkit.craftbukkit.util.CraftDamageSource;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.AreaEffectCloud;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Bat;
|
||||
@ -1129,4 +1130,10 @@ public class CraftEventFactory {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return !event.isCancelled();
|
||||
}
|
||||
|
||||
public static boolean handlePlayerRecipeListUpdateEvent(EntityHuman who, MinecraftKey recipe) {
|
||||
PlayerRecipeDiscoverEvent event = new PlayerRecipeDiscoverEvent((Player) who.getBukkitEntity(), CraftNamespacedKey.fromMinecraft(recipe));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return !event.isCancelled();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user