当前位置: 首页>>代码示例>>Java>>正文


Java MerchantRecipe类代码示例

本文整理汇总了Java中org.bukkit.inventory.MerchantRecipe的典型用法代码示例。如果您正苦于以下问题:Java MerchantRecipe类的具体用法?Java MerchantRecipe怎么用?Java MerchantRecipe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MerchantRecipe类属于org.bukkit.inventory包,在下文中一共展示了MerchantRecipe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toString

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
/**
 * Returns a String representation of a MerchantRecipe. Spaces are used as
 * delimeters between attributes. Utilizes
 * {@link ItemStackConverter ItemStackConverter} for the ItemStacks.
 * </b>
 * @param merchantRecipe - The MerchantRecipe to stringify.
 * @return A String that can be stored and passed in to
 * {@link #fromString(String) fromString(String)} later.
 * @throws IllegalArgumentException If MerchantRecipe is null.
 */
public static String toString(MerchantRecipe merchantRecipe) throws IllegalArgumentException {
    if (merchantRecipe == null) {
        throw new IllegalArgumentException("Cannot stringify a null MerchantRecipe!");
    }
    
    String ret = new String();
    ret += ItemStackConverter.toString(merchantRecipe.getResult()) + " ";
    
    for (ItemStack itemStack : merchantRecipe.getIngredients()) {
        ret += ItemStackConverter.toString(itemStack) + ",";
    }
    
    ret += " " + merchantRecipe.getUses();
    ret += " " + merchantRecipe.getMaxUses();
    ret += " " + merchantRecipe.hasExperienceReward();
    return ret;
}
 
开发者ID:RedPanda4552,项目名称:SimpleEgg,代码行数:28,代码来源:MerchantRecipeConverter.java

示例2: fromString

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
/**
 * Takes in a String produced by
 * {@link #toString(MerchantRecipe) toString(MerchantRecipe)} and converts
 * it to a MerchantRecipe.
 * @param string - The String to convert.
 * @return A MerchantRecipe with the attributes specified in the String.
 * @throws IllegalArgumentException If the String has an unexpected number
 * of attributes.
 */
public static MerchantRecipe fromString(String string) throws IllegalArgumentException {
    String[] attributes = string.split(" ");
    
    if (attributes.length != 5) {
        throw new IllegalArgumentException("Input string has an unexpected number of attributes!");
    }
    
    String resultString = attributes[0], ingredientString = attributes[1], usesString = attributes[2], maxUsesString = attributes[3], experienceString = attributes[4];
    
    ItemStack result = itemStackListFromString(resultString).get(0);
    ArrayList<ItemStack> ingredients = itemStackListFromString(ingredientString);
    int uses = Integer.parseInt(usesString);
    int maxUses = Integer.parseInt(maxUsesString);
    boolean experience = Boolean.parseBoolean(experienceString);
    MerchantRecipe ret = new MerchantRecipe(result, uses, maxUses, experience);
    ret.setIngredients(ingredients);
    return ret;
}
 
开发者ID:RedPanda4552,项目名称:SimpleEgg,代码行数:28,代码来源:MerchantRecipeConverter.java

示例3: openTradeWindow

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
@Override
public boolean openTradeWindow(String title, List<ItemStack[]> recipes, Player player) {
	// create empty merchant:
	Merchant merchant = Bukkit.createMerchant(title);

	// create list of merchant recipes:
	List<MerchantRecipe> merchantRecipes = new ArrayList<MerchantRecipe>();
	for (ItemStack[] recipe : recipes) {
		// skip invalid recipes:
		if (recipe == null || recipe.length != 3 || Utils.isEmpty(recipe[0]) || Utils.isEmpty(recipe[2])) {
			continue;
		}

		// create and add merchant recipe:
		merchantRecipes.add(this.createMerchantRecipe(recipe[0], recipe[1], recipe[2]));
	}

	// set merchant's recipes:
	merchant.setRecipes(merchantRecipes);

	// increase 'talked-to-villager' statistic:
	player.incrementStatistic(Statistic.TALKED_TO_VILLAGER);

	// open merchant:
	return player.openMerchant(merchant, true) != null;
}
 
开发者ID:nisovin,项目名称:Shopkeepers,代码行数:27,代码来源:NMSHandler.java

示例4: getUsedTradingRecipe

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
@Override
public ItemStack[] getUsedTradingRecipe(MerchantInventory merchantInventory) {
	MerchantRecipe merchantRecipe = merchantInventory.getSelectedRecipe();
	List<ItemStack> ingredients = merchantRecipe.getIngredients();
	ItemStack[] recipe = new ItemStack[3];
	recipe[0] = ingredients.get(0);
	recipe[1] = null;
	if (ingredients.size() > 1) {
		ItemStack buyItem2 = ingredients.get(1);
		if (!Utils.isEmpty(buyItem2)) {
			recipe[1] = buyItem2;
		}
	}
	recipe[2] = merchantRecipe.getResult();
	return recipe;
}
 
开发者ID:nisovin,项目名称:Shopkeepers,代码行数:17,代码来源:NMSHandler.java

示例5: getRecipes

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
@Override
public List<MerchantRecipe> getRecipes() {
    return Collections.unmodifiableList(Lists.transform(getHandle().getOffers(null), new Function<net.minecraft.server.MerchantRecipe, MerchantRecipe>() {
        @Override
        public MerchantRecipe apply(net.minecraft.server.MerchantRecipe recipe) {
            return recipe.asBukkit();
        }
    }));
}
 
开发者ID:bergerkiller,项目名称:SpigotSource,代码行数:10,代码来源:CraftVillager.java

示例6: setRecipes

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
@Override
public void setRecipes(List<MerchantRecipe> list) {
    MerchantRecipeList recipes = getHandle().getOffers(null);
    recipes.clear();
    for (MerchantRecipe m : list) {
        recipes.add(CraftMerchantRecipe.fromBukkit(m).toMinecraft());
    }
}
 
开发者ID:bergerkiller,项目名称:SpigotSource,代码行数:9,代码来源:CraftVillager.java

示例7: CraftMerchantRecipe

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward) {
    super(result, uses, maxUses, experienceReward);
    this.handle = new net.minecraft.server.MerchantRecipe(
            null,
            null,
            CraftItemStack.asNMSCopy(result),
            uses,
            maxUses,
            this
    );
}
 
开发者ID:bergerkiller,项目名称:SpigotSource,代码行数:12,代码来源:CraftMerchantRecipe.java

示例8: toMinecraft

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
public net.minecraft.server.MerchantRecipe toMinecraft() {
    List<ItemStack> ingredients = getIngredients();
    Preconditions.checkState(!ingredients.isEmpty(), "No offered ingredients");
    handle.buyingItem1 = CraftItemStack.asNMSCopy(ingredients.get(0));
    if (ingredients.size() > 1) {
        handle.buyingItem2 = CraftItemStack.asNMSCopy(ingredients.get(1));
    }
    return handle;
}
 
开发者ID:bergerkiller,项目名称:SpigotSource,代码行数:10,代码来源:CraftMerchantRecipe.java

示例9: fromBukkit

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
public static CraftMerchantRecipe fromBukkit(MerchantRecipe recipe) {
    if (recipe instanceof CraftMerchantRecipe) {
        return (CraftMerchantRecipe) recipe;
    } else {
        CraftMerchantRecipe craft = new CraftMerchantRecipe(recipe.getResult(), recipe.getUses(), recipe.getMaxUses(), recipe.hasExperienceReward());
        craft.setIngredients(recipe.getIngredients());

        return craft;
    }
}
 
开发者ID:bergerkiller,项目名称:SpigotSource,代码行数:11,代码来源:CraftMerchantRecipe.java

示例10: createMerchantRecipe

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
private MerchantRecipe createMerchantRecipe(ItemStack buyItem1, ItemStack buyItem2, ItemStack sellingItem) {
	assert !Utils.isEmpty(sellingItem) && !Utils.isEmpty(buyItem1);
	MerchantRecipe recipe = new MerchantRecipe(sellingItem, 10000); // no max-uses limit
	recipe.setExperienceReward(false); // no experience rewards
	recipe.addIngredient(buyItem1);
	if (!Utils.isEmpty(buyItem2)) {
		recipe.addIngredient(buyItem2);
	}
	return recipe;
}
 
开发者ID:nisovin,项目名称:Shopkeepers,代码行数:11,代码来源:NMSHandler.java

示例11: stringToRecipe

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
public static List<MerchantRecipe> stringToRecipe(String s){
    List<MerchantRecipe> recipes = new ArrayList<>();
    List<String> recipe = Arrays.asList(s.replace("[", "").replace("]", "").split(","));

    return recipes;
}
 
开发者ID:cadox8,项目名称:WC,代码行数:7,代码来源:MerchantUtils.java

示例12: getRecipes

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
public MerchantRecipe[] getRecipes(){
    Villager v;
    if (!mu.isVillager(entity)) return null;
    v = (Villager)entity;
    return v.getRecipes().toArray(new MerchantRecipe[v.getRecipes().size()]);
}
 
开发者ID:cadox8,项目名称:WC,代码行数:7,代码来源:SNMob.java

示例13: getRecipes

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
public List<MerchantRecipe> getRecipes() {
    if (entity instanceof Villager) {
        return ((Villager)entity).getRecipes();
    }
    return new ArrayList<>();
}
 
开发者ID:GameBoxx,项目名称:GameBoxx,代码行数:7,代码来源:EEntity.java

示例14: setRecipes

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
public EEntity setRecipes(List<MerchantRecipe> recipes) {
    if (entity instanceof Villager) {
        ((Villager)entity).setRecipes(recipes);
    }
    return this;
}
 
开发者ID:GameBoxx,项目名称:GameBoxx,代码行数:7,代码来源:EEntity.java

示例15: getRecipe

import org.bukkit.inventory.MerchantRecipe; //导入依赖的package包/类
public MerchantRecipe getRecipe(int i) {
    if (entity instanceof Villager) {
        return ((Villager)entity).getRecipe(i);
    }
    return null;
}
 
开发者ID:GameBoxx,项目名称:GameBoxx,代码行数:7,代码来源:EEntity.java


注:本文中的org.bukkit.inventory.MerchantRecipe类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。