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