Command repeats itself

Discussion in 'Plugin Development' started by militiaspack, Dec 15, 2013.

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

    militiaspack

    So i have this code that makes rods and lightningrod works but the waterrod command just repeats itself when i do /waterrod Help anyone?

    package io.github.militiaspack.lightningrod;




    import java.util.HashMap;





    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;


    public final class Main extends JavaPlugin implements Listener {

    private HashMap<Integer, ItemStack> addItem;



    @Override
    public void onEnable(){
    Bukkit.getPluginManager().registerEvents(this, this);
    getLogger().info("LightningRod has been enabled");
    getLogger().info("Created by Militiaspack!");

    }


    public void onDisable() {
    getLogger().info("LightningRod has been disabled");

    }

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    if(cmd.getName().equalsIgnoreCase("lightningrod")){
    Player player = (Player) sender;
    ItemStack is = new ItemStack(Material.STICK, 1);
    ItemMeta im = is.getItemMeta();
    im.setDisplayName(ChatColor.DARK_BLUE + "Lightning Rod");
    is.setItemMeta(im);
    player.getInventory().addItem(is);



    }
    return false;
    }
    {
    }

    @SuppressWarnings("deprecation")
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    World w = p.getWorld();
    if (p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.DARK_BLUE + "Lightning Rod")){
    if(e.getAction() == Action.RIGHT_CLICK_BLOCK) return;
    Block b = p.getTargetBlock(null, 100);
    Location l = b.getLocation();
    w.strikeLightning(l);
    w.createExplosion(l, 2);
    } else {
    return;
    }
    }

    public boolean onCommand1(CommandSender sender, Command cmd, String label, String[] args){
    if(cmd.getName().equalsIgnoreCase("WaterRod")){
    Player player = (Player) sender;
    ItemStack is = new ItemStack(Material.STICK, 1);
    ItemMeta im = is.getItemMeta();
    im.setDisplayName(ChatColor.BLUE + "Water Rod");
    is.setItemMeta(im);
    player.getInventory().addItem(is);
    {

    }
    }
    return false;
    }












    @SuppressWarnings("deprecation")
    @EventHandler
    public void onPlayerInteract1(PlayerInteractEvent e1) {
    Player p = e1.getPlayer();
    World w = p.getWorld();
    if (p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.BLUE + "Water Rod")){
    if(e1.getAction() == Action.RIGHT_CLICK_BLOCK) return;
    Block b = p.getTargetBlock(null, 100);
    Location l = b.getLocation();
    b.setType(Material.WATER);
    } else {
    return;


    }
    }
    }
     
  2. Offline

    Ventality

  3. Offline

    Pluto_

    Like Ven stated, Plugin Development is where it goes but you don't need 2 onCommands, you only need one.
     
  4. Offline

    militiaspack

    My bad thought this was development
     
  5. Offline

    Ventality

    militiaspack Try requesting post to be moved to correct section.
     
  6. Offline

    timtower Administrator Administrator Moderator

    militiaspack Requested move, and you have 2 command functions, I think that that is your issue here
     
  7. Offline

    Necrodoom

    Moved to correct section.
     
  8. Offline

    sgavster

    You need return true;.
     
  9. Offline

    mattrick

    militiaspack
    Also, post code in code tags. (The button on top with two brackets and a number sign(or as some call it a hashtag ._. ))
     
Thread Status:
Not open for further replies.

Share This Page