Made a join command and let the game work for a bit.
This commit is contained in:
		@@ -1,10 +1,12 @@
 | 
			
		||||
package nl.Steffion.BlockHunt;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
public class Arena {
 | 
			
		||||
	public String arenaName;
 | 
			
		||||
@@ -16,12 +18,18 @@ public class Arena {
 | 
			
		||||
	public int timeInLobbyUntilStart;
 | 
			
		||||
	public int waitingTimeSeeker;
 | 
			
		||||
	public int gameTime;
 | 
			
		||||
	public ArrayList<ItemStack> disguiseBlocks;
 | 
			
		||||
	public List<Player> playersInArena;
 | 
			
		||||
	public ArenaState gameState;
 | 
			
		||||
	public int timer;
 | 
			
		||||
	public List<Player> seekers;
 | 
			
		||||
 | 
			
		||||
	public Arena (String arenaName, LocationSerializable pos1,
 | 
			
		||||
			LocationSerializable pos2, int maxPlayers, int minPlayers,
 | 
			
		||||
			int amountSeekersOnStart, int timeInLobbyUntilStart,
 | 
			
		||||
			int waitingTimeSeeker, int gameTime, List<Player> playersInArena) {
 | 
			
		||||
			int waitingTimeSeeker, int gameTime,
 | 
			
		||||
			ArrayList<ItemStack> disguiseBlocks, List<Player> playersInArena,
 | 
			
		||||
			ArenaState gameState, int timer, List<Player> seekers) {
 | 
			
		||||
		this.arenaName = arenaName;
 | 
			
		||||
		this.pos1 = pos1;
 | 
			
		||||
		this.pos2 = pos2;
 | 
			
		||||
@@ -31,7 +39,11 @@ public class Arena {
 | 
			
		||||
		this.timeInLobbyUntilStart = timeInLobbyUntilStart;
 | 
			
		||||
		this.waitingTimeSeeker = waitingTimeSeeker;
 | 
			
		||||
		this.gameTime = gameTime;
 | 
			
		||||
		this.disguiseBlocks = disguiseBlocks;
 | 
			
		||||
		this.playersInArena = playersInArena;
 | 
			
		||||
		this.gameState = gameState;
 | 
			
		||||
		this.timer = timer;
 | 
			
		||||
		this.seekers = seekers;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public enum ArenaType {
 | 
			
		||||
@@ -42,4 +54,8 @@ public class Arena {
 | 
			
		||||
		waitingTimeSeeker,
 | 
			
		||||
		gameTime;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public enum ArenaState {
 | 
			
		||||
		WAITING, STARTING, INGAME, RESTARTING, DISABLED;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,10 @@
 | 
			
		||||
package nl.Steffion.BlockHunt;
 | 
			
		||||
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
 | 
			
		||||
import nl.Steffion.BlockHunt.Arena.ArenaState;
 | 
			
		||||
import nl.Steffion.BlockHunt.Listeners.OnInventoryClickEvent;
 | 
			
		||||
import nl.Steffion.BlockHunt.Listeners.OnInventoryCloseEvent;
 | 
			
		||||
import nl.Steffion.BlockHunt.Listeners.OnPlayerInteractEvent;
 | 
			
		||||
import nl.Steffion.BlockHunt.Managers.CommandC;
 | 
			
		||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
 | 
			
		||||
@@ -13,8 +17,13 @@ import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
import org.bukkit.plugin.java.JavaPlugin;
 | 
			
		||||
 | 
			
		||||
import pgDev.bukkit.DisguiseCraft.DisguiseCraft;
 | 
			
		||||
import pgDev.bukkit.DisguiseCraft.disguise.Disguise;
 | 
			
		||||
import pgDev.bukkit.DisguiseCraft.disguise.DisguiseType;
 | 
			
		||||
 | 
			
		||||
public class BlockHunt extends JavaPlugin implements Listener {
 | 
			
		||||
	/*
 | 
			
		||||
	 * Made by @author Steffion, <20> 2013.
 | 
			
		||||
@@ -26,6 +35,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
 | 
			
		||||
				new OnPlayerInteractEvent(), this);
 | 
			
		||||
		getServer().getPluginManager().registerEvents(
 | 
			
		||||
				new OnInventoryClickEvent(), this);
 | 
			
		||||
		getServer().getPluginManager().registerEvents(
 | 
			
		||||
				new OnInventoryCloseEvent(), this);
 | 
			
		||||
 | 
			
		||||
		ConfigurationSerialization.registerClass(LocationSerializable.class,
 | 
			
		||||
				"Location");
 | 
			
		||||
@@ -36,9 +47,117 @@ public class BlockHunt extends JavaPlugin implements Listener {
 | 
			
		||||
 | 
			
		||||
		ArenaHandler.loadArenas();
 | 
			
		||||
 | 
			
		||||
		W.dcAPI = DisguiseCraft.getAPI();
 | 
			
		||||
 | 
			
		||||
		MessageM.sendFMessage(null, ConfigC.log_Enabled, true, "name-"
 | 
			
		||||
				+ W.pluginName, "version-" + W.pluginVersion, "autors-"
 | 
			
		||||
				+ W.pluginAutors);
 | 
			
		||||
 | 
			
		||||
		getServer().getScheduler().runTaskTimer(this, new Runnable() {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void run() {
 | 
			
		||||
				for (Arena arena : W.arenaList) {
 | 
			
		||||
					if (arena.gameState == ArenaState.WAITING) {
 | 
			
		||||
						if (arena.playersInArena.size() >= arena.minPlayers) {
 | 
			
		||||
							arena.gameState = ArenaState.STARTING;
 | 
			
		||||
							arena.timer = arena.timeInLobbyUntilStart;
 | 
			
		||||
							ArenaHandler.sendFMessage(arena,
 | 
			
		||||
									ConfigC.normal_lobbyArenaIsStarting, true,
 | 
			
		||||
									"1-" + arena.timeInLobbyUntilStart);
 | 
			
		||||
						}
 | 
			
		||||
					} else if (arena.gameState == ArenaState.STARTING) {
 | 
			
		||||
						if (arena.timer > 0) {
 | 
			
		||||
							arena.timer = arena.timer - 1;
 | 
			
		||||
							if (arena.timer == 60) {
 | 
			
		||||
								ArenaHandler.sendFMessage(arena,
 | 
			
		||||
										ConfigC.normal_lobbyArenaIsStarting,
 | 
			
		||||
										true, "1-60");
 | 
			
		||||
							} else if (arena.timer == 30) {
 | 
			
		||||
								ArenaHandler.sendFMessage(arena,
 | 
			
		||||
										ConfigC.normal_lobbyArenaIsStarting,
 | 
			
		||||
										true, "1-30");
 | 
			
		||||
							} else if (arena.timer == 10) {
 | 
			
		||||
								ArenaHandler.sendFMessage(arena,
 | 
			
		||||
										ConfigC.normal_lobbyArenaIsStarting,
 | 
			
		||||
										true, "1-10");
 | 
			
		||||
							} else if (arena.timer == 5) {
 | 
			
		||||
								ArenaHandler.sendFMessage(arena,
 | 
			
		||||
										ConfigC.normal_lobbyArenaIsStarting,
 | 
			
		||||
										true, "1-5");
 | 
			
		||||
							} else if (arena.timer == 4) {
 | 
			
		||||
								ArenaHandler.sendFMessage(arena,
 | 
			
		||||
										ConfigC.normal_lobbyArenaIsStarting,
 | 
			
		||||
										true, "1-4");
 | 
			
		||||
							} else if (arena.timer == 3) {
 | 
			
		||||
								ArenaHandler.sendFMessage(arena,
 | 
			
		||||
										ConfigC.normal_lobbyArenaIsStarting,
 | 
			
		||||
										true, "1-3");
 | 
			
		||||
							} else if (arena.timer == 2) {
 | 
			
		||||
								ArenaHandler.sendFMessage(arena,
 | 
			
		||||
										ConfigC.normal_lobbyArenaIsStarting,
 | 
			
		||||
										true, "1-2");
 | 
			
		||||
							} else if (arena.timer == 1) {
 | 
			
		||||
								ArenaHandler.sendFMessage(arena,
 | 
			
		||||
										ConfigC.normal_lobbyArenaIsStarting,
 | 
			
		||||
										true, "1-1");
 | 
			
		||||
							}
 | 
			
		||||
						} else {
 | 
			
		||||
							arena.gameState = ArenaState.INGAME;
 | 
			
		||||
							arena.timer = arena.gameTime;
 | 
			
		||||
							ArenaHandler.sendFMessage(arena,
 | 
			
		||||
									ConfigC.normal_lobbyArenaStarted, true);
 | 
			
		||||
 | 
			
		||||
							for (int i = arena.amountSeekersOnStart; i > 0; i = i - 1) {
 | 
			
		||||
								Player seeker = arena.playersInArena
 | 
			
		||||
										.get(W.random
 | 
			
		||||
												.nextInt(arena.playersInArena
 | 
			
		||||
														.size()));
 | 
			
		||||
								ArenaHandler.sendFMessage(arena,
 | 
			
		||||
										ConfigC.normal_ingameSeekerChoosen,
 | 
			
		||||
										true, "seeker-" + seeker.getName());
 | 
			
		||||
								arena.seekers.add(seeker);
 | 
			
		||||
							}
 | 
			
		||||
							
 | 
			
		||||
							for (Player arenaPlayer : arena.playersInArena) {
 | 
			
		||||
								if (!arena.seekers.contains(arenaPlayer)) {
 | 
			
		||||
									ItemStack block = arena.disguiseBlocks.get(W.random
 | 
			
		||||
											.nextInt(arena.disguiseBlocks
 | 
			
		||||
													.size()));
 | 
			
		||||
									LinkedList<String> data = new LinkedList<String>();
 | 
			
		||||
									data.add("blockID:" + block.getTypeId());
 | 
			
		||||
									data.add("blockData:"
 | 
			
		||||
											+ block.getDurability());
 | 
			
		||||
									Disguise disguise = new Disguise(W.dcAPI
 | 
			
		||||
											.newEntityID(), data,
 | 
			
		||||
											DisguiseType.FallingBlock);
 | 
			
		||||
									if (W.dcAPI.isDisguised(arenaPlayer)) {
 | 
			
		||||
										W.dcAPI.changePlayerDisguise(
 | 
			
		||||
												arenaPlayer, disguise);
 | 
			
		||||
									} else {
 | 
			
		||||
										W.dcAPI.disguisePlayer(arenaPlayer,
 | 
			
		||||
												disguise);
 | 
			
		||||
									}
 | 
			
		||||
 | 
			
		||||
									MessageM.sendFMessage(
 | 
			
		||||
											arenaPlayer,
 | 
			
		||||
											ConfigC.normal_ingameBlock,
 | 
			
		||||
											true,
 | 
			
		||||
											"block-"
 | 
			
		||||
													+ block.getType()
 | 
			
		||||
															.name()
 | 
			
		||||
															.replaceAll("_", "")
 | 
			
		||||
															.replaceAll(
 | 
			
		||||
																	"BLOCK", "")
 | 
			
		||||
															.toLowerCase()
 | 
			
		||||
													+ ":"
 | 
			
		||||
													+ block.getDurability());
 | 
			
		||||
								}
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}, 0, 20);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void onDisable() {
 | 
			
		||||
 
 | 
			
		||||
@@ -31,8 +31,8 @@ public class CMDcreate extends DefaultCMD {
 | 
			
		||||
 | 
			
		||||
							ArenaSerializable arena = new ArenaSerializable(
 | 
			
		||||
									args[1], W.pos1.get(player),
 | 
			
		||||
									W.pos2.get(player), 12, 3, 1, 90, 20, 200,
 | 
			
		||||
									null);
 | 
			
		||||
									W.pos2.get(player), 12, 3, 1, 90, 20, 300,
 | 
			
		||||
									null, null, null, 0, null);
 | 
			
		||||
							W.arenas.getFile().set(args[1], arena);
 | 
			
		||||
							W.arenas.save();
 | 
			
		||||
							ArenaHandler.loadArenas();
 | 
			
		||||
 
 | 
			
		||||
@@ -38,12 +38,26 @@ public class CMDjoin extends DefaultCMD {
 | 
			
		||||
						for (Arena arena : W.arenaList) {
 | 
			
		||||
							if (arena.arenaName.equalsIgnoreCase(args[1])) {
 | 
			
		||||
								found = true;
 | 
			
		||||
								arena.playersInArena.add(player);
 | 
			
		||||
								ArenaHandler.sendFMessage(arena,
 | 
			
		||||
										ConfigC.normal_joinJoinedArena, true,
 | 
			
		||||
										"playername-" + player.getName(), "1-"
 | 
			
		||||
												+ arena.playersInArena.size(),
 | 
			
		||||
										"2-" + arena.maxPlayers);
 | 
			
		||||
								if (arena.disguiseBlocks.isEmpty()) {
 | 
			
		||||
									MessageM.sendFMessage(player,
 | 
			
		||||
											ConfigC.error_joinNoBlocksSet, true);
 | 
			
		||||
								} else {
 | 
			
		||||
									arena.playersInArena.add(player);
 | 
			
		||||
									ArenaHandler.sendFMessage(arena,
 | 
			
		||||
											ConfigC.normal_joinJoinedArena,
 | 
			
		||||
											true,
 | 
			
		||||
											"playername-" + player.getName(),
 | 
			
		||||
											"1-" + arena.playersInArena.size(),
 | 
			
		||||
											"2-" + arena.maxPlayers);
 | 
			
		||||
									if (arena.playersInArena.size() < arena.minPlayers) {
 | 
			
		||||
										ArenaHandler
 | 
			
		||||
												.sendFMessage(
 | 
			
		||||
														arena,
 | 
			
		||||
														ConfigC.warning_lobbyNeedAtleast,
 | 
			
		||||
														true,
 | 
			
		||||
														"1-" + arena.minPlayers);
 | 
			
		||||
									}
 | 
			
		||||
								}
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
					} else {
 | 
			
		||||
 
 | 
			
		||||
@@ -60,6 +60,17 @@ public enum ConfigC {
 | 
			
		||||
			W.messages),
 | 
			
		||||
	normal_createCreatedArena ("%NCreated an arena with the name '%A%name%%N'.",
 | 
			
		||||
			W.messages),
 | 
			
		||||
	normal_lobbyArenaIsStarting ("%NThe arena will start in %A%1%%N second(s)!",
 | 
			
		||||
			W.messages),
 | 
			
		||||
	normal_lobbyArenaStarted ("%NThe arena has been started! The seeker is comming to find you!",
 | 
			
		||||
			W.messages),
 | 
			
		||||
	normal_ingameSeekerChoosen ("%NPlayer %A%seeker%%N has been choosen as seeker!",
 | 
			
		||||
			W.messages),
 | 
			
		||||
	normal_ingameBlock ("%NYou're disguised as a(n) '%A%block%%N' block.",
 | 
			
		||||
			W.messages),
 | 
			
		||||
 | 
			
		||||
	warning_lobbyNeedAtleast ("%WYou need atleast %A%1%%W player(s) to start the game!",
 | 
			
		||||
			W.messages),
 | 
			
		||||
 | 
			
		||||
	error_noPermission ("%EYou don't have the permissions to do that!",
 | 
			
		||||
			W.messages),
 | 
			
		||||
@@ -71,6 +82,8 @@ public enum ConfigC {
 | 
			
		||||
	error_noArena ("%ENo arena found with the name '%A%name%%E'.", W.messages),
 | 
			
		||||
	error_onlyIngame ("%EThis is an only in-game command!", W.messages),
 | 
			
		||||
	error_joinAlreadyJoined ("%EYou've already joined an arena!", W.messages),
 | 
			
		||||
	error_joinNoBlocksSet ("%EThere are none blocks set for this arena. Notify the administrator.",
 | 
			
		||||
			W.messages),
 | 
			
		||||
	error_createSelectionFirst ("%EMake a selection first. Use the wand command: %A/"
 | 
			
		||||
			+ W.pluginName + " <wand|w>%E.",
 | 
			
		||||
			W.messages),
 | 
			
		||||
@@ -79,7 +92,8 @@ public enum ConfigC {
 | 
			
		||||
	error_setTooHighNumber ("%EThat amount is too high! Max amount is: %A%max%%E.",
 | 
			
		||||
			W.messages),
 | 
			
		||||
	error_setTooLowNumber ("%EThat amount is too low! Minimal amount is: %A%min%%E.",
 | 
			
		||||
			W.messages);
 | 
			
		||||
			W.messages),
 | 
			
		||||
	error_setNotABlock ("%EThat is not a block!", W.messages);
 | 
			
		||||
 | 
			
		||||
	public Object value;
 | 
			
		||||
	public ConfigM config;
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,12 @@ package nl.Steffion.BlockHunt;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Random;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import pgDev.bukkit.DisguiseCraft.api.DisguiseCraftAPI;
 | 
			
		||||
 | 
			
		||||
import nl.Steffion.BlockHunt.Managers.ConfigM;
 | 
			
		||||
import nl.Steffion.BlockHunt.Managers.MessageM;
 | 
			
		||||
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
 | 
			
		||||
@@ -27,6 +30,8 @@ public class W {
 | 
			
		||||
	public static ConfigM messages = new ConfigM("messages", "");
 | 
			
		||||
	public static ConfigM arenas = new ConfigM("arenas", "");
 | 
			
		||||
	public static ArrayList<Arena> arenaList = new ArrayList<Arena>();
 | 
			
		||||
	public static Random random = new Random();
 | 
			
		||||
	public static DisguiseCraftAPI dcAPI;
 | 
			
		||||
 | 
			
		||||
	public static void newFiles() {
 | 
			
		||||
		ConfigM.setDefaults();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user