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);
}
}
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!");
}
}
}
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);
}
}
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);
}
}
Aggregations