Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #19

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
Open

Dev #19

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/main/java/com/nexia/base/player/PlayerDataManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.nexia.base.player;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mongodb.client.model.Filters;
import com.mongodb.client.result.UpdateResult;
import com.nexia.core.NexiaCore;
Expand All @@ -14,6 +12,7 @@
import com.nexia.minigames.games.bedwars.util.player.BedwarsPlayerData;
import com.nexia.minigames.games.bedwars.util.player.BedwarsSavedPlayerData;
import com.nexia.minigames.games.bridge.util.player.BridgePlayerData;
import com.nexia.minigames.games.bridge.util.player.BridgeSavedPlayerData;
import com.nexia.minigames.games.duels.util.player.DuelsPlayerData;
import com.nexia.minigames.games.duels.util.player.DuelsSavedPlayerData;
import com.nexia.minigames.games.football.util.player.FootballPlayerData;
Expand All @@ -32,12 +31,9 @@ public class PlayerDataManager {
public static Map<ResourceLocation, PlayerDataManager> dataManagerMap = new HashMap<>();

private final String collectionName;

HashMap<UUID, PlayerData> allPlayerData = new HashMap<>();

public Class<? extends SavedPlayerData> savedPlayerDataClass;

public Class<? extends PlayerData> playerDataClass;
HashMap<UUID, PlayerData> allPlayerData = new HashMap<>();

public PlayerDataManager(ResourceLocation id, String collectionName, Class<? extends SavedPlayerData> savedPlayerDataClass, Class<? extends PlayerData> playerDataClass) {
this.collectionName = collectionName;
Expand All @@ -49,6 +45,7 @@ public PlayerDataManager(ResourceLocation id, String collectionName, Class<? ext
public static PlayerDataManager getDataManager(ResourceLocation identifier) {
return dataManagerMap.get(identifier);
}

public static void init() {
// <----------- Core --------------->
new PlayerDataManager(NexiaCore.CORE_DATA_MANAGER, "core", CoreSavedPlayerData.class, CorePlayerData.class);
Expand All @@ -72,6 +69,9 @@ public static void init() {
// <----------- Football --------------->
new PlayerDataManager(NexiaCore.FOOTBALL_DATA_MANAGER, "football", FootballSavedPlayerData.class, FootballPlayerData.class);

// <----------- Bridge --------------->
new PlayerDataManager(NexiaCore.BRIDGE_DATA_MANAGER, "bridge", BridgeSavedPlayerData.class, BridgePlayerData.class);

// <----------- OITC --------------->
new PlayerDataManager(NexiaCore.OITC_DATA_MANAGER, "oitc", WLKSavedPlayerData.class, OITCPlayerData.class);

Expand Down Expand Up @@ -105,7 +105,8 @@ public void addPlayerData(UUID uuid) {
PlayerData playerData;
try {
playerData = playerDataClass.getConstructor(SavedPlayerData.class).newInstance(loadPlayerData(uuid, savedPlayerDataClass));
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
throw new RuntimeException(e);
}
allPlayerData.put(uuid, playerData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.nexia.core.utilities.player.CorePlayerData;
import com.nexia.minigames.games.bedwars.areas.BwAreas;
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
import com.nexia.minigames.games.bridge.BridgeGame;
import com.nexia.minigames.games.duels.util.player.DuelsPlayerData;
import com.nexia.minigames.games.oitc.OitcGame;
import com.nexia.minigames.games.skywars.SkywarsGame;
Expand All @@ -33,21 +34,26 @@ public void registerListener() {
return;
}

if(gameMode == PlayerGameMode.OITC){
if (gameMode == PlayerGameMode.OITC) {
OitcGame.death(nexiaPlayer, playerDeathEvent);
return;
}

if(gameMode == PlayerGameMode.SKYWARS) {
if (gameMode == PlayerGameMode.BRIDGE) {
BridgeGame.death(nexiaPlayer, playerDeathEvent);
return;
}

if (gameMode == PlayerGameMode.SKYWARS) {
SkywarsGame.death(nexiaPlayer, playerDeathEvent);
}

if(gameMode == PlayerGameMode.LOBBY && duelsData.gameOptions != null) {
if(duelsData.gameOptions.duelsGame != null) {
if (gameMode == PlayerGameMode.LOBBY && duelsData.gameOptions != null) {
if (duelsData.gameOptions.duelsGame != null) {
duelsData.gameOptions.duelsGame.death(nexiaPlayer);
return;
}
if(duelsData.gameOptions.teamDuelsGame != null) {
if (duelsData.gameOptions.teamDuelsGame != null) {
duelsData.gameOptions.teamDuelsGame.death(nexiaPlayer, playerDeathEvent);
}
}
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/com/nexia/core/mixin/block/EndPortalBlockMixin.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package com.nexia.core.mixin.block;
import com.nexia.minigames.games.bridge.BridgeGame;

import com.nexia.base.player.NexiaPlayer;
import com.nexia.base.player.PlayerDataManager;
import com.nexia.core.NexiaCore;
import com.nexia.minigames.games.duels.util.player.DuelsPlayerData;
import com.nexia.minigames.games.bridge.BridgeGame;
import com.nexia.minigames.games.bridge.util.player.BridgePlayerData;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EndPortalBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static com.nexia.minigames.games.bridge.BridgeGame.team1;
import static com.nexia.minigames.games.bridge.BridgeGame.team2;
import static com.nexia.core.NexiaCore.BRIDGE_DATA_MANAGER;

@Mixin(EndPortalBlock.class)
public class EndPortalBlockMixin {
Expand All @@ -26,16 +24,21 @@ public class EndPortalBlockMixin {
)
private void entityInside(BlockState blockState, Level level, BlockPos blockPos, Entity entity, CallbackInfo ci) {
if (!(entity instanceof ServerPlayer serverPlayer)) return;
NexiaPlayer nexiaPlayer = new NexiaPlayer(serverPlayer);
if (nexiaPlayer.unwrap() == entity && nexiaPlayer.hasTag("in_bridge_game")) {

BridgeGame.goal(nexiaPlayer);
NexiaPlayer nexiaPlayer = new NexiaPlayer(serverPlayer);

if (nexiaPlayer.hasTag("in_bridge_game")) {

BridgePlayerData data = (BridgePlayerData) PlayerDataManager.getDataManager(BRIDGE_DATA_MANAGER).get(nexiaPlayer);

if (data.team == BridgeGame.team1) {

BridgeGame.goal(nexiaPlayer, "team1");
}
if (data.team == BridgeGame.team2) {

BridgeGame.goal(nexiaPlayer, "team2");
}
}

}
}
}
19 changes: 13 additions & 6 deletions src/main/java/com/nexia/core/utilities/time/ServerTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static void firstTick(MinecraftServer server) {
BwDimension.register();
BwGame.firstTick();
FootballGame.firstTick();
BridgeGame.firstTick();
WorldUtil.deleteTempWorlds();

SkywarsGame.firstTick();
Expand All @@ -84,7 +85,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)));
}

Expand All @@ -104,6 +105,7 @@ public static void everyTick() {
BwGame.tick();
SkyFfaBlocks.tick();
FootballGame.tick();
BridgeGame.tick();
OitcGame.tick();
BridgeGame.tick();

Expand All @@ -118,8 +120,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();
}
}
Expand All @@ -128,24 +132,27 @@ static void everySecond() {
totalSecondCount++;
OitcGame.second();
FootballGame.second();
BridgeGame.second();
SkywarsGame.second();
BridgeGame.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;
}
}
Expand Down
Loading
Loading