Merge pull request #6 from tylermurphy534/dev

merge fix
This commit is contained in:
Tyler Murphy 2021-08-24 18:09:31 -04:00 committed by GitHub
commit e45c39faf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 735 additions and 690 deletions

15
pom.xml
View file

@ -1,14 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<groupId>net.tylermurphy</groupId> <groupId>net.tylermurphy</groupId>
<artifactId>HideAndSeek</artifactId> <artifactId>HideAndSeek</artifactId>
<version>1.0.0</version> <version>1.2.0</version>
<name>Hide and Seek Plugin</name> <name>Hide and Seek Plugin</name>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration> <configuration>
<source>1.8</source> <source>1.8</source>
<target>1.8</target> <target>1.8</target>
@ -21,6 +21,10 @@
<id>spigot-repo</id> <id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/public/</url> <url>https://hub.spigotmc.org/nexus/content/repositories/public/</url>
</repository> </repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
@ -30,5 +34,10 @@
<type>jar</type> <type>jar</type>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.7.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -1,20 +1,24 @@
package net.tylermurphy.hideAndSeek.manager; package net.tylermurphy.hideAndSeek;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.ICommand; import net.tylermurphy.hideAndSeek.commands.About;
import net.tylermurphy.hideAndSeek.commands.*; import net.tylermurphy.hideAndSeek.commands.Help;
import net.tylermurphy.hideAndSeek.commands.SetBorder;
import net.tylermurphy.hideAndSeek.commands.SetSpawnLocation;
import net.tylermurphy.hideAndSeek.commands.Start;
import net.tylermurphy.hideAndSeek.commands.Stop;
import net.tylermurphy.hideAndSeek.util.ICommand;
import static net.tylermurphy.hideAndSeek.Store.*; import static net.tylermurphy.hideAndSeek.Store.*;
public class CommandManager implements CommandExecutor { public class CommandHandler {
public static Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<String,ICommand>(); public static Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<String,ICommand>();
@ -29,10 +33,8 @@ public class CommandManager implements CommandExecutor {
registerCommand(new Help()); registerCommand(new Help());
registerCommand(new Start()); registerCommand(new Start());
registerCommand(new Stop()); registerCommand(new Stop());
registerCommand(new SetSeeker());
registerCommand(new SetSpawnLocation()); registerCommand(new SetSpawnLocation());
registerCommand(new SetBorder()); registerCommand(new SetBorder());
registerCommand(new EnableBorder());
} }
public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) { public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) {
@ -54,7 +56,7 @@ public class CommandManager implements CommandExecutor {
} }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
return CommandManager.handleCommand(sender, command, label, args); return CommandHandler.handleCommand(sender, command, label, args);
} }
} }

View file

@ -0,0 +1,36 @@
package net.tylermurphy.hideAndSeek;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class CommandTabCompleter{
public static List<String> handleTabComplete(CommandSender sender, Command command, String label, String[] args) {
if(args.length == 1) {
return new ArrayList<String>(CommandHandler.COMMAND_REGISTER.keySet());
} else if(args.length > 1) {
if(!CommandHandler.COMMAND_REGISTER.containsKey(args[0].toLowerCase())) {
return null;
} else {
String[] usage = CommandHandler.COMMAND_REGISTER.get(args[0].toLowerCase()).getUsage().split(" ");
if(args.length - 2 < usage.length) {
String parameter = usage[args.length-2];
if(parameter.equals("<player>")) {
return null;//playerList.values().stream().map(p -> p.getName()).collect(Collectors.toList());
} else {
List<String> temp = new ArrayList<String>();
temp.add(parameter.replace("<", "").replace(">", ""));
return temp;
}
} else {
return null;
}
}
}
return null;
}
}

View file

@ -2,6 +2,8 @@ package net.tylermurphy.hideAndSeek;
import static net.tylermurphy.hideAndSeek.Store.*; import static net.tylermurphy.hideAndSeek.Store.*;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -11,22 +13,19 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.manager.BoardManager; import net.tylermurphy.hideAndSeek.events.EventListener;
import net.tylermurphy.hideAndSeek.manager.CommandManager; import net.tylermurphy.hideAndSeek.events.EventTick;
import net.tylermurphy.hideAndSeek.manager.EventManager;
import net.tylermurphy.hideAndSeek.manager.TickManager;
public class Main extends JavaPlugin implements Listener { public class Main extends JavaPlugin implements Listener {
public static Main plugin; public static Main plugin;
private int tickTaskId;
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
// Setup Initial Player Count // Setup Initial Player Count
getServer().getPluginManager().registerEvents(new EventManager(), this); getServer().getPluginManager().registerEvents(new EventListener(), this);
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
playerList.put(player.getName(), player); playerList.put(player.getName(), player);
} }
@ -45,38 +44,32 @@ public class Main extends JavaPlugin implements Listener {
} }
worldborderEnabled = getConfig().getBoolean("borderEnabled"); worldborderEnabled = getConfig().getBoolean("borderEnabled");
// Init Gamerules
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule sendCommandFeedback false");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule doImmediateRespawn true");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule logAdminCommands false");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule naturalRegeneration false");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule keepInventory true");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule showDeathMessages false");
// Register Commands // Register Commands
CommandManager.registerCommands(); CommandHandler.registerCommands();
// Init Scoreboard
if(Bukkit.getScoreboardManager() != null) {
BoardManager.loadScoreboard();
}
// Start Tick Timer // Start Tick Timer
tickTaskId = Bukkit.getServer().getScheduler().runTaskTimer(this, new Runnable(){ Bukkit.getServer().getScheduler().runTaskTimer(this, new Runnable(){
public void run(){ public void run(){
TickManager.onTick(); try{
EventTick.onTick();
} catch (Exception e) {
e.printStackTrace();
} }
},0,1).getTaskId(); }
},0,1);
} }
public void onDisable() { public void onDisable() {
Bukkit.getServer().getScheduler().cancelTask(tickTaskId);
saveConfig(); saveConfig();
} }
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
return CommandManager.handleCommand(sender, cmd, label, args); return CommandHandler.handleCommand(sender, cmd, label, args);
}
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return CommandTabCompleter.handleTabComplete(sender, command, label, args);
} }
} }

View file

@ -1,33 +1,37 @@
package net.tylermurphy.hideAndSeek; package net.tylermurphy.hideAndSeek;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.md_5.bungee.api.ChatColor;
public class Store { public class Store {
public static Map<String,Player> playerList = new HashMap<String,Player>(); public static Map<String,Player> playerList = new HashMap<String,Player>();
public static List<String> loadedPlayers = new ArrayList<String>();
public static Scoreboard board; public static Scoreboard board;
public static Team Hider,Seeker,Spectator; public static Team Hider,Seeker,Spectator;
public static String status = "Setup"; public static String status = "Setup";
public static String messagePrefix = String.format("%sHide and Seek > %s", ChatColor.BLUE, ChatColor.WHITE); public static String messagePrefix = String.format("%sHide and Seek > %s", ChatColor.BLUE, ChatColor.WHITE);
public static String errorPrefix = String.format("%sError > %s", ChatColor.RED, ChatColor.WHITE); public static String errorPrefix = String.format("%sError > %s", ChatColor.RED, ChatColor.WHITE);
public static Vector spawnPosition,worldborderPosition;
public static Vector spawnPosition;
public static Vector worldborderPosition;
public static int worldborderSize,worldborderDelay,currentWorldborderSize; public static int worldborderSize,worldborderDelay,currentWorldborderSize;
public static boolean worldborderEnabled = false, decreaseBorder = false; public static boolean worldborderEnabled = false, decreaseBorder = false;
public static String tauntPlayer = ""; public static String tauntPlayer = "";
public static HashMap<String,Integer> playerData = new HashMap<String,Integer>();
public static int startTaskId; public static int glowTime = 0;
public static int gameId = 0; public static int gameId = 0;
public static FileConfiguration getConfig() { public static FileConfiguration getConfig() {
@ -38,20 +42,4 @@ public class Store {
Main.plugin.saveConfig(); Main.plugin.saveConfig();
} }
public static int getPlayerData(String playerName, String key) {
if(playerData.get(playerName + " " + key) == null) {
return 0;
} else {
return playerData.get(playerName + " " + key);
}
}
public static void setPlayerData(String playerName, String key, int value) {
playerData.put(playerName + " " + key, value);
}
public static void resetPlayerData(String playerName, boolean giveItems) {
playerData.put(playerName+" Death", 0);
playerData.put(playerName+" GiveStatus", (giveItems) ? 1 : 0);
}
} }

View file

@ -3,13 +3,13 @@ package net.tylermurphy.hideAndSeek.commands;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import net.tylermurphy.hideAndSeek.ICommand; import net.tylermurphy.hideAndSeek.util.ICommand;
public class About implements ICommand { public class About implements ICommand {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
sender.sendMessage( sender.sendMessage(
String.format("%s%sHide and Seek %s(1.0.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%s%sHide and Seek %s(1.2.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("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) +
String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE)
); );

View file

@ -1,49 +0,0 @@
package net.tylermurphy.hideAndSeek.commands;
import org.bukkit.command.CommandSender;
import net.tylermurphy.hideAndSeek.ICommand;
import net.tylermurphy.hideAndSeek.manager.WorldborderManager;
import static net.tylermurphy.hideAndSeek.Store.*;
public class EnableBorder implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(!status.equals("Standby") && !status.equals("Setup")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}
if(worldborderPosition == null) {
sender.sendMessage(errorPrefix + "Please setup worldborder info before enabling");
return;
}
boolean bool;
try { bool = Boolean.parseBoolean(args[0]); } catch (Exception e) {
sender.sendMessage(errorPrefix + "Please enter true or false");
return;
}
if(spawnPosition != null && worldborderPosition != null && spawnPosition.distance(worldborderPosition) > 100) {
sender.sendMessage(errorPrefix + "Cannot enable worldborder, spawn position is outside 100 blocks from worldborder");
return;
}
sender.sendMessage(messagePrefix + "Set worldborder to "+args[0]);
getConfig().set("borderEnabled", bool);
worldborderEnabled = bool;
saveConfig();
WorldborderManager.reset();
}
public String getLabel() {
return "enableBorder";
}
public String getUsage() {
return "<true/false>";
}
public String getDescription() {
return "Enables or disables worldborder";
}
}

View file

@ -3,14 +3,14 @@ package net.tylermurphy.hideAndSeek.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.ICommand; import net.tylermurphy.hideAndSeek.CommandHandler;
import net.tylermurphy.hideAndSeek.manager.CommandManager; import net.tylermurphy.hideAndSeek.util.ICommand;
public class Help implements ICommand { public class Help implements ICommand {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
String message = ""; String message = "";
for(ICommand command : CommandManager.COMMAND_REGISTER.values()) { 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 += 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()-2); message = message.substring(0, message.length()-2);

View file

@ -4,8 +4,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.ICommand; import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.manager.WorldborderManager; import net.tylermurphy.hideAndSeek.util.ICommand;
import static net.tylermurphy.hideAndSeek.Store.*; import static net.tylermurphy.hideAndSeek.Store.*;
@ -21,7 +21,11 @@ public class SetBorder implements ICommand {
return; return;
} }
if(args.length < 2) { if(args.length < 2) {
sender.sendMessage(errorPrefix + "Please enter worldborder size and delay"); getConfig().set("borderEnabled", false);
worldborderEnabled = false;
saveConfig();
sender.sendMessage(messagePrefix + "Disabled worldborder.");
Functions.resetWorldborder();
return; return;
} }
int num,delay; int num,delay;
@ -53,8 +57,10 @@ public class SetBorder implements ICommand {
getConfig().set("borderPosition", newWorldborderPosition); getConfig().set("borderPosition", newWorldborderPosition);
getConfig().set("borderSize", num); getConfig().set("borderSize", num);
getConfig().set("borderDelay", delay); getConfig().set("borderDelay", delay);
getConfig().set("borderEnabled", false);
worldborderEnabled = true;
saveConfig(); saveConfig();
WorldborderManager.reset(); Functions.resetWorldborder();
} }
public String getLabel() { public String getLabel() {
@ -66,7 +72,7 @@ public class SetBorder implements ICommand {
} }
public String getDescription() { public String getDescription() {
return "Sets worldboarder's center location, size in blocks, and delay in minutes"; return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable.";
} }
} }

View file

@ -1,47 +0,0 @@
package net.tylermurphy.hideAndSeek.commands;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.ICommand;
public class SetSeeker implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(!status.equals("Standby") && !status.equals("Setup")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}
String playerName;
if(args.length < 1) {
playerName = sender.getName();
} else {
playerName = args[0];
}
Player player = playerList.get(playerName);
if(player == null) {
sender.sendMessage(errorPrefix + "Invalid player: " + playerName);
return;
}
for(Player temp : playerList.values()) {
Hider.addEntry(temp.getName());
}
Seeker.addEntry(player.getName());
sender.sendMessage(String.format("%s Set %s as the seaker.", messagePrefix, playerName));
}
public String getLabel() {
return "setSeeker";
}
public String getUsage() {
return "<player>";
}
public String getDescription() {
return "Sets the current or select player as the seeker";
}
}

View file

@ -1,11 +1,10 @@
package net.tylermurphy.hideAndSeek.commands; package net.tylermurphy.hideAndSeek.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.ICommand; import net.tylermurphy.hideAndSeek.util.ICommand;
import static net.tylermurphy.hideAndSeek.Store.*; import static net.tylermurphy.hideAndSeek.Store.*;
@ -26,8 +25,8 @@ public class SetSpawnLocation implements ICommand {
sender.sendMessage(messagePrefix + "Set spawn position to current location"); sender.sendMessage(messagePrefix + "Set spawn position to current location");
getConfig().set("spawnPosition", newSpawnPosition); getConfig().set("spawnPosition", newSpawnPosition);
saveConfig(); saveConfig();
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("setworldspawn %s %s %s", player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ())); // Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("setworldspawn %s %s %s", player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("spawnpoint @a %s %s %s", player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ())); // Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("spawnpoint @a %s %s %s", player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
} }
public String getLabel() { public String getLabel() {

View file

@ -9,14 +9,13 @@ import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import net.tylermurphy.hideAndSeek.ICommand;
import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.manager.TauntManager; import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.manager.WorldborderManager; import net.tylermurphy.hideAndSeek.util.ICommand;
import static net.tylermurphy.hideAndSeek.Store.*; import static net.tylermurphy.hideAndSeek.Store.*;
import java.util.HashMap; import java.util.Random;
public class Start implements ICommand { public class Start implements ICommand {
@ -29,24 +28,28 @@ public class Start implements ICommand {
sender.sendMessage(errorPrefix + "Game is already in session"); sender.sendMessage(errorPrefix + "Game is already in session");
return; return;
} }
if(Hider.getSize() < 1) { if(playerList.size() < 2) {
sender.sendMessage(errorPrefix + "No Hiders were found"); sender.sendMessage(errorPrefix + "You must have at least 2 players to start");
return; return;
} }
if(Seeker.getSize() < 1) {
sender.sendMessage(errorPrefix + "No Seekers were found");
return;
}
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule sendCommandFeedback false");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule doImmediateRespawn true");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule logAdminCommands false");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule naturalRegeneration false");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule keepInventory true");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule showDeathMessages false");
playerData = new HashMap<String,Integer>(); 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;
}
for(Player temp : playerList.values()) {
Hider.addEntry(temp.getName());
}
Seeker.addEntry(seeker.getName());
for(Player player : playerList.values()) { for(Player player : playerList.values()) {
resetPlayerData(player.getName(),true);
player.getInventory().clear(); player.getInventory().clear();
player.setGameMode(GameMode.ADVENTURE); player.setGameMode(GameMode.ADVENTURE);
player.teleport(new Location(player.getWorld(), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); player.teleport(new Location(player.getWorld(), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
@ -54,7 +57,7 @@ public class Start implements ICommand {
player.removePotionEffect(effect.getType()); player.removePotionEffect(effect.getType());
} }
} }
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("spawnpoint @a %s %s %s", spawnPosition.getBlockX(), spawnPosition.getBlockY(), spawnPosition.getBlockZ())); //Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("spawnpoint @a %s %s %s", spawnPosition.getBlockX(), spawnPosition.getBlockY(), spawnPosition.getBlockZ()));
for(String playerName : Seeker.getEntries()) { for(String playerName : Seeker.getEntries()) {
Player player = playerList.get(playerName); Player player = playerList.get(playerName);
if(player != null) { if(player != null) {
@ -68,40 +71,68 @@ public class Start implements ICommand {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
} }
} }
WorldborderManager.reset(); Functions.resetWorldborder();
status = "Starting"; status = "Starting";
startTaskId = Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){
public void run() {
int temp = gameId; int temp = gameId;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!"); Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!");
try { Thread.sleep(10*1000); } catch (InterruptedException e) {}
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return; if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 20 seconds to hide!"); Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 20 seconds to hide!");
try { Thread.sleep(10*1000); } catch (InterruptedException e) {} }
}, 20 * 10);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return; if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 10 seconds to hide!"); Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 10 seconds to hide!");
try { Thread.sleep(5*1000); } catch (InterruptedException e) {} }
}, 20 * 20);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return; if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 5 seconds to hide!"); Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 5 seconds to hide!");
try { Thread.sleep(2*1000); } catch (InterruptedException e) {} }
}, 20 * 25);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return; if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 3 seconds to hide!"); Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 3 seconds to hide!");
try { Thread.sleep(1*1000); } catch (InterruptedException e) {} }
}, 20 * 27);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return; if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 2 seconds to hide!"); Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 2 seconds to hide!");
try { Thread.sleep(1*1000); } catch (InterruptedException e) {} }
}, 20 * 28);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return; if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!"); Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!");
try { Thread.sleep(1*1000); } catch (InterruptedException e) {} }
}, 20 * 29);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return; if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!"); Bukkit.getServer().broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!");
status = "Playing"; status = "Playing";
for(Player player : playerList.values()) {
Functions.resetPlayer(player);
} }
}).getTaskId(); }
}, 20 * 30);
if(worldborderEnabled) { if(worldborderEnabled) {
WorldborderManager.schedule(); Functions.scheduleWorldborder();
} }
TauntManager.schedule(); Functions.scheduleTaunt();
} }
public String getLabel() { public String getLabel() {
@ -109,11 +140,11 @@ public class Start implements ICommand {
} }
public String getUsage() { public String getUsage() {
return ""; return "<player>";
} }
public String getDescription() { public String getDescription() {
return "Starts the game"; return "Starts the game either with a random seeker or chosen one";
} }
} }

View file

@ -10,14 +10,15 @@ import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import net.tylermurphy.hideAndSeek.ICommand; import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.manager.WorldborderManager; import net.tylermurphy.hideAndSeek.util.ICommand;
public class Stop implements ICommand { public class Stop implements ICommand {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(status.equals("Starting") || status.equals("Playing")) { if(status.equals("Starting") || status.equals("Playing")) {
onStop(true); Bukkit.broadcastMessage(messagePrefix + "Game has been force stopped.");
onStop();
} else { } else {
sender.sendMessage(errorPrefix + "There is no game in progress"); sender.sendMessage(errorPrefix + "There is no game in progress");
@ -29,15 +30,10 @@ public class Stop implements ICommand {
return "stop"; return "stop";
} }
public static void onStop(boolean forced) { public static void onStop() {
if(status.equals("Standby") || status.equals("Setup")) return; if(status.equals("Standby") || status.equals("Setup")) return;
if(forced) {
Bukkit.broadcastMessage(messagePrefix + "Game has been force stopped.");
} else {
Bukkit.broadcastMessage(messagePrefix + "Game over! All hiders have been found.");
}
status = "Standby"; status = "Standby";
Bukkit.getServer().getScheduler().cancelTask(startTaskId); gameId++;
for(Player player : playerList.values()) { for(Player player : playerList.values()) {
player.setGameMode(GameMode.ADVENTURE); player.setGameMode(GameMode.ADVENTURE);
Hider.addEntry(player.getName()); Hider.addEntry(player.getName());
@ -47,9 +43,11 @@ public class Stop implements ICommand {
player.removePotionEffect(effect.getType()); player.removePotionEffect(effect.getType());
} }
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
for(Player temp : playerList.values()) {
Functions.setGlow(player, temp, false);
} }
WorldborderManager.reset(); }
gameId++; Functions.resetWorldborder();
} }
public String getUsage() { public String getUsage() {

View file

@ -0,0 +1,115 @@
package net.tylermurphy.hideAndSeek.events;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.potion.PotionEffect;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Functions;
public class EventListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if(status.equals("Playing") || status.equals("Starting")) {
Spectator.addEntry(event.getPlayer().getName());
event.getPlayer().sendMessage(messagePrefix + "You have joined mid game, and thus have been placed on the spectator team.");
event.getPlayer().setGameMode(GameMode.SPECTATOR);
event.getPlayer().getInventory().clear();
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){
event.getPlayer().removePotionEffect(effect.getType());
}
event.getPlayer().teleport(new Location(event.getPlayer().getWorld(), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
} else if(status.equals("Setup") || status.equals("Standby")) {
Hider.addEntry(event.getPlayer().getName());
}
playerList.put(event.getPlayer().getName(), event.getPlayer());
}
@EventHandler
public void onQuit(PlayerQuitEvent event) {
playerList.remove(event.getPlayer().getName());
Hider.removeEntry(event.getPlayer().getName());
Seeker.removeEntry(event.getPlayer().getName());
Spectator.removeEntry(event.getPlayer().getName());
}
@EventHandler
public void onPlayerDamage(EntityDamageEvent event) {
if(event.getEntity() instanceof Player) {
if(!status.equals("Playing")) {
event.setCancelled(true);
return;
}
Player player = (Player) event.getEntity();
if(player.getHealth()-event.getDamage() < 0) {
if(spawnPosition == null) return;
event.setCancelled(true);
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
player.teleport(new Location(player.getWorld(), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
Functions.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1);
if(Hider.hasEntry(event.getEntity().getName())) {
Bukkit.broadcastMessage(String.format(messagePrefix + "%s%s%s has died and become a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE));
}
if(Seeker.hasEntry(event.getEntity().getName())) {
Bukkit.broadcastMessage(String.format(messagePrefix + "%s%s%s has been beat by a hider", ChatColor.RED, event.getEntity().getName(), ChatColor.WHITE));
}
Seeker.addEntry(player.getName());
Functions.resetPlayer(player);
}
}
}
@EventHandler
public void onProjectile(ProjectileLaunchEvent event) {
if(!status.equals("Playing")) return;
if(event.getEntity() instanceof Snowball) {
Snowball snowball = (Snowball) event.getEntity();
if(snowball.getShooter() instanceof Player) {
Player player = (Player) snowball.getShooter();
if(Hider.hasEntry(player.getName())) {
glowTime++;
snowball.remove();
player.getInventory().remove(Material.SNOWBALL);
int temp = gameId;
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
glowTime--;
}
}, 20 * 30);
}
}
}
}
@EventHandler
public void onFoodLevelChange(FoodLevelChangeEvent event) {
event.setCancelled(true);
}
@EventHandler
public void onPlayerRegainHealth(EntityRegainHealthEvent event) {
if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN)
event.setCancelled(true);
}
}

View file

@ -0,0 +1,139 @@
package net.tylermurphy.hideAndSeek.events;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import net.tylermurphy.hideAndSeek.commands.Stop;
import net.tylermurphy.hideAndSeek.util.Functions;
public class EventTick {
static int tick = 0;
public static void onTick() {
if(board == null) {
Functions.loadScoreboard();
}
Functions.emptyOfflinePlayers();
if(status.equals("Starting")) {
onStarting();
} else if(status.equals("Playing")) {
onPlaying();
}
tick ++;
if(( status.equals("Starting") || status.equals("Playing") ) && Hider.getSize() < 1) {
Bukkit.broadcastMessage(messagePrefix + "Game over! All hiders have been found.");
Stop.onStop();
}
if(( status.equals("Starting") || status.equals("Playing") ) && Seeker.getSize() < 1) {
Bukkit.broadcastMessage(messagePrefix + "Game has ended as all seekers have quit.");
Stop.onStop();
}
}
private static void onStarting() {
for(String playerName : Seeker.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.teleport(new Location(player.getWorld(), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
}
}
}
private static void onPlaying() {
if(decreaseBorder) {
World world = Bukkit.getWorld("world");
WorldBorder border = world.getWorldBorder();
border.setSize(border.getSize()-100,30);
decreaseBorder = false;
}
if(!tauntPlayer.equals("")) {
Player taunted = playerList.get(tauntPlayer);
if(taunted != null) {
Firework fw = (Firework) taunted.getLocation().getWorld().spawnEntity(taunted.getLocation(), EntityType.FIREWORK);
FireworkMeta fwm = fw.getFireworkMeta();
fwm.setPower(4);
fwm.addEffect(FireworkEffect.builder()
.withColor(Color.BLUE)
.withColor(Color.RED)
.withColor(Color.YELLOW)
.with(FireworkEffect.Type.STAR)
.with(FireworkEffect.Type.BALL)
.with(FireworkEffect.Type.BALL_LARGE)
.flicker(true)
.withTrail()
.build());
fw.setFireworkMeta(fwm);
Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "Taunt >" + ChatColor.WHITE + " Taunt has been activated");
}
tauntPlayer = "";
}
for(Player player : playerList.values()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false));
}
for(String playerName : Seeker.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 2, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 1, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 1000000, 1, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 10, false, false));
}
}
for(String playerName : Hider.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false));
}
int distance = 100;
for(String seekerName : Seeker.getEntries()) {
Player seeker = playerList.get(seekerName);
int temp = (int) player.getLocation().distance(seeker.getLocation());
if(distance > temp) {
distance = temp;
}
if(glowTime > 0) {
Functions.setGlow(player, seeker, true);
} else {
Functions.setGlow(player, seeker, false);
}
}
switch(tick%10) {
case 0:
if(distance < 30) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f);
if(distance < 10) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 3:
if(distance < 30) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f);
if(distance < 10) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 6:
if(distance < 10) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 9:
if(distance < 20) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
}
}
}
}

View file

@ -1,40 +0,0 @@
package net.tylermurphy.hideAndSeek.manager;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
public class BoardManager {
public static void loadScoreboard() {
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard mainBoard = manager.getMainScoreboard();
try { mainBoard.registerNewTeam("Seeker");} catch(Exception e) {}
Seeker = mainBoard.getTeam("Seeker");
Seeker.setColor(ChatColor.RED);
Seeker.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Seeker.setAllowFriendlyFire(false);
try { mainBoard.registerNewTeam("Hider");} catch(Exception e) {}
Hider = mainBoard.getTeam("Hider");
Hider.setColor(ChatColor.GOLD);
Hider.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Hider.setAllowFriendlyFire(false);
try { mainBoard.registerNewTeam("Spectator");} catch(Exception e) {}
Spectator = mainBoard.getTeam("Spectator");
Spectator.setColor(ChatColor.GRAY);
Spectator.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Spectator.setAllowFriendlyFire(false);
board = mainBoard;
}
}

View file

@ -1,61 +0,0 @@
package net.tylermurphy.hideAndSeek.manager;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.potion.PotionEffect;
import net.md_5.bungee.api.ChatColor;
public class EventManager implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if(status.equals("Playing") || status.equals("Starting")) {
Spectator.addEntry(event.getPlayer().getName());
resetPlayerData(event.getPlayer().getName(), false);
event.getPlayer().sendMessage(messagePrefix + "You have joined mid game, and thus have been placed on the spectator team.");
event.getPlayer().setGameMode(GameMode.SPECTATOR);
event.getPlayer().getInventory().clear();
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){
event.getPlayer().removePotionEffect(effect.getType());
}
event.getPlayer().teleport(new Location(event.getPlayer().getWorld(), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
} else if(status.equals("Setup") || status.equals("Standby")) {
Hider.addEntry(event.getPlayer().getName());
}
playerList.put(event.getPlayer().getName(), event.getPlayer());
if(board == null) BoardManager.loadScoreboard();
}
@EventHandler
public void onQuit(PlayerQuitEvent event) {
playerList.remove(event.getPlayer().getName());
Hider.removeEntry(event.getPlayer().getName());
Seeker.removeEntry(event.getPlayer().getName());
Spectator.removeEntry(event.getPlayer().getName());
}
@EventHandler
public void onDeath(PlayerDeathEvent event) {
if(status.equals("Playing")) {
if(Hider.hasEntry(event.getEntity().getName())) {
Bukkit.getServer().broadcastMessage(String.format(messagePrefix + "%s%s%s has died and become a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE));
}
if(Seeker.hasEntry(event.getEntity().getName())) {
Bukkit.getServer().broadcastMessage(String.format(messagePrefix + "%s%s%s has been beat by a hider", ChatColor.RED, event.getEntity().getName(), ChatColor.WHITE));
}
setPlayerData(event.getEntity().getName(), "Death", 1);
setPlayerData(event.getEntity().getName(), "GiveStatus", 1);
}
}
}

View file

@ -1,52 +0,0 @@
package net.tylermurphy.hideAndSeek.manager;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
public class TauntManager {
public static void schedule() {
Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){
public void run() {
int temp = gameId;
while(true) {
if(tauntPlayer != null && !tauntPlayer.equals("")) {
try { Thread.sleep(1000); } catch (InterruptedException e) {}
if(gameId != temp) break;
continue;
}
try { Thread.sleep(1000*60); } catch (InterruptedException e) {}
if(gameId != temp) break;
if(Math.random() > .9) {
Player taunted = null;
int rand = (int) (Math.random()*Hider.getEntries().size());
for(Player player : playerList.values()) {
if(Hider.hasEntry(player.getName())) {
rand--;
if(rand==0) {
taunted = player;
break;
}
}
}
if(taunted != null) {
taunted.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Oh no! You have been chosed to be taunted.");
Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "Taunt >" + ChatColor.WHITE + " A random hider will be taunted in the next 30s");
try { Thread.sleep(1000*30); } catch (InterruptedException e) {}
if(gameId != temp) break;
tauntPlayer = taunted.getName();
}
}
}
}
});
}
}

View file

@ -1,245 +0,0 @@
package net.tylermurphy.hideAndSeek.manager;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
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 org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
import net.tylermurphy.hideAndSeek.commands.Stop;
public class TickManager {
static int tick = 0;
public static void onTick() {
if(board == null) return;
checkTeams();
for(Player player : playerList.values()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 1000000, 127, false, false));
}
if(status.equals("Standby") || status.equals("Setup")) {
onStandby();
} else if(status.equals("Starting")) {
onStarting();
} else if(status.equals("Playing")) {
onPlaying();
}
tick ++;
tick %= 10;
if(Hider.getSize() < 1) {
Stop.onStop(false);
}
if(Seeker.getSize() < 1) {
Stop.onStop(false);
}
}
private static void checkTeams() {
try { Hider.getSize(); }
catch (Exception e) {
board.registerNewTeam("Hider");
Hider = board.getTeam("Hider");
Hider.setColor(ChatColor.GOLD);
Hider.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Hider.setAllowFriendlyFire(false);
}
try { Seeker.getSize(); }
catch (Exception e) {
board.registerNewTeam("Seeker");
Seeker = board.getTeam("Seeker");
Seeker.setColor(ChatColor.RED);
Seeker.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Seeker.setAllowFriendlyFire(false);
}
try { Spectator.getSize(); }
catch (Exception e) {
board.registerNewTeam("Spectator");
Spectator = board.getTeam("Spectator");
Spectator.setColor(ChatColor.GRAY);
Spectator.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Spectator.setAllowFriendlyFire(false);
}
for(String entry : Hider.getEntries()) {
if(!playerList.containsKey(entry)) {
Hider.removeEntry(entry);
}
}
for(String entry : Seeker.getEntries()) {
if(!playerList.containsKey(entry)) {
Seeker.removeEntry(entry);
}
}
for(String entry : Spectator.getEntries()) {
if(!playerList.containsKey(entry)) {
Spectator.removeEntry(entry);
}
}
}
private static void onStandby() {
for(Player player : playerList.values()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 1000000, 127, false, false));
}
}
private static void onStarting() {
for(String playerName : Seeker.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.teleport(new Location(player.getWorld(), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
}
}
}
private static void onPlaying() {
if(decreaseBorder) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder add -100 30");
decreaseBorder = false;
}
if(!tauntPlayer.equals("")) {
Player taunted = playerList.get(tauntPlayer);
if(taunted != null) {
Firework fw = (Firework) taunted.getLocation().getWorld().spawnEntity(taunted.getLocation(), EntityType.FIREWORK);
FireworkMeta fwm = fw.getFireworkMeta();
fwm.setPower(2);
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);
Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "Taunt >" + ChatColor.WHITE + " Taunt has been activated");
}
tauntPlayer = "";
}
for(Player player : playerList.values()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false));
if(getPlayerData(player.getName(),"Death") > 0) {
setPlayerData(player.getName(),"Death",0);
Seeker.addEntry(player.getName());
}
if(getPlayerData(player.getName(),"GiveStatus") > 0) {
setPlayerData(player.getName(),"GiveStatus",0);
player.getInventory().clear();
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
if(Seeker.getEntries().contains(player.getName())){
ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD,1);
diamondSword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
ItemMeta diamondSwordMeta = diamondSword.getItemMeta();
diamondSwordMeta.setDisplayName("Seeker Sword");
diamondSwordMeta.setUnbreakable(true);
diamondSword.setItemMeta(diamondSwordMeta);
player.getInventory().addItem(diamondSword);
ItemStack wackyStick = new ItemStack(Material.STICK,1);
wackyStick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 3);
ItemMeta wackyStickMeta = wackyStick.getItemMeta();
wackyStickMeta.setDisplayName("Wacky Stick");
wackyStick.setItemMeta(wackyStickMeta);
player.getInventory().addItem(wackyStick);
}
else if(Hider.getEntries().contains(player.getName())){
ItemStack stoneSword = new ItemStack(Material.STONE_SWORD,1);
stoneSword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
ItemMeta stoneSwordMeta = stoneSword.getItemMeta();
stoneSwordMeta.setDisplayName("Hider Sword");
stoneSwordMeta.setUnbreakable(true);
stoneSword.setItemMeta(stoneSwordMeta);
player.getInventory().addItem(stoneSword);
ItemStack splashPotion = new ItemStack(Material.SPLASH_POTION,1);
PotionMeta splashPotionMeta = (PotionMeta) splashPotion.getItemMeta();
splashPotionMeta.setBasePotionData(new PotionData(PotionType.REGEN));
splashPotion.setItemMeta(splashPotionMeta);
player.getInventory().addItem(splashPotion);
ItemStack potion = new ItemStack(Material.POTION,2);
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
potionMeta.setBasePotionData(new PotionData(PotionType.INSTANT_HEAL));
potion.setItemMeta(potionMeta);
player.getInventory().addItem(potion);
}
}
}
for(String playerName : Seeker.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 2, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 1, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 1000000, 1, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 10, false, false));
}
}
for(String playerName : Hider.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false));
}
int distance = 100;
for(String seekerName : Seeker.getEntries()) {
Player seeker = playerList.get(seekerName);
int temp = (int) player.getLocation().distance(seeker.getLocation());
if(distance > temp) {
distance = temp;
}
}
int x = player.getLocation().getBlockX();
int y = player.getLocation().getBlockY();
int z = player.getLocation().getBlockZ();
switch(tick) {
case 0:
if(distance < 30) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.basedrum master %s %s %s %s .5 1",player.getName(),x,y,z));
if(distance < 10) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z));
break;
case 3:
if(distance < 30) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.basedrum master %s %s %s %s 3.31",player.getName(),x,y,z));
if(distance < 10) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z));
break;
case 6:
if(distance < 10) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z));
break;
case 9:
if(distance < 20) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z));
break;
}
}
}
}

View file

@ -1,44 +0,0 @@
package net.tylermurphy.hideAndSeek.manager;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.Main;
public class WorldborderManager {
public static void schedule() {
Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){
public void run() {
int temp = gameId;
while(true) {
try { Thread.sleep(1000*60*worldborderDelay); } catch (InterruptedException e) {}
if(gameId != temp) break;
if(currentWorldborderSize-100 > 100) {
Bukkit.getServer().broadcastMessage(ChatColor.RED + "World Border> " + ChatColor.WHITE + "Worldborder decreacing by 100 blocks over the next 30s");
currentWorldborderSize -= 100;
decreaseBorder = true;
} else {
break;
}
}
}
});
}
public static void reset() {
if(worldborderEnabled) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder set "+worldborderSize);
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("worldborder center %s %s",worldborderPosition.getBlockX(),worldborderPosition.getBlockZ()));
currentWorldborderSize = worldborderSize;
} else {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder set 30000000");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder center 0 0");
}
}
}

View file

@ -0,0 +1,265 @@
package net.tylermurphy.hideAndSeek.util;
import static net.tylermurphy.hideAndSeek.Store.Hider;
import static net.tylermurphy.hideAndSeek.Store.Seeker;
import static net.tylermurphy.hideAndSeek.Store.Spectator;
import static net.tylermurphy.hideAndSeek.Store.board;
import static net.tylermurphy.hideAndSeek.Store.currentWorldborderSize;
import static net.tylermurphy.hideAndSeek.Store.decreaseBorder;
import static net.tylermurphy.hideAndSeek.Store.gameId;
import static net.tylermurphy.hideAndSeek.Store.playerList;
import static net.tylermurphy.hideAndSeek.Store.tauntPlayer;
import static net.tylermurphy.hideAndSeek.Store.worldborderDelay;
import static net.tylermurphy.hideAndSeek.Store.worldborderEnabled;
import static net.tylermurphy.hideAndSeek.Store.worldborderPosition;
import static net.tylermurphy.hideAndSeek.Store.worldborderSize;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.WorldBorder;
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.PotionType;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
import net.tylermurphy.hideAndSeek.Main;
public class Functions {
private static ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
public static void resetPlayer(Player player) {
player.getInventory().clear();
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
if(Seeker.getEntries().contains(player.getName())){
ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD,1);
diamondSword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
ItemMeta diamondSwordMeta = diamondSword.getItemMeta();
diamondSwordMeta.setDisplayName("Seeker Sword");
diamondSwordMeta.setUnbreakable(true);
diamondSword.setItemMeta(diamondSwordMeta);
player.getInventory().addItem(diamondSword);
ItemStack wackyStick = new ItemStack(Material.STICK,1);
wackyStick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 3);
ItemMeta wackyStickMeta = wackyStick.getItemMeta();
wackyStickMeta.setDisplayName("Wacky Stick");
wackyStick.setItemMeta(wackyStickMeta);
player.getInventory().addItem(wackyStick);
}
else if(Hider.getEntries().contains(player.getName())){
ItemStack stoneSword = new ItemStack(Material.STONE_SWORD,1);
stoneSword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
ItemMeta stoneSwordMeta = stoneSword.getItemMeta();
stoneSwordMeta.setDisplayName("Hider Sword");
stoneSwordMeta.setUnbreakable(true);
stoneSword.setItemMeta(stoneSwordMeta);
player.getInventory().addItem(stoneSword);
ItemStack splashPotion = new ItemStack(Material.SPLASH_POTION,1);
PotionMeta splashPotionMeta = (PotionMeta) splashPotion.getItemMeta();
splashPotionMeta.setBasePotionData(new PotionData(PotionType.REGEN));
splashPotion.setItemMeta(splashPotionMeta);
player.getInventory().addItem(splashPotion);
ItemStack potion = new ItemStack(Material.POTION,2);
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
potionMeta.setBasePotionData(new PotionData(PotionType.INSTANT_HEAL));
potion.setItemMeta(potionMeta);
player.getInventory().addItem(potion);
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);
player.getInventory().addItem(snowball);
}
}
public static void emptyOfflinePlayers() {
for(String entry : Hider.getEntries()) {
if(!playerList.containsKey(entry)) {
Hider.removeEntry(entry);
}
}
for(String entry : Seeker.getEntries()) {
if(!playerList.containsKey(entry)) {
Seeker.removeEntry(entry);
}
}
for(String entry : Spectator.getEntries()) {
if(!playerList.containsKey(entry)) {
Spectator.removeEntry(entry);
}
}
}
public static void loadScoreboard() {
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard mainBoard = manager.getMainScoreboard();
try { mainBoard.registerNewTeam("Seeker");} catch(Exception e) {}
Seeker = mainBoard.getTeam("Seeker");
Seeker.setColor(ChatColor.RED);
Seeker.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Seeker.setAllowFriendlyFire(false);
try { mainBoard.registerNewTeam("Hider");} catch(Exception e) {}
Hider = mainBoard.getTeam("Hider");
Hider.setColor(ChatColor.GOLD);
Hider.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Hider.setAllowFriendlyFire(false);
try { mainBoard.registerNewTeam("Spectator");} catch(Exception e) {}
Spectator = mainBoard.getTeam("Spectator");
Spectator.setColor(ChatColor.GRAY);
Spectator.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Spectator.setAllowFriendlyFire(false);
board = mainBoard;
}
public static void playSound(Player player, Sound sound, float volume, float pitch) {
PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.NAMED_SOUND_EFFECT);
packet.getSoundCategories().write(0, SoundCategory.MASTER);
packet.getSoundEffects().write(0, sound);
packet.getIntegers().write(0, (int)(player.getLocation().getX() * 8.0));
packet.getIntegers().write(1, (int)(player.getLocation().getY() * 8.0));
packet.getIntegers().write(2, (int)(player.getLocation().getZ() * 8.0));
packet.getFloat().write(0, volume);
packet.getFloat().write(1, pitch);
try {
protocolManager.sendServerPacket(player, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public static void setGlow(Player player, Player target, boolean glowing) {
PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
packet.getIntegers().write(0, target.getEntityId());
WrappedDataWatcher watcher = new WrappedDataWatcher();
Serializer serializer = Registry.get(Byte.class);
watcher.setEntity(target);
if(glowing) {
watcher.setObject(0, serializer, (byte) (0x40));
} else {
watcher.setObject(0, serializer, (byte) (0x0));
}
packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
try {
protocolManager.sendServerPacket(player, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public static void scheduleTaunt() {
Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){
public void run() {
int temp = gameId;
while(true) {
if(tauntPlayer != null && !tauntPlayer.equals("")) {
try { Thread.sleep(1000); } catch (InterruptedException e) {}
if(gameId != temp) break;
continue;
}
try { Thread.sleep(1000*60); } catch (InterruptedException e) {}
if(gameId != temp) break;
if(Math.random() > .8) {
Player taunted = null;
int rand = (int) (Math.random()*Hider.getEntries().size());
for(Player player : playerList.values()) {
if(Hider.hasEntry(player.getName())) {
rand--;
if(rand==0) {
taunted = player;
break;
}
}
}
if(taunted != null) {
taunted.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Oh no! You have been chosed to be taunted.");
Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "Taunt >" + ChatColor.WHITE + " A random hider will be taunted in the next 30s");
try { Thread.sleep(1000*30); } catch (InterruptedException e) {}
if(gameId != temp) break;
tauntPlayer = taunted.getName();
}
}
}
}
});
}
public static void scheduleWorldborder() {
Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){
public void run() {
int temp = gameId;
while(true) {
try { Thread.sleep(1000*60*worldborderDelay); } catch (InterruptedException e) {}
if(gameId != temp) break;
if(currentWorldborderSize-100 > 100) {
Bukkit.getServer().broadcastMessage(ChatColor.RED + "World Border> " + ChatColor.WHITE + "Worldborder decreacing by 100 blocks over the next 30s");
currentWorldborderSize -= 100;
decreaseBorder = true;
} else {
break;
}
}
}
});
}
public static void resetWorldborder() {
if(worldborderEnabled) {
World world = Bukkit.getWorld("world");
WorldBorder border = world.getWorldBorder();
border.setSize(worldborderSize);
border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ());
currentWorldborderSize = worldborderSize;
} else {
World world = Bukkit.getWorld("world");
WorldBorder border = world.getWorldBorder();
border.setSize(30000000);
border.setCenter(0, 0);
}
}
}

View file

@ -1,4 +1,4 @@
package net.tylermurphy.hideAndSeek; package net.tylermurphy.hideAndSeek.util;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View file

@ -1,8 +1,10 @@
name: HideAndSeek name: HideAndSeek
main: net.tylermurphy.hideAndSeek.Main main: net.tylermurphy.hideAndSeek.Main
version: 1.0 version: 1.2.0
author: KenshinEto author: KenshinEto
load: STARTUP load: STARTUP
api-version: 1.17
depend: [ProtocolLib]
commands: commands:
hideandseek: hideandseek:
description: Hide and Seek command description: Hide and Seek command