/** * Constructs a new Gui * * @param entity the entity to change the color of */ public ColorSelectionMenu(Creature entity) { super(null, 18, ChatColor.GREEN + "Select a color", 1); for (DyeColor dyeColor : DyeColor.values()) addItem(new Wool(dyeColor).toItemStack(1), event -> { if (entity instanceof Colorable) ((Colorable) entity).setColor(dyeColor); else if (entity instanceof Wolf) { Wolf wolf = (Wolf) entity; wolf.setTamed(true); wolf.setCollarColor(dyeColor); } event.setCancelled(true); }); }
/** * Sets the color of the specified block. * The block that is passed will be modified by reference after the operation. * @param block The block to modify the data of. * @param color The new color of the item. */ @SuppressWarnings("deprecation") public static void setColor(Block block, DyeColor color) { Validate.isTrue(block != null && ((block.getState() != null && block.getState().getData() instanceof Colorable) || (block.getType() == Material.STAINED_CLAY || block.getType() == Material.STAINED_GLASS || block.getType() == Material.STAINED_GLASS_PANE || block.getType() == Material.CARPET)), "The specified block is not colorable."); Validate.notNull(color, "The specified color is null."); if(block.getState().getData() instanceof Colorable){ MaterialData data = block.getState().getData(); ((Colorable)data).setColor(color); block.getState().setData(data); }else{ block.setData(color.getWoolData()); // Needed until Bukkit adds proper support } }
public boolean isAuthorized(final CommandSender sender, final Material material, final MaterialData data) { final String materialName = material.name(); final String materialId = String.valueOf(material.getId()); if (data != null) { final String durName = materialName + ":" + data.getData(); final String durId = materialId + ":" + data.getData(); if (data instanceof Colorable) { return super.isAuthorized(sender, materialName + ":" + ((Colorable)data).getColor().name(), durName, durId, materialName, materialId); } if (data instanceof TexturedMaterial) { return super.isAuthorized(sender, materialName + ":" + ((TexturedMaterial)data).getMaterial().name(), durName, durId, materialName, materialId); } return super.isAuthorized(sender, durName, durId, materialName, materialId); } return super.isAuthorized(sender, materialName, materialId); }
public DyeColor getColor() { if (entity instanceof Colorable) { return ((Colorable)entity).getColor(); } else if (entity instanceof Wolf) { return ((Wolf)entity).getCollarColor(); } return DyeColor.WHITE; }
public EEntity setColor(DyeColor color) { if (entity instanceof Colorable) { ((Colorable)entity).setColor(color); } else if (entity instanceof Wolf) { ((Wolf)entity).setCollarColor(color); } return this; }
@SuppressWarnings("null") @Override @Nullable public Color convert(final Object o) { if (o instanceof ItemStack || o instanceof Item) { final ItemStack is = o instanceof ItemStack ? (ItemStack) o : ((Item) o).getItemStack(); final MaterialData d = is.getData(); if (d instanceof Colorable) return Color.byWoolColor(((Colorable) d).getColor()); } else if (o instanceof Colorable) { // Sheep return Color.byWoolColor(((Colorable) o).getColor()); } return null; }
private boolean okToColor(Block b, BaseSTBBlock stb) { if (stb != null && !(stb instanceof Colorable)) { // we don't want blocks which happen to use a Colorable material to be paintable return false; } if (getBlockColour(b) == getColour() || getPaintLevel() <= 0) { return false; } return STBUtil.isColorable(b.getType()) || b.getType() == Material.GLASS || b.getType() == Material.THIN_GLASS || allowWoodStaining() && isStainableWood(b.getType()) && okWoodStain(getColour()); }
@Override public void onInteractEntity(PlayerInteractEntityEvent event) { event.setCancelled(true); if (getPaintLevel() <= 0) { return; } Entity e = event.getRightClicked(); int paintUsed = 0; if (e instanceof Colorable) { ((Colorable) e).setColor(getColour()); paintUsed = 1; } else if (e instanceof Painting) { Art a = ((Painting) e).getArt(); if (getPaintLevel() >= a.getBlockHeight() * a.getBlockWidth()) { IconMenu menu = buildMenu((Painting) e); menu.open(event.getPlayer()); } else { Location loc = e.getLocation().add(0, -a.getBlockHeight() / 2.0, 0); PopupMessage.quickMessage(event.getPlayer(), loc, ChatColor.RED + "Not enough paint!"); } } else if (e instanceof Wolf) { Wolf wolf = (Wolf) e; wolf.setCollarColor(getColour()); paintUsed = 1; } if (paintUsed > 0) { setPaintLevel(getPaintLevel() - paintUsed); event.getPlayer().setItemInHand(toItemStack()); event.getPlayer().playSound(e.getLocation(), Sound.WATER, 1.0f, 1.5f); } }
private int paintBlocks(Player player, Block... blocks) { int painted = 0; for (Block b : blocks) { if (!SensibleToolbox.getBlockProtection().playerCanBuild(player, b, BlockProtection.Operation.PLACE)) { continue; } Debugger.getInstance().debug(2, "painting! " + b + " " + getPaintLevel() + " " + getColour()); BaseSTBBlock stb = SensibleToolbox.getBlockAt(b.getLocation()); if (stb != null && stb instanceof Colorable) { ((Colorable) stb).setColor(getColour()); } else if (isStainableWood(b.getType())) { int data = b.getData() & 0xf8; data |= getWoodType(getColour()).getData(); b.setData((byte) data); } else { if (b.getType() == Material.GLASS) { b.setType(Material.STAINED_GLASS); } else if (b.getType() == Material.THIN_GLASS) { b.setType(Material.STAINED_GLASS_PANE); } b.setData(getColour().getWoolData()); } painted++; setPaintLevel(getPaintLevel() - 1); if (getPaintLevel() <= 0) { break; } } return painted; }
public ColorableAnimal(Entity entity) { PreCon.notNull(entity); PreCon.isValid(entity instanceof Colorable, "org.bukkit.material.Colorable expected."); Colorable colorable = (Colorable)entity; _color = colorable.getColor(); }
@Override public boolean apply(Entity entity) { PreCon.notNull(entity); PreCon.isValid(entity instanceof Colorable, "org.bukkit.material.Colorable expected."); Colorable colorable = (Colorable)entity; colorable.setColor(_color); return true; }
private void testColorable(final Colorable colorable) { assertThat(colorable.getColor(), is(this.dye)); }
private static boolean isColorable(ItemStack stack){ return stack.getData() instanceof Colorable || stack.getType() == Material.STAINED_CLAY || stack.getType() == Material.STAINED_GLASS || stack.getType() == Material.STAINED_GLASS_PANE || stack.getType() == Material.CARPET || stack.getType() == Material.FIREWORK; }