From ea8eed6010f13a73f05d80ea44a49f609f0c69a4 Mon Sep 17 00:00:00 2001 From: Steffion Date: Sun, 4 Aug 2013 15:05:07 +0200 Subject: [PATCH] Made a join command and let the game work for a bit. --- src/nl/Steffion/BlockHunt/Arena.java | 18 ++- src/nl/Steffion/BlockHunt/BlockHunt.java | 119 ++++++++++++++++++ .../BlockHunt/Commands/CMDcreate.java | 4 +- .../Steffion/BlockHunt/Commands/CMDjoin.java | 26 +++- .../Steffion/BlockHunt/Managers/ConfigC.java | 16 ++- src/nl/Steffion/BlockHunt/W.java | 5 + 6 files changed, 178 insertions(+), 10 deletions(-) diff --git a/src/nl/Steffion/BlockHunt/Arena.java b/src/nl/Steffion/BlockHunt/Arena.java index 3d8810d..9315b01 100644 --- a/src/nl/Steffion/BlockHunt/Arena.java +++ b/src/nl/Steffion/BlockHunt/Arena.java @@ -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 disguiseBlocks; public List playersInArena; + public ArenaState gameState; + public int timer; + public List seekers; public Arena (String arenaName, LocationSerializable pos1, LocationSerializable pos2, int maxPlayers, int minPlayers, int amountSeekersOnStart, int timeInLobbyUntilStart, - int waitingTimeSeeker, int gameTime, List playersInArena) { + int waitingTimeSeeker, int gameTime, + ArrayList disguiseBlocks, List playersInArena, + ArenaState gameState, int timer, List 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; + } } \ No newline at end of file diff --git a/src/nl/Steffion/BlockHunt/BlockHunt.java b/src/nl/Steffion/BlockHunt/BlockHunt.java index a43ff66..a481a04 100644 --- a/src/nl/Steffion/BlockHunt/BlockHunt.java +++ b/src/nl/Steffion/BlockHunt/BlockHunt.java @@ -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, © 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 data = new LinkedList(); + 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() { diff --git a/src/nl/Steffion/BlockHunt/Commands/CMDcreate.java b/src/nl/Steffion/BlockHunt/Commands/CMDcreate.java index 3e11ee8..cff6fb5 100644 --- a/src/nl/Steffion/BlockHunt/Commands/CMDcreate.java +++ b/src/nl/Steffion/BlockHunt/Commands/CMDcreate.java @@ -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(); diff --git a/src/nl/Steffion/BlockHunt/Commands/CMDjoin.java b/src/nl/Steffion/BlockHunt/Commands/CMDjoin.java index 5489d95..ed02261 100644 --- a/src/nl/Steffion/BlockHunt/Commands/CMDjoin.java +++ b/src/nl/Steffion/BlockHunt/Commands/CMDjoin.java @@ -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 { diff --git a/src/nl/Steffion/BlockHunt/Managers/ConfigC.java b/src/nl/Steffion/BlockHunt/Managers/ConfigC.java index 11ebce2..5b676f1 100644 --- a/src/nl/Steffion/BlockHunt/Managers/ConfigC.java +++ b/src/nl/Steffion/BlockHunt/Managers/ConfigC.java @@ -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 + " %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; diff --git a/src/nl/Steffion/BlockHunt/W.java b/src/nl/Steffion/BlockHunt/W.java index 9397ff1..0c41b6f 100644 --- a/src/nl/Steffion/BlockHunt/W.java +++ b/src/nl/Steffion/BlockHunt/W.java @@ -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 arenaList = new ArrayList(); + public static Random random = new Random(); + public static DisguiseCraftAPI dcAPI; public static void newFiles() { ConfigM.setDefaults();