Runnable time?

Discussion in 'Plugin Development' started by javoris767, Jun 24, 2012.

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

    javoris767

    Hey I need to know what the time is in and how to remember it. 20L is 30s right?
     
  2. Offline

    Njol

    The scheduler's arguments are in ticks which are usually 1/20th of a second (but can be longer if the server lags).
     
  3. 20L = long 20... This has nothing to do with time. Do you mean 20 ticks? if so: 20 ticks == 1 second.

    Also what time do you need? In-game time of a world or real time? If the first: Do you need it as minecraft timecode (from 0 to 24000) or in a 24 h format?
     
  4. Offline

    javoris767

    Code:
        @EventHandler
        void onDamage(EntityDamageEvent event){
            if(event.isCancelled()) return;
           
            if(event.getCause() == DamageCause.ENTITY_ATTACK){
                EntityDamageByEntityEvent EvEevent = (EntityDamageByEntityEvent)event;
                if(EvEevent.getDamager() instanceof Player && EvEevent.getEntity() instanceof Player){
                    final Player attacker = (Player)EvEevent.getDamager();
                    final Player victim = (Player)EvEevent.getEntity();
                    if(!plugin.PlayersBlocked.containsKey(attacker.getName()) && !attacker.hasPermission("fairpvp.bypass")){
                        attacker.sendMessage(ChatColor.GREEN + "[FairPvP]: " + ChatColor.RED + "You can no longer use most command for 30 seconds!");
                        plugin.PlayersBlocked.put(attacker.getName(), true);
                        plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable(){
                            @Override
                            public void run() {
                                if(attacker.isOnline()) attacker.sendMessage(ChatColor.GREEN + "[FairPvP] " + ChatColor.RED + "You can now use commands again!");
                                plugin.PlayersBlocked.remove(attacker.getName());
                            }
                           
                        }, plugin.BlockedCommands * 20L);
                        }
                    if(!plugin.PlayersBlocked.containsKey(victim.getName()) && !victim.hasPermission("FairPvP.bypass")){
                        victim.sendMessage(ChatColor.GREEN + "[FairPvP]: " + ChatColor.RED + "You can no longer use most command for 30 seconds!");
                        plugin.PlayersBlocked.put(victim.getName(), true);
                        plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable(){
                            @Override
                            public void run() {
                                if(victim.isOnline()) victim.sendMessage(ChatColor.GREEN + "[FairPvP] " + ChatColor.RED + "You can now use commands again!");
                                plugin.PlayersBlocked.remove(victim.getName());
                            }
                           
                        }, plugin.BlockedCommands * 20L);
                        }
                    }
                }
            }
           
           
        }
    
    Basically I'm doing this.
     
  5. 1. Don't use if(event.isCancelled()) return anymore. Add (ignoreCancelled = true) after @EventHandler instead.
    2. Instead of
    if(event.getCause() == DamageCause.ENTITY_ATTACK){
    EntityDamageByEntityEvent EvEevent = (EntityDamageByEntityEvent)event;
    listen to the EntityDamageByEntityEvent directly.
    3. Don't use async tasks for this! http://wiki.bukkit.org/Scheduler_Programming

    Else your code looks good. What exactly isn't working as expected?
     
    ferrybig likes this.
Thread Status:
Not open for further replies.

Share This Page