Schedulers and events not firing!

Discussion in 'Plugin Development' started by ark9026, Mar 25, 2015.

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

    ark9026

    Code:
    public void Spawner(final Player player){
        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {  
            public void run() {
        @SuppressWarnings("deprecation")
            Location loc = player.getTargetBlock(null, 10).getLocation();
            loc.setY(loc.getY() + 0.8);
            ItemStack red = new ItemStack(Material.WOOL, 1);
            Item item = loc.getWorld().dropItem(loc, red);
            item.setVelocity(new Vector(0,0,0));
            item.teleport(loc);
            Firework fw = (Firework) player.getWorld().spawn(player.getLocation(), Firework.class);
            FireworkMeta meta = fw.getFireworkMeta();
            fw.setFireworkMeta(meta);
            }
            }, 20*20L);
        }
            @EventHandler
            public void onItemPickup(PlayerPickupItemEvent e) {
                    Player p = e.getPlayer();
                    if (e.getItem().getType().equals(Material.WOOL)) {
                            int random = ((int) Math.random() * 10);
                            {
                                    if (random == 1 || random == 2 || random == 3 || random == 4
                                                    || random == 5 || random == 6) {
                                            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,
                                                            10, 1));
                                            p.sendMessage("You were given speed 1!");
                                            return;
                                    }
                                    if (random == 7) {
                                            p.setHealth(20);
                                            p.sendMessage("You were healed!");
                                            return;
                                    }
                                    if (random == 8) {
                                            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,
                                                            10, 2));
                                            p.sendMessage("You were given speed 2!");
                                            return;
                                    }
                                    if (random == 9) {
                                            p.addPotionEffect(new PotionEffect(
                                                            PotionEffectType.INCREASE_DAMAGE, 10, 1));
                                            p.sendMessage("You were given strength!");
                                            return;
                                    }
                                    if (random == 10) {
                                            p.addPotionEffect(new PotionEffect(
                                                            PotionEffectType.REGENERATION, 10, 1));
                                            p.sendMessage("You were given regeneration!");
                                            return;
                                    }
                            }
                    }
            }
    I'm using this code inside of a plugin, and it doesn't seem to be working.The block of wool doesn't spawn, and picking up wool just picks the block up without giving the player a random effect. I have eventhander above my code, and I've registered my events, why doesn't this work?
     
  2. Offline

    mythbusterma

    @ark9026

    First of all, methods begin with a lower case letter. Second, you should format your code so that it can actually be read. Then, are you sure you've invoked spawner()? Also, check to make sure your code isn't generating any stack traces.
     
    ark9026 likes this.
  3. Offline

    mine-care

    uppon what @mythbusterma correctly said, line 22, there is a body started for no reason ( { )
    Secondly, have you debuged?
    EDIT: to be more efficient in your event body, prefer a nested if or a switch statement
     
    ark9026 likes this.
  4. Offline

    ark9026

    @mythbusterma
    My mistake, forgot to make the method lowercase, and I must have forgot to format automatically like I normally do. Wouldn't spawner be overridden by the runnable though? To answer your final question, I have no stack traces on startup or while it's running.

    @mine-care
    That body might just be the problem on the second part, I'll fix it when I have the chance. Also, I've debugged, debugged, and debugged more, the problem is still there. Could you show me some documentation on the final part, I can't say I've ever used a nested if instead of a normal.

    Nope, didn't work guys, the wool block picked up like normal, without giving effects or a message.
     
    Last edited by a moderator: Mar 26, 2015
  5. Offline

    mine-care

    @ark9026 really weird. it should atleast show the debug messages. that means the event is not run :/
     
  6. Offline

    ark9026

    @mine-care That's why this is so weird. Maybe try the code on your end to see if my side is the broken one?
     
Thread Status:
Not open for further replies.

Share This Page