3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 20:40:07 +01:00

Implement PlayerRecipeDiscoverEvent and methods to (un/)discover recipes

Dieser Commit ist enthalten in:
Parker Hawke 2018-09-29 19:24:51 -04:00 committet von md_5
Ursprung 1cf8b5dc1b
Commit 7a2f486768
3 geänderte Dateien mit 67 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -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);

Datei anzeigen

@ -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()) {

Datei anzeigen

@ -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();
}
}