Solved Only OP has access to event handler?

Discussion in 'Plugin Help/Development/Requests' started by GoodMannersDev, May 16, 2015.

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

    GoodMannersDev

    In a plugin im making for my friends server i am using the PlayerInteractEvent, and in the console i get an error saying it can not pass the PlayerInteractEvent to *my plugin name here*. Although when i OP myself, everything works fine. Im not sure what the issue is here?

    * Don't ask why its blunts, that's just what he wanted.

    Class
    Code:
    package me.SpiffyBlunts;
    
    import java.util.ArrayList;
    
    import me.SpiffyBlunts.BluntListener;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class SpiffyBlunts extends JavaPlugin{
    
        @Override
        public void onEnable()
        {
            new BluntListener(this);
            ItemStack smallBlunt = new ItemStack(Material.REDSTONE_TORCH_ON);
            ItemMeta smallbluntIM = smallBlunt.getItemMeta();
            smallbluntIM.setDisplayName(ChatColor.RED + "Ugly ass blunt");
            ArrayList<String> bluntLore = new ArrayList<String>();
            bluntLore.add(ChatColor.GREEN + "Didn't use proper rolling papers");
            bluntLore.add(ChatColor.YELLOW + "Smoking cheap weed");
            bluntLore.add(ChatColor.RED + "Terrible high");
            bluntLore.add(ChatColor.AQUA + "Cannabis Rating: 1/10");
            smallbluntIM.setLore(bluntLore);
            smallBlunt.setItemMeta(smallbluntIM);
            ShapedRecipe bluntH = new ShapedRecipe(smallBlunt);
            bluntH.shape("*$*", "*$*", "*$*");
            bluntH.setIngredient('*', Material.PAPER);
            bluntH.setIngredient('$', Material.DEAD_BUSH);
            //Blunt added
           
            ItemStack catpiss = new ItemStack(Material.REDSTONE_TORCH_ON);
            ItemMeta catpissIM = catpiss.getItemMeta();
            catpissIM.setDisplayName(ChatColor.RED + "Blunt o' catpiss");
            ArrayList<String> catpissLore = new ArrayList<String>();
            catpissLore.add(ChatColor.GREEN + "Rolling papers were below average");
            catpissLore.add(ChatColor.YELLOW + "Weed smells foul");
            catpissLore.add(ChatColor.RED + "Unejoyable high");
            catpissLore.add(ChatColor.AQUA + "Cannabis Rating 1.5/10");
            catpissIM.setLore(catpissLore);
            catpiss.setItemMeta(catpissIM);
            ShapedRecipe catpissBlunt = new ShapedRecipe(catpiss);
            catpissBlunt.shape("&^&", "&^&", "&^&");
            catpissBlunt.setIngredient('&', Material.PAPER);
            catpissBlunt.setIngredient('^', Material.SAPLING);
            //Blunt added
           
           
           
            getServer().addRecipe(bluntH);
            getServer().addRecipe(catpissBlunt);
        }
       
        @Override
        public void onDisable()
        {
            getServer().clearRecipes();
        }
       
       
    }
    
    
    Listener Class
    Code:
    package me.SpiffyBlunts;
    
    import java.util.ArrayList;
    import java.util.Random;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class BluntListener implements Listener{
       
        private ArrayList<String> badWeed = new ArrayList<String>();
        private int jumpDur,confusionDur,blindDur,slowdigDur,hungerDur;
       
        public BluntListener(SpiffyBlunts plugin)
        {
            plugin.getServer().getPluginManager().registerEvents((Listener) this, plugin);
           
            badWeed.add("*cough* *cough* dude this is shit!");
            badWeed.add("I think i'm about to cough my lungs up! What the fuck is this !?");
            badWeed.add("Probably the most disgusting weed i've ever smoked.");
            jumpDur = 100;
            confusionDur = 225;
            blindDur = 200;
            slowdigDur = 120;
            hungerDur = 140;
        }
       
        @EventHandler
        public void playerClick(PlayerInteractEvent e)
        {
            Random gen = new Random();
            int genInt = 0;
           
            Player player = e.getPlayer();
            String name = player.getItemInHand().getItemMeta().toString();
           
            if(name.contains("Ugly ass blunt"))
            {
                if(player.hasPermission("allow.uglyBlunt"))
                {
                    genInt = gen.nextInt(2) + 1;
                    player.sendMessage(badWeed.get(genInt));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, jumpDur, 1));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, confusionDur, 5));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindDur, 5));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, slowdigDur, 10));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, hungerDur, 10));
                    player.getInventory().removeItem(player.getInventory().getItemInHand());
                }
                else
                {
                    player.sendMessage("No permission.");
                }
            }
            else if(name.contains("catpiss"))
            {
                if(player.hasPermission("allow.catpiss"))
                {
                    genInt = gen.nextInt(2) + 1;
                    player.sendMessage(badWeed.get(genInt));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, jumpDur + 30, 1));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, confusionDur + 40, 5));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindDur - 30, 5));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, slowdigDur + 40, 10));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, hungerDur + 30, 10));
                    player.getInventory().removeItem(player.getInventory().getItemInHand());
                }
                else
                {
                    player.sendMessage("No permission");
                }
            }
            else
            {
                //stub out
            }
        }
       
       
    
    }
    
    
    Error:
    http://pastebin.com/QAjNsykG
     
    Last edited: May 16, 2015
  2. Offline

    GoodMannersDev

  3. Offline

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
    @GoodMannersDev player.getItemInHand()
    That method can return null. Item doesn't always has item meta either.
     
  4. Offline

    GoodMannersDev

    So just add something that catches it, if its null?
     
  5. Offline

    timtower Administrator Administrator Moderator

  6. Offline

    GoodMannersDev

    Added it. Still doesn't work, but doesn't give errors anymore. Ops only for some reason.
     
  7. Offline

    timtower Administrator Administrator Moderator

    @GoodMannersDev Then the rest just doesn't has the required permissions.
     
  8. Offline

    GoodMannersDev

    Scratch that, still getting the error. I used getEvent() to check for null. I know its not a permission problem because if it denies them permission it sends the player a message saying so. I haven't gotten any of those, just keep getting the error. Not sure whats wrong.
     
  9. Offline

    timtower Administrator Administrator Moderator

  10. Offline

    GoodMannersDev

    Fixed it. Thank you for your time.
     
  11. Offline

    nverdier

    Please mark this thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page