From 9d3cf79879171a1a33fb9d0e3ed8272512589619 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 11 Oct 2021 11:52:56 -0400 Subject: [PATCH 1/5] beta 6 --- .../net/tylermurphy/hideAndSeek/Store.java | 4 ++ .../hideAndSeek/bukkit/EventListener.java | 31 +++++++++-- .../tylermurphy/hideAndSeek/command/Join.java | 51 +++++++++++++++++++ .../hideAndSeek/command/Reload.java | 13 +++++ .../hideAndSeek/command/SaveMap.java | 4 ++ .../hideAndSeek/command/Start.java | 2 +- .../hideAndSeek/util/Functions.java | 4 ++ 7 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Join.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Store.java b/src/main/java/net/tylermurphy/hideAndSeek/Store.java index f7b3905..88bab83 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Store.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Store.java @@ -52,6 +52,8 @@ public class Store { public static boolean nametagsVisible, permissionsRequired, + manualJoin, + lobbyStarted = false, unbreakableArmorstands, unbreakablePaintings, unbreakableItemframes, @@ -102,6 +104,7 @@ public class Store { getConfig().addDefault("prefix.warning", "&cWarning > &f"); getConfig().addDefault("nametagsVisible", false); getConfig().addDefault("permissionsRequired", true); + getConfig().addDefault("manualJoin", true); getConfig().addDefault("blockSettings.unbreakable.painting", false); getConfig().addDefault("blockSettings.unbreakable.armorstand", false); getConfig().addDefault("blockSettings.unbreakable.itemframe", false); @@ -147,6 +150,7 @@ public class Store { //Other nametagsVisible = getConfig().getBoolean("nametagsVisible"); permissionsRequired = getConfig().getBoolean("permissionsRequired"); + manualJoin = getConfig().getBoolean("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/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index c46dc87..61b484f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -40,6 +40,7 @@ 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; 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."); @@ -50,6 +51,12 @@ 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(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld)){ + event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + return; + } + } Hider.add(event.getPlayer().getName()); HiderTeam.addEntry(event.getPlayer().getName()); event.getPlayer().setGameMode(GameMode.ADVENTURE); @@ -85,6 +92,7 @@ public class EventListener implements Listener { @EventHandler public void onEntityDamage(EntityDamageEvent event) { if(event.getEntity() instanceof Player) { + if(!Functions.playerInProtectedWorld((Player) event.getEntity())) return; if(!status.equals("Playing")) { event.setCancelled(true); return; @@ -119,6 +127,7 @@ public class EventListener implements Listener { if(event.getEntity() instanceof ArmorStand) { if(unbreakableArmorstands) { if(event.getDamager() instanceof Player) { + if(!Functions.playerInProtectedWorld((Player) event.getDamager())) return; Player player = (Player) event.getDamager(); if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) { System.out.println('t'); @@ -133,6 +142,7 @@ public class EventListener implements Listener { @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if(!Functions.playerInProtectedWorld((Player) event.getPlayer())) return; if(!interactableArmorstands) { if(event.getRightClicked() instanceof ArmorStand) { if(status.equals("Playing") || status.equals("Starting") || !event.getPlayer().hasPermission("hideandseek.blockbypass")) { @@ -141,6 +151,7 @@ public class EventListener implements Listener { } } if(!interactableItemframes) { + if(!Functions.playerInProtectedWorld((Player) event.getPlayer())) return; if(event.getRightClicked() instanceof ItemFrame) { if(status.equals("Playing") || status.equals("Starting") || !event.getPlayer().hasPermission("hideandseek.blockbypass")) { event.setCancelled(true); @@ -151,6 +162,7 @@ public class EventListener implements Listener { @EventHandler public void onPlayerInteractBlock(PlayerInteractEvent event) { + if(!Functions.playerInProtectedWorld((Player) event.getPlayer())) return; if(!interactableDoors) { if( event.getClickedBlock().getType() == Material.ACACIA_DOOR || @@ -208,6 +220,7 @@ public class EventListener implements Listener { if(event.getEntity() instanceof ItemFrame) { if(unbreakableItemframes) { if(event.getRemover() instanceof Player) { + if(!Functions.playerInProtectedWorld((Player) event.getRemover())) return; Player player = (Player) event.getRemover(); if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) { event.setCancelled(true); @@ -221,6 +234,7 @@ public class EventListener implements Listener { if(event.getEntity() instanceof Painting) { if(unbreakableArmorstands) { if(event.getRemover() instanceof Player) { + if(!Functions.playerInProtectedWorld((Player) event.getRemover())) return; Player player = (Player) event.getRemover(); if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) { event.setCancelled(true); @@ -238,6 +252,7 @@ public class EventListener implements Listener { if(event.getEntity() instanceof Snowball) { Snowball snowball = (Snowball) event.getEntity(); if(snowball.getShooter() instanceof Player) { + if(!Functions.playerInProtectedWorld((Player) snowball.getShooter())) return; Player player = (Player) snowball.getShooter(); if(Hider.contains(player.getName())) { Main.glow.onProjectilve(); @@ -250,18 +265,28 @@ public class EventListener implements Listener { @EventHandler public void onFoodLevelChange(FoodLevelChangeEvent event) { - event.setCancelled(true); + if(event.getEntity() instanceof Player) { + if(playerList.containsKey(event.getEntity().getName())) { + event.setCancelled(true); + } + } } @EventHandler public void onPlayerRegainHealth(EntityRegainHealthEvent event) { - if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) - event.setCancelled(true); + if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) { + if(event.getEntity() instanceof Player) { + if(playerList.containsKey(event.getEntity().getName())) { + event.setCancelled(true); + } + } + } } @EventHandler public void onPlayerCommandPreProccess(PlayerCommandPreprocessEvent event) { if(status.equals("Setup") || status.equals("Standby")) return; + if(!playerList.containsKey(event.getPlayer().getName())) return; String handle = event.getMessage().split(" ")[0].substring(1); for(String blocked : blockedCommands) { if(handle.equalsIgnoreCase(blocked) || handle.equalsIgnoreCase("minecraft:"+blocked)) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java new file mode 100644 index 0000000..88e650d --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -0,0 +1,51 @@ +package net.tylermurphy.hideAndSeek.command; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import net.tylermurphy.hideAndSeek.util.ICommand; + +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"); + 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; + } + playerList.put(player.getName(), player); + Hider.add(player.getName()); + HiderTeam.addEntry(player.getName()); + player.teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the game lobby"); + } + + public String getLabel() { + return null; + } + + public String getUsage() { + return null; + } + + public String getDescription() { + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 1b1f1d5..9771c2f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -1,6 +1,8 @@ package net.tylermurphy.hideAndSeek.command; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import net.tylermurphy.hideAndSeek.Store; import net.tylermurphy.hideAndSeek.util.Functions; @@ -8,14 +10,25 @@ import net.tylermurphy.hideAndSeek.util.ICommand; import static net.tylermurphy.hideAndSeek.Store.*; +import java.util.HashMap; + public class Reload implements ICommand { public void execute(CommandSender sender, String[] args) { + if(!status.equals("Standby")) { + sender.sendMessage(errorPrefix + "Game is currently in session"); + return; + } Store.loadConfig(); try { Functions.loadScoreboard(); } catch(Exception e) {} sender.sendMessage(messagePrefix + "Reloaded the config"); + playerList = new HashMap(); + if(!manualJoin) { + for(Player p : Bukkit.getOnlinePlayers()) + playerList.put(p.getName(), p); + } } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java index 2956c80..2c7e75a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -21,6 +21,10 @@ import net.tylermurphy.hideAndSeek.util.ICommand; public class SaveMap implements ICommand { public void execute(CommandSender sender, String[] args) { + if(!status.equals("Standby")) { + sender.sendMessage(errorPrefix + "Game is currently in session"); + return; + } if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) { sender.sendMessage(errorPrefix + "Please set spawn location first"); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index a49ce41..f5f2148 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -69,7 +69,7 @@ public class Start implements ICommand { } Seeker.add(seeker.getName()); SeekerTeam.addEntry(seeker.getName()); - + currentWorldborderSize = worldborderSize; for(Player player : playerList.values()) { player.getInventory().clear(); player.setGameMode(GameMode.ADVENTURE); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java index 55ff03a..a41bab3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java @@ -156,5 +156,9 @@ public class Functions { board = mainBoard; } + + public static boolean playerInProtectedWorld(Player p) { + return p.getWorld().getName().equals("hideandseek_"+spawnWorld) || p.getWorld().getName().equals(spawnWorld); + } } \ No newline at end of file From 55e15245e631edda2d7e9146b5229df4f8043dba Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 11 Oct 2021 17:06:21 -0400 Subject: [PATCH 2/5] 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 From 62a4da3e66423c7684615084bef1fc8eed7b02b5 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 11 Oct 2021 17:13:25 -0400 Subject: [PATCH 3/5] fix typo --- src/main/java/net/tylermurphy/hideAndSeek/Store.java | 1 - src/main/java/net/tylermurphy/hideAndSeek/command/Join.java | 2 +- src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Store.java b/src/main/java/net/tylermurphy/hideAndSeek/Store.java index c6f48eb..9aa07e0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Store.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Store.java @@ -111,7 +111,6 @@ public class Store { getConfig().addDefault("nametagsVisible", false); getConfig().addDefault("permissionsRequired", 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); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 4b0baa3..6dffe60 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -13,7 +13,7 @@ public class Join implements ICommand { public void execute(CommandSender sender, String[] args) { if(!lobbyManualJoin) { - sender.sendMessage(errorPrefix + "Manual join/leave isnt set to manual in this server"); + sender.sendMessage(errorPrefix + "Manual join/leave isnt enabled in this server"); return; } if(!status.equals("Standby")) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index bde14da..5015516 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -12,7 +12,7 @@ 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"); + sender.sendMessage(errorPrefix + "Manual join/leave isnt enabled in this server"); return; } if(!status.equals("Standby")) { From 761550ac89a847d49c89c47568e3c40306110466 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 11 Oct 2021 17:18:37 -0400 Subject: [PATCH 4/5] fixed possible exception on player join --- src/main/java/net/tylermurphy/hideAndSeek/Store.java | 7 ++++--- .../net/tylermurphy/hideAndSeek/bukkit/EventListener.java | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Store.java b/src/main/java/net/tylermurphy/hideAndSeek/Store.java index 9aa07e0..ec64323 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Store.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Store.java @@ -1,5 +1,6 @@ package net.tylermurphy.hideAndSeek; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -23,9 +24,9 @@ public class Store { playerLastLocationList = new HashMap(); public static List - Hider, - Seeker, - Spectator; + Hider = new ArrayList(), + Seeker = new ArrayList(), + Spectator = new ArrayList(); public static Scoreboard board; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index 5cf83a1..40167c4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -58,14 +58,18 @@ public class EventListener implements Listener { } else if(status.equals("Setup") || status.equals("Standby")) { if (lobbyManualJoin) { if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld)){ - event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); + if(lobbyPosition.getBlockX() != 0 || lobbyPosition.getBlockY() != 0 || lobbyPosition.getBlockZ() != 0) { + 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), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); + if(lobbyPosition.getBlockX() != 0 || lobbyPosition.getBlockY() != 0 || lobbyPosition.getBlockZ() != 0) { + event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); + } } playerList.put(event.getPlayer().getName(), event.getPlayer()); } From d37ad3fc4500cf4d35db718bdaf964bad03840e4 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 17 Oct 2021 22:52:57 -0400 Subject: [PATCH 5/5] lobby bug fixes, titles, game time --- .../net/tylermurphy/hideAndSeek/Main.java | 6 - .../net/tylermurphy/hideAndSeek/Store.java | 99 +++----- .../hideAndSeek/bukkit/CommandHandler.java | 2 + .../hideAndSeek/bukkit/EventListener.java | 239 ++++-------------- .../tylermurphy/hideAndSeek/bukkit/Tick.java | 46 ++-- .../tylermurphy/hideAndSeek/command/Join.java | 39 +-- .../hideAndSeek/command/Leave.java | 21 +- .../hideAndSeek/command/Reload.java | 5 - .../hideAndSeek/command/SetExitLocation.java | 49 ++++ .../hideAndSeek/command/SetLobbyLocation.java | 3 +- .../hideAndSeek/command/SetSpawnLocation.java | 2 +- .../hideAndSeek/command/Setup.java | 57 +++++ .../hideAndSeek/command/Start.java | 40 +-- .../tylermurphy/hideAndSeek/command/Stop.java | 11 +- .../hideAndSeek/util/Functions.java | 24 +- .../tylermurphy/hideAndSeek/util/Packet.java | 2 +- 16 files changed, 315 insertions(+), 330 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index de6b043..67c9d16 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -1,7 +1,5 @@ package net.tylermurphy.hideAndSeek; -import static net.tylermurphy.hideAndSeek.Store.*; - import java.io.File; import java.util.List; @@ -9,7 +7,6 @@ import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; @@ -39,9 +36,6 @@ public class Main extends JavaPlugin implements Listener { // Setup Initial Player Count getServer().getPluginManager().registerEvents(new EventListener(), this); - for (Player player : Bukkit.getServer().getOnlinePlayers()) { - playerList.put(player.getName(), player); - } // Init Configuration Store.loadConfig(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Store.java b/src/main/java/net/tylermurphy/hideAndSeek/Store.java index ec64323..537ad7b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Store.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Store.java @@ -1,13 +1,11 @@ package net.tylermurphy.hideAndSeek; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; 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; @@ -20,13 +18,11 @@ public class Store { public static Map playerList = new HashMap(); - public static Map - playerLastLocationList = new HashMap(); - public static List Hider = new ArrayList(), Seeker = new ArrayList(), - Spectator = new ArrayList(); + Spectator = new ArrayList(), + Deaths = new ArrayList(); public static Scoreboard board; @@ -45,30 +41,21 @@ public class Store { gameoverPrefix, warningPrefix, spawnWorld, + exitWorld, + lobbyWorld, status = "Standby"; - public static Vector + public static Vector spawnPosition, lobbyPosition, + exitPosition, worldborderPosition; - public static List - blockedCommands; - public static boolean nametagsVisible, permissionsRequired, - lobbyManualJoin, - lobbyAnnounced, + announceMessagesToNonPlayers, lobbyStarted = false, - unbreakableArmorstands, - unbreakablePaintings, - unbreakableItemframes, - interactableArmorstands, - interactableItemframes, - interactableDoors, - interactableTrapdoors, - interactableFencegate, worldborderEnabled = false, runningBackup = false; @@ -77,7 +64,9 @@ public class Store { gameId = 0, worldborderSize, worldborderDelay, - currentWorldborderSize; + currentWorldborderSize, + gameLength, + timeLeft = 0; public static FileConfiguration getConfig() { return Main.plugin.getConfig(); @@ -92,16 +81,11 @@ public class Store { Main.plugin.reloadConfig(); //Default - getConfig().addDefault("spawn.x", 0); - getConfig().addDefault("spawn.y", 0); - getConfig().addDefault("spawn.z", 0); - getConfig().addDefault("spawn.world", "world"); getConfig().addDefault("worldBorder.x", 0); getConfig().addDefault("worldBorder.z", 0); getConfig().addDefault("worldBorder.delay", 10); getConfig().addDefault("worldBorder.size", 500); getConfig().addDefault("worldBorder.enabled", false); - getConfig().addDefault("blockedCommands", Arrays.asList("whisper","msg")); getConfig().addDefault("prefix.default", "&9Hide and Seek > &f"); getConfig().addDefault("prefix.error", "&cError > &f"); getConfig().addDefault("prefix.taunt", "&eTaunt > &f"); @@ -111,35 +95,46 @@ public class Store { getConfig().addDefault("prefix.warning", "&cWarning > &f"); getConfig().addDefault("nametagsVisible", false); getConfig().addDefault("permissionsRequired", true); - getConfig().addDefault("lobby.manualJoin", false); - 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); - getConfig().addDefault("blockSettings.interactable.armorstand", true); - getConfig().addDefault("blockSettings.interactable.itemframe", true); - getConfig().addDefault("blockSettings.interactable.door", true); - getConfig().addDefault("blockSettings.interactable.trapdoor", true); - getConfig().addDefault("blockSettings.interactable.fence", true); + getConfig().addDefault("announceMessagesToNonPlayers", false); + getConfig().addDefault("spawns.lobby.x", 0); + getConfig().addDefault("spawns.lobby.y", 0); + getConfig().addDefault("spawns.lobby.z", 0); + getConfig().addDefault("spawns.lobby.world", "world"); + getConfig().addDefault("spawns.exit.x", 0); + getConfig().addDefault("spawns.exit.y", 0); + getConfig().addDefault("spawns.exit.z", 0); + getConfig().addDefault("spawns.exit.world", "world"); + getConfig().addDefault("spawns.game.x", 0); + getConfig().addDefault("spawns.game.y", 0); + getConfig().addDefault("spawns.game.z", 0); + getConfig().addDefault("spawns.game.world", "world"); getConfig().addDefault("minPlayers", 2); + getConfig().addDefault("gameLength", 600); //Spawn spawnPosition = new Vector( - getConfig().getDouble("spawn.x"), - Math.max(0,Math.min(255,getConfig().getDouble("spawn.y"))), - getConfig().getDouble("spawn.z") + getConfig().getDouble("spawns.game.x"), + Math.max(0,Math.min(255,getConfig().getDouble("spawns.game.y"))), + getConfig().getDouble("spawns.game.z") ); - spawnWorld = getConfig().getString("spawn.world"); + spawnWorld = getConfig().getString("spawns.game.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") + getConfig().getDouble("spawns.lobby.x"), + Math.max(0,Math.min(255,getConfig().getDouble("spawns.lobby.y"))), + getConfig().getDouble("spawns.lobby.z") ); + lobbyWorld = getConfig().getString("spawns.lobby.world"); + + announceMessagesToNonPlayers = getConfig().getBoolean("announceMessagesToNonPlayers"); + + exitPosition = new Vector( + getConfig().getDouble("spawns.exit.x"), + Math.max(0,Math.min(255,getConfig().getDouble("spawns.exit.y"))), + getConfig().getDouble("spawns.exit.z") + ); + exitWorld = getConfig().getString("spawns.exit.world"); //World border worldborderPosition = new Vector( @@ -150,8 +145,6 @@ public class Store { worldborderSize = Math.max(100,getConfig().getInt("worldBorder.size")); worldborderDelay = Math.max(1,getConfig().getInt("worldBorder.delay")); worldborderEnabled = getConfig().getBoolean("worldBorder.enabled"); - blockedCommands = getConfig().getStringList("blockedCommands"); - blockedCommands.add("team"); //Prefix char SYMBOLE = '\u00A7'; @@ -168,16 +161,8 @@ public class Store { //Other nametagsVisible = getConfig().getBoolean("nametagsVisible"); permissionsRequired = getConfig().getBoolean("permissionsRequired"); - lobbyManualJoin = getConfig().getBoolean("lobby.manualJoin"); - unbreakablePaintings = getConfig().getBoolean("blockSettings.unbreakable.painting"); - unbreakableArmorstands = getConfig().getBoolean("blockSettings.unbreakable.armorstand"); - unbreakableItemframes = getConfig().getBoolean("blockSettings.unbreakable.itemframe"); - interactableArmorstands = getConfig().getBoolean("blockSettings.interactable.armorstand"); - interactableItemframes = getConfig().getBoolean("blockSettings.interactable.itemframe"); - interactableDoors = getConfig().getBoolean("blockSettings.interactable.door"); - interactableTrapdoors = getConfig().getBoolean("blockSettings.interactable.trapdoor"); - interactableFencegate = getConfig().getBoolean("blockSettings.interactable.fence"); minPlayers = Math.max(2,getConfig().getInt("minPlayers")); + gameLength = getConfig().getInt("gameLength"); getConfig().options().copyDefaults(true); saveConfig(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java index f688881..f15e68b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java @@ -26,10 +26,12 @@ public class CommandHandler { public static void registerCommands() { registerCommand(new About()); registerCommand(new Help()); + registerCommand(new Setup()); registerCommand(new Start()); registerCommand(new Stop()); registerCommand(new SetSpawnLocation()); registerCommand(new SetLobbyLocation()); + registerCommand(new SetExitLocation()); registerCommand(new SetBorder()); registerCommand(new Reload()); registerCommand(new SaveMap()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index 40167c4..1136ea4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -8,9 +8,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.attribute.Attribute; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.ItemFrame; -import org.bukkit.entity.Painting; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Snowball; import org.bukkit.event.EventHandler; @@ -21,10 +19,6 @@ import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; -import org.bukkit.event.hanging.HangingBreakByEntityEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -39,39 +33,33 @@ public class EventListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { + event.getPlayer().setLevel(0); + if(!Functions.setup()) return; + HiderTeam.removeEntry(event.getPlayer().getName()); + SeekerTeam.removeEntry(event.getPlayer().getName()); + SpectatorTeam.removeEntry(event.getPlayer().getName()); if(status.equals("Playing") || status.equals("Starting")) { - 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."); - event.getPlayer().setGameMode(GameMode.SPECTATOR); - event.getPlayer().getInventory().clear(); - for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ - event.getPlayer().removePotionEffect(effect.getType()); - } - event.getPlayer().teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); - } else if(status.equals("Setup") || status.equals("Standby")) { - if (lobbyManualJoin) { - if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld)){ - if(lobbyPosition.getBlockX() != 0 || lobbyPosition.getBlockY() != 0 || lobbyPosition.getBlockZ() != 0) { - event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); - } - return; + if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld)) { + 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."); + event.getPlayer().setGameMode(GameMode.SPECTATOR); + event.getPlayer().getInventory().clear(); + for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ + event.getPlayer().removePotionEffect(effect.getType()); } + event.getPlayer().teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); } - Hider.add(event.getPlayer().getName()); - HiderTeam.addEntry(event.getPlayer().getName()); - event.getPlayer().setGameMode(GameMode.ADVENTURE); - if(lobbyPosition.getBlockX() != 0 || lobbyPosition.getBlockY() != 0 || lobbyPosition.getBlockZ() != 0) { - event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); + if(event.getPlayer().getWorld().getName().equals(spawnWorld)) { + event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + event.getPlayer().setGameMode(GameMode.ADVENTURE); + } + } else if(status.equals("Setup") || status.equals("Standby")) { + if(Functions.playerInProtectedWorld(event.getPlayer())){ + event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + event.getPlayer().setGameMode(GameMode.ADVENTURE); } } - playerList.put(event.getPlayer().getName(), event.getPlayer()); } @EventHandler @@ -101,11 +89,22 @@ public class EventListener implements Listener { @EventHandler public void onEntityDamage(EntityDamageEvent event) { if(event.getEntity() instanceof Player) { - if(!Functions.playerInProtectedWorld((Player) event.getEntity())) return; + Player p = (Player) event.getEntity(); + if(!playerList.containsKey(p.getName())) return; if(!status.equals("Playing")) { event.setCancelled(true); return; } + Player attacker = null; + if(event instanceof EntityDamageByEntityEvent) { + Entity damager = ((EntityDamageByEntityEvent)event).getDamager(); + if(damager instanceof Player) { + attacker = (Player) damager; + if(Hider.contains(attacker.getName()) && Hider.contains(p.getName())) event.setCancelled(true); + if(Seeker.contains(attacker.getName()) && Seeker.contains(p.getName())) event.setCancelled(true); + if(Spectator.contains(attacker.getName())) event.setCancelled(true); + } + } Player player = (Player) event.getEntity(); if(player.getHealth()-event.getDamage() < 0) { if(spawnPosition == null) return; @@ -113,144 +112,20 @@ public class EventListener implements Listener { player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1); - if(Hider.contains(event.getEntity().getName())) { - Bukkit.broadcastMessage(String.format(messagePrefix + "%s%s%s was found and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE)); - } if(Seeker.contains(event.getEntity().getName())) { Bukkit.broadcastMessage(String.format(messagePrefix + "%s%s%s was killed", ChatColor.RED, event.getEntity().getName(), ChatColor.WHITE)); } - Seeker.add(player.getName()); - Hider.remove(player.getName()); - SeekerTeam.addEntry(player.getName()); + if(Hider.contains(event.getEntity().getName())) { + if(attacker == null) { + Functions.broadcastMessage(String.format(messagePrefix + "%s%s%s was found and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE)); + } else { + Functions.broadcastMessage(String.format(messagePrefix + "%s%s%s was found by %s%s%s and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE, ChatColor.RED, attacker.getName(), ChatColor.WHITE)); + } + Hider.remove(player.getName()); + Seeker.add(player.getName()); + SeekerTeam.addEntry(player.getName()); + } Functions.resetPlayer(player); - for(Player temp : playerList.values()) { - Packet.setGlow(player, temp, false); - } - } - } - - } - - @EventHandler - public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { - if(event.getEntity() instanceof ArmorStand) { - if(unbreakableArmorstands) { - if(event.getDamager() instanceof Player) { - if(!Functions.playerInProtectedWorld((Player) event.getDamager())) return; - Player player = (Player) event.getDamager(); - if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) { - System.out.println('t'); - event.setCancelled(true); - } - } else { - event.setCancelled(true); - } - } - } - } - - @EventHandler - public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { - if(!Functions.playerInProtectedWorld((Player) event.getPlayer())) return; - if(!interactableArmorstands) { - if(event.getRightClicked() instanceof ArmorStand) { - if(status.equals("Playing") || status.equals("Starting") || !event.getPlayer().hasPermission("hideandseek.blockbypass")) { - event.setCancelled(true); - } - } - } - if(!interactableItemframes) { - if(!Functions.playerInProtectedWorld((Player) event.getPlayer())) return; - if(event.getRightClicked() instanceof ItemFrame) { - if(status.equals("Playing") || status.equals("Starting") || !event.getPlayer().hasPermission("hideandseek.blockbypass")) { - event.setCancelled(true); - } - } - } - } - - @EventHandler - public void onPlayerInteractBlock(PlayerInteractEvent event) { - if(!Functions.playerInProtectedWorld((Player) event.getPlayer())) return; - if(!interactableDoors) { - if( - event.getClickedBlock().getType() == Material.ACACIA_DOOR || - event.getClickedBlock().getType() == Material.BIRCH_DOOR || - event.getClickedBlock().getType() == Material.CRIMSON_DOOR || - event.getClickedBlock().getType() == Material.DARK_OAK_DOOR || - event.getClickedBlock().getType() == Material.IRON_DOOR || - event.getClickedBlock().getType() == Material.JUNGLE_DOOR || - event.getClickedBlock().getType() == Material.OAK_DOOR || - event.getClickedBlock().getType() == Material.SPRUCE_DOOR || - event.getClickedBlock().getType() == Material.WARPED_DOOR - ) { - if(status.equals("Playing") || status.equals("Starting") || !event.getPlayer().hasPermission("hideandseek.blockbypass")) { - event.setCancelled(true); - } - } - } - if(!interactableTrapdoors) { - if( - event.getClickedBlock().getType() == Material.ACACIA_TRAPDOOR || - event.getClickedBlock().getType() == Material.BIRCH_TRAPDOOR || - event.getClickedBlock().getType() == Material.CRIMSON_TRAPDOOR || - event.getClickedBlock().getType() == Material.DARK_OAK_TRAPDOOR || - event.getClickedBlock().getType() == Material.IRON_TRAPDOOR || - event.getClickedBlock().getType() == Material.JUNGLE_TRAPDOOR || - event.getClickedBlock().getType() == Material.OAK_TRAPDOOR || - event.getClickedBlock().getType() == Material.SPRUCE_TRAPDOOR || - event.getClickedBlock().getType() == Material.WARPED_TRAPDOOR - ) { - if(status.equals("Playing") || status.equals("Starting") || !event.getPlayer().hasPermission("hideandseek.blockbypass")) { - event.setCancelled(true); - } - } - } - if(!interactableFencegate) { - if( - event.getClickedBlock().getType() == Material.ACACIA_FENCE_GATE || - event.getClickedBlock().getType() == Material.BIRCH_FENCE_GATE || - event.getClickedBlock().getType() == Material.CRIMSON_FENCE_GATE || - event.getClickedBlock().getType() == Material.DARK_OAK_FENCE_GATE || - event.getClickedBlock().getType() == Material.JUNGLE_FENCE_GATE || - event.getClickedBlock().getType() == Material.OAK_FENCE_GATE || - event.getClickedBlock().getType() == Material.SPRUCE_FENCE_GATE || - event.getClickedBlock().getType() == Material.WARPED_FENCE_GATE - ) { - if(status.equals("Playing") || status.equals("Starting") || !event.getPlayer().hasPermission("hideandseek.blockbypass")) { - event.setCancelled(true); - } - } - } - } - - @EventHandler - public void onHangingBreakByEntity(HangingBreakByEntityEvent event) { - if(event.getEntity() instanceof ItemFrame) { - if(unbreakableItemframes) { - if(event.getRemover() instanceof Player) { - if(!Functions.playerInProtectedWorld((Player) event.getRemover())) return; - Player player = (Player) event.getRemover(); - if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) { - event.setCancelled(true); - } - } else { - event.setCancelled(true); - } - - } - } - if(event.getEntity() instanceof Painting) { - if(unbreakableArmorstands) { - if(event.getRemover() instanceof Player) { - if(!Functions.playerInProtectedWorld((Player) event.getRemover())) return; - Player player = (Player) event.getRemover(); - if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) { - event.setCancelled(true); - } - } else { - event.setCancelled(true); - } } } } @@ -275,9 +150,8 @@ public class EventListener implements Listener { @EventHandler public void onFoodLevelChange(FoodLevelChangeEvent event) { if(event.getEntity() instanceof Player) { - if(playerList.containsKey(event.getEntity().getName())) { - event.setCancelled(true); - } + if(!playerList.containsKey(event.getEntity().getName())) return; + event.setCancelled(true); } } @@ -285,24 +159,9 @@ public class EventListener implements Listener { public void onPlayerRegainHealth(EntityRegainHealthEvent event) { if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) { if(event.getEntity() instanceof Player) { - if(playerList.containsKey(event.getEntity().getName())) { - event.setCancelled(true); - } + if(!playerList.containsKey(event.getEntity().getName())) return; + event.setCancelled(true); } } } - - @EventHandler - public void onPlayerCommandPreProccess(PlayerCommandPreprocessEvent event) { - if(status.equals("Setup") || status.equals("Standby")) return; - if(!playerList.containsKey(event.getPlayer().getName())) return; - String handle = event.getMessage().split(" ")[0].substring(1); - for(String blocked : blockedCommands) { - if(handle.equalsIgnoreCase(blocked) || handle.equalsIgnoreCase("minecraft:"+blocked)) { - event.setCancelled(true); - event.getPlayer().sendMessage(errorPrefix + "This command is blocked during gameplay!"); - break; - } - } - } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java index eccaf39..7224210 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java @@ -2,9 +2,7 @@ package net.tylermurphy.hideAndSeek.bukkit; import static net.tylermurphy.hideAndSeek.Store.*; - import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -22,34 +20,31 @@ public class Tick { Functions.loadScoreboard(); } - if(status.equals("Starting")) { - onStarting(); - } else if(status.equals("Playing")) { + if(status.equals("Standby")) { + tick = 0; + } + + if(status.equals("Playing")) { onPlaying(); } - tick ++; - if(( status.equals("Starting") || status.equals("Playing") ) && Hider.size() < 1) { - Bukkit.broadcastMessage(gameoverPrefix + "All hiders have been found."); + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + "All hiders have been found."); + else Functions.broadcastMessage(gameoverPrefix + "All hiders have been found."); Stop.onStop(); } if(( status.equals("Starting") || status.equals("Playing") ) && Seeker.size() < 1) { - Bukkit.broadcastMessage(abortPrefix + "All seekers have quit."); + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + "All seekers have quit."); + else Functions.broadcastMessage(abortPrefix + "All seekers have quit."); Stop.onStop(); } - } - - private static void onStarting() { - for(String playerName : Seeker) { - Player player = playerList.get(playerName); - if(player != null) { - player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); - } - } + } private static void onPlaying() { + + tick ++; + for(String playerName : Hider) { Player player = playerList.get(playerName); int distance = 100; @@ -76,6 +71,21 @@ public class Tick { if(distance < 20) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); break; } + + } + + if(tick%20 == 0) { + if(gameLength > 0) { + timeLeft--; + for(Player player : playerList.values()) { + player.setLevel(timeLeft); + } + if(timeLeft < 1) { + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + "Seekers ran out of time. Hiders win!"); + else Functions.broadcastMessage(gameoverPrefix + "Seekers ran out of time. Hiders win!"); + Stop.onStop(); + } + } } } } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 6dffe60..5168e25 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -1,10 +1,13 @@ package net.tylermurphy.hideAndSeek.command; import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.attribute.Attribute; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import net.tylermurphy.hideAndSeek.util.Functions; import net.tylermurphy.hideAndSeek.util.ICommand; import static net.tylermurphy.hideAndSeek.Store.*; @@ -12,16 +15,8 @@ import static net.tylermurphy.hideAndSeek.Store.*; public class Join implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!lobbyManualJoin) { - sender.sendMessage(errorPrefix + "Manual join/leave isnt enabled 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"); + if(!Functions.setup()) { + sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } Player player = Bukkit.getServer().getPlayer(sender.getName()); @@ -30,15 +25,27 @@ public class Join implements ICommand { return; } if(playerList.containsKey(player.getName())){ - sender.sendMessage(errorPrefix + "You are already in the lobby"); + sender.sendMessage(errorPrefix + "You are already in the lobby/game"); 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())); - if(lobbyAnnounced) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby"); + if(status.equals("Standby")) { + Hider.add(player.getName()); + HiderTeam.addEntry(player.getName()); + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby"); + else Functions.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby"); + player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); + player.setGameMode(GameMode.ADVENTURE); + } else { + Spectator.add(player.getName()); + SpectatorTeam.addEntry(player.getName()); + player.sendMessage(messagePrefix + "You have joined mid game and became a spectator"); + player.setGameMode(GameMode.SPECTATOR); + player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + } + + player.setFoodLevel(20); + player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue()); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index 5015516..4dec452 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -1,9 +1,11 @@ package net.tylermurphy.hideAndSeek.command; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import net.tylermurphy.hideAndSeek.util.Functions; import net.tylermurphy.hideAndSeek.util.ICommand; import static net.tylermurphy.hideAndSeek.Store.*; @@ -11,16 +13,8 @@ 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 enabled 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"); + if(!Functions.setup()) { + sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } Player player = Bukkit.getServer().getPlayer(sender.getName()); @@ -32,13 +26,16 @@ public class Leave implements ICommand { sender.sendMessage(errorPrefix + "You are currently not in the lobby"); return; } + if(!Seeker.contains(player.getName())) { + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has left the HideAndSeek lobby"); + else Functions.broadcastMessage(messagePrefix + sender.getName() + " has left the HideAndSeek lobby"); + } 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"); + player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index d333f6c..438ab26 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -1,6 +1,5 @@ package net.tylermurphy.hideAndSeek.command; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -25,10 +24,6 @@ public class Reload implements ICommand { } catch(Exception e) {} sender.sendMessage(messagePrefix + "Reloaded the config"); playerList = new HashMap(); - if(!lobbyManualJoin) { - for(Player p : Bukkit.getOnlinePlayers()) - playerList.put(p.getName(), p); - } } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java new file mode 100644 index 0000000..3f872a1 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -0,0 +1,49 @@ +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 SetExitLocation implements ICommand { + + public void execute(CommandSender sender, String[] args) { + Vector newExitPosition = new Vector(); + Player player = (Player) sender; + newExitPosition.setX(player.getLocation().getBlockX()); + newExitPosition.setY(player.getLocation().getBlockY()); + newExitPosition.setZ(player.getLocation().getBlockZ()); + if(!status.equals("Standby")) { + sender.sendMessage(errorPrefix + "Game is currently in session"); + return; + } + exitPosition = newExitPosition; + sender.sendMessage(messagePrefix + "Set exit position to current location"); + Map temp = new HashMap(); + temp.put("x", exitPosition.getX()); + temp.put("y", exitPosition.getY()); + temp.put("z", exitPosition.getZ()); + temp.put("world", player.getLocation().getWorld().getName()); + addToSection("spawns.exit",temp); + saveConfig(); + } + + public String getLabel() { + return "setexit"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks exit location to current position and world"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java index 299a227..7cb13fc 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java @@ -29,7 +29,8 @@ public class SetLobbyLocation implements ICommand { temp.put("x", lobbyPosition.getX()); temp.put("y", lobbyPosition.getY()); temp.put("z", lobbyPosition.getZ()); - addToSection("lobby.spawn",temp); + temp.put("world", player.getLocation().getWorld().getName()); + addToSection("spawns.lobby",temp); saveConfig(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java index 62d6bc9..0114e21 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java @@ -34,7 +34,7 @@ public class SetSpawnLocation implements ICommand { temp.put("y", spawnPosition.getY()); temp.put("z", spawnPosition.getZ()); temp.put("world", player.getLocation().getWorld().getName()); - addToSection("spawn",temp); + addToSection("spawns.game",temp); saveConfig(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java new file mode 100644 index 0000000..f071bee --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -0,0 +1,57 @@ +package net.tylermurphy.hideAndSeek.command; + +import org.bukkit.command.CommandSender; + +import net.md_5.bungee.api.ChatColor; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.ICommand; + +import static net.tylermurphy.hideAndSeek.Store.*; + +import java.io.File; + +public class Setup implements ICommand { + + public void execute(CommandSender sender, String[] args) { + + String message = String.format("%s%sThe following is needed for setup...", ChatColor.WHITE, ChatColor.BOLD); + int count = 0; + + if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) { + message = String.format("%s\n%s%s-%s%s", message, ChatColor.RED, ChatColor.BOLD, ChatColor.WHITE, "Game spawn isnt set, /hs setspawn"); + count++; + } + if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) { + message = String.format("%s\n%s%s-%s%s", message, ChatColor.RED, ChatColor.BOLD, ChatColor.WHITE, "Lobby spawn isnt set, /hs setlobby"); + sender.sendMessage(errorPrefix + "Please set lobby location first"); + count++; + } + if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) { + message = String.format("%s\n%s%s-%s%s", message, ChatColor.RED, ChatColor.BOLD, ChatColor.WHITE, "Quit/exit teleport location isnt set, /hs setexit"); + count++; + } + File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); + if(!destenation.exists()) { + message = String.format("%s\n%s%s-%s%s", message, ChatColor.RED, ChatColor.BOLD, ChatColor.WHITE, "Hide and seek map isnt saved, /hs savemap (after /hs setspawn)"); + count++; + } + if(count < 1) { + sender.sendMessage(messagePrefix + "Everything is setup and ready to go!"); + } else { + sender.sendMessage(message); + } + } + + public String getLabel() { + return "setup"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Shows what needs to be setup"; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index fb715d6..cd0c956 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -8,6 +8,7 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.events.Glow; import net.tylermurphy.hideAndSeek.events.Taunt; @@ -17,40 +18,33 @@ import net.tylermurphy.hideAndSeek.util.ICommand; import static net.tylermurphy.hideAndSeek.Store.*; -import java.io.File; import java.util.ArrayList; import java.util.Random; public class Start implements ICommand { public void execute(CommandSender sender, String[] args) { + if(!Functions.setup()) { + sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); + return; + } if(!status.equals("Standby")) { sender.sendMessage(errorPrefix + "Game is already in session"); return; } - if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) { - sender.sendMessage(errorPrefix + "Please set spawn location first"); + if(!playerList.containsKey(sender.getName())) { + sender.sendMessage(errorPrefix + "You are not in the lobby"); 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"); - return; - } else { - if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) { - Functions.rollback("hideandseek_"+spawnWorld); - } else { - Functions.loadMap("hideandseek_"+spawnWorld); - } - } if(playerList.size() < minPlayers) { sender.sendMessage(errorPrefix + "You must have at least "+minPlayers+" players to start"); return; } + if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) { + Functions.rollback("hideandseek_"+spawnWorld); + } else { + Functions.loadMap("hideandseek_"+spawnWorld); + } String seekerName; if(args.length < 1) { seekerName = playerList.values().stream().skip(new Random().nextInt(playerList.values().size())).findFirst().get().getName(); @@ -65,6 +59,7 @@ public class Start implements ICommand { Hider = new ArrayList(); Seeker = new ArrayList(); Spectator = new ArrayList(); + Deaths = new ArrayList(); for(Player temp : playerList.values()) { if(temp.getName().equals(seeker.getName())) continue; @@ -87,12 +82,14 @@ public class Start implements ICommand { if(player != null) { player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false)); player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false)); + player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + "Eliminate all hiders", 10, 70, 20); } } for(String playerName : Hider) { Player player = playerList.get(playerName); if(player != null) { player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); + player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + "Hide away from the seekers", 10, 70, 20); } } Functions.resetWorldborder("hideandseek_"+spawnWorld); @@ -163,6 +160,13 @@ public class Start implements ICommand { Main.taunt.schedule(); Main.glow = new Glow(gameId); + + if(gameLength > 0) { + timeLeft = gameLength; + for(Player player : playerList.values()) { + player.setLevel(timeLeft); + } + } } }, 20 * 30); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 2b96809..9c1e3d7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -17,8 +17,13 @@ import net.tylermurphy.hideAndSeek.util.Packet; public class Stop implements ICommand { public void execute(CommandSender sender, String[] args) { + if(!Functions.setup()) { + sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); + return; + } if(status.equals("Starting") || status.equals("Playing")) { - Bukkit.broadcastMessage(abortPrefix + "Game has been force stopped."); + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + "Game has been force stopped."); + else Functions.broadcastMessage(abortPrefix + "Game has been force stopped."); onStop(); } else { @@ -38,10 +43,11 @@ public class Stop implements ICommand { Functions.resetWorldborder("hideandseek_"+spawnWorld); for(Player player : playerList.values()) { player.setGameMode(GameMode.ADVENTURE); + player.setLevel(0); Hider.add(player.getName()); HiderTeam.addEntry(player.getName()); player.getInventory().clear(); - player.teleport(new Location(Bukkit.getWorld(spawnWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); + player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); for(PotionEffect effect : player.getActivePotionEffects()){ player.removePotionEffect(effect.getType()); } @@ -50,6 +56,7 @@ public class Stop implements ICommand { Packet.setGlow(player, temp, false); } } + Functions.unloadMap("hideandseek_"+spawnWorld); } public String getUsage() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java index fd2eeac..149e9ac 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java @@ -2,6 +2,7 @@ package net.tylermurphy.hideAndSeek.util; import static net.tylermurphy.hideAndSeek.Store.*; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -137,7 +138,6 @@ public class Functions { SeekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OTHER_TEAMS); else SeekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - SeekerTeam.setAllowFriendlyFire(false); try { mainBoard.registerNewTeam("Hider");} catch(Exception e) {} HiderTeam = mainBoard.getTeam("Hider"); @@ -146,13 +146,11 @@ public class Functions { HiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM); else HiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - HiderTeam.setAllowFriendlyFire(false); try { mainBoard.registerNewTeam("Spectator");} catch(Exception e) {} SpectatorTeam = mainBoard.getTeam("Spectator"); SpectatorTeam.setColor(ChatColor.GRAY); SpectatorTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - SpectatorTeam.setAllowFriendlyFire(false); board = mainBoard; } @@ -166,5 +164,25 @@ public class Functions { player.sendMessage(message); } } + + public static boolean setup() { + + 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; + } + + return true; + + } } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java index d93116d..564916a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java @@ -52,5 +52,5 @@ public class Packet { e.printStackTrace(); } } - + }