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 File root, data;
private BukkitTask onTickTask;
private int onTickTask;
public void onEnable() {
plugin = this;
@ -69,13 +69,13 @@ public class Main extends JavaPlugin implements Listener {
} catch (Exception e) {
e.printStackTrace();
}
},0,1);
},0,1).getTaskId();
}
public void onDisable() {
if(onTickTask != null)
onTickTask.cancel();
Main.plugin.getServer().getScheduler().cancelTask(onTickTask);
UUIDFetcher.cleanup();
Board.cleanup();
}
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.Game;
import net.tylermurphy.hideAndSeek.util.Status;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -64,7 +65,12 @@ public class Start implements ICommand {
} else {
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) {
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName));
return;

View file

@ -34,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() {
@ -74,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());
}
@ -94,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() {
@ -143,7 +146,7 @@ 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();
@ -172,7 +175,7 @@ public class Board {
i++;
}
board.display();
customBoards.put(player.getName(), board);
customBoards.put(player.getUniqueId(), board);
}
public static void createGameBoard(Player player){
@ -180,7 +183,7 @@ 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, GAME_TITLE);
board.updateTeams();
@ -235,14 +238,14 @@ public class Board {
i++;
}
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() {
@ -281,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 {

View file

@ -40,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;
@ -257,20 +256,6 @@ 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");
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(":");
for(String handle : blockedCommands){
if(

View file

@ -285,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 {
@ -414,7 +423,7 @@ class Glow {
class Taunt {
private String tauntPlayer;
private UUID tauntPlayer;
private int delay;
private boolean running;
@ -441,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;
}
@ -451,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;
@ -459,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;
@ -480,7 +489,7 @@ class Taunt {
fw.setFireworkMeta(fwm);
broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE"));
}
tauntPlayer = "";
tauntPlayer = null;
running = false;
delay = tauntDelay;
}

View file

@ -70,7 +70,8 @@ taunt:
# 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
# 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:
time: 30
stackable: true