Help Configuring

Discussion in 'Plugin Development' started by XKnucklesX, Jul 15, 2013.

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

    XKnucklesX

    Hello I am a developer of a guns plugin and I need help making it so the person can choose the item used as the gun. Here is the code for the guns part: ...

    Code:java
    1. @EventHandler
    2. public void onClick1(PlayerInteractEvent e) {
    3. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK);
    4. Player p = e.getPlayer();
    5. if(p.getItemInHand().getType() == Material.STONE_HOE) {
    6. Gun1(p);


    Code:java
    1.  
    2. private void Gun1(Player p) {
    3. EnderPearl ep = p.launchProjectile(EnderPearl.class); //Config - EnderPearl Example
    4. ep.setVelocity(p.getLocation().getDirection().multiply(2.5)); //Config - 2.5 Example
    5.  



    I want in the config that it has

    Gun#1: (item)

    So basically I do not need to have the STONE_HOE there.
     
  2. Offline

    Woobie

    XKnucklesX
    Code:
    if(p.getItemInHand().getType() == Material.getByName(getConfig().getString("guns.gun1"))) {
    In your config:
    Code:
    guns:
      gun1: STONE_HOE
    
    Untested, but should work.

    By the way, you have a semicolon at the end of that one if statement. You might want to fix that.

    EDIT: If getByName() doesn't exist, try getMaterial() instead.
     
  3. Offline

    Rocoty

    Woobie
    Material.valueOf(getConfig().getString("guns.gun1"));
     
  4. Offline

    MrMag518

    Rocoty
    Material.getMaterial(getConfig().getString("guns.gun1"));
     
  5. Offline

    Rocoty

    Why correct something that already works. Actually, I don't even know why they bother creating a method that does the exact same thing as another inherited method. If anything, getMaterial(String) is slower.
     
  6. Offline

    MrMag518

    But more reliable.
    It's also the 'proper' way of getting a Material object from a string.

    http://jd.bukkit.org/rb/doxygen/d6/d0e/enumorg_1_1bukkit_1_1Material.html
    The Material.valueOf(..) method isn't even documented.
     
  7. Offline

    Rocoty

  8. Offline

    XKnucklesX

    How come in the config.yml it is

    guns:
    gun1:

    Also does the gun1 have to be out like that

    Also if i add a second gun can it just go

    Guns:
    Gun1:
    Gun2:

    This is the final outcome:

    Code:java
    1. @EventHandler
    2. public void onClick1(PlayerInteractEvent e) {
    3. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK);
    4. Player p = e.getPlayer();
    5. if(p.getItemInHand().getType() == Material.valueOf(getConfig().getString("guns.gun1"))) {
    6. Gun1(p);
    7. }
    8. }
    9.  


    And the config is:
    Code:
    Guns:
      Gun1:
      Gun2:
     
    #Gun2 is there since i have to guns
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page