use of org.bukkit.entity.Painting in project RedProtect by FabioZumbi12.
the class RPBlockListener method onFrameBrake.
@EventHandler
public void onFrameBrake(HangingBreakEvent e) {
RedProtect.get().logger.debug("Is BlockListener - HangingBreakEvent event");
if (e.isCancelled()) {
return;
}
Entity ent = e.getEntity();
Location l = e.getEntity().getLocation();
if ((ent instanceof ItemFrame || ent instanceof Painting) && (e.getCause().toString().equals("EXPLOSION"))) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canFire()) {
e.setCancelled(true);
}
}
}
use of org.bukkit.entity.Painting in project modules-extra by CubeEngine.
the class ListenerHanging method onHangingBreak.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
if (event.getCause() == HangingBreakEvent.RemoveCause.PHYSICS) {
Hanging hanging = event.getEntity();
Location location = hanging.getLocation();
BaseAction cause = this.plannedHangingBreak.get(location);
if (cause != null) {
if (cause instanceof ActionPlayerBlock) {
HangingBreak action;
if (hanging instanceof ItemFrame) {
action = this.newAction(ItemframeBreak.class, location.getWorld());
ItemStack item = ((ItemFrame) hanging).getItem();
if (action != null && item != null) {
((ItemframeBreak) action).item = item;
}
} else if (hanging instanceof Painting) {
action = this.newAction(PaintingBreak.class, location.getWorld());
((PaintingBreak) action).art = ((Painting) hanging).getArt();
} else {
action = this.newAction(HangingBreak.class, location.getWorld());
}
if (action != null) {
action.setLocation(location);
action.setHanging(hanging);
action.player = ((ActionPlayerBlock) cause).player;
action.setCause(cause);
this.logAction(action);
}
}
// else // TODO
}
// else TODO this.module.getLog().info("Unexpected HangingBreakEvent");
}
}
use of org.bukkit.entity.Painting in project modules-extra by CubeEngine.
the class ListenerHanging method onHangingBreakByEntity.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
Entity causer;
if (event.getRemover() instanceof Projectile) {
ProjectileSource shooter = ((Projectile) event.getRemover()).getShooter();
if (shooter instanceof Entity) {
causer = (Entity) shooter;
} else {
// TODO other ProjectileSources
return;
}
} else {
causer = event.getRemover();
}
Hanging hanging = event.getEntity();
Location location = hanging.getLocation();
if (causer instanceof Player) {
HangingBreak action;
if (hanging instanceof ItemFrame) {
action = this.newAction(ItemframeBreak.class, location.getWorld());
ItemStack item = ((ItemFrame) hanging).getItem();
if (action != null && item != null) {
((ItemframeBreak) action).item = item;
}
} else if (hanging instanceof Painting) {
action = this.newAction(PaintingBreak.class, location.getWorld());
if (action != null) {
((PaintingBreak) action).art = ((Painting) hanging).getArt();
}
} else {
action = this.newAction(HangingBreak.class, location.getWorld());
}
if (action != null) {
action.setLocation(location);
action.setHanging(hanging);
action.setPlayer((Player) causer);
this.logAction(action);
}
} else {
// TODO
}
}
use of org.bukkit.entity.Painting in project MagicPlugin by elBukkit.
the class EntityData method modifyPreSpawn.
private boolean modifyPreSpawn(MageController controller, Entity entity) {
if (entity == null || entity.getType() != type)
return false;
boolean isPlayer = (entity instanceof Player);
if (extraData != null) {
extraData.apply(entity);
}
CompatibilityUtils.setSilent(entity, isSilent);
entity.setFireTicks(fireTicks);
if (entity instanceof Ageable) {
Ageable ageable = (Ageable) entity;
if (isBaby) {
ageable.setBaby();
} else {
ageable.setAdult();
}
}
if (entity instanceof Tameable) {
((Tameable) entity).setTamed(isTamed);
}
if (entity instanceof Colorable && dyeColor != null) {
Colorable colorable = (Colorable) entity;
colorable.setColor(dyeColor);
}
if (tags != null && !tags.isEmpty()) {
Set<String> entityTags = CompatibilityUtils.getTags(entity);
entityTags.addAll(tags);
}
if (entity instanceof Creature) {
Creature creature = (Creature) entity;
creature.setCanPickupItems(canPickupItems);
}
if (entity instanceof Painting) {
Painting painting = (Painting) entity;
if (art != null) {
painting.setArt(art, true);
}
if (facing != null) {
painting.setFacingDirection(facing, true);
}
} else if (entity instanceof ItemFrame) {
ItemFrame itemFrame = (ItemFrame) entity;
itemFrame.setItem(item);
if (facing != null) {
itemFrame.setFacingDirection(facing, true);
}
} else if (entity instanceof Item) {
Item droppedItem = (Item) entity;
droppedItem.setItemStack(item);
} else if (entity instanceof Wolf && dyeColor != null) {
Wolf wolf = (Wolf) entity;
wolf.setCollarColor(dyeColor);
} else if (entity instanceof Ocelot && ocelotType != null) {
Ocelot ocelot = (Ocelot) entity;
ocelot.setCatType(ocelotType);
} else if (entity instanceof Rabbit && rabbitType != null) {
Rabbit rabbit = (Rabbit) entity;
rabbit.setRabbitType(rabbitType);
} else if (entity instanceof ExperienceOrb && xp != null) {
((ExperienceOrb) entity).setExperience(xp);
}
if (entity instanceof LivingEntity) {
LivingEntity li = (LivingEntity) entity;
if (hasPotionEffects) {
Collection<PotionEffect> currentEffects = li.getActivePotionEffects();
for (PotionEffect effect : currentEffects) {
li.removePotionEffect(effect.getType());
}
if (potionEffects != null) {
for (PotionEffect effect : potionEffects) {
li.addPotionEffect(effect);
}
}
}
try {
if (!isPlayer) {
applyAttributes(li);
copyEquipmentTo(li);
if (maxHealth != null) {
li.setMaxHealth(maxHealth);
}
}
if (health != null) {
li.setHealth(Math.min(health, li.getMaxHealth()));
}
if (airLevel != null) {
li.setRemainingAir(Math.min(airLevel, li.getRemainingAir()));
}
if (!hasAI) {
li.setAI(hasAI);
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
if (!isPlayer && name != null && name.length() > 0) {
entity.setCustomName(name);
}
boolean needsMage = controller != null && mageData != null;
if (needsMage) {
Mage apiMage = controller.getMage(entity);
if (apiMage instanceof com.elmakers.mine.bukkit.magic.Mage) {
((com.elmakers.mine.bukkit.magic.Mage) apiMage).setEntityData(this);
}
}
return true;
}
use of org.bukkit.entity.Painting in project MagicPlugin by elBukkit.
the class AlterSpell method alterEntity.
protected SpellResult alterEntity(Entity entity) {
EntityType entityType = entity.getType();
switch(entityType) {
case PAINTING:
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;
}
}
registerModified(entity);
frameItem.setDurability(data);
itemFrame.setItem(frameItem);
break;
case HORSE:
registerModified(entity);
Horse horse = (Horse) entity;
Color color = horse.getColor();
Color[] colorValues = Color.values();
color = colorValues[(color.ordinal() + 1) % colorValues.length];
Style horseStyle = horse.getStyle();
Style[] styleValues = Style.values();
horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];
horse.setStyle(horseStyle);
horse.setColor(color);
break;
case OCELOT:
registerModified(entity);
Ocelot ocelot = (Ocelot) entity;
Type catType = ocelot.getCatType();
Type[] typeValues = Type.values();
catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
ocelot.setCatType(catType);
break;
case VILLAGER:
registerModified(entity);
Villager villager = (Villager) entity;
Profession profession = villager.getProfession();
Profession[] professionValues = Profession.values();
profession = professionValues[(profession.ordinal() + 1) % professionValues.length];
villager.setProfession(profession);
break;
case WOLF:
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:
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;
case SKELETON:
registerModified(entity);
Skeleton skeleton = (Skeleton) entity;
SkeletonType skeletonType = skeleton.getSkeletonType();
SkeletonType[] skeletonTypeValues = SkeletonType.values();
skeletonType = skeletonTypeValues[(skeletonType.ordinal() + 1) % skeletonTypeValues.length];
skeleton.setSkeletonType(skeletonType);
break;
default:
return SpellResult.NO_TARGET;
}
;
registerForUndo();
return SpellResult.CAST;
}
Aggregations