コード例 #1
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onCreatureSpawn(CreatureSpawnEvent evt) {

    Location l = evt.getEntity().getLocation();
    World w = l.getWorld();
    Chunk c = w.getChunkAt(l);

    Region r;

    ArrayList<Region> regionSet = new ArrayList<Region>();

    for (Region region : GlobalRegionManager.getRegions()) {
      for (Chunk chunk : region.getChunkGrid().getChunks()) {
        if (chunk.getWorld() == w) {
          if (areChunksEqual(chunk, c)) {
            if (!regionSet.contains(region)) {
              regionSet.add(region);
            }
          }
        }
      }
    }

    if (regionSet.isEmpty()) {
      if (GlobalRegionManager.getGlobalWorldSetting(w) != null) {
        if (!GlobalRegionManager.getGlobalWorldSetting(w).canCreatureSpawn(evt.getEntityType())) {
          evt.setCancelled(true);
        }
        return;
      }
    }

    ArrayList<Region> currentRegionSet = new ArrayList<Region>();

    for (Region reg : regionSet) {
      if (extReg.isInsideCuboid(
          l, reg.getL1().toBukkitLocation(), reg.getL2().toBukkitLocation())) {
        currentRegionSet.add(reg);
      }
    }

    if (currentRegionSet.isEmpty()) { // If player is in chunk range but not
      // inside region then cancel the
      // check.
      if (GlobalRegionManager.getGlobalWorldSetting(w) != null) {
        if (!GlobalRegionManager.getGlobalWorldSetting(w).canCreatureSpawn(evt.getEntityType())) {
          evt.setCancelled(true);
        }
      }
      return;
    }

    if (currentRegionSet.size() > 1) {
      r = srm.getCurrentRegion(null, currentRegionSet);
    } else {
      r = currentRegionSet.get(0);
    }

    if (!r.canMobsSpawn()) {
      EntityType ce = evt.getEntityType();
      if (ce == EntityType.CHICKEN
          || ce == EntityType.COW
          || ce == EntityType.PIG
          || ce == EntityType.SHEEP
          || ce == EntityType.SQUID) {
        LogRunner.addLogMessage(
            r,
            LogRunner.getPrefix(r)
                + (" Mob '" + ce.getName() + "' tried to spawn but was prevented."));
        evt.setCancelled(true);
        return;
      }
    }

    if (!r.canMonstersSpawn()) {
      EntityType ce = evt.getEntityType();
      if (ce != EntityType.CHICKEN
          && ce != EntityType.COW
          && ce != EntityType.PIG
          && ce != EntityType.SHEEP
          && ce != EntityType.SQUID) {
        LogRunner.addLogMessage(
            r,
            LogRunner.getPrefix(r)
                + (" Monster '" + ce.getName() + "' tried to spawn but was prevented."));
        evt.setCancelled(true);
        return;
      }
    }
  }
コード例 #2
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityDamage(EntityDamageEvent evt) {

    if (!(evt.getEntity() instanceof Player)) {
      return;
    }

    Location l = evt.getEntity().getLocation();
    World w = l.getWorld();
    Chunk c = w.getChunkAt(l);
    Player p = (Player) evt.getEntity();

    GlobalWorldSetting gws = GlobalRegionManager.getGlobalWorldSetting(w);

    Region r;

    ArrayList<Region> regionSet = new ArrayList<Region>();

    for (Region region : GlobalRegionManager.getRegions()) {
      for (Chunk chunk : region.getChunkGrid().getChunks()) {
        if (chunk.getWorld() == w) {
          if (areChunksEqual(chunk, c)) {
            if (!regionSet.contains(region)) {
              regionSet.add(region);
            }
          }
        }
      }
    }

    if (regionSet.isEmpty()) {
      return;
    }

    ArrayList<Region> currentRegionSet = new ArrayList<Region>();

    for (Region reg : regionSet) {
      Location rl1 = reg.getL1().toBukkitLocation(), rl2 = reg.getL2().toBukkitLocation();
      if (extReg.isInsideCuboid(l, rl1, rl2)) {
        currentRegionSet.add(reg);
      }
    }

    if (currentRegionSet.isEmpty()) { // If player is in chunk range but not
      // inside region then cancel the
      // check.
      if (gws != null) {
        if (!gws.invert_pvp && gws.overridingPvp) {
          evt.setCancelled(true);
          return;
        }
      }
      return;
    }

    if (currentRegionSet.size() > 1) {
      r = srm.getCurrentRegion(p, currentRegionSet);
    } else {
      r = currentRegionSet.get(0);
    }

    if (!r.isHealthEnabled()) {
      evt.setCancelled(true);
      evt.setDamage(0);
      return;
    }

    if (!r.isPvpEnabled()) {
      if (evt instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent edevt = (EntityDamageByEntityEvent) evt;
        if (edevt.getDamager() instanceof Player && edevt.getEntity() instanceof Player) {
          Player damager = (Player) edevt.getDamager();
          LogRunner.addLogMessage(
              r,
              LogRunner.getPrefix(r)
                  + (" Player '"
                      + damager.getName()
                      + "' tried to attack '"
                      + ((Player) evt.getEntity()).getName()
                      + " but was prevented."));
          damager.sendMessage(
              ChatColor.RED + "[Regios] You cannot fight within regions in this world!");
          evt.setCancelled(true);
          evt.setDamage(0);
          return;
        }
      }
    }
  }
コード例 #3
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPaintingPlace(PaintingPlaceEvent evt) {

    Player cause = evt.getPlayer();

    Location l = evt.getPainting().getLocation();
    World w = l.getWorld();
    Chunk c = w.getChunkAt(l);

    GlobalWorldSetting gws = GlobalRegionManager.getGlobalWorldSetting(w);

    Region r;

    ArrayList<Region> regionSet = new ArrayList<Region>();

    for (Region region : GlobalRegionManager.getRegions()) {
      for (Chunk chunk : region.getChunkGrid().getChunks()) {
        if (chunk.getWorld() == w) {
          if (areChunksEqual(chunk, c)) {
            if (!regionSet.contains(region)) {
              regionSet.add(region);
            }
          }
        }
      }
    }

    if (regionSet.isEmpty()) {
      if (gws != null) {
        if (gws.invert_protection) {
          evt.setCancelled(true);
          return;
        }
      }
      return;
    }

    ArrayList<Region> currentRegionSet = new ArrayList<Region>();

    for (Region reg : regionSet) {
      if (extReg.isInsideCuboid(
          l, reg.getL1().toBukkitLocation(), reg.getL2().toBukkitLocation())) {
        currentRegionSet.add(reg);
      }
    }

    if (currentRegionSet.isEmpty()) { // If player is in chunk range but not
      // inside region then cancel the
      // check.
      if (gws != null) {
        if (gws.invert_protection) {
          evt.setCancelled(true);
          return;
        }
      }
      return;
    }

    if (currentRegionSet.size() > 1) {
      r = srm.getCurrentRegion(null, currentRegionSet);
    } else {
      r = currentRegionSet.get(0);
    }

    if (r.is_protectionPlace()) {
      if (!r.canBuild(cause)) {
        LogRunner.addLogMessage(r, LogRunner.getPrefix(r) + (" Painting place was prevented."));
        r.sendBuildMessage(cause);
        evt.setCancelled(true);
        return;
      }
    }
  }