Skip to content

Commit

Permalink
add the ability to run the server locally
Browse files Browse the repository at this point in the history
  • Loading branch information
not-coded committed Dec 13, 2024
1 parent 8469524 commit 71e1537
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 30 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "run/world/datapacks"]
path = run/world/datapacks
url = https://github.com/nexia-cts/Nexia-Datapack.git
branch = main
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<br>

# Nexia

using **Nexus API**

The mod for the Nexia CTS server.
Expand All @@ -16,7 +17,18 @@ The mod for the Nexia CTS server.
- Gradle 8.7

### Build

- Clone the repository
- `git clone https://github.com/nexia-cts/Nexia-Mod`
- `git checkout 'main/dev'`
- Run `./gradlew build`

### Run the server locally

- Extract the zip file [Run_server_locally_(READ_README.md_FIRST).zip](Run_server_locally_(READ_README.md_FIRST).zip) so that the folder `run/` is in the main directory
- e.g. `/Nexia-Mod/run/...`
- **DO NOT DELETE THE ZIP FILE AFTER EXTRACTING!!!!**
- Run `git submodule update --init --recursive`
- Run the `Minecraft Server` Configuration in Intellij IDEA
- Accept the EULA ([/run/eula.txt](/run/eula.txt))
- Enjoy and don't forget to OP yourself!
Binary file added Run_server_locally_(READ_README.md_FIRST).zip
Binary file not shown.
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ dependencies {
// Important!
modImplementation("com.nexia.nexus:nexus-api:${project.nexus_version}-full")
modImplementation("com.nexia.nexus:nexus-builder:${project.nexus_version}-${project.minecraft_version}-full")
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Using Fabric API for CTS apparently just doesn't want to make it build but we have to use it so the server doesn't crash when right clicking something
modCompileOnlyApi("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")
//modRuntimeOnly("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}.combat")
// ↑ included in run/mods/ instead

include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${project.mixin_extras_version}")))

// MongoDB
Expand All @@ -78,7 +83,7 @@ dependencies {
modApi("me.lucko:fabric-permissions-api:${project.fabric_permissions_api_version}")
include(implementation("net.kyori:adventure-text-minimessage:${project.adventure_version}"))
include(implementation("net.kyori:adventure-text-serializer-gson:${project.adventure_version}"))
include(compileOnly("de.themoep:minedown-adventure:${project.minedown_adventure_version}"))
include(implementation("de.themoep:minedown-adventure:${project.minedown_adventure_version}"))
compileOnly("net.luckperms:api:${project.luckperms_api_version}")

// discord shit
Expand All @@ -89,7 +94,6 @@ dependencies {
// useless libraries
include(implementation("com.google.code.gson:gson:${project.gson_version}"))
include(implementation("com.googlecode.json-simple:json-simple:${project.json_simple_version}"))

}

// Custom Manifest and Intermediary mappings declaration
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.parallel=true
# check these on https://fabricmc.net/use
minecraft_version=1.16_combat-6
yarn_mappings=1.16_combat-6+build.2
loader_version=0.14.21
loader_version=0.14.25

# Mod Properties
mod_version = 2.0.0
Expand Down
1 change: 1 addition & 0 deletions run/world/datapacks
Submodule datapacks added at 9b9901
13 changes: 10 additions & 3 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 @@ -19,9 +17,9 @@
import com.nexia.minigames.games.football.util.player.FootballSavedPlayerData;
import com.nexia.minigames.games.oitc.util.player.OITCPlayerData;
import com.nexia.minigames.games.skywars.util.player.SkywarsPlayerData;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.resources.ResourceLocation;
import org.bson.Document;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -114,6 +112,7 @@ public void removePlayerData(UUID uuid) {
}

private void savePlayerData(UUID uuid) {
if(FabricLoader.getInstance().isDevelopmentEnvironment()) return;
Document document = NexiaCore.mongoManager.toDocument(get(uuid).savedData);
document.append("uuid", uuid.toString());
document.remove("data");
Expand All @@ -126,6 +125,14 @@ private void savePlayerData(UUID uuid) {
}

private <T extends SavedPlayerData> T loadPlayerData(UUID uuid, Class<T> toLoad) throws InstantiationException, IllegalAccessException {
if(FabricLoader.getInstance().isDevelopmentEnvironment()) {
try {
return toLoad.getDeclaredConstructor().newInstance();
} catch (InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}

T savedPlayerData = NexiaCore.mongoManager.getObject(collectionName, Filters.eq("uuid", uuid.toString()), toLoad);
if (savedPlayerData != null) {
return savedPlayerData;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/nexia/core/NexiaCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public void onInitialize() {
AutoConfig.register(ModConfig.class, GsonConfigSerializer::new);
config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();

if(FabricLoader.getInstance().isDevelopmentEnvironment()) {
config.serverType = "dev";
config.debugMode = true;
}

logger.info("Loading mod...");
PlayerDataManager.init();
logger.info("Registering commands...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.nexia.core.utilities.chat.LegacyChatFormat;
import com.nexia.core.utilities.item.InventoryUtil;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.SharedSuggestionProvider;
Expand All @@ -20,7 +21,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, bo
dispatcher.register((Commands.literal("deleteinventory")
.requires(commandSourceStack -> {
try {
return Permissions.check(commandSourceStack, "nexia.inventory.delete", 4);
return Permissions.check(commandSourceStack, "nexia.inventory.delete", 4) || FabricLoader.getInstance().isDevelopmentEnvironment();
} catch (Exception ignored) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, bo
dispatcher.register((Commands.literal("devexperimentalcmds")
.requires(commandSourceStack -> {
try {
return Permissions.check(commandSourceStack, "nexia.dev.experimentalcmds");
return Permissions.check(commandSourceStack, "nexia.dev.experimentalcmds") || FabricLoader.getInstance().isDevelopmentEnvironment();
} catch (Exception ignored) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.nexia.minigames.games.oitc.OitcGame;
import com.nexia.minigames.games.skywars.SkywarsGame;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.SharedSuggestionProvider;
Expand All @@ -18,7 +19,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, bo
dispatcher.register((Commands.literal("forcegameend")
.requires(commandSourceStack -> {
try {
return Permissions.check(commandSourceStack, "nexia.dev.forcegameend");
return Permissions.check(commandSourceStack, "nexia.dev.forcegameend") || FabricLoader.getInstance().isDevelopmentEnvironment();
} catch (Exception ignored) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.nexia.core.utilities.item.InventoryUtil;
import com.nexia.base.player.NexiaPlayer;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.Util;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
Expand All @@ -25,7 +26,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, bo
dispatcher.register((Commands.literal("loadinventory")
.requires(commandSourceStack -> {
try {
return Permissions.check(commandSourceStack, "nexia.inventory.load", 4);
return Permissions.check(commandSourceStack, "nexia.inventory.load", 4) || FabricLoader.getInstance().isDevelopmentEnvironment();
} catch (Exception ignored) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.nexia.core.utilities.chat.LegacyChatFormat;
import com.nexia.core.utilities.item.InventoryUtil;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.SharedSuggestionProvider;
Expand All @@ -23,7 +24,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, bo
dispatcher.register((Commands.literal("saveinventory")
.requires(commandSourceStack -> {
try {
return Permissions.check(commandSourceStack, "nexia.inventory.save", 4);
return Permissions.check(commandSourceStack, "nexia.inventory.save", 4) || FabricLoader.getInstance().isDevelopmentEnvironment();
} catch (Exception ignored) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
Expand All @@ -20,6 +21,6 @@ public class CommandBlockMixin {
)
)
public boolean canUseCommandBlock(boolean original, BlockState blockState, Level level, BlockPos blockPos, Player player) {
return Permissions.check(player, "nexia.dev.commandblock");
return Permissions.check(player, "nexia.dev.commandblock") || FabricLoader.getInstance().isDevelopmentEnvironment();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;
import java.util.function.Predicate;

Expand Down Expand Up @@ -81,7 +80,7 @@ public boolean isPushable() {
* @reason Make armor stands pushable
*/
@Overwrite
protected void doPush(Entity entity) {
public void doPush(Entity entity) {
if(!FootballGame.world.equals(this.level)) return;
entity.push(this);
}
Expand All @@ -92,7 +91,7 @@ protected void doPush(Entity entity) {
* @reason Make armor stands pushable
*/
@Overwrite
protected void pushEntities() {
public void pushEntities() {
if(!FootballGame.world.equals(this.level)) {
List<Entity> list = this.level.getEntities(this, this.getBoundingBox(), RIDABLE_MINECARTS);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.nexia.core.mixin.misc;

import com.mojang.authlib.GameProfile;
import com.nexia.core.NexiaCore;
import com.nexia.core.utilities.time.ServerTime;
import com.nexia.core.utilities.time.ServerType;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.status.ServerStatus;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.players.PlayerList;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -22,8 +21,6 @@
@Mixin(MinecraftServer.class)
public abstract class MinecraftServerMixin {

@Shadow public abstract PlayerList getPlayerList();

@Unique
boolean firstTickPassed = false;

Expand Down Expand Up @@ -53,7 +50,7 @@ private void noSpawnProtection(ServerLevel serverLevel, BlockPos blockPos, Playe
@ModifyArg(method = "tickServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/status/ServerStatus$Players;setSample([Lcom/mojang/authlib/GameProfile;)V"))
private GameProfile[] hidePlayers(GameProfile[] gameProfiles) {

if(ServerType.returnServer().equals(ServerType.DEV)) {
if(ServerType.returnServer().equals(ServerType.DEV) && !NexiaCore.config.debugMode) {
return new GameProfile[]{new GameProfile(Util.NIL_UUID, "§e⟡ you tried ⟡"),
new GameProfile(Util.NIL_UUID, "§eヽ(・∀・)ノ"),
new GameProfile(Util.NIL_UUID, " "),
Expand All @@ -68,7 +65,7 @@ private GameProfile[] hidePlayers(GameProfile[] gameProfiles) {

@ModifyArg(method = "tickServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/status/ServerStatus;setPlayers(Lnet/minecraft/network/protocol/status/ServerStatus$Players;)V"))
private ServerStatus.Players hidePlayerCount(ServerStatus.Players players) {
if(ServerType.returnServer().equals(ServerType.DEV)) {
if(ServerType.returnServer().equals(ServerType.DEV) && !NexiaCore.config.debugMode) {
// can't set current player count for some reason (69)
return new ServerStatus.Players(420, 69);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.nexia.minigames.games.oitc.OitcGame;
import com.nexia.minigames.games.skywars.SkywarsGame;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.*;
Expand Down Expand Up @@ -78,7 +79,7 @@ private void onCustomPayload(ServerboundCustomPayloadPacket serverboundCustomPay
)
)
public boolean canUseCommandBlock(boolean original) {
return Permissions.check(this.player, "nexia.dev.commandblock");
return Permissions.check(this.player, "nexia.dev.commandblock") || FabricLoader.getInstance().isDevelopmentEnvironment();
}

@Inject(at = @At("HEAD"), method = "onDisconnect")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.internal.bind.TypeAdapters;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoCredential;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import net.fabricmc.loader.api.FabricLoader;
import org.bson.Document;
import org.bson.conversions.Bson;

import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import static com.nexia.core.NexiaCore.config;

@SuppressWarnings("unused")
Expand All @@ -36,6 +33,7 @@ public MongoManager() {
}

public void openConnection() {
if(FabricLoader.getInstance().isDevelopmentEnvironment()) return;
final MongoCredential mongoCredential = MongoCredential.createCredential(
config.username,
config.database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static ProtectionMap importMap(String filePath, ProtectionBlock[] listedB
map = gson.fromJson(possibleJson, byte[][][].class);
} catch (Exception e) {
NexiaCore.logger.error(NexiaCore.MOD_NAME + ": Failed to import protection map from {}", filePath);
NexiaCore.logger.error("Use '/protectionmap' to recreate them (go to the correct dimension first)!");
return null;
}
return new ProtectionMap(map, listedBlocks, notListedBlock, outsideMessage);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/nexia/discord/NexiaDiscord.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;

Expand All @@ -22,6 +23,7 @@ public class NexiaDiscord implements ModInitializer {
public void onInitialize() {
AutoConfig.register(ModConfig.class, GsonConfigSerializer::new);
config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
if(FabricLoader.getInstance().isDevelopmentEnvironment()) return;

Logger logger = NexiaCore.logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
import com.nexia.ffa.base.BaseFfaUtil;
import com.nexia.nexus.api.world.entity.player.Player;
import com.nexia.nexus.api.world.util.Location;
import net.fabricmc.loader.api.FabricLoader;
import net.kyori.adventure.text.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.timers.FunctionCallback;
import net.minecraft.world.level.timers.TimerQueue;

import java.util.List;

public class FfaClassicUtil extends BaseFfaUtil {
public static final FfaClassicUtil INSTANCE = new FfaClassicUtil();

Expand All @@ -42,6 +40,8 @@ public PlayerDataManager getDataManager() {

@Override
public boolean checkBot() {
if(FabricLoader.getInstance().isDevelopmentEnvironment()) return false;

Player bot = ServerTime.nexusServer.getPlayer("femboy.ai");

if (bot != null && getNexusFfaWorld().getPlayers().size() == 1) {
Expand Down
Loading

0 comments on commit 71e1537

Please sign in to comment.