Skip to content

Commit

Permalink
make ffa world auto-generate if there is no world
Browse files Browse the repository at this point in the history
  • Loading branch information
not-coded committed Aug 3, 2024
1 parent c835b52 commit 61e9e5e
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.nexia.core.utilities.chat.LegacyChatFormat;
import com.nexia.core.utilities.misc.RandomUtil;
import com.nexia.core.utilities.time.ServerTime;
import com.nexia.ffa.FfaUtil;
import com.nexia.ffa.uhc.utilities.UhcFfaAreas;
import com.nexia.minigames.games.skywars.SkywarsGame;
import com.nexia.minigames.games.skywars.SkywarsMap;
Expand All @@ -23,16 +24,9 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.Difficulty;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.dimension.DimensionType;
import xyz.nucleoid.fantasy.RuntimeWorldConfig;

import java.io.FileWriter;

import static com.nexia.core.utilities.world.WorldUtil.getChunkGenerator;

public class DevExperimentalCommandsCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
dispatcher.register((Commands.literal("devexperimentalcmds")
Expand All @@ -58,23 +52,7 @@ private static int run(CommandContext<CommandSourceStack> context) throws Comman
if(name.contains("-")) name = name.split("-")[1];

if(argument.contains("cffa")){
ServerLevel level = ServerTime.fantasy.getOrOpenPersistentWorld(ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation("ffa", name)).location(), (
new RuntimeWorldConfig()
.setDimensionType(DimensionType.OVERWORLD_LOCATION)
.setGenerator(getChunkGenerator(Biomes.PLAINS))
.setDifficulty(Difficulty.HARD)
.setGameRule(GameRules.RULE_KEEPINVENTORY, true)
.setGameRule(GameRules.RULE_MOBGRIEFING, false)
.setGameRule(GameRules.RULE_WEATHER_CYCLE, false)
.setGameRule(GameRules.RULE_DAYLIGHT, true)
.setGameRule(GameRules.RULE_DO_IMMEDIATE_RESPAWN, true)
.setGameRule(GameRules.RULE_DOMOBSPAWNING, false)
.setGameRule(GameRules.RULE_SHOWDEATHMESSAGES, false)
.setGameRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS, false)
.setGameRule(GameRules.RULE_DISABLE_ELYTRA_MOVEMENT_CHECK, true)
.setGameRule(GameRules.RULE_DROWNING_DAMAGE, true)
.setGameRule(GameRules.RULE_SPAWN_RADIUS, 0))).asWorld();

ServerLevel level = ServerTime.fantasy.getOrOpenPersistentWorld(ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation("ffa", name)).location(), FfaUtil.ffaWorldConfig).asWorld();
player.teleportTo(level, 0, 80, 0, 0, 0);
} else if(argument.equalsIgnoreCase("rluhc")) {
UhcFfaAreas.resetMap(true);
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/nexia/ffa/FfaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.nexia.core.games.util.PlayerGameMode;
import com.nexia.core.utilities.chat.ChatFormat;
import com.nexia.core.utilities.player.CorePlayerData;
import com.nexia.core.utilities.time.ServerTime;
import com.nexia.ffa.classic.utilities.ClassicFfaAreas;
import com.nexia.ffa.classic.utilities.FfaClassicUtil;
import com.nexia.ffa.kits.utilities.FfaKitsUtil;
Expand All @@ -17,17 +18,47 @@
import com.nexia.ffa.uhc.utilities.FfaUhcUtil;
import com.nexia.ffa.uhc.utilities.UhcFfaAreas;
import net.kyori.adventure.text.Component;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Difficulty;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.dimension.DimensionType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.fantasy.RuntimeWorldConfig;

import java.text.DecimalFormat;

import static com.nexia.core.utilities.world.WorldUtil.getChunkGenerator;

public class FfaUtil {
public static final RuntimeWorldConfig ffaWorldConfig = new RuntimeWorldConfig()
.setDimensionType(DimensionType.OVERWORLD_LOCATION)
.setGenerator(getChunkGenerator(Biomes.PLAINS))
.setDifficulty(Difficulty.HARD)
.setGameRule(GameRules.RULE_KEEPINVENTORY, true)
.setGameRule(GameRules.RULE_MOBGRIEFING, false)
.setGameRule(GameRules.RULE_WEATHER_CYCLE, false)
.setGameRule(GameRules.RULE_DAYLIGHT, true)
.setGameRule(GameRules.RULE_DO_IMMEDIATE_RESPAWN, true)
.setGameRule(GameRules.RULE_DOMOBSPAWNING, false)
.setGameRule(GameRules.RULE_SHOWDEATHMESSAGES, false)
.setGameRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS, false)
.setGameRule(GameRules.RULE_DISABLE_ELYTRA_MOVEMENT_CHECK, true)
.setGameRule(GameRules.RULE_DROWNING_DAMAGE, true)
.setGameRule(GameRules.RULE_SPAWN_RADIUS, 0);

public static ServerLevel generateWorld(String id) {
return ServerTime.fantasy.getOrOpenPersistentWorld(ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation("ffa", id)).location(), FfaUtil.ffaWorldConfig).asWorld();
}

public static boolean isFfaPlayer(NexiaPlayer player) {
return ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode == PlayerGameMode.FFA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.nexia.core.utilities.pos.EntityPos;
import com.nexia.core.utilities.world.WorldUtil;
import com.nexia.ffa.FfaAreas;
import com.nexia.ffa.FfaUtil;
import com.nexia.nexus.api.world.World;
import com.nexia.nexus.api.world.util.Location;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -65,11 +66,15 @@ public static void setFfaWorld(MinecraftServer server) {
for (ServerLevel level : server.getAllLevels()) {
if (isFfaWorldStatic(level)) {
ffaWorld = level;
nexusFfaWorld = WorldUtil.getWorld(level);
break;
}
}

if(ffaWorld == null) {
ffaWorld = FfaUtil.generateWorld("classic");
}

nexusFfaWorld = WorldUtil.getWorld(ffaWorld);
nexusFfaLocation = new Location(spawn.x, spawn.y, spawn.z, spawn.yaw, spawn.pitch, nexusFfaWorld);
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/nexia/ffa/kits/utilities/KitFfaAreas.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.nexia.core.utilities.pos.EntityPos;
import com.nexia.core.utilities.world.WorldUtil;
import com.nexia.ffa.FfaAreas;
import com.nexia.ffa.FfaUtil;
import com.nexia.nexus.api.world.World;
import com.nexia.nexus.api.world.util.Location;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -66,11 +67,15 @@ public static void setFfaWorld(MinecraftServer server) {
for (ServerLevel level : server.getAllLevels()) {
if (isFfaWorldStatic(level)) {
ffaWorld = level;
nexusFfaWorld = WorldUtil.getWorld(level);
break;
}
}

if(ffaWorld == null) {
ffaWorld = FfaUtil.generateWorld("kits");
}

nexusFfaWorld = WorldUtil.getWorld(ffaWorld);
nexusFfaLocation = new Location(spawn.x, spawn.y, spawn.z, spawn.yaw, spawn.pitch, nexusFfaWorld);
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/nexia/ffa/pot/utilities/PotFfaAreas.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.nexia.core.utilities.pos.EntityPos;
import com.nexia.core.utilities.world.WorldUtil;
import com.nexia.ffa.FfaAreas;
import com.nexia.ffa.FfaUtil;
import com.nexia.nexus.api.world.World;
import com.nexia.nexus.api.world.util.Location;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -66,11 +67,15 @@ public static void setFfaWorld(MinecraftServer server) {
for (ServerLevel level : server.getAllLevels()) {
if (isFfaWorldStatic(level)) {
ffaWorld = level;
nexusFfaWorld = WorldUtil.getWorld(level);
break;
}
}

if(ffaWorld == null) {
ffaWorld = FfaUtil.generateWorld("pot");
}

nexusFfaWorld = WorldUtil.getWorld(ffaWorld);
nexusFfaLocation = new Location(spawn.x, spawn.y, spawn.z, spawn.yaw, spawn.pitch, nexusFfaWorld);
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/nexia/ffa/sky/utilities/SkyFfaAreas.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.nexia.core.utilities.pos.ProtectionMap;
import com.nexia.core.utilities.world.WorldUtil;
import com.nexia.ffa.FfaAreas;
import com.nexia.ffa.FfaUtil;
import com.nexia.nexus.api.world.World;
import com.nexia.nexus.api.world.util.Location;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -79,11 +80,15 @@ public static void setFfaWorld(MinecraftServer server) {
for (ServerLevel level : server.getAllLevels()) {
if (isFfaWorldStatic(level)) {
ffaWorld = level;
nexusFfaWorld = WorldUtil.getWorld(level);
break;
}
}

if(ffaWorld == null) {
ffaWorld = FfaUtil.generateWorld("sky");
}

nexusFfaWorld = WorldUtil.getWorld(ffaWorld);
nexusFfaLocation = new Location(spawn.x, spawn.y, spawn.z, spawn.yaw, spawn.pitch, nexusFfaWorld);
}

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/nexia/ffa/uhc/utilities/UhcFfaAreas.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.nexia.core.utilities.pos.EntityPos;
import com.nexia.core.utilities.world.WorldUtil;
import com.nexia.ffa.FfaAreas;
import com.nexia.ffa.FfaUtil;
import com.nexia.nexus.api.util.Identifier;
import com.nexia.nexus.api.world.World;
import com.nexia.nexus.api.world.entity.player.Player;
Expand Down Expand Up @@ -51,7 +52,7 @@ public static void resetMap(boolean announce) {

if (announce) {
for (Player player : nexusFfaWorld.getPlayers()) {
player.sendMessage(Component.text("[!] Map has been reloaded!").color(ChatFormat.lineTitleColor));
player.sendMessage(ChatFormat.nexiaMessage.append(Component.text("The map has been reloaded!", ChatFormat.normalColor)));
}
}
}
Expand Down Expand Up @@ -98,11 +99,15 @@ public static void setFfaWorld(MinecraftServer server) {
for (ServerLevel level : server.getAllLevels()) {
if (isFfaWorldStatic(level)) {
ffaWorld = level;
nexusFfaWorld = WorldUtil.getWorld(level);
break;
}
}

if(ffaWorld == null) {
ffaWorld = FfaUtil.generateWorld("uhc");
}

nexusFfaWorld = WorldUtil.getWorld(ffaWorld);
nexusFfaLocation = new Location(spawn.x, spawn.y, spawn.z, spawn.yaw, spawn.pitch, nexusFfaWorld);
}
}

0 comments on commit 61e9e5e

Please sign in to comment.