teams reference rewrite

This commit is contained in:
Tyler Murphy 2021-10-20 20:14:01 -04:00
parent 0503909014
commit fc87556d8c
25 changed files with 531 additions and 502 deletions

View file

@ -1,36 +1,13 @@
package net.tylermurphy.hideAndSeek;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;
public class Store {
public static Map<String,Player>
playerList = new HashMap<String,Player>();
public static List<String>
Hider = new ArrayList<String>(),
Seeker = new ArrayList<String>(),
Spectator = new ArrayList<String>(),
Deaths = new ArrayList<String>();
public static Scoreboard
board;
public static Team
HiderTeam,
SeekerTeam,
SpectatorTeam;
public class Config {
public static String
messagePrefix,
@ -42,8 +19,7 @@ public class Store {
warningPrefix,
spawnWorld,
exitWorld,
lobbyWorld,
status = "Standby";
lobbyWorld;
public static Vector
spawnPosition,
@ -55,18 +31,14 @@ public class Store {
nametagsVisible,
permissionsRequired,
announceMessagesToNonPlayers,
lobbyStarted = false,
worldborderEnabled = false,
runningBackup = false;
worldborderEnabled;
public static int
minPlayers,
gameId = 0,
worldborderSize,
worldborderDelay,
currentWorldborderSize,
gameLength,
timeLeft = 0;
gameLength;
public static FileConfiguration getConfig() {
return Main.plugin.getConfig();

View file

@ -1,12 +1,15 @@
package net.tylermurphy.hideAndSeek;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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;
@ -18,15 +21,24 @@ import net.tylermurphy.hideAndSeek.bukkit.Tick;
import net.tylermurphy.hideAndSeek.events.Glow;
import net.tylermurphy.hideAndSeek.events.Taunt;
import net.tylermurphy.hideAndSeek.events.Worldborder;
import net.tylermurphy.hideAndSeek.util.Board;
public class Main extends JavaPlugin implements Listener {
public static Main plugin;
public static File root;
public static Taunt taunt;
public static Glow glow;
public static Worldborder worldborder;
public Taunt taunt;
public Glow glow;
public Worldborder worldborder;
public Board board;
public Map<String,Player> playerList = new HashMap<String,Player>();
public String status = "Standby";
public int timeLeft = 0, gameId = 0;;
private BukkitTask onTickTask;
@ -38,7 +50,7 @@ public class Main extends JavaPlugin implements Listener {
getServer().getPluginManager().registerEvents(new EventListener(), this);
// Init Configuration
Store.loadConfig();
Config.loadConfig();
// Register Commands
CommandHandler.registerCommands();
@ -46,6 +58,10 @@ public class Main extends JavaPlugin implements Listener {
// Get Data Folder
root = this.getServer().getWorldContainer();
//Board
board = new Board();
board.init();
// Start Tick Timer
onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, new Runnable(){
public void run(){

View file

@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.bukkit;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import java.util.Arrays;
import java.util.LinkedHashMap;
@ -10,8 +10,8 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.command.*;
import net.tylermurphy.hideAndSeek.util.ICommand;
public class CommandHandler {
@ -40,6 +40,9 @@ public class CommandHandler {
}
public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(!Main.plugin.board.isReady()) {
Main.plugin.board.reload();
}
if(sender instanceof Player == false) {
sender.sendMessage(errorPrefix + "This command can only be run as a player.");
} else if(args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) {
@ -49,7 +52,7 @@ public class CommandHandler {
COMMAND_REGISTER.get("about").execute(sender, null);
}
} else {
if(!args[0].toLowerCase().equals("about") && !args[0].toLowerCase().equals("help") && runningBackup) {
if(!args[0].toLowerCase().equals("about") && !args[0].toLowerCase().equals("help") && SaveMap.runningBackup) {
sender.sendMessage(errorPrefix + "Map save is currently in progress. Try again later.");
} else if(permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) {
sender.sendMessage(errorPrefix + "You are not allowed to run this command.");

View file

@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.bukkit;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
@ -24,19 +24,22 @@ import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.Packet;
import net.tylermurphy.hideAndSeek.util.Util;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.command.Start;
public class EventListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
event.getPlayer().setLevel(0);
HiderTeam.removeEntry(event.getPlayer().getName());
SeekerTeam.removeEntry(event.getPlayer().getName());
SpectatorTeam.removeEntry(event.getPlayer().getName());
if(!Functions.setup()) return;
if(Main.plugin.board.isReady()) {
Main.plugin.board.remove(event.getPlayer());
} else {
Main.plugin.board.init();
}
if(!Util.isSetup()) return;
if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld) || event.getPlayer().getWorld().getName().equals(lobbyWorld)){
event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
event.getPlayer().setGameMode(GameMode.ADVENTURE);
@ -45,34 +48,20 @@ public class EventListener implements Listener {
@EventHandler
public void onQuit(PlayerQuitEvent event) {
if(!playerList.containsKey(event.getPlayer().getName())) return;
playerList.remove(event.getPlayer().getName());
Hider.remove(event.getPlayer().getName());
HiderTeam.removeEntry(event.getPlayer().getName());
Seeker.remove(event.getPlayer().getName());
SeekerTeam.removeEntry(event.getPlayer().getName());
Spectator.remove(event.getPlayer().getName());
SpectatorTeam.removeEntry(event.getPlayer().getName());
Main.plugin.board.remove(event.getPlayer());
}
@EventHandler
public void onKick(PlayerKickEvent event) {
if(!playerList.containsKey(event.getPlayer().getName())) return;
playerList.remove(event.getPlayer().getName());
Hider.remove(event.getPlayer().getName());
HiderTeam.removeEntry(event.getPlayer().getName());
Seeker.remove(event.getPlayer().getName());
SeekerTeam.removeEntry(event.getPlayer().getName());
Spectator.remove(event.getPlayer().getName());
SpectatorTeam.removeEntry(event.getPlayer().getName());
Main.plugin.board.remove(event.getPlayer());
}
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if(event.getEntity() instanceof Player) {
Player p = (Player) event.getEntity();
if(!playerList.containsKey(p.getName())) return;
if(!status.equals("Playing")) {
if(!Main.plugin.board.isPlayer(p)) return;
if(!Main.plugin.status.equals("Playing")) {
event.setCancelled(true);
return;
}
@ -81,9 +70,8 @@ public class EventListener implements Listener {
Entity damager = ((EntityDamageByEntityEvent)event).getDamager();
if(damager instanceof Player) {
attacker = (Player) damager;
if(Hider.contains(attacker.getName()) && Hider.contains(p.getName())) event.setCancelled(true);
if(Seeker.contains(attacker.getName()) && Seeker.contains(p.getName())) event.setCancelled(true);
if(Spectator.contains(attacker.getName())) event.setCancelled(true);
if(Main.plugin.board.onSameTeam(p, p)) event.setCancelled(true);
if(Main.plugin.board.isSpectator(p)) event.setCancelled(true);
}
}
Player player = (Player) event.getEntity();
@ -93,33 +81,31 @@ public class EventListener implements Listener {
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1);
if(Seeker.contains(event.getEntity().getName())) {
if(Main.plugin.board.isSeeker(player)) {
Bukkit.broadcastMessage(String.format(messagePrefix + "%s%s%s was killed", ChatColor.RED, event.getEntity().getName(), ChatColor.WHITE));
}
if(Hider.contains(event.getEntity().getName())) {
if(Main.plugin.board.isHider(player)) {
if(attacker == null) {
Functions.broadcastMessage(String.format(messagePrefix + "%s%s%s was found and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE));
Util.broadcastMessage(String.format(messagePrefix + "%s%s%s was found and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE));
} else {
Functions.broadcastMessage(String.format(messagePrefix + "%s%s%s was found by %s%s%s and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE, ChatColor.RED, attacker.getName(), ChatColor.WHITE));
Util.broadcastMessage(String.format(messagePrefix + "%s%s%s was found by %s%s%s and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE, ChatColor.RED, attacker.getName(), ChatColor.WHITE));
}
Hider.remove(player.getName());
Seeker.add(player.getName());
SeekerTeam.addEntry(player.getName());
Main.plugin.board.addSeeker(player);
}
Functions.resetPlayer(player);
Start.resetPlayer(player);
}
}
}
@EventHandler
public void onProjectile(ProjectileLaunchEvent event) {
if(!status.equals("Playing")) return;
if(Main.plugin.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.contains(player.getName())) {
Main.glow.onProjectilve();
if(Main.plugin.board.isHider(player)) {
Main.plugin.glow.onProjectilve();
snowball.remove();
player.getInventory().remove(Material.SNOWBALL);
}
@ -130,7 +116,7 @@ public class EventListener implements Listener {
@EventHandler
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if(event.getEntity() instanceof Player) {
if(!playerList.containsKey(event.getEntity().getName())) return;
if(!Main.plugin.board.isPlayer((Player) event.getEntity())) return;
event.setCancelled(true);
}
}
@ -139,7 +125,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(!playerList.containsKey(event.getEntity().getName())) return;
if(!Main.plugin.board.isPlayer((Player) event.getEntity())) return;
event.setCancelled(true);
}
}

View file

@ -1,14 +1,15 @@
package net.tylermurphy.hideAndSeek.bukkit;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.command.Stop;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.Packet;
import net.tylermurphy.hideAndSeek.util.Util;
public class Tick {
@ -16,26 +17,17 @@ public class Tick {
public static void onTick() {
if(board == null) {
Functions.loadScoreboard();
}
if(Main.plugin.status.equals("Standby")) tick = 0;
else if(Main.plugin.status.equals("Playing")) onPlaying();
if(status.equals("Standby")) {
tick = 0;
}
if(status.equals("Playing")) {
onPlaying();
}
if(( status.equals("Starting") || status.equals("Playing") ) && Hider.size() < 1) {
if(( Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing") ) && Main.plugin.board.sizeHider() < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + "All hiders have been found.");
else Functions.broadcastMessage(gameoverPrefix + "All hiders have been found.");
else Util.broadcastMessage(gameoverPrefix + "All hiders have been found.");
Stop.onStop();
}
if(( status.equals("Starting") || status.equals("Playing") ) && Seeker.size() < 1) {
if(( Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing") ) && Main.plugin.board.sizeSeeker() < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + "All seekers have quit.");
else Functions.broadcastMessage(abortPrefix + "All seekers have quit.");
else Util.broadcastMessage(abortPrefix + "All seekers have quit.");
Stop.onStop();
}
@ -43,32 +35,31 @@ public class Tick {
private static void onPlaying() {
tick ++;
if(tick<1000000) tick++;
else tick = 1;
for(String playerName : Hider) {
Player player = playerList.get(playerName);
for(Player hider : Main.plugin.board.getHiders()) {
int distance = 100;
for(String seekerName : Seeker) {
Player seeker = playerList.get(seekerName);
int temp = (int) player.getLocation().distance(seeker.getLocation());
for(Player seeker : Main.plugin.board.getSeekers()) {
int temp = (int) hider.getLocation().distance(seeker.getLocation());
if(distance > temp) {
distance = temp;
}
}
switch(tick%10) {
case 0:
if(distance < 30) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f);
if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f);
if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 3:
if(distance < 30) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f);
if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f);
if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 6:
if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 9:
if(distance < 20) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
}
@ -76,13 +67,13 @@ public class Tick {
if(tick%20 == 0) {
if(gameLength > 0) {
timeLeft--;
for(Player player : playerList.values()) {
player.setLevel(timeLeft);
Main.plugin.timeLeft--;
for(Player player : Main.plugin.board.getPlayers()) {
player.setLevel(Main.plugin.timeLeft);
}
if(timeLeft < 1) {
if(Main.plugin.timeLeft < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + "Seekers ran out of time. Hiders win!");
else Functions.broadcastMessage(gameoverPrefix + "Seekers ran out of time. Hiders win!");
else Util.broadcastMessage(gameoverPrefix + "Seekers ran out of time. Hiders win!");
Stop.onStop();
}
}

View file

@ -3,8 +3,6 @@ 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) {

View file

@ -4,7 +4,6 @@ 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 {

View file

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

View file

@ -7,15 +7,15 @@ import org.bukkit.attribute.Attribute;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.ICommand;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Util;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
public class Join implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(!Functions.setup()) {
if(!Util.isSetup()) {
sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do");
return;
}
@ -24,21 +24,19 @@ public class Join implements ICommand {
sender.sendMessage(errorPrefix + "An internal error has occured");
return;
}
if(playerList.containsKey(player.getName())){
if(Main.plugin.board.isPlayer(player)){
sender.sendMessage(errorPrefix + "You are already in the lobby/game");
return;
}
playerList.put(player.getName(), player);
if(status.equals("Standby")) {
Hider.add(player.getName());
HiderTeam.addEntry(player.getName());
if(Main.plugin.status.equals("Standby")) {
Main.plugin.board.addHider(player);
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby");
else Functions.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby");
else Util.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby");
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
player.setGameMode(GameMode.ADVENTURE);
} else {
Spectator.add(player.getName());
SpectatorTeam.addEntry(player.getName());
Main.plugin.board.addSeeker(player);
player.sendMessage(messagePrefix + "You have joined mid game and became a spectator");
player.setGameMode(GameMode.SPECTATOR);
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));

View file

@ -5,15 +5,15 @@ import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.ICommand;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Util;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
public class Leave implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(!Functions.setup()) {
if(!Util.isSetup()) {
sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do");
return;
}
@ -22,19 +22,13 @@ public class Leave implements ICommand {
sender.sendMessage(errorPrefix + "An internal error has occured");
return;
}
if(!playerList.containsKey(player.getName())) {
if(!Main.plugin.board.isPlayer(player)) {
sender.sendMessage(errorPrefix + "You are currently not in the lobby");
return;
}
if(!Seeker.contains(player.getName())) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has left the HideAndSeek lobby");
else Functions.broadcastMessage(messagePrefix + sender.getName() + " has left the HideAndSeek lobby");
}
playerList.remove(player.getName());
Hider.remove(player.getName());
Seeker.remove(player.getName());
HiderTeam.removeEntry(player.getName());
SeekerTeam.removeEntry(player.getName());
else Util.broadcastMessage(messagePrefix + sender.getName() + " has left the HideAndSeek lobby");
Main.plugin.board.remove(player);
player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
}

View file

@ -1,29 +1,23 @@
package net.tylermurphy.hideAndSeek.command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Store;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.ICommand;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.Config;
import static net.tylermurphy.hideAndSeek.Store.*;
import java.util.HashMap;
import static net.tylermurphy.hideAndSeek.Config.*;
public class Reload implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(!status.equals("Standby")) {
if(!Main.plugin.status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}
Store.loadConfig();
try {
Functions.loadScoreboard();
} catch(Exception e) {}
Config.loadConfig();
Main.plugin.board.reload();
sender.sendMessage(messagePrefix + "Reloaded the config");
playerList = new HashMap<String,Player>();
}
public String getLabel() {

View file

@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import java.io.File;
import java.io.FileInputStream;
@ -16,12 +16,13 @@ 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 static boolean runningBackup = false;
public void execute(CommandSender sender, String[] args) {
if(!status.equals("Standby")) {
if(!Main.plugin.status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}

View file

@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import java.util.HashMap;
import java.util.Map;
@ -9,13 +9,13 @@ 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;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.events.Worldborder;
public class SetBorder implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(!status.equals("Standby")) {
if(!Main.plugin.status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}
@ -30,7 +30,7 @@ public class SetBorder implements ICommand {
addToSection("worldBorder",temp);
saveConfig();
sender.sendMessage(messagePrefix + "Disabled worldborder.");
Functions.resetWorldborder(spawnWorld);
Worldborder.resetWorldborder(spawnWorld);
return;
}
int num,delay;
@ -68,7 +68,7 @@ public class SetBorder implements ICommand {
addToSection("worldBorder",temp);
sender.sendMessage(messagePrefix + "Set border center to current location, size to "+num+", and delay to "+delay);
saveConfig();
Functions.resetWorldborder(spawnWorld);
Worldborder.resetWorldborder(spawnWorld);
}
public String getLabel() {

View file

@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import java.util.HashMap;
import java.util.Map;
@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.util.ICommand;
import net.tylermurphy.hideAndSeek.Main;
public class SetExitLocation implements ICommand {
@ -19,7 +19,7 @@ public class SetExitLocation implements ICommand {
newExitPosition.setX(player.getLocation().getBlockX());
newExitPosition.setY(player.getLocation().getBlockY());
newExitPosition.setZ(player.getLocation().getBlockZ());
if(!status.equals("Standby")) {
if(!Main.plugin.status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}

View file

@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import java.util.HashMap;
import java.util.Map;
@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.util.ICommand;
import net.tylermurphy.hideAndSeek.Main;
public class SetLobbyLocation implements ICommand {
@ -19,7 +19,7 @@ public class SetLobbyLocation implements ICommand {
newLobbyPosition.setX(player.getLocation().getBlockX());
newLobbyPosition.setY(player.getLocation().getBlockY());
newLobbyPosition.setZ(player.getLocation().getBlockZ());
if(!status.equals("Standby")) {
if(!Main.plugin.status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}

View file

@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import java.util.HashMap;
import java.util.Map;
@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.util.ICommand;
import net.tylermurphy.hideAndSeek.Main;
public class SetSpawnLocation implements ICommand {
@ -19,7 +19,7 @@ public class SetSpawnLocation implements ICommand {
newSpawnPosition.setX(player.getLocation().getBlockX());
newSpawnPosition.setY(player.getLocation().getBlockY());
newSpawnPosition.setZ(player.getLocation().getBlockZ());
if(!status.equals("Standby")) {
if(!Main.plugin.status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}

View file

@ -4,9 +4,8 @@ import org.bukkit.command.CommandSender;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.ICommand;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import java.io.File;

View file

@ -3,73 +3,75 @@ package net.tylermurphy.hideAndSeek.command;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
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.Functions;
import net.tylermurphy.hideAndSeek.util.ICommand;
import net.tylermurphy.hideAndSeek.util.Util;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Start implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(!Functions.setup()) {
if(!Util.isSetup()) {
sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do");
return;
}
if(!status.equals("Standby")) {
if(!Main.plugin.status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is already in session");
return;
}
if(!playerList.containsKey(sender.getName())) {
if(!Main.plugin.board.isPlayer(sender)) {
sender.sendMessage(errorPrefix + "You are not in the lobby");
return;
}
if(playerList.size() < minPlayers) {
if(Main.plugin.board.size() < minPlayers) {
sender.sendMessage(errorPrefix + "You must have at least "+minPlayers+" players to start");
return;
}
if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) {
Functions.rollback("hideandseek_"+spawnWorld);
Util.rollback("hideandseek_"+spawnWorld);
} else {
Functions.loadMap("hideandseek_"+spawnWorld);
Util.loadMap("hideandseek_"+spawnWorld);
}
String seekerName;
if(args.length < 1) {
seekerName = playerList.values().stream().skip(new Random().nextInt(playerList.values().size())).findFirst().get().getName();
seekerName = Main.plugin.board.getPlayers().stream().skip(new Random().nextInt(Main.plugin.board.size())).findFirst().get().getName();
} else {
seekerName = args[0];
}
Player seeker = playerList.get(seekerName);
Player seeker = Main.plugin.board.getPlayer(seekerName);
if(seeker == null) {
sender.sendMessage(errorPrefix + "Invalid player: " + seekerName);
return;
}
Hider = new ArrayList<String>();
Seeker = new ArrayList<String>();
Spectator = new ArrayList<String>();
Deaths = new ArrayList<String>();
for(Player temp : playerList.values()) {
Main.plugin.board.init();
for(Player temp : Main.plugin.board.getPlayers()) {
if(temp.getName().equals(seeker.getName()))
continue;
Hider.add(temp.getName());
HiderTeam.addEntry(temp.getName());
Main.plugin.board.addHider(temp);
}
Seeker.add(seeker.getName());
SeekerTeam.addEntry(seeker.getName());
Main.plugin.board.addSeeker(seeker);
currentWorldborderSize = worldborderSize;
for(Player player : playerList.values()) {
for(Player player : Main.plugin.board.getPlayers()) {
player.getInventory().clear();
player.setGameMode(GameMode.ADVENTURE);
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
@ -77,94 +79,51 @@ public class Start implements ICommand {
player.removePotionEffect(effect.getType());
}
}
for(String playerName : Seeker) {
Player player = playerList.get(playerName);
if(player != null) {
for(Player player : Main.plugin.board.getSeekers()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false));
player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + "Eliminate all hiders", 10, 70, 20);
}
}
for(String playerName : Hider) {
Player player = playerList.get(playerName);
if(player != null) {
for(Player player : Main.plugin.board.getHiders()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + "Hide away from the seekers", 10, 70, 20);
}
}
Functions.resetWorldborder("hideandseek_"+spawnWorld);
status = "Starting";
int temp = gameId;
Functions.broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!");
Worldborder.resetWorldborder("hideandseek_"+spawnWorld);
Main.plugin.status = "Starting";
int temp = Main.plugin.gameId;
Util.broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!");
Util.sendDelayedMessage(messagePrefix + "Hiders have 20 seconds to hide!", Main.plugin.gameId, 20 * 10);
Util.sendDelayedMessage(messagePrefix + "Hiders have 10 seconds to hide!", Main.plugin.gameId, 20 * 20);
Util.sendDelayedMessage(messagePrefix + "Hiders have 5 seconds to hide!", Main.plugin.gameId, 20 * 25);
Util.sendDelayedMessage(messagePrefix + "Hiders have 3 seconds to hide!", Main.plugin.gameId, 20 * 27);
Util.sendDelayedMessage(messagePrefix + "Hiders have 2 seconds to hide!", Main.plugin.gameId, 20 * 28);
Util.sendDelayedMessage(messagePrefix + "Hiders have 1 seconds to hide!", Main.plugin.gameId, 20 * 29);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
Functions.broadcastMessage(messagePrefix + "Hiders have 20 seconds to hide!");
if(temp != Main.plugin.gameId) return;
Util.broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!");
Main.plugin.status = "Playing";
for(Player player : Main.plugin.board.getPlayers()) {
resetPlayer(player);
}
}, 20 * 10);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
Functions.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;
Functions.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;
Functions.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;
Functions.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;
Functions.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;
Functions.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;
Main.plugin.worldborder = null;
Main.plugin.taunt = null;
Main.plugin.glow = null;
if(worldborderEnabled) {
Main.worldborder = new Worldborder(gameId);
Main.worldborder.schedule();
Main.plugin.worldborder = new Worldborder(Main.plugin.gameId);
Main.plugin.worldborder.schedule();
}
Main.taunt = new Taunt(gameId);
Main.taunt.schedule();
Main.plugin.taunt = new Taunt(Main.plugin.gameId);
Main.plugin.taunt.schedule();
Main.glow = new Glow(gameId);
Main.plugin.glow = new Glow(Main.plugin.gameId);
if(gameLength > 0) {
timeLeft = gameLength;
for(Player player : playerList.values()) {
player.setLevel(timeLeft);
Main.plugin.timeLeft = gameLength;
for(Player player : Main.plugin.board.getPlayers()) {
player.setLevel(gameLength);
}
}
}
@ -172,6 +131,69 @@ public class Start implements ICommand {
}
public static void resetPlayer(Player player) {
player.getInventory().clear();
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false));
if(Main.plugin.board.isSeeker(player)){
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);
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));
}
else if(Main.plugin.board.isHider(player)){
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);
snowball.setItemMeta(snowballMeta);
player.getInventory().addItem(snowball);
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false));
}
}
public String getLabel() {
return "start";
}

View file

@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
@ -10,20 +10,21 @@ 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.Main;
import net.tylermurphy.hideAndSeek.events.Worldborder;
import net.tylermurphy.hideAndSeek.util.Packet;
import net.tylermurphy.hideAndSeek.util.Util;
public class Stop implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(!Functions.setup()) {
if(!Util.isSetup()) {
sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do");
return;
}
if(status.equals("Starting") || status.equals("Playing")) {
if(Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing")) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + "Game has been force stopped.");
else Functions.broadcastMessage(abortPrefix + "Game has been force stopped.");
else Util.broadcastMessage(abortPrefix + "Game has been force stopped.");
onStop();
} else {
@ -37,26 +38,25 @@ public class Stop implements ICommand {
}
public static void onStop() {
if(status.equals("Standby")) return;
status = "Standby";
gameId++;
Functions.resetWorldborder("hideandseek_"+spawnWorld);
for(Player player : playerList.values()) {
if(Main.plugin.status.equals("Standby")) return;
Main.plugin.status = "Standby";
Main.plugin.gameId++;
Worldborder.resetWorldborder("hideandseek_"+spawnWorld);
for(Player player : Main.plugin.board.getPlayers()) {
player.setGameMode(GameMode.ADVENTURE);
player.setLevel(0);
Hider.add(player.getName());
HiderTeam.addEntry(player.getName());
Main.plugin.board.addHider(player);
player.getInventory().clear();
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
for(Player temp : playerList.values()) {
for(Player temp : Main.plugin.board.getPlayers()) {
Packet.setGlow(player, temp, false);
}
}
Functions.unloadMap("hideandseek_"+spawnWorld);
Util.unloadMap("hideandseek_"+spawnWorld);
}
public String getUsage() {

View file

@ -1,7 +1,5 @@
package net.tylermurphy.hideAndSeek.events;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -27,12 +25,8 @@ public class Glow {
private void startGlow() {
running = true;
for(String hiderName : Hider) {
Player hider = playerList.get(hiderName);
if(hider == null) continue;
for(String seekerName : Seeker) {
Player seeker = playerList.get(seekerName);
if(seeker == null) continue;
for(Player hider : Main.plugin.board.getHiders()) {
for(Player seeker : Main.plugin.board.getSeekers()) {
Packet.setGlow(hider, seeker, true);
}
}
@ -42,7 +36,7 @@ public class Glow {
private void waitGlow() {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
if(temp != Main.plugin.gameId) return;
glowTime--;
glowTime = Math.max(glowTime, 0);
if(glowTime == 0) {
@ -55,12 +49,8 @@ public class Glow {
}
private void stopGlow() {
for(String hiderName : Hider) {
Player hider = playerList.get(hiderName);
if(hider == null) continue;
for(String seekerName : Seeker) {
Player seeker = playerList.get(seekerName);
if(seeker == null) continue;
for(Player hider : Main.plugin.board.getHiders()) {
for(Player seeker : Main.plugin.board.getSeekers()) {
Packet.setGlow(hider, seeker, false);
}
}

View file

@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.events;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -12,7 +12,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.Util;
public class Taunt {
@ -40,7 +40,7 @@ public class Taunt {
}
private void tryTaunt() {
if(temp != gameId) return;
if(temp != Main.plugin.gameId) return;
if(Math.random() > .8) {
executeTaunt();
} else {
@ -54,9 +54,9 @@ public class Taunt {
private void executeTaunt() {
Player taunted = null;
int rand = (int) (Math.random()*Hider.size());
for(Player player : playerList.values()) {
if(Hider.contains(player.getName())) {
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;
@ -66,12 +66,12 @@ public class Taunt {
}
if(taunted != null) {
taunted.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Oh no! You have been chosed to be taunted.");
Functions.broadcastMessage(tauntPrefix + " A random hider will be taunted in the next 30s");
Util.broadcastMessage(tauntPrefix + " A random hider will be taunted in the next 30s");
tauntPlayer = taunted.getName();
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
Player taunted = playerList.get(tauntPlayer);
if(temp != Main.plugin.gameId) return;
Player taunted = Main.plugin.board.getPlayer(tauntPlayer);
if(taunted != null) {
Firework fw = (Firework) taunted.getLocation().getWorld().spawnEntity(taunted.getLocation(), EntityType.FIREWORK);
FireworkMeta fwm = fw.getFireworkMeta();
@ -87,7 +87,7 @@ public class Taunt {
.withTrail()
.build());
fw.setFireworkMeta(fwm);
Functions.broadcastMessage(tauntPrefix + " Taunt has been activated");
Util.broadcastMessage(tauntPrefix + " Taunt has been activated");
}
tauntPlayer = "";
waitTaunt();

View file

@ -5,9 +5,9 @@ import org.bukkit.World;
import org.bukkit.WorldBorder;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.Util;
import static net.tylermurphy.hideAndSeek.Store.*;
import static net.tylermurphy.hideAndSeek.Config.*;
public class Worldborder {
@ -26,9 +26,9 @@ public class Worldborder {
}
private void decreaceWorldborder() {
if(temp != gameId) return;
if(temp != Main.plugin.gameId) return;
if(currentWorldborderSize-100 > 100) {
Functions.broadcastMessage(worldborderPrefix + "Worldborder decreacing by 100 blocks over the next 30s");
Util.broadcastMessage(worldborderPrefix + "Worldborder decreacing by 100 blocks over the next 30s");
currentWorldborderSize -= 100;
World world = Bukkit.getWorld("hideandseek_"+spawnWorld);
WorldBorder border = world.getWorldBorder();
@ -41,4 +41,19 @@ public class Worldborder {
}
}
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);
}
}
}

View file

@ -0,0 +1,178 @@
package net.tylermurphy.hideAndSeek.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import org.bukkit.scoreboard.Team;
import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
import static net.tylermurphy.hideAndSeek.Config.*;
public class Board {
private Team HiderTeam, SeekerTeam, SpectatorTeam;
private List<String> Hider, Seeker, Spectator;
private Map<String, Player> playerList = new HashMap<String,Player>();
private boolean setup = false;
public boolean isReady() {
return setup;
}
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.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 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());
HiderTeam.addEntry(player.getName());
if(!playerList.containsKey(player.getName()))
playerList.put(player.getName(), player);
}
public void addSeeker(Player player) {
Hider.remove(player.getName());
Seeker.add(player.getName());
Spectator.remove(player.getName());
SeekerTeam.addEntry(player.getName());
if(!playerList.containsKey(player.getName()))
playerList.put(player.getName(), player);
}
public void addSpectator(Player player) {
Hider.remove(player.getName());
Seeker.remove(player.getName());
Spectator.add(player.getName());
SpectatorTeam.addEntry(player.getName());
if(!playerList.containsKey(player.getName()))
playerList.put(player.getName(), player);
}
public void remove(Player player) {
Hider.remove(player.getName());
Seeker.remove(player.getName());
Spectator.remove(player.getName());
HiderTeam.removeEntry(player.getName());
SeekerTeam.removeEntry(player.getName());
SpectatorTeam.removeEntry(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 init() {
Hider = new ArrayList<String>();
Seeker = new ArrayList<String>();
Spectator = new ArrayList<String>();
reload();
}
public void reload() {
ScoreboardManager manager = Bukkit.getScoreboardManager();
if(manager == null) return;
Scoreboard board = manager.getMainScoreboard();
try { board.registerNewTeam("Seeker"); } catch(Exception e) {}
SeekerTeam = board.getTeam("Seeker");
SeekerTeam.setColor(ChatColor.RED);
if(nametagsVisible) SeekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OTHER_TEAMS);
else SeekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
try { board.registerNewTeam("Hider"); } catch(Exception e) {}
HiderTeam = board.getTeam("Hider");
HiderTeam.setColor(ChatColor.GOLD);
if(nametagsVisible) HiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM);
else HiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
try { board.registerNewTeam("Spectator"); } catch(Exception e) {}
SpectatorTeam = board.getTeam("Spectator");
SpectatorTeam.setColor(ChatColor.GRAY);
SpectatorTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
setup = true;
}
public void reset() {
Hider.clear();
Seeker.clear();
Spectator.clear();
for(String entry : HiderTeam.getEntries())
HiderTeam.removeEntry(entry);
for(String entry : SeekerTeam.getEntries())
SeekerTeam.removeEntry(entry);
for(String entry : SpectatorTeam.getEntries())
SpectatorTeam.removeEntry(entry);
}
}

View file

@ -1,184 +0,0 @@
package net.tylermurphy.hideAndSeek.util;
import static net.tylermurphy.hideAndSeek.Store.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.WorldCreator;
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 org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
import net.tylermurphy.hideAndSeek.Main;
public class Functions {
public static void resetPlayer(Player player) {
player.getInventory().clear();
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false));
if(Seeker.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);
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));
}
else if(Hider.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);
snowball.setItemMeta(snowballMeta);
player.getInventory().addItem(snowball);
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false));
}
}
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 static void unloadMap(String mapname){
if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(mapname), false)){
Main.plugin.getLogger().info("Successfully unloaded " + mapname);
}else{
Main.plugin.getLogger().severe("COULD NOT UNLOAD " + mapname);
}
}
public static void loadMap(String mapname){
Bukkit.getServer().createWorld(new WorldCreator(mapname));
Bukkit.getServer().getWorld("hideandseek_"+spawnWorld).setAutoSave(false);
}
public static void rollback(String mapname){
unloadMap(mapname);
loadMap(mapname);
}
public static void loadScoreboard() {
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard mainBoard = manager.getMainScoreboard();
try { mainBoard.registerNewTeam("Seeker");} catch(Exception e) {}
SeekerTeam = mainBoard.getTeam("Seeker");
SeekerTeam.setColor(ChatColor.RED);
if(nametagsVisible)
SeekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OTHER_TEAMS);
else
SeekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
try { mainBoard.registerNewTeam("Hider");} catch(Exception e) {}
HiderTeam = mainBoard.getTeam("Hider");
HiderTeam.setColor(ChatColor.GOLD);
if(nametagsVisible)
HiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM);
else
HiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
try { mainBoard.registerNewTeam("Spectator");} catch(Exception e) {}
SpectatorTeam = mainBoard.getTeam("Spectator");
SpectatorTeam.setColor(ChatColor.GRAY);
SpectatorTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
board = mainBoard;
}
public static void broadcastMessage(String message) {
for(Player player : playerList.values()) {
player.sendMessage(message);
}
}
public static boolean setup() {
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;
}
return true;
}
}

View file

@ -0,0 +1,57 @@
package net.tylermurphy.hideAndSeek.util;
import static net.tylermurphy.hideAndSeek.Config.*;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.WorldCreator;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
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;
return true;
}
public static void unloadMap(String mapname){
if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(mapname), false)){
Main.plugin.getLogger().info("Successfully unloaded " + mapname);
}else{
Main.plugin.getLogger().severe("COULD NOT UNLOAD " + mapname);
}
}
public static void loadMap(String mapname){
Bukkit.getServer().createWorld(new WorldCreator(mapname));
Bukkit.getServer().getWorld("hideandseek_"+spawnWorld).setAutoSave(false);
}
public static void rollback(String mapname){
unloadMap(mapname);
loadMap(mapname);
}
public static void sendDelayedMessage(String message, int gameId, int delay) {
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, new Runnable() {
public void run() {
if(gameId == Main.plugin.gameId)
Util.broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!");
}
}, delay);
}
}