From 55e15245e631edda2d7e9146b5229df4f8043dba Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 11 Oct 2021 17:06:21 -0400 Subject: [PATCH] finished lobby and manual join system --- .../net/tylermurphy/hideAndSeek/Store.java | 26 +++++++-- .../hideAndSeek/bukkit/CommandHandler.java | 3 + .../hideAndSeek/bukkit/EventListener.java | 13 +++-- .../tylermurphy/hideAndSeek/command/Join.java | 17 ++++-- .../hideAndSeek/command/Leave.java | 56 +++++++++++++++++++ .../hideAndSeek/command/Reload.java | 2 +- .../hideAndSeek/command/SetLobbyLocation.java | 48 ++++++++++++++++ .../hideAndSeek/command/Start.java | 20 ++++--- .../tylermurphy/hideAndSeek/command/Stop.java | 2 +- .../tylermurphy/hideAndSeek/events/Taunt.java | 5 +- .../hideAndSeek/events/Worldborder.java | 3 +- .../hideAndSeek/util/Functions.java | 6 ++ src/main/resources/plugin.yml | 12 ++++ 13 files changed, 186 insertions(+), 27 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Store.java b/src/main/java/net/tylermurphy/hideAndSeek/Store.java index 88bab83..c6f48eb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Store.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Store.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -16,7 +17,10 @@ import org.bukkit.util.Vector; public class Store { public static Map - playerList = new HashMap(); + playerList = new HashMap(); + + public static Map + playerLastLocationList = new HashMap(); public static List Hider, @@ -44,6 +48,7 @@ public class Store { public static Vector spawnPosition, + lobbyPosition, worldborderPosition; public static List @@ -52,7 +57,8 @@ public class Store { public static boolean nametagsVisible, permissionsRequired, - manualJoin, + lobbyManualJoin, + lobbyAnnounced, lobbyStarted = false, unbreakableArmorstands, unbreakablePaintings, @@ -104,7 +110,12 @@ public class Store { getConfig().addDefault("prefix.warning", "&cWarning > &f"); getConfig().addDefault("nametagsVisible", false); getConfig().addDefault("permissionsRequired", true); - getConfig().addDefault("manualJoin", true); + getConfig().addDefault("lobby.manualJoin", false); + getConfig().addDefault("lobby.countdownTime", 60); + getConfig().addDefault("lobby.announceJoinAndLeave", false); + getConfig().addDefault("lobby.spawn.x", 0); + getConfig().addDefault("lobby.spawn.y", 0); + getConfig().addDefault("lobby.spawn.z", 0); getConfig().addDefault("blockSettings.unbreakable.painting", false); getConfig().addDefault("blockSettings.unbreakable.armorstand", false); getConfig().addDefault("blockSettings.unbreakable.itemframe", false); @@ -123,6 +134,13 @@ public class Store { ); spawnWorld = getConfig().getString("spawn.world"); + ///Lobby + lobbyPosition = new Vector( + getConfig().getDouble("lobby.spawn.x"), + Math.max(0,Math.min(255,getConfig().getDouble("lobby.spawn.y"))), + getConfig().getDouble("lobby.spawn.z") + ); + //World border worldborderPosition = new Vector( getConfig().getInt("worldBorder.x"), @@ -150,7 +168,7 @@ public class Store { //Other nametagsVisible = getConfig().getBoolean("nametagsVisible"); permissionsRequired = getConfig().getBoolean("permissionsRequired"); - manualJoin = getConfig().getBoolean("manualJoin"); + lobbyManualJoin = getConfig().getBoolean("lobby.manualJoin"); unbreakablePaintings = getConfig().getBoolean("blockSettings.unbreakable.painting"); unbreakableArmorstands = getConfig().getBoolean("blockSettings.unbreakable.armorstand"); unbreakableItemframes = getConfig().getBoolean("blockSettings.unbreakable.itemframe"); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java index 73bfd08..f688881 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java @@ -29,9 +29,12 @@ public class CommandHandler { registerCommand(new Start()); registerCommand(new Stop()); registerCommand(new SetSpawnLocation()); + registerCommand(new SetLobbyLocation()); registerCommand(new SetBorder()); registerCommand(new Reload()); registerCommand(new SaveMap()); + registerCommand(new Join()); + registerCommand(new Leave()); } public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index 61b484f..5cf83a1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -40,7 +40,12 @@ public class EventListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { if(status.equals("Playing") || status.equals("Starting")) { - if(manualJoin && !Functions.playerInProtectedWorld(event.getPlayer())) return; + if(lobbyManualJoin) { + event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld)) { + return; + } else return; + } Spectator.add(event.getPlayer().getName()); SpectatorTeam.addEntry(event.getPlayer().getName()); event.getPlayer().sendMessage(messagePrefix + "You have joined mid game, and thus have been placed on the spectator team."); @@ -51,16 +56,16 @@ public class EventListener implements Listener { } event.getPlayer().teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); } else if(status.equals("Setup") || status.equals("Standby")) { - if (manualJoin) { + if (lobbyManualJoin) { if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld)){ - event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); return; } } Hider.add(event.getPlayer().getName()); HiderTeam.addEntry(event.getPlayer().getName()); event.getPlayer().setGameMode(GameMode.ADVENTURE); - event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); } playerList.put(event.getPlayer().getName(), event.getPlayer()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 88e650d..4b0baa3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -12,8 +12,8 @@ import static net.tylermurphy.hideAndSeek.Store.*; public class Join implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!manualJoin) { - sender.sendMessage(errorPrefix + "Manual join isnt enabled in this server"); + if(!lobbyManualJoin) { + sender.sendMessage(errorPrefix + "Manual join/leave isnt set to manual in this server"); return; } if(!status.equals("Standby")) { @@ -29,23 +29,28 @@ public class Join implements ICommand { sender.sendMessage(errorPrefix + "An internal error has occured"); return; } + if(playerList.containsKey(player.getName())){ + sender.sendMessage(errorPrefix + "You are already in the lobby"); + return; + } playerList.put(player.getName(), player); Hider.add(player.getName()); HiderTeam.addEntry(player.getName()); + playerLastLocationList.put(player.getName(), player.getLocation()); player.teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); - Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the game lobby"); + if(lobbyAnnounced) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby"); } public String getLabel() { - return null; + return "join"; } public String getUsage() { - return null; + return ""; } public String getDescription() { - return null; + return "Joins the lobby if game is set to manual join/leave"; } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java new file mode 100644 index 0000000..bde14da --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -0,0 +1,56 @@ +package net.tylermurphy.hideAndSeek.command; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import net.tylermurphy.hideAndSeek.util.ICommand; + +import static net.tylermurphy.hideAndSeek.Store.*; + +public class Leave implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if(!lobbyManualJoin) { + sender.sendMessage(errorPrefix + "Manual join/leave isnt set to manual in this server"); + return; + } + if(!status.equals("Standby")) { + sender.sendMessage(errorPrefix + "Game is currently in session"); + return; + } + if(!lobbyStarted) { + sender.sendMessage(errorPrefix + "There is currently no lobby in session"); + return; + } + Player player = Bukkit.getServer().getPlayer(sender.getName()); + if(player == null) { + sender.sendMessage(errorPrefix + "An internal error has occured"); + return; + } + if(!playerList.containsKey(player.getName())) { + sender.sendMessage(errorPrefix + "You are currently not in the lobby"); + return; + } + playerList.remove(player.getName()); + Hider.remove(player.getName()); + Seeker.remove(player.getName()); + HiderTeam.removeEntry(player.getName()); + SeekerTeam.removeEntry(player.getName()); + player.teleport(playerLastLocationList.get(player.getName())); + if(lobbyAnnounced) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has left the HideAndSeek lobby"); + } + + public String getLabel() { + return "leave"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Leaves the lobby if game is set to manual join/leave"; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 9771c2f..d333f6c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -25,7 +25,7 @@ public class Reload implements ICommand { } catch(Exception e) {} sender.sendMessage(messagePrefix + "Reloaded the config"); playerList = new HashMap(); - if(!manualJoin) { + if(!lobbyManualJoin) { for(Player p : Bukkit.getOnlinePlayers()) playerList.put(p.getName(), p); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java new file mode 100644 index 0000000..299a227 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java @@ -0,0 +1,48 @@ +package net.tylermurphy.hideAndSeek.command; + +import static net.tylermurphy.hideAndSeek.Store.*; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import net.tylermurphy.hideAndSeek.util.ICommand; + +public class SetLobbyLocation implements ICommand { + + public void execute(CommandSender sender, String[] args) { + Vector newLobbyPosition = new Vector(); + Player player = (Player) sender; + newLobbyPosition.setX(player.getLocation().getBlockX()); + newLobbyPosition.setY(player.getLocation().getBlockY()); + newLobbyPosition.setZ(player.getLocation().getBlockZ()); + if(!status.equals("Standby")) { + sender.sendMessage(errorPrefix + "Game is currently in session"); + return; + } + lobbyPosition = newLobbyPosition; + sender.sendMessage(messagePrefix + "Set lobby position to current location"); + Map temp = new HashMap(); + temp.put("x", lobbyPosition.getX()); + temp.put("y", lobbyPosition.getY()); + temp.put("z", lobbyPosition.getZ()); + addToSection("lobby.spawn",temp); + saveConfig(); + } + + public String getLabel() { + return "setlobby"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks lobby location to current position"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index f5f2148..fb715d6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -32,6 +32,10 @@ public class Start implements ICommand { sender.sendMessage(errorPrefix + "Please set spawn location first"); return; } + if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) { + sender.sendMessage(errorPrefix + "Please set lobby location first"); + return; + } File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); if(!destenation.exists()) { sender.sendMessage(errorPrefix + "Please set map save first"); @@ -94,54 +98,54 @@ public class Start implements ICommand { Functions.resetWorldborder("hideandseek_"+spawnWorld); status = "Starting"; int temp = gameId; - Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!"); + Functions.broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!"); Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { public void run() { if(temp != gameId) return; - Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 20 seconds to hide!"); + Functions.broadcastMessage(messagePrefix + "Hiders have 20 seconds to hide!"); } }, 20 * 10); Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { public void run() { if(temp != gameId) return; - Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 10 seconds to hide!"); + Functions.broadcastMessage(messagePrefix + "Hiders have 10 seconds to hide!"); } }, 20 * 20); Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { public void run() { if(temp != gameId) return; - Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 5 seconds to hide!"); + Functions.broadcastMessage(messagePrefix + "Hiders have 5 seconds to hide!"); } }, 20 * 25); Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { public void run() { if(temp != gameId) return; - Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 3 seconds to hide!"); + Functions.broadcastMessage(messagePrefix + "Hiders have 3 seconds to hide!"); } }, 20 * 27); Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { public void run() { if(temp != gameId) return; - Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 2 seconds to hide!"); + Functions.broadcastMessage(messagePrefix + "Hiders have 2 seconds to hide!"); } }, 20 * 28); Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { public void run() { if(temp != gameId) return; - Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!"); + Functions.broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!"); } }, 20 * 29); Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { public void run() { if(temp != gameId) return; - Bukkit.getServer().broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!"); + Functions.broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!"); status = "Playing"; for(Player player : playerList.values()) { Functions.resetPlayer(player); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index c956d3d..2b96809 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -41,7 +41,7 @@ public class Stop implements ICommand { Hider.add(player.getName()); HiderTeam.addEntry(player.getName()); player.getInventory().clear(); - player.teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + player.teleport(new Location(Bukkit.getWorld(spawnWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); for(PotionEffect effect : player.getActivePotionEffects()){ player.removePotionEffect(effect.getType()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java index f2f09a1..0890832 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java @@ -12,6 +12,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.meta.FireworkMeta; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.Functions; public class Taunt { @@ -65,7 +66,7 @@ public class Taunt { } if(taunted != null) { taunted.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Oh no! You have been chosed to be taunted."); - Bukkit.getServer().broadcastMessage(tauntPrefix + " A random hider will be taunted in the next 30s"); + Functions.broadcastMessage(tauntPrefix + " A random hider will be taunted in the next 30s"); tauntPlayer = taunted.getName(); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { public void run() { @@ -86,7 +87,7 @@ public class Taunt { .withTrail() .build()); fw.setFireworkMeta(fwm); - Bukkit.getServer().broadcastMessage(tauntPrefix + " Taunt has been activated"); + Functions.broadcastMessage(tauntPrefix + " Taunt has been activated"); } tauntPlayer = ""; waitTaunt(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java index 5e64381..04bddfb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java @@ -5,6 +5,7 @@ import org.bukkit.World; import org.bukkit.WorldBorder; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.Functions; import static net.tylermurphy.hideAndSeek.Store.*; @@ -27,7 +28,7 @@ public class Worldborder { private void decreaceWorldborder() { if(temp != gameId) return; if(currentWorldborderSize-100 > 100) { - Bukkit.getServer().broadcastMessage(worldborderPrefix + "Worldborder decreacing by 100 blocks over the next 30s"); + Functions.broadcastMessage(worldborderPrefix + "Worldborder decreacing by 100 blocks over the next 30s"); currentWorldborderSize -= 100; World world = Bukkit.getWorld("hideandseek_"+spawnWorld); WorldBorder border = world.getWorldBorder(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java index a41bab3..fd2eeac 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java @@ -160,5 +160,11 @@ public class Functions { public static boolean playerInProtectedWorld(Player p) { return p.getWorld().getName().equals("hideandseek_"+spawnWorld) || p.getWorld().getName().equals(spawnWorld); } + + public static void broadcastMessage(String message) { + for(Player player : playerList.values()) { + player.sendMessage(message); + } + } } \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index edb2235..1feeaf7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -19,10 +19,13 @@ permissions: hideandseek.reload: true hideandseek.setborder: true hideandseek.setspawn: true + hideandseek.setlobby: true hideandseek.start: true hideandseek.stop: true hideandseek.savemap: true hideandseek.blockbypass: true + hideandseek.join: true + hideandseek.leave: true hideandseek.about: description: Allows you to run the about command default: true @@ -38,6 +41,9 @@ permissions: hideandseek.setspawn: description: Allows you to set the game spawn point default: op + hideandseek.setlobby: + description: Allows you to set the game lobby point + default: op hideandseek.start: description: Allows you to start the game default: op @@ -50,3 +56,9 @@ permissions: hideandseek.blockbypass: description: Allows you to bypass the block break prevention default: op + hideandseek.join: + description: Allows you to join the game manual lobby + default: true + hideandseek.leave: + description: Allows you to leave the game manual lobby + default: true