Search in sources :

Example 1 with TradeTag

use of com.denizenscript.denizen.objects.TradeTag 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 2 with TradeTag

use of com.denizenscript.denizen.objects.TradeTag 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 3 with TradeTag

use of com.denizenscript.denizen.objects.TradeTag 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

TradeTag (com.denizenscript.denizen.objects.TradeTag)3 ArrayList (java.util.ArrayList)3 MerchantRecipe (org.bukkit.inventory.MerchantRecipe)3 ListTag (com.denizenscript.denizencore.objects.core.ListTag)2 Merchant (org.bukkit.inventory.Merchant)2 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 List (java.util.List)1