Solved Problems with cast an plugin!

Discussion in 'Plugin Development' started by jusjus112, Feb 9, 2014.

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

    jusjus112

    I have an static for the Listener class, called plugin!
    I want it for an SchedulerDelayedTask, so i dont no how to do it!
    I tied many things, but i cant figured it out.
    Maybe can someone help me?
    Here is my code sofar:
    Code:java
    1. static Main plugin;
    2.  
    3. public NetherStar(Main plugin){
    4. NetherStar.plugin = plugin;
    5. }
    6.  
    7. @EventHandler
    8. public void onCompassClick(final InventoryClickEvent e) {
    9. final Player player = (Player) e.getWhoClicked();
    10. Inventory inv = e.getInventory();
    11. ItemStack cl = e.getCurrentItem();
    12. if (inv.getName().equals(inv.getName())) {
    13. if (inv.getName().equals(inv.getName())) {
    14. if (cl.getType() == Material.COMPASS) {
    15. e.setCancelled(true);
    16. player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 120, 20000));
    17. player.closeInventory();
    18. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    19. @Override
    20. public void run() {
    21. player.performCommand("spawn");
    22. Location loc = e.getWhoClicked().getLocation();
    23. player.playSound(loc, Sound.LEVEL_UP, 1, 1);
    24. ParticleEffect.EXPLODE.display(loc, 0.0f, 1.0f, 0.0f, 0.3F, 50);
    25. ParticleEffect.CLOUD.display(loc, 0.0f, 1.0f, 0.0f, 0.3F, 50);
    26. ParticleEffect.PORTAL.display(loc, 0.0f, 1.0f, 0.0f, 0.5F, 50);
    27. player.sendMessage(MsgType.SPAWN + "Teleport you to spawn....");
    28. }
    29. }, 2 * 20L);
    30. }
    31. }
    32. }
    33. }
     
  2. Offline

    Harmings

    jusjus112
    What's currently wrong with that? But why make it static?
    Code:
    private Main plugin;
     
    public NetherStar(Main instance) {
        this.plugin = instance;
    }
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
     
  3. Offline

    jusjus112

    Harmings
    And btw i got this in my Main class:
    Code:java
    1. public void onEnable() {
    2. getServer().getPluginManager().registerEvents(new NetherStar(null), this);
    3. }


    The error says, "Plugin cannot be null"
    The error is in line 18 from my first code!
     
  4. Offline

    Harmings

    jusjus112
    In your listener class make this the constructor:
    Code:
    private Main plugin;
     
    public NetherStar(Main instance) {
        this.plugin = instance;
    }
    and in your main class register the event like so:
    Code:
    Bukkit.getServer().getPluginManager().registerEvents(new NetherStar(this), this);
     
Thread Status:
Not open for further replies.

Share This Page