1.4.0 rc3

This commit is contained in:
Tyler Murphy 2022-04-13 13:47:59 -04:00
parent 3794537cf4
commit 19488e62bf
6 changed files with 77 additions and 65 deletions

View file

@ -46,7 +46,7 @@ public class Main extends JavaPlugin implements Listener {
public static Main plugin; public static Main plugin;
public static File root, data; public static File root, data;
private BukkitTask onTickTask; private int onTickTask;
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
@ -69,13 +69,13 @@ public class Main extends JavaPlugin implements Listener {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
},0,1); },0,1).getTaskId();
} }
public void onDisable() { public void onDisable() {
if(onTickTask != null) Main.plugin.getServer().getScheduler().cancelTask(onTickTask);
onTickTask.cancel();
UUIDFetcher.cleanup(); UUIDFetcher.cleanup();
Board.cleanup();
} }
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {

View file

@ -24,6 +24,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
import net.tylermurphy.hideAndSeek.game.Board; import net.tylermurphy.hideAndSeek.game.Board;
import net.tylermurphy.hideAndSeek.game.Game; import net.tylermurphy.hideAndSeek.game.Game;
import net.tylermurphy.hideAndSeek.util.Status; import net.tylermurphy.hideAndSeek.util.Status;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -64,7 +65,12 @@ public class Start implements ICommand {
} else { } else {
seekerName = args[0]; seekerName = args[0];
} }
Player seeker = Board.getPlayer(seekerName); Player temp = Bukkit.getPlayer(seekerName);
if(temp == null) {
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName));
return;
}
Player seeker = Board.getPlayer(temp.getUniqueId());
if(seeker == null) { if(seeker == null) {
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName));
return; return;

View file

@ -34,32 +34,28 @@ import org.bukkit.scoreboard.*;
public class Board { public class Board {
private static final List<String> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>(); private static final List<UUID> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>();
private static final Map<String, Player> playerList = new HashMap<>(); private static final Map<UUID, Player> playerList = new HashMap<>();
private static final Map<String, CustomBoard> customBoards = new HashMap<>(); private static final Map<UUID, CustomBoard> customBoards = new HashMap<>();
public static boolean isPlayer(Player player) { public static boolean isPlayer(Player player) {
return playerList.containsKey(player.getName()); return playerList.containsKey(player.getUniqueId());
}
public static boolean isPlayer(String name){
return playerList.containsKey(name);
} }
public static boolean isPlayer(CommandSender sender) { 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) { public static boolean isHider(Player player) {
return Hider.contains(player.getName()); return Hider.contains(player.getUniqueId());
} }
public static boolean isSeeker(Player player) { public static boolean isSeeker(Player player) {
return Seeker.contains(player.getName()); return Seeker.contains(player.getUniqueId());
} }
public static boolean isSpectator(Player player) { public static boolean isSpectator(Player player) {
return Spectator.contains(player.getName()); return Spectator.contains(player.getUniqueId());
} }
public static int sizeHider() { public static int sizeHider() {
@ -74,6 +70,13 @@ public class Board {
return playerList.values().size(); 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(){ public static List<Player> getHiders(){
return Hider.stream().map(playerList::get).collect(Collectors.toList()); return Hider.stream().map(playerList::get).collect(Collectors.toList());
} }
@ -94,42 +97,42 @@ public class Board {
return new ArrayList<>(playerList.values()); return new ArrayList<>(playerList.values());
} }
public static Player getPlayer(String name) { public static Player getPlayer(UUID uuid) {
return playerList.get(name); return playerList.get(uuid);
} }
public static void addHider(Player player) { public static void addHider(Player player) {
Hider.add(player.getName()); Hider.add(player.getUniqueId());
Seeker.remove(player.getName()); Seeker.remove(player.getUniqueId());
Spectator.remove(player.getName()); Spectator.remove(player.getUniqueId());
playerList.put(player.getName(), player); playerList.put(player.getUniqueId(), player);
} }
public static void addSeeker(Player player) { public static void addSeeker(Player player) {
Hider.remove(player.getName()); Hider.remove(player.getUniqueId());
Seeker.add(player.getName()); Seeker.add(player.getUniqueId());
Spectator.remove(player.getName()); Spectator.remove(player.getUniqueId());
playerList.put(player.getName(), player); playerList.put(player.getUniqueId(), player);
} }
public static void addSpectator(Player player) { public static void addSpectator(Player player) {
Hider.remove(player.getName()); Hider.remove(player.getUniqueId());
Seeker.remove(player.getName()); Seeker.remove(player.getUniqueId());
Spectator.add(player.getName()); Spectator.add(player.getUniqueId());
playerList.put(player.getName(), player); playerList.put(player.getUniqueId(), player);
} }
public static void remove(Player player) { public static void remove(Player player) {
Hider.remove(player.getName()); Hider.remove(player.getUniqueId());
Seeker.remove(player.getName()); Seeker.remove(player.getUniqueId());
Spectator.remove(player.getName()); Spectator.remove(player.getUniqueId());
playerList.remove(player.getName()); playerList.remove(player.getUniqueId());
} }
public static boolean onSameTeam(Player player1, Player player2) { public static boolean onSameTeam(Player player1, Player player2) {
if(Hider.contains(player1.getName()) && Hider.contains(player2.getName())) return true; if(Hider.contains(player1.getUniqueId()) && Hider.contains(player2.getUniqueId())) return true;
else if(Seeker.contains(player1.getName()) && Seeker.contains(player2.getName())) return true; else if(Seeker.contains(player1.getUniqueId()) && Seeker.contains(player2.getUniqueId())) return true;
else return Spectator.contains(player1.getName()) && Spectator.contains(player2.getName()); else return Spectator.contains(player1.getUniqueId()) && Spectator.contains(player2.getUniqueId());
} }
public static void reload() { public static void reload() {
@ -143,7 +146,7 @@ public class Board {
} }
private static void createLobbyBoard(Player player, boolean recreate) { private static void createLobbyBoard(Player player, boolean recreate) {
CustomBoard board = customBoards.get(player.getName()); CustomBoard board = customBoards.get(player.getUniqueId());
if(recreate) { if(recreate) {
board = new CustomBoard(player, "&l&eHIDE AND SEEK"); board = new CustomBoard(player, "&l&eHIDE AND SEEK");
board.updateTeams(); board.updateTeams();
@ -172,7 +175,7 @@ public class Board {
i++; i++;
} }
board.display(); board.display();
customBoards.put(player.getName(), board); customBoards.put(player.getUniqueId(), board);
} }
public static void createGameBoard(Player player){ public static void createGameBoard(Player player){
@ -180,7 +183,7 @@ public class Board {
} }
private static void createGameBoard(Player player, boolean recreate){ private static void createGameBoard(Player player, boolean recreate){
CustomBoard board = customBoards.get(player.getName()); CustomBoard board = customBoards.get(player.getUniqueId());
if(recreate) { if(recreate) {
board = new CustomBoard(player, GAME_TITLE); board = new CustomBoard(player, GAME_TITLE);
board.updateTeams(); board.updateTeams();
@ -235,14 +238,14 @@ public class Board {
i++; i++;
} }
board.display(); board.display();
customBoards.put(player.getName(), board); customBoards.put(player.getUniqueId(), board);
} }
public static void removeBoard(Player player) { public static void removeBoard(Player player) {
ScoreboardManager manager = Bukkit.getScoreboardManager(); ScoreboardManager manager = Bukkit.getScoreboardManager();
assert manager != null; assert manager != null;
player.setScoreboard(manager.getMainScoreboard()); player.setScoreboard(manager.getMainScoreboard());
customBoards.remove(player.getName()); customBoards.remove(player.getUniqueId());
} }
public static void reloadLobbyBoards() { public static void reloadLobbyBoards() {
@ -281,6 +284,14 @@ public class Board {
else return ChatColor.WHITE + "UNKNOWN"; else return ChatColor.WHITE + "UNKNOWN";
} }
public static void cleanup(){
playerList.clear();
Hider.clear();
Seeker.clear();
Spectator.clear();
customBoards.clear();
}
} }
class CustomBoard { class CustomBoard {

View file

@ -40,7 +40,6 @@ import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.player.*; import org.bukkit.event.player.*;
import net.tylermurphy.hideAndSeek.util.Packet;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
@ -257,20 +256,6 @@ public class EventListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
String message = event.getMessage(); String message = event.getMessage();
String[] array = message.split(" "); 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");
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;
}
}
}
}
String[] temp = array[0].split(":"); String[] temp = array[0].split(":");
for(String handle : blockedCommands){ for(String handle : blockedCommands){
if( if(

View file

@ -285,7 +285,16 @@ public class Game {
return; return;
} }
String seekerName = rand.get().getName(); 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); start(seeker);
} }
} else { } else {
@ -414,7 +423,7 @@ class Glow {
class Taunt { class Taunt {
private String tauntPlayer; private UUID tauntPlayer;
private int delay; private int delay;
private boolean running; private boolean running;
@ -441,7 +450,7 @@ class Taunt {
Player taunted = rand.get(); Player taunted = rand.get();
taunted.sendMessage(message("TAUNTED").toString()); taunted.sendMessage(message("TAUNTED").toString());
broadcastMessage(tauntPrefix + message("TAUNT")); broadcastMessage(tauntPrefix + message("TAUNT"));
tauntPlayer = taunted.getName(); tauntPlayer = taunted.getUniqueId();
running = true; running = true;
delay = 30; delay = 30;
} }
@ -451,7 +460,7 @@ class Taunt {
if(taunted != null) { if(taunted != null) {
if(!Board.isHider(taunted)){ if(!Board.isHider(taunted)){
Main.plugin.getLogger().info("Taunted played died and is now seeker. Skipping taunt."); Main.plugin.getLogger().info("Taunted played died and is now seeker. Skipping taunt.");
tauntPlayer = ""; tauntPlayer = null;
running = false; running = false;
delay = tauntDelay; delay = tauntDelay;
return; return;
@ -459,7 +468,7 @@ class Taunt {
World world = taunted.getLocation().getWorld(); World world = taunted.getLocation().getWorld();
if(world == null){ if(world == null){
Main.plugin.getLogger().severe("Game world is null while trying to launch taunt."); Main.plugin.getLogger().severe("Game world is null while trying to launch taunt.");
tauntPlayer = ""; tauntPlayer = null;
running = false; running = false;
delay = tauntDelay; delay = tauntDelay;
return; return;
@ -480,7 +489,7 @@ class Taunt {
fw.setFireworkMeta(fwm); fw.setFireworkMeta(fwm);
broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE")); broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE"));
} }
tauntPlayer = ""; tauntPlayer = null;
running = false; running = false;
delay = tauntDelay; delay = tauntDelay;
} }

View file

@ -70,7 +70,8 @@ taunt:
# the amount of time set in seconds. You can allow it to be stackable, meaning # the amount of time set in seconds. You can allow it to be stackable, meaning
# when multiple Hiders use the powerup at the same time, it stacks the times, or # when multiple Hiders use the powerup at the same time, it stacks the times, or
# just overwrites. Only Hiders can see that the Seekers are glowing. Delay must # just overwrites. Only Hiders can see that the Seekers are glowing. Delay must
# be longer than 1s. # be longer than 1s. Since the glow effect wasn't added until Minecraft 1.9,
# any server running 1.8 will have this disabled regardless of the options below.
glow: glow:
time: 30 time: 30
stackable: true stackable: true