1.3.3 beta 3

This commit is contained in:
Tyler Murphy 2021-12-26 16:58:18 -06:00
parent 6e09da9150
commit 1617bfe44a
39 changed files with 1056 additions and 1153 deletions

View file

@ -1,91 +1,55 @@
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.game.Status;
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.util.CommandHandler;
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.util.Board;
import net.tylermurphy.hideAndSeek.world.WorldLoader;
import net.tylermurphy.hideAndSeek.game.Board;
public class Main extends JavaPlugin implements Listener {
public static Main plugin;
public static File root, data;
public Game game;
public Board board;
public WorldLoader worldLoader;
public Status status = Status.STANDBY;
public Database database;
private BukkitTask onTickTask;
public void onEnable() {
plugin = this;
// Setup Event Listener
getServer().getPluginManager().registerEvents(new EventListener(), this);
// Get Data Folder
root = this.getServer().getWorldContainer();
data = this.getDataFolder();
getServer().getPluginManager().registerEvents(new EventListener(), this);
// Init Configuration
Config.loadConfig();
Localization.loadLocalization();
Items.loadItems();
// Create World Loader
worldLoader = new WorldLoader(spawnWorld);
// Register Commands
CommandHandler.registerCommands();
//Board
board = new Board();
board.reload();
//Database
database = new Database();
database.init();
//UUIDFetcher Cache
Board.reload();
Database.init();
UUIDFetcher.init();
//Init game
game = new Game();
// Start Tick Timer
onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> {
try{
game.onTick();
Game.onTick();
} catch (Exception e) {
e.printStackTrace();
}
},0,1);
}
public void onDisable() {
@ -95,11 +59,11 @@ public class Main extends JavaPlugin implements Listener {
}
public boolean onCommand(CommandSender sender, Command cmd,String label, String[] args) {
return CommandHandler.handleCommand(sender, cmd, label, args);
return CommandHandler.handleCommand(sender, args);
}
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return TabCompleter.handleTabComplete(sender, command, label, args);
return TabCompleter.handleTabComplete(sender, args);
}
}

View file

@ -7,7 +7,7 @@ public class About implements ICommand {
public void execute(CommandSender sender, String[] args) {
sender.sendMessage(
String.format("%s%sHide and Seek %s(1.3.3%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)
);

View file

@ -3,17 +3,17 @@ package net.tylermurphy.hideAndSeek.command;
import org.bukkit.command.CommandSender;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.util.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() {

View file

@ -4,12 +4,12 @@ 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();
public String getUsage();
String getUsage();
public String getDescription();
String getDescription();
}

View file

@ -2,7 +2,9 @@ package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.game.Status;
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.GameMode;
import org.bukkit.Location;
@ -10,14 +12,14 @@ 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 java.util.Objects;
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;
}
@ -26,7 +28,7 @@ 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;
}
@ -35,25 +37,25 @@ public class Join implements ICommand {
}
public static void join(Player player){
if(Main.plugin.status == Status.STANDBY) {
if(Game.status == Status.STANDBY) {
player.getInventory().clear();
Main.plugin.board.addHider(player);
Board.addHider(player);
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
else Util.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);
Main.plugin.board.createLobbyBoard(player);
Main.plugin.board.reloadLobbyBoards();
Board.createLobbyBoard(player);
Board.reloadLobbyBoards();
} else {
Main.plugin.board.addSpectator(player);
Board.addSpectator(player);
player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR"));
player.setGameMode(GameMode.SPECTATOR);
Main.plugin.board.createGameBoard(player);
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());
player.setHealth(Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getBaseValue());
}
public String getLabel() {

View file

@ -2,20 +2,20 @@ package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.game.Status;
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;
}
@ -24,20 +24,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 == Status.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();
}
}

View file

@ -3,10 +3,10 @@ package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.game.Status;
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;
@ -16,7 +16,7 @@ public class Reload implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(Main.plugin.status != Status.STANDBY) {
if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}

View file

@ -2,8 +2,10 @@ package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.game.Status;
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;
@ -15,7 +17,7 @@ public class SaveMap implements ICommand {
public static boolean runningBackup = false;
public void execute(CommandSender sender, String[] args) {
if(Main.plugin.status != Status.STANDBY) {
if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}
@ -25,11 +27,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;
}

View file

@ -2,19 +2,18 @@ package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.game.Status;
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 != Status.STANDBY) {
if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}
@ -27,7 +26,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;
@ -63,7 +62,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() {

View file

@ -2,17 +2,17 @@ package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.game.Status;
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 != Status.STANDBY) {
if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}

View file

@ -2,21 +2,19 @@ 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.Status;
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 != Status.STANDBY) {
if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}
@ -29,7 +27,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());

View file

@ -2,21 +2,19 @@ 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.Status;
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 != Status.STANDBY) {
if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}
@ -29,7 +27,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());

View file

@ -2,23 +2,21 @@ 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.Status;
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 != Status.STANDBY) {
if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}
@ -35,7 +33,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());

View file

@ -17,24 +17,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) {

View file

@ -1,66 +1,55 @@
package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
import net.tylermurphy.hideAndSeek.game.Status;
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 != Status.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;
}
String seekerName;
if(args.length < 1) {
seekerName = Main.plugin.board.getPlayers().stream().skip(new Random().nextInt(Main.plugin.board.size())).findFirst().get().getName();
Optional<Player> 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.game.start(seeker);
Game.start(seeker);
}
public String getLabel() {

View file

@ -2,26 +2,25 @@ package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.game.Status;
import net.tylermurphy.hideAndSeek.game.WinType;
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.command.CommandSender;
import net.tylermurphy.hideAndSeek.Main;
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 == Status.STARTING || Main.plugin.status == Status.PLAYING) {
if(Game.status == Status.STARTING || Game.status == Status.PLAYING) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("STOP"));
else Util.broadcastMessage(abortPrefix + message("STOP"));
Main.plugin.game.stop(WinType.NONE);
else Game.broadcastMessage(abortPrefix + message("STOP"));
Game.stop(WinType.NONE);
} else {
sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS"));
}

View file

@ -1,6 +1,7 @@
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;
@ -25,10 +26,10 @@ public class Top implements ICommand {
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(page));
return;
}
String message = String.format(
StringBuilder message = new StringBuilder(String.format(
"%s------- %sLEADERBOARD %s(Page %s) %s-------\n",
ChatColor.WHITE, ChatColor.BOLD, ChatColor.GRAY, page, ChatColor.WHITE);
List<PlayerInfo> infos = Main.plugin.database.playerInfo.getInfoPage(page);
ChatColor.WHITE, ChatColor.BOLD, ChatColor.GRAY, page, ChatColor.WHITE));
List<PlayerInfo> infos = Database.playerInfo.getInfoPage(page);
int i = 1 + (page-1)*10;
for(PlayerInfo info : infos){
String name = Main.plugin.getServer().getOfflinePlayer(info.uuid).getName();
@ -39,11 +40,11 @@ public class Top implements ICommand {
case 3: color = ChatColor.GOLD; break;
default: color = ChatColor.WHITE; break;
}
message = message + String.format("%s%s. %s%s %s%s\n",
color, i, ChatColor.RED, info.wins, ChatColor.WHITE, name);
message.append(String.format("%s%s. %s%s %s%s\n",
color, i, ChatColor.RED, info.wins, ChatColor.WHITE, name));
i++;
}
sender.sendMessage(message);
sender.sendMessage(message.toString());
}
public String getLabel() {

View file

@ -1,14 +1,12 @@
package net.tylermurphy.hideAndSeek.command;
import com.comphenix.protocol.PacketType;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.database.Database;
import net.tylermurphy.hideAndSeek.database.PlayerInfo;
import net.tylermurphy.hideAndSeek.util.CommandHandler;
import net.tylermurphy.hideAndSeek.util.UUIDFetcher;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.UUID;
@ -23,7 +21,12 @@ public class Wins implements ICommand {
UUID uuid;
String name;
if(args.length == 0) {
uuid = Main.plugin.getServer().getPlayer(sender.getName()).getUniqueId();
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 {
@ -35,7 +38,7 @@ public class Wins implements ICommand {
return;
}
}
PlayerInfo info = Main.plugin.database.playerInfo.getInfo(uuid);
PlayerInfo info = Database.playerInfo.getInfo(uuid);
if(info == null){
sender.sendMessage(errorPrefix + message("NO_GAME_INFO"));
return;

View file

@ -11,17 +11,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 +33,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 +56,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 +74,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 +84,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 +119,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 +130,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 +153,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 +179,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();

View file

@ -10,7 +10,7 @@ public class Localization {
public static final Map<String,LocalizationString> LOCAL = new HashMap<>();
private static String[][] CHANGES = {{"WORLDBORDER_DECREASING"}};
private static final String[][] CHANGES = {{"WORLDBORDER_DECREASING"}};
public static void loadLocalization() {

View file

@ -1,6 +1,5 @@
package net.tylermurphy.hideAndSeek.configuration;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
public class LocalizationString {
@ -12,32 +11,22 @@ public class LocalizationString {
}
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());
this.message = message.replaceFirst("\\{PLAYER}", player.getName());
return this;
}
public LocalizationString addPlayer(String player) {
this.message = message.replaceFirst("\\{PLAYER\\}", player);
this.message = message.replaceFirst("\\{PLAYER}", player);
return this;
}
public LocalizationString addAmount(Integer value) {
this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString());
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());
this.message = message.replaceFirst("\\{AMOUNT}", value);
return this;
}

View file

@ -1,19 +1,25 @@
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 final File databaseFile = new File(Main.data, "database.db");
private static final File databaseFile = new File(Main.data, "database.db");
public PlayerInfoTable playerInfo;
public static PlayerInfoTable playerInfo;
protected Connection connect() {
protected static Connection connect() {
Connection conn = null;
try {
String url = "jdbc:sqlite:"+databaseFile;
@ -24,7 +30,25 @@ public class Database {
return conn;
}
public void init(){
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();
}
}

View file

@ -1,8 +1,7 @@
package net.tylermurphy.hideAndSeek.database;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.game.WinType;
import net.tylermurphy.hideAndSeek.util.Util;
import net.tylermurphy.hideAndSeek.util.WinType;
import java.io.IOException;
import java.io.InputStream;
@ -23,7 +22,7 @@ public class PlayerInfoTable {
+ " games_played int NOT NULL\n"
+ ");";
try(Connection connection = Main.plugin.database.connect(); Statement statement = connection.createStatement()){
try(Connection connection = Database.connect(); Statement statement = connection.createStatement()){
statement.execute(sql);
} catch (SQLException e){
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
@ -32,21 +31,22 @@ public class PlayerInfoTable {
public PlayerInfo getInfo(UUID uuid){
String sql = "SELECT * FROM player_info WHERE uuid = ?;";
try(Connection connection = Main.plugin.database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
InputStream is = Util.convertUniqueId(uuid);
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
InputStream is = Database.convertUniqueId(uuid);
byte[] bytes = new byte[is.available()];
is.read(bytes);
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()){
PlayerInfo info = new PlayerInfo(
return new PlayerInfo(
uuid,
rs.getInt("wins"),
rs.getInt("seeker_wins"),
rs.getInt("hider_wins"),
rs.getInt("games_played")
);
return info;
}
} catch (SQLException e){
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
@ -59,13 +59,13 @@ public class PlayerInfoTable {
public List<PlayerInfo> getInfoPage(int page){
String sql = "SELECT * FROM player_info ORDER BY wins DESC LIMIT 10 OFFSET ?;";
try(Connection connection = Main.plugin.database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
statement.setInt(1, (page-1)*10);
ResultSet rs = statement.executeQuery();
List<PlayerInfo> infoList = new ArrayList<>();
while(rs.next()){
PlayerInfo info = new PlayerInfo(
Util.convertBinaryStream(rs.getBinaryStream("uuid")),
Database.convertBinaryStream(rs.getBinaryStream("uuid")),
rs.getInt("wins"),
rs.getInt("seeker_wins"),
rs.getInt("hider_wins"),
@ -80,14 +80,16 @@ public class PlayerInfoTable {
return null;
}
public boolean addWins(List<UUID> uuids, List<UUID> winners, WinType type){
public void addWins(List<UUID> uuids, List<UUID> 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 = Main.plugin.database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
InputStream is = Util.convertUniqueId(uuid);
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
InputStream is = Database.convertUniqueId(uuid);
byte[] bytes = new byte[is.available()];
is.read(bytes);
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));
@ -97,13 +99,12 @@ public class PlayerInfoTable {
} catch (SQLException e){
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
e.printStackTrace();
return false;
return;
} catch (IOException e) {
Main.plugin.getLogger().severe("IO Error: " + e.getMessage());
e.printStackTrace();
}
}
return true;
}
}

View file

@ -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 onProjectile() {
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.game.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;
}
}

View file

@ -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.game.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.game.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;
}
}

View file

@ -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.game.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;
}
}

View file

@ -0,0 +1,351 @@
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<String> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>();
private static final Map<String, Player> playerList = new HashMap<>();
private static final Map<String, CustomBoard> customBoards = new HashMap<>();
public static boolean isPlayer(Player player) {
return playerList.containsKey(player.getName());
}
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<Player> getHiders(){
return Hider.stream().map(playerList::get).collect(Collectors.toList());
}
public static List<Player> getSeekers(){
return Seeker.stream().map(playerList::get).collect(Collectors.toList());
}
public static Player getFirstSeeker(){
return playerList.get(Seeker.get(0));
}
public static List<Player> getSpectators(){
return Spectator.stream().map(playerList::get).collect(Collectors.toList());
}
public static List<Player> 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<String,Line> 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;
}
}

View file

@ -1,15 +1,12 @@
package net.tylermurphy.hideAndSeek.util;
package net.tylermurphy.hideAndSeek.game;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
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;
@ -17,7 +14,7 @@ import net.tylermurphy.hideAndSeek.command.*;
public class CommandHandler {
public static Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<String,ICommand>();
public static Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<>();
private static void registerCommand(ICommand command) {
if(!COMMAND_REGISTER.containsKey(command.getLabel())) {
@ -44,7 +41,7 @@ public class CommandHandler {
registerCommand(new Wins());
}
public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) {
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()) ) {

View file

@ -3,6 +3,7 @@ package net.tylermurphy.hideAndSeek.game;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.command.Join;
import net.tylermurphy.hideAndSeek.util.Status;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Entity;
@ -20,19 +21,19 @@ import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.*;
import net.tylermurphy.hideAndSeek.util.Packet;
import net.tylermurphy.hideAndSeek.util.Util;
import net.tylermurphy.hideAndSeek.Main;
import org.bukkit.potion.PotionEffect;
import java.util.Objects;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
public class EventListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Main.plugin.board.remove(event.getPlayer());
Util.removeItems(event.getPlayer());
if(!Util.isSetup()) return;
Board.remove(event.getPlayer());
Game.removeItems(event.getPlayer());
if(Game.isNotSetup()) return;
if(autoJoin){
Join.join(event.getPlayer());
} else if(teleportToExit) {
@ -50,44 +51,45 @@ public class EventListener implements Listener {
@EventHandler
public void onQuit(PlayerQuitEvent event) {
Main.plugin.board.remove(event.getPlayer());
if(Main.plugin.status == Status.STANDBY) {
Main.plugin.board.reloadLobbyBoards();
Board.remove(event.getPlayer());
if(Game.status == Status.STANDBY) {
Board.reloadLobbyBoards();
} else {
Main.plugin.board.reloadGameBoards();
Board.reloadGameBoards();
}
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){
event.getPlayer().removePotionEffect(effect.getType());
}
Util.removeItems(event.getPlayer());
Game.removeItems(event.getPlayer());
}
@EventHandler
public void onKick(PlayerKickEvent event) {
Main.plugin.board.remove(event.getPlayer());
if(Main.plugin.status == Status.STANDBY) {
Main.plugin.board.reloadLobbyBoards();
Board.remove(event.getPlayer());
if(Game.status == Status.STANDBY) {
Board.reloadLobbyBoards();
} else {
Main.plugin.board.reloadGameBoards();
Board.reloadGameBoards();
}
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){
event.getPlayer().removePotionEffect(effect.getType());
}
Util.removeItems(event.getPlayer());
Game.removeItems(event.getPlayer());
}
@EventHandler
public void onChat(AsyncPlayerChatEvent event){
if(Main.plugin.board.isSeeker(event.getPlayer())){
if(Board.isSeeker(event.getPlayer())){
event.setCancelled(true);
Main.plugin.board.getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage()));
Board.getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage()));
}
}
@EventHandler
public void onMove(PlayerMoveEvent event){
if(!event.getPlayer().getWorld().equals("hideandseek_" + spawnWorld)) return;
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() > saveMinX || event.getTo().getBlockZ() < saveMinZ || event.getTo().getBlockZ() > saveMaxZ){
event.setCancelled(true);
@ -99,8 +101,8 @@ public class EventListener implements Listener {
try {
if (event.getEntity() instanceof Player) {
Player p = (Player) event.getEntity();
if (!Main.plugin.board.isPlayer(p)) return;
if (Main.plugin.status != Status.PLAYING) {
if (!Board.isPlayer(p)) return;
if (Game.status != Status.PLAYING) {
event.setCancelled(true);
return;
}
@ -109,30 +111,30 @@ public class EventListener implements Listener {
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);
if (Board.onSameTeam(p, attacker)) event.setCancelled(true);
if (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.setHealth(Objects.requireNonNull(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)) {
if (Board.isSeeker(player)) {
Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(event.getEntity()).toString());
}
if (Main.plugin.board.isHider(player)) {
if (Board.isHider(player)) {
if (attacker == null) {
Util.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(event.getEntity()).toString());
Game.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(event.getEntity()).toString());
} else {
Util.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(event.getEntity()).addPlayer(attacker).toString());
Game.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(event.getEntity()).addPlayer(attacker).toString());
}
Main.plugin.board.addSeeker(player);
Board.addSeeker(player);
}
Util.resetPlayer(player);
Main.plugin.board.reloadBoardTeams();
Game.resetPlayer(player);
Board.reloadBoardTeams();
}
}
} catch (Exception e){
@ -142,14 +144,14 @@ public class EventListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onProjectile(ProjectileLaunchEvent event) {
if(Main.plugin.status != Status.PLAYING) return;
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(Main.plugin.board.isHider(player)) {
Main.plugin.game.glow.onProjectile();
if(Board.isHider(player)) {
Game.glow.onProjectile();
snowball.remove();
player.getInventory().remove(Material.SNOWBALL);
}
@ -160,7 +162,7 @@ public class EventListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if(event.getEntity() instanceof Player) {
if(!Main.plugin.board.isPlayer((Player) event.getEntity())) return;
if(!Board.isPlayer((Player) event.getEntity())) return;
event.setCancelled(true);
}
}
@ -169,7 +171,7 @@ public class EventListener implements Listener {
public void onPlayerRegainHealth(EntityRegainHealthEvent event) {
if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) {
if(event.getEntity() instanceof Player) {
if(!Main.plugin.board.isPlayer((Player) event.getEntity())) return;
if(!Board.isPlayer((Player) event.getEntity())) return;
event.setCancelled(true);
}
}

View file

@ -3,58 +3,64 @@ package net.tylermurphy.hideAndSeek.game;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.events.Glow;
import net.tylermurphy.hideAndSeek.events.Taunt;
import net.tylermurphy.hideAndSeek.events.Worldborder;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Sound;
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.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 net.tylermurphy.hideAndSeek.util.Util;
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.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.game.Game.broadcastMessage;
public class Game {
public Taunt taunt;
public Glow glow;
public Worldborder worldborder;
public static Taunt taunt;
public static Glow glow;
public static WorldBorder 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;
private int tick = 0;
public int countdownTime = -1;
public int gameId = 0;
public int timeLeft = 0;
public void start(Player seeker){
if(Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING) return;
if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) {
Main.plugin.worldLoader.rollback();
} else {
Main.plugin.worldLoader.loadMap();
static {
worldLoader = new WorldLoader(spawnWorld);
}
Main.plugin.board.reload();
for(Player temp : Main.plugin.board.getPlayers()) {
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;
Main.plugin.board.addHider(temp);
Board.addHider(temp);
}
Main.plugin.board.addSeeker(seeker);
Board.addSeeker(seeker);
currentWorldborderSize = worldborderSize;
for(Player player : Main.plugin.board.getPlayers()) {
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()));
@ -62,141 +68,178 @@ public class Game {
player.removePotionEffect(effect.getType());
}
}
for(Player player : Main.plugin.board.getSeekers()) {
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 : Main.plugin.board.getHiders()) {
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);
}
Worldborder.resetWorldborder("hideandseek_"+spawnWorld);
for(Player player : Main.plugin.board.getPlayers()){
Main.plugin.board.createGameBoard(player);
}
Main.plugin.board.reloadGameBoards();
Main.plugin.status = Status.STARTING;
int temp = Main.plugin.game.gameId;
Util.broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30));
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), Main.plugin.game.gameId, 20 * 10);
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), Main.plugin.game.gameId, 20 * 20);
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), Main.plugin.game.gameId, 20 * 25);
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), Main.plugin.game.gameId, 20 * 27);
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), Main.plugin.game.gameId, 20 * 28);
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), Main.plugin.game.gameId, 20 * 29);
if(gameLength > 0) {
timeLeft = gameLength;
worldBorder.resetWorldborder("hideandseek_"+spawnWorld);
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 != Main.plugin.game.gameId) return;
Util.broadcastMessage(messagePrefix + message("START"));
for(Player player : Main.plugin.board.getPlayers()) {
Util.resetPlayer(player);
}
if(worldborderEnabled) {
worldborder = new Worldborder(Main.plugin.game.gameId);
worldborder.schedule();
}
if(tauntEnabled) {
taunt = new Taunt(Main.plugin.game.gameId);
taunt.schedule();
}
if (glowEnabled) {
glow = new Glow(Main.plugin.game.gameId);
}
Main.plugin.status = Status.PLAYING;
if(temp != gameId) return;
if(gameLength > 0) timeLeft = gameLength;
broadcastMessage(messagePrefix + message("START"));
for(Player player : Board.getPlayers()) resetPlayer(player);
if(worldborderEnabled) worldBorder = new WorldBorder();
if(tauntEnabled) taunt = new Taunt();
if (glowEnabled) glow = new Glow();
status = Status.PLAYING;
}, 20 * 30);
}
public void stop(WinType type){
if(Main.plugin.status == Status.STANDBY) return;
public static void stop(WinType type){
if(status == Status.STANDBY) return;
tick = 0;
countdownTime = -1;
Main.plugin.status = Status.STANDBY;
Main.plugin.game.gameId++;
status = Status.STANDBY;
gameId++;
timeLeft = 0;
List<UUID> players = Main.plugin.board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList());
List<UUID> players = Board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList());
if(type == WinType.HIDER_WIN){
List<UUID> winners = Main.plugin.board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList());
Main.plugin.database.playerInfo.addWins(players, winners, type);
List<UUID> winners = Board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList());
Database.playerInfo.addWins(players, winners, type);
} else if(type == WinType.SEEKER_WIN){
List<UUID> winners = new ArrayList<>();
winners.add(Main.plugin.board.getFirstSeeker().getUniqueId());
Main.plugin.database.playerInfo.addWins(players, winners, type);
winners.add(Board.getFirstSeeker().getUniqueId());
Database.playerInfo.addWins(players, winners, type);
}
Worldborder.resetWorldborder("hideandseek_"+spawnWorld);
for(Player player : Main.plugin.board.getPlayers()) {
Main.plugin.board.createLobbyBoard(player);
worldBorder.resetWorldborder("hideandseek_"+spawnWorld);
for(Player player : Board.getPlayers()) {
Board.createLobbyBoard(player);
player.setGameMode(GameMode.ADVENTURE);
Main.plugin.board.addHider(player);
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()) {
for(Player temp : Board.getPlayers()) {
Packet.setGlow(player, temp, false);
}
}
Main.plugin.worldLoader.unloadMap();
Main.plugin.board.reloadLobbyBoards();
worldLoader.unloadMap();
Board.reloadLobbyBoards();
}
public void onTick() {
if(!Util.isSetup()) return;
if(Main.plugin.status == Status.STANDBY) whileWaiting();
else if(Main.plugin.status == Status.PLAYING) whilePlaying();
if(( Main.plugin.status == Status.STARTING || Main.plugin.status == Status.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(WinType.SEEKER_WIN);
}
if(( Main.plugin.status == Status.STARTING || Main.plugin.status == Status.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(WinType.NONE);
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++;
}
private void whileWaiting() {
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<String> 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 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 <= Main.plugin.board.size()){
if(lobbyMin <= Board.size()){
if(countdownTime == -1)
countdownTime = countdown;
if(Main.plugin.board.size() >= changeCountdown)
if(Board.size() >= changeCountdown)
countdownTime = Math.min(countdownTime, 10);
if(tick % 20 == 0)
countdownTime--;
if(countdownTime == 0){
String seekerName = Main.plugin.board.getPlayers().stream().skip(new Random().nextInt(Main.plugin.board.size())).findFirst().get().getName();
Player seeker = Main.plugin.board.getPlayer(seekerName);
Optional<Player> 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 void whilePlaying() {
private static void whileStarting(){
checkWinConditions();
}
for(Player hider : Main.plugin.board.getHiders()) {
private static void whilePlaying() {
for(Player hider : Board.getHiders()) {
int distance = 100, temp = 100;
for(Player seeker : Main.plugin.board.getSeekers()) {
for(Player seeker : Board.getSeekers()) {
try {
temp = (int) hider.getLocation().distance(seeker.getLocation());
} catch (Exception e){
@ -222,19 +265,226 @@ public class Game {
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();
Board.reloadGameBoards();
timeLeft--;
if(timeLeft < 1) {
}
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 Util.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.size() > 1) executeTaunt();
} else {
delay--;
delay = Math.max(delay, 0);
}
}
private void executeTaunt() {
Player taunted = null;
int rand = (int) (Math.random()*Board.sizeHider());
for(Player player : Board.getPlayers()) {
if(Board.isHider(player)) {
rand--;
if(rand==0) {
taunted = player;
break;
}
}
}
if(taunted != null) {
taunted.sendMessage(message("TAUNTED").toString());
broadcastMessage(tauntPrefix + message("TAUNT"));
tauntPlayer = taunted.getName();
running = true;
delay = 30;
} else {
this.delay = tauntDelay;
}
}
private void launchTaunt(){
Player taunted1 = Board.getPlayer(tauntPlayer);
if(taunted1 != null) {
World world = taunted1.getLocation().getWorld();
assert world != null;
Firework fw = (Firework) world.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);
broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE"));
}
tauntPlayer = "";
running = false;
delay = tauntDelay;
}
public int getDelay(){
return delay;
}
public boolean isRunning() {
return running;
}
}
class WorldBorder {
private int delay;
private boolean running;
public WorldBorder() {
delay = 60 * worldborderDelay;
}
void update(){
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;
}
}

View file

@ -1,249 +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 net.tylermurphy.hideAndSeek.game.Status;
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<String> Hider, Seeker, Spectator;
private Map<String, Player> playerList = new HashMap<>();
private Map<String, CustomBoard> 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<Player> getHiders(){
return Hider.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList());
}
public List<Player> getSeekers(){
return Seeker.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList());
}
public Player getFirstSeeker(){
return playerList.get(Seeker.get(0));
}
public List<Player> getSpectators(){
return Spectator.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList());
}
public List<Player> getPlayers(){
return new ArrayList<Player>(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 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();
if(lobbyCountdownEnabled){
if(Main.plugin.game.countdownTime == -1){
board.setLine("waiting", "Waiting for players...");
} else {
board.setLine("waiting", "Starting in: "+ChatColor.GREEN + Main.plugin.game.countdownTime+"s");
}
} else {
board.setLine("waiting", "Waiting for gamemaster...");
}
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.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(Main.plugin.game.glow == null || Main.plugin.status == Status.STARTING || !Main.plugin.game.glow.isRunning())
board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive");
else
board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active");
}
if(tauntEnabled && tauntCountdown){
if(Main.plugin.game.taunt == null || Main.plugin.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(!Main.plugin.game.taunt.isRunning())
board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Main.plugin.game.taunt.getDelay()/60 + "m" + Main.plugin.game.taunt.getDelay()%60 + "s");
else
board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active");
}
if(worldborderEnabled){
if(Main.plugin.game.worldborder == null || Main.plugin.status == Status.STARTING){
board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s");
} else if(!Main.plugin.game.worldborder.isRunning()) {
board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Main.plugin.game.worldborder.getDelay()/60 + "m" + Main.plugin.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 + Main.plugin.game.timeLeft/60 + "m" + Main.plugin.game.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";
}
}

View file

@ -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<String,Line> LINES;
private int blanks;
private boolean displayed;
public CustomBoard(Player player, String title){
this.board = Bukkit.getScoreboardManager().getNewScoreboard();
this.LINES = new HashMap<String,Line>();
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;
}
}

View file

@ -16,7 +16,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);

View file

@ -1,4 +1,4 @@
package net.tylermurphy.hideAndSeek.game;
package net.tylermurphy.hideAndSeek.util;
public enum Status {
STANDBY,

View file

@ -5,14 +5,14 @@ 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<String> handleTabComplete(CommandSender sender, Command command, String label, String[] args) {
public static List<String> handleTabComplete(CommandSender sender, String[] args) {
if(args.length == 1) {
return new ArrayList<String>(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 +26,7 @@ public class TabCompleter{
if(parameter.equals("<player>")) {
return null;
} else {
List<String> temp = new ArrayList<String>();
List<String> temp = new ArrayList<>();
temp.add(parameter.replace("<", "").replace(">", ""));
return temp;
}

View file

@ -41,6 +41,9 @@ public final class UUIDFetcher {
uuid.append('-');
}
}
CACHE.put(playername, UUID.fromString(uuid.toString()));
return UUID.fromString(uuid.toString());
}

View file

@ -1,116 +0,0 @@
package net.tylermurphy.hideAndSeek.util;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import java.io.*;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import com.google.common.io.ByteStreams;
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.game.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<String> snowballLore = new ArrayList<String>();
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 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);
}
public static InputStream convertUniqueId(UUID uuid) {
byte[] bytes = new byte[16];
ByteBuffer.wrap(bytes)
.putLong(uuid.getMostSignificantBits())
.putLong(uuid.getLeastSignificantBits());
return new ByteArrayInputStream(bytes);
}
public 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 e) {}
return null;
}
}

View file

@ -1,4 +1,4 @@
package net.tylermurphy.hideAndSeek.game;
package net.tylermurphy.hideAndSeek.util;
public enum WinType {
HIDER_WIN,

View file

@ -11,6 +11,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 +26,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 +45,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 +72,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 +96,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 +109,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 +139,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());
}
}
}