Difficulties to hook into towny (get player town name)

Discussion in 'Plugin Development' started by Thej0y, Jun 7, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Thej0y

    Hi,
    i'm having a hard time hooking into towny. I simply want to get the town name for the given resident.

    Here's my code:
    Code:
    if(resident.hasTown()){
        try {
            town = ("{" + resident.getTown().getName() + "}");
        } catch (NotRegisteredException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
            TownMap.put(sender.getName(), town);
        }else{
              sender.sendMessage(ChatColor.DARK_RED + "You must be in a town to use this command.");
    }
    It always fail at getTown() saying that the resident is not in a town which is trange because it mean it has passed the " if(resident.hasTown()) ".

    Anyone know what i'm doing wrong ? :p

    Thanks in advance :)
     
  2. Offline

    Tirelessly

    Well, first off, getTown() checks hasTown and if not it throws the NotRegisteredException, so you checking hasTown is redundant. You shouldnt print stack trace in the catch block. That might fix your issue.
     
  3. Offline

    Thej0y

    -.- gonna try this. XD
    Thanks

    Edit: I dont know what i messed up while i tryed to fix it, but now i can't pass hasTown().
    Just to be sure, is the way to pass the command sender as a resident is:

    Resident resident = new Resident(sender.getName());

    I thought i had included it in my first post, but i must had deleted it by mistake
    thanks

    Edit,Edit: Anyone know where i can get the ref to the class towny use? i can't find any api or infos for hooking

    Simplified it a bit, but still the same result... :( ... resident doesn't belongs to any town

    Code:
    //TownMap is a Hashmap String, String...
    ...{
    Resident resident = new Resident(sender.getName());
    String town = null;
        try {
            town = "{" + resident.getTown().getName() + "}";
            TownMap.put(sender.getName(), town);
        } catch (NotRegisteredException e) {
            sender.sendMessage(ChatColor.DARK_RED + "You must be in a town to use this command.");
        }
    }..
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  4. Offline

    EnderTroll68

    I see this is from quite awhile ago but it is the only thread I have found on the matter. It always seems to say that the resident does not belong to a town. Anyone have an idea?
     
Thread Status:
Not open for further replies.

Share This Page