geforkt von Mirrors/Paper
SPIGOT-7867: Merchant instanceof AbstractVillager always returns false
By: Miles Holder <mwholder2005@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
7657f347d2
Commit
ac5e815b3e
@ -1,6 +1,6 @@
|
||||
--- a/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
|
||||
+++ b/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
|
||||
@@ -40,8 +40,24 @@
|
||||
@@ -40,8 +40,22 @@
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@ -15,17 +15,15 @@
|
||||
public abstract class EntityVillagerAbstract extends EntityAgeable implements InventoryCarrier, NPC, IMerchant {
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ private CraftMerchant craftMerchant;
|
||||
+
|
||||
+ @Override
|
||||
+ public CraftMerchant getCraftMerchant() {
|
||||
+ return (craftMerchant == null) ? craftMerchant = new CraftMerchant(this) : craftMerchant;
|
||||
+ return (org.bukkit.craftbukkit.entity.CraftAbstractVillager) getBukkitEntity();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
private static final DataWatcherObject<Integer> DATA_UNHAPPY_COUNTER = DataWatcher.defineId(EntityVillagerAbstract.class, DataWatcherRegistry.INT);
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
public static final int VILLAGER_SLOT_OFFSET = 300;
|
||||
@@ -50,7 +66,7 @@
|
||||
@@ -50,7 +64,7 @@
|
||||
private EntityHuman tradingPlayer;
|
||||
@Nullable
|
||||
protected MerchantRecipeList offers;
|
||||
@ -34,7 +32,7 @@
|
||||
|
||||
public EntityVillagerAbstract(EntityTypes<? extends EntityVillagerAbstract> entitytypes, World world) {
|
||||
super(entitytypes, world);
|
||||
@@ -179,7 +195,7 @@
|
||||
@@ -179,7 +193,7 @@
|
||||
public void readAdditionalSaveData(NBTTagCompound nbttagcompound) {
|
||||
super.readAdditionalSaveData(nbttagcompound);
|
||||
if (nbttagcompound.contains("Offers")) {
|
||||
@ -43,7 +41,7 @@
|
||||
Logger logger = EntityVillagerAbstract.LOGGER;
|
||||
|
||||
Objects.requireNonNull(logger);
|
||||
@@ -246,7 +262,16 @@
|
||||
@@ -246,7 +260,16 @@
|
||||
MerchantRecipe merchantrecipe = ((VillagerTrades.IMerchantRecipeOption) arraylist.remove(this.random.nextInt(arraylist.size()))).getOffer(this, this.random);
|
||||
|
||||
if (merchantrecipe != null) {
|
||||
|
@ -1,18 +1,16 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.world.entity.npc.EntityVillager;
|
||||
import net.minecraft.world.entity.npc.EntityVillagerAbstract;
|
||||
import net.minecraft.world.item.trading.IMerchant;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftMerchant;
|
||||
import org.bukkit.entity.AbstractVillager;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
|
||||
public class CraftAbstractVillager extends CraftAgeable implements AbstractVillager, InventoryHolder {
|
||||
public class CraftAbstractVillager extends CraftAgeable implements CraftMerchant, AbstractVillager, InventoryHolder {
|
||||
|
||||
public CraftAbstractVillager(CraftServer server, EntityVillagerAbstract entity) {
|
||||
super(server, entity);
|
||||
@ -23,6 +21,11 @@ public class CraftAbstractVillager extends CraftAgeable implements AbstractVilla
|
||||
return (EntityVillager) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMerchant getMerchant() {
|
||||
return getHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftAbstractVillager";
|
||||
@ -32,43 +35,4 @@ public class CraftAbstractVillager extends CraftAgeable implements AbstractVilla
|
||||
public Inventory getInventory() {
|
||||
return new CraftInventory(getHandle().getInventory());
|
||||
}
|
||||
|
||||
private CraftMerchant getMerchant() {
|
||||
return getHandle().getCraftMerchant();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MerchantRecipe> getRecipes() {
|
||||
return getMerchant().getRecipes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipes(List<MerchantRecipe> recipes) {
|
||||
this.getMerchant().setRecipes(recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MerchantRecipe getRecipe(int i) {
|
||||
return getMerchant().getRecipe(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipe(int i, MerchantRecipe merchantRecipe) {
|
||||
getMerchant().setRecipe(i, merchantRecipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeCount() {
|
||||
return getMerchant().getRecipeCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTrading() {
|
||||
return getTrader() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HumanEntity getTrader() {
|
||||
return getMerchant().getTrader();
|
||||
}
|
||||
}
|
||||
|
@ -11,21 +11,13 @@ import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Merchant;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
|
||||
public class CraftMerchant implements Merchant {
|
||||
public interface CraftMerchant extends Merchant {
|
||||
|
||||
protected final IMerchant merchant;
|
||||
|
||||
public CraftMerchant(IMerchant merchant) {
|
||||
this.merchant = merchant;
|
||||
}
|
||||
|
||||
public IMerchant getMerchant() {
|
||||
return merchant;
|
||||
}
|
||||
IMerchant getMerchant();
|
||||
|
||||
@Override
|
||||
public List<MerchantRecipe> getRecipes() {
|
||||
return Collections.unmodifiableList(Lists.transform(merchant.getOffers(), new Function<net.minecraft.world.item.trading.MerchantRecipe, MerchantRecipe>() {
|
||||
default List<MerchantRecipe> getRecipes() {
|
||||
return Collections.unmodifiableList(Lists.transform(getMerchant().getOffers(), new Function<net.minecraft.world.item.trading.MerchantRecipe, MerchantRecipe>() {
|
||||
@Override
|
||||
public MerchantRecipe apply(net.minecraft.world.item.trading.MerchantRecipe recipe) {
|
||||
return recipe.asBukkit();
|
||||
@ -34,8 +26,8 @@ public class CraftMerchant implements Merchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipes(List<MerchantRecipe> recipes) {
|
||||
MerchantRecipeList recipesList = merchant.getOffers();
|
||||
default void setRecipes(List<MerchantRecipe> recipes) {
|
||||
MerchantRecipeList recipesList = getMerchant().getOffers();
|
||||
recipesList.clear();
|
||||
for (MerchantRecipe recipe : recipes) {
|
||||
recipesList.add(CraftMerchantRecipe.fromBukkit(recipe).toMinecraft());
|
||||
@ -43,38 +35,28 @@ public class CraftMerchant implements Merchant {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MerchantRecipe getRecipe(int i) {
|
||||
return merchant.getOffers().get(i).asBukkit();
|
||||
default MerchantRecipe getRecipe(int i) {
|
||||
return getMerchant().getOffers().get(i).asBukkit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipe(int i, MerchantRecipe merchantRecipe) {
|
||||
merchant.getOffers().set(i, CraftMerchantRecipe.fromBukkit(merchantRecipe).toMinecraft());
|
||||
default void setRecipe(int i, MerchantRecipe merchantRecipe) {
|
||||
getMerchant().getOffers().set(i, CraftMerchantRecipe.fromBukkit(merchantRecipe).toMinecraft());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeCount() {
|
||||
return merchant.getOffers().size();
|
||||
default int getRecipeCount() {
|
||||
return getMerchant().getOffers().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTrading() {
|
||||
default boolean isTrading() {
|
||||
return getTrader() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HumanEntity getTrader() {
|
||||
EntityHuman eh = merchant.getTradingPlayer();
|
||||
default HumanEntity getTrader() {
|
||||
EntityHuman eh = getMerchant().getTradingPlayer();
|
||||
return eh == null ? null : eh.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return merchant.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return obj instanceof CraftMerchant && ((CraftMerchant) obj).merchant.equals(this.merchant);
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,12 @@ import net.minecraft.world.item.trading.MerchantRecipe;
|
||||
import net.minecraft.world.item.trading.MerchantRecipeList;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
|
||||
public class CraftMerchantCustom extends CraftMerchant {
|
||||
public class CraftMerchantCustom implements CraftMerchant {
|
||||
|
||||
private MinecraftMerchant merchant;
|
||||
|
||||
public CraftMerchantCustom(String title) {
|
||||
super(new MinecraftMerchant(title));
|
||||
this.merchant = new MinecraftMerchant(title);
|
||||
getMerchant().craftMerchant = this;
|
||||
}
|
||||
|
||||
@ -25,7 +27,7 @@ public class CraftMerchantCustom extends CraftMerchant {
|
||||
|
||||
@Override
|
||||
public MinecraftMerchant getMerchant() {
|
||||
return (MinecraftMerchant) super.getMerchant();
|
||||
return this.merchant;
|
||||
}
|
||||
|
||||
public static class MinecraftMerchant implements IMerchant {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren