use of org.bukkit.entity.Sheep in project MagicPlugin by elBukkit.
the class CycleEntityAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity entity = context.getTargetEntity();
EntityType entityType = entity.getType();
Mage mage = context.getMage();
switch(entityType) {
case PAINTING:
context.registerModified(entity);
Painting painting = (Painting) entity;
Art[] artValues = Art.values();
Art oldArt = painting.getArt();
Art newArt = oldArt;
int ordinal = (oldArt.ordinal() + 1);
for (int i = 0; i < artValues.length; i++) {
newArt = artValues[ordinal++ % artValues.length];
painting.setArt(newArt);
newArt = painting.getArt();
if (oldArt != newArt) {
break;
}
}
if (oldArt == newArt) {
return SpellResult.FAIL;
}
mage.sendDebugMessage("Altering art from " + oldArt + " to " + newArt);
break;
case ITEM_FRAME:
ItemFrame itemFrame = (ItemFrame) entity;
ItemStack frameItem = itemFrame.getItem();
if (frameItem == null || frameItem.getType() != Material.MAP) {
return SpellResult.NO_TARGET;
}
short data = frameItem.getDurability();
data++;
MapView mapView = DeprecatedUtils.getMap(data);
if (mapView == null) {
data = 0;
mapView = DeprecatedUtils.getMap(data);
if (mapView == null) {
return SpellResult.NO_TARGET;
}
}
context.registerModified(entity);
frameItem.setDurability(data);
itemFrame.setItem(frameItem);
break;
case HORSE:
context.registerModified(entity);
Horse horse = (Horse) entity;
Horse.Color color = horse.getColor();
Horse.Color[] colorValues = Horse.Color.values();
color = colorValues[(color.ordinal() + 1) % colorValues.length];
Horse.Style horseStyle = horse.getStyle();
Horse.Style[] styleValues = Horse.Style.values();
horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];
horse.setStyle(horseStyle);
horse.setColor(color);
break;
case OCELOT:
context.registerModified(entity);
Ocelot ocelot = (Ocelot) entity;
Ocelot.Type catType = ocelot.getCatType();
Ocelot.Type[] typeValues = Ocelot.Type.values();
catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
ocelot.setCatType(catType);
break;
case VILLAGER:
context.registerModified(entity);
Villager villager = (Villager) entity;
Villager.Profession profession = villager.getProfession();
Villager.Profession[] professionValues = Villager.Profession.values();
int villagerOrdinal = (profession.ordinal() + 1) % professionValues.length;
// Special-cases for zombie-reserved professions
if (villagerOrdinal == 0 || villagerOrdinal == 7) {
villagerOrdinal = 1;
}
profession = professionValues[villagerOrdinal];
villager.setProfession(profession);
break;
case WOLF:
context.registerModified(entity);
Wolf wolf = (Wolf) entity;
DyeColor wolfColor = wolf.getCollarColor();
DyeColor[] wolfColorValues = DyeColor.values();
wolfColor = wolfColorValues[(wolfColor.ordinal() + 1) % wolfColorValues.length];
wolf.setCollarColor(wolfColor);
break;
case SHEEP:
context.registerModified(entity);
Sheep sheep = (Sheep) entity;
DyeColor dyeColor = sheep.getColor();
DyeColor[] dyeColorValues = DyeColor.values();
dyeColor = dyeColorValues[(dyeColor.ordinal() + 1) % dyeColorValues.length];
sheep.setColor(dyeColor);
break;
default:
return SpellResult.NO_TARGET;
}
;
return SpellResult.CAST;
}
use of org.bukkit.entity.Sheep in project MagicPlugin by elBukkit.
the class EntityProjectileAction method setEntity.
protected Entity setEntity(MageController controller, @Nonnull Entity entity) {
this.entity = entity;
if (noTarget) {
entity.setMetadata("notarget", new FixedMetadataValue(controller.getPlugin(), true));
}
if (entity instanceof LivingEntity) {
((LivingEntity) entity).setMaxHealth(1000.0);
((LivingEntity) entity).setHealth(1000.0);
}
if (entity instanceof Slime) {
((Slime) entity).setSize(1);
}
// Variant name still used here for backwards compatibility
if (entity instanceof Ocelot) {
Ocelot ocelot = (Ocelot) entity;
Ocelot.Type variant = Ocelot.Type.WILD_OCELOT;
if (variantName != null) {
try {
variant = Ocelot.Type.valueOf(variantName.toUpperCase());
} catch (Exception ignored) {
}
} else {
variant = Ocelot.Type.WILD_OCELOT;
}
ocelot.setCatType(variant);
}
if (entity instanceof Sheep) {
Sheep sheep = (Sheep) entity;
DyeColor color = DyeColor.WHITE;
if (variantName != null) {
try {
color = DyeColor.valueOf(variantName.toUpperCase());
} catch (Exception ignored) {
}
}
sheep.setColor(color);
}
if (entity instanceof Wolf) {
Wolf wolf = (Wolf) entity;
if (variantName != null) {
// Only set collar color if a variant is set..
// this makes it a dog, versus a wolf. Technically.
DyeColor color = DyeColor.RED;
try {
color = DyeColor.valueOf(variantName.toUpperCase());
wolf.setTamed(true);
} catch (Exception ignored) {
}
wolf.setCollarColor(color);
}
}
if (projectileEffects != null && entity instanceof LivingEntity) {
CompatibilityUtils.applyPotionEffects((LivingEntity) entity, projectileEffects);
}
targeting.ignoreEntity(entity);
return entity;
}
use of org.bukkit.entity.Sheep 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.entity.Sheep in project StackMob-2 by Nathat23.
the class DyeEvent method onSheepDye.
@EventHandler
public void onSheepDye(SheepDyeWoolEvent event) {
if (!event.getEntity().hasMetadata(GlobalValues.METATAG)) {
return;
}
int stackSize = event.getEntity().getMetadata(GlobalValues.METATAG).get(0).asInt();
Entity oldEntity = event.getEntity();
if (sm.config.getCustomConfig().getBoolean("divide-on.sheep-dye") && stackSize > 1) {
Sheep newEntity = (Sheep) sm.tools.duplicate(oldEntity);
newEntity.setColor(event.getEntity().getColor());
newEntity.setMetadata(GlobalValues.METATAG, new FixedMetadataValue(sm, stackSize - 1));
newEntity.setMetadata(GlobalValues.NO_SPAWN_STACK, new FixedMetadataValue(sm, true));
oldEntity.setMetadata(GlobalValues.METATAG, new FixedMetadataValue(sm, 1));
oldEntity.setCustomName(null);
}
}
use of org.bukkit.entity.Sheep 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);
}
}
Aggregations