summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/game')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/Board.java244
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java46
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/Game.java81
3 files changed, 227 insertions, 144 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java
index 936f7ac..e91e3da 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java
@@ -21,13 +21,11 @@ package net.tylermurphy.hideAndSeek.game;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.stream.Collectors;
import net.tylermurphy.hideAndSeek.util.Status;
+import net.tylermurphy.hideAndSeek.util.Version;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@@ -36,32 +34,28 @@ import org.bukkit.scoreboard.*;
public class Board {
- private static final List<String> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>();
- private static final Map<String, Player> playerList = new HashMap<>();
- private static final Map<String, CustomBoard> customBoards = new HashMap<>();
+ private static final List<UUID> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>();
+ private static final Map<UUID, Player> playerList = new HashMap<>();
+ private static final Map<UUID, CustomBoard> customBoards = new HashMap<>();
public static boolean isPlayer(Player player) {
- return playerList.containsKey(player.getName());
- }
-
- public static boolean isPlayer(String name){
- return playerList.containsKey(name);
+ return playerList.containsKey(player.getUniqueId());
}
public static boolean isPlayer(CommandSender sender) {
- return playerList.containsKey(sender.getName());
+ return playerList.containsKey(Bukkit.getPlayer(sender.getName()).getUniqueId());
}
public static boolean isHider(Player player) {
- return Hider.contains(player.getName());
+ return Hider.contains(player.getUniqueId());
}
public static boolean isSeeker(Player player) {
- return Seeker.contains(player.getName());
+ return Seeker.contains(player.getUniqueId());
}
public static boolean isSpectator(Player player) {
- return Spectator.contains(player.getName());
+ return Spectator.contains(player.getUniqueId());
}
public static int sizeHider() {
@@ -76,6 +70,13 @@ public class Board {
return playerList.values().size();
}
+ public static void check(){
+ for(UUID uuid : playerList.keySet()){
+ if(Bukkit.getPlayer(uuid) == null)
+ playerList.remove(uuid);
+ }
+ }
+
public static List<Player> getHiders(){
return Hider.stream().map(playerList::get).collect(Collectors.toList());
}
@@ -96,42 +97,42 @@ public class Board {
return new ArrayList<>(playerList.values());
}
- public static Player getPlayer(String name) {
- return playerList.get(name);
+ public static Player getPlayer(UUID uuid) {
+ return playerList.get(uuid);
}
public static void addHider(Player player) {
- Hider.add(player.getName());
- Seeker.remove(player.getName());
- Spectator.remove(player.getName());
- playerList.put(player.getName(), player);
+ Hider.add(player.getUniqueId());
+ Seeker.remove(player.getUniqueId());
+ Spectator.remove(player.getUniqueId());
+ playerList.put(player.getUniqueId(), player);
}
public static void addSeeker(Player player) {
- Hider.remove(player.getName());
- Seeker.add(player.getName());
- Spectator.remove(player.getName());
- playerList.put(player.getName(), player);
+ Hider.remove(player.getUniqueId());
+ Seeker.add(player.getUniqueId());
+ Spectator.remove(player.getUniqueId());
+ playerList.put(player.getUniqueId(), player);
}
public static void addSpectator(Player player) {
- Hider.remove(player.getName());
- Seeker.remove(player.getName());
- Spectator.add(player.getName());
- playerList.put(player.getName(), player);
+ Hider.remove(player.getUniqueId());
+ Seeker.remove(player.getUniqueId());
+ Spectator.add(player.getUniqueId());
+ playerList.put(player.getUniqueId(), player);
}
public static void remove(Player player) {
- Hider.remove(player.getName());
- Seeker.remove(player.getName());
- Spectator.remove(player.getName());
- playerList.remove(player.getName());
+ Hider.remove(player.getUniqueId());
+ Seeker.remove(player.getUniqueId());
+ Spectator.remove(player.getUniqueId());
+ playerList.remove(player.getUniqueId());
}
public static boolean onSameTeam(Player player1, Player player2) {
- if(Hider.contains(player1.getName()) && Hider.contains(player2.getName())) return true;
- else if(Seeker.contains(player1.getName()) && Seeker.contains(player2.getName())) return true;
- else return Spectator.contains(player1.getName()) && Spectator.contains(player2.getName());
+ if(Hider.contains(player1.getUniqueId()) && Hider.contains(player2.getUniqueId())) return true;
+ else if(Seeker.contains(player1.getUniqueId()) && Seeker.contains(player2.getUniqueId())) return true;
+ else return Spectator.contains(player1.getUniqueId()) && Spectator.contains(player2.getUniqueId());
}
public static void reload() {
@@ -145,27 +146,36 @@ public class Board {
}
private static void createLobbyBoard(Player player, boolean recreate) {
- CustomBoard board = customBoards.get(player.getName());
+ CustomBoard board = customBoards.get(player.getUniqueId());
if(recreate) {
board = new CustomBoard(player, "&l&eHIDE AND SEEK");
board.updateTeams();
}
- board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER %" + ChatColor.WHITE + getHiderPercent());
- board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER %" + ChatColor.WHITE + getSeekerPercent());
- board.addBlank();
- board.setLine("players", "Players: " + playerList.values().size());
- board.addBlank();
- if(lobbyCountdownEnabled){
- if(Game.countdownTime == -1){
- board.setLine("waiting", "Waiting for players...");
+ int i=0;
+ for(String line : LOBBY_CONTENTS){
+ if(line.equalsIgnoreCase("")){
+ board.addBlank();
+ } else if(line.contains("{COUNTDOWN}")){
+ if(!lobbyCountdownEnabled){
+ board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_ADMINSTART));
+ } else if(Game.countdownTime == -1){
+ board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_WAITING));
+ } else {
+ board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_COUNTING.replace("{AMOUNT}",Game.countdownTime+"")));
+ }
+ } else if(line.contains("{COUNT}")){
+ board.setLine(String.valueOf(i), line.replace("{COUNT}", getPlayers().size()+""));
+ } else if(line.contains("{SEEKER%}")){
+ board.setLine(String.valueOf(i), line.replace("{SEEKER%}", getSeekerPercent()+""));
+ } else if(line.contains("{HIDER%}")){
+ board.setLine(String.valueOf(i), line.replace("{HIDER%}", getHiderPercent()+""));
} else {
- board.setLine("waiting", "Starting in: "+ChatColor.GREEN + Game.countdownTime+"s");
+ board.setLine(String.valueOf(i), line);
}
- } else {
- board.setLine("waiting", "Waiting for gamemaster...");
+ i++;
}
board.display();
- customBoards.put(player.getName(), board);
+ customBoards.put(player.getUniqueId(), board);
}
public static void createGameBoard(Player player){
@@ -173,53 +183,69 @@ public class Board {
}
private static void createGameBoard(Player player, boolean recreate){
- CustomBoard board = customBoards.get(player.getName());
+ CustomBoard board = customBoards.get(player.getUniqueId());
if(recreate) {
- board = new CustomBoard(player, "&l&eHIDE AND SEEK");
+ board = new CustomBoard(player, GAME_TITLE);
board.updateTeams();
}
- board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDERS:" + ChatColor.WHITE + " " + Hider.size());
- board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size());
- board.addBlank();
- if(glowEnabled){
- if(Game.glow == null || Game.status == Status.STARTING || !Game.glow.isRunning())
- board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive");
- else
- board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active");
- }
- if(tauntEnabled && tauntCountdown){
- if(Game.taunt == null || Game.status == Status.STARTING)
- board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s");
- else if(!tauntLast && Hider.size() == 1){
- board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired");
- } else if(!Game.taunt.isRunning())
- board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Game.taunt.getDelay()/60 + "m" + Game.taunt.getDelay()%60 + "s");
- else
- board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active");
- }
- if(worldborderEnabled){
- if(Game.worldBorder == null || Game.status == Status.STARTING){
- board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s");
- } else if(!Game.worldBorder.isRunning()) {
- board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Game.worldBorder.getDelay()/60 + "m" + Game.worldBorder.getDelay()%60 + "s");
+
+ int i = 0;
+ for(String line : GAME_CONTENTS){
+ if(line.equalsIgnoreCase("")){
+ board.addBlank();
} else {
- board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "Decreasing");
+ if(line.contains("{TIME}")) {
+ String value = Game.timeLeft/60 + "m" + Game.timeLeft%60 + "s";
+ board.setLine(String.valueOf(i), line.replace("{TIME}", value));
+ } else if(line.contains("{TEAM}")) {
+ String value = getTeam(player);
+ board.setLine(String.valueOf(i), line.replace("{TEAM}", value));
+ } else if(line.contains("{BORDER}")) {
+ if(!worldborderEnabled) continue;
+ if(Game.worldBorder == null || Game.status == Status.STARTING){
+ board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replace("{AMOUNT}", "0")));
+ } else if(!Game.worldBorder.isRunning()) {
+ board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replaceFirst("\\{AMOUNT}", Game.worldBorder.getDelay()/60+"").replaceFirst("\\{AMOUNT}", Game.worldBorder.getDelay()%60+"")));
+ } else {
+ board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_DECREASING));
+ }
+ } else if(line.contains("{TAUNT}")){
+ if(!tauntEnabled) continue;
+ if(Game.taunt == null || Game.status == Status.STARTING) {
+ board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replace("{AMOUNT}", "0")));
+ } else if(!tauntLast && Hider.size() == 1){
+ board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_EXPIRED));
+ } else if(!Game.taunt.isRunning()) {
+ board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replaceFirst("\\{AMOUNT}", Game.taunt.getDelay() / 60 + "").replaceFirst("\\{AMOUNT}", Game.taunt.getDelay() % 60 + "")));
+ } else {
+ board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_ACTIVE));
+ }
+ } else if(line.contains("{GLOW}")){
+ if(!glowEnabled) return;
+ if(Game.glow == null || Game.status == Status.STARTING || !Game.glow.isRunning()) {
+ board.setLine(String.valueOf(i), line.replace("{GLOW}", GLOW_INACTIVE));
+ } else {
+ board.setLine(String.valueOf(i), line.replace("{GLOW}", GLOW_ACTIVE));
+ }
+ } else if(line.contains("{#SEEKER}")) {
+ board.setLine(String.valueOf(i), line.replace("{#SEEKER}", getSeekers().size()+""));
+ } else if(line.contains("{#HIDER}")) {
+ board.setLine(String.valueOf(i), line.replace("{#HIDER}", getHiders().size()+""));
+ } else {
+ board.setLine(String.valueOf(i), line);
+ }
}
+ i++;
}
- if(glowEnabled || (tauntEnabled && tauntCountdown) || worldborderEnabled)
- board.addBlank();
- board.setLine("time", "Time Left: " + ChatColor.GREEN + Game.timeLeft/60 + "m" + Game.timeLeft%60 + "s");
- board.addBlank();
- board.setLine("team", "Team: " + getTeam(player));
board.display();
- customBoards.put(player.getName(), board);
+ customBoards.put(player.getUniqueId(), board);
}
public static void removeBoard(Player player) {
ScoreboardManager manager = Bukkit.getScoreboardManager();
assert manager != null;
player.setScoreboard(manager.getMainScoreboard());
- customBoards.remove(player.getName());
+ customBoards.remove(player.getUniqueId());
}
public static void reloadLobbyBoards() {
@@ -258,6 +284,14 @@ public class Board {
else return ChatColor.WHITE + "UNKNOWN";
}
+ public static void cleanup(){
+ playerList.clear();
+ Hider.clear();
+ Seeker.clear();
+ Spectator.clear();
+ customBoards.clear();
+ }
+
}
class CustomBoard {
@@ -275,8 +309,13 @@ class CustomBoard {
this.board = manager.getNewScoreboard();
this.LINES = new HashMap<>();
this.player = player;
- this.obj = board.registerNewObjective(
- "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title));
+ if(Version.atLeast("1.13")){
+ this.obj = board.registerNewObjective(
+ "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title));
+ } else {
+ this.obj = board.registerNewObjective("Scoreboard", "dummy");
+ this.obj.setDisplayName(ChatColor.translateAlternateColorCodes('&', title));
+ }
this.blanks = 0;
this.displayed = false;
this.updateTeams();
@@ -297,23 +336,38 @@ class CustomBoard {
seekerTeam.removeEntry(entry);
for(Player player : Board.getSeekers())
seekerTeam.addEntry(player.getName());
- if(nametagsVisible) {
- hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM);
- seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS);
+ if(Version.atLeast("1.9")){
+ if(nametagsVisible) {
+ hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM);
+ seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS);
+ } else {
+ hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
+ seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
+ }
+ } else {
+ if(nametagsVisible) {
+ hiderTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS);
+ seekerTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OWN_TEAM);
+ } else {
+ hiderTeam.setNameTagVisibility(NameTagVisibility.NEVER);
+ seekerTeam.setNameTagVisibility(NameTagVisibility.NEVER);
+ }
+ }
+ if(Version.atLeast("1.12")){
+ hiderTeam.setColor(ChatColor.GOLD);
+ seekerTeam.setColor(ChatColor.RED);
} else {
- hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
- seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
+ hiderTeam.setPrefix(ChatColor.translateAlternateColorCodes('&', "&6"));
+ seekerTeam.setPrefix(ChatColor.translateAlternateColorCodes('&', "&c"));
}
- hiderTeam.setColor(ChatColor.GOLD);
- seekerTeam.setColor(ChatColor.RED);
}
public void setLine(String key, String message){
Line line = LINES.get(key);
if(line == null)
- addLine(key, message);
+ addLine(key, ChatColor.translateAlternateColorCodes('&',message));
else
- updateLine(key, message);
+ updateLine(key, ChatColor.translateAlternateColorCodes('&',message));
}
private void addLine(String key, String message){
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java
index 42589bc..ffe452b 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java
@@ -21,8 +21,11 @@ package net.tylermurphy.hideAndSeek.game;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import com.cryptomorin.xseries.XMaterial;
+import com.cryptomorin.xseries.XSound;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Status;
+import net.tylermurphy.hideAndSeek.util.Version;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
@@ -37,7 +40,6 @@ import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.player.*;
-import net.tylermurphy.hideAndSeek.util.Packet;
import org.bukkit.potion.PotionEffect;
import org.bukkit.projectiles.ProjectileSource;
@@ -178,16 +180,23 @@ public class EventListener implements Listener {
}
}
}
- if (player.getHealth() - event.getDamage() < 0 || !pvpEnabled) {
+ if (player.getHealth() - event.getFinalDamage() < 0.5 || !pvpEnabled) {
if (spawnPosition == null) return;
event.setCancelled(true);
- AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
- if(attribute != null)
- player.setHealth(attribute.getValue());
+ if(Version.atLeast("1.9")) {
+ AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
+ if (attribute != null) player.setHealth(attribute.getValue());
+ } else {
+ player.setHealth(player.getMaxHealth());
+ }
player.teleport(new Location(Bukkit.getWorld("hideandseek_" + spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
- Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1);
+ if(Version.atLeast("1.9")){
+ XSound.ENTITY_PLAYER_DEATH.play(player, 1, 1);
+ } else {
+ XSound.ENTITY_PLAYER_HURT.play(player, 1, 1);
+ }
if (Board.isSeeker(player)) {
- Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString());
+ Game.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString());
}
if (Board.isHider(player)) {
if (attacker == null) {
@@ -217,7 +226,8 @@ public class EventListener implements Listener {
if(Board.isHider(player)) {
Game.glow.onProjectile();
snowball.remove();
- player.getInventory().remove(Material.SNOWBALL);
+ assert XMaterial.SNOWBALL.parseMaterial() != null;
+ player.getInventory().remove(XMaterial.SNOWBALL.parseMaterial());
}
}
}
@@ -246,18 +256,16 @@ public class EventListener implements Listener {
Player player = event.getPlayer();
String message = event.getMessage();
String[] array = message.split(" ");
- if(array[0].equalsIgnoreCase("/kill")){
- if(Board.isPlayer(player)){
- Main.plugin.getLogger().info("Blocking "+player.getName()+ "from running /kill with anyone associated in the lobby");
+ String[] temp = array[0].split(":");
+ for(String handle : blockedCommands){
+ if(
+ array[0].substring(1).equalsIgnoreCase(handle) && Board.isPlayer(player) &&
+ temp[temp.length-1].substring(1).equalsIgnoreCase(handle) && Board.isPlayer(player) &&
+ Game.status != Status.STANDBY
+ ) {
+ player.sendMessage(errorPrefix + message("BLOCKED_COMMAND"));
event.setCancelled(true);
- } else if(array.length > 1){
- for(int i=1; i<array.length; i++){
- if(Board.isPlayer(array[i])){
- Main.plugin.getLogger().info("Blocking "+player.getName()+ "from running /kill with anyone associated in the lobby");
- event.setCancelled(true);
- return;
- }
- }
+ break;
}
}
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java
index 225eab0..41b0bc8 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java
@@ -21,14 +21,19 @@ package net.tylermurphy.hideAndSeek.game;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import com.cryptomorin.xseries.XMaterial;
+import com.cryptomorin.xseries.XSound;
+import com.cryptomorin.xseries.messages.Titles;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.database.Database;
import net.tylermurphy.hideAndSeek.util.Status;
+import net.tylermurphy.hideAndSeek.util.Version;
import net.tylermurphy.hideAndSeek.util.WinType;
import net.tylermurphy.hideAndSeek.world.WorldLoader;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
+import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
@@ -42,7 +47,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
-import java.beans.EventHandler;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
@@ -92,11 +96,12 @@ public class Game {
for(Player player : Board.getSeekers()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false));
- player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString(), 10, 70, 20);
+ player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP,1000000,128,false,false));
+ Titles.sendTitle(player, 10, 70, 20, ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString());
}
for(Player player : Board.getHiders()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
- player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString(), 10, 70, 20);
+ Titles.sendTitle(player, 10, 70, 20, ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString());
}
if(tauntEnabled)
taunt = new Taunt();
@@ -153,8 +158,10 @@ public class Game {
player.removePotionEffect(effect.getType());
}
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
- for(Player temp : Board.getPlayers()) {
- Packet.setGlow(player, temp, false);
+ if(Version.atLeast("1.9")){
+ for(Player temp : Board.getPlayers()) {
+ Packet.setGlow(player, temp, false);
+ }
}
}
EventListener.temp_loc.clear();
@@ -207,7 +214,8 @@ public class Game {
for(PotionEffect effect : Items.HIDER_EFFECTS)
player.addPotionEffect(effect);
if(glowEnabled) {
- ItemStack snowball = new ItemStack(Material.SNOWBALL, 1);
+ assert XMaterial.SNOWBALL.parseMaterial() != null;
+ ItemStack snowball = new ItemStack(XMaterial.SNOWBALL.parseMaterial(), 1);
ItemMeta snowballMeta = snowball.getItemMeta();
assert snowballMeta != null;
snowballMeta.setDisplayName("Glow Powerup");
@@ -238,11 +246,16 @@ public class Game {
player.setGameMode(GameMode.SPECTATOR);
Board.createGameBoard(player);
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
- player.sendTitle(ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString(), 10, 70, 20);
+ Titles.sendTitle(player, 10, 70, 20, ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString());
}
player.setFoodLevel(20);
- player.setHealth(Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getBaseValue());
+ if(Version.atLeast("1.9")) {
+ AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
+ if (attribute != null) player.setHealth(attribute.getValue());
+ } else {
+ player.setHealth(player.getMaxHealth());
+ }
}
public static void removeItems(Player player){
@@ -261,8 +274,10 @@ public class Game {
countdownTime = countdown;
if(Board.size() >= changeCountdown)
countdownTime = Math.min(countdownTime, 10);
- if(tick % 20 == 0)
+ if(tick % 20 == 0) {
countdownTime--;
+ Board.reloadLobbyBoards();
+ }
if(countdownTime == 0){
Optional<Player> rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst();
if(!rand.isPresent()){
@@ -270,7 +285,16 @@ public class Game {
return;
}
String seekerName = rand.get().getName();
- Player seeker = Board.getPlayer(seekerName);
+ Player temp = Bukkit.getPlayer(seekerName);
+ if(temp == null){
+ Main.plugin.getLogger().warning("Failed to select random seeker.");
+ return;
+ }
+ Player seeker = Board.getPlayer(temp.getUniqueId());
+ if(seeker == null){
+ Main.plugin.getLogger().warning("Failed to select random seeker.");
+ return;
+ }
start(seeker);
}
} else {
@@ -296,20 +320,20 @@ public class Game {
distance = temp;
}
}
- switch(tick%10) {
+ if(seekerPing) switch(tick%10) {
case 0:
- if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f);
- if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
+ if(distance < seekerPingLevel1) XSound.BLOCK_NOTE_BLOCK_BASEDRUM.play(hider, .5f, 1f);
+ if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f);
break;
case 3:
- if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f);
- if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
+ if(distance < seekerPingLevel1) XSound.BLOCK_NOTE_BLOCK_BASEDRUM.play(hider, .3f, 1f);
+ if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f);
break;
case 6:
- if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
+ if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f);
break;
case 9:
- if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
+ if(distance < seekerPingLevel2) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f);
break;
}
}
@@ -362,21 +386,18 @@ class Glow {
public void onProjectile() {
if(glowStackable) glowTime += glowLength;
else glowTime = glowLength;
- if(!running)
- startGlow();
+ running = true;
}
- private void startGlow() {
- running = true;
- for(Player hider : Board.getHiders()) {
- for(Player seeker : Board.getSeekers()) {
+ private void sendPackets(){
+ for(Player hider : Board.getHiders())
+ for(Player seeker : Board.getSeekers())
Packet.setGlow(hider, seeker, true);
- }
- }
}
protected void update() {
if(running) {
+ sendPackets();
glowTime--;
glowTime = Math.max(glowTime, 0);
if (glowTime == 0) {
@@ -402,7 +423,7 @@ class Glow {
class Taunt {
- private String tauntPlayer;
+ private UUID tauntPlayer;
private int delay;
private boolean running;
@@ -429,7 +450,7 @@ class Taunt {
Player taunted = rand.get();
taunted.sendMessage(message("TAUNTED").toString());
broadcastMessage(tauntPrefix + message("TAUNT"));
- tauntPlayer = taunted.getName();
+ tauntPlayer = taunted.getUniqueId();
running = true;
delay = 30;
}
@@ -439,7 +460,7 @@ class Taunt {
if(taunted != null) {
if(!Board.isHider(taunted)){
Main.plugin.getLogger().info("Taunted played died and is now seeker. Skipping taunt.");
- tauntPlayer = "";
+ tauntPlayer = null;
running = false;
delay = tauntDelay;
return;
@@ -447,7 +468,7 @@ class Taunt {
World world = taunted.getLocation().getWorld();
if(world == null){
Main.plugin.getLogger().severe("Game world is null while trying to launch taunt.");
- tauntPlayer = "";
+ tauntPlayer = null;
running = false;
delay = tauntDelay;
return;
@@ -468,7 +489,7 @@ class Taunt {
fw.setFireworkMeta(fwm);
broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE"));
}
- tauntPlayer = "";
+ tauntPlayer = null;
running = false;
delay = tauntDelay;
}