@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); } } }
@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); } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onHangingPlace(HangingPlaceEvent event) { Hanging hanging = event.getEntity(); HangingPlace action; if (hanging instanceof Painting) { action = this.newAction(PaintingPlace.class, hanging.getWorld()); if (action != null) { ((PaintingPlace)action).art = ((Painting)hanging).getArt(); } } else { action = this.newAction(HangingPlace.class, hanging.getWorld()); } if (action != null) { action.setLocation(hanging.getLocation()); action.setHanging(hanging); action.setPlayer(event.getPlayer()); this.logAction(action); } }
private static Material getHangingType(Hanging hanging) { if(hanging instanceof Painting) { return Material.PAINTING; } else if(hanging instanceof ItemFrame) { return Material.ITEM_FRAME; } else if(hanging instanceof LeashHitch) { return Material.LEASH; } else { return null; } }
public static String serializeState(Entity entity) { YamlConfiguration yaml = new YamlConfiguration(); if (Support.ARMOR_STAND && entity instanceof ArmorStand) { EulerAngleSerializer eas = EulerAngleSerializer.getInstance(); ArmorStand stand = (ArmorStand) entity; yaml.set(PITCH, stand.getLocation().getPitch()); yaml.set(YAW, stand.getLocation().getYaw()); yaml.set(ARMOR_STAND_HELMET, stand.getHelmet()); yaml.set(ARMOR_STAND_CHESTPLATE, stand.getChestplate()); yaml.set(ARMOR_STAND_LEGGINGS, stand.getLeggings()); yaml.set(ARMOR_STAND_BOOTS, stand.getBoots()); yaml.set(ARMOR_STAND_HAND, stand.getItemInHand()); yaml.set(ARMOR_STAND_POSE_HEAD, eas.serialize(stand.getHeadPose())); yaml.set(ARMOR_STAND_POSE_BODY, eas.serialize(stand.getBodyPose())); yaml.set(ARMOR_STAND_POSE_ARM_LEFT, eas.serialize(stand.getLeftArmPose())); yaml.set(ARMOR_STAND_POSE_ARM_RIGHT, eas.serialize(stand.getRightArmPose())); yaml.set(ARMOR_STAND_POSE_LEG_LEFT, eas.serialize(stand.getLeftLegPose())); yaml.set(ARMOR_STAND_POSE_LEG_RIGHT, eas.serialize(stand.getRightLegPose())); yaml.set(ARMOR_STAND_ARMS, stand.hasArms()); yaml.set(ARMOR_STAND_BASE_PLATE, stand.hasBasePlate()); yaml.set(ARMOR_STAND_GRAVITY, stand.hasGravity()); yaml.set(ARMOR_STAND_SMALL, stand.isSmall()); yaml.set(ARMOR_STAND_VISIBLE, stand.isVisible()); } else if (entity instanceof Hanging) { yaml.set(HANGING_FACING, ((Hanging) entity).getFacing().name()); if (entity instanceof ItemFrame) { yaml.set(ITEM_FRAME_ITEM, ((ItemFrame) entity).getItem()); yaml.set(ITEM_FRAME_ROTATION, ((ItemFrame) entity).getRotation().name()); } else if (entity instanceof Painting) { yaml.set(PAINTING_ART, ((Painting) entity).getArt().name()); } } return yaml.saveToString(); }
@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); } }
private static PacketContainer fromPainting(Painting painting) { if (entityConstructor == null) { entityConstructor = ProtocolLibrary.getProtocolManager().createPacketConstructor(TYPE, (Entity) painting); } return entityConstructor.createPacket((Entity) painting); }
@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 IconMenu buildMenu(Painting painting) { editingPainting = painting; Art[] other = getOtherArt(painting.getArt()); IconMenu menu = new IconMenu("Select Artwork", STBUtil.roundUp(other.length, 9), this, getProviderPlugin()); int pos = 0; for (Art a : other) { menu.setOption(pos++, new ItemStack(Material.PAINTING), a.name(), ""); } return menu; }
/** * Get classes used to detect a furniture entity. */ public static Class<?>[] getFurnitureClasses() { return new Class<?>[] { Painting.class, ItemFrame.class, ArmorStand.class }; }
public PaintingBreakEvent(final Painting painting, final RemoveCause cause) { super(painting); this.cause = cause; }
public PaintingPlaceEvent(final Painting painting, final Player player, final Block block, final BlockFace blockFace) { super(painting); this.player = player; this.block = block; this.blockFace = blockFace; }
protected PaintingEvent(final Painting painting) { this.painting = painting; }
public PaintingBreakByEntityEvent(final Painting painting, final Entity remover) { super(painting, RemoveCause.ENTITY); this.remover = remover; }
public static void deserializeState(Entity entity, String serial) throws InvalidConfigurationException, IOException { YamlConfiguration yaml = new YamlConfiguration(); yaml.loadFromString(serial); if (Support.ARMOR_STAND && entity instanceof ArmorStand) { EulerAngleSerializer eas = EulerAngleSerializer.getInstance(); ArmorStand stand = (ArmorStand) entity; stand.setHelmet(yaml.getItemStack(ARMOR_STAND_HELMET)); stand.setChestplate(yaml.getItemStack(ARMOR_STAND_CHESTPLATE)); stand.setLeggings(yaml.getItemStack(ARMOR_STAND_LEGGINGS)); stand.setBoots(yaml.getItemStack(ARMOR_STAND_BOOTS)); stand.setItemInHand(yaml.getItemStack(ARMOR_STAND_HAND)); stand.setHeadPose(eas.deserialize(yaml.getString(ARMOR_STAND_POSE_HEAD))); stand.setBodyPose(eas.deserialize(yaml.getString(ARMOR_STAND_POSE_BODY))); stand.setLeftArmPose(eas.deserialize(yaml.getString(ARMOR_STAND_POSE_ARM_LEFT))); stand.setRightArmPose(eas.deserialize(yaml.getString(ARMOR_STAND_POSE_ARM_RIGHT))); stand.setLeftLegPose(eas.deserialize(yaml.getString(ARMOR_STAND_POSE_LEG_LEFT))); stand.setRightLegPose(eas.deserialize(yaml.getString(ARMOR_STAND_POSE_LEG_RIGHT))); stand.setArms(yaml.getBoolean(ARMOR_STAND_ARMS)); stand.setBasePlate(yaml.getBoolean(ARMOR_STAND_BASE_PLATE)); stand.setGravity(yaml.getBoolean(ARMOR_STAND_GRAVITY)); stand.setSmall(yaml.getBoolean(ARMOR_STAND_SMALL)); stand.setVisible(yaml.getBoolean(ARMOR_STAND_VISIBLE)); } else if (entity instanceof Hanging) { BlockFace facing = BlockFace.valueOf(yaml.getString(HANGING_FACING)); if (facing != null) { ((Hanging) entity).setFacingDirection(facing, true); } else { SteelCore.logVerbose("Invalid serialized BlockFace value for hanging entity with UUID " + entity.getUniqueId().toString()); } if (entity instanceof ItemFrame) { ((ItemFrame) entity).setItem(yaml.getItemStack(ITEM_FRAME_ITEM)); Rotation rotation = Rotation.valueOf(yaml.getString(ITEM_FRAME_ROTATION)); if (rotation != null) { ((ItemFrame) entity).setRotation(rotation); // rotation doesn't sound like a word anymore } else { SteelCore.logVerbose("Invalid serialized Rotation value for item frame with UUID " + entity.getUniqueId().toString()); } } else if (entity instanceof Painting) { Art art = Art.valueOf(yaml.getString("art")); if (art != null) { ((Painting) entity).setArt(art, true); // neither does art } else { SteelCore.logVerbose("Invalid serialized Art value for item frame with UUID " + entity.getUniqueId().toString()); } } } }
public CanaryPainting(net.canarymod.api.entity.hanging.Painting entity) { super(entity); }
@Override protected net.canarymod.api.entity.hanging.Painting getHandle() { return (net.canarymod.api.entity.hanging.Painting) super.getHandle(); }
public WrapperPlayServerSpawnEntityPainting(Painting painting) { super(fromPainting(painting), TYPE); }
@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"); } }
@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 { return; // TODO other ProjectileSources } } 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 } }