Runnable works but on interact it does not D:

Discussion in 'Spigot Plugin Development' started by dmb219910, Jun 15, 2016.

  1. My Classes runnable works but the interact does not its probably something i didn't see that i cant see to find seems like a stupid question i know but please help a dude out :D

    Code (Text):
    package me.dmb219910;

    import java.util.ArrayList;

    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.scheduler.BukkitRunnable;

    import com.connorlinfoot.actionbarapi.ActionBarAPI;

    import net.md_5.bungee.api.ChatColor;


    public final class StartUp extends JavaPlugin {
        @Override
        public void onEnable() {
            new ExampleListener(this);
        }
    }
    class ExampleListener implements Listener {
        private final StartUp plugin;
        public ExampleListener(StartUp plugin) {
            this.plugin = plugin;
            this.plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            // Create the task anonymously and schedule to run it once, after 20 ticks
            new BukkitRunnable() {
           
                @Override
                public void run() {
                    // What you want to schedule goes here
                    plugin.getServer().broadcastMessage(
                        ChatColor.GREEN + "This server is powered by lonelycamper plugins!");
                }
               
            }.runTaskLater(this.plugin, 900);
        }
        ArrayList<Player> cooldown = new ArrayList<Player>();
        @EventHandler
        public void onInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            player.getItemInHand();
            ItemStack Wand = new ItemStack(Material.BLAZE_ROD);
            if(player.getInventory().getItemInHand().equals(Wand)) {
               
                new BukkitRunnable() {
                   
                    @Override
                    public void run() {
                        // What you want to schedule goes here
                        cooldown.remove(player);
                        player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 10));
                        ActionBarAPI.sendActionBar(player,ChatColor.GOLD + "Ability Activated!");
                        cooldown.add(player);
                       
                    }
                   
                }.runTaskLater(this.plugin, 1200);
            }
               
               
               
               
            }
       
       

    }
     
  2. you should probably organize your code into different classes, make sure your events are registered in the onEnable.
     
  3. Seems like it is registerd and right now i wanna keep it in one class because if you dont have the on a sperate class i wont be able to do a runnable because it needs to extend the java plugin..
     
  4. Choco

    Moderator

    You declared a new instance of your listener, but you didn't register it.
    Code (Java):
    Bukkit.getPluginManager().registerEvents(/*your listener instance*/, /*your plugin instance*/);
     
  5.  
  6. Choco

    Moderator

    @lookcook Heh... hehh... awkwaaaard :oops: That's what I get for not reading the code properly. Lol
     
  7. Thats why i think Simple reasoning D: oh wait nvm i declared it
     
    #7 dmb219910, Jun 15, 2016
    Last edited: Jun 15, 2016
  8. Change that to maybe:

    if (player.getInventory().getItemInHand().getType().equals(Material.BLAZE_ROD))
     
  9. Ill try it when i get back on da pc
     
  10. Nah dosent work
     
  11. do system.out.println(player.getInventory().getItemInHand().getType().equals(Material.BLAZE_ROD));

    Tell the results here ;), does the event even trigger? does the plugin show up in /plugins?
     
  12. Were would i put this because im getting errors every were i put it
     
  13. We can't help you if you don't give us the error and where the error is located.
    Well we can . . . but it's alot easier if you give us the error. . . XD
     
  14. Umm hello cant you ever read there is no error thats the weird problem
     
  15.  
  16. Syntax error, insert "while ( Expression ) ;" to complete BlockStatements if your talking about the do state ment here ya go
     
  17. Gotta be more specific
     
  18. Could you give me your new code?
    I don't see any do-whiles in your code in the first post.
     
  19. Code (Text):
    package me.dmb219910;

    import java.util.ArrayList;

    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.scheduler.BukkitRunnable;

    import com.connorlinfoot.actionbarapi.ActionBarAPI;

    import net.md_5.bungee.api.ChatColor;


    public final class StartUp extends JavaPlugin {
        @Override
        public void onEnable() {
            new ExampleListener(this);
        }
    }
    class ExampleListener implements Listener {
        private final StartUp plugin;
        public ExampleListener(StartUp plugin) {
            this.plugin = plugin;
            this.plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            // Create the task anonymously and schedule to run it once, after 20 ticks
            new BukkitRunnable() {
           
                @Override
                public void run() {
                    // What you want to schedule goes here
                    plugin.getServer().broadcastMessage(
                        ChatColor.GREEN + "This server is powered by lonelycamper plugins!");
                }
               
            }.runTaskLater(this.plugin, 900);
        }
        ArrayList<Player> cooldown = new ArrayList<Player>();
        @EventHandler
       

        public void onInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            player.getItemInHand();
            if (player.getInventory().getItemInHand().getType().equals(Material.BLAZE_ROD)) {
               
                new BukkitRunnable() {
                   
                    @Override
                    public void run() {
                        // What you want to schedule goes here
                        do system.out.println(player.getInventory().getItemInHand().getType().equals(Material.BLAZE_ROD));
                        cooldown.remove(player);
                        player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 10));
                        ActionBarAPI.sendActionBar(player,ChatColor.GOLD + "Ability Activated!");
                        cooldown.add(player);
                       
                    }
                   
                }.runTaskLater(this.plugin, 1200);
            }
               
               
               
               
            }
       
       

    }