Package com.palmergames.bukkit.towny.object

Examples of com.palmergames.bukkit.towny.object.Resident


      TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));

  }

  public void nationEnemy(Player player, String[] split) {
    Resident resident;
    Nation nation;

    if (split.length < 2) {
      TownyMessaging.sendErrorMsg(player, "Eg: /nation enemy [add/remove] [name]");
      return;
    }

    try {
      resident = TownyUniverse.getDataSource().getResident(player.getName());
      nation = resident.getTown().getNation();
      if (!resident.isKing())
        if (!nation.hasAssistant(resident))
          throw new TownyException(TownySettings.getLangString("msg_not_king_ass"));
    } catch (TownyException x) {
      TownyMessaging.sendErrorMsg(player, x.getMessage());
      return;
View Full Code Here


      player.sendMessage(ChatTools.formatCommand("", "/nation set", "taxes [$]", ""));
      player.sendMessage(ChatTools.formatCommand("", "/nation set", "name [name]", ""));
      player.sendMessage(ChatTools.formatCommand("", "/nation set", "title/surname [resident] [text]", ""));
      player.sendMessage(ChatTools.formatCommand("", "/nation set", "tag [upto 4 letters] or clear", ""));
    } else {
      Resident resident;
      Nation nation;
      try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
        nation = resident.getTown().getNation();
        if (!resident.isKing())
          if (!nation.hasAssistant(resident))
            throw new TownyException(TownySettings.getLangString("msg_not_king_ass"));
      } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
      }

      // TODO: Let admin's call a subfunction of this.
      if (split[0].equalsIgnoreCase("king")) {
        if (split.length < 2)
          TownyMessaging.sendErrorMsg(player, "Eg: /nation set king Dumbo");
        else
          try {
            Resident newKing = TownyUniverse.getDataSource().getResident(split[1]);
            String oldKingsName = nation.getCapital().getMayor().getName();
            nation.setKing(newKing);
            plugin.deleteCache(oldKingsName);
            plugin.deleteCache(newKing.getName());
            TownyMessaging.sendNationMessage(nation, TownySettings.getNewKingMsg(newKing.getName(), nation.getName()));
          } catch (TownyException e) {
            TownyMessaging.sendErrorMsg(player, e.getMessage());
          }
      } else if (split[0].equalsIgnoreCase("capital")) {
        if (split.length < 2)
View Full Code Here

  public void nationToggle(Player player, String[] split) {
    if (split.length == 0) {
      player.sendMessage(ChatTools.formatTitle("/nation toggle"));
      player.sendMessage(ChatTools.formatCommand("", "/nation toggle", "neutral", ""));
    } else {
      Resident resident;
      Nation nation;
      try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
        nation = resident.getTown().getNation();
        if (!resident.isKing())
          if (!nation.hasAssistant(resident))
            throw new TownyException(TownySettings.getLangString("msg_not_king_ass"));
      } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
View Full Code Here

  private List<Resident> getResidents(Player player, String[] names) {
    List<Resident> invited = new ArrayList<Resident>();
    for (String name : names)
      try {
        Resident target = TownyUniverse.getDataSource().getResident(name);
        invited.add(target);
      } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
      }
    return invited;
View Full Code Here

                                        sendErrorMsg(player, x.getMessage());
                                        return;
                                }
                        } else if (split.length == 1)
                                try {
                                        Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                                        town = resident.getTown();
                                } catch (NotRegisteredException x) {
                                }
                               
                        for (String line : getTownyPrices(town))
                                player.sendMessage(line);
View Full Code Here

    }

    @Override
    public void onCustomEvent(Event event) {

      Resident resident = null;
      Player player = null;

      try {
        if (event instanceof GMUserEvent) {
         
          if (PermissionEventEnums.GMUser_Action.valueOf(event.getEventName()) != null) {
            GMUserEvent UserEvent = (GMUserEvent) event;
            try {
              resident = TownyUniverse.getDataSource().getResident(UserEvent.getUserName());
              player = plugin.getServer().getPlayerExact(resident.getName());
              if (player != null) {
                //setup default modes for this player.
                String[] modes = getPlayerPermissionStringNode(player.getName(), PermissionNodes.TOWNY_DEFAULT_MODES.getNode()).split(",");
                plugin.setPlayerMode(player, modes, false);
              }
View Full Code Here

  }
 
  public static void generateAndSend(Towny plugin, Player player, int lineHeight) {
    // Collect Sample Data
    boolean hasTown = false;
    Resident resident;
    try {
      resident = TownyUniverse.getDataSource().getResident(player.getName());
      if (resident.hasTown())
        hasTown = true;
    } catch (TownyException x) {
      TownyMessaging.sendErrorMsg(player, x.getMessage());
      return;
    }

    TownyWorld world;
    try {
      world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
    } catch (NotRegisteredException e1) {
      TownyMessaging.sendErrorMsg(player, "You are not in a registered world.");
      return;
    }
    if (!world.isUsingTowny()) {
      TownyMessaging.sendErrorMsg(player, "This world is not using towny.");
      return;
    }
    Coord pos = Coord.parseCoord(plugin.getCache(player).getLastLocation());

    // Generate Map
    int halfLineHeight = lineHeight / 2;
    String[][] townyMap = new String[lineWidth][lineHeight];
    int x, y = 0;
    for (int tby = pos.getX() + (lineWidth-halfLineWidth-1); tby >= pos.getX() - halfLineWidth; tby--) {
      x = 0;
      for (int tbx = pos.getZ() - halfLineHeight; tbx <= pos.getZ() + (lineHeight-halfLineHeight-1); tbx++) {
        try {
          TownBlock townblock = world.getTownBlock(tby, tbx);
          //TODO: possibly claim outside of towns
          if (!townblock.hasTown())
            throw new TownyException();
          if (x == halfLineHeight && y == halfLineWidth)
            // location
            townyMap[y][x] = Colors.Gold;
          else if (hasTown) {
            if (resident.getTown() == townblock.getTown()) {
              // own town
              townyMap[y][x] = Colors.LightGreen;
              try {
                if (resident == townblock.getResident())
                  //own plot
                  townyMap[y][x] = Colors.Yellow;
              } catch(NotRegisteredException e) {
              }
            } else if (resident.hasNation()) {
              if (resident.getTown().getNation().hasTown(townblock.getTown()))
                // towns
                townyMap[y][x] = Colors.Green;
              else if (townblock.getTown().hasNation()) {
                Nation nation = resident.getTown().getNation();
                if (nation.hasAlly(townblock.getTown().getNation()))
                  townyMap[y][x] = Colors.Green;
                else if (nation.hasEnemy(townblock.getTown().getNation()))
                  // towns
                  townyMap[y][x] = Colors.Red;
View Full Code Here

            return true;
          }
        }

        if (b instanceof Animals) {
          Resident resident = TownyUniverse.getDataSource().getResident(ap.getName());
          if ((!resident.hasTown()) || (resident.hasTown() && (resident.getTown() != townblock.getTown())))
            return true;
        }
      }
    } catch (NotRegisteredException e) {
      // Not in a town
View Full Code Here

    }

    @Override
    public void onCustomEvent(Event event) {

      Resident resident = null;
      Player player = null;

      try {
        if (event instanceof PermissionEntityEvent) {
          if (PermissionEventEnums.PEXEntity_Action.valueOf(event.getEventName()) != null) {
            PermissionEntityEvent EntityEvent = (PermissionEntityEvent) event;
            PermissionEntity entity = EntityEvent.getEntity();
            if (entity instanceof PermissionGroup) {
              PermissionGroup group = (PermissionGroup)entity;
             
              // Update all players who are in this group.
              for (Player toUpdate : TownyUniverse.getOnlinePlayers()) {
                if (Arrays.asList(getPlayerGroups(toUpdate)).contains(group)) {
                  //setup default modes
                  String[] modes = getPlayerPermissionStringNode(toUpdate.getName(), PermissionNodes.TOWNY_DEFAULT_MODES.getNode()).split(",");
                  plugin.setPlayerMode(player, modes, false);
                }
              }
             
            } else if (entity instanceof PermissionUser) {
             
              try {
                resident = TownyUniverse.getDataSource().getResident(((PermissionUser)entity).getName());
                player = plugin.getServer().getPlayerExact(resident.getName());
                if (player != null) {
                  //setup default modes for this player.
                  String[] modes = getPlayerPermissionStringNode(player.getName(), PermissionNodes.TOWNY_DEFAULT_MODES.getNode()).split(",");
                  plugin.setPlayerMode(player, modes, false);
                }
View Full Code Here

  public void parseNationCommand(Player player, String[] split) {
    String nationCom = "/nation";

    if (split.length == 0)
      try {
        Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
        Town town = resident.getTown();
        Nation nation = town.getNation();
        TownyMessaging.sendMessage(player, TownyFormatter.getStatus(nation));
      } catch (NotRegisteredException x) {
        TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_dont_belong_nation"));
      }
    else if (split[0].equalsIgnoreCase("?"))
      for (String line : nation_help)
        player.sendMessage(line);
    else if (split[0].equalsIgnoreCase("list"))
      listNations(player);
    else if (split[0].equalsIgnoreCase("new")) {
      // TODO: Make an overloaded function
      // newNation(Player,String,Town)
      if (split.length == 1)
        TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_specify_nation_name"));
      else if (split.length == 2)
        try { // TODO: Make sure of the error catching
          Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
          if (!resident.isMayor() && !resident.getTown().hasAssistant(resident))
            throw new TownyException(TownySettings.getLangString("msg_peasant_right"));
          newNation(player, split[1], resident.getTown().getName());
        } catch (TownyException x) {
          TownyMessaging.sendErrorMsg(player, x.getMessage());
        }
      else
        // TODO: Check if player is an admin
        newNation(player, split[1], split[2]);
    } else if (split[0].equalsIgnoreCase("leave"))
      nationLeave(player);
    else if (split[0].equalsIgnoreCase("withdraw")) {
      if (split.length == 2)
        try {
          nationWithdraw(player, Integer.parseInt(split[1].trim()));
        } catch (NumberFormatException e) {
          TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_int"));
        }
      else
        TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_must_specify_amnt"), nationCom));
    } else if (split[0].equalsIgnoreCase("deposit")) {
      if (split.length == 2)
        try {
          nationDeposit(player, Integer.parseInt(split[1].trim()));
        } catch (NumberFormatException e) {
          TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_int"));
        }
      else
        TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_must_specify_amnt"), nationCom + " deposit"));
    } else {
      String[] newSplit = StringMgmt.remFirstArg(split);

      if (split[0].equalsIgnoreCase("king"))
        nationKing(player, newSplit);
      else if (split[0].equalsIgnoreCase("add"))
        nationAdd(player, newSplit);
      else if (split[0].equalsIgnoreCase("kick"))
        nationKick(player, newSplit);
      else if (split[0].equalsIgnoreCase("assistant"))
        nationAssistant(player, newSplit);
      else if (split[0].equalsIgnoreCase("set"))
        nationSet(player, newSplit);
      else if (split[0].equalsIgnoreCase("toggle"))
        nationToggle(player, newSplit);
      else if (split[0].equalsIgnoreCase("ally"))
        nationAlly(player, newSplit);
      else if (split[0].equalsIgnoreCase("enemy"))
        nationEnemy(player, newSplit);
      else if (split[0].equalsIgnoreCase("delete"))
        nationDelete(player, newSplit);
      else if (split[0].equalsIgnoreCase("online")) {
        try {
          Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
          Town town = resident.getTown();
          Nation nation = town.getNation();
          TownyMessaging.sendMessage(player, TownyFormatter.getFormattedOnlineResidents(plugin, TownySettings.getLangString("msg_nation_online"), nation));
        } catch (NotRegisteredException x) {
          TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_dont_belong_nation"));
        }
View Full Code Here

TOP

Related Classes of com.palmergames.bukkit.towny.object.Resident

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.