示例#1
1
  public void lookAtPoint(Location origLocation, Location newLocation) {
    if (this.getWorld() != newLocation.getWorld()) {
      return;
    }
    double xDiff = newLocation.getX() - origLocation.getX();
    double yDiff = newLocation.getY() - origLocation.getY();
    double zDiff = newLocation.getZ() - origLocation.getZ();
    double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
    double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
    double newYaw = (Math.acos(xDiff / DistanceXZ) * 180 / Math.PI);
    double newPitch = (Math.acos(yDiff / DistanceY) * 180 / Math.PI) - 90;

    if (zDiff < 0.0) {
      newYaw = newYaw + (Math.abs(180 - newYaw) * 2);
    }

    getHandle().yaw = (float) (newYaw - 90);
    getHandle().pitch = (float) newPitch;
    getHandle().X = (float) (newYaw - 90);
    getHandle()
        .setPositionRotation(
            getHandle().locX,
            getHandle().locY,
            getHandle().locZ,
            (float) (newYaw - 90),
            (float) newPitch);
  }
示例#2
1
  public Location getFaceLocationFromMe(Location location) {
    try {
      // citizens - https://github.com/fullwall/Citizens
      Location loc = this.getBukkitEntity().getLocation();
      double xDiff = location.getX() - loc.getX();
      double yDiff = location.getY() - loc.getY();
      double zDiff = location.getZ() - loc.getZ();

      double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
      double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
      double yaw = (Math.acos(xDiff / DistanceXZ) * 180 / Math.PI);
      double pitch = (Math.acos(yDiff / DistanceY) * 180 / Math.PI) - 90;
      if (zDiff < 0.0) {
        yaw = yaw + (Math.abs(180 - yaw) * 2);
      }
      Location finalloc =
          new Location(
              loc.getWorld(), loc.getX(), loc.getY(), loc.getZ(), (float) yaw - 90, (float) pitch);
      return finalloc;

    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
示例#3
0
  private void playOutExplosion(GlowPlayer player, Iterable<BlockVector> blocks) {
    Collection<ExplosionMessage.Record> records = new ArrayList<>();

    Location clientLoc = location.clone();
    clientLoc.setX((int) clientLoc.getX());
    clientLoc.setY((int) clientLoc.getY());
    clientLoc.setZ((int) clientLoc.getZ());

    for (BlockVector block : blocks) {
      byte x = (byte) (block.getBlockX() - clientLoc.getBlockX());
      byte y = (byte) (block.getBlockY() - clientLoc.getBlockY());
      byte z = (byte) (block.getBlockZ() - clientLoc.getBlockZ());
      records.add(new ExplosionMessage.Record(x, y, z));
    }

    Vector velocity = player.getVelocity();
    ExplosionMessage message =
        new ExplosionMessage(
            (float) location.getX(),
            (float) location.getY(),
            (float) location.getZ(),
            5,
            (float) velocity.getX(),
            (float) velocity.getY(),
            (float) velocity.getZ(),
            records);

    player.getSession().send(message);
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlock();

    // Deny GameWorld Blocks
    GameWorld gworld = GameWorld.get(block.getWorld());
    if (gworld != null) {
      if (!GamePlaceableBlock.canBuildHere(
          block, block.getFace(event.getBlockAgainst()), event.getItemInHand().getType(), gworld)) {

        // Workaround for a bug that would allow 3-Block-high jumping
        Location loc = event.getPlayer().getLocation();
        if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) {
          if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) {
            if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) {
              loc.setX(block.getX() + 0.5);
              loc.setY(block.getY());
              loc.setZ(block.getZ() + 0.5);
              event.getPlayer().teleport(loc);
            }
          }
        }
        event.setCancelled(true);
      }
    }
  }
示例#5
0
  public static Location lookAt(Location loc, Location lookat) {

    loc = loc.clone();

    double dx = lookat.getX() - loc.getX();
    double dy = lookat.getY() - loc.getY();
    double dz = lookat.getZ() - loc.getZ();

    if (dx != 0) {
      if (dx < 0) {
        loc.setYaw((float) (1.5 * Math.PI));
      } else {
        loc.setYaw((float) (0.5 * Math.PI));
      }
      loc.setYaw(loc.getYaw() - (float) Math.atan(dz / dx));
    } else if (dz < 0) {
      loc.setYaw((float) Math.PI);
    }

    double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2));

    loc.setPitch((float) -Math.atan(dy / dxz));

    loc.setYaw(-loc.getYaw() * 180f / (float) Math.PI);
    loc.setPitch(loc.getPitch() * 180f / (float) Math.PI);

    return loc;
  }
示例#6
0
 // currently unused
 public static boolean getWithinDistanceToForceField(int distance, Location loc) {
   if (Math.abs(loc.getZ() - loc.getZ()) > Config.forcefieldSideLength - distance
       || Math.abs(loc.getX() - loc.getX()) > Config.forcefieldSideLength - distance) {
     return true;
   }
   return false;
 }
  static Location jitter(final Location teamSpawn, int index) {
    if (index == 0) return teamSpawn;
    index = index % 6;
    Location loc = teamSpawn.clone();

    switch (index) {
      case 0:
        break;
      case 1:
        loc.setX(loc.getX() - 1);
        break;
      case 2:
        loc.setX(loc.getX() + 1);
        break;
      case 3:
        loc.setZ(loc.getZ() - 1);
        break;
      case 4:
        loc.setZ(loc.getZ() + 1);
        break;
      case 5:
        loc.setX(loc.getX() + rand.nextDouble() - 0.5);
        loc.setZ(loc.getZ() + rand.nextDouble() - 0.5);
    }
    return loc;
  }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPlayerMove(PlayerMoveEvent event) {

    // BAD BAD BAD test code
    //	hwh.randomlyRegisterWorld(event.getPlayer().getWorld());

    Location to = event.getTo();
    int newY = to.getBlockY();
    if (newY < HigherWorldsHack.SHARE_HEIGHT) {
      Player p = event.getPlayer();
      World w = worldStack.get(event.getTo().getWorld());
      if (w == null) return;
      Location toTeleportTo =
          new Location(w, to.getX(), HigherWorldsHack.transformPosUp(newY), to.getZ());
      HigherWorldsHack.HWH_LOGGER.log(
          Level.WARNING, "Player moved from " + to + " to " + toTeleportTo);
      p.teleport(toTeleportTo);
    } else if (newY > HigherWorldsHack.WORLD_HEIGHT - HigherWorldsHack.SHARE_HEIGHT) {
      Player p = event.getPlayer();
      World w = worldStack.inverse().get(event.getTo().getWorld());
      if (w == null) return;
      Location toTeleportTo =
          new Location(w, to.getX(), HigherWorldsHack.transformPosDown(newY), to.getZ());
      HigherWorldsHack.HWH_LOGGER.log(
          Level.WARNING, "Player moved from " + to + " to " + toTeleportTo);
      p.teleport(toTeleportTo);
    }
  }
 public void sendToSpawn(Gamer gamer) {
   final Player p = gamer.getPlayer();
   Location originalSpawn = p.getWorld().getSpawnLocation();
   MainConfig main = HungergamesApi.getConfigManager().getMainConfig();
   int spawnRadius = main.getSpawnRadius();
   int spawnHeight = main.getSpawnHeight();
   if (spawns.size() > 0) {
     if (spawnItel == null || !spawnItel.hasNext()) spawnItel = spawns.keySet().iterator();
     originalSpawn = spawnItel.next();
     spawnRadius = Math.max(1, spawns.get(originalSpawn)[0]);
     spawnHeight = Math.max(1, spawns.get(originalSpawn)[1]);
   }
   Location spawn = originalSpawn.clone();
   int chances = 0;
   if (p.isInsideVehicle()) p.leaveVehicle();
   p.eject();
   while (chances < main.getTimesToCheckForValidSpawnPerPlayer()) {
     chances++;
     Location newLoc =
         new Location(
             p.getWorld(),
             spawn.getX() + returnChance(-spawnRadius, spawnRadius),
             spawn.getY() + new Random().nextInt(spawnHeight),
             spawn.getZ() + returnChance(-spawnRadius, spawnRadius));
     if (nonSolid.contains(newLoc.getBlock().getTypeId())
         && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.UP).getTypeId())) {
       while (newLoc.getBlockY() >= 1
           && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.DOWN).getTypeId())) {
         newLoc = newLoc.add(0, -1, 0);
       }
       if (newLoc.getBlockY() <= 1) continue;
       spawn = newLoc;
       break;
     }
   }
   if (spawn.equals(originalSpawn)) {
     spawn =
         new Location(
             p.getWorld(),
             spawn.getX() + returnChance(-spawnRadius, spawnRadius),
             0,
             spawn.getZ() + returnChance(-spawnRadius, spawnRadius));
     spawn.setY(spawn.getWorld().getHighestBlockYAt(spawn));
     if (gamer.isAlive() && spawn.getY() <= 1) {
       spawn.getBlock().setType(Material.GLASS);
       spawn.setY(spawn.getY() + 1);
     }
   }
   final Location destination = spawn.add(0.5, 0.1, 0.5);
   p.teleport(destination);
   Bukkit.getScheduler()
       .scheduleSyncDelayedTask(
           hg,
           new Runnable() {
             public void run() {
               p.teleport(destination);
             }
           });
 }
示例#10
0
 public static void moveAway(Entity entity, Location center, double speed) {
   Location loc = entity.getLocation();
   double x = loc.getX() - center.getX();
   double y = loc.getY() - center.getY();
   double z = loc.getZ() - center.getZ();
   Vector vel = new Vector(x, y, z).normalize().multiply(speed);
   entity.setVelocity(vel);
 }
示例#11
0
  private boolean isInDropOffArea(Location loc) {
    if (loc.getY() < dropOffCenter.getY() || loc.getY() > dropOffCenter.getY() + 4) return false;

    return loc.getX() > dropOffCenter.getX() - 3
        && loc.getX() < dropOffCenter.getX() + 4
        && loc.getZ() > dropOffCenter.getZ() - 3
        && loc.getZ() < dropOffCenter.getZ() + 4;
  }
 public double getDistance(Player player1, Player player2) {
   Location loc1 = player1.getLocation();
   Location loc2 = player1.getLocation();
   return Math.sqrt(
       Math.pow(loc1.getX() - loc2.getX(), 2)
           + Math.pow(loc1.getY() - loc2.getY(), 2)
           + Math.pow(loc1.getZ() - loc2.getZ(), 2));
 }
示例#13
0
  public void update() {
    if (particles) {
      world.playEffect(location, Effect.SMOKE, 1);
      world.playEffect(location, Effect.MOBSPAWNER_FLAMES, 1);
    }

    if (!anyPlayerInRange()) return;

    if (delay == -1) updateDelay();

    if (delay > 0) {
      delay--;
      return;
    }

    byte byte0 = 4;

    for (int i = 0; i < byte0; i++) {
      Entity entity2;
      EntityLiving entityliving = (EntityLiving) entity;
      if (entityliving == null) return;

      net.minecraft.server.v1_4_R1.World worldObj = ((CraftWorld) location.getWorld()).getHandle();
      int j =
          worldObj
              .getEntities(
                  entityliving,
                  AxisAlignedBB.a(
                          location.getX(),
                          location.getY(),
                          location.getZ(),
                          location.getX() + 1,
                          location.getY() + 1,
                          location.getZ() + 1)
                      .a(8D, 4D, 8D))
              .size();

      if (j >= 6) {
        updateDelay();
        return;
      }

      double d3 =
          location.getX() + (worldObj.random.nextDouble() - worldObj.random.nextDouble()) * 4D;
      double d4 = (location.getY() + worldObj.random.nextInt(3)) - 1;
      double d5 =
          location.getZ() + (worldObj.random.nextDouble() - worldObj.random.nextDouble()) * 4D;
      entityliving.setPositionRotation(d3, d4, d5, worldObj.random.nextFloat() * 360F, 0.0F);

      if (entityliving.canSpawn()) {
        worldObj.addEntity(entityliving);
        // worldObj.playNote(2004, location.getBlockX(), location.getBlockY(), location.getBlockZ(),
        // 0, 0);
        // entityliving.spawnExplosionParticle();
        updateDelay();
      }
    }
  }
示例#14
0
 /**
  * Add exact coordinates, multiple lines. No leading new line.
  *
  * @param from
  * @param to
  * @param loc Reference location for from, usually Player.getLocation().
  * @param builder
  */
 public static void addMove(
     final Location from, final Location to, final Location loc, final StringBuilder builder) {
   if (loc != null && !TrigUtil.isSamePos(from, loc)) {
     builder.append("Location: ");
     addLocation(loc, builder);
     builder.append("\n");
   }
   addMove(from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), builder);
 }
示例#15
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void playerWalk(PlayerMoveEvent event) {
   // Player Moved
   int walkingBoots = config.getInt("walking_boots", 3);
   Player player = event.getPlayer();
   Location fromLoc = event.getFrom();
   Location toLoc = event.getTo();
   int fromX = (int) fromLoc.getX();
   int fromZ = (int) fromLoc.getZ();
   int toX = (int) toLoc.getX();
   int toZ = (int) toLoc.getZ();
   if ((fromX != toX || fromZ != toZ)
       && player.hasPermission("walkthewalk.use")
       && !player.isInsideVehicle()) {
     // Player moved to a new block, and has permission
     boolean rightBoots = false;
     if (walkingBoots != 0) {
       int invBoots = 0;
       if (player.getInventory().getBoots() != null) {
         invBoots = player.getInventory().getBoots().getTypeId();
       }
       if (invBoots == 301 && walkingBoots == 1) {
         // Leather Boots
         rightBoots = true;
       } else if (invBoots == 309 && walkingBoots == 2) {
         // Iron Boots
         rightBoots = true;
       } else if (invBoots == 317 && walkingBoots == 3) {
         // Gold Boots
         rightBoots = true;
       } else if (invBoots == 313 && walkingBoots == 4) {
         // Diamond Boots
         rightBoots = true;
       } else if (invBoots == 305 && walkingBoots == 5) {
         // Chain Boots
         rightBoots = true;
       }
     } else {
       rightBoots = true;
     }
     if (rightBoots) {
       // Player was wearing the right boots
       int xpBoost = config.getInt("xp_boost", 1);
       int boostBlocks = config.getInt("boost_blocks", 10);
       double rounding = 0.00;
       if (xpRounding.get(player.getName()) != null) {
         rounding = xpRounding.get(player.getName());
       }
       rounding += (double) xpBoost / boostBlocks;
       if (rounding >= xpBoost) {
         rounding -= xpBoost;
         player.giveExp(xpBoost);
       }
       xpRounding.put(player.getName(), rounding);
     }
   }
 }
示例#16
0
 /**
  * Calculates the distance in 2d (x,z)
  *
  * @param loc1 location of the first entity
  * @param loc2 location of the first entity
  * @return The distant
  */
 public static double calcDistance2d(Location loc1, Location loc2) {
   if (loc1.getWorld().equals(loc2.getWorld())) {
     double x = Math.pow(loc1.getX() - loc2.getX(), 2);
     double z = Math.pow(loc1.getZ() - loc2.getZ(), 2);
     return Math.sqrt(x + z);
   } else {
     return Integer.MAX_VALUE;
   }
 }
示例#17
0
  public static int point_distance(Location loc1, Location loc2) {
    int p1x = (int) loc1.getX();
    int p1y = (int) loc1.getY();
    int p1z = (int) loc1.getZ();

    int p2x = (int) loc2.getX();
    int p2y = (int) loc2.getY();
    int p2z = (int) loc2.getZ();
    return (int) magnitude(p1x, p1y, p1z, p2x, p2y, p2z);
  }
示例#18
0
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onItemSpawn(ItemSpawnEvent event) {
   Location loc = event.getLocation();
   if (dropOffCenter != null
       && loc.getX() > dropOffCenter.getX() - 80
       && loc.getX() < dropOffCenter.getX() + 80
       && loc.getZ() > dropOffCenter.getZ() - 80
       && loc.getZ() < dropOffCenter.getZ() + 80) {
     event.setCancelled(true);
   }
 }
示例#19
0
 private Vector getDirection(Location location, Location destination) {
   double x1, y1, z1;
   double x0, y0, z0;
   x1 = destination.getX();
   y1 = destination.getY();
   z1 = destination.getZ();
   x0 = location.getX();
   y0 = location.getY();
   z0 = location.getZ();
   return new Vector(x1 - x0, y1 - y0, z1 - z0);
 }
示例#20
0
 /**
  * Checks if location is anywhere in the island space (island distance)
  *
  * @param target
  * @return true if in the area
  */
 public boolean inIslandSpace(Location target) {
   if (target.getWorld().equals(ASkyBlock.getIslandWorld())
       || target.getWorld().equals(ASkyBlock.getNetherWorld())) {
     if (target.getX() >= center.getBlockX() - islandDistance / 2
         && target.getX() < center.getBlockX() + islandDistance / 2
         && target.getZ() >= center.getBlockZ() - islandDistance / 2
         && target.getZ() < center.getBlockZ() + islandDistance / 2) {
       return true;
     }
   }
   return false;
 }
示例#21
0
  public static Boolean canSpawn(Location loc, float width, float height, float length) {
    net.minecraft.server.v1_7_R1.World mcWorld = ((CraftWorld) loc.getWorld()).getHandle();
    float halfEntityWidth = width / 2;
    AxisAlignedBB bb =
        AxisAlignedBB.a(
            loc.getX() - halfEntityWidth,
            loc.getY() - height,
            loc.getZ() - halfEntityWidth,
            loc.getX() + halfEntityWidth,
            loc.getY() - height + length,
            loc.getZ() + halfEntityWidth);

    return getBlockBBsInBB(loc.getWorld(), bb).isEmpty() && !mcWorld.containsLiquid(bb);
  }
示例#22
0
 public void turnToFace(Location point) {
   if (getEntity().getBukkitEntity().getWorld() != point.getWorld()) {
     return;
   }
   Location npcLoc = ((LivingEntity) getEntity().getBukkitEntity()).getEyeLocation();
   double xDiff = point.getX() - npcLoc.getX();
   double zDiff = point.getZ() - npcLoc.getZ();
   double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
   double newYaw = Math.acos(xDiff / DistanceXZ) * 180 / Math.PI;
   if (zDiff < 0.0) {
     newYaw = newYaw + Math.abs(180 - newYaw) * 2;
   }
   setYaw((float) (newYaw - 90));
 }
示例#23
0
 public void lookAtPoint(final Location point) {
   if (this.getEntity().getBukkitEntity().getWorld() != point.getWorld()) return;
   final Location npcLoc = ((LivingEntity) this.getEntity().getBukkitEntity()).getEyeLocation();
   final double xDiff = point.getX() - npcLoc.getX();
   final double yDiff = point.getY() - npcLoc.getY();
   final double zDiff = point.getZ() - npcLoc.getZ();
   final double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
   final double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
   double newYaw = Math.acos(xDiff / DistanceXZ) * 180 / Math.PI;
   final double newPitch = Math.acos(yDiff / DistanceY) * 180 / Math.PI - 90;
   if (zDiff < 0.0) newYaw = newYaw + Math.abs(180 - newYaw) * 2;
   this.setYaw((float) (newYaw - 90));
   this.setPitch((float) newPitch);
 }
示例#24
0
  @Override
  public void run(Player player, String[] args) {
    try {
      Material block = player.getTargetBlock(null, 7).getType();
      if (block == Material.COBBLESTONE) {
        player.getTargetBlock(null, 7).setType(Material.STONE);
        player.getWorld().playSound(player.getLocation(), Sound.FIRE_IGNITE, 1, 1);
        Location loc = player.getTargetBlock(null, 7).getLocation();
        loc.setX(loc.getX() + 0.5);
        loc.setZ(loc.getZ() + 0.5);
        loc.setY(loc.getY() + 0.5);
        ParticleEffects.sendToLocation(ParticleEffects.FLAME, loc, 1, 1, 1, 0, 10);
      } else if (block == Material.SAND) {
        player.getTargetBlock(null, 7).setType(Material.GLASS);
        player.getWorld().playSound(player.getLocation(), Sound.FIRE_IGNITE, 1, 1);
        Location loc = player.getTargetBlock(null, 7).getLocation();
        loc.setX(loc.getX() + 0.5);
        loc.setZ(loc.getZ() + 0.5);
        loc.setY(loc.getY() + 0.5);
        ParticleEffects.sendToLocation(ParticleEffects.FLAME, loc, 1, 1, 1, 0, 10);
      } else if (block == Material.IRON_ORE) {
        Block b = player.getTargetBlock(null, 7);
        b.setType(Material.AIR);
        b.getWorld().dropItem(b.getLocation(), new ItemStack(Material.IRON_INGOT));
        player.getWorld().playSound(player.getLocation(), Sound.FIRE_IGNITE, 1, 1);
        Location loc = player.getTargetBlock(null, 7).getLocation();
        loc.setX(loc.getX() + 0.5);
        loc.setZ(loc.getZ() + 0.5);
        loc.setY(loc.getY() + 0.5);
        ParticleEffects.sendToLocation(ParticleEffects.FLAME, loc, 1, 1, 1, 0, 10);
      } else if (block == Material.GOLD_ORE) {
        Block b = player.getTargetBlock(null, 7);
        b.setType(Material.AIR);
        b.getWorld().dropItem(b.getLocation(), new ItemStack(Material.GOLD_INGOT));
        player.getWorld().playSound(player.getLocation(), Sound.FIRE_IGNITE, 1, 1);
        Location loc = player.getTargetBlock(null, 7).getLocation();
        loc.setX(loc.getX() + 0.5);
        loc.setZ(loc.getZ() + 0.5);
        loc.setY(loc.getY() + 0.5);
        ParticleEffects.sendToLocation(ParticleEffects.FLAME, loc, 1, 1, 1, 0, 30);
      } else {
        LivingEntity en = (LivingEntity) getTarget(player);
        player.getWorld().playSound(player.getLocation(), Sound.FIRE_IGNITE, 1, 1);
        en.setFireTicks(160);
      }
    } catch (Exception e) {

    }
  }
示例#25
0
  /**
   * Determines the direction a player is moving based on two sets of coordinates.
   *
   * @param locFrom The position the player was at before moving.
   * @param locTo The position the player is currently at.
   * @return An int representation of the direction the player is moving:<br>
   *     1 - Negative X direction, 2 - Negative Z direction, 3 - Positive X direction, 0 - Positive
   *     Z direction.
   */
  public int getDirection(Location locFrom, Location locTo) {
    int dir = 0;

    if (locFrom.getX() > locTo.getX() && locFrom.getBlockZ() == locTo.getBlockZ()) {
      dir = 1;
    } else if (locFrom.getZ() > locTo.getZ() && locFrom.getBlockX() == locTo.getBlockX()) {
      dir = 2;
    } else if (locFrom.getX() < locTo.getX() && locFrom.getBlockZ() == locTo.getBlockZ()) {
      dir = 3;
    } else if (locFrom.getZ() < locTo.getZ() && locFrom.getBlockX() == locTo.getBlockX()) {
      dir = 4;
    }

    return dir;
  }
示例#26
0
 public static org.bukkit.entity.Entity spawnCustomEntity(
     org.bukkit.World world, Location at, Class<? extends Entity> clazz, EntityType type) {
   World handle = ((CraftWorld) world).getHandle();
   Entity entity = null;
   try {
     Constructor<?> constructor = getCustomEntityConstructor(clazz, type);
     entity = (Entity) constructor.newInstance(handle);
   } catch (Exception e) {
     Messaging.logTr(Messages.ERROR_SPAWNING_CUSTOM_ENTITY, e.getMessage());
     return null;
   }
   entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
   handle.addEntity(entity);
   entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
   return entity.getBukkitEntity();
 }
 // Getting the region
 public boolean contains(Location loc, int x1, int x2, int y1, int y2, int z1, int z2) {
   int bottomCornerX = x1 < x2 ? x1 : x2;
   int bottomCornerZ = z1 < z2 ? z1 : z2;
   int topCornerX = x1 > x2 ? x1 : x2;
   int topCornerZ = z1 > z2 ? z1 : z2;
   int bottomCornerY = y1 < y2 ? y1 : y2;
   int topCornerY = y1 > y2 ? y1 : y2;
   if (loc.getX() >= bottomCornerX && loc.getX() <= topCornerX) {
     if (loc.getZ() >= bottomCornerZ && loc.getZ() <= topCornerZ) {
       if (loc.getY() >= bottomCornerY && loc.getY() <= topCornerY) {
         return true;
       }
     }
   }
   return false;
 }
示例#28
0
  /**
   * @param location the {@link Location} around which players must be to see the effect
   * @param effectName list of effects: https://gist.github.com/riking/5759002
   * @param offsetX the amount to be randomly offset by in the X axis
   * @param offsetY the amount to be randomly offset by in the Y axis
   * @param offsetZ the amount to be randomly offset by in the Z axis
   * @param speed the speed of the particles
   * @param count the number of particles
   * @param radius the radius around the location
   */
  public static void playParticleEffect(
      Location location,
      String effectName,
      float offsetX,
      float offsetY,
      float offsetZ,
      float speed,
      int count,
      int radius) {
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effectName, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");

    PacketPlayOutWorldParticles packet =
        new PacketPlayOutWorldParticles(
            effectName,
            (float) location.getX(),
            (float) location.getY(),
            (float) location.getZ(),
            offsetX,
            offsetY,
            offsetZ,
            speed,
            count);

    for (Player player : location.getWorld().getPlayers()) {
      if ((int) player.getLocation().distance(location) <= radius) {
        ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
      }
    }
  }
示例#29
0
 public boolean spawn() {
   if (location.getChunk().isLoaded()) {
     NPCHuman entity = (NPCHuman) getHandle();
     getHandle()
         .setPositionRotation(
             location.getX(),
             location.getY(),
             location.getZ(),
             location.getYaw(),
             location.getPitch());
     if (heldItem != null) {
       entity.getBukkitEntity().setItemInHand(heldItem.getItemStack());
     }
     if (armorHelm != null) {
       entity.getBukkitEntity().getInventory().setHelmet(armorHelm.getItemStack());
     }
     if (armorChest != null) {
       entity.getBukkitEntity().getInventory().setChestplate(armorChest.getItemStack());
     }
     if (armorLegging != null) {
       entity.getBukkitEntity().getInventory().setLeggings(armorLegging.getItemStack());
     }
     if (armorBoot != null) {
       entity.getBukkitEntity().getInventory().setBoots(armorBoot.getItemStack());
     }
     ((CraftWorld) location.getWorld()).getHandle().addEntity(entity);
     return true;
   }
   return false;
 }
示例#30
0
 public void save(ConfigurationSection section) {
   section.set("location.world", loc.getWorld().getName());
   section.set("location.x", loc.getX());
   section.set("location.y", loc.getY());
   section.set("location.z", loc.getZ());
   section.set("arena", arena.getID());
 }