diff --git a/pom.xml b/pom.xml index 544d3bb..7e48a1c 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 net.tylermurphy HideAndSeek - 1.3.2 + 1.3.3 Hide and Seek Plugin @@ -39,5 +39,15 @@ ProtocolLib 4.7.0 + + org.xerial + sqlite-jdbc + 3.36.0.3 + + + org.jetbrains + annotations + 23.0.0 + \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index f92bf15..e486cda 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -1,103 +1,89 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek; -import static net.tylermurphy.hideAndSeek.configuration.Config.spawnWorld; - import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import net.tylermurphy.hideAndSeek.database.Database; +import net.tylermurphy.hideAndSeek.util.UUIDFetcher; 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; -import net.tylermurphy.hideAndSeek.bukkit.CommandHandler; -import net.tylermurphy.hideAndSeek.bukkit.EventListener; -import net.tylermurphy.hideAndSeek.bukkit.TabCompleter; -import net.tylermurphy.hideAndSeek.bukkit.Tick; +import net.tylermurphy.hideAndSeek.game.CommandHandler; +import net.tylermurphy.hideAndSeek.game.EventListener; +import net.tylermurphy.hideAndSeek.util.TabCompleter; +import net.tylermurphy.hideAndSeek.game.Game; import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Localization; import net.tylermurphy.hideAndSeek.configuration.Items; -import net.tylermurphy.hideAndSeek.events.Glow; -import net.tylermurphy.hideAndSeek.events.Taunt; -import net.tylermurphy.hideAndSeek.events.Worldborder; -import net.tylermurphy.hideAndSeek.util.Board; -import net.tylermurphy.hideAndSeek.world.WorldLoader; +import net.tylermurphy.hideAndSeek.game.Board; +import org.jetbrains.annotations.NotNull; public class Main extends JavaPlugin implements Listener { public static Main plugin; public static File root, data; - - public Taunt taunt; - public Glow glow; - public Worldborder worldborder; - - public Board board; - - public WorldLoader worldLoader; - - public Map playerList = new HashMap(); - - public String status = "Standby"; - - public int timeLeft = 0, gameId = 0;; - private BukkitTask onTickTask; - + public void onEnable() { - plugin = this; - - // Setup Initial Player Count - getServer().getPluginManager().registerEvents(new EventListener(), this); - - // Get Data Folder root = this.getServer().getWorldContainer(); data = this.getDataFolder(); - - // Init Configuration + getServer().getPluginManager().registerEvents(new EventListener(), this); + Config.loadConfig(); Localization.loadLocalization(); Items.loadItems(); - - // Create World Loader - worldLoader = new WorldLoader(spawnWorld); - - // Register Commands + CommandHandler.registerCommands(); - - //Board - board = new Board(); - board.reload(); - - // Start Tick Timer + Board.reload(); + Database.init(); + UUIDFetcher.init(); + onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> { try{ - Tick.onTick(); + Game.onTick(); } catch (Exception e) { e.printStackTrace(); } },0,1); - } public void onDisable() { if(onTickTask != null) onTickTask.cancel(); + UUIDFetcher.cleanup(); } - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - return CommandHandler.handleCommand(sender, cmd, label, args); + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { + return CommandHandler.handleCommand(sender, args); } - public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { - return TabCompleter.handleTabComplete(sender, command, label, args); + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + return TabCompleter.handleTabComplete(sender, args); } -} +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java deleted file mode 100644 index ffad241..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ /dev/null @@ -1,163 +0,0 @@ -package net.tylermurphy.hideAndSeek.bukkit; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -import net.tylermurphy.hideAndSeek.command.Join; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.attribute.Attribute; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Snowball; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -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.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerQuitEvent; - -import net.tylermurphy.hideAndSeek.util.Packet; -import net.tylermurphy.hideAndSeek.util.Util; -import net.tylermurphy.hideAndSeek.Main; -import org.bukkit.potion.PotionEffect; - -import static net.tylermurphy.hideAndSeek.configuration.Localization.*; - -public class EventListener implements Listener { - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - event.getPlayer().setLevel(0); - Main.plugin.board.remove(event.getPlayer()); - if(!Util.isSetup()) return; - if(autoJoin){ - Join.join(event.getPlayer()); - } else if(teleportToExit) { - if (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld) || event.getPlayer().getWorld().getName().equals(lobbyWorld)) { - event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); - event.getPlayer().setGameMode(GameMode.ADVENTURE); - } - } else { - if (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld)) { - event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); - event.getPlayer().setGameMode(GameMode.ADVENTURE); - } - } - } - - @EventHandler - public void onQuit(PlayerQuitEvent event) { - Main.plugin.board.remove(event.getPlayer()); - if(Main.plugin.status.equals("Standby")) { - Main.plugin.board.reloadLobbyBoards(); - } else { - Main.plugin.board.reloadGameBoards(); - } - for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ - event.getPlayer().removePotionEffect(effect.getType()); - } - } - - @EventHandler - public void onKick(PlayerKickEvent event) { - Main.plugin.board.remove(event.getPlayer()); - if(Main.plugin.status.equals("Standby")) { - Main.plugin.board.reloadLobbyBoards(); - } else { - Main.plugin.board.reloadGameBoards(); - } - for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ - event.getPlayer().removePotionEffect(effect.getType()); - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onEntityDamage(EntityDamageEvent event) { - try { - if (event.getEntity() instanceof Player) { - Player p = (Player) event.getEntity(); - if (!Main.plugin.board.isPlayer(p)) return; - if (!Main.plugin.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 (Main.plugin.board.onSameTeam(p, attacker)) event.setCancelled(true); - if (Main.plugin.board.isSpectator(p)) event.setCancelled(true); - } - } - Player player = (Player) event.getEntity(); - if (player.getHealth() - event.getDamage() < 0 || !pvpEnabled) { - if (spawnPosition == null) return; - event.setCancelled(true); - 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 (Main.plugin.board.isSeeker(player)) { - Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(event.getEntity()).toString()); - } - if (Main.plugin.board.isHider(player)) { - if (attacker == null) { - Util.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(event.getEntity()).toString()); - } else { - Util.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(event.getEntity()).addPlayer(attacker).toString()); - } - Main.plugin.board.addSeeker(player); - } - Util.resetPlayer(player); - Main.plugin.board.reloadBoardTeams(); - } - } - } catch (Exception e){ - //Has shown to cause problems, so ignore if exception - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onProjectile(ProjectileLaunchEvent event) { - if(!Main.plugin.status.equals("Playing")) return; - if(event.getEntity() instanceof Snowball) { - if(!glowEnabled) return; - Snowball snowball = (Snowball) event.getEntity(); - if(snowball.getShooter() instanceof Player) { - Player player = (Player) snowball.getShooter(); - if(Main.plugin.board.isHider(player)) { - Main.plugin.glow.onProjectilve(); - snowball.remove(); - player.getInventory().remove(Material.SNOWBALL); - } - } - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onFoodLevelChange(FoodLevelChangeEvent event) { - if(event.getEntity() instanceof Player) { - if(!Main.plugin.board.isPlayer((Player) event.getEntity())) return; - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onPlayerRegainHealth(EntityRegainHealthEvent event) { - if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) { - if(event.getEntity() instanceof Player) { - if(!Main.plugin.board.isPlayer((Player) event.getEntity())) return; - event.setCancelled(true); - } - } - } -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java deleted file mode 100644 index 8efbe80..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java +++ /dev/null @@ -1,85 +0,0 @@ -package net.tylermurphy.hideAndSeek.bukkit; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -import org.bukkit.Bukkit; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.Stop; -import net.tylermurphy.hideAndSeek.util.Packet; -import net.tylermurphy.hideAndSeek.util.Util; -import static net.tylermurphy.hideAndSeek.configuration.Localization.*; - -public class Tick { - - static int tick = 0; - - public static void onTick() { - - if(Main.plugin.status.equals("Standby")) tick = 0; - else if(Main.plugin.status.equals("Playing")) onPlaying(); - - if(( Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing") ) && Main.plugin.board.sizeHider() < 1) { - if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); - else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); - Stop.onStop(); - } - if(( Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing") ) && Main.plugin.board.sizeSeeker() < 1) { - if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); - else Util.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); - Stop.onStop(); - } - - } - - private static void onPlaying() { - - if(tick<1000000) tick++; - else tick = 1; - - for(Player hider : Main.plugin.board.getHiders()) { - int distance = 100, temp = 100; - for(Player seeker : Main.plugin.board.getSeekers()) { - try { - temp = (int) hider.getLocation().distance(seeker.getLocation()); - } catch (Exception e){ - //Players in different worlds, NOT OK!!! - } - if(distance > temp) { - distance = temp; - } - } - switch(tick%10) { - case 0: - if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f); - if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); - break; - case 3: - if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f); - if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); - break; - case 6: - if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); - break; - case 9: - if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); - break; - } - - } - - if(tick%20 == 0) { - if(gameLength > 0) { - Main.plugin.board.reloadGameBoards(); - Main.plugin.timeLeft--; - if(Main.plugin.timeLeft < 1) { - if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); - else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); - Stop.onStop(); - } - } - } - } -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index c341666..de1062b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -1,3 +1,22 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import org.bukkit.ChatColor; @@ -7,7 +26,7 @@ public class About implements ICommand { public void execute(CommandSender sender, String[] args) { sender.sendMessage( - String.format("%s%sHide and Seek %s(1.3.2%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(%s1.3.3%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index e38c19a..c1934a9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -1,19 +1,38 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import org.bukkit.command.CommandSender; import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.bukkit.CommandHandler; +import net.tylermurphy.hideAndSeek.game.CommandHandler; public class Help implements ICommand { public void execute(CommandSender sender, String[] args) { - String message = ""; + StringBuilder message = new StringBuilder(); for(ICommand command : CommandHandler.COMMAND_REGISTER.values()) { - message += String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription()+"\n"); + message.append(String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription() + "\n")); } - message = message.substring(0, message.length()-1); - sender.sendMessage(message); + message = new StringBuilder(message.substring(0, message.length() - 1)); + sender.sendMessage(message.toString()); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java index 928787e..6404c22 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java @@ -1,15 +1,34 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import org.bukkit.command.CommandSender; public interface ICommand { - public void execute(CommandSender sender, String[] args); + void execute(CommandSender sender, String[] args); - public String getLabel(); + String getLabel(); + + String getUsage(); - public String getUsage(); - - public String getDescription(); + String getDescription(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 17b8f7a..0ca21d1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -1,22 +1,38 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.game.Board; +import net.tylermurphy.hideAndSeek.game.Game; 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.Main; -import net.tylermurphy.hideAndSeek.util.Util; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class Join implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Util.isSetup()) { + if(Game.isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } @@ -25,34 +41,12 @@ public class Join implements ICommand { sender.sendMessage(errorPrefix + message("COMMAND_ERROR")); return; } - if(Main.plugin.board.isPlayer(player)){ + if(Board.isPlayer(player)){ sender.sendMessage(errorPrefix + message("GAME_INGAME")); return; } - join(player); - } - - public static void join(Player player){ - if(Main.plugin.status.equals("Standby")) { - player.getInventory().clear(); - Main.plugin.board.addHider(player); - if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); - else Util.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); - player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); - player.setGameMode(GameMode.ADVENTURE); - Main.plugin.board.createLobbyBoard(player); - Main.plugin.board.reloadLobbyBoards(); - } else { - Main.plugin.board.addSpectator(player); - player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR")); - player.setGameMode(GameMode.SPECTATOR); - Main.plugin.board.createGameBoard(player); - 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()); + Game.join(player); } 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 8809b5d..cc4f0b4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -1,20 +1,40 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.game.Board; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Util; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class Leave implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Util.isSetup()) { + if(Game.isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } @@ -23,20 +43,20 @@ public class Leave implements ICommand { sender.sendMessage(errorPrefix + message("COMMAND_ERROR")); return; } - if(!Main.plugin.board.isPlayer(player)) { + if(!Board.isPlayer(player)) { sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); return; } if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); - else Util.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); - Main.plugin.board.removeBoard(player); - Main.plugin.board.remove(player); + else Game.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); + Board.removeBoard(player); + Board.remove(player); player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); - if(Main.plugin.status.equals("Standby")) { - Main.plugin.board.reloadLobbyBoards(); + if(Game.status == Status.STANDBY) { + Board.reloadLobbyBoards(); } else { - Main.plugin.board.reloadGameBoards(); - Main.plugin.board.reloadBoardTeams(); + Board.reloadGameBoards(); + Board.reloadBoardTeams(); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 971cd13..fc2592b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -1,11 +1,31 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import net.tylermurphy.hideAndSeek.configuration.Items; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.command.CommandSender; -import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Localization; @@ -15,7 +35,7 @@ public class Reload implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java index 2befd73..c48e1c6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -1,8 +1,30 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitRunnable; @@ -14,7 +36,7 @@ public class SaveMap implements ICommand { public static boolean runningBackup = false; public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -24,11 +46,15 @@ public class SaveMap implements ICommand { } sender.sendMessage(messagePrefix + message("MAPSAVE_START")); sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); - Bukkit.getServer().getWorld(spawnWorld).save(); + World world = Bukkit.getServer().getWorld(spawnWorld); + if(world == null){ + throw new RuntimeException("Unable to get world: " + spawnWorld); + } + world.save(); BukkitRunnable runnable = new BukkitRunnable() { public void run() { sender.sendMessage( - Main.plugin.worldLoader.save() + Game.worldLoader.save() ); runningBackup = false; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java index 472396c..5f14b20 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -1,22 +1,38 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.HashMap; -import java.util.Map; - +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.events.Worldborder; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetBorder implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -29,7 +45,7 @@ public class SetBorder implements ICommand { addToConfig("worldBorder.enabled",false); saveConfig(); sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); - Worldborder.resetWorldborder(spawnWorld); + Game.resetWorldborder(spawnWorld); return; } int num,delay; @@ -65,7 +81,7 @@ public class SetBorder implements ICommand { addToConfig("worldBorder.enabled", true); sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); saveConfig(); - Worldborder.resetWorldborder(spawnWorld); + Game.resetWorldborder(spawnWorld); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java index c94a0d1..9f4101a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java @@ -1,17 +1,37 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.tylermurphy.hideAndSeek.Main; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetBounds implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java index aeaa89b..7461767 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -1,21 +1,39 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.HashMap; -import java.util.Map; - +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; +import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.Main; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetExitLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -28,7 +46,11 @@ public class SetExitLocation implements ICommand { newExitPosition.setX(player.getLocation().getBlockX()); newExitPosition.setY(player.getLocation().getBlockY()); newExitPosition.setZ(player.getLocation().getBlockZ()); - exitWorld = player.getLocation().getWorld().getName(); + World world = player.getLocation().getWorld(); + if(world == null){ + throw new RuntimeException("Unable to get world: " + spawnWorld); + } + exitWorld = world.getName(); exitPosition = newExitPosition; sender.sendMessage(messagePrefix + message("EXIT_SPAWN")); addToConfig("spawns.exit.x", exitPosition.getX()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java index 2e96a9d..69e5e52 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java @@ -1,21 +1,39 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.HashMap; -import java.util.Map; - +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; +import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.Main; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetLobbyLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -28,7 +46,11 @@ public class SetLobbyLocation implements ICommand { newLobbyPosition.setX(player.getLocation().getBlockX()); newLobbyPosition.setY(player.getLocation().getBlockY()); newLobbyPosition.setZ(player.getLocation().getBlockZ()); - lobbyWorld = player.getLocation().getWorld().getName(); + World world = player.getLocation().getWorld(); + if(world == null){ + throw new RuntimeException("Unable to get world: " + spawnWorld); + } + lobbyWorld = world.getName(); lobbyPosition = newLobbyPosition; sender.sendMessage(messagePrefix + message("LOBBY_SPAWN")); addToConfig("spawns.lobby.x", lobbyPosition.getX()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java index bb3de6d..7afe861 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java @@ -1,23 +1,41 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.HashMap; -import java.util.Map; - +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.world.WorldLoader; +import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.Main; - import static net.tylermurphy.hideAndSeek.configuration.Config.addToConfig; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetSpawnLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -34,7 +52,15 @@ public class SetSpawnLocation implements ICommand { sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); return; } - spawnWorld = player.getLocation().getWorld().getName(); + World world = player.getLocation().getWorld(); + if(world == null){ + throw new RuntimeException("Unable to get world: " + spawnWorld); + } + if(!world.getName().equals(spawnWorld)){ + Game.worldLoader.unloadMap(); + Game.worldLoader = new WorldLoader(world.getName()); + } + spawnWorld = world.getName(); spawnPosition = newSpawnPosition; sender.sendMessage(messagePrefix + message("GAME_SPAWN")); addToConfig("spawns.game.x", spawnPosition.getX()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java index f47503a..74c29bf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -1,3 +1,22 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import org.bukkit.command.CommandSender; @@ -17,24 +36,24 @@ public class Setup implements ICommand { int count = 0; if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_GAME").toString(); + msg = msg + "\n" + message("SETUP_GAME"); count++; } if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_LOBBY").toString(); + msg = msg + "\n" + message("SETUP_LOBBY"); count++; } if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_EXIT").toString(); + msg = msg + "\n" + message("SETUP_EXIT"); count++; } if(saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) { - msg = msg + "\n" + message("SETUP_BOUNDS").toString(); + msg = msg + "\n" + message("SETUP_BOUNDS"); count++; } File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); if(!destenation.exists()) { - msg = msg + "\n" + message("SETUP_SAVEMAP").toString(); + msg = msg + "\n" + message("SETUP_SAVEMAP"); count++; } if(count < 1) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 05565da..b82e3b5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -1,140 +1,75 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; + import static net.tylermurphy.hideAndSeek.configuration.Localization.*; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import net.tylermurphy.hideAndSeek.game.Board; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; -import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.events.Glow; -import net.tylermurphy.hideAndSeek.events.Taunt; -import net.tylermurphy.hideAndSeek.events.Worldborder; -import net.tylermurphy.hideAndSeek.util.Util; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.ArrayList; -import java.util.List; +import java.util.Optional; import java.util.Random; public class Start implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Util.isSetup()) { + if(Game.isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } - if(!Main.plugin.status.equals("Standby")) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } - if(!Main.plugin.board.isPlayer(sender)) { + if(!Board.isPlayer(sender)) { sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); return; } - if(Main.plugin.board.size() < minPlayers) { + if(Board.size() < minPlayers) { sender.sendMessage(errorPrefix + message("START_MIN_PLAYERS").addAmount(minPlayers)); return; } - if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) { - Main.plugin.worldLoader.rollback(); - } else { - Main.plugin.worldLoader.loadMap(); - } String seekerName; if(args.length < 1) { - seekerName = Main.plugin.board.getPlayers().stream().skip(new Random().nextInt(Main.plugin.board.size())).findFirst().get().getName(); + Optional rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst(); + if(!rand.isPresent()){ + Main.plugin.getLogger().warning("Failed to select random seeker."); + return; + } + seekerName = rand.get().getName(); } else { seekerName = args[0]; } - Player seeker = Main.plugin.board.getPlayer(seekerName); + Player seeker = Board.getPlayer(seekerName); if(seeker == null) { sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); return; } - Main.plugin.board.reload(); - for(Player temp : Main.plugin.board.getPlayers()) { - if(temp.getName().equals(seeker.getName())) - continue; - Main.plugin.board.addHider(temp); - } - Main.plugin.board.addSeeker(seeker); - currentWorldborderSize = worldborderSize; - for(Player player : Main.plugin.board.getPlayers()) { - player.getInventory().clear(); - player.setGameMode(GameMode.ADVENTURE); - player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); - for(PotionEffect effect : player.getActivePotionEffects()){ - player.removePotionEffect(effect.getType()); - } - } - for(Player player : Main.plugin.board.getSeekers()) { - 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 + message("SEEKERS_SUBTITLE").toString(), 10, 70, 20); - } - for(Player player : Main.plugin.board.getHiders()) { - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); - player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString(), 10, 70, 20); - } - Worldborder.resetWorldborder("hideandseek_"+spawnWorld); - for(Player player : Main.plugin.board.getPlayers()){ - Main.plugin.board.createGameBoard(player); - } - Main.plugin.board.reloadGameBoards(); - Main.plugin.status = "Starting"; - int temp = Main.plugin.gameId; - Util.broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30)); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), Main.plugin.gameId, 20 * 10); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), Main.plugin.gameId, 20 * 20); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), Main.plugin.gameId, 20 * 25); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), Main.plugin.gameId, 20 * 27); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), Main.plugin.gameId, 20 * 28); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), Main.plugin.gameId, 20 * 29); - Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { - public void run() { - if(temp != Main.plugin.gameId) return; - Util.broadcastMessage(messagePrefix + message("START")); - Main.plugin.status = "Playing"; - for(Player player : Main.plugin.board.getPlayers()) { - Util.resetPlayer(player); - } - Main.plugin.worldborder = null; - Main.plugin.taunt = null; - Main.plugin.glow = null; - - if(worldborderEnabled) { - Main.plugin.worldborder = new Worldborder(Main.plugin.gameId); - Main.plugin.worldborder.schedule(); - } - - if(tauntEnabled) { - Main.plugin.taunt = new Taunt(Main.plugin.gameId); - Main.plugin.taunt.schedule(); - } - - if (glowEnabled) { - Main.plugin.glow = new Glow(Main.plugin.gameId); - } - - if(gameLength > 0) { - Main.plugin.timeLeft = gameLength; - } - } - }, 20 * 30); - + Game.start(seeker); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index e4dd16e..b41277b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -1,36 +1,47 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.util.WinType; import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.events.Worldborder; -import net.tylermurphy.hideAndSeek.util.Packet; -import net.tylermurphy.hideAndSeek.util.Util; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class Stop implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Util.isSetup()) { + if(Game.isNotSetup()) { sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } - if(Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing")) { + if(Game.status == Status.STARTING || Game.status == Status.PLAYING) { if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("STOP")); - else Util.broadcastMessage(abortPrefix + message("STOP")); - onStop(); - + else Game.broadcastMessage(abortPrefix + message("STOP")); + Game.stop(WinType.NONE); } else { sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS")); - return; } } @@ -38,30 +49,6 @@ public class Stop implements ICommand { return "stop"; } - public static void onStop() { - if(Main.plugin.status.equals("Standby")) return; - Main.plugin.status = "Standby"; - Main.plugin.gameId++; - Main.plugin.timeLeft = 0; - Worldborder.resetWorldborder("hideandseek_"+spawnWorld); - for(Player player : Main.plugin.board.getPlayers()) { - Main.plugin.board.createLobbyBoard(player); - player.setGameMode(GameMode.ADVENTURE); - Main.plugin.board.addHider(player); - player.getInventory().clear(); - player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); - for(PotionEffect effect : player.getActivePotionEffects()){ - player.removePotionEffect(effect.getType()); - } - player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); - for(Player temp : Main.plugin.board.getPlayers()) { - Packet.setGlow(player, temp, false); - } - } - Main.plugin.worldLoader.unloadMap(); - Main.plugin.board.reloadLobbyBoards(); - } - public String getUsage() { return ""; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java new file mode 100644 index 0000000..760bb2c --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -0,0 +1,80 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.database.Database; +import net.tylermurphy.hideAndSeek.database.PlayerInfo; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +import java.util.List; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.*; + +public class Top implements ICommand { + + public void execute(CommandSender sender, String[] args) { + int page; + if(args.length == 0) page = 1; + else try{ + page = Integer.parseInt(args[0]); + } catch(Exception e){ + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); + return; + } + if(page < 1){ + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(page)); + return; + } + StringBuilder message = new StringBuilder(String.format( + "%s------- %sLEADERBOARD %s(Page %s) %s-------\n", + ChatColor.WHITE, ChatColor.BOLD, ChatColor.GRAY, page, ChatColor.WHITE)); + List infos = Database.playerInfo.getInfoPage(page); + int i = 1 + (page-1)*10; + for(PlayerInfo info : infos){ + String name = Main.plugin.getServer().getOfflinePlayer(info.uuid).getName(); + ChatColor color; + switch (i){ + case 1: color = ChatColor.YELLOW; break; + case 2: color = ChatColor.GRAY; break; + case 3: color = ChatColor.GOLD; break; + default: color = ChatColor.WHITE; break; + } + message.append(String.format("%s%s. %s%s %s%s\n", + color, i, ChatColor.RED, info.wins, ChatColor.WHITE, name)); + i++; + } + sender.sendMessage(message.toString()); + } + + public String getLabel() { + return "top"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Gets the top players in the server."; + } +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java new file mode 100644 index 0000000..dfa5338 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -0,0 +1,88 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.database.Database; +import net.tylermurphy.hideAndSeek.database.PlayerInfo; +import net.tylermurphy.hideAndSeek.util.UUIDFetcher; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.UUID; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.*; + +public class Wins implements ICommand { + + public void execute(CommandSender sender, String[] args) { + Main.plugin.getServer().getScheduler().runTaskAsynchronously(Main.plugin, () -> { + + UUID uuid; + String name; + if(args.length == 0) { + Player player = Main.plugin.getServer().getPlayer(sender.getName()); + if(player == null){ + sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(sender.getName())); + return; + } + uuid = player.getUniqueId(); + name = sender.getName(); + } + else { + try { + name = args[0]; + uuid = UUIDFetcher.getUUID(args[0]); + } catch (Exception e){ + sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(args[0])); + return; + } + } + PlayerInfo info = Database.playerInfo.getInfo(uuid); + if(info == null){ + sender.sendMessage(errorPrefix + message("NO_GAME_INFO")); + return; + } + String message = ChatColor.WHITE + "" + ChatColor.BOLD + "==============================\n"; + message = message + message("INFORMATION_FOR").addPlayer(name) + "\n"; + message = message + "==============================\n"; + message = message + String.format("%sTOTAL WINS: %s%s\n%sHIDER WINS: %s%s\n%sSEEKER WINS: %s%s\n%sGAMES PLAYED: %s", + ChatColor.YELLOW, ChatColor.WHITE, info.wins, ChatColor.GOLD, ChatColor.WHITE, info.hider_wins, + ChatColor.RED, ChatColor.WHITE, info.seeker_wins, ChatColor.WHITE, info.games_played); + message = message + ChatColor.WHITE + "" + ChatColor.BOLD + "\n=============================="; + sender.sendMessage(message); + + }); + } + + public String getLabel() { + return "wins"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Get the win information for yourself or another player."; + } +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index ee9d88d..524eeac 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -1,3 +1,22 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.configuration; import org.bukkit.util.Vector; @@ -37,7 +56,8 @@ public class Config { glowStackable, pvpEnabled, autoJoin, - teleportToExit; + teleportToExit, + lobbyCountdownEnabled; public static int minPlayers, @@ -50,7 +70,11 @@ public class Config { saveMaxX, saveMaxZ, tauntDelay, - glowLength; + glowLength, + countdown, + changeCountdown, + lobbyMin, + lobbyMax; public static void loadConfig() { @@ -121,10 +145,17 @@ public class Config { glowStackable = manager.getBoolean("glow.stackable"); glowEnabled = manager.getBoolean("glow.enabled"); + //Lobby + minPlayers = Math.max(2, manager.getInt("minPlayers")); + countdown = Math.max(10,manager.getInt("lobby.countdown")); + changeCountdown = Math.max(minPlayers,manager.getInt("lobby.changeCountdown")); + lobbyMin = Math.max(minPlayers,manager.getInt("lobby.min")); + lobbyMax = manager.getInt("lobby.max"); + lobbyCountdownEnabled = manager.getBoolean("lobby.enabled"); + //Other nametagsVisible = manager.getBoolean("nametagsVisible"); permissionsRequired = manager.getBoolean("permissionsRequired"); - minPlayers = Math.max(2, manager.getInt("minPlayers")); gameLength = manager.getInt("gameLength"); pvpEnabled = manager.getBoolean("pvp"); autoJoin = manager.getBoolean("autoJoin"); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index c1757d1..84ad5b4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -1,3 +1,22 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.configuration; import net.tylermurphy.hideAndSeek.Main; @@ -11,17 +30,20 @@ import java.util.Map; public class ConfigManager { - private File file; + private final File file; private YamlConfiguration config,defaultConfig; private String defaultFilename; public ConfigManager(String filename){ - this.file = new File(Main.plugin.getDataFolder(), filename); + this.file = new File(Main.data, filename); this.defaultFilename = file.getName(); - File folder = Main.plugin.getDataFolder(); - if(!folder.exists()) - folder.mkdirs(); + File folder = Main.data; + if(!folder.exists()){ + if(!folder.mkdirs()){ + throw new RuntimeException("Failed to make directory: " + file.getPath()); + } + } if(!file.exists()){ saveDefaultConfiguration(); @@ -30,18 +52,21 @@ public class ConfigManager { this.config = YamlConfiguration.loadConfiguration(file); InputStream input = Main.plugin.getResource(file.getName()); + if(input == null){ + throw new RuntimeException("Could not create input stream for "+file.getPath()); + } InputStreamReader reader = new InputStreamReader(input); this.defaultConfig = YamlConfiguration.loadConfiguration(reader); try{ input.close(); reader.close(); - } catch (IOException e){} + } catch (IOException ignored){} } public ConfigManager(String filename, String defaultFilename){ this.defaultFilename = defaultFilename; - this.file = new File(Main.plugin.getDataFolder(), filename); + this.file = new File(Main.data, filename); if(!file.exists()){ saveDefaultConfiguration(); @@ -50,6 +75,9 @@ public class ConfigManager { this.config = YamlConfiguration.loadConfiguration(file); InputStream input = Main.plugin.getResource(defaultFilename); + if(input == null){ + throw new RuntimeException("Could not create input stream for "+defaultFilename); + } InputStreamReader reader = new InputStreamReader(input); this.defaultConfig = YamlConfiguration.loadConfiguration(reader); try{ @@ -65,6 +93,9 @@ public class ConfigManager { private void saveDefaultConfiguration(){ try{ InputStream input = Main.plugin.getResource(defaultFilename); + if(input == null){ + throw new RuntimeException("Could not create input stream for "+defaultFilename); + } java.nio.file.Files.copy(input, file.toPath()); input.close(); } catch(IOException e){ @@ -72,10 +103,6 @@ public class ConfigManager { } } - public void addToConfig(String path, Object value) { - config.set(path, value); - } - public double getDouble(String path){ double value = config.getDouble(path); if(value == 0.0D){ @@ -111,6 +138,9 @@ public class ConfigManager { this.defaultFilename = newDefaultFilename; InputStream input = Main.plugin.getResource(defaultFilename); + if(input == null){ + throw new RuntimeException("Could not create input stream for "+defaultFilename); + } InputStreamReader reader = new InputStreamReader(input); this.config = YamlConfiguration.loadConfiguration(reader); this.defaultConfig = YamlConfiguration.loadConfiguration(reader); @@ -119,7 +149,7 @@ public class ConfigManager { public boolean getBoolean(String path){ boolean value = config.getBoolean(path); - if(value == false){ + if(!value){ return defaultConfig.getBoolean(path); } else { return true; @@ -142,9 +172,12 @@ public class ConfigManager { public void saveConfig(){ try { InputStream is = Main.plugin.getResource(defaultFilename); + if(is == null){ + throw new RuntimeException("Could not create input stream for "+defaultFilename); + } StringBuilder textBuilder = new StringBuilder(); Reader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name()))); - int c = 0; + int c; while((c = reader.read()) != -1){ textBuilder.append((char) c); } @@ -165,7 +198,7 @@ public class ConfigManager { i++; if(index == -1) break; } - if(index < 10) continue;; + if(index < 10) continue; int start = yamlString.indexOf(' ', index); int end = yamlString.indexOf('\n', index); if(end == -1) end = yamlString.length(); @@ -173,7 +206,6 @@ public class ConfigManager { if(entry.getValue() instanceof String){ replace = "\"" + replace + "\""; } - System.out.println(entry.getKey() + " " + index + " " + start + " " + end); StringBuilder builder = new StringBuilder(yamlString); builder.replace(start+1, end, replace); yamlString = builder.toString(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index e5470af..569cae6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -1,3 +1,22 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.configuration; import org.bukkit.ChatColor; @@ -78,6 +97,7 @@ public class Items { if(material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION){ PotionMeta meta = getPotionMeta(stack, item); stack.setItemMeta(meta); + } else { ConfigurationSection enchantments = item.getConfigurationSection("enchantments"); if (enchantments != null) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 61dc5a4..d5ae01d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -1,3 +1,22 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.configuration; import java.io.File; @@ -10,7 +29,7 @@ public class Localization { public static final Map LOCAL = new HashMap<>(); - private static String[][] CHANGES = {{"WORLDBORDER_DECREASING"}}; + private static final String[][] CHANGES = {{"WORLDBORDER_DECREASING"}}; public static void loadLocalization() { @@ -48,7 +67,7 @@ public class Localization { public static LocalizationString message(String key) { LocalizationString temp = LOCAL.get(key); if(temp == null) { - return new LocalizationString(ChatColor.RED + "" + ChatColor.ITALIC + key + "is not found in localization.yml. This is a plugin issue, please report it."); + return new LocalizationString(ChatColor.RED + "" + ChatColor.ITALIC + key + " is not found in localization.yml. This is a plugin issue, please report it."); } return new LocalizationString(temp.toString()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java index fd0e020..3d8bc0f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java @@ -1,48 +1,56 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.configuration; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; public class LocalizationString { - - String message; - - public LocalizationString(String message) { - this.message = message; - } - - public LocalizationString addPlayer(Entity player) { - this.message = message.replaceFirst("\\{PLAYER\\}", player.getName()); - return this; - } - - public LocalizationString addPlayer(CommandSender player) { - this.message = message.replaceFirst("\\{PLAYER\\}", player.getName()); - return this; - } - - public LocalizationString addPlayer(String player) { - this.message = message.replaceFirst("\\{PLAYER\\}", player); - return this; - } - - public LocalizationString addAmount(Integer value) { - this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString()); - return this; - } - - public LocalizationString addAmount(String value) { - this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString()); - return this; - } - - public LocalizationString addAmount(Float value) { - this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString()); - return this; - } - - public String toString() { - return message; - } - -} + + String message; + + public LocalizationString(String message) { + this.message = message; + } + + public LocalizationString addPlayer(Entity player) { + this.message = message.replaceFirst("\\{PLAYER}", player.getName()); + return this; + } + + public LocalizationString addPlayer(String player) { + this.message = message.replaceFirst("\\{PLAYER}", player); + return this; + } + + public LocalizationString addAmount(Integer value) { + this.message = message.replaceFirst("\\{AMOUNT}", value.toString()); + return this; + } + + public LocalizationString addAmount(String value) { + this.message = message.replaceFirst("\\{AMOUNT}", value); + return this; + } + + public String toString() { + return message; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java new file mode 100644 index 0000000..602c948 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java @@ -0,0 +1,73 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.database; + +import com.google.common.io.ByteStreams; +import net.tylermurphy.hideAndSeek.Main; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.UUID; + +public class Database { + + private static final File databaseFile = new File(Main.data, "database.db"); + + public static PlayerInfoTable playerInfo; + + protected static Connection connect() { + Connection conn = null; + try { + String url = "jdbc:sqlite:"+databaseFile; + conn = DriverManager.getConnection(url); + } catch (SQLException e) { + System.out.println(e.getMessage()); + } + return conn; + } + + protected static InputStream convertUniqueId(UUID uuid) { + byte[] bytes = new byte[16]; + ByteBuffer.wrap(bytes) + .putLong(uuid.getMostSignificantBits()) + .putLong(uuid.getLeastSignificantBits()); + return new ByteArrayInputStream(bytes); + } + + protected static UUID convertBinaryStream(InputStream stream) { + ByteBuffer buffer = ByteBuffer.allocate(16); + try { + buffer.put(ByteStreams.toByteArray(stream)); + buffer.flip(); + return new UUID(buffer.getLong(), buffer.getLong()); + } catch (IOException ignored) {} + return null; + } + + public static void init(){ + playerInfo = new PlayerInfoTable(); + } +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java new file mode 100644 index 0000000..8464b54 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java @@ -0,0 +1,37 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.database; + +import java.util.UUID; + +public class PlayerInfo { + + public UUID uuid; + public int wins, hider_wins, seeker_wins, games_played; + + public PlayerInfo(UUID uuid, int wins, int hider_wins, int seeker_wins, int games_played){ + this.uuid = uuid; + this.wins = wins; + this.hider_wins = hider_wins; + this.seeker_wins = seeker_wins; + this.games_played = games_played; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java new file mode 100644 index 0000000..e859687 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java @@ -0,0 +1,129 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.database; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.WinType; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.*; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class PlayerInfoTable { + + protected PlayerInfoTable(){ + + String sql = "CREATE TABLE IF NOT EXISTS player_info (\n" + + " uuid BINARY(16) PRIMARY KEY,\n" + + " wins int NOT NULL,\n" + + " seeker_wins int NOT NULL,\n" + + " hider_wins int NOT NULL,\n" + + " games_played int NOT NULL\n" + + ");"; + + try(Connection connection = Database.connect(); Statement statement = connection.createStatement()){ + statement.execute(sql); + } catch (SQLException e){ + Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); + } + } + + public PlayerInfo getInfo(UUID uuid){ + String sql = "SELECT * FROM player_info WHERE uuid = ?;"; + try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ + InputStream is = Database.convertUniqueId(uuid); + byte[] bytes = new byte[is.available()]; + if(is.read(bytes) == -1){ + throw new IOException("Failed to read bytes from input stream"); + } + statement.setBytes(1, bytes); + ResultSet rs = statement.executeQuery(); + if(rs.next()){ + return new PlayerInfo( + uuid, + rs.getInt("wins"), + rs.getInt("seeker_wins"), + rs.getInt("hider_wins"), + rs.getInt("games_played") + ); + } + } catch (SQLException e){ + Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); + } catch (IOException e) { + Main.plugin.getLogger().severe("IO Error: " + e.getMessage()); + e.printStackTrace(); + } + return new PlayerInfo(uuid, 0, 0, 0, 0); + } + + public List getInfoPage(int page){ + String sql = "SELECT * FROM player_info ORDER BY wins DESC LIMIT 10 OFFSET ?;"; + try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ + statement.setInt(1, (page-1)*10); + ResultSet rs = statement.executeQuery(); + List infoList = new ArrayList<>(); + while(rs.next()){ + PlayerInfo info = new PlayerInfo( + Database.convertBinaryStream(rs.getBinaryStream("uuid")), + rs.getInt("wins"), + rs.getInt("seeker_wins"), + rs.getInt("hider_wins"), + rs.getInt("games_played") + ); + infoList.add(info); + } + return infoList; + } catch (SQLException e){ + Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); + } + return null; + } + + public void addWins(List uuids, List winners, WinType type){ + for(UUID uuid : uuids){ + String sql = "INSERT OR REPLACE INTO player_info (uuid, wins, seeker_wins, hider_wins, games_played) VALUES (?,?,?,?,?)"; + PlayerInfo info = getInfo(uuid); + try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ + InputStream is = Database.convertUniqueId(uuid); + byte[] bytes = new byte[is.available()]; + if(is.read(bytes) == -1){ + throw new IOException("Failed to read bytes from input stream"); + } + statement.setBytes(1, bytes); + statement.setInt(2, info.wins + (winners.contains(uuid) ? 1 : 0)); + statement.setInt(3, info.seeker_wins + (winners.contains(uuid) && type == WinType.SEEKER_WIN ? 1 : 0)); + statement.setInt(4, info.hider_wins + (winners.contains(uuid) && type == WinType.HIDER_WIN ? 1 : 0)); + statement.setInt(5, info.games_played + 1); + statement.execute(); + } catch (SQLException e){ + Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); + e.printStackTrace(); + return; + } catch (IOException e) { + Main.plugin.getLogger().severe("IO Error: " + e.getMessage()); + e.printStackTrace(); + } + } + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java deleted file mode 100644 index a817df3..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java +++ /dev/null @@ -1,65 +0,0 @@ -package net.tylermurphy.hideAndSeek.events; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Packet; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -public class Glow { - - private final int temp; - private int glowTime; - private boolean running; - - public Glow(int temp) { - this.temp = temp; - this.glowTime = 0; - } - - public void onProjectilve() { - if(glowStackable) glowTime += glowLength; - else glowTime = glowLength; - if(!running) - startGlow(); - } - - private void startGlow() { - running = true; - for(Player hider : Main.plugin.board.getHiders()) { - for(Player seeker : Main.plugin.board.getSeekers()) { - Packet.setGlow(hider, seeker, true); - } - } - waitGlow(); - } - - private void waitGlow() { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { - if(temp != Main.plugin.gameId) return; - glowTime--; - glowTime = Math.max(glowTime, 0); - if(glowTime == 0) { - stopGlow(); - } else { - waitGlow(); - } - }, 20); - } - - private void stopGlow() { - running = false; - for(Player hider : Main.plugin.board.getHiders()) { - for (Player seeker : Main.plugin.board.getSeekers()) { - Packet.setGlow(hider, seeker, false); - } - } - } - - public boolean isRunning() { - return running; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java deleted file mode 100644 index d24c93f..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java +++ /dev/null @@ -1,101 +0,0 @@ -package net.tylermurphy.hideAndSeek.events; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.FireworkEffect; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Firework; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.FireworkMeta; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Util; -import static net.tylermurphy.hideAndSeek.configuration.Localization.*; - -public class Taunt { - - private final int temp; - private String tauntPlayer; - private int delay; - private boolean running; - - public Taunt(int temp) { - this.temp = temp; - this.delay = 0; - } - - public void schedule() { - delay = tauntDelay; - waitTaunt(); - } - - private void waitTaunt() { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { - if(delay == 0) { - if(!tauntLast && Main.plugin.board.size() < 2) return; - else executeTaunt(); - } else { - delay--; - waitTaunt(); - } - },20); - } - - private void executeTaunt() { - if(temp != Main.plugin.gameId) return; - Player taunted = null; - int rand = (int) (Math.random()*Main.plugin.board.sizeHider()); - for(Player player : Main.plugin.board.getPlayers()) { - if(Main.plugin.board.isHider(player)) { - rand--; - if(rand==0) { - taunted = player; - break; - } - } - } - if(taunted != null) { - running = true; - taunted.sendMessage(message("TAUNTED").toString()); - Util.broadcastMessage(tauntPrefix + message("TAUNT")); - tauntPlayer = taunted.getName(); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { - if(temp != Main.plugin.gameId) return; - Player taunted1 = Main.plugin.board.getPlayer(tauntPlayer); - if(taunted1 != null) { - Firework fw = (Firework) taunted1.getLocation().getWorld().spawnEntity(taunted1.getLocation(), EntityType.FIREWORK); - FireworkMeta fwm = fw.getFireworkMeta(); - fwm.setPower(4); - fwm.addEffect(FireworkEffect.builder() - .withColor(Color.BLUE) - .withColor(Color.RED) - .withColor(Color.YELLOW) - .with(FireworkEffect.Type.STAR) - .with(FireworkEffect.Type.BALL) - .with(FireworkEffect.Type.BALL_LARGE) - .flicker(true) - .withTrail() - .build()); - fw.setFireworkMeta(fwm); - Util.broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE")); - } - tauntPlayer = ""; - running = false; - schedule(); - },20*30); - } else { - schedule(); - } - } - - public int getDelay(){ - return delay; - } - - public boolean isRunning() { - return running; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java deleted file mode 100644 index 5d0e48c..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java +++ /dev/null @@ -1,74 +0,0 @@ -package net.tylermurphy.hideAndSeek.events; - -import static net.tylermurphy.hideAndSeek.configuration.Localization.*; -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldBorder; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Util; - -public class Worldborder { - - private final int temp; - private int delay; - private boolean running; - - public Worldborder(int temp) { - this.temp = temp; - } - - public void schedule() { - delay = 60*worldborderDelay; - running = false; - waitBorder(); - } - - private void waitBorder(){ - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { - if(delay == 0) decreaceWorldborder(); - else { - delay--; waitBorder(); - } - }, 20); - } - - private void decreaceWorldborder() { - if(temp != Main.plugin.gameId) return; - if(currentWorldborderSize-100 > 100) { - running = true; - Util.broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING")); - currentWorldborderSize -= 100; - World world = Bukkit.getWorld("hideandseek_"+spawnWorld); - WorldBorder border = world.getWorldBorder(); - border.setSize(border.getSize()-100,30); - schedule(); - } - } - - public static void resetWorldborder(String worldName) { - if(worldborderEnabled) { - World world = Bukkit.getWorld(worldName); - WorldBorder border = world.getWorldBorder(); - border.setSize(worldborderSize); - border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ()); - currentWorldborderSize = worldborderSize; - } else { - World world = Bukkit.getWorld(worldName); - WorldBorder border = world.getWorldBorder(); - border.setSize(30000000); - border.setCenter(0, 0); - } - } - - public int getDelay(){ - return delay; - } - - public boolean isRunning() { - return running; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java new file mode 100644 index 0000000..936f7ac --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -0,0 +1,374 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.game; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import net.tylermurphy.hideAndSeek.util.Status; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.*; + +public class Board { + + private static final List Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>(); + private static final Map playerList = new HashMap<>(); + private static final Map customBoards = new HashMap<>(); + + public static boolean isPlayer(Player player) { + return playerList.containsKey(player.getName()); + } + + public static boolean isPlayer(String name){ + return playerList.containsKey(name); + } + + public static boolean isPlayer(CommandSender sender) { + return playerList.containsKey(sender.getName()); + } + + public static boolean isHider(Player player) { + return Hider.contains(player.getName()); + } + + public static boolean isSeeker(Player player) { + return Seeker.contains(player.getName()); + } + + public static boolean isSpectator(Player player) { + return Spectator.contains(player.getName()); + } + + public static int sizeHider() { + return Hider.size(); + } + + public static int sizeSeeker() { + return Seeker.size(); + } + + public static int size() { + return playerList.values().size(); + } + + public static List getHiders(){ + return Hider.stream().map(playerList::get).collect(Collectors.toList()); + } + + public static List getSeekers(){ + return Seeker.stream().map(playerList::get).collect(Collectors.toList()); + } + + public static Player getFirstSeeker(){ + return playerList.get(Seeker.get(0)); + } + + public static List getSpectators(){ + return Spectator.stream().map(playerList::get).collect(Collectors.toList()); + } + + public static List getPlayers(){ + return new ArrayList<>(playerList.values()); + } + + public static Player getPlayer(String name) { + return playerList.get(name); + } + + public static void addHider(Player player) { + Hider.add(player.getName()); + Seeker.remove(player.getName()); + Spectator.remove(player.getName()); + playerList.put(player.getName(), player); + } + + public static void addSeeker(Player player) { + Hider.remove(player.getName()); + Seeker.add(player.getName()); + Spectator.remove(player.getName()); + playerList.put(player.getName(), player); + } + + public static void addSpectator(Player player) { + Hider.remove(player.getName()); + Seeker.remove(player.getName()); + Spectator.add(player.getName()); + playerList.put(player.getName(), player); + } + + public static void remove(Player player) { + Hider.remove(player.getName()); + Seeker.remove(player.getName()); + Spectator.remove(player.getName()); + playerList.remove(player.getName()); + } + + public static boolean onSameTeam(Player player1, Player player2) { + if(Hider.contains(player1.getName()) && Hider.contains(player2.getName())) return true; + else if(Seeker.contains(player1.getName()) && Seeker.contains(player2.getName())) return true; + else return Spectator.contains(player1.getName()) && Spectator.contains(player2.getName()); + } + + public static void reload() { + Hider.clear(); + Seeker.clear(); + Spectator.clear(); + } + + public static void createLobbyBoard(Player player) { + createLobbyBoard(player, true); + } + + private static void createLobbyBoard(Player player, boolean recreate) { + CustomBoard board = customBoards.get(player.getName()); + if(recreate) { + board = new CustomBoard(player, "&l&eHIDE AND SEEK"); + board.updateTeams(); + } + board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER %" + ChatColor.WHITE + getHiderPercent()); + board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER %" + ChatColor.WHITE + getSeekerPercent()); + board.addBlank(); + board.setLine("players", "Players: " + playerList.values().size()); + board.addBlank(); + if(lobbyCountdownEnabled){ + if(Game.countdownTime == -1){ + board.setLine("waiting", "Waiting for players..."); + } else { + board.setLine("waiting", "Starting in: "+ChatColor.GREEN + Game.countdownTime+"s"); + } + } else { + board.setLine("waiting", "Waiting for gamemaster..."); + } + board.display(); + customBoards.put(player.getName(), board); + } + + public static void createGameBoard(Player player){ + createGameBoard(player, true); + } + + private static void createGameBoard(Player player, boolean recreate){ + CustomBoard board = customBoards.get(player.getName()); + if(recreate) { + board = new CustomBoard(player, "&l&eHIDE AND SEEK"); + board.updateTeams(); + } + board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDERS:" + ChatColor.WHITE + " " + Hider.size()); + board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size()); + board.addBlank(); + if(glowEnabled){ + if(Game.glow == null || Game.status == Status.STARTING || !Game.glow.isRunning()) + board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive"); + else + board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active"); + } + if(tauntEnabled && tauntCountdown){ + if(Game.taunt == null || Game.status == Status.STARTING) + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s"); + else if(!tauntLast && Hider.size() == 1){ + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired"); + } else if(!Game.taunt.isRunning()) + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Game.taunt.getDelay()/60 + "m" + Game.taunt.getDelay()%60 + "s"); + else + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active"); + } + if(worldborderEnabled){ + if(Game.worldBorder == null || Game.status == Status.STARTING){ + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s"); + } else if(!Game.worldBorder.isRunning()) { + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Game.worldBorder.getDelay()/60 + "m" + Game.worldBorder.getDelay()%60 + "s"); + } else { + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "Decreasing"); + } + } + if(glowEnabled || (tauntEnabled && tauntCountdown) || worldborderEnabled) + board.addBlank(); + board.setLine("time", "Time Left: " + ChatColor.GREEN + Game.timeLeft/60 + "m" + Game.timeLeft%60 + "s"); + board.addBlank(); + board.setLine("team", "Team: " + getTeam(player)); + board.display(); + customBoards.put(player.getName(), board); + } + + public static void removeBoard(Player player) { + ScoreboardManager manager = Bukkit.getScoreboardManager(); + assert manager != null; + player.setScoreboard(manager.getMainScoreboard()); + customBoards.remove(player.getName()); + } + + public static void reloadLobbyBoards() { + for(Player player : playerList.values()) + createLobbyBoard(player, false); + } + + public static void reloadGameBoards() { + for(Player player : playerList.values()) + createGameBoard(player, false); + } + + public static void reloadBoardTeams() { + for(CustomBoard board : customBoards.values()) + board.updateTeams(); + } + + private static String getSeekerPercent() { + if(playerList.values().size() < 2) + return " --"; + else + return " "+(int)(100*(1.0/playerList.size())); + } + + private static String getHiderPercent() { + if(playerList.size() < 2) + return " --"; + else + return " "+(int)(100-100*(1.0/playerList.size())); + } + + private static String getTeam(Player player) { + if(isHider(player)) return ChatColor.GOLD + "HIDER"; + else if(isSeeker(player)) return ChatColor.RED + "SEEKER"; + else if(isSpectator(player)) return ChatColor.GRAY + "SPECTATOR"; + else return ChatColor.WHITE + "UNKNOWN"; + } + +} + +class CustomBoard { + + private final Scoreboard board; + private final Objective obj; + private final Player player; + private final Map LINES; + private int blanks; + private boolean displayed; + + public CustomBoard(Player player, String title){ + ScoreboardManager manager = Bukkit.getScoreboardManager(); + assert manager != null; + this.board = manager.getNewScoreboard(); + this.LINES = new HashMap<>(); + this.player = player; + this.obj = board.registerNewObjective( + "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title)); + this.blanks = 0; + this.displayed = false; + this.updateTeams(); + } + + public void updateTeams() { + try{ board.registerNewTeam("Hider"); } catch (Exception ignored){} + try{ board.registerNewTeam("Seeker"); } catch (Exception ignored){} + Team hiderTeam = board.getTeam("Hider"); + assert hiderTeam != null; + for(String entry : hiderTeam.getEntries()) + hiderTeam.removeEntry(entry); + for(Player player : Board.getHiders()) + hiderTeam.addEntry(player.getName()); + Team seekerTeam = board.getTeam("Seeker"); + assert seekerTeam != null; + for(String entry : seekerTeam.getEntries()) + seekerTeam.removeEntry(entry); + for(Player player : Board.getSeekers()) + seekerTeam.addEntry(player.getName()); + if(nametagsVisible) { + hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); + seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS); + } else { + hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + } + hiderTeam.setColor(ChatColor.GOLD); + seekerTeam.setColor(ChatColor.RED); + } + + public void setLine(String key, String message){ + Line line = LINES.get(key); + if(line == null) + addLine(key, message); + else + updateLine(key, message); + } + + private void addLine(String key, String message){ + Score score = obj.getScore(message); + score.setScore(LINES.values().size()+1); + Line line = new Line(LINES.values().size()+1, message); + LINES.put(key, line); + } + + public void addBlank(){ + if(displayed) return; + StringBuilder temp = new StringBuilder(); + for(int i = 0; i <= blanks; i ++) + temp.append(ChatColor.RESET); + blanks++; + addLine("blank"+blanks, temp.toString()); + } + + private void updateLine(String key, String message){ + Line line = LINES.get(key); + board.resetScores(line.getMessage()); + line.setMessage(message); + Score newScore = obj.getScore(message); + + newScore.setScore(line.getScore()); + } + + public void display() { + displayed = true; + obj.setDisplaySlot(DisplaySlot.SIDEBAR); + player.setScoreboard(board); + } + +} + +class Line { + + private final int score; + private String message; + + public Line(int score, String message){ + this.score = score; + this.message = message; + } + + public int getScore() { + return score; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java similarity index 66% rename from src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java rename to src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java index 1efb505..8df3cf2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java @@ -1,4 +1,23 @@ -package net.tylermurphy.hideAndSeek.bukkit; +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; @@ -7,7 +26,6 @@ import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,7 +33,7 @@ import net.tylermurphy.hideAndSeek.command.*; public class CommandHandler { - public static Map COMMAND_REGISTER = new LinkedHashMap(); + public static Map COMMAND_REGISTER = new LinkedHashMap<>(); private static void registerCommand(ICommand command) { if(!COMMAND_REGISTER.containsKey(command.getLabel())) { @@ -38,10 +56,12 @@ public class CommandHandler { registerCommand(new SetBounds()); registerCommand(new Join()); registerCommand(new Leave()); + registerCommand(new Top()); + registerCommand(new Wins()); } - public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) { - if(sender instanceof Player == false) { + public static boolean handleCommand(CommandSender sender, String[] args) { + if(!(sender instanceof Player)) { sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY")); } else if(args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) { if(permissionsRequired && !sender.hasPermission("hideandseek.about")) { @@ -50,7 +70,7 @@ public class CommandHandler { COMMAND_REGISTER.get("about").execute(sender, null); } } else { - if(!args[0].toLowerCase().equals("about") && !args[0].toLowerCase().equals("help") && SaveMap.runningBackup) { + if(!args[0].equalsIgnoreCase("about") && !args[0].equalsIgnoreCase("help") && SaveMap.runningBackup) { sender.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); } else if(permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) { sender.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); @@ -66,8 +86,4 @@ public class CommandHandler { return true; } - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - return CommandHandler.handleCommand(sender, command, label, args); - } - } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java new file mode 100644 index 0000000..42589bc --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -0,0 +1,264 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.game; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.Status; +import org.bukkit.*; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Snowball; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.*; +import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; +import org.bukkit.event.player.*; + +import net.tylermurphy.hideAndSeek.util.Packet; +import org.bukkit.potion.PotionEffect; +import org.bukkit.projectiles.ProjectileSource; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import static net.tylermurphy.hideAndSeek.configuration.Localization.*; + +public class EventListener implements Listener { + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerJoin(PlayerJoinEvent event) { + Board.remove(event.getPlayer()); + Game.removeItems(event.getPlayer()); + if(Game.isNotSetup()) return; + if(autoJoin){ + Game.join(event.getPlayer()); + } else if(teleportToExit) { + if (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld) || event.getPlayer().getWorld().getName().equals(lobbyWorld)) { + event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + event.getPlayer().setGameMode(GameMode.ADVENTURE); + } + } else { + if (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld)) { + if(Game.status != Status.STANDBY){ + Game.join(event.getPlayer()); + } else { + event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + event.getPlayer().setGameMode(GameMode.ADVENTURE); + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onQuit(PlayerQuitEvent event) { + Board.remove(event.getPlayer()); + if(Game.status == Status.STANDBY) { + Board.reloadLobbyBoards(); + } else { + Board.reloadGameBoards(); + } + for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ + event.getPlayer().removePotionEffect(effect.getType()); + } + Game.removeItems(event.getPlayer()); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onKick(PlayerKickEvent event) { + Board.remove(event.getPlayer()); + if(Game.status == Status.STANDBY) { + Board.reloadLobbyBoards(); + } else { + Board.reloadGameBoards(); + } + for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ + event.getPlayer().removePotionEffect(effect.getType()); + } + Game.removeItems(event.getPlayer()); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onChat(AsyncPlayerChatEvent event){ + if(Board.isSeeker(event.getPlayer())){ + event.setCancelled(true); + Board.getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage())); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onMove(PlayerMoveEvent event){ + if(!event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld)) return; + if(event.getPlayer().hasPermission("hideandseek.leavebounds")) return; + if(event.getTo() == null || event.getTo().getWorld() == null) return; + if(!event.getTo().getWorld().getName().equals("hideandseek_" + spawnWorld)) return; + if(event.getTo().getBlockX() < saveMinX || event.getTo().getBlockX() > saveMaxX || event.getTo().getBlockZ() < saveMinZ || event.getTo().getBlockZ() > saveMaxZ){ + event.setCancelled(true); + } + } + + public static final Map temp_loc = new HashMap<>(); + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerDeath(PlayerDeathEvent event){ + Player player = event.getEntity(); + if(!Board.isPlayer(player)) return; + event.setKeepInventory(true); + event.setDeathMessage(""); + temp_loc.put(player.getUniqueId(), player.getLocation()); + Main.plugin.getLogger().severe("Player "+player.getName() + " died when not supposed to. Attempting to roll back death."); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerRespawn(PlayerRespawnEvent event){ + Player player = event.getPlayer(); + if(!Board.isPlayer(player)) return; + if(temp_loc.containsKey(player.getUniqueId())){ + player.teleport(temp_loc.get(player.getUniqueId())); + temp_loc.remove(player.getUniqueId()); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onEntityDamage(EntityDamageEvent event) { + try { + if (event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + if (!Board.isPlayer(player)) { + if (event instanceof EntityDamageByEntityEvent) { + Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); + if (damager instanceof Player) { + if(Board.isPlayer(damager)){ + event.setCancelled(true); + return; + } + } + } + } + if (Game.status != Status.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 (Board.onSameTeam(player, attacker)) event.setCancelled(true); + if (Board.isSpectator(player)) event.setCancelled(true); + } else if(damager instanceof Arrow){ + ProjectileSource source = ((Arrow) damager).getShooter(); + if(source instanceof Player){ + attacker = (Player) source; + if (Board.onSameTeam(player, attacker)) event.setCancelled(true); + if (Board.isSpectator(player)) event.setCancelled(true); + } + } + } + if (player.getHealth() - event.getDamage() < 0 || !pvpEnabled) { + if (spawnPosition == null) return; + event.setCancelled(true); + AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); + if(attribute != null) + player.setHealth(attribute.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 (Board.isSeeker(player)) { + Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString()); + } + if (Board.isHider(player)) { + if (attacker == null) { + Game.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(player).toString()); + } else { + Game.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(player).addPlayer(attacker).toString()); + } + Board.addSeeker(player); + } + Game.resetPlayer(player); + Board.reloadBoardTeams(); + } + } + } catch (Exception e){ + Main.plugin.getLogger().severe("Entity Damage Event Error: " + e.getMessage()); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onProjectile(ProjectileLaunchEvent event) { + if(Game.status != Status.PLAYING) return; + if(event.getEntity() instanceof Snowball) { + if(!glowEnabled) return; + Snowball snowball = (Snowball) event.getEntity(); + if(snowball.getShooter() instanceof Player) { + Player player = (Player) snowball.getShooter(); + if(Board.isHider(player)) { + Game.glow.onProjectile(); + snowball.remove(); + player.getInventory().remove(Material.SNOWBALL); + } + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onFoodLevelChange(FoodLevelChangeEvent event) { + if(event.getEntity() instanceof Player) { + if(!Board.isPlayer((Player) event.getEntity())) return; + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerRegainHealth(EntityRegainHealthEvent event) { + if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) { + if(event.getEntity() instanceof Player) { + if(!Board.isPlayer((Player) event.getEntity())) return; + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerCommand(PlayerCommandPreprocessEvent event) { + Player player = event.getPlayer(); + String message = event.getMessage(); + String[] array = message.split(" "); + if(array[0].equalsIgnoreCase("/kill")){ + if(Board.isPlayer(player)){ + Main.plugin.getLogger().info("Blocking "+player.getName()+ "from running /kill with anyone associated in the lobby"); + event.setCancelled(true); + } else if(array.length > 1){ + for(int i=1; i. + * + */ + +package net.tylermurphy.hideAndSeek.game; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +import net.md_5.bungee.api.ChatColor; +import net.tylermurphy.hideAndSeek.configuration.Items; +import net.tylermurphy.hideAndSeek.database.Database; +import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.util.WinType; +import net.tylermurphy.hideAndSeek.world.WorldLoader; +import org.bukkit.*; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Firework; +import org.bukkit.entity.Player; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.Packet; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.FireworkMeta; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.beans.EventHandler; +import java.io.File; +import java.util.*; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Localization.*; +import static net.tylermurphy.hideAndSeek.game.Game.broadcastMessage; + +public class Game { + + public static Taunt taunt; + public static Glow glow; + public static Border worldBorder; + public static WorldLoader worldLoader; + public static int tick = 0; + public static int countdownTime = -1; + public static int gameId = 0; + public static int timeLeft = 0; + public static Status status = Status.STANDBY; + + static { + worldLoader = new WorldLoader(spawnWorld); + } + + public static void start(Player seeker){ + if(status == Status.STARTING || status == Status.PLAYING) return; + if(worldLoader.getWorld() != null) { + worldLoader.rollback(); + } else { + worldLoader.loadMap(); + } + Board.reload(); + for(Player temp : Board.getPlayers()) { + if(temp.getName().equals(seeker.getName())) + continue; + Board.addHider(temp); + } + Board.addSeeker(seeker); + currentWorldborderSize = worldborderSize; + for(Player player : Board.getPlayers()) { + player.getInventory().clear(); + player.setGameMode(GameMode.ADVENTURE); + player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + for(PotionEffect effect : player.getActivePotionEffects()){ + player.removePotionEffect(effect.getType()); + } + } + for(Player player : Board.getSeekers()) { + 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 + message("SEEKERS_SUBTITLE").toString(), 10, 70, 20); + } + for(Player player : Board.getHiders()) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); + player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString(), 10, 70, 20); + } + if(tauntEnabled) + taunt = new Taunt(); + if (glowEnabled) + glow = new Glow(); + worldBorder = new Border(); + worldBorder.resetWorldborder("hideandseek_"+spawnWorld); + if(gameLength > 0) + timeLeft = gameLength; + for(Player player : Board.getPlayers()) + Board.createGameBoard(player); + Board.reloadGameBoards(); + status = Status.STARTING; + int temp = gameId; + broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30)); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), gameId, 20 * 10); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), gameId, 20 * 20); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), gameId, 20 * 25); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), gameId, 20 * 27); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), gameId, 20 * 28); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), gameId, 20 * 29); + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, () -> { + if(temp != gameId) return; + broadcastMessage(messagePrefix + message("START")); + for(Player player : Board.getPlayers()) resetPlayer(player); + status = Status.PLAYING; + }, 20 * 30); + } + + public static void stop(WinType type){ + if(status == Status.STANDBY) return; + tick = 0; + countdownTime = -1; + status = Status.STANDBY; + gameId++; + timeLeft = 0; + List players = Board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList()); + if(type == WinType.HIDER_WIN){ + List winners = Board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList()); + Database.playerInfo.addWins(players, winners, type); + } else if(type == WinType.SEEKER_WIN){ + List winners = new ArrayList<>(); + winners.add(Board.getFirstSeeker().getUniqueId()); + Database.playerInfo.addWins(players, winners, type); + } + worldBorder.resetWorldborder("hideandseek_"+spawnWorld); + for(Player player : Board.getPlayers()) { + Board.createLobbyBoard(player); + player.setGameMode(GameMode.ADVENTURE); + Board.addHider(player); + player.getInventory().clear(); + player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); + for(PotionEffect effect : player.getActivePotionEffects()){ + player.removePotionEffect(effect.getType()); + } + player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); + for(Player temp : Board.getPlayers()) { + Packet.setGlow(player, temp, false); + } + } + EventListener.temp_loc.clear(); + worldLoader.unloadMap(); + Board.reloadLobbyBoards(); + } + + public static boolean isNotSetup() { + if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true; + if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true; + if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true; + File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); + if(!destenation.exists()) return true; + return saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0; + } + + public static void onTick() { + if(isNotSetup()) return; + if(status == Status.STANDBY) whileWaiting(); + else if(status == Status.STARTING) whileStarting(); + else if(status == Status.PLAYING) whilePlaying(); + tick++; + } + + public static void resetWorldborder(String worldName){ + worldBorder.resetWorldborder(worldName); + } + + public static void broadcastMessage(String message) { + for(Player player : Board.getPlayers()) { + player.sendMessage(message); + } + } + + public static void resetPlayer(Player player) { + player.getInventory().clear(); + for (PotionEffect effect : player.getActivePotionEffects()) { + player.removePotionEffect(effect.getType()); + } + if (Board.isSeeker(player)) { + if(pvpEnabled) + for(ItemStack item : Items.SEEKER_ITEMS) + player.getInventory().addItem(item); + for(PotionEffect effect : Items.SEEKER_EFFECTS) + player.addPotionEffect(effect); + } else if (Board.isHider(player)) { + if(pvpEnabled) + for(ItemStack item : Items.HIDER_ITEMS) + player.getInventory().addItem(item); + for(PotionEffect effect : Items.HIDER_EFFECTS) + player.addPotionEffect(effect); + if(glowEnabled) { + ItemStack snowball = new ItemStack(Material.SNOWBALL, 1); + ItemMeta snowballMeta = snowball.getItemMeta(); + assert snowballMeta != null; + snowballMeta.setDisplayName("Glow Powerup"); + List snowballLore = new ArrayList<>(); + snowballLore.add("Throw to make all seekers glow"); + snowballLore.add("Last 30s, all hiders can see it"); + snowballLore.add("Time stacks on multi use"); + snowballMeta.setLore(snowballLore); + snowball.setItemMeta(snowballMeta); + player.getInventory().addItem(snowball); + } + } + } + + public static void join(Player player){ + if(Game.status == Status.STANDBY) { + player.getInventory().clear(); + Board.addHider(player); + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); + else Game.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); + player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); + player.setGameMode(GameMode.ADVENTURE); + Board.createLobbyBoard(player); + Board.reloadLobbyBoards(); + } else { + Board.addSpectator(player); + player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR")); + player.setGameMode(GameMode.SPECTATOR); + Board.createGameBoard(player); + player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + player.sendTitle(ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString(), 10, 70, 20); + } + + player.setFoodLevel(20); + player.setHealth(Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getBaseValue()); + } + + public static void removeItems(Player player){ + for(ItemStack si : Items.SEEKER_ITEMS) + for(ItemStack i : player.getInventory().getContents()) + if(si.isSimilar(i)) player.getInventory().remove(i); + for(ItemStack hi : Items.HIDER_ITEMS) + for(ItemStack i : player.getInventory().getContents()) + if(hi.isSimilar(i)) player.getInventory().remove(i); + } + + private static void whileWaiting() { + if(lobbyCountdownEnabled){ + if(lobbyMin <= Board.size()){ + if(countdownTime == -1) + countdownTime = countdown; + if(Board.size() >= changeCountdown) + countdownTime = Math.min(countdownTime, 10); + if(tick % 20 == 0) + countdownTime--; + if(countdownTime == 0){ + Optional rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst(); + if(!rand.isPresent()){ + Main.plugin.getLogger().warning("Failed to select random seeker."); + return; + } + String seekerName = rand.get().getName(); + Player seeker = Board.getPlayer(seekerName); + start(seeker); + } + } else { + countdownTime = -1; + } + } + } + + private static void whileStarting(){ + checkWinConditions(); + } + + private static void whilePlaying() { + for(Player hider : Board.getHiders()) { + int distance = 100, temp = 100; + for(Player seeker : Board.getSeekers()) { + try { + temp = (int) hider.getLocation().distance(seeker.getLocation()); + } catch (Exception e){ + //Players in different worlds, NOT OK!!! + } + if(distance > temp) { + distance = temp; + } + } + switch(tick%10) { + case 0: + if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f); + if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + break; + case 3: + if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f); + if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + break; + case 6: + if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + break; + case 9: + if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + break; + } + } + if(tick%20 == 0) { + if(gameLength > 0) { + Board.reloadGameBoards(); + timeLeft--; + } + if(worldborderEnabled) worldBorder.update(); + if(tauntEnabled) taunt.update(); + if (glowEnabled) glow.update(); + } + checkWinConditions(); + } + + private static void checkWinConditions(){ + if(Board.sizeHider() < 1) { + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); + else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); + stop(WinType.SEEKER_WIN); + } else if(Board.sizeSeeker() < 1) { + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); + else broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); + stop(WinType.NONE); + } else if(timeLeft < 1) { + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); + else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); + stop(WinType.HIDER_WIN); + } + } + + private static void sendDelayedMessage(String message, int gameId, int delay) { + Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, () -> { + if(gameId == Game.gameId) + broadcastMessage(message); + }, delay); + } + +} + +class Glow { + + private int glowTime; + private boolean running; + + public Glow() { + this.glowTime = 0; + } + + public void onProjectile() { + if(glowStackable) glowTime += glowLength; + else glowTime = glowLength; + if(!running) + startGlow(); + } + + private void startGlow() { + running = true; + for(Player hider : Board.getHiders()) { + for(Player seeker : Board.getSeekers()) { + Packet.setGlow(hider, seeker, true); + } + } + } + + protected void update() { + if(running) { + glowTime--; + glowTime = Math.max(glowTime, 0); + if (glowTime == 0) { + stopGlow(); + } + } + } + + private void stopGlow() { + running = false; + for(Player hider : Board.getHiders()) { + for (Player seeker : Board.getSeekers()) { + Packet.setGlow(hider, seeker, false); + } + } + } + + public boolean isRunning() { + return running; + } + +} + +class Taunt { + + private String tauntPlayer; + private int delay; + private boolean running; + + public Taunt() { + this.delay = tauntDelay; + } + + protected void update() { + if(delay == 0) { + if(running) launchTaunt(); + else if(tauntLast || Board.sizeHider() > 1) executeTaunt(); + } else { + delay--; + delay = Math.max(delay, 0); + } + } + + private void executeTaunt() { + Optional rand = Board.getHiders().stream().skip(new Random().nextInt(Board.size())).findFirst(); + if(!rand.isPresent()){ + Main.plugin.getLogger().warning("Failed to select random seeker."); + return; + } + Player taunted = rand.get(); + taunted.sendMessage(message("TAUNTED").toString()); + broadcastMessage(tauntPrefix + message("TAUNT")); + tauntPlayer = taunted.getName(); + running = true; + delay = 30; + } + + private void launchTaunt(){ + Player taunted = Board.getPlayer(tauntPlayer); + if(taunted != null) { + if(!Board.isHider(taunted)){ + Main.plugin.getLogger().info("Taunted played died and is now seeker. Skipping taunt."); + tauntPlayer = ""; + running = false; + delay = tauntDelay; + return; + } + World world = taunted.getLocation().getWorld(); + if(world == null){ + Main.plugin.getLogger().severe("Game world is null while trying to launch taunt."); + tauntPlayer = ""; + running = false; + delay = tauntDelay; + return; + } + Firework fw = (Firework) world.spawnEntity(taunted.getLocation(), EntityType.FIREWORK); + FireworkMeta fwm = fw.getFireworkMeta(); + fwm.setPower(4); + fwm.addEffect(FireworkEffect.builder() + .withColor(Color.BLUE) + .withColor(Color.RED) + .withColor(Color.YELLOW) + .with(FireworkEffect.Type.STAR) + .with(FireworkEffect.Type.BALL) + .with(FireworkEffect.Type.BALL_LARGE) + .flicker(true) + .withTrail() + .build()); + fw.setFireworkMeta(fwm); + broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE")); + } + tauntPlayer = ""; + running = false; + delay = tauntDelay; + } + + public int getDelay(){ + return delay; + } + + public boolean isRunning() { + return running; + } + +} + +class Border { + + private int delay; + private boolean running; + + public Border() { + delay = 60 * worldborderDelay; + } + + void update(){ + if(delay == 30 && !running){ + broadcastMessage(worldborderPrefix + message("WORLDBORDER_WARN")); + } else if(delay == 0){ + if(running){ + delay = 60 * worldborderDelay; + running = false; + } + else decreaceWorldborder(); + } + delay--; + } + + private void decreaceWorldborder() { + if(currentWorldborderSize-100 > 100) { + running = true; + broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING")); + currentWorldborderSize -= 100; + World world = Bukkit.getWorld("hideandseek_"+spawnWorld); + assert world != null; + org.bukkit.WorldBorder border = world.getWorldBorder(); + border.setSize(border.getSize()-100,30); + delay = 30; + } + } + + public void resetWorldborder(String worldName) { + World world = Bukkit.getWorld(worldName); + assert world != null; + org.bukkit.WorldBorder border = world.getWorldBorder(); + if(worldborderEnabled) { + border.setSize(worldborderSize); + border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ()); + currentWorldborderSize = worldborderSize; + } else { + border.setSize(30000000); + border.setCenter(0, 0); + } + } + + public int getDelay(){ + return delay; + } + + public boolean isRunning() { + return running; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java deleted file mode 100644 index 9d856b5..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java +++ /dev/null @@ -1,257 +0,0 @@ -package net.tylermurphy.hideAndSeek.util; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Score; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; -import org.bukkit.scoreboard.Team.Option; -import org.bukkit.scoreboard.Team.OptionStatus; - -import net.tylermurphy.hideAndSeek.Main; - -public class Board { - - private List Hider, Seeker, Spectator; - private Map playerList = new HashMap(); - private Map customBoards = new HashMap(); - - public boolean isPlayer(Player player) { - return playerList.containsKey(player.getName()); - } - - public boolean isPlayer(CommandSender sender) { - return playerList.containsKey(sender.getName()); - } - - public boolean isHider(Player player) { - return Hider.contains(player.getName()); - } - - public boolean isSeeker(Player player) { - return Seeker.contains(player.getName()); - } - - public boolean isSpectator(Player player) { - return Spectator.contains(player.getName()); - } - - public int sizeHider() { - return Hider.size(); - } - - public int sizeSeeker() { - return Seeker.size(); - } - - public int sizeSpectator() { - return Spectator.size(); - } - - public int size() { - return playerList.values().size(); - } - - public List getHiders(){ - return Hider.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList()); - } - - public List getSeekers(){ - return Seeker.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList()); - } - - public List getSpectators(){ - return Spectator.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList()); - } - - public List getPlayers(){ - return new ArrayList(playerList.values()); - } - - public Player getPlayer(String name) { - return playerList.get(name); - } - - public void addHider(Player player) { - Hider.add(player.getName()); - Seeker.remove(player.getName()); - Spectator.remove(player.getName()); - playerList.put(player.getName(), player); - } - - public void addSeeker(Player player) { - Hider.remove(player.getName()); - Seeker.add(player.getName()); - Spectator.remove(player.getName()); - playerList.put(player.getName(), player); - } - - public void addSpectator(Player player) { - Hider.remove(player.getName()); - Seeker.remove(player.getName()); - Spectator.add(player.getName()); - playerList.put(player.getName(), player); - } - - public void remove(Player player) { - Hider.remove(player.getName()); - Seeker.remove(player.getName()); - Spectator.remove(player.getName()); - playerList.remove(player.getName()); - } - - public boolean onSameTeam(Player player1, Player player2) { - if(Hider.contains(player1.getName()) && Hider.contains(player2.getName())) return true; - else if(Seeker.contains(player1.getName()) && Seeker.contains(player2.getName())) return true; - else if(Spectator.contains(player1.getName()) && Spectator.contains(player2.getName())) return true; - else return false; - } - - public void reload() { - Hider = new ArrayList(); - Seeker = new ArrayList(); - Spectator = new ArrayList(); - } - - public void reset() { - Hider.clear(); - Seeker.clear(); - Spectator.clear(); - } - - private void createTeamsForBoard(Scoreboard board) { - Team hiderTeam = board.registerNewTeam("Hider"); - for(String name : Hider) - hiderTeam.addEntry(name); - Team seekerTeam = board.registerNewTeam("Seeker"); - for(String name : Seeker) - seekerTeam.addEntry(name); - if(nametagsVisible) { - hiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM); - seekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OTHER_TEAMS); - } else { - hiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - seekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - } - } - - public void createLobbyBoard(Player player) { - createLobbyBoard(player, true); - } - - private void createLobbyBoard(Player player, boolean recreate) { - CustomBoard board = customBoards.get(player.getName()); - if(recreate) { - board = new CustomBoard(player, "&l&eHIDE AND SEEK"); - board.updateTeams(); - } - board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER%" + ChatColor.WHITE + getHiderPercent()); - board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER%" + ChatColor.WHITE + getSeekerPercent()); - board.addBlank(); - board.setLine("players", "Players: " + playerList.values().size()); - board.addBlank(); - board.setLine("waiting", "Waiting to start..."); - board.display(); - customBoards.put(player.getName(), board); - } - - public void createGameBoard(Player player){ - createGameBoard(player, true); - } - - private void createGameBoard(Player player, boolean recreate){ - CustomBoard board = customBoards.get(player.getName()); - if(recreate) { - board = new CustomBoard(player, "&l&eHIDE AND SEEK"); - } - board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDERS:" + ChatColor.WHITE + " " + Hider.size()); - board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size()); - board.addBlank(); - if(glowEnabled){ - if(Main.plugin.glow == null || Main.plugin.status.equals("Starting") || !Main.plugin.glow.isRunning()) - board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive"); - else - board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active"); - } - if(tauntEnabled && tauntCountdown){ - if(Main.plugin.taunt == null || Main.plugin.status.equals("Starting")) - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s"); - else if(!tauntLast && Hider.size() == 1){ - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired"); - } else if(!Main.plugin.taunt.isRunning()) - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Main.plugin.taunt.getDelay()/60 + "m" + Main.plugin.taunt.getDelay()%60 + "s"); - else - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active"); - } - if(worldborderEnabled){ - if(Main.plugin.worldborder == null || Main.plugin.status.equals("Starting")){ - board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s"); - } else if(!Main.plugin.worldborder.isRunning()) { - board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Main.plugin.worldborder.getDelay()/60 + "m" + Main.plugin.worldborder.getDelay()%60 + "s"); - } else { - board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "Decreasing"); - } - } - if(glowEnabled || (tauntEnabled && tauntCountdown) || worldborderEnabled) - board.addBlank(); - board.setLine("time", "Time Left: " + ChatColor.GREEN + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s"); - board.addBlank(); - board.setLine("team", "Team: " + getTeam(player)); - board.display(); - customBoards.put(player.getName(), board); - } - - public void removeBoard(Player player) { - player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); - customBoards.remove(player.getName()); - } - - public void reloadLobbyBoards() { - for(Player player : playerList.values()) - createLobbyBoard(player, false); - } - - public void reloadGameBoards() { - for(Player player : playerList.values()) - createGameBoard(player, false); - } - - public void reloadBoardTeams() { - for(CustomBoard board : customBoards.values()) - board.updateTeams(); - } - - private String getSeekerPercent() { - if(playerList.values().size() < 2) - return " --"; - else - return " "+(int)(100*(1.0/playerList.size())); - } - - private String getHiderPercent() { - if(playerList.size() < 2) - return " --"; - else - return " "+(int)(100-100*(1.0/playerList.size())); - } - - private String getTeam(Player player) { - if(isHider(player)) return ChatColor.GOLD + "HIDER"; - else if(isSeeker(player)) return ChatColor.RED + "SEEKER"; - else if(isSpectator(player)) return ChatColor.GRAY + "SPECTATOR"; - else return ChatColor.WHITE + "UNKNOWN"; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java deleted file mode 100644 index 69d865a..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java +++ /dev/null @@ -1,121 +0,0 @@ -package net.tylermurphy.hideAndSeek.util; - -import net.tylermurphy.hideAndSeek.Main; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.scoreboard.*; - -import java.util.HashMap; -import java.util.Map; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -public class CustomBoard { - - private final Scoreboard board; - private final Objective obj; - private final Player player; - private final Map LINES; - private int blanks; - private boolean displayed; - - public CustomBoard(Player player, String title){ - this.board = Bukkit.getScoreboardManager().getNewScoreboard(); - this.LINES = new HashMap(); - this.player = player; - this.obj = board.registerNewObjective( - "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title)); - this.blanks = 0; - this.displayed = false; - this.updateTeams(); - } - - public void updateTeams() { - try{ board.registerNewTeam("Hider"); } catch (Exception e){} - try{ board.registerNewTeam("Seeker"); } catch (Exception e){} - Team hiderTeam = board.getTeam("Hider"); - for(String entry : hiderTeam.getEntries()) - hiderTeam.removeEntry(entry); - for(Player player : Main.plugin.board.getHiders()) - hiderTeam.addEntry(player.getName()); - Team seekerTeam = board.getTeam("Seeker"); - for(String entry : seekerTeam.getEntries()) - seekerTeam.removeEntry(entry); - for(Player player : Main.plugin.board.getSeekers()) - seekerTeam.addEntry(player.getName()); - if(nametagsVisible) { - hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); - seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS); - } else { - hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); - seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); - } - hiderTeam.setColor(ChatColor.GOLD); - seekerTeam.setColor(ChatColor.RED); - } - - public void setLine(String key, String message){ - Line line = LINES.get(key); - if(line == null) - addLine(key, message); - else - updateLine(key, message); - } - - private void addLine(String key, String message){ - Score score = obj.getScore(message); - score.setScore(LINES.values().size()+1); - Line line = new Line(LINES.values().size()+1, message); - LINES.put(key, line); - } - - public void addBlank(){ - if(displayed) return; - String temp = ""; - for(int i = 0; i <= blanks; i ++) - temp += ChatColor.RESET; - blanks++; - addLine("blank"+blanks, temp); - } - - private void updateLine(String key, String message){ - Line line = LINES.get(key); - board.resetScores(line.getMessage()); - line.setMessage(message); - Score newScore = obj.getScore(message); - - newScore.setScore(line.getScore()); - } - - public void display() { - displayed = true; - obj.setDisplaySlot(DisplaySlot.SIDEBAR); - player.setScoreboard(board); - } - -} - -class Line { - - private int score; - private String message; - - public Line(int score, String message){ - this.score = score; - this.message = message; - } - - public int getScore() { - return score; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java index 564916a..18913da 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java @@ -1,3 +1,22 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.util; import java.lang.reflect.InvocationTargetException; @@ -16,7 +35,7 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; public class Packet { - private static ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); + private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); public static void playSound(Player player, Sound sound, float volume, float pitch) { PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.NAMED_SOUND_EFFECT); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java new file mode 100644 index 0000000..44a3e42 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java @@ -0,0 +1,26 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.util; + +public enum Status { + STANDBY, + STARTING, + PLAYING +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/TabCompleter.java b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java similarity index 52% rename from src/main/java/net/tylermurphy/hideAndSeek/bukkit/TabCompleter.java rename to src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java index 2f7dbd4..4c949e1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/TabCompleter.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java @@ -1,18 +1,37 @@ -package net.tylermurphy.hideAndSeek.bukkit; +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.util; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.stream.Collectors; -import org.bukkit.command.Command; +import net.tylermurphy.hideAndSeek.game.CommandHandler; import org.bukkit.command.CommandSender; public class TabCompleter{ - public static List handleTabComplete(CommandSender sender, Command command, String label, String[] args) { + public static List handleTabComplete(CommandSender sender, String[] args) { if(args.length == 1) { - return new ArrayList(CommandHandler.COMMAND_REGISTER.keySet()) + return new ArrayList<>(CommandHandler.COMMAND_REGISTER.keySet()) .stream() .filter(handle -> sender.hasPermission("hideandseek."+handle.toLowerCase()) && handle.toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT))) .collect(Collectors.toList()); @@ -26,7 +45,7 @@ public class TabCompleter{ if(parameter.equals("")) { return null; } else { - List temp = new ArrayList(); + List temp = new ArrayList<>(); temp.add(parameter.replace("<", "").replace(">", "")); return temp; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java b/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java new file mode 100644 index 0000000..ef65af3 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java @@ -0,0 +1,106 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.util; + +import net.tylermurphy.hideAndSeek.Main; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public final class UUIDFetcher { + + private static final Map CACHE = new HashMap<>(); + + private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/"; + private static int cacheTask; + + public static void init(){ + cacheTask = Main.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, CACHE::clear,600*20, 600*20); + } + + public static void cleanup(){ + Main.plugin.getServer().getScheduler().cancelTask(cacheTask); + } + + public static UUID getUUID(String playername) { + + if(CACHE.containsKey(playername)) return CACHE.get(playername); + + String output = callURL(UUID_URL + playername); + StringBuilder result = new StringBuilder(); + readData(output, result); + String u = result.toString(); + StringBuilder uuid = new StringBuilder(); + for (int i = 0; i <= 31; i++) { + uuid.append(u.charAt(i)); + if (i == 7 || i == 11 || i == 15 || i == 19) { + uuid.append('-'); + } + } + + CACHE.put(playername, UUID.fromString(uuid.toString())); + + return UUID.fromString(uuid.toString()); + } + + private static void readData(String toRead, StringBuilder result) { + for (int i = toRead.length() - 3; i >= 0; i--) { + if (toRead.charAt(i) != '"') { + result.insert(0, toRead.charAt(i)); + } else { + break; + } + } + } + + private static String callURL(String urlStr) { + StringBuilder sb = new StringBuilder(); + URLConnection urlConn; + InputStreamReader in; + try { + URL url = new URL(urlStr); + urlConn = url.openConnection(); + if (urlConn != null) { + urlConn.setReadTimeout(60 * 1000); + } + if (urlConn != null && urlConn.getInputStream() != null) { + in = new InputStreamReader(urlConn.getInputStream(), + Charset.defaultCharset()); + BufferedReader bufferedReader = new BufferedReader(in); + int cp; + while ((cp = bufferedReader.read()) != -1) { + sb.append((char) cp); + } + bufferedReader.close(); + in.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sb.toString(); + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java deleted file mode 100644 index c24936b..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java +++ /dev/null @@ -1,85 +0,0 @@ -package net.tylermurphy.hideAndSeek.util; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -import java.io.*; -import java.util.ArrayList; -import java.util.List; - -import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.configuration.Items; -import net.tylermurphy.hideAndSeek.configuration.LocalizationString; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; - -import net.tylermurphy.hideAndSeek.Main; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; - -public class Util { - - public static void broadcastMessage(String message) { - for(Player player : Main.plugin.board.getPlayers()) { - player.sendMessage(message); - } - } - - public static boolean isSetup() { - 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; - if(saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) return false; - return true; - } - - public static void sendDelayedMessage(String message, int gameId, int delay) { - Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, new Runnable() { - public void run() { - if(gameId == Main.plugin.gameId) - Util.broadcastMessage(message); - } - }, delay); - } - - public static void resetPlayer(Player player) { - player.getInventory().clear(); - for (PotionEffect effect : player.getActivePotionEffects()) { - player.removePotionEffect(effect.getType()); - } - if (Main.plugin.board.isSeeker(player)) { - if(pvpEnabled) - for(ItemStack item : Items.SEEKER_ITEMS) - player.getInventory().addItem(item); - for(PotionEffect effect : Items.SEEKER_EFFECTS) - player.addPotionEffect(effect); - } else if (Main.plugin.board.isHider(player)) { - if(pvpEnabled) - for(ItemStack item : Items.HIDER_ITEMS) - player.getInventory().addItem(item); - for(PotionEffect effect : Items.HIDER_EFFECTS) - player.addPotionEffect(effect); - if(glowEnabled) { - ItemStack snowball = new ItemStack(Material.SNOWBALL, 1); - ItemMeta snowballMeta = snowball.getItemMeta(); - snowballMeta.setDisplayName("Glow Powerup"); - List snowballLore = new ArrayList(); - snowballLore.add("Throw to make all seekers glow"); - snowballLore.add("Last 30s, all hiders can see it"); - snowballLore.add("Time stacks on multi use"); - snowballMeta.setLore(snowballLore); - snowball.setItemMeta(snowballMeta); - player.getInventory().addItem(snowball); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java b/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java new file mode 100644 index 0000000..3c555cc --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java @@ -0,0 +1,26 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.util; + +public enum WinType { + HIDER_WIN, + SEEKER_WIN, + NONE +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java index 46636cf..7b12767 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java @@ -1,3 +1,22 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.world; import java.util.Collections; @@ -7,11 +26,12 @@ import java.util.Random; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; +import org.jetbrains.annotations.NotNull; public class VoidGenerator extends ChunkGenerator{ - public List getDefaultPopulators(World world) { - return Collections.emptyList(); + public @NotNull List getDefaultPopulators(@NotNull World world) { + return Collections.emptyList(); } public boolean shouldGenerateNoise() { @@ -42,10 +62,11 @@ public class VoidGenerator extends ChunkGenerator{ return false; } - public boolean canSpawn(World world, int x, int z) { + public boolean canSpawn(@NotNull World world, int x, int z) { return true; } - public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { return createChunkData(world); } - + // Backwards compatibility + public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) { return createChunkData(world); } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 5a8c324..5d6e377 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -1,3 +1,22 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.world; import static net.tylermurphy.hideAndSeek.configuration.Config.*; @@ -11,6 +30,7 @@ import java.io.InputStream; import java.io.OutputStream; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.WorldCreator; import net.tylermurphy.hideAndSeek.Main; @@ -25,8 +45,17 @@ public class WorldLoader { this.savename = "hideandseek_"+mapname; } + public World getWorld(){ + return Bukkit.getServer().getWorld(savename); + } + public void unloadMap(){ - if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(savename), false)){ + World world = Bukkit.getServer().getWorld(savename); + if(world == null){ + Main.plugin.getLogger().warning(savename + " already unloaded."); + return; + } + if(Bukkit.getServer().unloadWorld(world, false)){ Main.plugin.getLogger().info("Successfully unloaded " + savename); }else{ Main.plugin.getLogger().severe("COULD NOT UNLOAD " + savename); @@ -35,7 +64,12 @@ public class WorldLoader { public void loadMap(){ Bukkit.getServer().createWorld(new WorldCreator(savename).generator(new VoidGenerator())); - Bukkit.getServer().getWorld(savename).setAutoSave(false); + World world = Bukkit.getServer().getWorld(savename); + if(world == null){ + Main.plugin.getLogger().severe("COULD NOT LOAD " + savename); + return; + } + world.setAutoSave(false); } public void rollback(){ @@ -57,9 +91,13 @@ public class WorldLoader { copyFile(srcFile,destFile); if(destenation.exists()) { deleteDirectory(destenation); - destenation.mkdir(); + if(!destenation.mkdir()){ + throw new RuntimeException("Failed to create directory: "+destenation.getPath()); + } + } + if(!temp_destenation.renameTo(destenation)){ + throw new RuntimeException("Failed to rename directory: "+temp_destenation.getPath()); } - temp_destenation.renameTo(destenation); } catch(IOException e) { e.printStackTrace(); return errorPrefix + message("COMMAND_ERROR"); @@ -77,7 +115,11 @@ public class WorldLoader { if(!temp.exists()) if(!temp.mkdirs()) throw new IOException("Couldn't create region directory!"); - String files[] = region.list(); + String[] files = region.list(); + if(files == null){ + Main.plugin.getLogger().severe("Region directory is null or cannot be accessed"); + return; + } for (String file : files) { if(isMca) { @@ -86,7 +128,7 @@ public class WorldLoader { int maxX = (int)Math.floor(saveMaxX / 32.0); int maxZ = (int)Math.floor(saveMaxZ / 32.0); - String[] parts = file.split("."); + String[] parts = file.split("\\."); if(parts.length > 1) { Main.plugin.getLogger().info(file); if( Integer.parseInt(parts[1]) < minX || Integer.parseInt(parts[1]) > maxX ||Integer.parseInt(parts[2]) < minZ || Integer.parseInt(parts[2]) > maxZ ) @@ -116,14 +158,16 @@ public class WorldLoader { out.close(); } - private boolean deleteDirectory(File directoryToBeDeleted) { + private void deleteDirectory(File directoryToBeDeleted) { File[] allContents = directoryToBeDeleted.listFiles(); if (allContents != null) { for (File file : allContents) { deleteDirectory(file); } } - return directoryToBeDeleted.delete(); + if(!directoryToBeDeleted.delete()){ + throw new RuntimeException("Failed to delete directory: "+directoryToBeDeleted.getPath()); + } } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7366476..778e3b4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -79,9 +79,20 @@ prefix: gameover: '&aGame Over > &f' warning: '&cWarning > &f' +# This is the section if you want a standard "waiting for players" lobby. You can specify +# the standard countdown length under [countdown] (min 10 seconds). Then once the lobby gets to a size specified +# by [changeCountdown], the timer will automatically go to 10 seconds. [min] is the minimum players +# to start the countdown. [max] is the lobby cap, set to -1 to remove maximum cap. +lobby: + countdown: 60 + changeCountdown: 5 + min: 3 + max: 10 + enabled: true + # Changes the default plugin language. Currently, Supported localizations are: -# en-US (United States) -# de-DE (German) +# en-US (English - United States) +# de-DE (German - Germany) local: "en-US" # ---------------------------------------------------------- # diff --git a/src/main/resources/lang/localization_de-DE.yml b/src/main/resources/lang/localization_de-DE.yml index c5b0b72..d2dcc1e 100644 --- a/src/main/resources/lang/localization_de-DE.yml +++ b/src/main/resources/lang/localization_de-DE.yml @@ -36,6 +36,7 @@ Localization: WORLDBORDER_POSITION: "Spawn muss mindestens 100 Blöcke vom Zentrum der World Border entfernt sein." WORLDBORDER_ENABLE: "Setze World Border zentriert von dieser Position aus. Größe: {AMOUNT}. Verzögerung: {AMOUNT}." WORLDBORDER_DECREASING: "World Norder schrumpoft 100 Blöcke über die nächsten 30 Sekunden!" + WORLDBORDER_WARN: "Die Weltgrenze wird in den nächsten 30er Jahren schrumpfen!" TAUNTED: "$c$oOh nein! Du wurdest geärgert!" TAUNT: "Ein zufälliger Hider wird in den nächsten 30 Sekunden geärgert." TAUNT_ACTIVATE: "Ärgern wurde aktiviert" @@ -46,7 +47,7 @@ Localization: SETUP_EXIT: "&c&l- &fTeleport-Position für das Spielende festlegen mit /hs setexit" SETUP_SAVEMAP: "&c&l- &fHide and Seek Weltkarte speichern mit /hs savemap (nach /hs setspawn)" SETUP_COMPLETE: "Alles eingerichtet! Hide and Seek ist spielbereit." - SETUP_BOUNDS: "&c&l- &fBitte legen Sie Spielgrenzen in 2 gegenüberliegenden Ecken der Spielkarte fest, /hs setbounds" + SETUP_BOUNDS: "&c&l- &fSpielgrenze in 2 gegenüberliegenden Ecken der Welt festlegen mit /hs setbounds" GAME_SPAWN: "Teleport-Position für Spielbeginn festgelegt" LOBBY_SPAWN: "Teleport-Position für Lobby festgelegt" EXIT_SPAWN: "Teleport-Position für Spielende festgelegt" @@ -57,9 +58,12 @@ Localization: STOP: "Das Spiel wurde gestoppt." HIDERS_SUBTITLE: "Verstecke dich gut vor den Seekern!" SEEKERS_SUBTITLE: "Finde alle Hider!" + SPECTATOR_SUBTITLE: "Du bist mitten im spiel beigetreten." BOUNDS_WRONG_WORLD: "Führe diesen Befehl bitte in der Spielwelt aus." BOUNDS: "Grenzen erfolgreich an dieser Position gesetzt. ({AMOUNT}/2)" NOT_AT_ZERO: "Bitte nicht an einer Position setzen, die eine Koordinate bei 0 enthält." + NO_GAME_INFO: "Keine Informationen zum Gameplay für diesen Spieler vorhanden." + INFORMATION_FOR: "Gewinninformationen für {PLAYER}:" # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE version: 2 diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index af5b80c..93cbd4e 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -36,6 +36,7 @@ Localization: WORLDBORDER_POSITION: "Spawn position must be 100 from world border center." WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, and delay to {AMOUNT}." WORLDBORDER_DECREASING: "World border decreasing by 100 blocks over the next 30s." + WORLDBORDER_WARN: "World border will shrink in the next 30s!" TAUNTED: "$c$oOh no! You have been chosen to be taunted." TAUNT: "A random hider will be taunted in the next 30s." TAUNT_ACTIVATE: "Taunt has been activated." @@ -57,9 +58,12 @@ Localization: STOP: "Game has been force stopped." HIDERS_SUBTITLE: "Hide away from the seekers" SEEKERS_SUBTITLE: "Eliminate all hiders" + SPECTATOR_SUBTITLE: "You joined mid-game." BOUNDS_WRONG_WORLD: "Please run this command in the game world." BOUNDS: "Successfully set bounds at this position ({AMOUNT}/2)." NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0." + NO_GAME_INFO: "Player has no gameplay information." + INFORMATION_FOR: "Win information for {PLAYER}:" # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE version: 2 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ce62925..bd391c9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: HideAndSeek main: net.tylermurphy.hideAndSeek.Main -version: 1.3.2 +version: 1.3.3 author: KenshinEto load: STARTUP api-version: 1.14 @@ -28,6 +28,7 @@ permissions: hideandseek.savemap: true hideandseek.join: true hideandseek.leave: true + hideandseek.leavebounds: true hideandseek.about: description: Allows you to run the about command default: true @@ -70,3 +71,6 @@ permissions: hideandseek.leave: description: Allows you to leave the game manual lobby default: true + hideandseek.leavebounds: + description: Allows players to leave specified game bounderies + default: op