Plugin attempted to register task while disabled?

Discussion in 'Plugin Development' started by Alkerti, Aug 23, 2013.

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

    Alkerti

    Problem:

    Code:
    Could not pass event PlayerInteractEvent to Hearth v1.3
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:190)
        at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:160)
        at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:608)
        at net.minecraft.server.v1_6_R2.Packet15Place.handle(SourceFile:58)
        at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
        at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)
        at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
        at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register task while disabled
        at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.validate(CraftScheduler.java:394)
        at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:120)
        at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:116)
        at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.scheduleSyncDelayedTask(CraftScheduler.java:100)
        at me.Alkerti.hearth.PlayerListener.onPlayerInteract(PlayerListener.java:37)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 16 more
    My code :
    Code:
    package me.Alkerti.hearth;
     
    import java.util.ArrayList;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    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;
     
    public class PlayerListener extends JavaPlugin implements Listener {
     
        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent event) {
            final Player player = event.getPlayer();
            player.getInventory().addItem(new ItemStack[] { new ItemStack(90, 1) });
            player.sendMessage(ChatColor.GRAY + "Your Hearth stone returns to you");
     
            if(player.getInventory().contains(90, 1));
            return;
     
        }
     
        private Main plugin;
     
        public PlayerListener(Main plugin)
        {
            this.plugin = plugin;
        }
     
    ArrayList<Player> cooldown = new ArrayList<Player>();
     
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent event) {
        if (event.getItem() != null && event.getItem().getType() == Material.PORTAL){
            final Player player = event.getPlayer();
     
            if(cooldown.contains(player)) {
                player.sendMessage(ChatColor.GRAY + "You can't do that yet!");
                return;
            }
     
            cooldown.add(player);
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
       
                public void run(){
                    cooldown.remove(player);
                    player.sendMessage(ChatColor.LIGHT_PURPLE + "Your Hearth starts to glow.");
                }
            }, 12000);
     
            player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 180, 0));
            player.sendMessage(ChatColor.LIGHT_PURPLE + "Warping..");
     
        // Time which it takes to warp to spawn.
     
        getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
            @Override
            public void run() {
                player.teleport(player.getWorld().getSpawnLocation());
            }
        }, 6L);
     
        if(cooldown.contains(player));
        player.teleport(player.getWorld().getSpawnLocation());
        event.setCancelled(true);
        }
    }
    }
    Can anyone explain what the problem is/how to fix it?

    - The plugin was enabled and doing everything else but teleport me to spawn when I use the Right click Event.
     
  2. Offline

    Loogeh

    Alkerti Where are your onEnable and onDisable?
     
  3. Offline

    The_Doctor_123

    PlayerListener.java is your main class? And also what Loogeh said.
     
  4. Offline

    Alkerti

    I'll give you it now,
    Sorry about that.

    Loogeh
    The_Doctor_123

    Code:
    package me.Alkerti.hearth;
     
    import java.util.logging.Logger;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin {
        private static final Logger log = Logger.getLogger("Minecraft");
     
        @Override
        public void onEnable (){
            log.info("Hearth has been enabled.");
            getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
        }
     
        @Override
        public void onDisable (){
            log.info("Successfully disabled Hearth.");
        }
    }
     
  5. Offline

    Loogeh

    Alkerti Wait... Do you have the main class, and then a listener which extends JavaPlugin?
     
  6. Offline

    Alkerti

    Loogeh
    Just implemented the Listener to the main, problem still occurs.

    - I do have an extends JavaPlugin in the listener.
     
  7. Offline

    snap64

    Alkerti The problem is you use "this", rather than the variable "plugin". Your listener class should never extend JavaPlugin. Just get rid of the "extends JavaPlugin" and replace the "this" reference in the schedule call with "plugin". Since the Bukkit plugin loader doesn't have an object of the listener class saved as a plugin main class, it thinks it's an unregistered plugin.
     
  8. Offline

    Alkerti

    snap64
    Thank you, that worked.
    Could you help me with this?
    Code:
        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent event) {
            final Player player = event.getPlayer();
            player.getInventory().addItem(new ItemStack[] { new ItemStack(Material.PORTAL, 1) });
            player.sendMessage(ChatColor.LIGHT_PURPLE + "Your Hearthstone returns to you");
            if(player.getInventory().contains(Material.PORTAL, 1));
     
    
    I want if(player.getInventory().contains(Material.PORTAL, 1)); to cancel the event above so he does not recieve 2. I used, event.setCancelled(true);
    But that did not work.
     
  9. Offline

    Loogeh

    Alkerti Just use
    Code:
    if(!player.getInventory().contains(Material.PORTAL) {
        player.getInventory.addItem(new ItemStack(Material.PORTAL));
        player.sendMessage(ChatColor.LIGHT_PURPLE + "Your Hearthstone returns to you");
    }
    This will add 1 portal to the player's inventory if they do not already have one
     
  10. Offline

    Alkerti

Thread Status:
Not open for further replies.

Share This Page