Exemplo n.º 1
0
  /**
   * 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;
  }
Exemplo n.º 2
0
 /**
  * Gets the Collision Mode for colliding with the Entity specified
  *
  * @param entity to collide with
  * @return Collision Mode
  */
 public CollisionMode getCollisionMode(Entity entity) {
   if (!this.getColliding() || entity.isDead()) {
     return CollisionMode.CANCEL;
   }
   MinecartMember<?> member = MinecartMemberStore.get(entity);
   if (member != null) {
     if (this.trainCollision == CollisionMode.LINK) {
       if (member.getGroup().getProperties().trainCollision == CollisionMode.LINK) {
         return CollisionMode.LINK;
       } else {
         return CollisionMode.CANCEL;
       }
     } else {
       return this.trainCollision;
     }
   } else if (entity instanceof Player) {
     if (TrainCarts.collisionIgnoreOwners && this.playerCollision != CollisionMode.DEFAULT) {
       if (TrainCarts.collisionIgnoreGlobalOwners) {
         if (CartProperties.hasGlobalOwnership((Player) entity)) {
           return CollisionMode.DEFAULT;
         }
       }
       if (this.hasOwnership((Player) entity)) {
         return CollisionMode.DEFAULT;
       }
     }
     return this.playerCollision;
   } else if (EntityUtil.isMob(entity)) {
     return this.mobCollision;
   } else {
     return this.miscCollision;
   }
 }
Exemplo n.º 3
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);
      }
    }
  }
Exemplo n.º 4
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();
        }
      }
    }
  }
Exemplo n.º 5
0
  @Override
  public SpellResult perform(CastContext context) {
    Entity entity = context.getTargetEntity();
    if (entity == null || !(entity instanceof Damageable) || entity.isDead()) {
      return SpellResult.NO_TARGET;
    }

    double damage = 1;

    Damageable targetEntity = (Damageable) entity;
    LivingEntity livingTarget = (entity instanceof LivingEntity) ? (LivingEntity) entity : null;
    context.registerDamaged(targetEntity);
    Mage mage = context.getMage();
    MageController controller = context.getController();

    double previousKnockbackResistance = 0D;
    try {
      if (knockbackResistance != null && livingTarget != null) {
        AttributeInstance knockBackAttribute =
            livingTarget.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
        previousKnockbackResistance = knockBackAttribute.getBaseValue();
        knockBackAttribute.setBaseValue(knockbackResistance);
      }
      if (controller.isElemental(entity)) {
        damage = elementalDamage;
        controller.damageElemental(
            entity, damage * mage.getDamageMultiplier(), 0, mage.getCommandSender());
      } else {
        if (percentage != null) {
          damage = percentage * targetEntity.getMaxHealth();
        } else if (targetEntity instanceof Player) {
          damage = playerDamage;
        } else {
          damage = entityDamage;
        }
        damage *= mage.getDamageMultiplier();
        if (magicDamage && (magicEntityDamage || targetEntity instanceof Player)) {
          CompatibilityUtils.magicDamage(targetEntity, damage, mage.getEntity());
        } else {
          CompatibilityUtils.damage(targetEntity, damage, mage.getEntity());
        }
      }
    } finally {
      if (knockbackResistance != null && livingTarget != null) {
        AttributeInstance knockBackAttribute =
            livingTarget.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
        knockBackAttribute.setBaseValue(previousKnockbackResistance);
      }
    }

    return SpellResult.CAST;
  }
  /** Check win * */
  private void checkWin() {
    for (Player p : Bukkit.getOnlinePlayers()) {
      if (points.containsKey(p.getName())) {
        if (points.get(p.getName()) == 15) {
          /** Clear inventories * */
          for (Player t : Bukkit.getOnlinePlayers()) {
            t.getInventory().clear();

            t.setLevel(0);
            p.setExp(0f);
          }

          /** Bukkit task * */
          runnable.cancel();

          /** Remove chickens * */
          for (Entity e : chickens) {
            if (!e.isDead()) e.remove();
          }

          /** Broadcast * */
          Bukkit.broadcastMessage(MTP.PREFIX + "" + p.getName() + " �at gewonnen!");

          /** Sounds * */
          for (Player tp : Bukkit.getOnlinePlayers()) {
            if (tp == p) {
              /** Points * */
              MTP.points.put(p.getName(), MTP.points.get(p.getName()) + 1);

              tp.playSound(tp.getLocation(), "win", 1, 1);
            } else tp.playSound(tp.getLocation(), "lose", 1, 1);
          }

          /** Runnable * */
          new BukkitRunnable() {
            public void run() {
              end();
            }
          }.runTaskLater(MTP.getPlugin(), 10 * 20L);

          /** Break * */
          break;
        }
      }
    }
  }
Exemplo n.º 7
0
  /**
   * Returns true if the entity was damaged.
   *
   * @return
   */
  protected boolean hurt() {

    int radius = 10; // Default Radius
    int damage = 2;
    Location location = getSign().getLocation();
    Type type = Type.MOB_HOSTILE;
    try {
      radius = Integer.parseInt(getSign().getLine(2).split("=")[0]);
      if (getSign().getLine(2).contains("=")) {
        int x = Integer.parseInt(getSign().getLine(2).split("=")[1].split(":")[0]);
        int y = Integer.parseInt(getSign().getLine(2).split("=")[1].split(":")[1]);
        int z = Integer.parseInt(getSign().getLine(2).split("=")[1].split(":")[2]);
        location.add(x, y, z);

        damage = Integer.parseInt(getSign().getLine(2).split("=")[2]);
      }
    } catch (Exception e) {
    }

    if (getSign().getLine(3).length() != 0) type = Type.fromString(getSign().getLine(3));

    try {
      for (Entity e : LocationUtil.getNearbyEntities(location, radius)) {
        if (e.isDead() || !e.isValid()) continue;
        if (!type.is(e)) continue;
        if (e instanceof LivingEntity) ((LivingEntity) e).damage(damage);
        else if (e instanceof Minecart)
          ((Minecart) e).setDamage(((Minecart) e).getDamage() + damage);
        else e.remove();
        return true;
      }
    } catch (Exception e) {
    }

    return false;
  }
Exemplo n.º 8
0
  public void target(TargetMode mode) {
    targetMode = mode == null ? TargetMode.STABILIZE : mode;
    switch (targetMode) {
      case FLEE:
      case HUNT:
      case DIRECTED:
        Target bestTarget = null;
        reverseTargetDistanceScore = true;
        if (targetType == TargetType.ANY || targetType == TargetType.MOB) {
          List<Entity> entities =
              CompatibilityUtils.getNearbyEntities(
                  center, huntMaxRange, huntMaxRange, huntMaxRange);
          for (Entity entity : entities) {
            // We'll get the players from the Mages list
            if (entity instanceof Player || !(entity instanceof LivingEntity) || entity.isDead())
              continue;
            if (!entity.getLocation().getWorld().equals(center.getWorld())) continue;
            LivingEntity li = (LivingEntity) entity;
            if (li.hasPotionEffect(PotionEffectType.INVISIBILITY)) continue;
            Target newScore =
                new Target(center, entity, huntMinRange, huntMaxRange, huntFov, false);
            int score = newScore.getScore();
            if (bestTarget == null || score > bestTarget.getScore()) {
              bestTarget = newScore;
            }
          }
        }
        if (targetType == TargetType.MAGE
            || targetType == TargetType.AUTOMATON
            || targetType == TargetType.ANY
            || targetType == TargetType.PLAYER) {
          Collection<Mage> mages = controller.getMages();
          for (Mage mage : mages) {
            if (mage == this.mage) continue;
            if (targetType == TargetType.AUTOMATON && mage.getPlayer() != null) continue;
            if (targetType == TargetType.PLAYER && mage.getPlayer() == null) continue;
            if (mage.isDead() || !mage.isOnline() || !mage.hasLocation()) continue;
            if (!mage.getLocation().getWorld().equals(center.getWorld())) continue;
            if (!mage.getLocation().getWorld().equals(center.getWorld())) continue;

            if (!mage.isPlayer()) {
              // Check for automata of the same type, kinda hacky.. ?
              Block block = mage.getLocation().getBlock();
              if (block.getType() == Material.COMMAND) {
                BlockState blockState = block.getState();
                if (blockState != null && blockState instanceof CommandBlock) {
                  CommandBlock command = (CommandBlock) blockState;
                  String commandString = command.getCommand();
                  if (commandString != null
                      && commandString.length() > 0
                      && commandString.startsWith("cast " + spell.getKey())) {
                    continue;
                  }
                }
              }
            } else {
              Player player = mage.getPlayer();
              if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) continue;
            }

            Target newScore = new Target(center, mage, huntMinRange, huntMaxRange, huntFov, false);
            int score = newScore.getScore();
            if (bestTarget == null || score > bestTarget.getScore()) {
              bestTarget = newScore;
            }
          }
        }

        if (bestTarget != null) {
          String targetDescription =
              bestTarget.getEntity() == null
                  ? "NONE"
                  : ((bestTarget instanceof Player)
                      ? ((Player) bestTarget.getEntity()).getName()
                      : bestTarget.getEntity().getType().name());

          if (DEBUG) {
            controller
                .getLogger()
                .info(
                    " *Tracking "
                        + targetDescription
                        + " score: "
                        + bestTarget.getScore()
                        + " location: "
                        + center
                        + " -> "
                        + bestTarget.getLocation()
                        + " move "
                        + commandMoveRangeSquared);
          }
          Vector direction = null;

          if (targetMode == TargetMode.DIRECTED) {
            direction = bestTarget.getLocation().getDirection();
            if (DEBUG) {
              controller.getLogger().info(" *Directed: " + direction);
            }
          } else {
            Location targetLocation = bestTarget.getLocation();
            direction = targetLocation.toVector().subtract(center.toVector());
          }

          if (direction != null) {
            center.setDirection(direction);
          }

          // Check for obstruction
          // TODO Think about this more..
          /*
          Block block = spell.getInteractBlock();
          if (block.getType() != Material.AIR && block.getType() != POWER_MATERIAL && !!birthMaterial.is(block)) {
          	// TODO: Use location.setDirection in 1.7+
          	center = CompatibilityUtils.setDirection(center, new Vector(0, 1, 0));
          }
          */

          if (level != null
              && center.distanceSquared(bestTarget.getLocation()) < castRange * castRange) {
            level.onTick(mage, birthMaterial);
          }

          // After ticking, re-position for movement. This way spells still fire towards the target.
          if (targetMode == TargetMode.FLEE) {
            direction = direction.multiply(-1);
            // Don't Flee upward
            if (direction.getY() > 0) {
              direction.setY(-direction.getY());
            }
          }
        }
        break;
      case GLIDE:
        reverseTargetDistanceScore = true;
        break;
      default:
        reverseTargetDistanceScore = false;
    }
  }
Exemplo n.º 9
0
 public boolean isDead() {
   return e.isDead();
 }