[SOLVED]Player die in radius of location

Discussion in 'Plugin Development' started by ceoepts, Jul 11, 2012.

Thread Status:
Not open for further replies.
  1. got it working! well almost. it doesn't give me errors, but the server get a severe error all the time when i'm connected. when no one is on there's no errors.
    assume it's the scheduling that's wrong somehow, maybe i should use the delayed version.

    btw when i change plugin to this i get errors.
    oh yea and when i go to the location that's supposed to harm me, nothing happens.
    here's my code now:

    Code:
         
    this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
                  public void run() {
                   
                      for (Player player : getServer().getOnlinePlayers()){
                          int duration = (plugin.getConfig().getInt("poisontime")*1200);
                       
                                  double x = plugin.getConfig().getDouble("PL.X");
                                double y = plugin.getConfig().getDouble("PL.Y");
                                double z = plugin.getConfig().getDouble("PL.Z");
                                String World = getConfig().getString("PL.World");  //plugin.getConfig().getString("PL.world");
                                Location PoisonLoc = new Location(getServer().getWorld(World),x,y,z);
                                Location PlayerLocation = player.getLocation();
                                if( PlayerLocation.distance( PoisonLoc ) <= 5 )
                          {
                                    player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, duration, 1));
                              //PotionEffect effect = new PotionEffect(PotionEffectType.POISON,duration,1);
                              //effect.apply(getEntity());
                                    //doesn't work
                          }
                          return ;
                      }
                  }
                }, 60L, 20L);
    
    found another way to do it, easier:
    :D
    Code:
       
    @EventHandler(priority = EventPriority.NORMAL)
        public void onMove(PlayerMoveEvent event){
            Player player = event.getPlayer();
            Location playerLocation = player.getLocation();
            int duration = (plugin.getConfig().getInt("poisontime")*1200);
            double x = plugin.getConfig().getDouble("PL.X");
            double y = plugin.getConfig().getDouble("PL.Y");
            double z = plugin.getConfig().getDouble("PL.Z");
            String World = plugin.getConfig().getString("PL.World");  //plugin.getConfig().getString("PL.world");
            Location PoisonLoc = new Location(plugin.getServer().getWorld(World),x,y,z);
            if(playerLocation.distance(PoisonLoc) < 5)
            {
                //player.sendMessage("warning! you are contaminated");
                player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, duration, 1));
            }   
        }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
Thread Status:
Not open for further replies.

Share This Page