summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java
blob: 722421086102915b37c8d3baf5f690b4fea43e6e (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package net.tylermurphy.hideAndSeek.bukkit;

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

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

import net.tylermurphy.hideAndSeek.command.Stop;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.Packet;

public class Tick {

	static int tick = 0;
	
	public static void onTick() {

		if(board == null) {
			Functions.loadScoreboard();
		}
		
		if(status.equals("Standby")) {
			tick = 0;
		}
		 
		if(status.equals("Playing")) {
			onPlaying();
		}
		
		if(( status.equals("Starting") || status.equals("Playing") ) && Hider.size() < 1) {
			if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + "All hiders have been found.");
			else Functions.broadcastMessage(gameoverPrefix + "All hiders have been found.");
			Stop.onStop();
		}
		if(( status.equals("Starting") || status.equals("Playing") ) && Seeker.size() < 1) {
			if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + "All seekers have quit.");
			else Functions.broadcastMessage(abortPrefix + "All seekers have quit.");
			Stop.onStop();
		}
		
	}
	
	private static void onPlaying() {
		
		tick ++;
		
		for(String playerName : Hider) {
			Player player = playerList.get(playerName);
			int distance = 100;
			for(String seekerName : Seeker) {
				Player seeker = playerList.get(seekerName);
				int temp = (int) player.getLocation().distance(seeker.getLocation());
				if(distance > temp) {
					distance = temp;
				}
			}
			switch(tick%10) {
				case 0:
					if(distance < 30) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f);
					if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
					break;
				case 3:
					if(distance < 30) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f);
					if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
					break;
				case 6:
					if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
					break;
				case 9:
					if(distance < 20) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
					break;
			}
			
		}
		
		if(tick%20 == 0) {
			if(gameLength > 0) {
				timeLeft--;
				for(Player player : playerList.values()) {
					player.setLevel(timeLeft);
				}
				if(timeLeft < 1) {
					if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + "Seekers ran out of time. Hiders win!");
					else Functions.broadcastMessage(gameoverPrefix + "Seekers ran out of time. Hiders win!");
					Stop.onStop();
				}
			}
		}
	}
}