Skip to content

Commit

Permalink
theres still 1 million bugs but atleast it works
Browse files Browse the repository at this point in the history
  • Loading branch information
not-coded committed Dec 14, 2024
1 parent 1627aeb commit 9df69c6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ private static int run(CommandContext<CommandSourceInfo> 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;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/nexia/minigames/NexiaMinigames.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/nexia/minigames/games/duels/DuelGameHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,6 +47,16 @@ public class DuelGameHandler {
public static List<DuelsGame> duelsGames = new ArrayList<>();
public static List<TeamDuelsGame> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand All @@ -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);

Expand All @@ -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))
Expand All @@ -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);

Expand All @@ -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))
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 9df69c6

Please sign in to comment.