Solved Trying to do damage to a player every second they are stuck in a web

Discussion in 'Plugin Development' started by Calebizzthaman, Aug 3, 2017.

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

    Calebizzthaman

    I've been trying to damage to a player every second that they're stuck in a web.

    Code:
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent e)
        {
            Player p = e.getPlayer();
            if(!e.getFrom().getBlock().equals(e.getTo().getBlock()))
            {
                Block b1 = e.getTo().getBlock();
                Block b2 = e.getTo().getBlock().getRelative(BlockFace.UP);
                while(b1.getType() == Material.WEB | b2.getType() == Material.WEB)
                {
                            p.damage(2);
                             return;   
                }
            }
        }
    It only does damage to the player once and not every second. Could someone help?
     
  2. Offline

    Kermit_23

    create a repeating task that damages the player and cancel it when it leaves the web?
     
  3. Offline

    Omer H.

    @Calebizzthaman You need to create a bukkit runnable task that every X amount of ticks does something.
     
  4. Offline

    Calebizzthaman

    @Kermit_23 @Omer H.

    Everytime I try to schedule the task in my listener it gives me an error and says plugin cannot = null.
    I create a "private static Plugin plugin;" to use in the arguments of the task and it still says the same thing.
     
  5. Offline

    Kermit_23

    @Calebizzthaman

    show us how you get your main instance, also is plugin = this set first onEnable?
     
  6. Offline

    Calebizzthaman

    Code:
    public class Main extends JavaPlugin implements Listener{
       
        private static Plugin plugin;
    
       
        @Override
        public void onEnable()
        {
            getLogger().info("Zombie Apocalypse enabled!");
            plugin = this;
            registerEvents(this, new PlayerDeath());
            registerEvents(this, new ZombieSpawn());
            registerEvents(this, new PlayerHeads());
            registerEvents(this, new Medicines());
            registerEvents(this, new BlockPlacing());
            registerEvents(this, new ParticleEffects());
            registerEvents(this, new ZombieFlesh());
            registerEvents(this, new ItemNames());
            registerEvents(this, new LegBreaking());
            registerEvents(this, new ZombieDrops());
            registerEvents(this, new ZombieEffects());
            registerEvents(this, new ZombiesDuringDay());
            registerEvents(this, new BarbedWire());
        }
       
    
        @Override
        public void onDisable()
        {
            getLogger().info("Zombie Apocalypse disabled!");
            plugin = null;//to stop memory leaks
        }
       
    
       
       
        //Makes it much easier than registering events in 10 different methods
        public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
            for (Listener listener : listeners) {
            Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
            }
            }
       
        //To access the plugin variable from other classes
        public static Plugin getPlugin()
        {
            return plugin;
        }
       
    
       
    }

    This is my Main class.
     
  7. Offline

    Kermit_23

    hmm can you post us your current code with the scheduler? and also the full error code?
    EDIT: are you using 'Plugin.getPlugin().plugin' and not 'plugin' ?
     
Thread Status:
Not open for further replies.

Share This Page