Solved trouble getting a material from config.yml

Discussion in 'Plugin Development' started by coolmonkeyguy, Apr 23, 2014.

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

    coolmonkeyguy

    Im having some trouble getting a material from the config.
    Basically when the player right clicks the item defined under "Item" in the config the message should be displayed to the user defined under "Message" in the config. But its not working for me. What am I doing wrong?

    Main Class:
    Code:java
    1. public void onPlayerInteract(PlayerInteractEvent e) {
    2.  
    3. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) {
    4. Player player = e.getPlayer();{
    5.  
    6. Material m = Material.getMaterial(this.getConfig().getString("Item").toUpperCase());
    7. if (e.getPlayer().getItemInHand().getType().equals(m)){
    8.  
    9. //player.sendMessage(getConfig().getString("Message").replaceAll("&", "§"));
    10. player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Message")));
    11.  
    12.  
    13.  
    14. }
    15. }
    16. }
    17. }


    config.yml:

    Code:
    Message: 'This is a test message!'
    Item: EMERALD
    Help would be much appreciated!
     
  2. coolmonkeyguy

    Try This

    Code:java
    1. public void onPlayerInteract(PlayerInteractEvent e) {
    2. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) {
    3. Player player = e.getPlayer();{
    4.  
    5. Material m = Material.getMaterial(this.getConfig().getString("Item").toUpperCase());
    6. if (e.getPlayer().getItemInHand().getType().equals(m)){
    7.  
    8. //player.sendMessage(getConfig().getString("Message").replaceAll("&", "§"));
    9. player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Message")));
    10.  
    11.  
    12.  
    13. }
    14. }
    15. }
     
  3. Offline

    agent6262

    Try this
    Code:java
    1. public void onPlayerInteract(PlayerInteractEvent e) {
    2.  
    3. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) {
    4. Player player = e.getPlayer();
    5.  
    6. Material m = Material.getMaterial(this.getConfig().getString("Item").toUpperCase());
    7. if (e.getPlayer().getItemInHand().getType().equals(m))}
    8. //player.sendMessage(getConfig().getString("Message").replaceAll("&", "§"));
    9. player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Message")));
    10. }
    11. }
    12. }

    You had a stray open and close brace.
     
  4. Offline

    coolmonkeyguy

    It still does not seem to work. I think it has to do with recalling "Item" and getString. but im still not sure. and is my config correct for using an emerald?
     
  5. Offline

    agent6262

    This is what i used in my plugin
    Code:java
    1. ItemStack tempItem = new ItemStack(Material.getMaterial(tempConfig.getString(keys[j])), 64, 0);
     
  6. Offline

    coolmonkeyguy

    i dont know whats wrong but it just wont work.
     
  7. Offline

    killerman747

    Use item ID's instead? Not the most practical...but it works.
     
  8. Offline

    agent6262

  9. Offline

    Tehmaker

    have you tried using the valueOf method, or the matchMaterial method? Test them out.
     
  10. Offline

    coolmonkeyguy

    i figured out what was wrong. ;) i forgot to put @EventHandler
    GG
    :)
    Thanks for the help agent6262
     
Thread Status:
Not open for further replies.

Share This Page