Help with Undefined Config and Spaced commands! PLEASE Help!

Discussion in 'Plugin Development' started by TECGaming360, Apr 26, 2014.

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

    TECGaming360

    My first bit of coding is for a person to set the Meterial/Item but i get a error saying that is a undefined "The method getConfig() is undefined for the type PlayerListener"
    Code:java
    1. @EventHandler
    2. public void onDropItem(PlayerDropItemEvent e) {
    3. Player player = e.getPlayer();
    4. if (e.getItemDrop().getItemStack().getType() == getConfig().getString("Acquired item")) {
    5. e.setCancelled(true);
    6. player.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + "You can not Drop this Item!");
    7. }
    8. }
    9. }


    This next bit im trying to set the Command to allow a person to Set a Config while in game, but i just get a error every time i start game, it is grabbing the config because /ktiacquire works but a error after i get a item shows up in chat, but can some one explain the spacing of the commands i don't really get it also the config.yml. Heres the coding for my giving item
    Code:java
    1. Player player = (Player) sender;
    2.  
    3. String KtIAcquire = "give " + player.getName() + " " + getConfig().getString("Acquired item") + " " + "1";
    4. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), KtIAcquire);
    5. System.out.println(ChatColor.AQUA + "Player has requested a Item that player is " + player.getName());
    6. player.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + "You have acquired the item that you have requested!");
    7. }
    8. if (cmd.getName().equalsIgnoreCase("Setup")){
    9. if (args.length == 0)
    10. sender.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + "Sorry, Incorrect Argument common argument /setup Acquired Item <input itemid>");
    11. } else {
    12. //Else statement. If the args are not 0...do stuff below
    13. if (args[0].equalsIgnoreCase("Acquired"))
    14. if (args.length == 1){
    15. sender.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + "Sorry, Incorrect Argument common argument /setup Acquired Item <input itemid>");
    16. } else {
    17. //Else statement. If the args are not 0...do stuff below
    18. if (args[1].equalsIgnoreCase("Item")) {
    19.  
    20. }
    21. if (args.length == 0) {
    22. sender.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + "You have to specify a item ID!");
    23. }
    24. StringBuilder str = new StringBuilder();
    25. for (int i = 0; i < args.length; i++){
    26. str.append(args[i] + " ");
    27. }
    28. String KtIAcquire = str.toString();
    29. getConfig().set("Acquired item" , KtIAcquire);
    30. saveConfig();
    31. sender.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + "You have set the acquired item!");
    32. }
    33. }[/i]
     
  2. Your getConfig() method can be located in the class which extends JavaPlugin.
    Could you post the error which happens which is related to the command?
     
  3. Offline

    killerman747

    If this isnt the main class, add this to the top of the class:
    Code:java
    1. public static YourPluginName plugin;
    2.  
    3. public YourClassName(YourPluginName instance){
    4. plugin = instance;
    5. }

    Then when you need to get something from the config in that class use:
    Code:
    plugin.getConfig().getString("String Required");
    Again thats if this isnt your main class.
     
Thread Status:
Not open for further replies.

Share This Page