From 9df69c6a9b492e8ae2654dcf46614dbd3f5d6879 Mon Sep 17 00:00:00 2001 From: NotCoded <66999075+not-coded@users.noreply.github.com> Date: Sat, 14 Dec 2024 14:48:19 +0100 Subject: [PATCH] theres still 1 million bugs but atleast it works --- .../player/duels/custom/KitEditorCommand.java | 4 +- .../com/nexia/minigames/NexiaMinigames.java | 2 + .../games/duels/DuelGameHandler.java | 11 ++++ .../custom/team/CustomTeamDuelsGame.java | 20 ++++--- .../games/duels/team/TeamDuelsGame.java | 57 +++++++------------ 5 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/nexia/core/commands/player/duels/custom/KitEditorCommand.java b/src/main/java/com/nexia/core/commands/player/duels/custom/KitEditorCommand.java index 62a820bb..f68125c0 100644 --- a/src/main/java/com/nexia/core/commands/player/duels/custom/KitEditorCommand.java +++ b/src/main/java/com/nexia/core/commands/player/duels/custom/KitEditorCommand.java @@ -90,7 +90,9 @@ private static int run(CommandContext context, @NotNull Strin File playerDir = playerPath.toFile(); try { if(!playerDir.exists()) Files.createDirectory(playerPath); - } catch (IOException ignored) { } + } catch (IOException e) { + if(NexiaCore.config.debugMode) NexiaCore.logger.info("[DEBUG]: Failed to create custom duels inventory path for {}!\nPath: {}\n{}", player, playerPath.toString(), e.getMessage()); + } KitRoom kitRoom = playerData.kitRoom; diff --git a/src/main/java/com/nexia/minigames/NexiaMinigames.java b/src/main/java/com/nexia/minigames/NexiaMinigames.java index cb80ef2f..d6c288bc 100644 --- a/src/main/java/com/nexia/minigames/NexiaMinigames.java +++ b/src/main/java/com/nexia/minigames/NexiaMinigames.java @@ -1,9 +1,11 @@ package com.nexia.minigames; +import com.nexia.minigames.games.duels.DuelGameHandler; import net.fabricmc.api.ModInitializer; public class NexiaMinigames implements ModInitializer { @Override public void onInitialize() { + DuelGameHandler.createDirectories(); } } diff --git a/src/main/java/com/nexia/minigames/games/duels/DuelGameHandler.java b/src/main/java/com/nexia/minigames/games/duels/DuelGameHandler.java index a8d3ee92..096ae626 100644 --- a/src/main/java/com/nexia/minigames/games/duels/DuelGameHandler.java +++ b/src/main/java/com/nexia/minigames/games/duels/DuelGameHandler.java @@ -31,6 +31,7 @@ import xyz.nucleoid.fantasy.RuntimeWorldConfig; import java.io.File; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.time.Duration; @@ -46,6 +47,16 @@ public class DuelGameHandler { public static List duelsGames = new ArrayList<>(); public static List teamDuelsGames = new ArrayList<>(); + public static void createDirectories() { + + Path customDuelsInventoriesPath = Path.of(InventoryUtil.dirpath + File.separator + "duels" + File.separator + "custom"); + try { + if(!customDuelsInventoriesPath.toFile().exists()) Files.createDirectory(customDuelsInventoriesPath); + } catch (IOException e) { + if(NexiaCore.config.debugMode) NexiaCore.logger.info("[DEBUG]: Failed to create custom duels inventory path!\nPath: {}\n{}", customDuelsInventoriesPath.toString(), e.getMessage()); + } + } + public static boolean validCustomKit(NexiaPlayer player, String kitID) { if(kitID.trim().isEmpty()) return false; diff --git a/src/main/java/com/nexia/minigames/games/duels/custom/team/CustomTeamDuelsGame.java b/src/main/java/com/nexia/minigames/games/duels/custom/team/CustomTeamDuelsGame.java index cd356f92..13e8f5d5 100644 --- a/src/main/java/com/nexia/minigames/games/duels/custom/team/CustomTeamDuelsGame.java +++ b/src/main/java/com/nexia/minigames/games/duels/custom/team/CustomTeamDuelsGame.java @@ -20,10 +20,8 @@ import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; - import java.io.File; import java.util.UUID; - import static com.nexia.minigames.games.duels.gamemodes.GamemodeHandler.removeQueue; public class CustomTeamDuelsGame extends TeamDuelsGame { @@ -46,10 +44,10 @@ public static CustomTeamDuelsGame startGame(@NotNull DuelsTeam team1, @NotNull D NexiaCore.logger.error(String.format("[Nexia]: Invalid per-custom (team 2) duel kit (%s) selected!", team1LeaderData.inviteOptions.inviteKit2)); else perCustomKitID = team1LeaderData.inviteOptions.inviteKit2; - team1.alive.clear(); - team1.alive.addAll(team1.all); + team1.refreshTeam(); + team2.refreshTeam(); - team2.alive.clear(); + team1.alive.addAll(team1.all); team2.alive.addAll(team2.all); UUID gameUUID = UUID.randomUUID(); @@ -71,6 +69,8 @@ public static CustomTeamDuelsGame startGame(@NotNull DuelsTeam team1, @NotNull D DuelGameHandler.teamDuelsGames.add(game); for (NexiaPlayer player : team1.all) { + player = player.refreshPlayer(); + ServerPlayer serverPlayer = player.unwrap(); DuelsPlayerData data = (DuelsPlayerData) PlayerDataManager.getDataManager(NexiaCore.DUELS_DATA_MANAGER).get(player); @@ -84,6 +84,8 @@ public static CustomTeamDuelsGame startGame(@NotNull DuelsTeam team1, @NotNull D selectedMap.p1Pos.teleportPlayer(duelLevel, serverPlayer); + player.reset(true, Minecraft.GameMode.ADVENTURE); + player.sendNexiaMessage( Component.text("Your opponent: ", ChatFormat.normalColor) .append(Component.text(team2.getLeader().getRawName() + "'s Team", ChatFormat.brandColor2)) @@ -94,11 +96,11 @@ public static CustomTeamDuelsGame startGame(@NotNull DuelsTeam team1, @NotNull D player.removeTag(LobbyUtil.NO_DAMAGE_TAG); player.removeTag(LobbyUtil.NO_FALL_DAMAGE_TAG); - - player.reset(true, Minecraft.GameMode.ADVENTURE); } for (NexiaPlayer player : team2.all) { + player = player.refreshPlayer(); + ServerPlayer serverPlayer = player.unwrap(); DuelsPlayerData data = (DuelsPlayerData) PlayerDataManager.getDataManager(NexiaCore.DUELS_DATA_MANAGER).get(player); @@ -112,6 +114,8 @@ public static CustomTeamDuelsGame startGame(@NotNull DuelsTeam team1, @NotNull D selectedMap.p2Pos.teleportPlayer(duelLevel, serverPlayer); + player.reset(true, Minecraft.GameMode.ADVENTURE); + player.sendNexiaMessage( Component.text("Your opponent: ", ChatFormat.normalColor) .append(Component.text(team1.getLeader().getRawName() + "'s Team", ChatFormat.brandColor2)) @@ -127,8 +131,6 @@ public static CustomTeamDuelsGame startGame(@NotNull DuelsTeam team1, @NotNull D player.removeTag(LobbyUtil.NO_DAMAGE_TAG); player.removeTag(LobbyUtil.NO_FALL_DAMAGE_TAG); - - player.reset(true, Minecraft.GameMode.ADVENTURE); } game.uuid = gameUUID; diff --git a/src/main/java/com/nexia/minigames/games/duels/team/TeamDuelsGame.java b/src/main/java/com/nexia/minigames/games/duels/team/TeamDuelsGame.java index 1984d04f..6dd27ecb 100644 --- a/src/main/java/com/nexia/minigames/games/duels/team/TeamDuelsGame.java +++ b/src/main/java/com/nexia/minigames/games/duels/team/TeamDuelsGame.java @@ -1,11 +1,11 @@ package com.nexia.minigames.games.duels.team; +import com.nexia.base.player.NexiaPlayer; import com.nexia.base.player.PlayerDataManager; import com.nexia.core.NexiaCore; import com.nexia.core.games.util.LobbyUtil; import com.nexia.core.utilities.chat.ChatFormat; import com.nexia.core.utilities.misc.RandomUtil; -import com.nexia.base.player.NexiaPlayer; import com.nexia.core.utilities.player.PlayerUtil; import com.nexia.core.utilities.pos.EntityPos; import com.nexia.minigames.games.duels.DuelGameHandler; @@ -25,10 +25,8 @@ import net.minecraft.sounds.SoundSource; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; - import java.util.Random; import java.util.UUID; - import static com.nexia.minigames.games.duels.gamemodes.GamemodeHandler.removeQueue; public class TeamDuelsGame extends DuelsGame { @@ -165,17 +163,11 @@ public static TeamDuelsGame startGame(@NotNull DuelsTeam team1, @NotNull DuelsTe public void duelSecond() { String isBroken = this.detectBrokenGame(); - if (isBroken != null) { + if (isBroken != null && !this.isEnding) { Component error = ChatFormat.nexiaMessage .append(Component.text("The game you were in was identified as broken, please contact a developer with a video of the last 30 seconds.", ChatFormat.normalColor)); Component errormsg = Component.text("Cause: " + isBroken); - - for (NexiaPlayer spectator : this.spectators) { - spectator.sendMessage(error); - spectator.sendMessage(errormsg); - } - for (ServerPlayer player : this.level.players()) { NexiaPlayer nexusPlayer = new NexiaPlayer(player); nexusPlayer.sendMessage(error); @@ -192,42 +184,34 @@ public void duelSecond() { if(notNullTeam != null) this.endGame(notNullTeam, null, false); } if (this.isEnding) { - int color = 160 * 65536 + 248; - // r * 65536 + g * 256 + b; - DuelGameHandler.winnerRockets(this.winner.alive.get(new Random().nextInt(this.winner.alive.size())), - this.level, color); + + if(this.winner != null && this.winner.alive != null && !this.winner.alive.isEmpty() && this.shouldWait) { + int color = 160 * 65536 + 248; + + // r * 65536 + g * 256 + b; + DuelGameHandler.winnerRockets(this.winner.alive.get(new Random().nextInt(this.winner.alive.size())), this.level, color); + } + this.currentEndTime++; + if (this.currentEndTime >= this.endTime || !this.shouldWait) { DuelsTeam winnerTeam = this.winner == null ? this.team1 : this.winner; DuelsTeam loserTeam = this.loser == null ? this.team2 : this.loser; - for (NexiaPlayer spectator : this.spectators) { - spectator = spectator.refreshPlayer(); - spectator.runCommand("/hub", 0, false); - } + for(ServerPlayer serverPlayer : this.level.players()) { + NexiaPlayer player = new NexiaPlayer(serverPlayer); - this.isEnding = false; - - if(loserTeam != null) { - for (NexiaPlayer player : loserTeam.all) { - player = player.refreshPlayer(); - ((DuelsPlayerData)PlayerDataManager.getDataManager(NexiaCore.DUELS_DATA_MANAGER).get(player)).gameOptions = null; - player.runCommand("/hub", 0, false); - } - loserTeam.refreshTeam(); + ((DuelsPlayerData)PlayerDataManager.getDataManager(NexiaCore.DUELS_DATA_MANAGER).get(player)).gameOptions = null; + player.runCommand("/hub", 0, false); } - if(winnerTeam != null) { - for (NexiaPlayer player : winnerTeam.all) { - player = player.refreshPlayer(); - ((DuelsPlayerData)PlayerDataManager.getDataManager(NexiaCore.DUELS_DATA_MANAGER).get(player)).gameOptions = null; - player.runCommand("/hub", 0, false); - } - winnerTeam.refreshTeam(); - } + if(loserTeam != null) loserTeam.refreshTeam(); + if(winnerTeam != null) winnerTeam.refreshTeam(); + DuelGameHandler.deleteWorld(String.valueOf(this.uuid)); removeDuelsGame(); + this.isEnding = false; return; } } @@ -304,7 +288,8 @@ public void endGame(@NotNull DuelsTeam loserTeam, @Nullable DuelsTeam winnerTeam Component subtitleWin = win; if ((winnerTeam == null || winnerTeam.getLeader() == null || winnerTeam.getLeader().unwrap() == null)) { - for (NexiaPlayer player : loserTeam.all) { + for (ServerPlayer serverPlayer : level.players()) { + NexiaPlayer player = new NexiaPlayer(serverPlayer); player.sendTitle(Title.title(titleWin, subtitleWin)); player.sendMessage(win); }