summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/manager/TauntManager.java
blob: 6465e446e86b5f85905241794d2685af0e9d1ce8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package net.tylermurphy.hideAndSeek.manager;

import static net.tylermurphy.hideAndSeek.Store.*;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import net.tylermurphy.hideAndSeek.Main;

public class TauntManager {

public static void schedule() {
		
		Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){

			public void run() {
				int temp = gameId;
				while(true) {
					if(tauntPlayer != null && !tauntPlayer.equals("")) {
						try { Thread.sleep(1000); } catch (InterruptedException e) {}
						if(gameId != temp) break;
						continue;
					}
					try { Thread.sleep(1000*60); } catch (InterruptedException e) {}
					if(gameId != temp) break;
					if(Math.random() > .9) {
						Player taunted = null;
						int rand = (int) (Math.random()*Hider.getEntries().size());
						for(Player player : playerList.values()) {
							if(Hider.hasEntry(player.getName())) {
								rand--;
								if(rand==0) {
									taunted = player;
									break;
								}
							}
						}
						if(taunted != null) {
							taunted.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Oh no! You have been chosed to be taunted.");
							Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "Taunt >" + ChatColor.WHITE + " A random hider will be taunted in the next 30s");
							try { Thread.sleep(1000*30); } catch (InterruptedException e) {}
							if(gameId != temp) break;
							tauntPlayer = taunted.getName();
						}
					}
				}
			}
		});
	}
	
}