On night

Discussion in 'Plugin Development' started by Wingas, Jul 24, 2014.

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

    Wingas

    I want to make, when night, players gains like nightvision, I have code, but I don't know where to write it, code:
    Code:java
    1. if(player.getWorld().getTime() == 13000){
    2. player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 600, 2));
    3. }

    Maybe this thing have specific event?
     
  2. Offline

    vtg_the_kid

  3. Offline

    Pizza371

    Wingas it doesn't unfortunately.
    You can use a schedular though, it willk do the same thing.
     
  4. Offline

    Wingas

    any more answers?
     
  5. Offline

    DannyDog

    There are many different approaches to this. But you should look into schedulers.
     
    MarinD99 likes this.
  6. Offline

    Wingas

    DannyDog uhhh, im new in scheduler, can you write an example?
     
  7. Offline

    Gater12

  8. Offline

    Wingas

    Gater12 I don't know which to use..
     
  9. Offline

    desht

    Wingas use a sync repeating task (.runTaskTimer()) with an interval chosen by you (say, every 5 seconds). In that task, check the time - if it's dusk (within the same time range as the interval you chose) then give the player(s) the night vision effect. Do the opposite if it's dawn.
     
  10. Offline

    MarinD99

    I agree with DannyDog. The are more ways to approach this. I reccomend to start here: http://wiki.bukkit.org/Scheduler_Programming I also understand that you're looking for an example? Here's one:
    Code:java
    1. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    2. {
    3. public void run()
    4. {
    5. // Do desired code here, and of course, define the Player above;
    6. }
    7. }, <The ticks, i don't know how many ticks a day has :P>();
    Warning: May contain mistakes, written by hand!
     
  11. Offline

    Wingas

    How to get specific player for scheduler? or all players
     
Thread Status:
Not open for further replies.

Share This Page