Ir para conteúdo

[Bukkit Java] Crie banners de A-Z, 0-9


zMathi

Posts Recomendados

Sim, algumas pessoas já postaram classes com a mesma função, porém, com códigos bem feinhos e nada eficazes/fluídos/limpos, então fiz do meu modo ;)

 

Código:

 

import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;

/**
 *
 * @author zMathi
 */
public enum BannerAlphabetic {

    A(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    B(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    C(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    D(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.BLACK, PatternType.CURLY_BORDER), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    E(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), new Pattern(DyeColor.BLACK, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    F(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), new Pattern(DyeColor.BLACK, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    G(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.BLACK, PatternType.HALF_HORIZONTAL), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    H(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    I(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_CENTER), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    J(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLACK, PatternType.HALF_HORIZONTAL), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    K(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), new Pattern(DyeColor.BLACK, PatternType.HALF_VERTICAL_MIRROR), new Pattern(DyeColor.WHITE, PatternType.CROSS), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    L(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    M(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.TRIANGLE_TOP), new Pattern(DyeColor.BLACK, PatternType.TRIANGLES_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    N(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLACK, PatternType.DIAGONAL_RIGHT_MIRROR), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNRIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    O(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    P(new Pattern[]{new Pattern(DyeColor.BLACK, PatternType.HALF_HORIZONTAL), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.BLACK, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    Q(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.SQUARE_BOTTOM_RIGHT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    R(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.BLACK, PatternType.HALF_HORIZONTAL_MIRROR), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNRIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    S(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.BLACK, PatternType.RHOMBUS_MIDDLE), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNRIGHT), new Pattern(DyeColor.BLACK, PatternType.BORDER), new Pattern(DyeColor.BLACK, PatternType.CURLY_BORDER)}),
    T(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_CENTER), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    U(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    V(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLACK, PatternType.TRIANGLES_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNLEFT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    W(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.TRIANGLE_BOTTOM), new Pattern(DyeColor.BLACK, PatternType.TRIANGLES_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    X(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.BLACK, PatternType.STRIPE_CENTER), new Pattern(DyeColor.WHITE, PatternType.CROSS), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    Y(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.CROSS), new Pattern(DyeColor.BLACK, PatternType.HALF_VERTICAL_MIRROR), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNLEFT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    Z(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNLEFT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    ONE(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.SQUARE_TOP_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_CENTER), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    TWO(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.BLACK, PatternType.RHOMBUS_MIDDLE), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNLEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    THREE(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), new Pattern(DyeColor.BLACK, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    FOUR(new Pattern[]{new Pattern(DyeColor.BLACK, PatternType.HALF_HORIZONTAL), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLACK, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    FIVE(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNRIGHT), new Pattern(DyeColor.BLACK, PatternType.CURLY_BORDER), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.SQUARE_BOTTOM_LEFT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    SIX(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.BLACK, PatternType.HALF_HORIZONTAL), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    SEVEN(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.BLACK, PatternType.DIAGONAL_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNLEFT), new Pattern(DyeColor.WHITE, PatternType.SQUARE_BOTTOM_LEFT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    EIGHT(new Pattern[]{}), //Não achei o 8
    NINE(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLACK, PatternType.HALF_HORIZONTAL_MIRROR), new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.BLACK, PatternType.BORDER)}),
    ZERO(new Pattern[]{new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNLEFT), new Pattern(DyeColor.BLACK, PatternType.BORDER)});

    private Pattern[] patterns = null;

    private BannerAlphabetic(Pattern[] patterns) {
        this.patterns = patterns;
    }

    public Pattern[] getPatterns() {
        return patterns;
    }

    public ItemStack getBanner() {
        return getBanner(DyeColor.WHITE, DyeColor.BLACK);
    }

    public ItemStack getBanner(DyeColor letterColor, DyeColor backColor) {
        ItemStack banner = new ItemStack(Material.BANNER);
        BannerMeta bannerMeta = (BannerMeta) banner.getItemMeta();
        bannerMeta.setBaseColor(backColor);

        for (Pattern patterns : getPatterns()) {
            bannerMeta.addPattern(patterns.getColor() == DyeColor.BLACK ? new Pattern(backColor, patterns.getPattern()) : new Pattern(letterColor, patterns.getPattern()));
        }
        banner.setItemMeta(bannerMeta);
        return banner;
    }

    public static BannerAlphabetic getBannerByLetter(String letter) {
        for (BannerAlphabetic banners : values()) {
            if (banners.name().equalsIgnoreCase(letter)) {
                return banners;
            }
        }
        return null;
    }
}
 

 

 

Como usar:

BannerAlphabetic.A.getBanner(); //Caso você não especifique os parâmetros como abaixo, as cores seram BRANCO e PRETA.
BannerAlphabetic.B.getBanner(DyeColor.RED, DyeCOLOR.WHITE); //RED = Cor da letra/número  WHITE = Cor de fundo.

BannerAlphabetic.getBannerByLetter("A"); //Vai retornar a BannerAlphabetic da letra A.

É isso aí. Deixa seu like por quê fiz agora de madrugada e com sono.

Editado por zMathi
Link para o comentário
Compartilhar em outros sites

Carai ó o tamanho disso ;-; irei usar em um pl que tinha feito, só o 8 que fode :/

 

@Edit

Você testou? ;-; aqui alguns não funciona

2MFHxIe1Qq2I_FES81g47w.png

Inventory inventory = getServer().createInventory(null, 4*9);
Arrays.stream(BannerAlphabetic.values()).forEach(bannerAlphabetic -> inventory.addItem(bannerAlphabetic.getBanner()));
player.openInventory(inventory);

A

 

 

A(new Pattern[]{
    new Pattern(DyeColor.BLACK, PatternType.HALF_HORIZONTAL), 
    new Pattern(DyeColor.BLACK, PatternType.STRIPE_BOTTOM), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), 
    new Pattern(DyeColor.BLACK, PatternType.BORDER)
}),   

 

 

P

 

 

P(new Pattern[]{
new Pattern(DyeColor.BLACK, PatternType.HALF_HORIZONTAL),
new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT),
new Pattern(DyeColor.BLACK, PatternType.STRIPE_BOTTOM),
new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT),
new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP),
new Pattern(DyeColor.BLACK, PatternType.BORDER)}
),

 

 

8

 

 

EIGHT(new Pattern[]{
    new Pattern(DyeColor.BLACK, PatternType.STRIPE_CENTER), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), 
    new Pattern(DyeColor.BLACK, PatternType.BORDER)}
), 

 

 

Editado por zAth
Link para o comentário
Compartilhar em outros sites

Carai ó o tamanho disso ;-; irei usar em um pl que tinha feito, só o 8 que fode :/

 

@Edit

Você testou? ;-; aqui alguns não funciona

2MFHxIe1Qq2I_FES81g47w.png

Inventory inventory = getServer().createInventory(null, 4*9);
Arrays.stream(BannerAlphabetic.values()).forEach(bannerAlphabetic -> inventory.addItem(bannerAlphabetic.getBanner()));
player.openInventory(inventory);

A

 

 

A(new Pattern[]{
    new Pattern(DyeColor.BLACK, PatternType.HALF_HORIZONTAL), 
    new Pattern(DyeColor.BLACK, PatternType.STRIPE_BOTTOM), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT), 
    new Pattern(DyeColor.BLACK, PatternType.BORDER)
}),   

 

 

P

 

 

P(new Pattern[]{
new Pattern(DyeColor.BLACK, PatternType.HALF_HORIZONTAL),
new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT),
new Pattern(DyeColor.BLACK, PatternType.STRIPE_BOTTOM),
new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT),
new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP),
new Pattern(DyeColor.BLACK, PatternType.BORDER)}
),

 

 

8

 

 

EIGHT(new Pattern[]{
    new Pattern(DyeColor.BLACK, PatternType.STRIPE_CENTER), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_TOP), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM), 
    new Pattern(DyeColor.WHITE, PatternType.STRIPE_MIDDLE), 
    new Pattern(DyeColor.BLACK, PatternType.BORDER)}
), 

 

 

Nem tinha testado mesmo. O erro estava no setBaseColor no getBanner e também algumas patterns erradas. Mas está tudo corrigido.

Link para o comentário
Compartilhar em outros sites

Participe da Conversa

Você pode postar agora e se cadastrar mais tarde. Se você tiver uma conta, a class='ipsType_brandedLink' href='https://gamersboard.com.br/login/' data-ipsDialog data-ipsDialog-size='medium' data-ipsDialog-title='Sign In Now'>acesse agora para postar com sua conta.
Observação: sua postagem exigirá aprovação do moderador antes de ficar visível.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.

Processando...
×
×
  • Criar Novo...