Solved help with setting home and sending players home

Discussion in 'Plugin Development' started by jamiemac262, Jan 6, 2013.

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

    jamiemac262

    hi, i am trying to make my plugin ServerAI similar to essentials. i would like it to send players home and set their homes for them. i cannot seem to get it to work. it sets a home just fine but if the player has the permission sai.home it gives me a stacktrace

    PHP:
    else if((containsString(Playermessage"sai") && containsString(Playermessage"home") && containsString(Playermessage"set") == false)){
                if(
    p.hasPermission("sai.home")){
               
                    
    playerStatFile = new File("plugins" File.separator "ServerAI" File.separator "Players"p.getName() + ".yml");
                    
    playerStat YamlConfiguration.loadConfiguration(playerStatFile);
                    
    Location home = (LocationplayerStat.get("home");
                    
    p.teleport(home);
                    new 
    SendAIMessage(0.5,"Sure thing " p.getName() + "! welcome home","ahh, home sweet home","3... 2... uhhh, 1... WARP!");
                }
                else if(!
    p.hasPermission("sai.home")){
                   
                    
    noPerms();
                }
            }
            else if((
    containsString(Playermessage"sai") && containsString(Playermessage"set") && containsString(Playermessage"home"))){
                if(
    p.hasPermission("sai.home")){
               
                    
    playerStatFile = new File("plugins" File.separator "ServerAI" File.separator "Players"p.getName() + ".yml");
                    
    playerStat YamlConfiguration.loadConfiguration(playerStatFile);
                    
    playerStat.set("home"p.getLocation());
                   
                    new 
    SendAIMessage(0.5,"Sure thing " p.getName() + "! welcome home","ahh, home sweet home","Done! should i arrange a house warming?");
                }
                else if(!
    p.hasPermission("sai.home")){
                   
                    
    noPerms();
                }
            }
    the stacktrace is here http://pastebin.com/gmHYE1Vt
     
  2. Offline

    CorrieKay

    Your home location is null. Check your playerstat class that retrieves the location. (also, youre casting it to a location? Why not just use a loation object?)
     
  3. Offline

    jamiemac262

    sorry i'm still a bit of a noob with config files and... alot of java stuff :(

    could you paste an example? because i'm not sure what you mean by just use a location object :(
     
  4. Offline

    CubixCoders

    try using
    Code:java
    1.  
    2. if(playerStatFile.exists()){
    3. playerStat = YamlConfiguration.loadConfiguration(playerStatFile);
    4. Location home = (Location) playerStat.get("home");
    5. p.teleport(home);
    6. new SendAIMessage(0.5,"Sure thing " + p.getName() + "! welcome home","ahh, home sweet home","3... 2... uhhh, 1... WARP!");
    7. }
    8.  
     
  5. Offline

    CorrieKay

    You're casting whatever is returned by playerStat.get("home"); into a string, seen here:
    Code:
    Location home = (Location) playerStat.get("home");
    
    Thats what confused me.
     
  6. Offline

    CubixCoders

    Well its because its not just for location. As you see he is using "home" so it has to return Object because he can be using "name" to return a string too. See what i'm saying?
    He has it like this i think
    Map<String, Object> playerStat
     
  7. Offline

    CorrieKay

    Then you should do specific getter methods.

    public String getName()
    public Location getHome()

    etc. Anyways, check your method, its returning a null location.
     
  8. Offline

    jamiemac262

    so this sounds like it wont be a quick 5 minute fix to get an update out tomorrow before my driving lesson.... there goes that schedule lol i think i get what you guys are saying which is remarkable cos it's 5:20 in the morning and i'm shattered
     
  9. Offline

    chasechocolate

    Just save the X, Y, Z location of the player's home in your config and get it by using a method somewhat like this:
    Code:java
    1. public Location getHome(Player player){
    2. //Whatever your YamlConfiguration variable is
    3. String playerName = player.getName();
    4. String world = playerStat.getString("home.world");
    5. int x = playerStat.getInt("home.x");
    6. int y = playerStat.getInt("home.y");
    7. int z = playerStat.getInt.getInt("home.z");
    8. Location homeLoc = new Location(world, x, y, z);
    9. return homeLoc;
    10. }

    Setting the home location:
    Code:java
    1. public void setHome(Player player){
    2. String playerName = player.getName();
    3. String world = player.getLocation().getWorld().getName();
    4. int x = player.getLocation().getBlockX();
    5. int y = player.getLocation().getBlockY();
    6. int z = player.getLocation().getBlockZ();
    7. //Your YamlConfiguration variable
    8. playerStat.set("home." + playerName + ".world", world);
    9. playerStat.set("home." + playerName + ".x", x);
    10. playerStat.set("home." + playerName + ".y", y);
    11. playerStat.set("home." + playerName + ".z", z);
    12. }
     
  10. Offline

    jamiemac262

    SO close lol.... "the constructor Location(String, int, int, int) is undefined"

    i copy and pasted both those methods exactly as you wrote them
     
  11. Offline

    fireblast709

    Cast the int values to double
     
  12. Offline

    jamiemac262

    the problem is the String world

    it asks me to cast String world to World but then i do that it asks me to change String world to World world..... but when i do that it tells me to change World world to String I AM SO CONFUSED! :( lol
     
  13. Offline

    fireblast709

    World w = Bukkit.getWorld(worldname); Input your String - assumed the worlds name - in that method
     
  14. Offline

    jamiemac262

    thanx soooooo much guys, i have been stuck on this for god knows how many months and in a night and an hr it's been solved :D and i believe i can use this for setting warps aswell xD (with minor changes)
     
Thread Status:
Not open for further replies.

Share This Page