Need Help

Discussion in 'Plugin Development' started by aidenkrz, Aug 19, 2013.

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

    aidenkrz

    i need help makeing a config.yml i want it so you can change the x y z here is the code i want you to be able to change
    Code:
    {
            case 0: loc = new Location(target.getWorld(), 100, 60, 100);
            break;
            case 2: loc = new Location(target.getWorld(), 160, 60, 160);
            break;
            case 1: loc = new Location(target.getWorld(), 120, 60, 120);
            break;
            }
        
    How would i be able to do this or add more to
     
  2. Offline

    Lactem

    Setting in the config: getConfig().set(path, object);
     
  3. Offline

    aidenkrz

  4. Offline

    lycano

    seems this message has triggered a critical error ...
     
  5. Offline

    fireblast709

    aidenkrz What Lactem was telling you about is the method to set things in config.yml. The only thing is that Location objects are not configuration serializable.

    Thus you either need to create a String from the location and save that (which you later retrieve, and parse back into a Location object), or you save the worldname and location.toVector() (as org.bukkit.util.Vector is configuration serializable).

    In that case you retrieve your Vector object by using getConfig().getVector("some.path"), and get the world name with getConfig().getString("some.path", ""), and call Bukkit.getWorld(thatWorldName) to load the World.

    Finally you would need to call vectorObject.toLocation(justLoadedWorldObject).

    While I think the second one is a bit cleaner (less error catching and such), I would recommend the first one for new programmers.
    Code:java
    1. public String locToStr(Location loc)
    2. {
    3. StringBuilder sb = new StringBuilder(loc.getWorld().getName());
    4. sb.append(",").append(loc.getX());
    5. sb.append(",").append(loc.getY());
    6. sb.append(",").append(loc.getZ);
    7. return sb.toString();
    8. }
    Returning this into a Location object would be getting that String from the config, splitting around the ',', using Bukkit.getWorld(name) to get the World object, and parsing the rest to doubles for x, y and z.
     
  6. Offline

    aidenkrz

    How Would i add this into my config.yml
    Code:java
    1. // Notify
    2. target.sendMessage(ChatColor.BLUE + "You Have Been Teleported To A Random Spot!");
    3. return true;
    4.  


    Bump.

    Can Some One Plzz Help

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page