What am I doing wrong? I can't bear the fact that I don't know!

Discussion in 'Plugin Development' started by liquid1an, May 10, 2014.

Thread Status:
Not open for further replies.
  1. Hey y'all.

    So here's the thing:
    My bukkit seems to be spamming with lots of errors when I try to perform a command.


    The script I made has not been finished yet, what I am trying to make is a warpingsystem. I am just a beginner and I thought I'd be nice to learn scripting by making this plugin. The plugin now only can save warps, but for some reason it won't work.

    The error occurs somewhere around line 48.
    So here's the SCRIPT:
    Code:java
    1. package io.github.liquidian.FastTravel;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class FastTravel extends JavaPlugin{
    14.  
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static FastTravel plugin;
    17. public final Location[] warpLocations = new Location[100];
    18. public final String[] warpName = new String[100];
    19.  
    20. public void loadConfig(){
    21. getConfig().options().copyDefaults(true);
    22. saveConfig();
    23. }
    24.  
    25. @Override
    26. public void onEnable() {
    27. loadConfig();
    28. PluginDescriptionFile pdfFile = this.getDescription();
    29. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled!");
    30. }
    31.  
    32. @Override
    33. public void onDisable () {
    34. PluginDescriptionFile pdfFile = this.getDescription();
    35. saveConfig();
    36. this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    37. }
    38.  
    39. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String [] args){
    40. Player player = (Player) sender;
    41. if(commandLabel.equalsIgnoreCase("fasttravellocationset") || commandLabel.equalsIgnoreCase("ftlocationset") || commandLabel.equalsIgnoreCase ("ftls"));
    42. if(args.length == 0){
    43. player.sendMessage(ChatColor.RED + "/ftls <warpname>");}
    44.  
    45. else if(args.length == 1){
    46. this.logger.info(ChatColor.GRAY + "..Loading Config");
    47. this.logger.info(ChatColor.GRAY + "..Saving Data");
    48. Location loc = player.getLocation();
    49. getConfig().set("warps." + args[2] + ".x", Double.valueOf(loc.getX()));
    50. getConfig().set("warps." + args[2] + ".y", Double.valueOf(loc.getY()));
    51. getConfig().set("warps." + args[2] + ".z", Double.valueOf(loc.getZ()));
    52. getConfig().set("warps." + args[2] + ".world", loc.getWorld().getName());
    53. getConfig().set("warps." + args[2] + ".yaw", Float.valueOf(loc.getYaw()));
    54. getConfig().set("warps." + args[2] + ".pitch", Float.valueOf(loc.getPitch()));
    55. player.sendMessage("Public Warp " + args[2] + " created.");
    56.  
    57. saveConfig();
    58. this.logger.info(ChatColor.GRAY + "..Data Succesfully Saved!");
    59. return true;}
    60.  
    61. else if(args.length > 1){
    62. player.sendMessage(ChatColor.RED + "Too many arguments! Correct use: /ftls <warpname>.");}
    63. return false;
    64. }
    65. }


    And here's the error:
    [​IMG]

    Thanks in advance!
    - Liquidian
     
  2. Offline

    Adriani6

    I would presonally change few things around.
    Youre checking the amount of args, you check if its exactly 1... which is wrong because then in config you get 3rd arg from the command...

    Do just args lenght > 1

    Also args go the following way

    arg[0] is the first one
    arg[1] is the second one

    And so on, you also need to register your commands if you havent done ao
     
  3. Adriani6 Thanks for the support. Btw, how can I register my commands?
     
  4. Offline

    NDUGAR


    I'm guessing in your plugin.yml :p
     
  5. I have solved it by doing this.
    Code:java
    1. getConfig().set("warps." + args[0] + ".x", Double.valueOf(loc.getX()));
    2. getConfig().set("warps." + args[0] + ".y", Double.valueOf(loc.getY()));
    3. getConfig().set("warps." + args[0] + ".z", Double.valueOf(loc.getZ()));
    4. getConfig().set("warps." + args[0] + ".world", loc.getWorld().getName());
    5. getConfig().set("warps." + args[0] + ".yaw", Float.valueOf(loc.getYaw()));
    6. getConfig().set("warps." + args[0] + ".pitch", Float.valueOf(loc.getPitch()));


    PS: Sorry for posting twice.

    NDUGAR Thankyou!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  6. Offline

    Adriani6

    liquid1an
    commands:
    basic:
    description: This is a demo command.
    usage: /<command> [player]
    permission: <plugin name>.basic
    permission-message: You don't have <permission>

    Sorry for not tags around the code as im on my phone. Also change basic with one of your commands.

    Also I seen you check commandlabel I would use cmd.getName().equalsIgnoreString("ftls")

    And change basic in plugin.yml to ftls

    Or register all 3 commands you check I guess

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  7. @Adriani Thanks, it all worked. I actually already had that plugin.yml thing done, you really really helped me by eplaining the args[0] thing.
     
Thread Status:
Not open for further replies.

Share This Page