Search in sources :

Example 1 with Dye

use of org.bukkit.material.Dye in project Citizens2 by CitizensDev.

the class SheepEquipper method equip.

@Override
public void equip(Player equipper, NPC toEquip) {
    ItemStack hand = equipper.getInventory().getItemInHand();
    Sheep sheep = (Sheep) toEquip.getEntity();
    if (hand.getType() == Material.SHEARS) {
        Messaging.sendTr(equipper, toEquip.getTrait(SheepTrait.class).toggleSheared() ? Messages.SHEARED_SET : Messages.SHEARED_STOPPED, toEquip.getName());
    } else if (hand.getType() == Material.INK_SACK) {
        Dye dye = (Dye) hand.getData();
        if (sheep.getColor() == dye.getColor())
            return;
        DyeColor color = dye.getColor();
        toEquip.getTrait(WoolColor.class).setColor(color);
        Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_SHEEP_COLOURED, toEquip.getName(), color.name().toLowerCase().replace("_", " "));
        hand.setAmount(hand.getAmount() - 1);
    } else {
        toEquip.getTrait(WoolColor.class).setColor(DyeColor.WHITE);
        Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_SHEEP_COLOURED, toEquip.getName(), "white");
    }
    equipper.getInventory().setItemInHand(hand);
}
Also used : Dye(org.bukkit.material.Dye) Sheep(org.bukkit.entity.Sheep) ItemStack(org.bukkit.inventory.ItemStack) DyeColor(org.bukkit.DyeColor) SheepTrait(net.citizensnpcs.trait.SheepTrait)

Example 2 with Dye

use of org.bukkit.material.Dye in project modules-extra by CubeEngine.

the class ListenerPlayerEntity method onPlayerInteractEntityEvent.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
    if (!(event.getRightClicked() instanceof LivingEntity)) {
        return;
    }
    Player player = event.getPlayer();
    Entity entity = event.getRightClicked();
    ActionPlayerEntity action;
    if (player.getItemInHand().getType() == COAL && entity instanceof PoweredMinecart) {
        action = this.newAction(UseFurnaceMinecart.class, entity.getWorld());
    } else if (player.getItemInHand().getType() == INK_SACK && entity instanceof Sheep || entity instanceof Wolf) {
        action = this.newAction(EntityDye.class, entity.getWorld());
        if (action != null) {
            ((EntityDye) action).setColor(((Dye) player.getItemInHand().getData()).getColor());
        }
    } else if (player.getItemInHand().getType().equals(BOWL) && entity instanceof MushroomCow) {
        action = this.newAction(EntityFillSoup.class, entity.getWorld());
    } else {
        return;
    }
    if (action != null) {
        action.setEntity(entity);
        action.setPlayer(player);
        action.setLocation(entity.getLocation());
        this.logAction(action);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.spongepowered.api.entity.Entity) Dye(org.bukkit.material.Dye) Player(org.spongepowered.api.entity.player.Player) MushroomCow(org.bukkit.entity.MushroomCow) PoweredMinecart(org.bukkit.entity.minecart.PoweredMinecart) Sheep(org.bukkit.entity.Sheep) Wolf(org.bukkit.entity.Wolf) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Dye

use of org.bukkit.material.Dye in project Glowstone by GlowstoneMC.

the class GlowBannerMatcher method getResult.

@Override
public ItemStack getResult(ItemStack[] matrix) {
    DyeColor color = null;
    Pattern texture = null;
    ItemStack banner = null;
    for (ItemStack item : matrix) {
        if (item == null) {
            continue;
        }
        if (Tag.BANNERS.isTagged(item.getType())) {
            if (banner != null) {
                // Multiple banners found
                return null;
            }
            banner = item;
            continue;
        }
        if (MaterialTags.DYES.isTagged(item.getType())) {
            DyeColor itemColor = ((Dye) item.getData()).getColor();
            if (color != null && itemColor != color) {
                // Can't have multiple colors
                return null;
            }
            color = itemColor;
        }
    }
    if (banner == null) {
        // Couldn't found a banner to alter
        return null;
    }
    recipe: for (LayerRecipe recipe : LayerRecipe.values()) {
        if (recipe.hasItem()) {
            boolean foundDye = false;
            for (ItemStack item : matrix) {
                if (item == null) {
                    // Ignore blanks
                    continue;
                }
                if (Tag.BANNERS.isTagged(item.getType())) {
                    // Banner is already checked
                    continue;
                }
                if (MaterialTags.DYES.isTagged(item.getType())) {
                    if (foundDye) {
                        // Can't have multiple dyes
                        continue recipe;
                    }
                    foundDye = true;
                    continue;
                }
                if (item.getType() == recipe.getType() && item.getDurability() == recipe.getData()) {
                    if (texture != null) {
                        // Can't have multiple of same item
                        return null;
                    }
                    // Matches texture type
                    texture = recipe.getPattern();
                    continue;
                }
                // Non-recipe item in grid
                continue recipe;
            }
            if (texture == null) {
                // No item type for this recipe found
                continue;
            }
            if (color == null) {
                color = DyeColor.BLACK;
            }
            // Recipe matches
            break;
        } else {
            if (matrix.length != 9) {
                // Non-item recipes only work on 3x3
                return null;
            }
            for (int i = 0; i < 9; i++) {
                boolean hasValue = recipe.getValues()[i] == '#';
                ItemStack item = matrix[i];
                if (hasValue && item != null && MaterialTags.DYES.isTagged(item.getType())) {
                    continue;
                }
                if (!hasValue && (item == null || Tag.BANNERS.isTagged(item.getType()))) {
                    // Allow banner and blanks
                    continue;
                }
                // Non-recipe item found or no dye where dye should be
                continue recipe;
            }
            texture = recipe.getPattern();
            // Recipe matches
            break;
        }
    }
    if (texture == null) {
        // No texture found
        return null;
    }
    // Create result banner
    BannerMeta meta = (BannerMeta) banner.getItemMeta();
    List<Pattern> layers = meta.getPatterns();
    meta.setPatterns(layers);
    result = banner.clone();
    result.setItemMeta(meta);
    return result;
}
Also used : Pattern(org.bukkit.block.banner.Pattern) Dye(org.bukkit.material.Dye) BannerMeta(org.bukkit.inventory.meta.BannerMeta) DyeColor(org.bukkit.DyeColor) ItemStack(org.bukkit.inventory.ItemStack)

Example 4 with Dye

use of org.bukkit.material.Dye in project Glowstone by GlowstoneMC.

the class GlowChargeFadeMatcher method getResult.

@Override
public ItemStack getResult(ItemStack[] matrix) {
    ItemStack charge = null;
    List<Color> colors = new ArrayList<>();
    for (ItemStack item : matrix) {
        if (item == null) {
            continue;
        }
        switch(item.getType()) {
            case INK_SAC:
                Dye dye = (Dye) item.getData();
                colors.add(dye.getColor().getFireworkColor());
                break;
            case FIREWORK_STAR:
                charge = item;
                break;
            default:
                // Wrong item on matrix
                return null;
        }
    }
    if (charge == null || colors.isEmpty()) {
        // No charge, or no colors
        return null;
    }
    FireworkEffectMeta meta = (FireworkEffectMeta) charge.getItemMeta();
    FireworkEffect old = meta.getEffect();
    if (old == null) {
        return null;
    }
    FireworkEffect newEffect = FireworkEffect.builder().with(old.getType()).withColor(old.getColors()).flicker(old.hasFlicker()).trail(old.hasTrail()).withFade(colors).build();
    meta.setEffect(newEffect);
    ItemStack ret = charge.clone();
    ret.setItemMeta(meta);
    return ret;
}
Also used : Dye(org.bukkit.material.Dye) Color(org.bukkit.Color) ArrayList(java.util.ArrayList) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) ItemStack(org.bukkit.inventory.ItemStack) FireworkEffect(org.bukkit.FireworkEffect)

Example 5 with Dye

use of org.bukkit.material.Dye in project Glowstone by GlowstoneMC.

the class GlowChargeMatcher method getResult.

@Override
public ItemStack getResult(ItemStack[] matrix) {
    boolean hasGunpowder = false;
    boolean trail = false;
    boolean twinkle = false;
    List<Color> colors = new ArrayList<>();
    Type type = Type.BALL;
    for (ItemStack item : matrix) {
        if (item == null) {
            continue;
        }
        switch(item.getType()) {
            case GUNPOWDER:
                if (hasGunpowder) {
                    // Only 1 gunpowder allowed
                    return null;
                }
                hasGunpowder = true;
                break;
            case INK_SAC:
                Dye dye = (Dye) item.getData();
                colors.add(dye.getColor().getFireworkColor());
                break;
            case DIAMOND:
                if (trail) {
                    // Only 1 diamond allowed
                    return null;
                }
                trail = true;
                break;
            case GLOWSTONE_DUST:
                if (twinkle) {
                    // Only 1 dust allowed
                    return null;
                }
                twinkle = true;
                break;
            case FIRE_CHARGE:
                if (type != Type.BALL) {
                    return null;
                }
                type = Type.BALL_LARGE;
                break;
            case GOLD_NUGGET:
                if (type != Type.BALL) {
                    return null;
                }
                type = Type.STAR;
                break;
            case FEATHER:
                if (type != Type.BALL) {
                    return null;
                }
                type = Type.BURST;
                break;
            case SKELETON_SKULL:
            case WITHER_SKELETON_SKULL:
            case ZOMBIE_HEAD:
            case PLAYER_HEAD:
            case CREEPER_HEAD:
            case DRAGON_HEAD:
                if (type != Type.BALL) {
                    return null;
                }
                type = Type.CREEPER;
                break;
            default:
                // Non firework item on matrix
                return null;
        }
    }
    if (!hasGunpowder || colors.isEmpty()) {
        // Not enough ingredients
        return null;
    }
    FireworkEffect effect = FireworkEffect.builder().withColor(colors).trail(trail).flicker(twinkle).with(type).build();
    ItemStack charge = new ItemStack(Material.FIREWORK_STAR, 1);
    FireworkEffectMeta meta = (FireworkEffectMeta) charge.getItemMeta();
    meta.setEffect(effect);
    charge.setItemMeta(meta);
    return charge;
}
Also used : Dye(org.bukkit.material.Dye) Type(org.bukkit.FireworkEffect.Type) Color(org.bukkit.Color) ArrayList(java.util.ArrayList) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) ItemStack(org.bukkit.inventory.ItemStack) FireworkEffect(org.bukkit.FireworkEffect)

Aggregations

Dye (org.bukkit.material.Dye)8 ItemStack (org.bukkit.inventory.ItemStack)6 DyeColor (org.bukkit.DyeColor)4 ArrayList (java.util.ArrayList)2 Color (org.bukkit.Color)2 FireworkEffect (org.bukkit.FireworkEffect)2 Sheep (org.bukkit.entity.Sheep)2 EventHandler (org.bukkit.event.EventHandler)2 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)2 SheepTrait (net.citizensnpcs.trait.SheepTrait)1 GlowWorld (net.glowstone.GlowWorld)1 Type (org.bukkit.FireworkEffect.Type)1 Material (org.bukkit.Material)1 Note (org.bukkit.Note)1 Block (org.bukkit.block.Block)1 BlockState (org.bukkit.block.BlockState)1 Jukebox (org.bukkit.block.Jukebox)1 NoteBlock (org.bukkit.block.NoteBlock)1 Pattern (org.bukkit.block.banner.Pattern)1 LivingEntity (org.bukkit.entity.LivingEntity)1