Making one Event execute Before another

Discussion in 'Plugin Development' started by revocam, Jul 22, 2015.

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

    revocam

    Ok, so i am making a minigame. To win the minigame you have to get to the bottom without taking damage. My problem is that players can jump from the top of the map to the bottom and win the game, to be teleported back to the top. Please read my code and tell me how i can fix this. I will not be disclosing my whole project as people could use it to make their own minigame!
    Code:
              
    package net.steamcade.minigame.games;
    
    import net.steamcade.minigame.Arcade;
    import net.steamcade.minigame.MinigameManager;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Sound;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    
    public class TrickyParkour implements Listener{
        public TrickyParkour(){
           
        }
       
        @EventHandler
        public void onDamage(EntityDamageEvent event){
            if(event.getEntityType() == EntityType.PLAYER){
                Player p = (Player) event.getEntity();
                p.teleport(TestMap.spawns.get(0));
                p.playSound(p.getLocation(), Sound.ANVIL_LAND, 1, 1);
                event.setDamage(0);
            }
        }
       
        @EventHandler(priority = EventPriority.LOWEST)
        public void onMove(PlayerMoveEvent event){
            if(event.getTo().getY() <= 4 && event.getPlayer().getHealth() >= 20){
                Bukkit.getScheduler().scheduleSyncDelayedTask(Arcade.core, new Runnable() {
                   
                    @Override
                    public void run() {
                        MinigameManager.restartGame();
                       
                    }
                }, 40l);
                Bukkit.getServer().broadcastMessage(ChatColor.BOLD + "" + ChatColor.GREEN + "------------------------------");
                Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "" + ChatColor.BOLD +                          "The game is over!");
                Bukkit.getServer().broadcastMessage(ChatColor.RED + "" + ChatColor.BOLD +                          event.getPlayer().getDisplayName() + " has won the game!");
                Bukkit.getServer().broadcastMessage(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD +                          "GG everyone!");
                Bukkit.getServer().broadcastMessage(ChatColor.BOLD + "" + ChatColor.GREEN +"------------------------------");
            }
        }
    }
    
    
    
     
  2. Offline

    Boomer

    They will always be moving through a slice of space with perfect health before they take any damage
    That slice of space is where you want them to cross with perfect health.

    You can not prioritize one event over another - just declare priority for your event handler with respect to other plugins.

    One approach would be to schedule instead a function that performs a check when that player has reached the bottom 20 ticks later: Is his health still >20 --

    This way, a player crosses into the end zone with full health triggering a future check
    Half a second later, that player is standing jumping victoriously on the ground still, safe, or he had been damaged by the continued downwards momentum being imparted into his spine and organs.
     
  3. Offline

    Ganga

    I would simply check the time the players need to get to the ground. If time time is smaller than 2 seconds they will be teleported back without winning!
     
  4. Offline

    Boomer

    parkour - so it could take some players seconds, some minutes...
    we're not talking about simply falling down a pit
     
Thread Status:
Not open for further replies.

Share This Page