예제 #1
0
 /** 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.");
   }
 }
예제 #2
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();
        }
      }
    }
  }
  private int removeEntities(Chunk chunk) {
    int entityCount = 0;

    for (Entity entity : chunk.getEntities()) {
      if (entity instanceof Player || entity instanceof Hanging || entity instanceof NPC) {
        continue;
      }
      entity.remove();
      entityCount++;
    }

    return entityCount;
  }
 /** Remove all the old shop items who aren't deleted for some reason */
 public void removeDupedItems() {
   Chunk c = getBlock().getChunk();
   for (Entity e : c.getEntities()) {
     if (e.getLocation().getBlock().equals(getBlock()) && e instanceof Item && !e.equals(item)) {
       e.remove();
     }
     if (e.getLocation()
             .getBlock()
             .equals(
                 getWorld()
                     .getBlockAt(getBlock().getX(), getBlock().getY() + 1, getBlock().getZ()))
         && e instanceof Item
         && !e.equals(item)) {
       e.remove();
     }
   }
 }
예제 #5
0
 public void crystalRegen() {
   Chunk bukkitChunk;
   for (final EndChunk c : chunks.values()) {
     if (c.containsCrystal()) {
       final World w = Bukkit.getWorld(c.getWorldName());
       bukkitChunk = w.getChunkAt(c.getX(), c.getZ());
       final Set<Location> locs = c.getCrystalLocations();
       for (final Entity e : bukkitChunk.getEntities()) {
         if (e.getType() == EntityType.ENDER_CRYSTAL) {
           e.remove();
         }
       }
       for (final Location loc : locs) {
         w.spawnEntity(loc.clone().add(0, -1, 0), EntityType.ENDER_CRYSTAL);
         loc.getBlock().getRelative(BlockFace.DOWN).setType(Material.BEDROCK);
       }
     }
   }
 }
  private int removeEntities(final Chunk chunk) {
    int _entityCount = 0;

    for (final Entity _e : chunk.getEntities()) {
      if ((_e instanceof Player) || (_e instanceof Painting)) {
        continue;
      } else {
        if (((CraftEntity) _e).getHandle() instanceof NPC) {
          if (!(((CraftEntity) _e).getHandle() instanceof EntityCreature)) {
            continue;
          }
        }
        _e.remove();
        _entityCount++;
      }
    }

    return _entityCount;
  }
예제 #7
0
  public ItemFrame getFrame(boolean force) {
    ItemFrame frame = (instance != null) ? instance.get() : null;
    if (frame == null || !frame.isValid()) {
      final World world = (worldId != null) ? Bukkit.getWorld(worldId) : null;
      if (world != null) {
        Chunk chunk = world.getChunkAt(chunk_x, chunk_z);
        if (!chunk.isLoaded() && force) chunk.load();

        if (chunk.isLoaded())
          for (Entity entity : chunk.getEntities())
            if (entity.getUniqueId().equals(id)) {
              frame = (ItemFrame) entity;
              instance = new WeakReference<ItemFrame>(frame);
              break;
            }
      }
    }

    return frame;
  }
  /**
   * Remove creatures from chunk at and around the given location.
   *
   * @param l
   */
  public void removeCreatures(Location l) {
    if (!this.settings.getRemoveCreaturesByTeleport() || l == null) {
      return;
    }

    int px = l.getBlockX();
    int py = l.getBlockY();
    int pz = l.getBlockZ();
    for (int x = -1; x <= 1; x++) {
      for (int z = -1; z <= 1; z++) {
        Chunk c = l.getWorld().getChunkAt(new Location(l.getWorld(), px + x * 16, py, pz + z * 16));
        for (Entity e : c.getEntities()) {
          if (e.getType() == EntityType.SPIDER
              || e.getType() == EntityType.CREEPER
              || e.getType() == EntityType.ENDERMAN
              || e.getType() == EntityType.SKELETON
              || e.getType() == EntityType.ZOMBIE) {
            e.remove();
          }
        }
      }
    }
  }
예제 #9
0
  public static void clear(final Location bottom, final Location top) {
    final AthionMaps pmi = getMap(bottom);

    final int bottomX = bottom.getBlockX();
    final int topX = top.getBlockX();
    final int bottomZ = bottom.getBlockZ();
    final int topZ = top.getBlockZ();

    final int minChunkX = (int) Math.floor((double) bottomX / 16);
    final int maxChunkX = (int) Math.floor((double) topX / 16);
    final int minChunkZ = (int) Math.floor((double) bottomZ / 16);
    final int maxChunkZ = (int) Math.floor((double) topZ / 16);

    final World w = bottom.getWorld();

    for (int cx = minChunkX; cx <= maxChunkX; cx++) {
      for (int cz = minChunkZ; cz <= maxChunkZ; cz++) {
        final Chunk chunk = w.getChunkAt(cx, cz);

        for (final Entity e : chunk.getEntities()) {
          final Location eloc = e.getLocation();

          if (!(e instanceof Player)
              && (eloc.getBlockX() >= bottom.getBlockX())
              && (eloc.getBlockX() <= top.getBlockX())
              && (eloc.getBlockZ() >= bottom.getBlockZ())
              && (eloc.getBlockZ() <= top.getBlockZ())) {
            e.remove();
          }
        }
      }
    }

    for (int x = bottomX; x <= topX; x++) {
      for (int z = bottomZ; z <= topZ; z++) {
        Block block = new Location(w, x, 0, z).getBlock();

        block.setBiome(Biome.PLAINS);

        for (int y = w.getMaxHeight(); y >= 0; y--) {
          block = new Location(w, x, y, z).getBlock();

          final BlockState state = block.getState();

          if (state instanceof InventoryHolder) {
            final InventoryHolder holder = (InventoryHolder) state;
            holder.getInventory().clear();
          }

          if (state instanceof Jukebox) {
            final Jukebox jukebox = (Jukebox) state;
            // Remove once they fix the NullPointerException
            try {
              jukebox.setPlaying(Material.AIR);
            } catch (final Exception e) {
            }
          }

          if (y == 0) {
            block.setTypeId(pmi.BottomBlockId);
          } else if (y == pmi.RoadHeight) {
            block.setTypeId(pmi.PlotFloorBlockId);
          } else if (y < pmi.RoadHeight) {
            block.setTypeId(pmi.PlotFillingBlockId);
          } else {
            if ((y == (pmi.RoadHeight))
                && ((x == (bottomX - 1))
                    || (x == (topX + 1))
                    || (z == (bottomZ - 1))
                    || (z == (topZ + 1)))) {
              // block.setTypeId(pmi.WallBlockId);
            } else {
              block.setTypeIdAndData(0, (byte) 0, false); // .setType(Material.AIR);
            }
          }
        }
      }
    }

    adjustWall(bottom);
  }
예제 #10
0
  private void sitOn(vData v) {
    Location l = v.owner().p.getLocation();
    double px = l.getX();
    double py = l.getY();
    double pz = l.getZ();

    Entity closest = null;
    double range = 99999999;

    Chunk c = w.getChunkAt(tb.getLocation());
    int chunkx = c.getX();
    int chunkz = c.getZ();

    for (int x = chunkx - 1; x <= chunkx + 1; x++) {
      for (int y = chunkz - 1; y <= chunkz + 1; y++) {
        c = w.getChunkAt(x, y);
        Entity[] toCheck = c.getEntities();
        for (Entity e : toCheck) {
          if (e.getEntityId() == v.owner().p.getEntityId()) {
            continue;
          }
          Location el = e.getLocation();

          double erange =
              Math.pow(bx - el.getX(), 2)
                  + Math.pow(by - el.getY(), 2)
                  + Math.pow(bz - el.getZ(), 2);

          if (erange < range) {
            range = erange;
            closest = e;
          }
        }
      }
    }

    if (closest != null) {
      boolean teleport = false;
      PlayerTeleportEvent teleEvent = null;

      Player player = v.owner().p;
      teleport = player.isOnline();

      if (teleport) {
        teleEvent =
            new PlayerTeleportEvent(
                player,
                player.getLocation(),
                closest.getLocation(),
                PlayerTeleportEvent.TeleportCause.PLUGIN);
        Bukkit.getPluginManager().callEvent(teleEvent);
        teleport = !teleEvent.isCancelled();
      }

      if (teleport) {
        ((CraftEntity) v.owner().p).getHandle().setPassengerOf(((CraftEntity) closest).getHandle());
        v.sendMessage(ChatColor.GREEN + "You are now saddles on entity: " + closest.getEntityId());
      }
    } else {
      v.sendMessage(ChatColor.RED + "Could not find any entities");
    }
  }