use of org.bukkit.entity.Painting 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.Painting in project MagicPlugin by elBukkit.
the class CompatibilityUtils method createPainting.
public static Painting createPainting(Location location, BlockFace facing, Art art) {
Painting newPainting = null;
try {
location = getPaintingOffset(location, facing, art);
Object worldHandle = getHandle(location.getWorld());
Object newEntity = null;
@SuppressWarnings("unchecked") Enum<?> directionEnum = Enum.valueOf(class_EnumDirection, facing.name());
Object blockLocation = class_BlockPosition_Constructor.newInstance(location.getX(), location.getY(), location.getZ());
newEntity = class_EntityPaintingConstructor.newInstance(worldHandle, blockLocation, directionEnum);
if (newEntity != null) {
Entity bukkitEntity = getBukkitEntity(newEntity);
if (bukkitEntity == null || !(bukkitEntity instanceof Painting))
return null;
newPainting = (Painting) bukkitEntity;
newPainting.setFacingDirection(facing, true);
newPainting.setArt(art, true);
}
} catch (Throwable ex) {
ex.printStackTrace();
newPainting = null;
}
return newPainting;
}
use of org.bukkit.entity.Painting in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onPlayerInteract.
@EventHandler
public void onPlayerInteract(PlayerInteractEntityEvent e) {
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
Entity ent = e.getRightClicked();
Location l = ent.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null) {
return;
}
if (ent instanceof ItemFrame || ent instanceof Painting) {
if (!bypassBuild(p, null, 0)) {
e.setCancelled(true);
return;
}
}
if (ent instanceof Minecart || ent instanceof Boat) {
if (!RPConfig.getGlobalFlagBool(l.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (!RPConfig.getGlobalFlagBool(l.getWorld().getName() + ".interact") && !p.hasPermission("redprotect.bypass.world") && (!(ent instanceof Player))) {
if (RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-interact-false.allow-entities").contains(ent.getType().name())) {
return;
}
e.setCancelled(true);
}
}
use of org.bukkit.entity.Painting in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onPlayerInteract.
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEntityEvent event) {
Entity e = event.getRightClicked();
Player p = event.getPlayer();
if (e == null) {
return;
}
RedProtect.get().logger.debug("RPPlayerListener - Is PlayerInteractEntityEvent event: " + e.getType().name());
Location l = e.getLocation();
if (e instanceof ItemFrame || e instanceof Painting) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantedit");
event.setCancelled(true);
}
} else if ((e instanceof Minecart || e instanceof Boat)) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantenter");
event.setCancelled(true);
}
} else if (RedProtect.get().MyPet && e instanceof MyPetBukkitEntity) {
if (((MyPetBukkitEntity) e).getOwner().getPlayer().equals(p)) {
}
} else if (!RPUtil.isBukkitEntity(e) && (!(event.getRightClicked() instanceof Player))) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.allowMod(p)) {
RedProtect.get().logger.debug("PlayerInteractEntityEvent - Block is " + event.getRightClicked().getType().name());
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
}
}
}
use of org.bukkit.entity.Painting in project RedProtect by FabioZumbi12.
the class RPBlockListener method onFrameBrake.
@EventHandler
public void onFrameBrake(HangingBreakByEntityEvent e) {
RedProtect.get().logger.debug("Is BlockListener - HangingBreakByEntityEvent event");
if (e.isCancelled()) {
return;
}
Entity remover = e.getRemover();
Entity ent = e.getEntity();
Location l = e.getEntity().getLocation();
if ((ent instanceof ItemFrame || ent instanceof Painting) && remover instanceof Monster) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canMobLoot()) {
e.setCancelled(true);
}
}
}
Aggregations