diff --git a/src/main/java/com/nexia/core/utilities/time/ServerTime.java b/src/main/java/com/nexia/core/utilities/time/ServerTime.java index 1739b031..e259814d 100644 --- a/src/main/java/com/nexia/core/utilities/time/ServerTime.java +++ b/src/main/java/com/nexia/core/utilities/time/ServerTime.java @@ -19,6 +19,7 @@ import com.nexia.minigames.games.bedwars.areas.BwAreas; import com.nexia.minigames.games.bedwars.areas.BwDimension; import com.nexia.minigames.games.bedwars.shop.BwLoadShop; +import com.nexia.minigames.games.bridge.BridgeGame; import com.nexia.minigames.games.duels.DuelGameHandler; import com.nexia.minigames.games.duels.DuelsGame; import com.nexia.minigames.games.duels.team.TeamDuelsGame; @@ -73,6 +74,7 @@ public static void firstTick(MinecraftServer server) { BwDimension.register(); BwGame.firstTick(); FootballGame.firstTick(); + BridgeGame.firstTick(); WorldUtil.deleteTempWorlds(); SkywarsGame.firstTick(); @@ -82,7 +84,7 @@ public static void firstTick(MinecraftServer server) { public static void stopServer() { try { - for(Player player : ServerTime.nexusServer.getPlayers()){ + for (Player player : ServerTime.nexusServer.getPlayers()) { player.disconnect(ChatFormat.nexiaMessage.append(Component.text("The server is restarting!", ChatFormat.Minecraft.white))); } @@ -102,6 +104,7 @@ public static void everyTick() { BwGame.tick(); SkyFfaBlocks.tick(); FootballGame.tick(); + BridgeGame.tick(); OitcGame.tick(); if (totalTickCount % 5 == 0) { @@ -115,8 +118,10 @@ public static void everyTick() { // Most second methods are also handled here to avoid too many methods from being executed at the same time switch (totalTickCount % 20) { case 0 -> everySecond(); - case 2 -> {} - case 4 -> {} + case 2 -> { + } + case 4 -> { + } case 6 -> BwGame.bedWarsSecond(); } } @@ -125,23 +130,26 @@ static void everySecond() { totalSecondCount++; OitcGame.second(); FootballGame.second(); + BridgeGame.second(); SkywarsGame.second(); try { for (DuelsGame game : DuelGameHandler.duelsGames) { if (game == null) return; game.duelSecond(); } - } catch (Exception ignored) { } + } catch (Exception ignored) { + } try { for (TeamDuelsGame game : DuelGameHandler.teamDuelsGames) { if (game == null) return; game.duelSecond(); } - } catch (Exception ignored) { } + } catch (Exception ignored) { + } - if(totalSecondCount % 3600 == 0 && !UhcFfaAreas.shouldResetMap) { + if (totalSecondCount % 3600 == 0 && !UhcFfaAreas.shouldResetMap) { UhcFfaAreas.shouldResetMap = true; } } diff --git a/src/main/java/com/nexia/minigames/games/bridge/BridgeGame.java b/src/main/java/com/nexia/minigames/games/bridge/BridgeGame.java index ef2c6a3f..c642572f 100644 --- a/src/main/java/com/nexia/minigames/games/bridge/BridgeGame.java +++ b/src/main/java/com/nexia/minigames/games/bridge/BridgeGame.java @@ -12,32 +12,23 @@ import com.nexia.core.utilities.time.ServerTime; import com.nexia.core.utilities.time.TickUtil; import com.nexia.core.utilities.world.WorldUtil; -import com.nexia.minigames.games.bridge.BridgeMap; -import com.nexia.nexus.api.event.player.PlayerDeathEvent; -import com.nexia.minigames.games.duels.DuelGameHandler; import com.nexia.minigames.games.bridge.util.player.BridgePlayerData; +import com.nexia.minigames.games.duels.DuelGameHandler; +import com.nexia.nexus.api.event.player.PlayerDeathEvent; import com.nexia.nexus.api.world.types.Minecraft; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.title.Title; import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.decoration.ArmorStand; -import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.DyeableLeatherItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.phys.AABB; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -49,33 +40,20 @@ import static com.nexia.core.NexiaCore.BRIDGE_DATA_MANAGER; public class BridgeGame { + public static final String BRIDGE_TAG = "bridge"; public static ArrayList players = new ArrayList<>(); - public static ArrayList spectator = new ArrayList<>(); - public static ServerLevel world = null; - public static BridgeMap map = BridgeMap.STADIUM; - public static BridgeTeam team1 = new BridgeTeam(new ArrayList<>(), map.team1Pos); public static BridgeTeam team2 = new BridgeTeam(new ArrayList<>(), map.team2Pos); - - // Both timers counted in seconds. public static int gameTime = 600; - public static int queueTime = 15; - public static ArrayList queue = new ArrayList<>(); - public static boolean isStarted = false; - public static boolean isEnding = false; - private static BridgeTeam winnerTeam = null; - - public static final String BRIDGE_TAG = "bridge"; - private static int endTime = 5; @@ -85,25 +63,26 @@ public static void leave(NexiaPlayer player) { BridgeGame.queue.remove(player); BridgeGame.players.remove(player); - if(data.gameMode.equals(BridgeGameMode.PLAYING) && (winnerTeam == null || !winnerTeam.players.contains(player))) data.savedData.incrementInteger("losses"); + if (data.gameMode.equals(BridgeGameMode.PLAYING) && (winnerTeam == null || !winnerTeam.players.contains(player))) + data.savedData.incrementInteger("losses"); data.team = null; player.removeTag("in_bridge_game"); player.reset(true, Minecraft.GameMode.ADVENTURE); - if(!BridgeGame.team1.refreshTeam()) BridgeGame.endGame(BridgeGame.team2); - if(!BridgeGame.team2.refreshTeam()) BridgeGame.endGame(BridgeGame.team1); + if (!BridgeGame.team1.refreshTeam()) BridgeGame.endGame(BridgeGame.team2); + if (!BridgeGame.team2.refreshTeam()) BridgeGame.endGame(BridgeGame.team1); player.removeTag("bridge"); data.gameMode = BridgeGameMode.LOBBY; } - public static void death(NexiaPlayer victim, @Nullable PlayerDeathEvent playerDeathEvent){ + public static void death(NexiaPlayer victim, @Nullable PlayerDeathEvent playerDeathEvent) { BridgePlayerData victimData = (BridgePlayerData) PlayerDataManager.getDataManager(BRIDGE_DATA_MANAGER).get(victim); - if(playerDeathEvent != null) { + if (playerDeathEvent != null) { playerDeathEvent.setDropEquipment(false); playerDeathEvent.setDropExperience(false); playerDeathEvent.setDropLoot(false); @@ -145,12 +124,12 @@ public static void giveKit(NexiaPlayer player) { ItemStack blocks = new ItemStack(Items.CLAY); - if(BridgeGame.team1.players.contains(player)) { + if (BridgeGame.team1.players.contains(player)) { // r * 65536 + g * 256 + b colour = 255 * 65536; blocks = new ItemStack(Items.BLUE_TERRACOTTA); - } else if(BridgeGame.team1.players.contains(player)) { + } else if (BridgeGame.team1.players.contains(player)) { colour = 255; blocks = new ItemStack(Items.RED_TERRACOTTA); } @@ -186,18 +165,18 @@ public static void giveKit(NexiaPlayer player) { } public static void second() { - if(BridgeGame.isStarted) { - if(BridgeGame.isEnding) { + if (BridgeGame.isStarted) { + if (BridgeGame.isEnding) { int color = 244 * 65536 + 166 * 256 + 71; // r * 65536 + g * 256 + b; - if(winnerTeam != null) { + if (winnerTeam != null) { NexiaPlayer randomPlayer = winnerTeam.players.get(RandomUtil.randomInt(winnerTeam.players.size())); - if(randomPlayer != null) DuelGameHandler.winnerRockets(randomPlayer, BridgeGame.world, color); + if (randomPlayer != null) DuelGameHandler.winnerRockets(randomPlayer, BridgeGame.world, color); } - if(BridgeGame.endTime <= 0) { - for(NexiaPlayer player : BridgeGame.getViewers()){ + if (BridgeGame.endTime <= 0) { + for (NexiaPlayer player : BridgeGame.getViewers()) { player.runCommand("/hub", 0, false); } @@ -208,27 +187,27 @@ public static void second() { } else { BridgeGame.updateInfo(); - if(BridgeGame.gameTime <= 0 && !BridgeGame.isEnding){ + if (BridgeGame.gameTime <= 0 && !BridgeGame.isEnding) { int team1 = BridgeGame.team1.goals; int team2 = BridgeGame.team2.goals; - if(team1 == team2) endGame(null); - if(team1 > team2) endGame(BridgeGame.team1); + if (team1 == team2) endGame(null); + if (team1 > team2) endGame(BridgeGame.team1); else endGame(BridgeGame.team2); - } else if(BridgeGame.gameTime > 0 && !BridgeGame.isEnding){ + } else if (BridgeGame.gameTime > 0 && !BridgeGame.isEnding) { BridgeGame.gameTime--; } } } else { - if(BridgeGame.queue.size() >= 2) { - for(NexiaPlayer player : BridgeGame.queue){ - if(player == null || player.unwrap() == null) return; + if (BridgeGame.queue.size() >= 2) { + for (NexiaPlayer player : BridgeGame.queue) { + if (player == null || player.unwrap() == null) return; - if(BridgeGame.queueTime <= 5) { + if (BridgeGame.queueTime <= 5) { Title title = getTitle(BridgeGame.queueTime); player.sendTitle(title); @@ -244,7 +223,7 @@ public static void second() { .append(Component.text(BridgeGame.queueTime, ChatFormat.brandColor2)) ); - if(BridgeGame.queueTime <= 5 || BridgeGame.queueTime == 10 || BridgeGame.queueTime == 15) { + if (BridgeGame.queueTime <= 5 || BridgeGame.queueTime == 10 || BridgeGame.queueTime == 15) { player.sendMessage(Component.text("The game will start in ").color(TextColor.fromHexString("#b3b3b3")) .append(Component.text(BridgeGame.queueTime, ChatFormat.brandColor1)) .append(Component.text(" seconds.").color(TextColor.fromHexString("#b3b3b3"))) @@ -256,30 +235,30 @@ public static void second() { } else { BridgeGame.queueTime = 15; } - if(BridgeGame.queueTime <= 0) startGame(); + if (BridgeGame.queueTime <= 0) startGame(); } } public static void goal(NexiaPlayer player) { - if(!team1.refreshTeam() || !team2.refreshTeam()) endGame(null); + if (!team1.refreshTeam() || !team2.refreshTeam()) endGame(null); var teamID = '0'; - if(!BridgeGame.isEnding) { + if (!BridgeGame.isEnding) { var i = 0; - for (i=0; player == team1.players.get(i); i++) { + for (i = 0; player == team1.players.get(i); i++) { PlayerDataManager.getDataManager(BRIDGE_DATA_MANAGER).get(player.getUUID()).savedData.incrementInteger("goals"); team1.goals++; teamID = '1'; } - for (i=0; player == team2.players.get(i); i++) { + for (i = 0; player == team2.players.get(i); i++) { PlayerDataManager.getDataManager(BRIDGE_DATA_MANAGER).get(player.getUUID()).savedData.incrementInteger("goals"); team1.goals++; teamID = '2'; @@ -298,8 +277,8 @@ public static void goal(NexiaPlayer player) { // } - if(team1.goals >= BridgeGame.map.maxGoals) BridgeGame.endGame(team1); - if(team2.goals >= BridgeGame.map.maxGoals) BridgeGame.endGame(team2); + if (team1.goals >= BridgeGame.map.maxGoals) BridgeGame.endGame(team1); + if (team2.goals >= BridgeGame.map.maxGoals) BridgeGame.endGame(team2); } @@ -309,25 +288,24 @@ public static void goal(NexiaPlayer player) { //PlayerDataManager.getDataManager(NexiaCore.FOOTBALL_DATA_MANAGER).get(scorer.get()).savedData.goals++; - if(!BridgeGame.isEnding) { + if (!BridgeGame.isEnding) { // entity.setDeltaMovement(0, 0, 0); // entity.moveTo(0, 80, 0, 0, 0); - for(NexiaPlayer viewer : BridgeGame.getViewers()) { + for (NexiaPlayer viewer : BridgeGame.getViewers()) { viewer.sendTitle(Title.title(Component.text("Team " + teamID, ChatFormat.brandColor2), Component.text("has scored a goal!", ChatFormat.normalColor))); } - for(NexiaPlayer playerT1 : BridgeGame.team1.players) { + for (NexiaPlayer playerT1 : BridgeGame.team1.players) { BridgeGame.team1.spawnPosition.teleportPlayer(BridgeGame.world, playerT1.unwrap()); } - for(NexiaPlayer playerT2 : BridgeGame.team2.players) { + for (NexiaPlayer playerT2 : BridgeGame.team2.players) { BridgeGame.team2.spawnPosition.teleportPlayer(BridgeGame.world, playerT2.unwrap()); } } - } @NotNull @@ -347,9 +325,9 @@ public static void joinQueue(NexiaPlayer player) { BridgePlayerData data = (BridgePlayerData) PlayerDataManager.getDataManager(BRIDGE_DATA_MANAGER).get(player); data.team = null; - if(BridgeGame.isStarted){ + if (BridgeGame.isStarted) { BridgeGame.spectator.add(player); - ((BridgePlayerData)PlayerDataManager.getDataManager(BRIDGE_DATA_MANAGER).get(player)).gameMode = BridgeGameMode.SPECTATOR; + ((BridgePlayerData) PlayerDataManager.getDataManager(BRIDGE_DATA_MANAGER).get(player)).gameMode = BridgeGameMode.SPECTATOR; player.setGameMode(Minecraft.GameMode.SPECTATOR); } else { BridgeGame.queue.add(player); @@ -363,14 +341,14 @@ public static void joinQueue(NexiaPlayer player) { public static void endGame(BridgeTeam winnerTeam) { BridgeGame.isEnding = true; - if(winnerTeam == null) { + if (winnerTeam == null) { Component msg = Component.text("The game was a ") .color(ChatFormat.normalColor) .append(Component.text("draw", ChatFormat.brandColor2)) .append(Component.text("!", ChatFormat.normalColor) ); - for(NexiaPlayer player : BridgeGame.getViewers()){ - if(player != null && player.unwrap() != null) player.sendTitle(Title.title(msg, Component.text(""))); + for (NexiaPlayer player : BridgeGame.getViewers()) { + if (player != null && player.unwrap() != null) player.sendTitle(Title.title(msg, Component.text(""))); } return; @@ -379,14 +357,14 @@ public static void endGame(BridgeTeam winnerTeam) { BridgeGame.winnerTeam = winnerTeam; int teamID = 1; - if(winnerTeam == BridgeGame.team2) teamID = 2; + if (winnerTeam == BridgeGame.team2) teamID = 2; - for(NexiaPlayer player : winnerTeam.players) { + for (NexiaPlayer player : winnerTeam.players) { player.sendTitle(Title.title(Component.text("You won!").color(ChatFormat.greenColor), Component.text(""))); PlayerDataManager.getDataManager(BRIDGE_DATA_MANAGER).get(player).savedData.incrementInteger("wins"); } - for(NexiaPlayer player : BridgeGame.getViewers()){ + for (NexiaPlayer player : BridgeGame.getViewers()) { player.sendTitle(Title.title(Component.text("Team " + teamID, ChatFormat.brandColor2), Component.text("has won the game! (" + winnerTeam.goals + " goals)", ChatFormat.normalColor))); } } @@ -394,12 +372,12 @@ public static void endGame(BridgeTeam winnerTeam) { public static void updateInfo() { String[] timer = TickUtil.minuteTimeStamp(BridgeGame.gameTime * 20); - for(NexiaPlayer player : BridgeGame.getViewers()) { - if(player == null) return; - BridgeTeam playerTeam = ((BridgePlayerData)PlayerDataManager.getDataManager(BRIDGE_DATA_MANAGER).get(player)).team; - if(playerTeam == null) playerTeam = BridgeGame.team1; // maybe cuz spectator + for (NexiaPlayer player : BridgeGame.getViewers()) { + if (player == null) return; + BridgeTeam playerTeam = ((BridgePlayerData) PlayerDataManager.getDataManager(BRIDGE_DATA_MANAGER).get(player)).team; + if (playerTeam == null) playerTeam = BridgeGame.team1; // maybe cuz spectator BridgeTeam otherTeam = BridgeGame.team1; - if(playerTeam.equals(BridgeGame.team1)) otherTeam = BridgeGame.team2; + if (playerTeam.equals(BridgeGame.team1)) otherTeam = BridgeGame.team2; player.sendActionBarMessage( Component.text("Map ยป ").color(TextColor.fromHexString("#b3b3b3")) @@ -465,15 +443,15 @@ private static BridgeTeam assignPlayer(NexiaPlayer player) { int team1 = BridgeGame.team1.players.size(); int team2 = BridgeGame.team2.players.size(); - if(team1 >= players/2) { + if (team1 >= players / 2) { BridgeGame.team2.addPlayer(player); return BridgeGame.team2; - } else if (team2 >= players/2) { + } else if (team2 >= players / 2) { BridgeGame.team1.addPlayer(player); return BridgeGame.team1; } - if(random == 1) { + if (random == 1) { BridgeGame.team1.addPlayer(player); return BridgeGame.team1; } else if (random == 2) { @@ -485,7 +463,7 @@ private static BridgeTeam assignPlayer(NexiaPlayer player) { } public static void startGame() { - if(BridgeGame.queueTime <= 0){ + if (BridgeGame.queueTime <= 0) { BridgeGame.isStarted = true; BridgeGame.gameTime = 600; BridgeGame.players.addAll(BridgeGame.queue); @@ -499,8 +477,7 @@ public static void startGame() { // kicking.hideTooltipPart(ItemStack.TooltipPart.UNBREAKABLE); - - for(NexiaPlayer player : BridgeGame.players) { + for (NexiaPlayer player : BridgeGame.players) { BridgePlayerData data = (BridgePlayerData) PlayerDataManager.getDataManager(BRIDGE_DATA_MANAGER).get(player); @@ -511,7 +488,7 @@ public static void startGame() { // player.unwrap().addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 99999, 255, false, false, false)); data.team = BridgeGame.assignPlayer(player); - while(data.team == null) { + while (data.team == null) { data.team = BridgeGame.assignPlayer(player); // if you're still null then im going to beat the shit out of you } @@ -571,8 +548,8 @@ public static void startGame() { } } - public static boolean isBridgePlayer(NexiaPlayer player){ - return ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode == PlayerGameMode.BRIDGE || player.hasTag("bridge") || player.hasTag("in_bridge_game"); + public static boolean isBridgePlayer(NexiaPlayer player) { + return ((CorePlayerData) PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode == PlayerGameMode.BRIDGE || player.hasTag("bridge") || player.hasTag("in_bridge_game"); } public static void resetAll() { @@ -580,7 +557,7 @@ public static void resetAll() { players.clear(); spectator.clear(); - map = BridgeMap. bridgeMaps.get(RandomUtil.randomInt(BridgeMap.bridgeMaps.size())); + map = BridgeMap.bridgeMaps.get(RandomUtil.randomInt(BridgeMap.bridgeMaps.size())); world = ServerTime.fantasy.getOrOpenPersistentWorld(new ResourceLocation("bridge", BridgeGame.map.id), WorldUtil.defaultWorldConfig).asWorld(); isStarted = false; @@ -594,8 +571,8 @@ public static void resetAll() { } public static void tick() { - if(BridgeGame.world == null) return; - if(BridgeGame.world.players().isEmpty()) return; + if (BridgeGame.world == null) return; + if (BridgeGame.world.players().isEmpty()) return; AABB aabb = new AABB(BridgeGame.map.corner1, BridgeGame.map.corner2); Predicate predicate = o -> true; @@ -640,7 +617,7 @@ public static void tick() { } - public static void firstTick(){ + public static void firstTick() { resetAll(); } diff --git a/src/main/java/com/nexia/minigames/games/bridge/BridgeMap.java b/src/main/java/com/nexia/minigames/games/bridge/BridgeMap.java index a0b27962..609b2f2a 100644 --- a/src/main/java/com/nexia/minigames/games/bridge/BridgeMap.java +++ b/src/main/java/com/nexia/minigames/games/bridge/BridgeMap.java @@ -22,7 +22,6 @@ public class BridgeMap { public EntityPos team1Pos; public EntityPos team2Pos; - public BridgeMap(String id, String name, int maxGoals, BlockPos corner1, BlockPos corner2, EntityPos team1Pos, EntityPos team2Pos, BlockPos team1goalCorner1, BlockPos team1goalCorner2, BlockPos team2goalCorner1, BlockPos team2goalCorner2) { this.id = id; this.name = name; @@ -49,4 +48,6 @@ public static BridgeMap identifyMap(String name) { } return null; } + + } \ No newline at end of file