Converting 'Player' to 'Resident' for Towny hook.

Discussion in 'Plugin Development' started by dxwarlock, Jun 6, 2012.

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

    dxwarlock

    Anyone know the syntax for converting the command sender to 'Resident' that towny accepts for it 'townAddResident(Town town,Resident resident)' command?

    Im working on doing a /command I need for my server that puts said player into a start town of thier choice...issue is that:

    Resident res = (Player)cs;
    and
    Resident res = player.getName();

    dont work, as obviously it looking for the Resident, and get "Type mismatch cannot convert Player to Resident" error in eclipse.

    anyone know what the correct way to do this is?
     
  2. Offline

    BobbyD441

    You are using the wrong cast: Resident res = (Player)cs;
    You should cast the player to resident like so: Resident res = (Resident) player;
     
  3. Offline

    dxwarlock

    ahh...silly me.
    dont know why I didnt think of that

    Ok even after that ignorant mistake it seems setting a 'Town' doesnt work that way.
    any tips of trying to set the town, even if just hardcoded for now? what I have is:
    Code:java
    1.  
    2. public void NewPlayer(Player player){
    3. Resident resident = (Resident)player;
    4. Town town = Town("Starter");
    5. town.addResident(resident);
    6. TownyUniverse.getDataSource().saveResident(resident);
    7. TownyUniverse.getDataSource().saveTown(town);
    8. }
    9.  


    the Town town = Town("Starter"); fails, again by a "Town to String" issue.
    Sorry for the noobness, first time diving into hooking Towny.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  4. Offline

    BobbyD441

    try:
    Code:
     Town town = new Town("starter");
    
     
  5. Offline

    dxwarlock

    Ill give that a shot, thanks!
     
  6. I don't belive casting that will work.... you'll get a similar error because the player object isn't created as a Resident...

    I looked into Towny and it seems residents are made from player names like this:
    Code:
    Resident resident = new Resident(player.getName());
     
Thread Status:
Not open for further replies.

Share This Page