OnRight event need help!

Discussion in 'Plugin Development' started by CheifKeef, Jul 31, 2015.

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

    CheifKeef

    Im trying to make a plugin when you type /wifebeater it gives you a sword, and that works fine but i want it so when you right click a block or a person or air you get a potion effect, now thats not working,, Please don't leave a comment like "First learn java" Ok i didn't come here for that i just came here for a nudge not a solution, i need a little help heres my code
    I highlighted the part red cause thats where it starts!

    Code:
    package me.PokeMasterBrobee.MagicStick;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    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.Plugin;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class MagicStick extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Plugin plugin;
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + pdfFile.getVersion() + " has been disabled!");
        }
       
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + pdfFile.getVersion() + " has been enabled!");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
                if(cmd.getName().equalsIgnoreCase("ms")) {
                ItemStack magicstick = new ItemStack(Material.STICK);
                ItemMeta item = magicstick.getItemMeta();
                List<String> magicstickl = new ArrayList<String>();
                magicstickl.add(ChatColor.RED + "Use to fight off dangerous criters!");
                item.setLore(magicstickl);
                item.setDisplayName(ChatColor.GREEN + "MagicStick");
                magicstick.setItemMeta(item);
                magicstick.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 4);
                magicstick.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 4);
                player.setItemInHand(magicstick);   
                return true;
                }
               
                else if(cmd.getName().equalsIgnoreCase("im")){
                    ItemStack ironman = new ItemStack(Material.IRON_INGOT);
                    ItemMeta ironitem = ironman.getItemMeta();
                    List<String> ironiteml = new ArrayList<String>();
                    ironiteml.add(ChatColor.RED + "Use to activate potions" + ChatColor.GRAY + "(Right click)");
                    ironitem.setLore(ironiteml);
                    ironitem.setDisplayName(ChatColor.AQUA + "Ironman");
                    ironman.setItemMeta(ironitem);
                    ironman.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 4);
                    player.setItemInHand(ironman);
                }
               
    [COLOR=#ff4d4d]            else if(cmd.getName().equalsIgnoreCase("wifebeater")){
                    ItemStack wifebeater = new ItemStack(Material.DIAMOND_SWORD);
                    ItemMeta wifeitem = wifebeater.getItemMeta();
                    List<String> wifeiteml = new ArrayList<String>();
                    wifeiteml.add(ChatColor.GRAY + "Launcher I");
                    wifeitem.setLore(wifeiteml);
                    wifeitem.setDisplayName(ChatColor.AQUA + "WifeBeater");
                    wifebeater.setItemMeta(wifeitem);
                    wifebeater.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10);
                    wifebeater.addUnsafeEnchantment(Enchantment.DAMAGE_UNDEAD, 10);
                    wifebeater.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 5);
                    wifebeater.addUnsafeEnchantment(Enchantment.DAMAGE_ARTHROPODS, 5);
                    player.setItemInHand(wifebeater);
                }
                
            
            return false;
        }
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event){
            if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) {
                Player player = event.getPlayer();
                ItemStack wifebeater = new ItemStack(Material.DIAMOND_SWORD);
                ItemMeta wifeitem = wifebeater.getItemMeta();
                List<String> wifeiteml = new ArrayList<String>();
                wifeiteml.add(ChatColor.GRAY + "Launcher I");
                wifeitem.setLore(wifeiteml);
                wifeitem.setDisplayName(ChatColor.AQUA + "WifeBeater");
                wifebeater.setItemMeta(wifeitem);
                wifebeater.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10);
                wifebeater.addUnsafeEnchantment(Enchantment.DAMAGE_UNDEAD, 10);
                wifebeater.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 5);
                wifebeater.addUnsafeEnchantment(Enchantment.DAMAGE_ARTHROPODS, 5);
                if(player.getItemInHand() == wifebeater);
                player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2000, 3));
            }
        }[/COLOR]
    }
     
  2. Offline

    teej107

  3. Offline

    stormneo7

  4. Offline

    NickDEV

    When you will fix your code there could be another problem and that is spawn-protection. Every server has spawn protection in server-properties.yml and it could block right click on spawn protected area. (If you want to disable it just set spawn-protection to 0)
     
Thread Status:
Not open for further replies.

Share This Page