Search in sources :

Example 6 with MerchantRecipe

use of org.bukkit.inventory.MerchantRecipe in project Denizen-For-Bukkit by DenizenScript.

the class TradeResult method adjust.

public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("result") && mechanism.requireObject(ItemTag.class)) {
        ItemStack item = mechanism.valueAsType(ItemTag.class).getItemStack();
        MerchantRecipe oldRecipe = recipe.getRecipe();
        MerchantRecipe newRecipe = new MerchantRecipe(item, oldRecipe.getUses(), oldRecipe.getMaxUses(), oldRecipe.hasExperienceReward());
        newRecipe.setIngredients(oldRecipe.getIngredients());
        recipe.setRecipe(newRecipe);
    }
}
Also used : MerchantRecipe(org.bukkit.inventory.MerchantRecipe) ItemTag(com.denizenscript.denizen.objects.ItemTag) ItemStack(org.bukkit.inventory.ItemStack)

Example 7 with MerchantRecipe

use of org.bukkit.inventory.MerchantRecipe in project Denizen-For-Bukkit by DenizenScript.

the class OpenTradesCommand method execute.

public void execute(ScriptEntry scriptEntry) {
    ElementTag title = scriptEntry.getElement("title");
    EntityTag entity = scriptEntry.getObjectTag("entity");
    List<TradeTag> trades = (List<TradeTag>) scriptEntry.getObject("trades");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), entity, db("trades", trades), title, db("players", players));
    }
    if (entity != null) {
        if (players.size() > 1) {
            Debug.echoError("No more than one player can access the same entity!");
            return;
        }
        if (entity.getBukkitEntity() instanceof Merchant) {
            PlayerTag player = players.get(0);
            if (player.isValid() && player.isOnline()) {
                player.getPlayerEntity().openMerchant((Merchant) entity.getBukkitEntity(), true);
            } else {
                Debug.echoError("Tried to make a nonexistent or offline player trade with a villager entity!");
            }
            return;
        }
        Debug.echoError("The specified entity isn't a merchant!");
        return;
    }
    List<MerchantRecipe> recipes = new ArrayList<>();
    for (TradeTag trade : trades) {
        recipes.add(trade.getRecipe());
    }
    for (PlayerTag player : players) {
        if (player.isValid() && player.isOnline()) {
            Merchant merchant = Bukkit.createMerchant(title.asString());
            merchant.setRecipes(recipes);
            player.getPlayerEntity().openMerchant(merchant, true);
        } else {
            Debug.echoError("Tried to make a nonexistent or offline player view a virtual trading inventory!");
        }
    }
}
Also used : MerchantRecipe(org.bukkit.inventory.MerchantRecipe) Merchant(org.bukkit.inventory.Merchant) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ArrayList(java.util.ArrayList) TradeTag(com.denizenscript.denizen.objects.TradeTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ArrayList(java.util.ArrayList) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 8 with MerchantRecipe

use of org.bukkit.inventory.MerchantRecipe in project Denizen-For-Bukkit by DenizenScript.

the class InventoryTrades method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("trades") && mechanism.requireInteger()) {
        ArrayList<MerchantRecipe> recipes = new ArrayList<>();
        for (TradeTag recipe : mechanism.valueAsType(ListTag.class).filter(TradeTag.class, mechanism.context)) {
            recipes.add(recipe.getRecipe());
        }
        ((MerchantInventory) inventory.getInventory()).getMerchant().setRecipes(recipes);
    }
}
Also used : MerchantRecipe(org.bukkit.inventory.MerchantRecipe) ArrayList(java.util.ArrayList) TradeTag(com.denizenscript.denizen.objects.TradeTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 9 with MerchantRecipe

use of org.bukkit.inventory.MerchantRecipe in project Denizen-For-Bukkit by DenizenScript.

the class EntityTrades method adjust.

public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("trades")) {
        ArrayList<MerchantRecipe> recipes = new ArrayList<>();
        for (TradeTag recipe : mechanism.valueAsType(ListTag.class).filter(TradeTag.class, mechanism.context)) {
            recipes.add(recipe.getRecipe());
        }
        ((Merchant) entity.getBukkitEntity()).setRecipes(recipes);
    }
}
Also used : MerchantRecipe(org.bukkit.inventory.MerchantRecipe) Merchant(org.bukkit.inventory.Merchant) ArrayList(java.util.ArrayList) TradeTag(com.denizenscript.denizen.objects.TradeTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Aggregations

MerchantRecipe (org.bukkit.inventory.MerchantRecipe)9 ArrayList (java.util.ArrayList)5 TradeTag (com.denizenscript.denizen.objects.TradeTag)3 ItemStack (org.bukkit.inventory.ItemStack)3 ListTag (com.denizenscript.denizencore.objects.core.ListTag)2 List (java.util.List)2 CompoundTag (net.glowstone.util.nbt.CompoundTag)2 Merchant (org.bukkit.inventory.Merchant)2 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 ItemTag (com.denizenscript.denizen.objects.ItemTag)1 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 ByteBuf (io.netty.buffer.ByteBuf)1 GlowVillager (net.glowstone.entity.passive.GlowVillager)1 NbtSerialization (net.glowstone.io.nbt.NbtSerialization)1 PluginMessage (net.glowstone.net.message.play.game.PluginMessage)1 EntityType (org.bukkit.entity.EntityType)1