Ejemplo n.º 1
0
 @Subscribe
 public void onFloraGrow(FloraGrowEvent event) {
   org.spongepowered.api.world.Location block = event.getLocation();
   Extent extent = block.getExtent();
   if (extent instanceof World) {
     World world = (World) extent;
     final String worldname = world.getName();
     if (!PS.get().isPlotWorld(worldname)) {
       return;
     }
     if (MainUtil.isPlotRoad(SpongeUtil.getLocation(worldname, block))) {
       event.setCancelled(true);
     }
   }
 }
Ejemplo n.º 2
0
  @Subscribe
  public void onMobSpawn(EntitySpawnEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof Player) {
      return;
    }
    final Location loc = SpongeUtil.getLocation(event.getLocation());
    final String world = loc.getWorld();
    PlotWorld plotworld = PS.get().getPlotWorld(world);
    if (plotworld == null) {
      return;
    }
    Plot plot = MainUtil.getPlot(loc);
    if (plot == null) {
      if (MainUtil.isPlotRoad(loc)) {
        event.setCancelled(true);
      }
      return;
    }
    final PlotWorld pW = PS.get().getPlotWorld(world);

    // TODO selectively cancel depending on spawn reason
    // - Not sure if possible to get spawn reason (since there are no callbacks)

    if (entity.getType() == EntityTypes.DROPPED_ITEM) {
      if (FlagManager.isPlotFlagFalse(plot, "item-drop")) {
        event.setCancelled(true);
      }
      return;
    }
    int[] mobs = null;
    if (entity instanceof Living) {
      if (!plotworld.MOB_SPAWNING) {
        event.setCancelled(true);
        return;
      }
      Flag mobCap = FlagManager.getPlotFlag(plot, "mob-cap");
      if (mobCap != null) {
        Integer cap = (Integer) mobCap.getValue();
        if (cap == 0) {
          event.setCancelled(true);
          return;
        }
        if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
        if (mobs[3] >= cap) {
          event.setCancelled(true);
          return;
        }
      }
      if (entity instanceof Ambient || entity instanceof Animal) {
        Flag animalFlag = FlagManager.getPlotFlag(plot, "animal-cap");
        if (animalFlag != null) {
          int cap = ((Integer) animalFlag.getValue());
          if (cap == 0) {
            event.setCancelled(true);
            return;
          }
          if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
          if (mobs[1] >= cap) {
            event.setCancelled(true);
            return;
          }
        }
      }
      if (entity instanceof Monster) {
        Flag monsterFlag = FlagManager.getPlotFlag(plot, "hostile-cap");
        if (monsterFlag != null) {
          int cap = ((Integer) monsterFlag.getValue());
          if (cap == 0) {
            event.setCancelled(true);
            return;
          }
          if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
          if (mobs[2] >= cap) {
            event.setCancelled(true);
            return;
          }
        }
      }
      return;
    }
    if (entity instanceof Minecart || entity instanceof Boat) {
      Flag vehicleFlag = FlagManager.getPlotFlag(plot, "vehicle-cap");
      if (vehicleFlag != null) {
        int cap = ((Integer) vehicleFlag.getValue());
        if (cap == 0) {
          event.setCancelled(true);
          return;
        }
        if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
        if (mobs[4] >= cap) {
          event.setCancelled(true);
          return;
        }
      }
    }
    Flag entityCap = FlagManager.getPlotFlag(plot, "entity-cap");
    if (entityCap != null) {
      Integer cap = (Integer) entityCap.getValue();
      if (cap == 0) {
        event.setCancelled(true);
        return;
      }
      if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
      if (mobs[0] >= cap) {
        event.setCancelled(true);
        return;
      }
    }
  }