Setting a warp.

Discussion in 'Plugin Development' started by HyrulesLegend, Oct 29, 2012.

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

    HyrulesLegend

    ATM, my config.yml is blank. What should I add to my source, and my config.yml?
    (I'm only adding that one warp, not multiple.)
     
  2. Offline

    fireblast709

    are you going to make a static point (static as in not going to be moved) or are you going to set it command wise?
    [addition] Typing ahead of your answer. If you say "static set in my config" then add a default. If you are going to do it command-wise just set the normal stuff like
    Code:
    main:
      lobby:
        x:
        y:
        z:
        world:
    And set them using the code already posted in the thread
     
  3. Offline

    Woobie

    Oh, well that makes things so much easier!
    I was starting to write a warp plugin, becouse I thought that you wanted more than 1 warp :p
     
  4. Offline

    HyrulesLegend

    I only want 1, the command being /setcasual to change where it warps, and /casual to go to the warp
     
  5. Offline

    Woobie

    Oh, well if you havent gotten it working until tomorrow, I'll give you the code, I'm not on my computer anymore,
     
  6. Offline

    callum.thepro

    You need to reference your class with "extends JavaPlugin" in it, so it would be plugin.getConfig() not getConfig

    Also i would reccomend using int's not doubles for example change

    Code:
     Player player = (Player) sender;
            Location loc = player.getLocation();
            config.set("your.path", loc.getX());
            config.set("your.path", loc.getY());
            config.set("your.path", loc.getZ());

    to
    Code:
     Player player = (Player) sender;
     
            Location loc = player.getLocation()
            config.set("your.path", (int) loc.getX());
            config.set("your.path", (int) loc.getY());
            config.set("your.path", (int) loc.getZ());
     
  7. Offline

    fireblast709

    Code:java
    1. package me.kyrp.KitPvP;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.World;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandExecutor;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11.  
    12. public class KitPvPCasual implements CommandExecutor
    13. {
    14. private KitPvP plugin;
    15.  
    16. public KitPvPCasual(KitPvP plugin)
    17. {
    18. this.plugin = plugin;
    19. }
    20.  
    21. // Its not onCommand1 but just onCommand
    22. @Override
    23. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    24. {
    25. // You had ; after your if statement, which makes is ALWAYS execute the code
    26. if(commandLabel.equalsIgnoreCase("setcasual"))
    27. {
    28. Player player = (Player) sender;
    29. Location loc = player.getLocation();
    30. // You might want to set the world
    31. plugin.getConfig().set("your.path.world", player.getWorld().getName());
    32. plugin.getConfig().set("your.path.x", loc.getX());
    33. plugin.getConfig().set("your.path.y", loc.getY());
    34. plugin.getConfig().set("your.path.z", loc.getZ());
    35. // Then also save the config
    36. plugin.saveConfig();
    37. player.sendMessage(ChatColor.GREEN + "Casual warp set");
    38. return true;
    39. }
    40. // You had ; after your if statement, which makes is ALWAYS execute the code
    41. if(commandLabel.equalsIgnoreCase("casual"))
    42. {
    43. Bukkit.broadcastMessage(ChatColor.GOLD + "[SonicKitPvP] " + sender.getName() + "is at casual, Do /casual to 1v1 him!");
    44. World w = player.getServer().getWorld(config.getString("your.path.world", ""));
    45. Double x = config.getInt("main.lobby.location.x");
    46. Double y = config.getInt("main.lobby.location.y");
    47. Double z = config.getInt("main.lobby.location.z");
    48. if(w == null || x == null || y == null || z == null)
    49. {
    50. player.sendMessage("Warp does not exist");
    51. return true;
    52. }
    53. Location lobbyspawn = new Location(w, x, y, z);
    54. player.teleport(lobbyspawn);
    55. return true;
    56. }
    57. // Missing some return statements
    58. return false;
    59. }
    60. }

    read the comments in the code. This part is fixed
     
  8. Offline

    HyrulesLegend

    Still some errors about config

    World w = player.getServer().getWorld(config.getString("your.path.world", ""));
    Double x = config.getInt("main.lobby.location.x");
    Double y = config.getInt("main.lobby.location.y");
    Double z = config.getInt("main.lobby.location.z");

    in those lines
     
  9. Offline

    the_merciless

    Code:
        if(commandLabel.equalsIgnoreCase("casual")){
       
            Bukkit.broadcastMessage(ChatColor.GOLD + "[SonicKitPvP] " + sender.getName() + "is at casual, Do /casual to 1v1 him!");
       
            World w = player.getServer().getWorld(getConfig().getString("your.path.world", ""));
            String x = plugin.getConfig().getString("main.lobby.location.x");
            String y = plugin.getConfig().getString("main.lobby.location.y");
            String z = plugin.getConfig().getString("main.lobby.location.z");
            double xd = Double.parseDouble(x);
            double yd = Double.parseDouble(y);
            double zd = Double.parseDouble(z);   
            Location lobbyspawn = new Location(w, xd, yd, zd);
            player.teleport(lobbyspawn);
            return true;
        }
     
  10. Offline

    Squirtle771

    You could also, in theory, declare a variable called config with the code
    Code:Java
    1.  
    2. FileConfiguration config = plugin.getConfig();
    3.  

    making the code in question look like this
    Code:Java
    1.  
    2. public class KitPvpCasual extends JavaPlugin{
    3. FileConfiguration config = this.getConfig();
    4. public KitPvpCasual(KitPvP plugin){
    5. //Skip to config part
    6. Player player = (Player)sender
    7. Location loc = player.getLocation();
    8. config.set("your.plugin.path", loc.getX());
    9. config.set("your.plugin.path", loc.getY());
    10. config.set("your.plugin.path", loc.getZ());
    11. }
     
  11. Offline

    HyrulesLegend

    I really need this, so many different codes, don't know which one to use, if someone could just fix this code up for me:

    Code:
    package me.kyrp.KitPvP;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class KitPvPCasual extends JavaPlugin{
    FileConfiguration config = this.getConfig();
    public KitPvPCasual(KitPvP plugin){
        }
     
        // Its not onCommand1 but just onCommand
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            // You had ; after your if statement, which makes is ALWAYS execute the code
            if(commandLabel.equalsIgnoreCase("setcasual"))
            {
                Player player = (Player) sender;
                Location loc = player.getLocation();
                // You might want to set the world
                plugin.getConfig().set("your.path.world", player.getWorld().getName());
                plugin.getConfig().set("your.path.x", loc.getX());
                plugin.getConfig().set("your.path.y", loc.getY());
                plugin.getConfig().set("your.path.z", loc.getZ());
                // Then also save the config
                plugin.saveConfig();
                player.sendMessage(ChatColor.GREEN + "Casual warp set");
                return true;
            }
            // You had ; after your if statement, which makes is ALWAYS execute the code
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("casual")){
                 
                Bukkit.broadcastMessage(ChatColor.GOLD + "[SonicKitPvP] " + sender.getName() + "is at casual, Do /casual to 1v1 them!");
         
                World w = player.getServer().getWorld(getConfig().getString("your.path.world", ""));
                String x = plugin.getConfig().getString("main.lobby.location.x");
                String y = plugin.getConfig().getString("main.lobby.location.y");
                String z = plugin.getConfig().getString("main.lobby.location.z");
                double xd = Double.parseDouble(x);
                double yd = Double.parseDouble(y);
                double zd = Double.parseDouble(z); 
                Location lobbyspawn = new Location(w, xd, yd, zd);
                player.teleport(lobbyspawn);
                return true;
     
            }
            // Missing some return statements
            return false;
        }
    }
     
  12. Offline

    fireblast709

    Why are you extending JavaPlugin now? Was it not your CommandExecutor class?
    Code:java
    1. package me.kyrp.KitPvP;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.World;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandExecutor;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.configuration.file.FileConfiguration;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class KitPvPCasual extends CommandExecutor
    15. {
    16. FileConfiguration config;
    17. public KitPvPCasual(KitPvP plugin)
    18. {
    19. config = plugin.getConfig();
    20. }
    21.  
    22. // Its not onCommand1 but just onCommand
    23. @Override
    24. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    25. {
    26. if(!(sender instanceof Player))
    27. {
    28. sender.sendMessage("This is a player-only command");
    29. return true;
    30. }
    31. Player player = (Player) sender;
    32. // You had ; after your if statement, which makes is ALWAYS execute the code
    33. if(commandLabel.equalsIgnoreCase("setcasual"))
    34. {
    35. Location loc = player.getLocation();
    36. // You might want to set the world
    37. config.set("your.path.world", player.getWorld().getName());
    38. config.set("your.path.x", loc.getX());
    39. config.set("your.path.y", loc.getY());
    40. config.set("your.path.z", loc.getZ());
    41. // Then also save the config
    42. plugin.saveConfig();
    43. player.sendMessage(ChatColor.GREEN + "Casual warp set");
    44. return true;
    45. }
    46. // You had ; after your if statement, which makes is ALWAYS execute the code
    47. if(commandLabel.equalsIgnoreCase("casual")){
    48.  
    49. Bukkit.broadcastMessage(ChatColor.GOLD + "[SonicKitPvP] " + sender.getName() + "is at casual, Do /casual to 1v1 them!");
    50.  
    51. World w = player.getServer().getWorld(plugin.getConfig().getString("your.path.world", ""));
    52. String x = config.getDouble("main.lobby.location.x");
    53. String y = config.getDouble("main.lobby.location.y");
    54. String z = config.getDouble("main.lobby.location.z");
    55. Location lobbyspawn = new Location(w, x, y, z);
    56. player.teleport(lobbyspawn);
    57. return true;
    58.  
    59. }
    60. // Missing some return statements
    61. return false;
    62. }
    63. }
     
  13. Offline

    CeramicTitan

    Max_The_Link_Fan

    Please read upon on bukkit before you attempting stuff like this. You are clearly lacking knowledge so I think reading and learning java/bukkit is your best advice. It's also helpful if you wanna attempt something more in-depth and advanced.

    Code:java
    1. package me.kyrp.KitPvP;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.World;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandExecutor;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.configuration.file.FileConfiguration;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class KitPvPCasual extends CommandExecutor
    15. {
    16. FileConfiguration config;
    17. public KitPvPCasual(KitPvP plugin)
    18. {
    19. config = plugin.getConfig();
    20. }
    21.  
    22. // Its not onCommand1 but just onCommand
    23. @Override
    24. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    25. {
    26. if(!(sender instanceof Player))
    27. {
    28. sender.sendMessage("This is a player-only command");
    29. return true;
    30. }
    31. Player player = (Player) sender;
    32. // You had ; after your if statement, which makes is ALWAYS execute the code
    33. if(commandLabel.equalsIgnoreCase("setcasual"))
    34. {
    35. Location loc = player.getLocation();
    36. // You might want to set the world
    37. config.set("your.path.world", player.getWorld().getName());
    38. config.set("main.lobby.location.x", loc.getX());
    39. config.set("main.lobby.location.y", loc.getY());
    40. config.set("main.lobby.location.z", loc.getZ());
    41. // Then also save the config
    42. plugin.saveConfig();
    43. player.sendMessage(ChatColor.GREEN + "Casual warp set");
    44. return true;
    45. }
    46. // You had ; after your if statement, which makes is ALWAYS execute the code
    47. if(commandLabel.equalsIgnoreCase("casual")){
    48.  
    49. Bukkit.broadcastMessage(ChatColor.GOLD + "[SonicKitPvP] " + sender.getName() + "is at casual, Do /casual to 1v1 them!");
    50.  
    51. World w = player.getServer().getWorld(plugin.getConfig().getString("your.path.world", ""));
    52. String x = config.getDouble("main.lobby.location.x");
    53. String y = config.getDouble("main.lobby.location.y");
    54. String z = config.getDouble("main.lobby.location.z");
    55. Location lobbyspawn = new Location(w, x, y, z);
    56. player.teleport(lobbyspawn);
    57. return true;
    58.  
    59. }
    60. // Missing some return statements
    61. return false;
    62. }
    63. }

    You need path you set needs to be the same as the path you get otherwise it will return null. fireblast709 I'm sure you know this. I think it was something that you might have missed in your previous post.

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

    fireblast709

    CeramicTitan yea besides the syntax errors that are still in there xD. But they were already there in the last code the OP posted ;3
     
  15. Offline

    HyrulesLegend

    Um..
    Im a beginner, we all start somewhere, don't we..?
     
  16. Offline

    CeramicTitan

    Maybe you should start with something a bit more simple?
     
  17. Offline

    HyrulesLegend

    I have started..
    I needed help on this, thats why I came here..
     
  18. Offline

    CeramicTitan

    Maybe you should come back, when you understand a bit better.
     
  19. Offline

    HyrulesLegend

    :/...
     
  20. Offline

    crushh87

    Kinda late to the party, but this code is the greatest thing that has happened to me in like 2 weeks of trying to figure this out.
     
Thread Status:
Not open for further replies.

Share This Page