summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java
blob: e2cb5632858a0713841c109c85811abb9ead1e09 (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
package net.tylermurphy.hideAndSeek.command;

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

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.events.Worldborder;
import net.tylermurphy.hideAndSeek.util.Packet;
import net.tylermurphy.hideAndSeek.util.Util;

public class Stop implements ICommand {

	public void execute(CommandSender sender, String[] args) {
		if(!Util.isSetup()) {
			sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do");
			return;
		}
		if(Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing")) {
			if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + "Game has been force stopped.");
			else Util.broadcastMessage(abortPrefix + "Game has been force stopped.");
			onStop();
			
		} else {
			sender.sendMessage(errorPrefix + "There is no game in progress");
			return;
		}
	}

	public String getLabel() {
		return "stop";
	}
	
	public static void onStop() {
		if(Main.plugin.status.equals("Standby")) return;
		Main.plugin.status = "Standby";
		Main.plugin.gameId++;
		Main.plugin.timeLeft = 0;
		Worldborder.resetWorldborder("hideandseek_"+spawnWorld);
		for(Player player : Main.plugin.board.getPlayers()) {
			player.setGameMode(GameMode.ADVENTURE);
			player.setLevel(0);
			Main.plugin.board.addHider(player);
			player.getInventory().clear();
			player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
			for(PotionEffect effect : player.getActivePotionEffects()){
			    player.removePotionEffect(effect.getType());
			}
			player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
			for(Player temp : Main.plugin.board.getPlayers()) {
				Packet.setGlow(player, temp, false);
			}
		}
		Util.unloadMap("hideandseek_"+spawnWorld);
		Main.plugin.board.reloadLobbyBoards();
	}
	
	public String getUsage() {
		return "";
	}

	public String getDescription() {
		return "Stops the game";
	}

}