Example #1
0
 public void editRemoveFromPermRemoveCache(Region r, String message) {
   YamlConfiguration c = r.getConfigFile();
   Map<String, Object> all = c.getValues(true);
   String current = (String) all.get("Region.Permissions.PermanentCache.RemoveNodes");
   current = current.replaceAll(" ", "");
   current = current.replaceAll(message + ",", "");
   current = current.replaceAll(",,", ",");
   all.remove("Region.Permissions.PermanentCache.RemoveNodes");
   for (Entry<String, Object> entry : all.entrySet()) {
     c.set(entry.getKey(), entry.getValue());
   }
   c.set("Region.Permissions.PermanentCache.RemoveNodes", current.trim());
   r.setPermanentNodesCacheRemove((current.trim()).split(","));
 }
Example #2
0
 public void editResetTempAddCache(Region r) {
   YamlConfiguration c = r.getConfigFile();
   Map<String, Object> all = c.getValues(true);
   all.remove("Region.Permissions.TemporaryCache.AddNodes");
   for (Entry<String, Object> entry : all.entrySet()) {
     c.set(entry.getKey(), entry.getValue());
   }
   c.set("Region.Permissions.TemporaryCache.AddNodes", "");
   r.setTemporaryNodesCacheAdd(("").split(","));
   try {
     c.save(r.getRawConfigFile());
   } catch (IOException e) {
   }
 }
Example #3
0
 public void editAddToPermAddCache(Region r, String message) {
   YamlConfiguration c = r.getConfigFile();
   Map<String, Object> all = c.getValues(true);
   String current = (String) all.get("Region.Permissions.PermanentCache.AddNodes");
   all.remove("Region.Permissions.PermanentCache.AddNodes");
   for (Entry<String, Object> entry : all.entrySet()) {
     c.set(entry.getKey(), entry.getValue());
   }
   c.set("Region.Permissions.PermanentCache.AddNodes", current.trim() + message.trim() + ",");
   r.setPermanentNodesCacheAdd((current.trim() + "," + message.trim()).split(","));
   try {
     c.save(r.getRawConfigFile());
   } catch (IOException e) {
   }
 }
 public void listRegionBackups(Region r, String region, Player p) {
   if (r == null) {
     p.sendMessage(
         ChatColor.RED
             + "[Regios] The region to inherit : "
             + ChatColor.BLUE
             + region
             + ChatColor.RED
             + " does not exist!");
     return;
   }
   File f = r.getBackupsDirectory();
   if (f.listFiles().length < 1) {
     p.sendMessage(
         ChatColor.RED
             + "[Regios] The region "
             + ChatColor.BLUE
             + region
             + ChatColor.RED
             + " has no backups!");
   } else {
     StringBuilder sb = new StringBuilder();
     for (File backup : f.listFiles()) {
       sb.append(ChatColor.WHITE)
           .append(backup.getName().substring(0, backup.getName().lastIndexOf(".")))
           .append(ChatColor.BLUE)
           .append(", ");
     }
     p.sendMessage(sb.toString());
     return;
   }
 }
 public void setOwner(Region r, String name, String owner, Player p) {
   if (r == null) {
     p.sendMessage(
         ChatColor.RED
             + "[Regios] The region to inherit : "
             + ChatColor.BLUE
             + name
             + ChatColor.RED
             + " does not exist!");
     return;
   }
   if (!r.canModify(p)) {
     p.sendMessage(ChatColor.RED + "[Regios] You are not permitted to modify this region!");
     return;
   }
   mutable.setOwner(r, owner);
   p.sendMessage(
       ChatColor.GREEN
           + "[Regios] Owner for region "
           + ChatColor.BLUE
           + name
           + ChatColor.GREEN
           + " changed to "
           + ChatColor.BLUE
           + owner);
 }
Example #6
0
 public boolean checkPermRemove(Region r, String match) {
   for (String s : r.getPermanentNodesCacheRemove()) {
     if (s.trim().equalsIgnoreCase(match.trim())) {
       return true;
     }
   }
   return false;
 }
Example #7
0
 public boolean checkTempCache(Region r, String match) {
   for (String s : r.getTempCacheNodes()) {
     if (s.trim().equalsIgnoreCase(match.trim())) {
       return true;
     }
   }
   return false;
 }
Example #8
0
 public void editRemoveFromTempAddCache(Region r, String message) {
   YamlConfiguration c = r.getConfigFile();
   Map<String, Object> all = c.getValues(true);
   String current = (String) all.get("Region.Permissions.TemporaryCache.AddNodes");
   current = current.replaceAll(" ", "");
   current = current.replaceAll(message + ",", "");
   current = current.replaceAll(",,", ",");
   all.remove("Region.Permissions.TemporaryCache.AddNodes");
   for (Entry<String, Object> entry : all.entrySet()) {
     c.set(entry.getKey(), entry.getValue());
   }
   c.set("Region.Permissions.TemporaryCache.AddNodes", current.trim());
   r.setTemporaryNodesCacheAdd((current.trim()).split(","));
   try {
     c.save(r.getRawConfigFile());
   } catch (IOException e) {
   }
 }
 public void setModifyPoints(Location l1, Location l2, Player p) {
   if (l1 == null || l2 == null) {
     p.sendMessage(ChatColor.RED + "[Regios] You have not set 2 points!");
     return;
   }
   Region r = CreationCommands.modRegion.get(p);
   if (!super.canModifyMain(r, p)) {
     p.sendMessage(ChatColor.RED + "[Regios] You are not permitted to modify this region!");
     return;
   }
   p.sendMessage(
       ChatColor.GREEN
           + "[Regios] Region "
           + ChatColor.BLUE
           + r.getName()
           + ChatColor.GREEN
           + ", points modified successfully");
   mutable.editModifyPoints(r, l1, l2);
 }
 public void inherit(Region tin, Region inf, String tinName, String infName, Player p) {
   if (tin == null) {
     p.sendMessage(
         ChatColor.RED
             + "[Regios] The region to inherit : "
             + ChatColor.BLUE
             + tinName
             + ChatColor.RED
             + " does not exist!");
     return;
   }
   if (inf == null) {
     p.sendMessage(
         ChatColor.RED
             + "[Regios] The region to inherit from : "
             + ChatColor.BLUE
             + infName
             + ChatColor.RED
             + " does not exist!");
     return;
   }
   if (!tin.canModify(p)) {
     p.sendMessage(ChatColor.RED + "[Regios] You are not permitted to modify this region!");
     return;
   }
   mutable.inherit(tin, inf);
   p.sendMessage(
       ChatColor.GREEN
           + "[Regios] Region "
           + ChatColor.BLUE
           + tinName
           + ChatColor.GREEN
           + " inherited properties from region "
           + ChatColor.BLUE
           + infName);
   return;
 }
Example #11
0
 public String listPermRemCache(Region r) {
   YamlConfiguration c = r.getConfigFile();
   String s = c.getString("Region.Permissions.PermanentCache.RemoveNodes", "");
   return s;
 }
Example #12
0
 public String listTempAddCache(Region r) {
   YamlConfiguration c = r.getConfigFile();
   String s = c.getString("Region.Permissions.TemporaryCache.AddNodes", "");
   return s;
 }
Example #13
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;
        }
      }
    }
  }
Example #14
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;
      }
    }
  }
Example #15
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onExplosionPrime(ExplosionPrimeEvent evt) {

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

    if (evt.getEntity() instanceof Creeper) {
      if (GlobalRegionManager.getGlobalWorldSetting(w) != null) {
        if (!GlobalRegionManager.getGlobalWorldSetting(w).creeperExplodes) {
          evt.setCancelled(true);
          evt.setRadius(0);
          return;
        }
      }
    }

    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 (rl1.getX() > rl2.getX()) {
        rl2.subtract(6, 0, 0);
        rl1.add(6, 0, 0);
      } else {
        rl2.add(6, 0, 0);
        rl1.subtract(6, 0, 0);
      }
      if (rl1.getZ() > rl2.getZ()) {
        rl2.subtract(0, 0, 6);
        rl1.add(0, 0, 6);
      } else {
        rl2.add(0, 0, 6);
        rl1.subtract(0, 0, 6);
      }
      if (rl1.getY() > rl2.getY()) {
        rl2.subtract(0, 10, 0);
        rl1.add(0, 10, 0);
      } else {
        rl2.add(0, 10, 0);
        rl1.subtract(0, 10, 0);
      }
      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.
      return;
    } else {
      for (Region r : currentRegionSet) {
        if (r.is_protection()) {
          LogRunner.addLogMessage(r, LogRunner.getPrefix(r) + (" Entity explosion was prevented."));
          evt.setCancelled(true);
          evt.setRadius(0);
          return;
        }
      }
    }
  }
Example #16
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;
      }
    }
  }