Hide and Seek Question

Discussion in 'Plugin Development' started by xWatermelon, Jul 29, 2013.

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

    xWatermelon

    I am making a hide and seek plugin similar to TheHiveMC, and am wondering how they made it so players would turn solid. What happens is if you stand still for 5 seconds, the block that you are disguised as will be placed (using block changes and player.sendBlockChange()).
     
  2. Offline

    adam753

    I don't understand, it sounds like you've answered your own question here. What are you having trouble with?
     
    etaxi341 likes this.
  3. Offline

    Pawnguy7

    I was wondering how that game worked. Anyway, keep a timer that is reset when they move, and if it is over value, make a block there?
     
  4. Offline

    xWatermelon

    I don't know how to make a countdown timer to check if the player hasn't moved for 5 seconds.
     
  5. Offline

    etaxi341

    xWatermelon Look at a Tutorial about Schedulers. There are many out there. The timers are called Schedulers.
     
  6. Offline

    xWatermelon

    I know how to use schedulers, but I don't know how to check if the player hasn't moved for x seconds.
     
  7. Offline

    adam753

    Keep a HashMap<string,int>. The strings will be the names of all the players who should be affected by this*, and the ints will represent how many seconds that player has been standing still. Schedule a repeating task to be running all the time and repeat every 20 ticks (1 second), and every time it runs, increment every int in the hashmap by 1. Finally, listen to PlayerMoveEvent and set the player's timer back down to 0.

    * always store player names as strings, not actual Player objects which can cause memory leaks.
     
  8. Offline

    etaxi341

    xWatermelon Let a Scheduler run all the time but set the time back to 0 if the PlayerMoveEvent get's triggered.
     
  9. Offline

    chasechocolate

    I'm not exactly sure if this will work, but it might (untested):
    Code:java
    1. //In PlayerMoveEvent
    2. final Location oldLoc = player.getLocation();
    3.  
    4. new BukkitRunnable(){
    5. int secondsLeft = 5;
    6.  
    7. @Override
    8. public void run(){
    9. Location newLoc = player.getLocation();
    10.  
    11. if(newLoc.equals(oldLoc)){
    12. if(secondsLeft == 0){
    13. //Turn them into a block or whatever
    14. this.cancel();
    15. } else {
    16. secondsLeft -= 1;
    17. }
    18. } else {
    19. if(secondsLeft != 5){
    20. secondsLeft += 1;
    21. } else {
    22. this.cancel();
    23. }
    24. }
    25. }
    26. }.runTaskTimer(<plugin instance>, 20L, 20L);
     
    xWatermelon likes this.
Thread Status:
Not open for further replies.

Share This Page