Ejemplo n.º 1
0
    @Command(
        name = "remove",
        permission = "mytown.cmd.assistant.ranks.remove",
        parentName = "mytown.cmd.everyone.ranks",
        syntax = "/town ranks remove <rank>",
        completionKeys = {"rankCompletion"})
    public static CommandResponse ranksRemoveCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);
      Rank rank = getRankFromTown(town, args.get(0));

      if (rank.getType().unique) {
        throw new MyTownCommandException("mytown.cmd.err.ranks.cantDelete");
      }

      for (Rank residentRank : town.residentsMap.values()) {
        if (residentRank == rank) {
          throw new MyTownCommandException("mytown.cmd.err.ranks.assigned");
        }
      }

      getDatasource().deleteRank(rank);
      res.sendMessage(
          getLocal()
              .getLocalization("mytown.notification.town.ranks.rem", args.get(0), town.getName()));

      return CommandResponse.DONE;
    }
Ejemplo n.º 2
0
  /**
   * Delete a resident and it's data file (if not online) Available Only to players with the
   * 'towny.admin' permission node.
   *
   * @param player
   * @param split
   */
  public void residentDelete(Player player, String[] split) {

    if (split.length == 0)
      TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));
    else
      try {
        if (!TownyUniverse.getPermissionSource().isTownyAdmin(player))
          throw new TownyException(TownySettings.getLangString("msg_err_admin_only_delete"));

        for (String name : split) {
          try {
            Resident resident = TownyUniverse.getDataSource().getResident(name);
            if (!resident.isNPC() && !BukkitTools.isOnline(resident.getName())) {
              TownyUniverse.getDataSource().removeResident(resident);
              TownyUniverse.getDataSource().removeResidentList(resident);
              TownyMessaging.sendGlobalMessage(TownySettings.getDelResidentMsg(resident));
            } else
              TownyMessaging.sendErrorMsg(
                  player,
                  String.format(TownySettings.getLangString("msg_err_online_or_npc"), name));
          } catch (NotRegisteredException x) {
            // This name isn't registered as a resident
            TownyMessaging.sendErrorMsg(
                player, String.format(TownySettings.getLangString("msg_err_invalid_name"), name));
          }
        }
      } catch (TownyException x) {
        // Admin only escape
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
      }
  }
Ejemplo n.º 3
0
  @Command(
      name = "pass",
      permission = "mytown.cmd.mayor.pass",
      parentName = "mytown.cmd",
      syntax = "/town pass <resident>",
      completionKeys = {"residentCompletion"})
  public static CommandResponse passCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Resident target = getResidentFromName(args.get(0));

    if (res == target) {
      throw new MyTownCommandException("mytown.cmd.err.resident.same");
    }

    Town town = getTownFromResident(res);

    if (!town.residentsMap.containsKey(target)) {
      throw new MyTownCommandException(
          "mytown.cmd.err.resident.notsametown", target.getPlayerName(), town.getName());
    }
    if (town.residentsMap.get(res).getType() == Rank.Type.MAYOR) {
      getDatasource().updateResidentToTownLink(target, town, town.ranksContainer.getMayorRank());
      target.sendMessage(getLocal().getLocalization("mytown.notification.town.mayorShip.passed"));
      getDatasource().updateResidentToTownLink(res, town, town.ranksContainer.getDefaultRank());
      res.sendMessage(getLocal().getLocalization("mytown.notification.town.mayorShip.taken"));
    } else {
      // ...
    }
    return CommandResponse.DONE;
  }
Ejemplo n.º 4
0
  @Command(
      name = "promote",
      permission = "mytown.cmd.assistant.promote",
      parentName = "mytown.cmd",
      syntax = "/town promote <resident> <rank>",
      completionKeys = {"residentCompletion", "rankCompletion"})
  public static CommandResponse promoteCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 2) return CommandResponse.SEND_SYNTAX;
    Resident resSender = MyTownUniverse.instance.getOrMakeResident(sender);
    Resident resTarget = getResidentFromName(args.get(0));
    Town town = getTownFromResident(resSender);

    if (!resTarget.townsContainer.contains(town))
      throw new MyTownCommandException(
          "mytown.cmd.err.resident.notsametown", args.get(0), town.getName());

    Rank mayorRank = town.ranksContainer.getMayorRank();
    if (args.get(1).equalsIgnoreCase(mayorRank.getName()))
      throw new MyTownCommandException("mytown.cmd.err.promote.notMayor");
    Rank rank = getRankFromTown(town, args.get(1));
    if (getDatasource().updateResidentToTownLink(resTarget, town, rank)) {
      resSender.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.cmd.promote.success.sender", resTarget.getPlayerName(), rank.getName()));
      resTarget.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.cmd.promote.success.target", rank.getName(), town.getName()));
    }
    return CommandResponse.DONE;
  }
Ejemplo n.º 5
0
  @Override
  public List<String> getTreeString(int depth) {
    List<String> out = new ArrayList<String>();
    out.add(getTreeDepth(depth) + "Universe (" + getName() + ")");
    if (plugin != null) {
      out.add(getTreeDepth(depth + 1) + "Server (" + plugin.getServer().getName() + ")");
      out.add(getTreeDepth(depth + 2) + "Version: " + plugin.getServer().getVersion());
      out.add(
          getTreeDepth(depth + 2)
              + "Players: "
              + plugin.getServer().getOnlinePlayers().length
              + "/"
              + plugin.getServer().getMaxPlayers());
      out.add(
          getTreeDepth(depth + 2)
              + "Worlds ("
              + plugin.getServer().getWorlds().size()
              + "): "
              + Arrays.toString(plugin.getServer().getWorlds().toArray(new World[0])));
    }
    out.add(getTreeDepth(depth + 1) + "Worlds (" + getDataSource().getWorlds().size() + "):");
    for (TownyWorld world : getDataSource().getWorlds()) out.addAll(world.getTreeString(depth + 2));

    out.add(getTreeDepth(depth + 1) + "Nations (" + getDataSource().getNations().size() + "):");
    for (Nation nation : getDataSource().getNations()) out.addAll(nation.getTreeString(depth + 2));

    Collection<Town> townsWithoutNation = getDataSource().getTownsWithoutNation();
    out.add(getTreeDepth(depth + 1) + "Towns (" + townsWithoutNation.size() + "):");
    for (Town town : townsWithoutNation) out.addAll(town.getTreeString(depth + 2));

    Collection<Resident> residentsWithoutTown = getDataSource().getResidentsWithoutTown();
    out.add(getTreeDepth(depth + 1) + "Residents (" + residentsWithoutTown.size() + "):");
    for (Resident resident : residentsWithoutTown) out.addAll(resident.getTreeString(depth + 2));
    return out;
  }
Ejemplo n.º 6
0
    @Command(
        name = "add",
        permission = "mytown.cmd.assistant.ranks.add",
        parentName = "mytown.cmd.everyone.ranks",
        syntax = "/town ranks add <name> [templateRank]",
        completionKeys = {"-", "ranksCompletion"})
    public static CommandResponse ranksAddCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);

      if (town.ranksContainer.contains(args.get(0)))
        throw new MyTownCommandException("mytown.cmd.err.ranks.add.already", args.get(0));

      Rank rank = new Rank(args.get(0), town, Rank.Type.REGULAR);
      if (args.size() == 2) {
        Rank template = getRankFromTown(town, args.get(1));
        rank.permissionsContainer.addAll(template.permissionsContainer);
      }

      getDatasource().saveRank(rank);

      res.sendMessage(
          getLocal()
              .getLocalization("mytown.notification.town.ranks.add", args.get(0), town.getName()));
      return CommandResponse.DONE;
    }
Ejemplo n.º 7
0
  @Command(
      name = "unclaim",
      permission = "mytown.cmd.assistant.unclaim",
      parentName = "mytown.cmd",
      syntax = "/town unclaim")
  public static CommandResponse unclaimCommand(ICommandSender sender, List<String> args) {
    EntityPlayer player = (EntityPlayer) sender;
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    TownBlock block = getBlockAtResident(res);
    Town town = getTownFromResident(res);

    if (town != block.getTown())
      throw new MyTownCommandException("mytown.cmd.err.unclaim.notInTown");
    if (block.isPointIn(town.getSpawn().getDim(), town.getSpawn().getX(), town.getSpawn().getZ()))
      throw new MyTownCommandException("mytown.cmd.err.unclaim.spawnPoint");
    if (!checkNearby(block.getDim(), block.getX(), block.getZ(), town)
        && town.townBlocksContainer.size() <= 1) {
      throw new MyTownCommandException("mytown.cmd.err.unclaim.lastClaim");
    }

    getDatasource().deleteBlock(block);
    res.sendMessage(
        getLocal()
            .getLocalization(
                "mytown.notification.block.removed",
                block.getX() << 4,
                block.getZ() << 4,
                block.getX() << 4 + 15,
                block.getZ() << 4 + 15,
                town.getName()));
    makeBankRefund(player, town, block.getPricePaid());
    return CommandResponse.DONE;
  }
Ejemplo n.º 8
0
  @Command(
      name = "kick",
      permission = "mytown.cmd.assistant.kick",
      parentName = "mytown.cmd",
      syntax = "/town kick <resident>",
      completionKeys = {"residentCompletion"})
  public static CommandResponse kickCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 1) {
      return CommandResponse.SEND_SYNTAX;
    }
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Resident target = getResidentFromName(args.get(0));
    Town town = getTownFromResident(res);
    if (!target.townsContainer.contains(town)) {
      throw new MyTownCommandException(
          "mytown.cmd.err.resident.notsametown", args.get(0), town.getName());
    }
    if (target == res) {
      throw new MyTownCommandException("mytown.cmd.err.kick.self");
    }

    if (town.residentsMap.get(target) == town.ranksContainer.getMayorRank()) {
      throw new MyTownCommandException("mytown.cmd.err.kick.mayor");
    }

    getDatasource().unlinkResidentFromTown(target, town);
    target.sendMessage(
        getLocal().getLocalization("mytown.notification.town.kicked", town.getName()));
    town.notifyEveryone(
        getLocal()
            .getLocalization(
                "mytown.notification.town.left", target.getPlayerName(), town.getName()));
    return CommandResponse.DONE;
  }
Ejemplo n.º 9
0
  @Command(
      name = "withdraw",
      permission = "mytown.cmd.assistant.bank.withdraw",
      parentName = "mytown.cmd.everyone.bank",
      syntax = "/town bank withdraw <amount>")
  public static CommandResponse bankWithdrawCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

    if (!StringUtils.tryParseInt(args.get(0)))
      throw new MyTownCommandException("mytown.cmd.err.notPositiveInteger", args.get(0));

    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);

    if (town instanceof AdminTown)
      throw new MyTownCommandException("mytown.cmd.err.adminTown", town.getName());

    int amount = Integer.parseInt(args.get(0));
    if (town.bank.getAmount() < amount)
      throw new MyTownCommandException(
          "mytown.cmd.err.bank.withdraw", EconomyProxy.getCurrency(town.bank.getAmount()));

    makeRefund(res.getPlayer(), amount);
    town.bank.addAmount(-amount);
    getDatasource().saveTownBank(town.bank);
    return CommandResponse.DONE;
  }
Ejemplo n.º 10
0
  @Command(
      name = "delete",
      permission = "mytown.cmd.mayor.leave.delete",
      parentName = "mytown.cmd.everyone.leave",
      syntax = "/town leave delete")
  public static CommandResponse leaveDeleteCommand(ICommandSender sender, List<String> args) {
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    EntityPlayer player = (EntityPlayer) sender;

    if (town.residentsMap.get(res).getType() == Rank.Type.MAYOR) {
      town.notifyEveryone(
          getLocal()
              .getLocalization(
                  "mytown.notification.town.deleted", town.getName(), res.getPlayerName()));
      int refund = 0;
      for (TownBlock block : town.townBlocksContainer) {
        refund += block.getPricePaid();
      }
      refund += town.bank.getAmount();
      makeRefund(player, refund);
      getDatasource().deleteTown(town);
    }
    return CommandResponse.DONE;
  }
Ejemplo n.º 11
0
 public List<String> getResidentsAsString() {
   List<String> res = new ArrayList<String>();
   for (Resident r : this.residents) {
     res.add(r.getName());
   }
   return res;
 }
Ejemplo n.º 12
0
    @Command(
        name = "reset",
        permission = "mytown.cmd.assistant.ranks.reset",
        parentName = "mytown.cmd.everyone.ranks",
        syntax = "/town ranks reset")
    public static CommandResponse ranksResetCommand(ICommandSender sender, List<String> args) {
      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);

      for (Rank defaultRank : Rank.defaultRanks) {
        Rank rank = town.ranksContainer.get(defaultRank.getName());

        rank.permissionsContainer.clear();
        rank.permissionsContainer.addAll(defaultRank.permissionsContainer);
        rank.setType(defaultRank.getType());

        getDatasource().saveRank(rank);
      }

      for (int i = 0; i < town.ranksContainer.size(); i++) {
        Rank rank = town.ranksContainer.get(i);
        if (!Rank.defaultRanks.contains(rank.getName())) {
          getDatasource().deleteRank(rank);
          i--;
        }
      }

      res.sendMessage(getLocal().getLocalization("mytown.notification.ranks.reset"));

      return CommandResponse.DONE;
    }
Ejemplo n.º 13
0
 public static void sendMessageBackToSender(ICommandSender sender, String message) {
   if (sender instanceof EntityPlayer) {
     Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
     res.sendMessage(message);
   } else {
     sender.addChatMessage(new ChatComponentText(message));
   }
 }
Ejemplo n.º 14
0
 public void onLogout(Player player) {
   try {
     Resident resident = getDataSource().getResident(player.getName());
     resident.setLastOnline(System.currentTimeMillis());
     getDataSource().saveResident(resident);
   } catch (NotRegisteredException e) {
   }
   setChangedNotify(PLAYER_LOGOUT);
 }
Ejemplo n.º 15
0
 public static void makeRefund(EntityPlayer player, int amount) {
   if (amount == 0) return;
   Resident res = MyTownUniverse.instance.getOrMakeResident(player);
   EconomyProxy.getEconomy().giveMoneyToPlayer(player, amount);
   res.sendMessage(
       getLocal()
           .getLocalization(
               "mytown.notification.resident.refund", EconomyProxy.getCurrency(amount)));
 }
Ejemplo n.º 16
0
 public List<Player> getOnlineResidents() {
   List<Player> players = new ArrayList<Player>();
   for (Resident r : this.residents) {
     OfflinePlayer p = Bukkit.getOfflinePlayer(r.getName());
     if (!p.isOnline()) continue;
     players.add(p.getPlayer());
   }
   return players;
 }
Ejemplo n.º 17
0
 public Location getTownSpawnLocation(Player player) throws TownyException {
   try {
     Resident resident = getDataSource().getResident(player.getName());
     Town town = resident.getTown();
     return town.getSpawn();
   } catch (TownyException x) {
     throw new TownyException("Unable to get spawn location");
   }
 }
Ejemplo n.º 18
0
  public List<Resident> getOnlineResidents(ResidentList residentList) {
    List<Resident> onlineResidents = new ArrayList<Resident>();
    for (Player player : plugin.getServer().getOnlinePlayers()) {
      for (Resident resident : residentList.getResidents()) {
        if (resident.getName().equalsIgnoreCase(player.getName())) onlineResidents.add(resident);
      }
    }

    return onlineResidents;
  }
Ejemplo n.º 19
0
  public void onLogin(Player player) throws AlreadyRegisteredException, NotRegisteredException {

    if (!player.isOnline()) return;

    // Test and kick any players with invalid names.
    if ((player.getName().trim() == null) || (player.getName().contains(" "))) {
      player.kickPlayer("Invalid name!");
      return;
    }

    Resident resident;

    if (!getDataSource().hasResident(player.getName())) {
      getDataSource().newResident(player.getName());
      resident = getDataSource().getResident(player.getName());

      TownyMessaging.sendMessage(player, TownySettings.getRegistrationMsg(player.getName()));
      resident.setRegistered(System.currentTimeMillis());
      if (!TownySettings.getDefaultTownName().equals(""))
        try {
          Town town = getDataSource().getTown(TownySettings.getDefaultTownName());
          town.addResident(resident);
          getDataSource().saveTown(town);
        } catch (NotRegisteredException e) {
        } catch (AlreadyRegisteredException e) {
        }

      getDataSource().saveResident(resident);
      getDataSource().saveResidentList();

    } else {
      resident = getDataSource().getResident(player.getName());
      resident.setLastOnline(System.currentTimeMillis());

      getDataSource().saveResident(resident);
    }

    try {
      TownyMessaging.sendTownBoard(player, resident.getTown());
    } catch (NotRegisteredException e) {
    }

    if (isWarTime()) getWarEvent().sendScores(player, 3);

    // Schedule to setup default modes when the player has finished loading
    if (getPlugin()
            .getServer()
            .getScheduler()
            .scheduleSyncDelayedTask(getPlugin(), new SetDefaultModes(this, player, false), 1)
        == -1)
      TownyMessaging.sendErrorMsg("Could not set default modes for " + player.getName() + ".");

    setChangedNotify(PLAYER_LOGIN);
  }
Ejemplo n.º 20
0
 public static void makePayment(EntityPlayer player, int amount) {
   if (amount == 0) return;
   Resident res = MyTownUniverse.instance.getOrMakeResident(player);
   if (!EconomyProxy.getEconomy().takeMoneyFromPlayer(player, amount)) {
     throw new MyTownCommandException(
         "mytown.cmd.err.resident.payment", EconomyProxy.getCurrency(amount));
   }
   res.sendMessage(
       getLocal()
           .getLocalization(
               "mytown.notification.resident.payment", EconomyProxy.getCurrency(amount)));
 }
Ejemplo n.º 21
0
 public static TownBlock getBlockAtResident(Resident res) {
   TownBlock block =
       getUniverse()
           .blocks
           .get(
               res.getPlayer().dimension,
               ((int) res.getPlayer().posX) >> 4,
               ((int) res.getPlayer().posZ >> 4));
   if (block == null)
     throw new MyTownCommandException(
         "mytown.cmd.err.claim.notexist", res.townsContainer.getMainTown().getName());
   return block;
 }
Ejemplo n.º 22
0
 @Command(
     name = "show",
     permission = "mytown.cmd.assistant.plot.limit.show",
     parentName = "mytown.cmd.assistant.plot.limit",
     syntax = "/town plot limit show")
 public static CommandResponse plotLimitShowCommand(ICommandSender sender, List<String> args) {
   Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
   Town town = getTownFromResident(res);
   res.sendMessage(
       getLocal()
           .getLocalization(
               "mytown.notification.plot.limit", town.plotsContainer.getMaxPlots()));
   return CommandResponse.DONE;
 }
Ejemplo n.º 23
0
    @Command(
        name = "set",
        permission = "mytown.cmd.assistant.ranks.set",
        parentName = "mytown.cmd.everyone.ranks",
        syntax = "/town ranks set <rank> <type>",
        completionKeys = {"rankCompletion"})
    public static CommandResponse ranksSetCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 2) {
        return CommandResponse.SEND_SYNTAX;
      }

      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);
      Rank rank = getRankFromTown(town, args.get(0));
      Rank.Type type = getRankTypeFromString(args.get(1));

      if (type.unique) {
        Rank fromRank = town.ranksContainer.get(type);
        if (fromRank == rank) {
          throw new MyTownCommandException("mytown.cmd.err.ranks.set.already", type.toString());
        }

        fromRank.setType(Rank.Type.REGULAR);
        rank.setType(type);

        getDatasource().saveRank(rank);
        getDatasource().saveRank(fromRank);
      } else {
        if (rank.getType().unique) {
          throw new MyTownCommandException("mytown.cmd.err.ranks.set.unique", rank.getName());
        }

        rank.setType(type);

        getDatasource().saveRank(rank);
      }

      res.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.notification.ranks.set.successful", rank.getName(), type.toString()));
      return CommandResponse.DONE;
    }
Ejemplo n.º 24
0
  @Command(
      name = "rename",
      permission = "mytown.cmd.assistant.rename",
      parentName = "mytown.cmd",
      syntax = "/town rename <name>")
  public static CommandResponse renameCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);

    if (getUniverse().towns.contains(args.get(0))) // Is the town name already in use?
    throw new MyTownCommandException("mytown.cmd.err.newtown.nameinuse", args.get(0));

    town.rename(args.get(0));
    getDatasource().saveTown(town);
    res.sendMessage(getLocal().getLocalization("mytown.notification.town.renamed"));
    return CommandResponse.DONE;
  }
Ejemplo n.º 25
0
  @Override
  public void step(SimState simState) {
    long stepsIntoRun = ((EbolaABM) simState).schedule.getSteps();

    if (stepsIntoRun % 24 != 0) return;

    if (state == State.IDENTIFYING) {
      if (daysIdentifying == Parameters.DAYS_TO_IDENTIFY) {
        // we are done identifying, tell manager to add discovered contacts of this resident
        myManager.addContactsForFollowUp(whoseContactsBeingIdentified);
        state = State.FREE;
        daysIdentifying = 0;
      } else daysIdentifying++;

      return;
    }

    if (state == State.FOLLOWING_UP) {
      int todaysListIndex = totalFollowUpDays % Parameters.DAYS_BETWEEN_CHECKS;
      ArrayList<Resident> todaysList = followUpLists.get(todaysListIndex);

      for (Resident resident : todaysList) {
        if (resident.getFollowedUpDays() == Parameters.FOLLOW_UP_DAYS) {
          // no need to check this resident further, remove this resident from our day's list
          todaysList.remove(resident);
        } else // check resident's health status
        if (resident.getHealthStatus() == Constants.INFECTIOUS) {
          // resident is sick, stop following up and immediately send him to nearest ETC
          // TODO: Add code to send resident to nearest ETC

          todaysList.remove(resident);
        } else // increment resident's follow up day count
        resident.incrementFollowUpDays();
      }

      if (getFollowUpCapacity() == 0) state = State.FREE;

      totalFollowUpDays++;
    }

    System.out.println(this);
  }
Ejemplo n.º 26
0
  /** Populates the tab completion map. */
  public static void populateCompletionMap() {

    List<String> populator = new ArrayList<String>();
    for (Town town : getUniverse().towns) {
      populator.add(town.getName());
    }

    CommandCompletion.addCompletions("townCompletionAndAll", populator);
    CommandCompletion.addCompletion("townCompletionAndAll", "@a");

    CommandCompletion.addCompletions("townCompletion", populator);

    populator = new ArrayList<String>();
    for (Resident res : getUniverse().residents) {
      populator.add(res.getPlayerName());
    }
    CommandCompletion.addCompletions("residentCompletion", populator);

    populator = new ArrayList<String>();
    for (FlagType flag : FlagType.values()) {
      populator.add(flag.name.toLowerCase());
    }
    CommandCompletion.addCompletions("flagCompletion", populator);

    populator = new ArrayList<String>();
    for (FlagType flag : FlagType.values()) {
      if (flag.isWhitelistable) populator.add(flag.name.toLowerCase());
    }
    CommandCompletion.addCompletions("flagCompletionWhitelist", populator);

    populator = new ArrayList<String>();
    for (Plot plot : MyTownUniverse.instance.plots) {
      populator.add(plot.toString());
    }
    CommandCompletion.addCompletions("plotCompletion", populator);

    populator = new ArrayList<String>();
    for (Rank rank : Rank.defaultRanks) {
      populator.add(rank.getName());
    }
    CommandCompletion.addCompletions("rankCompletion", populator);
  }
Ejemplo n.º 27
0
 public void setResident(Resident resident) {
   try {
     if (hasResident()) this.resident.removeTownBlock(this);
   } catch (NotRegisteredException e) {
   }
   this.resident = resident;
   try {
     resident.addTownBlock(this);
   } catch (AlreadyRegisteredException e) {
   } catch (NullPointerException e) {
   }
 }
Ejemplo n.º 28
0
    @Command(
        name = "remove",
        permission = "mytown.cmd.assistant.ranks.perm.remove",
        parentName = "mytown.cmd.assistant.ranks.perm",
        syntax = "/town ranks perm remove <rank> <perm>",
        completionKeys = {"rankCompletion"})
    public static CommandResponse ranksPermRemoveCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 2) return CommandResponse.SEND_SYNTAX;

      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);
      Rank rank = getRankFromTown(town, args.get(0));

      getDatasource().deleteRankPermission(rank, args.get(1));
      res.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.notification.town.ranks.perm.remove", args.get(1), args.get(0)));

      return CommandResponse.DONE;
    }
Ejemplo n.º 29
0
  @Command(
      name = "invite",
      permission = "mytown.cmd.assistant.invite",
      parentName = "mytown.cmd",
      syntax = "/town invite <resident>",
      completionKeys = {"residentCompletion"})
  public static CommandResponse inviteCommand(ICommandSender sender, List<String> args) {
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    if (args.size() < 1) return CommandResponse.SEND_SYNTAX;
    Resident target = getResidentFromName(args.get(0));
    if (town.residentsMap.contains(args.get(0)))
      throw new MyTownCommandException(
          "mytown.cmd.err.invite.already", args.get(0), town.getName());

    getDatasource().saveTownInvite(target, town);
    target.sendMessage(
        getLocal().getLocalization("mytown.notification.town.invited", town.getName()));
    res.sendMessage(
        getLocal().getLocalization("mytown.notification.town.invite.sent", args.get(0)));
    return CommandResponse.DONE;
  }
Ejemplo n.º 30
0
    @Command(
        name = "set",
        permission = "mytown.cmd.assistant.plot.limit.set",
        parentName = "mytown.cmd.assistant.plot.limit",
        syntax = "/town plot limit set <limit>")
    public static CommandResponse plotLimitSetCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

      if (!StringUtils.tryParseInt(args.get(0)) || Integer.parseInt(args.get(0)) < 1) {
        throw new MyTownCommandException("mytown.cmd.err.notPositiveInteger", args.get(0));
      }
      int limit = Integer.parseInt(args.get(0));
      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);
      town.plotsContainer.setMaxPlots(limit);
      getDatasource().saveTown(town);
      res.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.notification.plot.limit.set", town.plotsContainer.getMaxPlots()));
      return CommandResponse.DONE;
    }