Improves setup description

This commit is contained in:
2023-07-07 03:42:04 +02:00
parent 638094be33
commit b6eb6a26d1
6 changed files with 236 additions and 208 deletions

View File

@@ -19,8 +19,8 @@ import java.util.Map;
public class Arena implements ConfigurationSerializable {
public final String arenaName;
public final Location pos1;
public final Location pos2;
public final Location corner1;
public final Location corner2;
public int maxPlayers;
public int minPlayers;
public int amountSeekersOnStart;
@@ -52,7 +52,7 @@ public class Arena implements ConfigurationSerializable {
public final List<Player> seekers;
public final Scoreboard scoreboard;
public Arena(String arenaName, Location pos1, Location pos2, int maxPlayers, int minPlayers, int amountSeekersOnStart,
public Arena(String arenaName, Location corner1, Location corner2, int maxPlayers, int minPlayers, int amountSeekersOnStart,
int timeInLobbyUntilStart, int waitingTimeSeeker, int gameTime, int timeUntilHidersSword,
int blockAnnouncerTime, boolean seekersCanHurtSeekers, boolean hidersCanHurtSeekers,
boolean hidersCanHurtHiders, boolean seekersTakeFallDamage, boolean hidersTakeFallDamage,
@@ -62,8 +62,8 @@ public class Arena implements ConfigurationSerializable {
List<Player> playersInArena, ArenaState gameState, int timer, List<Player> seekers,
Scoreboard scoreboard) {
this.arenaName = arenaName;
this.pos1 = pos1;
this.pos2 = pos2;
this.corner1 = corner1;
this.corner2 = corner2;
this.maxPlayers = maxPlayers;
this.minPlayers = minPlayers;
this.amountSeekersOnStart = amountSeekersOnStart;
@@ -99,8 +99,8 @@ public class Arena implements ConfigurationSerializable {
public @NotNull Map<String, Object> serialize() {
Map<String, Object> map = new HashMap<>();
map.put("arenaName", arenaName);
map.put("pos1", pos1);
map.put("pos2", pos2);
map.put("pos1", corner1);
map.put("pos2", corner2);
map.put("maxPlayers", maxPlayers);
map.put("minPlayers", minPlayers);
map.put("amountSeekersOnStart", amountSeekersOnStart);

View File

@@ -73,164 +73,165 @@ public class ArenaHandler {
}
}
if (!alreadyJoined) {
for (Arena arena : MemoryStorage.arenaList) {
if (arena.arenaName.equalsIgnoreCase(arenaName)) {
found = true;
if (arena.disguiseBlocks.isEmpty()) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_NO_BLOCKS_SET);
} else {
boolean inventoryEmpty = true;
for (ItemStack inventoryItem : player.getInventory()) {
if (inventoryItem != null) {
if (inventoryItem.getType() != Material.AIR) {
inventoryEmpty = false;
}
}
}
if (alreadyJoined) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_ALREADY_JOINED);
return;
}
for (ItemStack inventoryItem : player.getInventory().getArmorContents()) {
if (inventoryItem != null) {
if (inventoryItem.getType() != Material.AIR) {
inventoryEmpty = false;
}
}
}
if ((Boolean) MemoryStorage.config.get(ConfigKey.REQUIRE_INVENTORY_CLEAR_ON_JOIN) && !inventoryEmpty) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_INVENTORY_NOT_EMPTY);
return;
}
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)) {
if (arena.gameState == ArenaState.WAITING || arena.gameState == ArenaState.STARTING) {
if (arena.playersInArena.size() >= arena.maxPlayers) {
if (!PermissionsManager.hasPermission(player, Permission.JOIN_FULL, false)) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_FULL);
return;
}
}
boolean canWarp = PlayerHandler.teleport(player, arena.lobbyWarp);
if (!canWarp) {
MessageManager.sendFMessage(player, MessageKey.ERROR_TELEPORT_FAILED);
return;
}
BlockHunt.plugin.getLogger().log(Level.INFO, player.getName() + " has joined " + arenaName);
arena.playersInArena.add(player);
JoinArenaEvent event = new JoinArenaEvent(player, arena);
Bukkit.getPluginManager().callEvent(event);
PlayerArenaData pad = new PlayerArenaData(player.getLocation(), player.getGameMode(), player.getInventory().getContents(), player
.getInventory().getArmorContents(), player.getExp(), player.getLevel(), player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(), player.getHealth(), player.getFoodLevel(),
player.getActivePotionEffects(), player.getAllowFlight());
MemoryStorage.pData.put(player, pad);
player.setGameMode(GameMode.SURVIVAL);
for (PotionEffect pe : player.getActivePotionEffects()) {
player.removePotionEffect(pe.getType());
}
player.setFoodLevel(20);
player.setHealth(20);
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(20);
player.setLevel(arena.timer);
player.setExp(0);
player.getInventory().clear();
player.getInventory().setHelmet(new ItemStack(Material.AIR));
player.getInventory().setChestplate(new ItemStack(Material.AIR));
player.getInventory().setLeggings(new ItemStack(Material.AIR));
player.getInventory().setBoots(new ItemStack(Material.AIR));
player.setFlying(false);
player.setAllowFlight(false);
player.setWalkSpeed(0.2F);
// Fix for client not showing players after
// they join
for (Player otherPlayer : arena.playersInArena) {
if (otherPlayer.canSee(player)) {
otherPlayer.showPlayer(BlockHunt.plugin, player); // Make
}
// new
// player
// visible
// to
// others
if (player.canSee(otherPlayer)) {
player.showPlayer(BlockHunt.plugin, otherPlayer); // Make
}
// other
// players
// visible
// to
// new
// player
}
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ENABLED)) {
if (MemoryStorage.shop.getFile().get(player.getName() + ".blockchooser") != null
|| PermissionsManager.hasPermission(player, Permission.SHOP_BLOCK_CHOOSER, false)) {
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)));
List<String> loreStrings = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_DESCRIPTION.getPath());
List<String> loreStrings2 = new ArrayList<>();
for (String lore : loreStrings) {
loreStrings2.add(MessageManager.replaceAll(lore));
}
shopBlockChooser_IM.setLore(loreStrings2);
shopBlockChooser.setItemMeta(shopBlockChooser_IM);
player.getInventory().addItem(shopBlockChooser);
}
}
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ENABLED)) {
if (MemoryStorage.shop.getFile().getInt(player.getName() + ".blockhuntpass") != 0) {
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)));
List<String> loreStrings = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_DESCRIPTION.getPath());
List<String> loreStrings2 = new ArrayList<>();
for (String lore : loreStrings) {
loreStrings2.add(MessageManager.replaceAll(lore));
}
shopBlockHuntPass_IM.setLore(loreStrings2);
shopBlockHuntPass.setItemMeta(shopBlockHuntPass_IM);
shopBlockHuntPass.setAmount(MemoryStorage.shop.getFile().getInt(player.getName() + ".blockhuntpass"));
player.getInventory().addItem(shopBlockHuntPass);
}
}
player.updateInventory();
DisguiseAPI.undisguiseToAll(player);
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_JOIN_JOINED_ARENA, "%playerName%-" + player.getName(),
"1-" + arena.playersInArena.size(), "2-" + arena.maxPlayers);
if (arena.playersInArena.size() < arena.minPlayers) {
sendFMessage(arena, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-" + arena.minPlayers);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_ARENA_IN_GAME);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_WARPS_NOT_SET);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_WARPS_NOT_SET);
for (Arena arena : MemoryStorage.arenaList) {
if (!arena.arenaName.equalsIgnoreCase(arenaName)) {
continue;
}
found = true;
if (arena.disguiseBlocks.isEmpty()) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_NO_BLOCKS_SET);
} else {
boolean inventoryEmpty = true;
for (ItemStack inventoryItem : player.getInventory()) {
if (inventoryItem != null) {
if (inventoryItem.getType() != Material.AIR) {
inventoryEmpty = false;
}
}
}
for (ItemStack inventoryItem : player.getInventory().getArmorContents()) {
if (inventoryItem != null) {
if (inventoryItem.getType() != Material.AIR) {
inventoryEmpty = false;
}
}
}
if ((Boolean) MemoryStorage.config.get(ConfigKey.REQUIRE_INVENTORY_CLEAR_ON_JOIN) && !inventoryEmpty) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_INVENTORY_NOT_EMPTY);
return;
}
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)) {
if (arena.gameState == ArenaState.WAITING || arena.gameState == ArenaState.STARTING) {
if (arena.playersInArena.size() >= arena.maxPlayers &&
!PermissionsManager.hasPermission(player, Permission.JOIN_FULL, false)) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_FULL);
return;
}
boolean canWarp = PlayerHandler.teleport(player, arena.lobbyWarp);
if (!canWarp) {
MessageManager.sendFMessage(player, MessageKey.ERROR_TELEPORT_FAILED);
return;
}
BlockHunt.plugin.getLogger().log(Level.INFO, player.getName() + " has joined " + arenaName);
arena.playersInArena.add(player);
JoinArenaEvent event = new JoinArenaEvent(player, arena);
Bukkit.getPluginManager().callEvent(event);
PlayerArenaData pad = new PlayerArenaData(player.getLocation(), player.getGameMode(), player.getInventory().getContents(), player
.getInventory().getArmorContents(), player.getExp(), player.getLevel(), player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(), player.getHealth(), player.getFoodLevel(),
player.getActivePotionEffects(), player.getAllowFlight());
MemoryStorage.pData.put(player, pad);
player.setGameMode(GameMode.SURVIVAL);
for (PotionEffect pe : player.getActivePotionEffects()) {
player.removePotionEffect(pe.getType());
}
player.setFoodLevel(20);
player.setHealth(20);
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(20);
player.setLevel(arena.timer);
player.setExp(0);
player.getInventory().clear();
player.getInventory().setHelmet(new ItemStack(Material.AIR));
player.getInventory().setChestplate(new ItemStack(Material.AIR));
player.getInventory().setLeggings(new ItemStack(Material.AIR));
player.getInventory().setBoots(new ItemStack(Material.AIR));
player.setFlying(false);
player.setAllowFlight(false);
player.setWalkSpeed(0.2F);
// Fix for client not showing players after
// they join
for (Player otherPlayer : arena.playersInArena) {
if (otherPlayer.canSee(player)) {
otherPlayer.showPlayer(BlockHunt.plugin, player); // Make
}
// new
// player
// visible
// to
// others
if (player.canSee(otherPlayer)) {
player.showPlayer(BlockHunt.plugin, otherPlayer); // Make
}
// other
// players
// visible
// to
// new
// player
}
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ENABLED)) {
if (MemoryStorage.shop.getFile().get(player.getName() + ".blockchooser") != null
|| PermissionsManager.hasPermission(player, Permission.SHOP_BLOCK_CHOOSER, false)) {
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)));
List<String> loreStrings = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_DESCRIPTION.getPath());
List<String> loreStrings2 = new ArrayList<>();
for (String lore : loreStrings) {
loreStrings2.add(MessageManager.replaceAll(lore));
}
shopBlockChooser_IM.setLore(loreStrings2);
shopBlockChooser.setItemMeta(shopBlockChooser_IM);
player.getInventory().addItem(shopBlockChooser);
}
}
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ENABLED)) {
if (MemoryStorage.shop.getFile().getInt(player.getName() + ".blockhuntpass") != 0) {
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)));
List<String> loreStrings = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_DESCRIPTION.getPath());
List<String> loreStrings2 = new ArrayList<>();
for (String lore : loreStrings) {
loreStrings2.add(MessageManager.replaceAll(lore));
}
shopBlockHuntPass_IM.setLore(loreStrings2);
shopBlockHuntPass.setItemMeta(shopBlockHuntPass_IM);
shopBlockHuntPass.setAmount(MemoryStorage.shop.getFile().getInt(player.getName() + ".blockhuntpass"));
player.getInventory().addItem(shopBlockHuntPass);
}
}
player.updateInventory();
DisguiseAPI.undisguiseToAll(player);
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_JOIN_JOINED_ARENA, "%playerName%-" + player.getName(),
"1-" + arena.playersInArena.size(), "2-" + arena.maxPlayers);
if (arena.playersInArena.size() < arena.minPlayers) {
sendFMessage(arena, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-" + arena.minPlayers);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_ARENA_IN_GAME);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_WARPS_NOT_SET);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_WARPS_NOT_SET);
}
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_ALREADY_JOINED);
return;
}
if (!found) {
@@ -258,9 +259,7 @@ public class ArenaHandler {
if (cleanup) {
arena.playersInArena.remove(player);
if (arena.seekers.contains(player)) {
arena.seekers.remove(player);
}
arena.seekers.remove(player);
if (arena.playersInArena.size() < arena.minPlayers && arena.gameState.equals(ArenaState.STARTING)) {
arena.gameState = ArenaState.WAITING;

View File

@@ -13,15 +13,11 @@ public class BlockHuntTabCompleter implements TabCompleter {
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command cmd, @NotNull String label,
String[] args) {
for (Command command : MemoryStorage.commands) {
if (cmd.getName().equalsIgnoreCase(command.label())) {
if (args.length == 1) {
return command.mainTabList();
}
if (cmd.getName().equalsIgnoreCase(command.label()) && args.length == 1) {
return command.mainTabList();
}
}
return null;
}

View File

@@ -10,7 +10,6 @@ import org.bukkit.entity.Player;
public class HelpCommand extends DefaultCommand {
@Override
public boolean execute(Player player, String[] args) {
int amountCommands = 0;

View File

@@ -28,11 +28,11 @@ public class OnPlayerMoveEvent implements Listener {
if (arena.playersInArena.contains(player)) {
if (arena.gameState == ArenaState.IN_GAME) {
MemoryStorage.moveLoc.put(player, player.getLocation());
if (arena.pos1 == null || arena.pos2 == null) {
if (arena.corner1 == null || arena.corner2 == null) {
BlockHunt.plugin.getLogger().info("Arena:" +
arena.arenaName + " appears to have bad coords : pos1:" +
((arena.pos1 != null) ? arena.pos1.toString() : " NULL") + " Pos2:" +
((arena.pos2 != null) ? arena.pos2.toString() : " NULL"));
((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();
@@ -41,12 +41,12 @@ public class OnPlayerMoveEvent implements Listener {
PlayerHandler.teleport(player, arena.hidersWarp);
return;
}
double maxX = Math.max(arena.pos1.getX(), arena.pos2.getX());
double minX = Math.min(arena.pos1.getX(), arena.pos2.getX());
double maxY = Math.max(arena.pos1.getY(), arena.pos2.getY());
double minY = Math.min(arena.pos1.getY(), arena.pos2.getY());
double maxZ = Math.max(arena.pos1.getZ(), arena.pos2.getZ());
double minZ = Math.min(arena.pos1.getZ(), arena.pos2.getZ());
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) {