Exemplo n.º 1
0
 public boolean addResidence(String name, String owner, Location loc1, Location loc2) {
   if (!Residence.validName(name)) return false;
   if (loc1 == null
       || loc2 == null
       || !loc1.getWorld().getName().equals(loc2.getWorld().getName())) {
     return false;
   }
   PermissionGroup group =
       Residence.getPermissionManager().getGroup(owner, loc1.getWorld().getName());
   CuboidArea newArea = new CuboidArea(loc1, loc2);
   ClaimedResidence newRes = new ClaimedResidence(owner, loc1.getWorld().getName());
   newRes.getPermissions().applyDefaultFlags();
   newRes.setEnterMessage(group.getDefaultEnterMessage());
   newRes.setLeaveMessage(group.getDefaultLeaveMessage());
   ResidenceCreationEvent resevent = new ResidenceCreationEvent(null, name, newRes, newArea);
   Residence.getServ().getPluginManager().callEvent(resevent);
   if (resevent.isCancelled()) {
     return false;
   }
   newArea = resevent.getPhysicalArea();
   name = resevent.getResidenceName();
   if (residences.containsKey(name)) {
     return false;
   }
   newRes.addArea(newArea, "main");
   if (newRes.getAreaCount() != 0) {
     residences.put(name, newRes);
   }
   return true;
 }
Exemplo n.º 2
0
  public void addResidence(
      Player player, String name, Location loc1, Location loc2, boolean resadmin) {
    if (!Residence.validName(name)) {
      player.sendMessage("§c" + Residence.getLanguage().getPhrase("InvalidNameCharacters"));
      return;
    }
    if (player == null) return;
    if (loc1 == null
        || loc2 == null
        || !loc1.getWorld().getName().equals(loc2.getWorld().getName())) {
      player.sendMessage("§c" + Residence.getLanguage().getPhrase("SelectPoints"));
      return;
    }
    PermissionGroup group = Residence.getPermissionManager().getGroup(player);
    boolean createpermission =
        group.canCreateResidences()
            || Residence.getPermissionManager().hasAuthority(player, "residence.create", false);
    if (!createpermission && !resadmin) {
      player.sendMessage("§c" + Residence.getLanguage().getPhrase("NoPermission"));
      return;
    }
    if (getOwnedZoneCount(player.getName()) >= group.getMaxZones() && !resadmin) {
      player.sendMessage("§c" + Residence.getLanguage().getPhrase("ResidenceTooMany"));
      return;
    }
    CuboidArea newArea = new CuboidArea(loc1, loc2);
    ClaimedResidence newRes = new ClaimedResidence(player.getName(), loc1.getWorld().getName());
    newRes.getPermissions().applyDefaultFlags();
    newRes.setEnterMessage(group.getDefaultEnterMessage());
    newRes.setLeaveMessage(group.getDefaultLeaveMessage());

    ResidenceCreationEvent resevent = new ResidenceCreationEvent(player, name, newRes, newArea);
    Residence.getServ().getPluginManager().callEvent(resevent);
    if (resevent.isCancelled()) return;
    newArea = resevent.getPhysicalArea();
    name = resevent.getResidenceName();
    if (residences.containsKey(name)) {
      player.sendMessage(
          "§c" + Residence.getLanguage().getPhrase("ResidenceAlreadyExists", "§e" + name + "§c"));
      return;
    }
    newRes.addArea(player, newArea, "main", resadmin);
    if (newRes.getAreaCount() != 0) {
      residences.put(name, newRes);
      Residence.getLeaseManager().removeExpireTime(name);
      player.sendMessage(
          "§a" + Residence.getLanguage().getPhrase("ResidenceCreate", "§e" + name + "§a"));
      if (Residence.getConfigManager().useLeases())
        Residence.getLeaseManager().setExpireTime(player, name, group.getLeaseGiveTime());
    }
  }