コード例 #1
0
  // When a chunk unloads, remove its monsters, excluding Withers
  // EnderDragon is NOT a monster, it is a ComplexLivingEntity (LEAVE ENDER ALONE)
  // Hoping this cuts down on lag?
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();
    for (Entity entity : chunk.getEntities()) {
      if (!entity.isDead() && entity instanceof Monster) {
        Monster monster = (Monster) entity;

        Boolean remove = true;

        if (monster.getCustomName() != null) {
          remove = false;
        }
        if (monster.getType() == EntityType.WITHER) {
          remove = false;
        }
        for (ItemStack item : monster.getEquipment().getArmorContents()) {
          if (item != null) {
            remove = false;
            break;
          }
        }
        if ((monster.getEquipment().getItemInHand() != null)
            || (monster.getType() == EntityType.SKELETON
                && monster.getEquipment().getItemInHand().getType() != Material.BOW)) {
          remove = false;
        }
        if (remove) {
          if (monster.getVehicle() instanceof Chicken) {
            monster.getVehicle().remove();
          }
          monster.remove();
        }
      }
    }
  }
コード例 #2
0
  @Override
  public SpellResult step(CastContext context) {
    if (entity == null) {
      return SpellResult.FAIL;
    }
    SpellResult result = super.step(context);
    Location target = actionContext.getTargetLocation();

    // TODO: locationOffset and velocityOffset should be made relative
    if (locationOffset != null) {
      target = target.clone().add(locationOffset);
    }
    if (doVelocity) {
      Vector velocity = this.velocity.clone().multiply(distanceTravelledThisTick);
      if (velocityOffset != null) {
        velocity = velocity.add(velocityOffset);
      }
      entity.setVelocity(velocity);
    }
    Location currentLocation = entity.getLocation();
    if (doTeleport) {
      if (!orient) {
        target.setYaw(currentLocation.getYaw());
        target.setPitch(currentLocation.getPitch());
      }
      entity.teleport(target);
    }
    return result;
  }
コード例 #3
0
 @EventHandler
 public void onDammange(EntityDamageByEntityEvent event) {
   Entity dammage = event.getEntity();
   if (dammage.getType() == EntityType.ENDER_CRYSTAL) {
     event.setCancelled(true);
   }
 }
コード例 #4
0
ファイル: SuperHeat.java プロジェクト: riking/Zephyrus
  public Entity getTarget(Player player) {

    BlockIterator iterator =
        new BlockIterator(
            player.getWorld(),
            player.getLocation().toVector(),
            player.getEyeLocation().getDirection(),
            0,
            100);
    Entity target = null;
    while (iterator.hasNext()) {
      Block item = iterator.next();
      for (Entity entity : player.getNearbyEntities(100, 100, 100)) {
        int acc = 2;
        for (int x = -acc; x < acc; x++) {
          for (int z = -acc; z < acc; z++) {
            for (int y = -acc; y < acc; y++) {
              if (entity.getLocation().getBlock().getRelative(x, y, z).equals(item)) {
                return target = entity;
              }
            }
          }
        }
      }
    }
    return target;
  }
コード例 #5
0
ファイル: EntityCannon.java プロジェクト: wizjany/craftbook
  /**
   * This method launches near by entities
   *
   * @return true if a entity was thrown.
   */
  protected boolean shoot() {

    boolean resultBoolean = false;
    Location location = BukkitUtil.toSign(getSign()).getLocation();
    EntityType type = EntityType.MOB_HOSTILE;

    if (!getSign().getLine(3).isEmpty()) {
      type = EntityType.fromString(getSign().getLine(3));
    }

    try {
      for (Entity e : LocationUtil.getNearbyEntities(location, new Vector(3, 3, 3))) {
        if (e.isDead() || !e.isValid()) {
          continue;
        }
        if (!type.is(e)) {
          continue;
        }

        String[] split = RegexUtil.COLON_PATTERN.split(getSign().getLine(2));
        double x = Double.parseDouble(split[0]);
        double y = Double.parseDouble(split[1]);
        double z = Double.parseDouble(split[2]);

        e.setVelocity(new org.bukkit.util.Vector(x, y, z).add(e.getVelocity()));

        resultBoolean = true;
      }
    } catch (Exception ignored) {
    }

    return resultBoolean;
  }
コード例 #6
0
 @Override
 public void run() {
   for (Entity damagee : affectedWorld.getEntities()) {
     if (StormUtil.isEntityUnderSky(damagee)
         && StormUtil.isSnowy(damagee.getLocation().getBlock().getBiome())) {
       if (StormUtil.isLocationNearBlock(
           damagee.getLocation(), glob.Blizzard_Heating__Blocks, glob.Blizzard_Heat__Radius)) {
         if (glob.Blizzard_Features_Entity__Damaging
             && damagee instanceof LivingEntity
             && !(damagee instanceof Player))
           ((LivingEntity) (damagee)).damage(glob.Blizzard_Entity_Damage__From__Exposure);
         else if (glob.Blizzard_Features_Player__Damaging && damagee instanceof Player) {
           Player dam = (Player) damagee;
           if (!dam.getGameMode().equals(GameMode.CREATIVE)
               && !dam.hasPermission("storm.blizzard.immune")
               && !glob.Blizzard_Heating__Blocks.contains(dam.getItemInHand().getTypeId())) {
             if (dam.getHealth() > 0) {
               dam.addPotionEffect(blindness, true);
               dam.damage(glob.Blizzard_Player_Damage__From__Exposure);
               dam.sendMessage(glob.Blizzard_Messages_On__Player__Damaged__Cold);
               StormUtil.playSound(dam, glob.Blizzard_Sounds_Player__Damage, 1F, 1F);
             }
           }
         }
       }
     }
   }
 }
コード例 #7
0
ファイル: DyeListener.java プロジェクト: boozaa/Quester
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void onEntityRightClick(PlayerInteractEntityEvent event) {
   QuestManager qm = Quester.qMan;
   Player player = event.getPlayer();
   Quest quest = qm.getPlayerQuest(player.getName());
   if (quest != null) {
     if (!quest.allowedWorld(player.getWorld().getName().toLowerCase())) return;
     List<Objective> objs = quest.getObjectives();
     Entity entity = event.getRightClicked();
     ItemStack item = player.getItemInHand();
     for (int i = 0; i < objs.size(); i++) {
       if (objs.get(i).getType().equalsIgnoreCase("DYE")) {
         if (!qm.isObjectiveActive(player, i)) {
           continue;
         }
         DyeObjective obj = (DyeObjective) objs.get(i);
         if (entity.getType() == EntityType.SHEEP) {
           Sheep sheep = (Sheep) entity;
           if (item.getType() == Material.INK_SACK
               && obj.checkDye(15 - item.getDurability())
               && sheep.getColor().getDyeData() != (15 - item.getDurability())) {
             qm.incProgress(player, i);
             return;
           }
         }
       }
     }
   }
 }
コード例 #8
0
  // @EventHandler(priority = EventPriority.NORMAL)
  public void explodingArrow(ProjectileHitEvent event) {
    Entity projectile = event.getEntity();
    World w = projectile.getWorld();
    Location hit = projectile.getLocation();

    if (w.getName().equals(name)) {

      if (projectile instanceof Arrow) {
        Arrow arrow = (Arrow) projectile;
        Entity shooter = arrow.getShooter();
        Location l = shooter.getLocation();
        Block bl = l.getBlock();
        Block b = bl.getRelative(BlockFace.DOWN, 2);
        Material mat = b.getType();

        if (shooter instanceof Player) {
          Player p = (Player) shooter;
          ItemStack is = p.getItemInHand();
          Material i = is.getType();
          if (i == Material.BOW && mat == Material.SPONGE) {
            p.getInventory().removeItem(new ItemStack(Material.ARROW, 20));
            w.createExplosion(hit, 8);
            int strikes = 0;
            while (strikes < 20) {
              strikes++;
              w.strikeLightning(hit);
            }
          }
          Bukkit.getWorld(name).playEffect(arrow.getLocation(), Effect.STEP_SOUND, 10);
        }
      }
    }
  }
コード例 #9
0
  /**
   * Handle EntityExplode events that involve modifying the event.
   *
   * @param event The event to modify
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEnitityExplode(EntityExplodeEvent event) {
    Entity entity = event.getEntity();

    if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) {
      return;
    }

    // We can make this assumption because we (should) be the only ones using this exact metadata
    Player player =
        plugin
            .getServer()
            .getPlayerExact(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());

    if (Misc.isNPCEntity(player)) {
      return;
    }

    MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();

    if (miningManager.canUseBlastMining()) {
      miningManager.blastMiningDropProcessing(event.getYield(), event.blockList());
      event.setYield(0);
    }
  }
コード例 #10
0
 @Override
 public boolean standsOnEntity(
     final Entity entity,
     final double minX,
     final double minY,
     final double minZ,
     final double maxX,
     final double maxY,
     final double maxZ) {
   try {
     // TODO: Probably check other ids too before doing this ?
     for (final Entity other : entity.getNearbyEntities(2.0, 2.0, 2.0)) {
       final EntityType type = other.getType();
       if (type != EntityType.BOAT) { //  && !(other instanceof Minecart))
         continue;
       }
       final double locY = entity.getLocation(useLoc).getY();
       useLoc.setWorld(null);
       if (Math.abs(locY - minY) < 0.7) {
         // TODO: A "better" estimate is possible, though some more tolerance would be good.
         return true;
       } else return false;
     }
   } catch (Throwable t) {
     // Ignore exceptions (Context: DisguiseCraft).
   }
   return false;
 }
コード例 #11
0
  @Override
  public void cast(Entity entity) {
    // entity.getWorld().playSound(entity.getLocation(), Sound.GHAST_FIREBALL, 1F, 1F);
    entity.getWorld().playSound(entity.getLocation(), Sound.NOTE_STICKS, 1F, 0.4F);

    // TODO - find a better way to launch block without needing Player
    if (entity instanceof Player) {
      Player player = (Player) entity;

      Vector velocity = player.getEyeLocation().getDirection();
      velocity.normalize().multiply(power);

      FallingBlock fb =
          DeprecatedMethods.spawnFallingBlock(
              entity.getLocation().clone().add(0, 1, 0),
              DeprecatedMethods.getMaterialByID(blockID),
              (byte) 0);
      fb.setDropItem(false);
      fb.setVelocity(velocity);

      // make it do damage
      if (damage) {
        DynamicClassFunctions.setFallingBlockHurtEntities(fb, hurt, hurt);
      }
    }
  }
コード例 #12
0
  /** {@inheritDoc} */
  @Override
  public TeleportResult safelyTeleport(
      CommandSender teleporter, Entity teleportee, MVDestination d) {
    if (d instanceof InvalidDestination) {
      this.plugin.log(Level.FINER, "Entity tried to teleport to an invalid destination");
      return TeleportResult.FAIL_INVALID;
    }
    Player teleporteePlayer = null;
    if (teleportee instanceof Player) {
      teleporteePlayer = ((Player) teleportee);
    } else if (teleportee.getPassenger() instanceof Player) {
      teleporteePlayer = ((Player) teleportee.getPassenger());
    }

    if (teleporteePlayer == null) {
      return TeleportResult.FAIL_INVALID;
    }
    MultiverseCore.addPlayerToTeleportQueue(teleporter.getName(), teleporteePlayer.getName());

    Location safeLoc = d.getLocation(teleportee);
    if (d.useSafeTeleporter()) {
      safeLoc = this.getSafeLocation(teleportee, d);
    }

    if (safeLoc != null) {
      if (teleportee.teleport(safeLoc)) {
        if (!d.getVelocity().equals(new Vector(0, 0, 0))) {
          teleportee.setVelocity(d.getVelocity());
        }
        return TeleportResult.SUCCESS;
      }
      return TeleportResult.FAIL_OTHER;
    }
    return TeleportResult.FAIL_UNSAFE;
  }
コード例 #13
0
ファイル: RaiseDead.java プロジェクト: ngseclub/FIGHT
  @Override
  public boolean effect(Player p, Block b) {
    Location loc = b.getLocation().add(0, 1, 0);

    if (!loc.getBlock().isEmpty()) {
      return false;
    }

    for (int x = -1; x <= 1; x++) {
      for (int z = -1; z <= 1; z++) {
        Location l = loc;
        Effects.play(l.add(x, 0, z), Effect.TILE_BREAK, NUM);
      }
    }
    Zombie z = p.getWorld().spawn(loc, Zombie.class);

    for (Entity e : p.getNearbyEntities(20, 20, 20)) {
      if (e instanceof Player && !e.equals(p)) {
        z.setTarget((Player) e);
        break;
      }
    }

    return true;
  }
コード例 #14
0
ファイル: Bows.java プロジェクト: FriedCream/lol-
 @EventHandler
 public void onland(ProjectileHitEvent e) {
   if (!Api.allowsPVP(e.getEntity())) return;
   if (Arrow.containsKey(e.getEntity())) {
     Entity arrow = e.getEntity();
     if (Enchant.get(arrow).equalsIgnoreCase("Boom")) {
       if (Api.isEnchantmentEnabled("Boom")) {
         if (Api.randomPicker(6 - Api.getPower(Arrow.get(arrow) + "", Api.getEnchName("Boom")))) {
           TNTPrimed tnt = arrow.getWorld().spawn(arrow.getLocation(), TNTPrimed.class);
           tnt.setFuseTicks(0);
           tnt.getWorld().playEffect(tnt.getLocation(), Effect.EXPLOSION_LARGE, 1);
           Explode.add(tnt);
           arrow.remove();
         }
       }
       Arrow.remove(arrow);
     }
     if (Enchant.get(arrow).equalsIgnoreCase("Lightning")) {
       if (Api.isEnchantmentEnabled("Lightning")) {
         Location loc = arrow.getLocation();
         if (Api.randomPicker(5)) {
           loc.getWorld().strikeLightning(loc);
         }
       }
     }
   }
 }
コード例 #15
0
 private Entity getTopPassenger(Entity entity) {
   if (entity.getPassenger() != null) {
     return getTopPassenger(entity.getPassenger());
   } else {
     return entity;
   }
 }
コード例 #16
0
ファイル: DamageListener.java プロジェクト: Destro168/FC_Rpg
  @EventHandler(priority = EventPriority.HIGH)
  public void onEntityDamage(EntityDamageEvent event_) {
    // If the event is cancelled, then we want to return.
    if (event_.isCancelled() == true) return;

    // Block damage in creative world.
    WorldConfig wm = new WorldConfig();

    if (!wm.getIsRpg(event_.getEntity().getWorld().getName())) return;

    // Store event.
    event = event_;

    // Set defaults.
    setGlobalDefaults();

    // Always set event damage to 0.
    event.setDamage(0);

    boolean dealEnviromentalDamage = false;

    // For entity damage events we want to handle the attck normally.
    if (event instanceof EntityDamageByEntityEvent) {
      Entity damager = ((EntityDamageByEntityEvent) event).getDamager();

      if (damager.getType() == EntityType.WITHER) dealEnviromentalDamage = true;
      else if (damager.getType() == EntityType.WITHER_SKULL) dealEnviromentalDamage = true;
      else if (damager.getType() == EntityType.SPLASH_POTION) dealEnviromentalDamage = true;
      else if (damager.getType() == EntityType.PRIMED_TNT) dealEnviromentalDamage = true;
      else entityAttack((EntityDamageByEntityEvent) event, -1);
    } else dealEnviromentalDamage = true;

    // Else we want to deal the damage to the player/mob as though not from an entity.
    if (dealEnviromentalDamage == true) {
      // If the defender is a player, then we attacker player defender.
      if (event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();

        // Prevent damage done to already dead players
        if (FC_Rpg.rpgEntityManager.getRpgPlayer(player).playerConfig.getIsActive() == true) {
          if (FC_Rpg.rpgEntityManager.getRpgPlayer(player).getIsAlive() == false) return;
        }

        // Prepare the defender.
        prepareDefender(player);

        double damage = getEnviromentalDamage(player);

        if (damage == 0) return;

        // Attack the player with enviromental damage.
        edm.attackPlayerDefender(
            rpgDefender, null, null, damage, damageType, event.getCause().toString());
      } else {
        // If the event entity is a livingentity and the damage isn't fall damage, then nuke.
        if (event.getCause() != DamageCause.FALL && event.getEntity() instanceof LivingEntity)
          edm.nukeMob((LivingEntity) event.getEntity());
      }
    }
  }
コード例 #17
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void stackPlayer(PlayerInteractEntityEvent event) {
    // Do nothing if clicked entity is not a player.
    if (!(event.getRightClicked() instanceof Player)) return;

    // Do nothing if player does not have permission.
    Player player = event.getPlayer();
    if (!Perm.PLAYERSTACKER.has(player)) return;

    // Do nothing if clicking player is not stacking.
    User user = plugin.getUser(player.getUniqueId());
    if (user != null && !user.isStacking()) return;

    // Do nothing if clicked player is not stacking.
    Player clicked = (Player) event.getRightClicked();
    user = plugin.getUser(clicked.getUniqueId());
    if (user != null && !user.isStacking()) return;

    // Do nothing if player or clicked player are inside a vehicle.
    if (clicked.isInsideVehicle() || player.isInsideVehicle()) return;

    // Stack the player.
    Entity topPassenger = getTopPassenger(player);
    topPassenger.setPassenger(clicked);
  }
コード例 #18
0
  /**
   * Monitor EntityDamageByEntity events.
   *
   * @param event The event to monitor
   */
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    if (event instanceof FakeEntityDamageByEntityEvent) {
      return;
    }

    Entity defender = event.getEntity();
    Entity attacker = event.getDamager();

    if (attacker instanceof Player && defender instanceof Player) {
      if (!defender.getWorld().getPVP()) {
        return;
      }

      if (Party.getInstance().inSameParty((Player) defender, (Player) attacker)) {
        event.setCancelled(true);
        return;
      }
    }

    /* Check for invincibility */
    if (defender instanceof LivingEntity) {
      LivingEntity livingDefender = (LivingEntity) defender;

      if (!m.isInvincible(livingDefender, event)) {
        // Make sure event isn't cancelled before trying to proc?
        if (!event.isCancelled()) Combat.combatChecks(event, plugin);
      }
    }
  }
コード例 #19
0
ファイル: HologramTest.java プロジェクト: ShootGame/Arcade
  @Override
  public void execute(Sender sender, String[] args) throws CommandException {
    Player player = (Player) sender;

    if (args[0].equals("-k")) {
      int i = 0;
      Iterator<Entity> it = new ArrayList<>(BukkitLocation.getWorld().getEntities()).iterator();

      while (it.hasNext()) {
        Entity entity = it.next();

        if (entity instanceof ArmorStand
            && this.matchLocation(entity.getLocation(), player.getLocation())) {
          entity.remove();
          i++;
        }
      }

      if (i == 0) {
        player.sendError("Brak hologramów w tej lokalizacji.");
      } else {
        player.sendSuccess("Usunieto " + i + " hologramów.");
      }
    } else {
      String value = Color.translate(StringUtils.join(args, ' ')) + Color.RESET;

      Hologram hologram = Holograms.create((player).getLocation());
      hologram.setHologram(value);
      hologram.update();

      player.sendSuccess("Stworzono hologram \"" + value + Color.GREEN + "\".");
    }
  }
コード例 #20
0
ファイル: EndWorldHandler.java プロジェクト: OhBlihv/NPlugins
 /** Counts: - EnderDragons - EnderCrystals */
 private void countEntities() {
   if (this.endWorld.getEnvironment() == Environment.THE_END) {
     this.plugin.getLogger().info("Counting existing EDs in " + this.endWorld.getName() + "...");
     for (final EndChunk c : this.chunks.getSafeChunksList()) {
       if (this.endWorld.isChunkLoaded(c.getX(), c.getZ())) {
         final Chunk chunk = this.endWorld.getChunkAt(c.getX(), c.getZ());
         for (final Entity e : chunk.getEntities()) {
           if (e.getType() == EntityType.ENDER_DRAGON) {
             final EnderDragon ed = (EnderDragon) e;
             if (!this.dragons.containsKey(ed.getUniqueId())) {
               ed.setMaxHealth(this.config.getEdHealth());
               ed.setHealth(ed.getMaxHealth());
               this.dragons.put(ed.getUniqueId(), new HashMap<String, Double>());
               this.loadedDragons.add(ed.getUniqueId());
             }
           } else if (e.getType() == EntityType.ENDER_CRYSTAL) {
             c.addCrystalLocation(e);
           }
         }
       } else {
         this.endWorld.loadChunk(c.getX(), c.getZ());
         c.resetSavedDragons();
         this.endWorld.unloadChunkRequest(c.getX(), c.getZ());
       }
     }
     this.plugin
         .getLogger()
         .info("Done, " + this.getNumberOfAliveEnderDragons() + " EnderDragon(s) found.");
   }
 }
コード例 #21
0
  @Override
  public void run() {
    long worldTime = world.getTime();

    if (worldTime < 13000 || worldTime > 23000) {
      return;
    }

    spawn:
    for (Chunk chunk : world.getLoadedChunks()) {
      if (this.random.nextInt(100) == 1) {
        int x = (chunk.getX() * 16) + this.random.nextInt(12) + 2;
        int z = (chunk.getZ() * 16) + this.random.nextInt(12) + 2;
        int y = world.getHighestBlockYAt(x, z);

        Location spawnLocation = new Location(world, x, y, z);

        for (Entity entity : this.world.getLivingEntities()) {
          if (!entity.isDead() && entity.getLocation().distanceSquared(spawnLocation) < 1024) {
            continue spawn;
          }
        }

        EntityGiantZombie entity = new EntityGiantZombie(world);

        entity.setPositionRotation(x, y, z, 0, 90);
        ((CraftWorld) world).getHandle().addEntity(entity, SpawnReason.CUSTOM);
        entity.p(null);
      }
    }
  }
コード例 #22
0
 public Entity addRider(Entity vehicle, ISpawnableEntity riderData) {
   Location vehicleLoc = vehicle.getLocation();
   Entity rider = spawnMobAt(riderData, vehicleLoc);
   vehicle.setPassenger(rider);
   spawner.addSecondaryMob(rider.getUniqueId(), vehicle.getUniqueId());
   return rider;
 }
コード例 #23
0
 public void clearNearbyItems() {
   if (item == null) {
     return;
   }
   List<Entity> nearbyEntities = item.getNearbyEntities(7, 7, 7);
   for (Entity entity : nearbyEntities) {
     if (entity instanceof Item) {
       Item nearbyItem = (Item) entity;
       boolean display = false;
       for (MetadataValue cmeta : nearbyItem.getMetadata("HyperConomy")) {
         if (cmeta.asString().equalsIgnoreCase("item_display")) {
           display = true;
           break;
         }
       }
       if (!nearbyItem.equals(item) && !display) {
         if (nearbyItem.getItemStack().getType() == item.getItemStack().getType()) {
           HyperItemStack near = new HyperItemStack(nearbyItem.getItemStack());
           HyperItemStack displayItem = new HyperItemStack(item.getItemStack());
           if (near.getDamageValue() == displayItem.getDamageValue()) {
             entity.remove();
           }
         }
       }
     }
   }
 }
コード例 #24
0
 public static void doBoundingBox(TargetedDisguise disguise) {
   // TODO Slimes
   Entity entity = disguise.getEntity();
   if (entity != null) {
     if (isDisguiseInUse(disguise)) {
       DisguiseValues disguiseValues = DisguiseValues.getDisguiseValues(disguise.getType());
       FakeBoundingBox disguiseBox = disguiseValues.getAdultBox();
       if (disguiseValues.getBabyBox() != null) {
         if ((disguise.getWatcher() instanceof AgeableWatcher
                 && ((AgeableWatcher) disguise.getWatcher()).isBaby())
             || (disguise.getWatcher() instanceof ZombieWatcher
                 && ((ZombieWatcher) disguise.getWatcher()).isBaby())) {
           disguiseBox = disguiseValues.getBabyBox();
         }
       }
       ReflectionManager.setBoundingBox(entity, disguiseBox);
     } else {
       DisguiseValues entityValues =
           DisguiseValues.getDisguiseValues(DisguiseType.getType(entity.getType()));
       FakeBoundingBox entityBox = entityValues.getAdultBox();
       if (entityValues.getBabyBox() != null) {
         if ((entity instanceof Ageable && !((Ageable) entity).isAdult())
             || (entity instanceof Zombie && ((Zombie) entity).isBaby())) {
           entityBox = entityValues.getBabyBox();
         }
       }
       ReflectionManager.setBoundingBox(entity, entityBox);
     }
   }
 }
コード例 #25
0
ファイル: Damage.java プロジェクト: keenerb/ModDamage
  public static EventData getEventData(EntityDamageEvent event) {
    if (event == null) return null;

    DamageType damageElement = DamageType.get(event.getCause());

    Entity attacker = null;
    Projectile projectile = null;
    Entity target = event.getEntity();
    World world = target.getWorld();

    if (event instanceof EntityDamageByEntityEvent) {
      EntityDamageByEntityEvent event_EE = (EntityDamageByEntityEvent) event;
      Entity damager = event_EE.getDamager();

      if (damager instanceof Projectile) {
        projectile = (Projectile) damager;

        attacker = projectile.getShooter();
      } else {
        attacker = damager;
      }
    }

    return myInfo.makeData(
        attacker, projectile, target, world, damageElement, event.getDamage(), event.isCancelled());
  }
コード例 #26
0
 /** Setup it so he can see himself when disguised */
 public static void setupFakeDisguise(final Disguise disguise) {
   Entity e = disguise.getEntity();
   // If the disguises entity is null, or the disguised entity isn't a player return
   if (e == null
       || !(e instanceof Player)
       || !getDisguises().containsKey(e.getUniqueId())
       || !getDisguises().get(e.getUniqueId()).contains(disguise)) {
     return;
   }
   Player player = (Player) e;
   // Check if he can even see this..
   if (!((TargetedDisguise) disguise).canSee(player)) {
     return;
   }
   // Remove the old disguise, else we have weird disguises around the place
   DisguiseUtilities.removeSelfDisguise(player);
   // If the disguised player can't see himself. Return
   if (!disguise.isSelfDisguiseVisible()
       || !PacketsManager.isViewDisguisesListenerEnabled()
       || player.getVehicle() != null) {
     return;
   }
   selfDisguised.add(player.getUniqueId());
   sendSelfDisguise(player, (TargetedDisguise) disguise);
   if (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()) {
     if (PacketsManager.isInventoryListenerEnabled()) {
       player.updateInventory();
     }
   }
 }
コード例 #27
0
 /**
  * Handles explosion block damage caused by TnT, Creepers, or Fireballs.<br>
  * If the arena allows explosion block breaking, each block is handled separately<br>
  * as if a player attempted to destroy it. If the arena doesn't allow explosion block breaking,
  * <br>
  * no blocks are broken.
  */
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onTntExplode(EntityExplodeEvent event) {
   Entity entity = event.getEntity();
   if (entity instanceof TNTPrimed || entity instanceof Creeper || entity instanceof Fireball) {
     Arena arena = ultimateGames.getArenaManager().getLocationArena(entity.getLocation());
     if (arena != null) {
       if (arena.getStatus() == ArenaStatus.RUNNING) {
         if (arena.allowExplosionBlockBreaking()) {
           Set<Block> canBeBroken =
               ultimateGames
                   .getWhitelistManager()
                   .getBlockBreakWhitelist()
                   .blocksWhitelisted(arena.getGame(), new HashSet<Block>(event.blockList()));
           event.blockList().clear();
           event.blockList().addAll(canBeBroken);
           arena.getGame().getGamePlugin().onEntityExplode(arena, event);
         } else if (arena.allowExplosionDamage()) {
           event.blockList().clear();
           arena.getGame().getGamePlugin().onEntityExplode(arena, event);
         } else {
           event.setCancelled(true);
         }
       } else {
         event.setCancelled(true);
       }
     }
   }
 }
コード例 #28
0
  /**
   * Tag creepers hurt by players.
   *
   * <p>Only those creepers hurt recently by players will have special drops.
   */
  @EventHandler(ignoreCancelled = true)
  public void onCreeperDamage(EntityDamageByEntityEvent event) {
    if (!CONFIG.isAffectedWorld(event)) {
      return;
    }

    if (event.getEntityType() == EntityType.CREEPER) {
      boolean isPlayerAttack = false;
      if (event.getDamager() instanceof Player) {
        isPlayerAttack = true;
      } else if (event.getDamager() instanceof Projectile) {
        Projectile projectile = (Projectile) event.getDamager();
        if (projectile.getShooter() instanceof Player) {
          isPlayerAttack = true;
        }
      }

      // Tag creepers hurt by players with the damage time stamp.
      if (isPlayerAttack) {
        Entity creeper = event.getEntity();
        creeper.setMetadata(
            PLAYER_DAMAGE_TIME_KEY,
            new FixedMetadataValue(this, new Long(creeper.getWorld().getFullTime())));
      }
    }
  }
コード例 #29
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void grapple(ProjectileHitEvent event) {
    Entity proj = event.getEntity();
    Location hit = proj.getLocation();

    if (contains(hit, x1, x2, y1, y2, z1, z2) == true) {

      if (proj instanceof Snowball) {
        Snowball fish = (Snowball) proj;
        Entity shooter = fish.getShooter();

        if (shooter instanceof Player) {
          Player p = (Player) shooter;
          Location loc = p.getLocation();
          ItemStack is = p.getItemInHand();
          Material mat = is.getType();

          if (mat == Material.FISHING_ROD) {

            p.setFallDistance(0);
            p.playSound(loc, Sound.ARROW_HIT, 1, 1);

            int hitx = hit.getBlockX();
            int hity = hit.getBlockY();
            int hitz = hit.getBlockZ();
            int locx = loc.getBlockX();
            int locy = loc.getBlockY();
            int locz = loc.getBlockZ();
            double co[] = new double[3];

            if (hitx > locx) {
              co[0] = 1.2;
            } else if (hitx < locx) {
              co[0] = -1.2;
            } else if (hitx == locx) {
              co[0] = 0;
            }

            if (hity > locy) {
              co[1] = 1.4;
            } else if (hity < locy) {
              co[1] = -0.8;
            } else if (hity == locy) {
              co[1] = 0;
            }

            if (hitz > locz) {
              co[2] = 1.2;
            } else if (hitz < locz) {
              co[2] = -1.2;
            } else if (hitz == locz) {
              co[2] = 0;
            }

            p.setVelocity(new Vector(co[0], co[1], co[2]));
          }
        }
      }
    }
  }
コード例 #30
0
  public void rollback(final int id, final boolean shutdown) {
    loadSave(id);
    if (!shutdown) {
      Bukkit.getScheduler()
          .scheduleSyncDelayedTask(
              GameManager.getInstance().getPlugin(), new Rollback(id, shutdown));
    } else {
      new Rollback(id, shutdown).run();
    }
    ArrayList<Entity> removelist = new ArrayList<Entity>();

    if (SettingsManager.getGameWorld(id) == null) {
      return;
    }
    for (Entity e : SettingsManager.getGameWorld(id).getEntities()) {
      if ((!(e instanceof Player)) && (!(e instanceof HumanEntity))) {
        if (GameManager.getInstance().getBlockGameId(e.getLocation()) == id) {
          removelist.add(e);
        }
      }
    }
    for (int a = 0; a < removelist.size(); a = 0) {
      try {
        removelist.remove(0).remove();
      } catch (Exception e) {
      }
    }
  }