Ejemplo n.º 1
0
 @Subscribe
 public void onRedstoneEvent(BlockRedstoneUpdateEvent event) {
   org.spongepowered.api.world.Location block = event.getLocation();
   Location loc = SpongeUtil.getLocation(block);
   if (loc == null || !PS.get().isPlotWorld(loc.getWorld())) {
     return;
   }
   Plot plot = MainUtil.getPlot(loc);
   if (plot == null || !plot.hasOwner()) {
     return;
   }
   if (event.getOldSignalStrength() > event.getNewSignalStrength()) {
     return;
   }
   if (Settings.REDSTONE_DISABLER) {
     if (UUIDHandler.getPlayer(plot.owner) == null) {
       boolean disable = true;
       for (UUID trusted : plot.getTrusted()) {
         if (UUIDHandler.getPlayer(trusted) != null) {
           disable = false;
           break;
         }
       }
       if (disable) {
         event.setNewSignalStrength(0);
         return;
       }
     }
   }
   Flag redstone = FlagManager.getPlotFlag(plot, "redstone");
   if (FlagManager.isPlotFlagFalse(plot, "redstone")) {
     event.setNewSignalStrength(0);
     // TODO only disable clocks
   }
 }
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;
      }
    }
  }