Пример #1
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());
    }
  }
Пример #2
0
 public void giveResidence(
     Player reqPlayer, String targPlayer, String residence, boolean resadmin) {
   ClaimedResidence res = getByName(residence);
   if (res == null) {
     reqPlayer.sendMessage("§c" + Residence.getLanguage().getPhrase("InvalidResidence"));
     return;
   }
   if (!res.getPermissions().hasResidencePermission(reqPlayer, true) && !resadmin) {
     reqPlayer.sendMessage("§c" + Residence.getLanguage().getPhrase("NoPermission"));
     return;
   }
   Player giveplayer = Residence.getServ().getPlayer(targPlayer);
   if (giveplayer == null || !giveplayer.isOnline()) {
     reqPlayer.sendMessage("§c" + Residence.getLanguage().getPhrase("NotOnline"));
     return;
   }
   CuboidArea[] areas = res.getAreaArray();
   PermissionGroup g = Residence.getPermissionManager().getGroup(giveplayer);
   if (areas.length > g.getMaxPhysicalPerResidence() && !resadmin) {
     reqPlayer.sendMessage("§c" + Residence.getLanguage().getPhrase("ResidenceGiveLimits"));
     return;
   }
   if (getOwnedZoneCount(giveplayer.getName()) >= g.getMaxZones() && !resadmin) {
     reqPlayer.sendMessage("§c" + Residence.getLanguage().getPhrase("ResidenceGiveLimits"));
     return;
   }
   if (!resadmin) {
     for (CuboidArea area : areas) {
       if (!g.inLimits(area)) {
         reqPlayer.sendMessage("§c" + Residence.getLanguage().getPhrase("ResidenceGiveLimits"));
         return;
       }
     }
   }
   res.getPermissions().setOwner(giveplayer.getName(), true);
   reqPlayer.sendMessage(
       "§a"
           + Residence.getLanguage()
               .getPhrase(
                   "ResidenceGive", "§e" + residence + "§a.§e" + giveplayer.getName() + "§a"));
   giveplayer.sendMessage(
       Residence.getLanguage()
           .getPhrase(
               "ResidenceRecieve", "§a" + reqPlayer.getName() + "§e.§a" + residence + "§e"));
 }