Speed Clicking Ice

Discussion in 'Plugin Development' started by MCraftGamer35, Aug 24, 2014.

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

    MCraftGamer35

    Im coding it so if you right click ice, it gives you speed2 for 5 seconds, and takes 1 ice away. Problem is, you can right click any block, and it works. Can anyone try to fix my code?
    Here it is:
    Code:
    package me.Alex.FrostIce;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.Sound;
    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.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class Code extends JavaPlugin implements Listener {
       
        public void onEnable(){
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
            public void InventoryClick(InventoryClickEvent e){
            Player p1 = e.getPlayer();
            if(getClick().isRightClick().p1.getInventory().getItemInHand().getType() == Material.ICE);
            p1.getInventory().removeItem(new ItemStack(Material.ICE, 1));
            p1.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100 , 2));
            p1.playSound(null, Sound.GLASS, 1, 0);
            p1.sendMessage(ChatColor.AQUA + "You have used your speed item!");
      }
    }
    
     
  2. Offline

    Jalau

    MCraftGamer35
    Code:java
    1. @EventHandler
    2. public void InventoryClick(InventoryClickEvent e){
    3. Player p1 = e.getPlayer();
    4. if(getClick().isRightClick() && p1.getInventory().getItemInHand() != null && p1.getInventory().getItemInHand().getType() == Material.ICE) {
    5. p1.getInventory().removeItem(new ItemStack(Material.ICE, 1));
    6. p1.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100 , 2));
    7. p1.playSound(null, Sound.GLASS, 1, 0);
    8. p1.sendMessage(ChatColor.AQUA + "You have used your speed item!");
    9. }
    10. }
     
  3. Offline

    MCraftGamer35

  4. Offline

    AoH_Ruthless

    MCraftGamer35
    e.getClick() and (Player) e.getWhoClicked() ... don't blindly copy/paste code.
     
Thread Status:
Not open for further replies.

Share This Page