Moves arena-related locations to their own class

This commit is contained in:
Kristian Knarvik 2023-07-20 15:20:36 +02:00
parent cc0007fb1b
commit 79cd565cb5
11 changed files with 465 additions and 161 deletions

View File

@ -43,6 +43,7 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.List;
public class BlockHunt extends JavaPlugin implements Listener {
@ -111,10 +112,10 @@ public class BlockHunt extends JavaPlugin implements Listener {
if (arena.timer == 60 || arena.timer == 30 || arena.timer == 10) {
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timer);
} else if (arena.timer <= 5) {
World world = arena.lobbyWarp.getWorld();
World world = arena.arenaLocations.getLobbyWarp().getWorld();
if (world != null) {
int pitch = (int) (2 - Math.floor(arena.timer / 2.0));
world.playSound(arena.lobbyWarp, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, pitch);
world.playSound(arena.arenaLocations.getLobbyWarp(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, pitch);
}
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timer);
}
@ -145,7 +146,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
if (!arena.seekers.contains(seeker)) {
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_CHOSEN, "seeker-" + seeker.getName());
arena.seekers.add(seeker);
PlayerHandler.teleport(seeker, arena.seekersWarp);
PlayerHandler.teleport(seeker, arena.arenaLocations.getSeekersWarp());
seeker.getInventory().clear();
seeker.updateInventory();
seeker.setWalkSpeed(0.3F);
@ -169,7 +170,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
MiscDisguise disguise = new MiscDisguise(DisguiseType.FALLING_BLOCK, block.getType());
DisguiseAPI.disguiseToAll(arenaPlayer, disguise);
PlayerHandler.teleport(arenaPlayer, arena.hidersWarp);
PlayerHandler.teleport(arenaPlayer, arena.arenaLocations.getHidersWarp());
ItemStack blockCount = new ItemStack(block.getType(), 5);
arenaPlayer.getInventory().setItem(8, blockCount);
arenaPlayer.getInventory().setHelmet(new ItemStack(block));
@ -204,7 +205,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
if (MemoryStorage.seekerTime.get(player) != null) {
MemoryStorage.seekerTime.put(player, MemoryStorage.seekerTime.get(player) - 1);
if (MemoryStorage.seekerTime.get(player) <= 0) {
PlayerHandler.teleport(player, arena.hidersWarp);
PlayerHandler.teleport(player, arena.arenaLocations.getHidersWarp());
MemoryStorage.seekerTime.remove(player);
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_SPAWNED,
"%playerName%-" + player.getName());
@ -228,7 +229,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
// blockAnnouncer code.
if ((arena.blockAnnouncerTime > 0) && (arena.timer == arena.blockAnnouncerTime)) {
ArrayList<String> remainingBlocks = new ArrayList<>();
List<String> remainingBlocks = new ArrayList<>();
for (Player arenaPlayer : arena.playersInArena) {
if (!arena.seekers.contains(arenaPlayer)) {
ItemStack item = arenaPlayer.getInventory().getItem(8);
@ -246,10 +247,10 @@ public class BlockHunt extends JavaPlugin implements Listener {
if (arena.timer == 190 || arena.timer == 60 || arena.timer == 30 || arena.timer == 10) {
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_ARENA_END, "1-" + arena.timer);
} else if (arena.timer <= 5) {
World world = arena.lobbyWarp.getWorld();
World world = arena.arenaLocations.getLobbyWarp().getWorld();
if (world != null) {
int pitch = (int) (2 - Math.floor(arena.timer / 2.0));
world.playSound(arena.lobbyWarp, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, pitch);
world.playSound(arena.arenaLocations.getLobbyWarp(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, pitch);
}
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timer);
}

View File

@ -90,32 +90,32 @@ public class InventoryHandler {
//
updownButton(panel, arena, ArenaProperty.MAX_PLAYERS, "maxPlayers", "1", maxPlayers_UP, maxPlayers, maxPlayers_DOWN, 1, 10, 19);
upDownButton(panel, arena, ArenaProperty.MAX_PLAYERS, "maxPlayers", "1", maxPlayers_UP, maxPlayers, maxPlayers_DOWN, 1, 10, 19);
updownButton(panel, arena, ArenaProperty.MIN_PLAYERS, "minPlayers", "1", minPlayers_UP, minPlayers, minPlayers_DOWN, 2, 11, 20);
upDownButton(panel, arena, ArenaProperty.MIN_PLAYERS, "minPlayers", "1", minPlayers_UP, minPlayers, minPlayers_DOWN, 2, 11, 20);
updownButton(panel, arena, ArenaProperty.AMOUNT_SEEKERS_ON_START, "amountSeekersOnStart", "1", amountSeekersOnStart_UP, amountSeekersOnStart,
upDownButton(panel, arena, ArenaProperty.AMOUNT_SEEKERS_ON_START, "amountSeekersOnStart", "1", amountSeekersOnStart_UP, amountSeekersOnStart,
amountSeekersOnStart_DOWN, 4, 13, 22);
updownButton(panel, arena, ArenaProperty.TIME_IN_LOBBY_UNTIL_START, "timeInLobbyUntilStart", "1 %Nsecond", timeInLobbyUntilStart_UP, timeInLobbyUntilStart,
upDownButton(panel, arena, ArenaProperty.TIME_IN_LOBBY_UNTIL_START, "timeInLobbyUntilStart", "1 %Nsecond", timeInLobbyUntilStart_UP, timeInLobbyUntilStart,
timeInLobbyUntilStart_DOWN, 6, 15, 24);
updownButton(panel, arena, ArenaProperty.WAITING_TIME_SEEKER, "waitingTimeSeeker", "1 %Nsecond", waitingTimeSeeker_UP, waitingTimeSeeker, waitingTimeSeeker_DOWN,
upDownButton(panel, arena, ArenaProperty.WAITING_TIME_SEEKER, "waitingTimeSeeker", "1 %Nsecond", waitingTimeSeeker_UP, waitingTimeSeeker, waitingTimeSeeker_DOWN,
7, 16, 25);
updownButton(panel, arena, ArenaProperty.GAME_TIME, "gameTime", "1 %Nsecond", gameTime_UP, gameTime, gameTime_DOWN, 8, 17, 26);
upDownButton(panel, arena, ArenaProperty.GAME_TIME, "gameTime", "1 %Nsecond", gameTime_UP, gameTime, gameTime_DOWN, 8, 17, 26);
updownButton(panel, arena, ArenaProperty.BLOCK_ANNOUNCER_TIME, "blockAnnouncerTime", "5 %Nseconds", blockAnnouncerTime_UP, blockAnnouncerTime,
upDownButton(panel, arena, ArenaProperty.BLOCK_ANNOUNCER_TIME, "blockAnnouncerTime", "5 %Nseconds", blockAnnouncerTime_UP, blockAnnouncerTime,
blockAnnouncerTime_DOWN, 29, 38, 47);
updownButton(panel, arena, ArenaProperty.TIME_UNTIL_HIDERS_SWORD, "timeUntilHidersSword", "1 %Nsecond", timeUntilHidersSword_UP, timeUntilHidersSword,
upDownButton(panel, arena, ArenaProperty.TIME_UNTIL_HIDERS_SWORD, "timeUntilHidersSword", "1 %Nsecond", timeUntilHidersSword_UP, timeUntilHidersSword,
timeUntilHidersSword_DOWN, 30, 39, 48);
updownButton(panel, arena, ArenaProperty.HIDERS_TOKEN_WIN, "hidersTokenWin", "1 %Ntoken", hidersTokenWin_UP, hidersTokenWin, hidersTokenWin_DOWN, 32, 41, 50);
upDownButton(panel, arena, ArenaProperty.HIDERS_TOKEN_WIN, "hidersTokenWin", "1 %Ntoken", hidersTokenWin_UP, hidersTokenWin, hidersTokenWin_DOWN, 32, 41, 50);
updownButton(panel, arena, ArenaProperty.SEEKERS_TOKEN_WIN, "seekersTokenWin", "1 %Ntoken", seekersTokenWin_UP, seekersTokenWin, seekersTokenWin_DOWN, 33, 42, 51);
upDownButton(panel, arena, ArenaProperty.SEEKERS_TOKEN_WIN, "seekersTokenWin", "1 %Ntoken", seekersTokenWin_UP, seekersTokenWin, seekersTokenWin_DOWN, 33, 42, 51);
updownButton(panel, arena, ArenaProperty.KILL_TOKENS, "killTokens", "1 %Ntoken", killTokens_UP, killTokens, killTokens_DOWN, 34, 43, 52);
upDownButton(panel, arena, ArenaProperty.KILL_TOKENS, "killTokens", "1 %Ntoken", killTokens_UP, killTokens, killTokens_DOWN, 34, 43, 52);
player.openInventory(panel);
} else {
@ -123,13 +123,15 @@ public class InventoryHandler {
}
}
public static void updownButton(Inventory panel, Arena arena, ArenaProperty at, String option, String addremove, ItemStack UP, ItemStack BUTTON, ItemStack DOWN, int up,
int button, int down) {
ItemMeta UP_IM = UP.getItemMeta();
UP_IM.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.messages.get(MessageKey.BUTTON_ADD), "1-" + addremove, "2-" + option));
UP.setItemMeta(UP_IM);
public static void upDownButton(Inventory panel, Arena arena, ArenaProperty arenaProperty, String option,
String addRemove, ItemStack upItem, ItemStack buttonItem, ItemStack downItem,
int up, int button, int down) {
ItemMeta upItemItemMeta = upItem.getItemMeta();
upItemItemMeta.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.messages.get(MessageKey.BUTTON_ADD),
"1-" + addRemove, "2-" + option));
upItem.setItemMeta(upItemItemMeta);
int setting = switch (at) {
int setting = switch (arenaProperty) {
case MAX_PLAYERS -> arena.maxPlayers;
case MIN_PLAYERS -> arena.minPlayers;
case AMOUNT_SEEKERS_ON_START -> arena.amountSeekersOnStart;
@ -141,20 +143,21 @@ public class InventoryHandler {
case HIDERS_TOKEN_WIN -> arena.hidersTokenWin;
case SEEKERS_TOKEN_WIN -> arena.seekersTokenWin;
case KILL_TOKENS -> arena.killTokens;
default -> 0;
};
ItemMeta BUTTON_IM = BUTTON.getItemMeta();
BUTTON_IM.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.messages.get(MessageKey.BUTTON_SETTING), "1-" + option, "2-" + setting));
BUTTON.setItemMeta(BUTTON_IM);
ItemMeta buttonItemMeta = buttonItem.getItemMeta();
buttonItemMeta.setDisplayName(MessageManager.replaceAll(
(String) MemoryStorage.messages.get(MessageKey.BUTTON_SETTING), "1-" + option, "2-" + setting));
buttonItem.setItemMeta(buttonItemMeta);
ItemMeta DOWN_IM = DOWN.getItemMeta();
DOWN_IM.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.messages.get(MessageKey.BUTTON_REMOVE), "1-" + addremove, "2-" + option));
DOWN.setItemMeta(DOWN_IM);
ItemMeta DOWN_IM = downItem.getItemMeta();
DOWN_IM.setDisplayName(MessageManager.replaceAll(
(String) MemoryStorage.messages.get(MessageKey.BUTTON_REMOVE), "1-" + addRemove, "2-" + option));
downItem.setItemMeta(DOWN_IM);
panel.setItem(up, UP);
panel.setItem(button, BUTTON);
panel.setItem(down, DOWN);
panel.setItem(up, upItem);
panel.setItem(button, buttonItem);
panel.setItem(down, downItem);
}
public static void openDisguiseBlocks(Arena arena, Player player) {
@ -162,12 +165,12 @@ public class InventoryHandler {
Inventory panel = Bukkit.createInventory(null, 36, MessageManager.replaceAll("%N&lDisguiseBlocks"));
ItemStack arenaNameNote = new ItemStack(Material.PAPER, 1);
ItemMeta arenaNameNote_IM = arenaNameNote.getItemMeta();
arenaNameNote_IM.setDisplayName(MessageManager.replaceAll("%NDisguiseBlocks of arena: %A" + arenaName));
ArrayList<String> lores = new ArrayList<>();
lores.add(MessageManager.replaceAll("%NPlace the DisguiseBlocks inside this inventory."));
arenaNameNote_IM.setLore(lores);
arenaNameNote.setItemMeta(arenaNameNote_IM);
ItemMeta arenaNameNoteItemMeta = arenaNameNote.getItemMeta();
arenaNameNoteItemMeta.setDisplayName(MessageManager.replaceAll("%NDisguiseBlocks of arena: %A" + arenaName));
List<String> loreLines = new ArrayList<>();
loreLines.add(MessageManager.replaceAll("%NPlace the DisguiseBlocks inside this inventory."));
arenaNameNoteItemMeta.setLore(loreLines);
arenaNameNote.setItemMeta(arenaNameNoteItemMeta);
panel.setItem(0, arenaNameNote);
if (arena.disguiseBlocks != null) {
for (int i = arena.disguiseBlocks.size(); i > 0; i = i - 1) {
@ -178,51 +181,59 @@ public class InventoryHandler {
}
public static void openShop(Player player) {
Inventory shop = Bukkit.createInventory(null, 9, MessageManager.replaceAll("\u00A7r" + MemoryStorage.config.get(ConfigKey.SHOP_TITLE)));
Inventory shop = Bukkit.createInventory(null, 9, MessageManager.replaceAll("\u00A7r" +
MemoryStorage.config.get(ConfigKey.SHOP_TITLE)));
if (MemoryStorage.shop.getFile().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", 0);
MemoryStorage.shop.save();
}
int playerTokens = MemoryStorage.shop.getFile().getInt(player.getName() + ".tokens");
List<String> lores = new ArrayList<>();
List<String> lores2 = new ArrayList<>();
List<String> loreLines;
List<String> loreLines2;
ItemStack shopTokens = new ItemStack(Material.EMERALD, 1);
ItemMeta shopTokens_IM = shopTokens.getItemMeta();
shopTokens_IM.setDisplayName(MessageManager.replaceAll("%N&lTokens: %A" + playerTokens));
shopTokens.setItemMeta(shopTokens_IM);
ItemStack shopBlockChooser = new ItemStack(Material.getMaterial((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ID_NAME)), 1);
ItemStack shopBlockChooser = new ItemStack(Material.getMaterial((String) MemoryStorage.config.get(
ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ID_NAME)), 1);
ItemMeta shopBlockChooser_IM = shopBlockChooser.getItemMeta();
shopBlockChooser_IM.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)));
lores = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_DESCRIPTION.getPath());
lores2 = new ArrayList<>();
for (String lore : lores) {
lores2.add(MessageManager.replaceAll(lore));
shopBlockChooser_IM.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.config.get(
ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)));
loreLines = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_DESCRIPTION.getPath());
loreLines2 = new ArrayList<>();
for (String lore : loreLines) {
loreLines2.add(MessageManager.replaceAll(lore));
}
lores2.add(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_PRICE), "amount-" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_PRICE)));
loreLines2.add(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_PRICE),
"amount-" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_PRICE)));
shopBlockChooser_IM.setLore(lores2);
shopBlockChooser_IM.setLore(loreLines2);
shopBlockChooser.setItemMeta(shopBlockChooser_IM);
ItemStack shopBlockHuntPass = new ItemStack(Material.getMaterial((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ID_NAME)), 1);
ItemStack shopBlockHuntPass = new ItemStack(Material.getMaterial((String) MemoryStorage.config.get(
ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ID_NAME)), 1);
ItemMeta shopBlockHuntPass_IM = shopBlockHuntPass.getItemMeta();
shopBlockHuntPass_IM.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME)));
lores = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_DESCRIPTION.getPath());
lores2 = new ArrayList<>();
for (String lore : lores) {
lores2.add(MessageManager.replaceAll(lore));
shopBlockHuntPass_IM.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.config.get(
ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME)));
loreLines = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_DESCRIPTION.getPath());
loreLines2 = new ArrayList<>();
for (String lore : loreLines) {
loreLines2.add(MessageManager.replaceAll(lore));
}
lores2.add(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_PRICE), "amount-" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_PRICE)));
loreLines2.add(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_PRICE),
"amount-" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_PRICE)));
shopBlockHuntPass_IM.setLore(lores2);
shopBlockHuntPass_IM.setLore(loreLines2);
shopBlockHuntPass.setItemMeta(shopBlockHuntPass_IM);
shop.setItem(0, shopTokens);
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ENABLED)
&& (MemoryStorage.shop.getFile().get(player.getName() + ".blockchooser") == null && !PermissionsManager.hasPermission(player, Permission.SHOP_BLOCK_CHOOSER, false))) {
&& (MemoryStorage.shop.getFile().get(player.getName() + ".blockchooser") == null &&
!PermissionsManager.hasPermission(player, Permission.SHOP_BLOCK_CHOOSER, false))) {
shop.setItem(1, shopBlockChooser);
}
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ENABLED)) {

View File

@ -18,36 +18,127 @@ import java.util.Map;
@SerializableAs("BlockHuntArena")
public class Arena implements ConfigurationSerializable {
/**
* The name of this arena
*/
public final String arenaName;
public final Location corner1;
public final Location corner2;
/**
* The maximum amount of players that can join at once
*/
public int maxPlayers;
/**
* The minimum amount of players required for the arena to start
*/
public int minPlayers;
/**
* The amount of players made into seekers when this arena starts
*/
public int amountSeekersOnStart;
/**
* The amount of seconds players have to wait in the lobby before this arena starts
*/
public int timeInLobbyUntilStart;
/**
* The amount of time seekers have to wait before they can start seeking
*/
public int waitingTimeSeeker;
/**
* The amount of seconds the game will last before hiders automatically win
*/
public int gameTime;
/**
* The amount of seconds until hiders get swords to defend themselves
*/
public int timeUntilHidersSword;
/**
* The amount of seconds left of the game when remaining hidden blocks are announced
*/
public int blockAnnouncerTime;
/**
* Whether seekers can hurt other seekers
*/
public final boolean seekersCanHurtSeekers;
/**
* Whether hiders can hurt seekers
*/
public final boolean hidersCanHurtSeekers;
/**
* Whether hiders can hurt other hiders
*/
public final boolean hidersCanHurtHiders;
/**
* Whether seekers take fall damage
*/
public final boolean seekersTakeFallDamage;
/**
* Whether hiders take fall damage
*/
public final boolean hidersTakeFallDamage;
/**
* The blocks allowed for disguises
*/
public List<ItemStack> disguiseBlocks;
public Location lobbyWarp;
public Location hidersWarp;
public Location seekersWarp;
public Location spawnWarp;
/**
* The commands to be run on the seekers if the seekers win (%player%)
*/
public final List<String> seekersWinCommands;
/**
* The commands to be run on the hiders if the hiders win (%player%)
*/
public final List<String> hidersWinCommands;
/**
* The commands players are allowed to use while in this arena
* TODO: This seems to be missing a proper implementation
*/
public final List<String> allowedCommands;
/**
* The amount of tokens granted to each seeker if seekers win
*/
public int seekersTokenWin;
/**
* The amount of tokens granted to each hider if hiders win
*/
public int hidersTokenWin;
/**
* The amount of tokens granted for killing another player
*/
public int killTokens;
/**
* The players currently in this arena
*/
public final List<Player> playersInArena;
/**
* The current state of this arena
*/
public ArenaState gameState;
public ArenaLocations arenaLocations;
/**
* A timer that counts from the game duration towards 0
*/
public int timer;
public final List<Player> seekers;
public final Scoreboard scoreboard;
@ -62,8 +153,6 @@ public class Arena implements ConfigurationSerializable {
List<Player> playersInArena, ArenaState gameState, int timer, List<Player> seekers,
Scoreboard scoreboard) {
this.arenaName = arenaName;
this.corner1 = corner1;
this.corner2 = corner2;
this.maxPlayers = maxPlayers;
this.minPlayers = minPlayers;
this.amountSeekersOnStart = amountSeekersOnStart;
@ -78,10 +167,6 @@ public class Arena implements ConfigurationSerializable {
this.seekersTakeFallDamage = seekersTakeFallDamage;
this.hidersTakeFallDamage = hidersTakeFallDamage;
this.disguiseBlocks = disguiseBlocks;
this.lobbyWarp = lobbyWarp;
this.hidersWarp = hidersWarp;
this.seekersWarp = seekersWarp;
this.spawnWarp = spawnWarp;
this.seekersWinCommands = seekersWinCommands;
this.hidersWinCommands = hidersWinCommands;
this.allowedCommands = allowedCommands;
@ -93,14 +178,15 @@ public class Arena implements ConfigurationSerializable {
this.timer = timer;
this.seekers = seekers;
this.scoreboard = scoreboard;
this.arenaLocations = new ArenaLocations(corner1, corner2, lobbyWarp, hidersWarp, seekersWarp, spawnWarp);
}
@Override
public @NotNull Map<String, Object> serialize() {
Map<String, Object> map = new HashMap<>();
map.put("arenaName", arenaName);
map.put("pos1", corner1);
map.put("pos2", corner2);
map.put("pos1", arenaLocations.getCorner1());
map.put("pos2", arenaLocations.getCorner2());
map.put("maxPlayers", maxPlayers);
map.put("minPlayers", minPlayers);
map.put("amountSeekersOnStart", amountSeekersOnStart);
@ -115,10 +201,10 @@ public class Arena implements ConfigurationSerializable {
map.put("seekersTakeFallDamage", seekersTakeFallDamage);
map.put("hidersTakeFallDamage", hidersTakeFallDamage);
map.put("disguiseBlocks", disguiseBlocks);
map.put("lobbyWarp", lobbyWarp);
map.put("hidersWarp", hidersWarp);
map.put("seekersWarp", seekersWarp);
map.put("spawnWarp", spawnWarp);
map.put("lobbyWarp", arenaLocations.getLobbyWarp());
map.put("hidersWarp", arenaLocations.getHidersWarp());
map.put("seekersWarp", arenaLocations.getSeekersWarp());
map.put("spawnWarp", arenaLocations.getSpawnWarp());
map.put("seekersWinCommands", seekersWinCommands);
map.put("hidersWinCommands", hidersWinCommands);
map.put("allowedCommands", allowedCommands);

View File

@ -106,9 +106,11 @@ public class ArenaHandler {
}
Location zero = new Location(Bukkit.getWorld(player.getWorld().getName()), 0, 0, 0, 0, 0);
if (arena.lobbyWarp != null && arena.hidersWarp != null && arena.seekersWarp != null && arena.spawnWarp != null) {
if (!arena.lobbyWarp.equals(zero) && !arena.hidersWarp.equals(zero) &&
!arena.seekersWarp.equals(zero) && !arena.spawnWarp.equals(zero)) {
ArenaLocations locations = arena.arenaLocations;
if (locations.getLobbyWarp() != null && locations.getHidersWarp() != null &&
locations.getSeekersWarp() != null && locations.getSpawnWarp() != null) {
if (!locations.getLobbyWarp().equals(zero) && !locations.getHidersWarp().equals(zero) &&
!locations.getSeekersWarp().equals(zero) && !locations.getSpawnWarp().equals(zero)) {
if (arena.gameState == ArenaState.WAITING || arena.gameState == ArenaState.STARTING) {
if (arena.playersInArena.size() >= arena.maxPlayers &&
!PermissionsManager.hasPermission(player, Permission.JOIN_FULL, false)) {
@ -116,7 +118,7 @@ public class ArenaHandler {
return;
}
boolean canWarp = PlayerHandler.teleport(player, arena.lobbyWarp);
boolean canWarp = PlayerHandler.teleport(player, locations.getLobbyWarp());
if (!canWarp) {
MessageManager.sendFMessage(player, MessageKey.ERROR_TELEPORT_FAILED);
return;
@ -285,7 +287,7 @@ public class ArenaHandler {
}
seeker.getInventory().clear();
arena.seekers.add(seeker);
PlayerHandler.teleport(seeker, arena.seekersWarp);
PlayerHandler.teleport(seeker, arena.arenaLocations.getSeekersWarp());
MemoryStorage.seekerTime.put(seeker, arena.waitingTimeSeeker);
seeker.setWalkSpeed(0.3F);
@ -320,7 +322,7 @@ public class ArenaHandler {
player.setHealth(pad.playerHealth());
player.setFoodLevel(pad.playerFood());
player.addPotionEffects(pad.playerPotionEffects());
PlayerHandler.teleport(player, arena.spawnWarp);
PlayerHandler.teleport(player, arena.arenaLocations.getSpawnWarp());
player.setGameMode(pad.playerGameMode());
player.setAllowFlight(pad.playerFlying());
if (player.getAllowFlight()) {

View File

@ -0,0 +1,133 @@
package net.knarcraft.blockhunt.arena;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* The locations of an arena
*/
public class ArenaLocations {
private final @NotNull Location corner1;
private final @NotNull Location corner2;
private Location lobbyWarp;
private Location hidersWarp;
private Location seekersWarp;
private Location spawnWarp;
/**
* Instantiates a new arena locations container
*
* @param corner1 <p>First corner of this arena's region</p>
* @param corner2 <p>Second corner of this arena's region</p>
* @param lobbyWarp <p>The location of the lobby's warp</p>
* @param hidersWarp <p>The location of the hiders' warp</p>
* @param seekersWarp <p>The location of the temporary seekers warp (should not be able to see hiders from this location)</p>
* @param spawnWarp <p>The location of the spawn warp where players are sent once this arena's game ends</p>
*/
public ArenaLocations(@NotNull Location corner1, @NotNull Location corner2, @Nullable Location lobbyWarp,
@Nullable Location hidersWarp, @Nullable Location seekersWarp, @Nullable Location spawnWarp) {
this.corner1 = corner1;
this.corner2 = corner2;
this.lobbyWarp = lobbyWarp;
this.hidersWarp = hidersWarp;
this.seekersWarp = seekersWarp;
this.spawnWarp = spawnWarp;
}
/**
* Gets the first corner of this arena's region
*
* @return <p>The first corner of this arena's region</p>
*/
public @NotNull Location getCorner1() {
return corner1;
}
/**
* Gets the second corner of this arena's region
*
* @return <p>The second corner of this arena's region</p>
*/
public @NotNull Location getCorner2() {
return corner2;
}
/**
* Gets the location of the lobby's warp
*
* @return <p>The location of the lobby's warp</p>
*/
public @Nullable Location getLobbyWarp() {
return lobbyWarp;
}
/**
* Sets the location of the lobby's warp
*
* @param lobbyWarp <p>The new location of the lobby's warp</p>
*/
public void setLobbyWarp(@NotNull Location lobbyWarp) {
this.lobbyWarp = lobbyWarp;
}
/**
* Gets the location of the hiders' warp
*
* @return <p>The location of the hiders' warp</p>
*/
public @Nullable Location getHidersWarp() {
return hidersWarp;
}
/**
* Sets the location of the hiders' warp
*
* @param hidersWarp <p>The new location of the hiders' warp</p>
*/
public void setHidersWarp(@NotNull Location hidersWarp) {
this.hidersWarp = hidersWarp;
}
/**
* Gets the location of the seekers' initial warp
*
* <p>Seekers are teleported here while the hiders are given time to hide.</p>
*
* @return <p>The location of the seekers' initial warp</p>
*/
public @Nullable Location getSeekersWarp() {
return seekersWarp;
}
/**
* Sets the location of the seekers' initial warp
*
* @param seekersWarp <p>The new location of the seekers' initial warp</p>
*/
public void setSeekersWarp(@NotNull Location seekersWarp) {
this.seekersWarp = seekersWarp;
}
/**
* Gets the location of the "spawn" warp
*
* <p>This location is where players are teleported to when leaving the arena</p>
*
* @return <p>The location of the "spawn" warp</p>
*/
public @Nullable Location getSpawnWarp() {
return spawnWarp;
}
/**
* Sets the location of the "spawn" warp
*
* @param spawnWarp <p>The location of the "spawn" warp</p>
*/
public void setSpawnWarp(@NotNull Location spawnWarp) {
this.spawnWarp = spawnWarp;
}
}

View File

@ -1,17 +1,63 @@
package net.knarcraft.blockhunt.arena;
/**
* The arena properties that can be edited through a GUI
*/
public enum ArenaProperty {
/**
* The maximum amount of players that can play at once
*/
MAX_PLAYERS,
/**
* The minimum amount of players required for the arena to start
*/
MIN_PLAYERS,
/**
* The amount of players made into seekers when the arena starts
*/
AMOUNT_SEEKERS_ON_START,
/**
* The amount of seconds the players are kept in the lobby to allow more players to join
*/
TIME_IN_LOBBY_UNTIL_START,
/**
* The amount of seconds the hiders have to hide before the seekers start seeking
*/
WAITING_TIME_SEEKER,
/**
* The amount of time until the game ends, unless all hiders are killed
*/
GAME_TIME,
/**
* The amount of seconds until hiders are granted a sword to defend themselves with
*/
TIME_UNTIL_HIDERS_SWORD,
/**
* The amount of tokens given to each hider if they win
*/
HIDERS_TOKEN_WIN,
/**
* The amount of tokens given to each seeker if they win
*/
SEEKERS_TOKEN_WIN,
/**
* The amount of tokens given to a seeker when they kill a hider
*/
KILL_TOKENS,
/**
* The amount of seconds left on the arena timer when the types of hidden blocks are announced
*/
BLOCK_ANNOUNCER_TIME
}

View File

@ -1,11 +1,23 @@
package net.knarcraft.blockhunt.arena;
/**
* The current state of an arena
*/
public enum ArenaState {
/**
* The arena is waiting for enough players
*/
WAITING,
/**
* The arena is about to start, and is counting down while players are kept in the lobby
*/
STARTING,
/**
* The arena has an active game
*/
IN_GAME,
RESTARTING,
DISABLED
}

View File

@ -3,6 +3,7 @@ package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.arena.ArenaLocations;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
@ -19,29 +20,30 @@ public class SetWarpCommand extends DefaultCommand {
CommandManager.setWarpCommand().usage());
} else {
String arenaName = args[2];
String warpname = args[1];
String warpName = args[1];
Arena arena = MemoryStorage.arenaMap.get(arenaName.toLowerCase());
if (arena != null) {
Location loc = player.getLocation();
if (warpname.equalsIgnoreCase("lobby")) {
arena.lobbyWarp = loc;
ArenaLocations locations = arena.arenaLocations;
Location playerLocation = player.getLocation();
if (warpName.equalsIgnoreCase("lobby")) {
locations.setLobbyWarp(playerLocation);
save(arena);
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpname);
} else if (warpname.equalsIgnoreCase("hiders")) {
arena.hidersWarp = loc;
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
} else if (warpName.equalsIgnoreCase("hiders")) {
locations.setHidersWarp(playerLocation);
save(arena);
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpname);
} else if (warpname.equalsIgnoreCase("seekers")) {
arena.seekersWarp = loc;
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
} else if (warpName.equalsIgnoreCase("seekers")) {
locations.setSeekersWarp(playerLocation);
save(arena);
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpname);
} else if (warpname.equalsIgnoreCase("spawn")) {
arena.spawnWarp = loc;
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
} else if (warpName.equalsIgnoreCase("spawn")) {
locations.setSpawnWarp(playerLocation);
save(arena);
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpname);
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_SET_WARP_WARP_NOT_FOUND, "warp-" + warpname);
MessageManager.sendFMessage(player, MessageKey.ERROR_SET_WARP_WARP_NOT_FOUND, "warp-" + warpName);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + arenaName);
@ -58,5 +60,5 @@ public class SetWarpCommand extends DefaultCommand {
MemoryStorage.arenas.save();
ArenaHandler.loadArenas();
}
}

View File

@ -151,7 +151,7 @@ public class OnEntityDamageByEntityEvent implements Listener {
} else {
DisguiseAPI.undisguiseToAll(player);
MemoryStorage.seekerTime.put(player, arena.waitingTimeSeeker);
PlayerHandler.teleport(player, arena.seekersWarp);
PlayerHandler.teleport(player, arena.arenaLocations.getSeekersWarp());
player.setGameMode(GameMode.SURVIVAL);
player.setWalkSpeed(0.3F);

View File

@ -15,6 +15,7 @@ import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
public class OnInventoryCloseEvent implements Listener {
@ -28,7 +29,7 @@ public class OnInventoryCloseEvent implements Listener {
Arena arena = MemoryStorage.arenaMap.get(arenaName.toLowerCase());
ArrayList<ItemStack> blocks = new ArrayList<>();
List<ItemStack> blocks = new ArrayList<>();
for (ItemStack item : inv.getContents()) {
if (item != null) {
if (!item.getType().equals(Material.PAPER)) {

View File

@ -5,6 +5,7 @@ import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.PlayerHandler;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.arena.ArenaLocations;
import net.knarcraft.blockhunt.arena.ArenaState;
import org.bukkit.Effect;
import org.bukkit.Location;
@ -15,6 +16,8 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.function.BiFunction;
public class OnPlayerMoveEvent implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@ -25,63 +28,70 @@ public class OnPlayerMoveEvent implements Listener {
}
Player player = event.getPlayer();
for (Arena arena : MemoryStorage.arenaMap.values()) {
if (arena.playersInArena.contains(player)) {
if (arena.gameState == ArenaState.IN_GAME) {
MemoryStorage.moveLoc.put(player, player.getLocation());
if (arena.corner1 == null || arena.corner2 == null) {
BlockHunt.plugin.getLogger().info("Arena:" +
arena.arenaName + " appears to have bad coords : pos1:" +
((arena.corner1 != null) ? arena.corner1.toString() : " NULL") + " Pos2:" +
((arena.corner2 != null) ? arena.corner2.toString() : " NULL"));
BlockHunt.plugin.getLogger().info("Player has been returned to hiderswarp due to bad arena state");
//event.setCancelled(true);
Location loc = player.getLocation();
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
PlayerHandler.teleport(player, arena.hidersWarp);
return;
}
double maxX = Math.max(arena.corner1.getX(), arena.corner2.getX());
double minX = Math.min(arena.corner1.getX(), arena.corner2.getX());
double maxY = Math.max(arena.corner1.getY(), arena.corner2.getY());
double minY = Math.min(arena.corner1.getY(), arena.corner2.getY());
double maxZ = Math.max(arena.corner1.getZ(), arena.corner2.getZ());
double minZ = Math.min(arena.corner1.getZ(), arena.corner2.getZ());
Location loc = player.getLocation();
if (loc.getBlockX() > maxX) {
//event.setCancelled(true);
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
PlayerHandler.teleport(player, arena.hidersWarp);
} else if (loc.getBlockX() < minX) {
//event.setCancelled(true);
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
PlayerHandler.teleport(player, arena.hidersWarp);
} else if (loc.getBlockZ() > maxZ) {
//event.setCancelled(true);
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
PlayerHandler.teleport(player, arena.hidersWarp);
} else if (loc.getBlockZ() < minZ) {
//event.setCancelled(true);
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
PlayerHandler.teleport(player, arena.hidersWarp);
} else if (loc.getBlockY() > maxY) {
//event.setCancelled(true);
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
PlayerHandler.teleport(player, arena.hidersWarp);
} else if (loc.getBlockY() < minY) {
//event.setCancelled(true);
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
PlayerHandler.teleport(player, arena.hidersWarp);
}
}
//TODO: Optimize this to runtime O(1)
if (!arena.playersInArena.contains(player)) {
continue;
}
if (arena.gameState != ArenaState.IN_GAME) {
return;
}
ArenaLocations locations = arena.arenaLocations;
MemoryStorage.moveLoc.put(player, player.getLocation());
if (locations.getCorner1() == null || locations.getCorner2() == null) {
BlockHunt.plugin.getLogger().info("Arena:" +
arena.arenaName + " appears to have bad coords : pos1:" +
((locations.getCorner1() != null) ? locations.getCorner1().toString() : " NULL") + " Pos2:" +
((locations.getCorner2() != null) ? locations.getCorner2().toString() : " NULL"));
BlockHunt.plugin.getLogger().info("Player has been returned to hiderswarp due to bad arena state");
//event.setCancelled(true);
Location loc = player.getLocation();
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
PlayerHandler.teleport(player, locations.getHidersWarp());
return;
}
// Force the player back in bounds if they are about to leave the arena
Location maxLocation = getRelativeLocation(locations.getCorner1(), locations.getCorner2(), Math::max);
Location minLocation = getRelativeLocation(locations.getCorner1(), locations.getCorner2(), Math::min);
Location playerLocation = player.getLocation();
if (!areIntersecting(playerLocation, minLocation, maxLocation)) {
player.playEffect(playerLocation, Effect.ENDER_SIGNAL, null);
player.playSound(playerLocation, Sound.ENTITY_GHAST_SHOOT, 1, 1);
PlayerHandler.teleport(player, locations.getHidersWarp());
}
return;
}
}
/**
* Gets a location relative to the two given locations
*
* @param location1 <p>The first location</p>
* @param location2 <p>The second location</p>
* @param function <p>The function to apply on the two locations' X, Y, Z properties to get new X, Y, Z values</p>
* @return <p>A location relative to the two input locations</p>
*/
private Location getRelativeLocation(Location location1, Location location2,
BiFunction<Double, Double, Double> function) {
return new Location(location1.getWorld(), function.apply(location1.getX(), location2.getX()),
function.apply(location1.getY(), location2.getY()), function.apply(location1.getZ(), location2.getZ()));
}
/**
* Checks if the given location is intersecting with the hit-box defined by the given location pair
*
* @param point <p>The point to check for intersection</p>
* @param locationMin <p>The minimum corner of the hit-box to check against</p>
* @param locationMax <p>The maximum corner of the hit-box to check against</p>
* @return <p>True if the point is intersecting with the hit-box</p>
*/
private static boolean areIntersecting(Location point, Location locationMin, Location locationMax) {
return (point.getBlockX() >= locationMin.getBlockX() && point.getBlockX() <= locationMax.getBlockX()) &&
(point.getBlockY() >= locationMin.getBlockY() && point.getBlockY() <= locationMax.getBlockY()) &&
(point.getBlockZ() >= locationMin.getBlockZ() && point.getBlockZ() <= locationMax.getBlockZ());
}
}