From 9d3cf79879171a1a33fb9d0e3ed8272512589619 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 11 Oct 2021 11:52:56 -0400 Subject: [PATCH] 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