summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java
blob: 9c6c1eb761dbdbc7bd2317ed2ae2e12e56a7abdf (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
package net.tylermurphy.hideAndSeek.util;

import static net.tylermurphy.hideAndSeek.configuration.Config.*;

import java.io.*;

import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.configuration.LocalizationString;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import net.tylermurphy.hideAndSeek.Main;

public class Util {
    
    public static void broadcastMessage(String message) {
    	for(Player player : Main.plugin.board.getPlayers()) {
    		player.sendMessage(message);
    	}
    }
    
    public static boolean isSetup() {
    	if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return false;
		if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return false;
		if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return false;
		File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld);
		if(!destenation.exists()) return false;
		if(saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) return false;
		return true;
    }
    
    public static void sendDelayedMessage(String message, int gameId, int delay) {
		Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, new Runnable() {
			public void run() {
				if(gameId == Main.plugin.gameId)
					Util.broadcastMessage(message);
			}
		}, delay);
	}

	public YamlConfiguration loadDefaultConfig(String name) {

		YamlConfiguration defaultConfig = null;

		InputStream deafult_stream = null;
		InputStreamReader default_stream_reader = null;
		try {
			deafult_stream = Class.class.getResourceAsStream(name + ".yml");
			default_stream_reader = new InputStreamReader(deafult_stream);
			defaultConfig = YamlConfiguration.loadConfiguration(default_stream_reader);
		} catch (Exception e) {
			// No Issue Here
		} finally {
			try {
				deafult_stream.close();
				default_stream_reader.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return defaultConfig;
	}
	
}