summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit
diff options
context:
space:
mode:
authorParker Hawke <hawkeboyz2@hotmail.com>2018-09-29 19:24:51 -0400
committermd_5 <git@md-5.net>2018-10-01 19:15:12 +1000
commit7a2f486768afeb6a54c39b19079e9f31f3adad1a (patch)
tree27b9238669a7cc89fbb4719d977c66ab55410a14 /src/main/java/org/bukkit
parent1cf8b5dc1b55459f9a470860f820310294b48787 (diff)
downloadcraftbukkit-7a2f486768afeb6a54c39b19079e9f31f3adad1a.tar
craftbukkit-7a2f486768afeb6a54c39b19079e9f31f3adad1a.tar.gz
craftbukkit-7a2f486768afeb6a54c39b19079e9f31f3adad1a.tar.lz
craftbukkit-7a2f486768afeb6a54c39b19079e9f31f3adad1a.tar.xz
craftbukkit-7a2f486768afeb6a54c39b19079e9f31f3adad1a.zip
Implement PlayerRecipeDiscoverEvent and methods to (un/)discover recipes
Diffstat (limited to 'src/main/java/org/bukkit')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java41
-rw-r--r--src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java7
2 files changed, 48 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
index 289e267b..497783d4 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
@@ -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;
@@ -456,6 +461,42 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
}
@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()) {
Entity shoulder = EntityTypes.a(getHandle().getShoulderEntityLeft(), getHandle().world);
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index deb166d7..67d2eb1b 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -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();
+ }
}