Private warping?

Discussion in 'Plugin Development' started by lcpvp, Mar 22, 2013.

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

    lcpvp

    I need some hints on how to do private warps. So a player could set a private warp, only available to them.
     
  2. Offline

    crushh87

    Get the players location
    Save it in the config under their name
    Like
    Code:
    crushh87:
      warp1:
        - x:
        - y:
        - z:
    etc....
    then when they type
    /privatewarp warp1

    Double x = getConfig().get(player.getName() + "." + args[0] + ".x")

    then teleport them

    Let me know if you need any more help and I'll right out the entire code
     
  3. Offline

    microgeek

    This. It's honestly not all that hard.
     
  4. Offline

    lcpvp

    Could you show me more? I dont reallly know how to do this completely. How do I store players in a config?
     
  5. Offline

    microgeek

    Learn Java, that's a start.
     
    devilquak and Phinary like this.
  6. Offline

    chasechocolate

  7. Offline

    crushh87

    Here ya go, tested it and it works like a charm

    Code:
     if(commandLabel.equalsIgnoreCase("setprivatewarp")){
                  if(args.length == 1){
                  Location warp = player.getLocation();
                  getConfig().set(player.getName() + "." +  args[0] + ".X", warp.getX());
                  getConfig().set(player.getName() + "." +  args[0] + ".Y", warp.getY());
                  getConfig().set(player.getName() + "." +  args[0] + ".Z", warp.getZ());
                  getConfig().set(player.getName() + "." +  args[0] + ".World", warp.getWorld().getName());
                  getConfig().set(player.getName() + "." +  args[0] + ".Pitch", warp.getPitch());
                  getConfig().set(player.getName() + "." +  args[0] + ".Yaw", warp.getYaw());
                  player.sendMessage("Warp " + args[0] + " has been set!");
              }
             
             
              }else if(commandLabel.equalsIgnoreCase("pwarp")){
                  if(args.length == 1){
                      if(!getConfig().contains(player.getName() + "." +  args[0])){
                          player.sendMessage("No warp named " + args[0] + " is set");
                      }
                        World w = player.getServer().getWorld(getConfig().getString(player.getName() + "." +  args[0] + ".World"));
                        Double x = getConfig().getDouble(player.getName() + "." +  args[0] + ".X");
                        Double y = getConfig().getDouble(player.getName() + "." +  args[0] + ".Y");
                        Double z = getConfig().getDouble(player.getName() + "." +  args[0] + ".Z");
                        float Yaw = getConfig().getInt(player.getName() + "." +  args[0] + ".Yaw");
                        float Pitch = getConfig().getInt(player.getName() + "." +  args[0] + ".Pitch");
                        Location PersonalWarp = new Location(w, x, y, z, Yaw, Pitch);
                        player.teleport(PersonalWarp);
                  }
              }
    lcpvp

    It basically works like this:
    Get there Location
    Set it to the config under there name
    (getConfig().set(player.getName() + "." + args[0] + ".X", warp.getX());

    Player types /pwarp blah
    Get the values form the config and set them to variables
    Double x = getConfig().getDouble(player.getName() + "." + args[0] + ".X");
    Then create a new Location, with the variables as the values.
    Location PersonalWarp = new Location(w, x, y, z, Yaw, Pitch);
    The Teleport them!
     
  8. Offline

    lcpvp

    Any idea how to delete them?
     
  9. Offline

    crushh87

    Code:
              }else if(commandLabel.equalsIgnoreCase("delpwarp")){
                  if(args.length == 1){
                      if(!getConfig().contains(player.getName() + "." +  args[0])){
                        getConfig().set(player.getName() + "." + args[0], args[0] == null);
                      }
                  }
              }
    That should work. I never tested, but I think it will work

    lcpvp
     
  10. Offline

    ZeusAllMighty11

    Even easier would be to learn regex and what Java's 'split()' method does on Strings. Easy way to store locations
     
    devilquak likes this.
  11. Offline

    lcpvp

    Thanks for your help! Kust one last thing, how could I make it so if player has perm warp.fve they can only set 5 warps max?

    Thanks for the tip, I have just been really busy lately and cant code much by myself :-/ I will lookinto this if i find some time

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

    crushh87

    Code:
                      int warpAmount = getConfig().getInt(player.getName() + ".Number-Of-Warps");
                      if(player.hasPermission("private.warps.5")){
                          if(warpAmount == 5){
                              player.sendMessage("You have reached your warp maxium!");
                              return false;
                          }
                      }
                  Location warp = player.getLocation();
                  getConfig().set(player.getName() + "." +  args[0] + ".X", warp.getX());
                  getConfig().set(player.getName() + "." +  args[0] + ".Y", warp.getY());
                  getConfig().set(player.getName() + "." +  args[0] + ".Z", warp.getZ());
                  getConfig().set(player.getName() + "." +  args[0] + ".World", warp.getWorld().getName());
                  getConfig().set(player.getName() + "." +  args[0] + ".Pitch", warp.getPitch());
                  getConfig().set(player.getName() + "." +  args[0] + ".Yaw", warp.getYaw());
                  getConfig().set(player.getName() + ".Number-Of-Warps", warpAmount);
                  player.sendMessage("Warp " + args[0] + " has been set!");
                      warpAmount++;
                   
                      
    Did not test, may not work but I think it will.

    This is not the most efficient way to do this but, I could not think of a better way


    EDIT:
    This may throw a NullPointer on the first warp set
    Just check if the Number-Of-Warps is there in and then if it's not create it at the beginning
     
  13. Offline

    lcpvp

    Thanks, surry to bug but how wud I do /go list to see current warps?
     
  14. Offline

    Compressions

    lcpvp Get someone to make all of it for you if you can't do it yourself! :)
     
  15. Offline

    microgeek

    [​IMG]
     
    Phinary likes this.
  16. Offline

    lcpvp

    I get a syntax error when I try to.

    This is my code.
    I get a
    Code:terminal
    1.  
    2. Caused by: java.lang.IllegalArgumentException: Name cannot be null
    3. at org.apache.commons.lang.Validate.notNull(Validate.java:203)
    4. at org.bukkit.craftbukkit.v1_5_R1.CraftServer.getWorld(CraftServer.java:818)
    5.  

    I do /setwarp and it says Warp test has been set, but then nothing happens when I do /go test.

    here is my code. What do I need to add?
    Code:java
    1.  
    2. if(commandLabel.equalsIgnoreCase("setwarp")){
    3. if(args.length == 1){
    4. Location warp = player.getLocation();
    5. getConfig().set(player.getName() + "." + args[0] + ".X", warp.getX());
    6. getConfig().set(player.getName() + "." + args[0] + ".Y", warp.getY());
    7. getConfig().set(player.getName() + "." + args[0] + ".Z", warp.getZ());
    8. getConfig().set(player.getName() + "." + args[0] + ".World", warp.getWorld().getName());
    9. getConfig().set(player.getName() + "." + args[0] + ".Pitch", warp.getPitch());
    10. getConfig().set(player.getName() + "." + args[0] + ".Yaw", warp.getYaw());
    11. player.sendMessage("Warp " + args[0] + " has been set!");
    12. }
    13. }else if(commandLabel.equalsIgnoreCase("go")){
    14. if(args.length == 1){
    15. if(!getConfig().contains(player.getName() + "." + args[0])){
    16. player.sendMessage(ChatColor.GREEN + "No warp named " + args[0] + " is set");
    17. }
    18. World w = player.getServer().getWorld(getConfig().getString(player.getName() + "." + args[0] + ".World"));
    19. Double x = getConfig().getDouble(player.getName() + "." + args[0] + ".X");
    20. Double y = getConfig().getDouble(player.getName() + "." + args[0] + ".Y");
    21. Double z = getConfig().getDouble(player.getName() + "." + args[0] + ".Z");
    22. float Yaw = getConfig().getInt(player.getName() + "." + args[0] + ".Yaw");
    23. float Pitch = getConfig().getInt(player.getName() + "." + args[0] + ".Pitch");
    24. Location PersonalWarp = new Location(w, x, y, z, Yaw, Pitch);
    25. player.teleport(PersonalWarp);
    26. }
    27. }else if(commandLabel.equalsIgnoreCase("delwarp")){
    28. if(args.length == 1){
    29. if(!getConfig().contains(player.getName() + "." + args[0])){
    30. getConfig().set(player.getName() + "." + args[0], args[0] == null);
    31. }
    32. }
    33. }
    34.  


    Nevermind I fixed that part, but how do I list the waeps a plauer has on command, add a 10 second teleport delay if other players are near, cancel the teleport if the player moves in the 10 seconds and also limit how many warps a player can set using permissions?

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

    lcpvp

    Not sure how to list. Bump!
     
  18. Offline

    skipperguy12

    lcpvp
    List<String> list = (List<String>) this.getConfig().getList("SomeList");

    list.add("hai");
    list.remove("bai");

    this.getConfig().set("SomeList", list);
    this.saveConfig();
     
  19. Offline

    lcpvp

    Not getting how to use that to list warps set. Also, cant seem to limit warps set able per permission
     
  20. Offline

    skipperguy12

    lcpvp
    "list.add("hai");"

    that adds stuff to the list, then when you re set it using .set, it's added to the list.

    To set a limit, do something like: Warps.Player.1.location.

    ALSO: If your using my API, AnvilAPI (if it's approved :l), there's a built in config parser, PlayerWarpEvent custom event for my warping plugin, methods to handle warps, and stuff like that :p

    Edit: By config parser, I mean there's a way to save a location to a string, in one line of config, instead of separate lines for x y and z.
     
  21. Offline

    lcpvp

    I dont know how to limit the warps, I know how to do the permission for it though...can you show me?

    BUmp?

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

    _Filip

  23. Offline

    lcpvp

    Could you please help me out? I know I need to learn java more, but I am trying to get this plugin done and could use some help. I need to list warps, delete warps and also limit the amount of warps one can set via permission. I don't know what to do for them, which is why I am asking here.
     
  24. Offline

    RingOfStorms

    You obviously have very little java background, you shouldn't be trying to learn with a Bukkit api or anything like that. You need to do some tutorials and actually learn how to code, then come back.
     
  25. Offline

    ZeusAllMighty11

    I am in the process of recreating an essentials plugin for my own server. It has a warp system, but at the moment it's not on github. If you'd like to see the source, http://github.com/YourAverageCamper/ZomboidEssentials

    Otherwise, I am not going to help you anymore because you don't seem to know enough Java to figure this out. Like I said above, string splitting is much easier and managable. (Example in my onEnable() and in the SpawnCommand.class
     
  26. Offline

    lcpvp

    Thanks for the help!
    I know, I am in the process of learning java as well(not bukkit api) but I need this done for my server, so that is why I was asking for help. I still need help, if anyone else can.
     
  27. Offline

    RingOfStorms

    You should go to the plugin requests forum and ask for it to be made, and im also guessing that what you want is the same thing as the hundreds of home/warp plugins that offer private based warping.
     
  28. Offline

    lcpvp

    None of them do what I want, I have searched.

    http://dev.bukkit.org/server-mods/kjustgo does, but it is no longer supported and is almost completely broken. None of the commands work.
     
  29. Offline

    RingOfStorms

    After my first google search of "Bukkit private warps" The second link brought me here:
    http://dev.bukkit.org/server-mods/mywarp/

    And to boot, the very first feature listing is: Create private and public warps,

    There you go :)
     
  30. Offline

    lcpvp

    I know about this plugin, but I don't want those commands.
     
Thread Status:
Not open for further replies.

Share This Page