public void move(double d0, double d1, double d2) { if (!this.world.isStatic && !this.dead && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) { if (this.dead) return; // CraftBukkit // CraftBukkit start - fire break events // TODO - Does this need its own cause? Seems to only be triggered by pistons HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.PHYSICS); this.world.getServer().getPluginManager().callEvent(event); if (this.dead || event.isCancelled()) { return; } // CraftBukkit end this.die(); this.b((Entity) null); } }
@EventHandler public void onEntityDamage(EntityDamageEvent event) { if(event.getEntity() != null) { Lot lot = this.module.getLotManager().getLot(event.getEntity().getLocation()); Town town = this.module.getLotManager().getTown(event.getEntity().getLocation()); if(event.getEntity() instanceof Player && (lot != null || town != null)) { event.setCancelled(true); } else if(lot != null && event instanceof EntityDamageByEntityEvent && (event.getEntity() instanceof Hanging || event.getEntity() instanceof ArmorStand)) { EntityDamageByEntityEvent entityEvent = (EntityDamageByEntityEvent) event; if(entityEvent.getDamager() instanceof Player && !entityEvent.getDamager().getName().equals(lot.getOwner()) && !entityEvent.getDamager().hasPermission(LotPermissions.BUILD_ANYWHERE)) { sendMessage(entityEvent.getDamager(), "lots.cannot-do"); event.setCancelled(true); } } } }
@Override public Collection<Entity> getTargetEntities() { if (cloneTarget == null || mage == null) return null; if (mode == BrushMode.CLONE || mode == BrushMode.REPLICATE || mode == BrushMode.SCHEMATIC) { List<Entity> targetData = new ArrayList<Entity>(); World targetWorld = cloneTarget.getWorld(); List<Entity> targetEntities = targetWorld.getEntities(); for (Entity entity : targetEntities) { // Schematics currently only deal with Hanging entities if (mode == BrushMode.SCHEMATIC && !(entity instanceof Hanging)) continue; // Note that we ignore players and NPCs if (!(entity instanceof Player) && !mage.getController().isNPC(entity)) { targetData.add(entity); } } return targetData; } return null; }
public void moveEntity(double p_70091_1_, double p_70091_3_, double p_70091_5_) { if (!this.worldObj.isRemote && !this.isDead && p_70091_1_ * p_70091_1_ + p_70091_3_ * p_70091_3_ + p_70091_5_ * p_70091_5_ > 0.0D) { if (this.isDead) { return; // CraftBukkit } // CraftBukkit start // TODO - Does this need its own cause? Seems to only be triggered by pistons HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.PHYSICS); this.worldObj.getServer().getPluginManager().callEvent(event); if (this.isDead || event.isCancelled()) { return; } // CraftBukkit end this.setDead(); this.onBroken((Entity)null); } }
@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); } }
public void move(double d0, double d1, double d2) { if (!this.world.isClientSide && !this.dead && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) { if (this.dead) return; // CraftBukkit // CraftBukkit start - fire break events // TODO - Does this need its own cause? Seems to only be triggered by pistons HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.PHYSICS); this.world.getServer().getPluginManager().callEvent(event); if (this.dead || event.isCancelled()) { return; } // CraftBukkit end this.die(); this.a((Entity) null); } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void checkItemFrameItemRemove(EntityDamageByEntityEvent event) { // This event is fired when popping an item out of an item frame, without breaking the frame itself if(event.getEntity() instanceof ItemFrame && ((ItemFrame) event.getEntity()).getItem() != null) { this.handleHangingBreak(event, (Hanging) event.getEntity(), event.getDamager()); } }
private void handleHangingBreak(Event event, Hanging hanging, Entity breaker) { BlockState blockState = getHangingBlockState(hanging); if(blockState == null) return; IEventQuery query = makeBlockQuery(event, breaker, blockState); for(EventRule rule : this.ruleContext.get(EventRuleScope.BLOCK_BREAK)) { if(rule.region().contains(blockState)) { if(processQuery(rule, query)) { sendCancelMessage(rule, query); if(this.useRegionPriority) break; } } } }
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(priority = EventPriority.HIGHEST) public void onHangingBreak(HangingBreakEvent event) { Hanging hanging = event.getEntity(); if (event.getCause().equals(RemoveCause.OBSTRUCTION)) { hanging.getLocation().getBlock().breakNaturally(); event.setCancelled(true); } else if (event.getCause().equals(RemoveCause.EXPLOSION)) { event.setCancelled(true); } }
private void clearMobs(World world) { for (Entity entity : world.getEntities()) { if (!(entity instanceof Hanging) && !(entity instanceof Player)) { entity.remove(); } } }
/** * On entity damage. * * @param event the event */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent event) { if (conf.isOverrideExplosions() && event.getEntity() instanceof Hanging && (event.getCause() == DamageCause.BLOCK_EXPLOSION || event.getCause() == DamageCause.ENTITY_EXPLOSION || event.getCause() == DamageCause.PROJECTILE)) { // Check for ItemFrame Factoid.getThisPlugin().iLog().write("Cancel HangingBreak : " + event.getEntity() + ", Cause: " + event.getCause()); event.setCancelled(true); } }
public static void logAttachedBlocks(LogListener ll, EventManager em, Block block, ActionBlock action) { if (!block.getType().isSolid() && !(block.getType() == SUGAR_CANE_BLOCK)) { return; // cannot have attached } for (Block aBlock : BlockUtil.getAttachedBlocks(block)) { em.fireEvent(new BlockPreBreakEvent(aBlock.getLocation(), action)); } for (Block dBlock : BlockUtil.getDetachableBlocksOnTop(block)) { if (isNotUpperDoorHalf(dBlock)) // ignore upper door halfs { em.fireEvent(new BlockPreBreakEvent(dBlock.getLocation(), action)); } } if (ll.isActive(HangingBreak.class, block.getWorld())) { Location location = block.getLocation(); Location entityLocation = block.getLocation(); for (Entity entity : block.getChunk().getEntities()) { if (entity instanceof Hanging && location.distanceSquared(entity.getLocation(entityLocation)) < 4) { em.fireEvent(new HangingPreBreakEvent(entityLocation, action)); } } } }
public void onLightningStrike(EntityLightning entitylightning) { // CraftBukkit start final org.bukkit.entity.Entity thisBukkitEntity = this.getBukkitEntity(); final org.bukkit.entity.Entity stormBukkitEntity = entitylightning.getBukkitEntity(); final PluginManager pluginManager = Bukkit.getPluginManager(); if (thisBukkitEntity instanceof Hanging) { HangingBreakByEntityEvent hangingEvent = new HangingBreakByEntityEvent((Hanging) thisBukkitEntity, stormBukkitEntity); pluginManager.callEvent(hangingEvent); if (hangingEvent.isCancelled()) { return; } } if (this.fireProof) { return; } CraftEventFactory.entityDamage = entitylightning; if (!this.damageEntity(DamageSource.LIGHTNING, 5.0F)) { CraftEventFactory.entityDamage = null; return; } // CraftBukkit end ++this.fireTicks; if (this.fireTicks == 0) { // CraftBukkit start - Call a combust event when lightning strikes EntityCombustByEntityEvent entityCombustEvent = new EntityCombustByEntityEvent(stormBukkitEntity, thisBukkitEntity, 8); pluginManager.callEvent(entityCombustEvent); if (!entityCombustEvent.isCancelled()) { this.setOnFire(entityCombustEvent.getDuration()); } // CraftBukkit end } }
public void m() { this.lastX = this.locX; this.lastY = this.locY; this.lastZ = this.locZ; if (this.d++ == this.world.spigotConfig.hangingTickFrequency && !this.world.isClientSide) { // Spigot this.d = 0; if (!this.dead && !this.survives()) { // CraftBukkit start - fire break events Material material = this.world.getType(new BlockPosition(this)).getMaterial(); HangingBreakEvent.RemoveCause cause; if (!material.equals(Material.AIR)) { // TODO: This feels insufficient to catch 100% of suffocation cases cause = HangingBreakEvent.RemoveCause.OBSTRUCTION; } else { cause = HangingBreakEvent.RemoveCause.PHYSICS; } HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), cause); this.world.getServer().getPluginManager().callEvent(event); if (dead || event.isCancelled()) { return; } // CraftBukkit end this.die(); this.a((Entity) null); } } }
private static BlockState getHangingBlockState(Hanging hanging) { Block block = hanging.getLocation().getBlock(); Material type = getHangingType(hanging); return type == null ? null : BlockStateUtils.cloneWithMaterial(block, type); }
public HangingPlaceEvent(final Hanging hanging, final Player player, final Block block, final BlockFace blockFace) { super(hanging); this.player = player; this.block = block; this.blockFace = blockFace; }
public HangingBreakByEntityEvent(final Hanging hanging, final Entity remover) { super(hanging, HangingBreakEvent.RemoveCause.ENTITY); this.remover = remover; }
protected HangingEvent(final Hanging painting) { this.hanging = painting; }
public HangingBreakEvent(final Hanging hanging, final HangingBreakEvent.RemoveCause cause) { super(hanging); this.cause = cause; }
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()); } } } }
@EventHandler(priority = EventPriority.LOWEST) public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent e) { Player p = null; RedProtect.get().logger.debug("RPLayerListener: Is EntityDamageByEntityEvent event"); if (e.getDamager() instanceof Player){ p = (Player)e.getDamager(); } else if (e.getDamager() instanceof Projectile){ Projectile proj = (Projectile)e.getDamager(); if (proj.getShooter() instanceof Player){ p = (Player) proj.getShooter(); } } if (p != null){ RedProtect.get().logger.debug("Player: " + p.getName()); } else { RedProtect.get().logger.debug("Player: is null"); return; } RedProtect.get().logger.debug("Damager: " + e.getDamager().getType().name()); //check killaura or freekill if (RPConfig.getBool("server-protection.check-killaura-freekill.enable")){ startCheckRate(p.getName()); } Location l = e.getEntity().getLocation(); Region r = RedProtect.get().rm.getTopRegion(l); if (r == null){ return; } if (RedProtect.get().tpWait.contains(p.getName())){ RedProtect.get().tpWait.remove(p.getName()); RPLang.sendMessage(p, "cmdmanager.region.tpcancelled"); } if (e.getEntity() instanceof Player && !p.equals(e.getEntity()) && r.flagExists("pvp") && !r.canPVP((Player)e.getEntity(), p)){ RPLang.sendMessage(p, "entitylistener.region.cantpvp"); e.setCancelled(true); } if ((e.getEntity() instanceof Hanging || e.getEntity() instanceof EnderCrystal) && !r.canBuild(p) && !r.canBreak(e.getEntityType())){ RPLang.sendMessage(p, "playerlistener.region.cantremove"); e.setCancelled(true); } if ((e.getEntity() instanceof Boat || e.getEntity() instanceof Minecart) && !r.canMinecart(p)){ RPLang.sendMessage(p, "blocklistener.region.cantbreak"); e.setCancelled(true); } }
/** * On entity damage by entity. * * @param event * the event */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { IPlayerConfEntry entry; Player player = getSourcePlayer(event.getDamager()); // Check for non-player kill if (player != null) { IDummyLand land = Factoid.getThisPlugin().iLands().getLandOrOutsideArea( event.getEntity().getLocation()); Entity entity = event.getEntity(); EntityType et = entity.getType(); // kill an entity (none player) if ((entry = playerConf.get(player)) != null // Citizens bugfix && !entry.isAdminMod() && ((land instanceof ILand && ((ILand) land) .isBanned(player)) || ((BKVersion.isArmorStand(et) || entity instanceof Hanging) && (!checkPermission(land, player, PermissionList.BUILD.getPermissionType()) || !checkPermission(land, player, PermissionList.BUILD_DESTROY.getPermissionType()))) || (entity instanceof Animals && !checkPermission( land, player, PermissionList.ANIMAL_KILL .getPermissionType())) || (entity instanceof Monster && !checkPermission( land, player, PermissionList.MOB_KILL .getPermissionType())) || (et == EntityType.VILLAGER && !checkPermission( land, player, PermissionList.VILLAGER_KILL .getPermissionType())) || (et == EntityType.IRON_GOLEM && !checkPermission( land, player, PermissionList.VILLAGER_GOLEM_KILL .getPermissionType())) || (et == EntityType.HORSE && !checkPermission( land, player, PermissionList.HORSE_KILL .getPermissionType())) || (entity instanceof Tameable && ((Tameable) entity).isTamed() == true && ((Tameable) entity).getOwner() != player && !checkPermission( land, player, PermissionList.TAMED_KILL .getPermissionType())))) { messagePermission(player); event.setCancelled(true); } } }