Solved Having problems Setting Config Material, HELP!!!!!

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

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

    TECGaming360

    I'm trying to give people the option to set the config for a stuck hotbar item and a Non-dropable item why does it say "The method getConfig() is undefined for the type Material" for both Handlers?
    Code:java
    1. @EventHandler
    2. public void onDropItem(PlayerDropItemEvent e) {
    3. Player player = e.getPlayer();
    4. String Undropableitem = (e.getItemDrop().getItemStack().getType() == Material.getConfig().getString("Undropable 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. @EventHandler
    9. public void PlayerInvClick(InventoryClickEvent e){
    10. Player player = (Player) e.getWhoClicked() == Material.getConfig().getString("Set Stuck Item");
    11. if(e.getInventory().equals(player.getInventory())) {
    12. e.setCancelled(true);
    13. }
    14. }
     
  2. TECGaming360 I'd imagine because Material doesn't have a getConfig() method. I'm not sure how to explain the basics of Java really, sorry.
     
  3. Offline

    Heirteir

    TECGaming360
    Your doing Material.getConfig() Your not able to do that try doing getConfig() that should work I don't understand why you were using Material.getConfig()
     
  4. Offline

    TECGaming360

    I thought so to but how would it know what I'm trying to define could I just do getConfig ??? I just don't think it would work cause Material grabs the name of item.
     
  5. Heirteir I think he's trying to get the Material.WHATEVER where whatever is a string specified in the config, but that's not how to do it. I think the logic he's using goes:

    Material.WORKBENCH = Crafting table
    getConfig().getString("whatever") = WORKBENCH
    Therefore, Material.getConfig().getString("whatever") must equal Material.WORKBENCH

    Am I right, TECGaming360?
     
  6. Offline

    Heirteir

    TECGaming360
    Material does not grap the name of the item... e.getItemDrop().getItemStack().getItemMeta().getDisplayName() Would give you the name of the item.
    EDIT:
    Basically: ItemStack.getItemMeta().getDisplayName(); will get a set display name for an item but it will return null if it's a default name.
     
  7. Offline

    TECGaming360

    Yes that's right but I'm new to this and I'm looking for help not to be criticized on trying!
     
  8. Offline

    Heirteir

    TECGaming360
    Well AdamQpzm can do that sometimes but he means the best to help you. What exactly don't you know so I can tailor my search results to your criteria and get you a nice set of tutorials so you can learn how to do all of this.
     
    AdamQpzm likes this.
  9. Offline

    BillyGalbreath

    Material.getMaterial(getConfig().getString("Undropable item"));

    Is how you would get a material by it's name stored in a config. ;)
     
  10. Offline

    Heirteir

    TECGaming360
    I would recommend http://www.youtube.com/thepogostick29dev he should be able to help you out with your problems he has over 50 tutorials on bukkit plugins from beginner to advanced. You should check him out! Hopefully this helped you out with your problems.
     
  11. TECGaming360 Sorry, didn't really mean to sound so harsh. Heirteir has it right when I want to help. But I prefer to know exactly what the problem is first before that happens - me explaining something you already know or explaining the wrong thing because I assumed something else isn't good for either of us. :)
     
    Heirteir likes this.
  12. Offline

    TECGaming360

    I'm sorry to Adam it's just I didn't see it as helping because there was no solution but I see why you asked so you can find a solution for me. But I'm new to this and I was just giving it a shot! Sorry again.
     
  13. TECGaming360 No problem at all :) Just follow Billy's suggestion and you should be fine. :)
     
  14. Offline

    TECGaming360

    I enter the Code in but still receiving errors "The method getConfig() is undefined for the type PlayerListener"

    Sorry, its just Billy is offline :)
    Code:java
    1. @EventHandler
    2. public void onDropItem(PlayerDropItemEvent e) {
    3. Player player = e.getPlayer();
    4. String Undropableitem = (e.getItemDrop().getItemStack().getType() == Material.getMaterial(getConfig().getString("Undropable item")) {
    5. e.setCancelled(true);
    6. player.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + "You can not Drop this Item!");
    7. } }


    @BillyGalbreath Read above /\

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

    BillyGalbreath

    getConfig() is from JavaPlugin. You need a reference to your plugin's instance to use it.
     
  16. Offline

    TECGaming360

    Ok i will tell you if that works cause i have 2 files 1 main and 1 called Player Listners
    Could i do this so a person can set item id?
    Code:java
    1. if (e.getItemDrop().getItemStack().getType() == Material.getMaterial(getConfig().getInt("undroppableItem"))) {


    I dont think this is right but i tried it probably looks stupid but i gave it a shot!
    but you need to go in depth but in my main file i put this under public void onEnable
    Code:java
    1. new PlayerListener(this);{
    2. getConfig().options().copyDefaults(true);
    3. saveConfig();
    4. }


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

Share This Page