diff options
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command')
8 files changed, 582 insertions, 0 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java new file mode 100644 index 0000000..3c4a8f0 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -0,0 +1,30 @@ +package net.tylermurphy.hideAndSeek.command; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +import net.tylermurphy.hideAndSeek.util.ICommand; + +public class About implements ICommand { + + public void execute(CommandSender sender, String[] args) { + sender.sendMessage( + String.format("%s%sHide and Seek %s(1.3.0%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) + ); + } + + public String getLabel() { + return "about"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Get information about the plugin"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java new file mode 100644 index 0000000..f33717e --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -0,0 +1,32 @@ +package net.tylermurphy.hideAndSeek.command; + +import org.bukkit.command.CommandSender; + +import net.md_5.bungee.api.ChatColor; +import net.tylermurphy.hideAndSeek.bukkit.CommandHandler; +import net.tylermurphy.hideAndSeek.util.ICommand; + +public class Help implements ICommand { + + public void execute(CommandSender sender, String[] args) { + String message = ""; + 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 = message.substring(0, message.length()-1); + sender.sendMessage(message); + } + + public String getLabel() { + return "help"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Get the commands for the plugin"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java new file mode 100644 index 0000000..1b1f1d5 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -0,0 +1,33 @@ +package net.tylermurphy.hideAndSeek.command; + +import org.bukkit.command.CommandSender; + +import net.tylermurphy.hideAndSeek.Store; +import net.tylermurphy.hideAndSeek.util.Functions; +import net.tylermurphy.hideAndSeek.util.ICommand; + +import static net.tylermurphy.hideAndSeek.Store.*; + +public class Reload implements ICommand { + + public void execute(CommandSender sender, String[] args) { + Store.loadConfig(); + try { + Functions.loadScoreboard(); + } catch(Exception e) {} + sender.sendMessage(messagePrefix + "Reloaded the config"); + } + + public String getLabel() { + return "reload"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Reloads the config"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java new file mode 100644 index 0000000..2956c80 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -0,0 +1,106 @@ +package net.tylermurphy.hideAndSeek.command; + +import static net.tylermurphy.hideAndSeek.Store.*; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.scheduler.BukkitRunnable; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.ICommand; + +public class SaveMap implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) { + sender.sendMessage(errorPrefix + "Please set spawn location first"); + return; + } + sender.sendMessage(messagePrefix + "Starting map save"); + sender.sendMessage(warningPrefix + "All commands will be disabled when the save is in progress. Do not turn off the server."); + Bukkit.getServer().getWorld(spawnWorld).save(); + BukkitRunnable runnable = new BukkitRunnable() { + public void run() { + File current = new File(Main.root+File.separator+spawnWorld); + if(current.exists()) { + File temp_destenation = new File(Main.root+File.separator+"temp_hideandseek_"+spawnWorld); + File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); + copyFileStructure(current, temp_destenation); + if(destenation.exists()) { + deleteDirectory(destenation); + destenation.mkdir(); + } + temp_destenation.renameTo(destenation); + sender.sendMessage(messagePrefix + "Map save complete"); + runningBackup = false; + } else { + sender.sendMessage(errorPrefix + "Coudnt find current map"); + } + } + }; + runnable.runTaskAsynchronously(Main.plugin); + runningBackup = true; + } + + private static void copyFileStructure(File source, File target){ + try { + ArrayList<String> ignore = new ArrayList<>(Arrays.asList("uid.dat", "session.lock")); + if(!ignore.contains(source.getName())) { + if(source.isDirectory()) { + if(!target.exists()) + if (!target.mkdirs()) + throw new IOException("Couldn't create world directory!"); + String files[] = source.list(); + for (String file : files) { + File srcFile = new File(source, file); + File destFile = new File(target, file); + copyFileStructure(srcFile, destFile); + } + } else { + InputStream in = new FileInputStream(source); + OutputStream out = new FileOutputStream(target); + byte[] buffer = new byte[1024]; + int length; + while ((length = in.read(buffer)) > 0) + out.write(buffer, 0, length); + in.close(); + out.close(); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private boolean deleteDirectory(File directoryToBeDeleted) { + File[] allContents = directoryToBeDeleted.listFiles(); + if (allContents != null) { + for (File file : allContents) { + deleteDirectory(file); + } + } + return directoryToBeDeleted.delete(); + } + + public String getLabel() { + return "saveMap"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Saves current map for the game. May lag server."; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java new file mode 100644 index 0000000..e8ad2c9 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -0,0 +1,86 @@ +package net.tylermurphy.hideAndSeek.command; + +import static net.tylermurphy.hideAndSeek.Store.*; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import net.tylermurphy.hideAndSeek.util.Functions; +import net.tylermurphy.hideAndSeek.util.ICommand; + +public class SetBorder implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if(!status.equals("Standby")) { + sender.sendMessage(errorPrefix + "Game is currently in session"); + return; + } + if(spawnPosition == null) { + sender.sendMessage(errorPrefix + "Please set spawn position first"); + return; + } + if(args.length < 2) { + worldborderEnabled = false; + Map<String, Object> temp = new HashMap<String,Object>(); + temp.put("enabled", false); + addToSection("worldBorder",temp); + saveConfig(); + sender.sendMessage(messagePrefix + "Disabled worldborder."); + Functions.resetWorldborder(spawnWorld); + return; + } + int num,delay; + try { num = Integer.parseInt(args[0]); } catch (Exception e) { + sender.sendMessage(errorPrefix + "Invalid integer: "+args[0]); + return; + } + try { delay = Integer.parseInt(args[1]); } catch (Exception e) { + sender.sendMessage(errorPrefix + "Invalid integer: "+args[1]); + return; + } + if(num < 100) { + sender.sendMessage(errorPrefix + "Worldborder cannot be smaller than 100 blocks."); + return; + } + Vector newWorldborderPosition = new Vector(); + Player player = (Player) sender; + newWorldborderPosition.setX(player.getLocation().getBlockX()); + newWorldborderPosition.setY(0); + newWorldborderPosition.setZ(player.getLocation().getBlockZ()); + if(spawnPosition.distance(newWorldborderPosition) > 100) { + sender.sendMessage(errorPrefix + "Spawn position must be 100 from worldborder center"); + return; + } + worldborderPosition = newWorldborderPosition; + worldborderSize = num; + worldborderDelay = delay; + worldborderEnabled = true; + Map<String, Object> temp = new HashMap<String,Object>(); + temp.put("x", worldborderPosition.getBlockX()); + temp.put("z", worldborderPosition.getBlockZ()); + temp.put("delay", worldborderDelay); + temp.put("size", worldborderSize); + temp.put("enabled", true); + addToSection("worldBorder",temp); + sender.sendMessage(messagePrefix + "Set border center to current location, size to "+num+", and delay to "+delay); + saveConfig(); + Functions.resetWorldborder(spawnWorld); + } + + public String getLabel() { + return "setBorder"; + } + + public String getUsage() { + return "<size> <delay>"; + } + + public String getDescription() { + return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable."; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java new file mode 100644 index 0000000..62d6bc9 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java @@ -0,0 +1,53 @@ +package net.tylermurphy.hideAndSeek.command; + +import static net.tylermurphy.hideAndSeek.Store.*; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import net.tylermurphy.hideAndSeek.util.ICommand; + +public class SetSpawnLocation implements ICommand { + + public void execute(CommandSender sender, String[] args) { + Vector newSpawnPosition = new Vector(); + Player player = (Player) sender; + newSpawnPosition.setX(player.getLocation().getBlockX()); + newSpawnPosition.setY(player.getLocation().getBlockY()); + newSpawnPosition.setZ(player.getLocation().getBlockZ()); + if(!status.equals("Standby")) { + sender.sendMessage(errorPrefix + "Game is currently in session"); + return; + } + if(worldborderEnabled && spawnPosition.distance(worldborderPosition) > 100) { + sender.sendMessage(errorPrefix + "Spawn position must be 100 from worldborder center"); + return; + } + spawnPosition = newSpawnPosition; + sender.sendMessage(messagePrefix + "Set spawn position to current location"); + Map<String, Object> temp = new HashMap<String,Object>(); + temp.put("x", spawnPosition.getX()); + temp.put("y", spawnPosition.getY()); + temp.put("z", spawnPosition.getZ()); + temp.put("world", player.getLocation().getWorld().getName()); + addToSection("spawn",temp); + saveConfig(); + } + + public String getLabel() { + return "setspawn"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks spawn location to current position"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java new file mode 100644 index 0000000..a49ce41 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -0,0 +1,179 @@ +package net.tylermurphy.hideAndSeek.command; + +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.events.Glow; +import net.tylermurphy.hideAndSeek.events.Taunt; +import net.tylermurphy.hideAndSeek.events.Worldborder; +import net.tylermurphy.hideAndSeek.util.Functions; +import net.tylermurphy.hideAndSeek.util.ICommand; + +import static net.tylermurphy.hideAndSeek.Store.*; + +import java.io.File; +import java.util.ArrayList; +import java.util.Random; + +public class Start implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if(!status.equals("Standby")) { + sender.sendMessage(errorPrefix + "Game is already in session"); + return; + } + if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) { + sender.sendMessage(errorPrefix + "Please set spawn location first"); + return; + } + File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); + if(!destenation.exists()) { + sender.sendMessage(errorPrefix + "Please set map save first"); + return; + } else { + if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) { + Functions.rollback("hideandseek_"+spawnWorld); + } else { + Functions.loadMap("hideandseek_"+spawnWorld); + } + } + if(playerList.size() < minPlayers) { + sender.sendMessage(errorPrefix + "You must have at least "+minPlayers+" players to start"); + return; + } + String seekerName; + if(args.length < 1) { + seekerName = playerList.values().stream().skip(new Random().nextInt(playerList.values().size())).findFirst().get().getName(); + } else { + seekerName = args[0]; + } + Player seeker = playerList.get(seekerName); + if(seeker == null) { + sender.sendMessage(errorPrefix + "Invalid player: " + seekerName); + return; + } + Hider = new ArrayList<String>(); + Seeker = new ArrayList<String>(); + Spectator = new ArrayList<String>(); + for(Player temp : playerList.values()) { + if(temp.getName().equals(seeker.getName())) + continue; + Hider.add(temp.getName()); + HiderTeam.addEntry(temp.getName()); + } + Seeker.add(seeker.getName()); + SeekerTeam.addEntry(seeker.getName()); + + for(Player player : playerList.values()) { + player.getInventory().clear(); + player.setGameMode(GameMode.ADVENTURE); + player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + for(PotionEffect effect : player.getActivePotionEffects()){ + player.removePotionEffect(effect.getType()); + } + } + for(String playerName : Seeker) { + Player player = playerList.get(playerName); + if(player != null) { + player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false)); + } + } + for(String playerName : Hider) { + Player player = playerList.get(playerName); + if(player != null) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); + } + } + Functions.resetWorldborder("hideandseek_"+spawnWorld); + status = "Starting"; + int temp = gameId; + Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!"); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { + if(temp != gameId) return; + Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 20 seconds to hide!"); + } + }, 20 * 10); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { + if(temp != gameId) return; + Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 10 seconds to hide!"); + } + }, 20 * 20); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { + if(temp != gameId) return; + Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 5 seconds to hide!"); + } + }, 20 * 25); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { + if(temp != gameId) return; + Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 3 seconds to hide!"); + } + }, 20 * 27); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { + if(temp != gameId) return; + Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 2 seconds to hide!"); + } + }, 20 * 28); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { + if(temp != gameId) return; + Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!"); + } + }, 20 * 29); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { + if(temp != gameId) return; + Bukkit.getServer().broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!"); + status = "Playing"; + for(Player player : playerList.values()) { + Functions.resetPlayer(player); + } + Main.worldborder = null; + Main.taunt = null; + Main.glow = null; + + if(worldborderEnabled) { + Main.worldborder = new Worldborder(gameId); + Main.worldborder.schedule(); + } + + Main.taunt = new Taunt(gameId); + Main.taunt.schedule(); + + Main.glow = new Glow(gameId); + } + }, 20 * 30); + + } + + public String getLabel() { + return "start"; + } + + public String getUsage() { + return "<player>"; + } + + public String getDescription() { + return "Starts the game either with a random seeker or chosen one"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java new file mode 100644 index 0000000..c956d3d --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -0,0 +1,63 @@ +package net.tylermurphy.hideAndSeek.command; + +import static net.tylermurphy.hideAndSeek.Store.*; + +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import net.tylermurphy.hideAndSeek.util.Functions; +import net.tylermurphy.hideAndSeek.util.ICommand; +import net.tylermurphy.hideAndSeek.util.Packet; + +public class Stop implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if(status.equals("Starting") || status.equals("Playing")) { + Bukkit.broadcastMessage(abortPrefix + "Game has been force stopped."); + onStop(); + + } else { + sender.sendMessage(errorPrefix + "There is no game in progress"); + return; + } + } + + public String getLabel() { + return "stop"; + } + + public static void onStop() { + if(status.equals("Standby")) return; + status = "Standby"; + gameId++; + Functions.resetWorldborder("hideandseek_"+spawnWorld); + for(Player player : playerList.values()) { + player.setGameMode(GameMode.ADVENTURE); + Hider.add(player.getName()); + HiderTeam.addEntry(player.getName()); + player.getInventory().clear(); + player.teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + for(PotionEffect effect : player.getActivePotionEffects()){ + player.removePotionEffect(effect.getType()); + } + player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); + for(Player temp : playerList.values()) { + Packet.setGlow(player, temp, false); + } + } + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Stops the game"; + } + +} |