Skip to content

Commit 0fa371a

Browse files
committed
Fix issues #161 #159 #156
1 parent 9e4a8f1 commit 0fa371a

27 files changed

Lines changed: 201 additions & 84 deletions

Multiworld-Common/src/main/java/me/isaiah/multiworld/MultiworldMod.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public static void on_server_started(MinecraftServer mc) {
145145
}
146146
for (File fi : f.listFiles()) {
147147
String id = f.getName() + ":" + fi.getName().replace(".yml", "");
148-
LOGGER.info("Found saved world " + id);
148+
LOGGER.info("Found legacy saved world " + id);
149149
CreateCommand.reinit_world_from_config(mc, id);
150150
}
151151
}
@@ -207,7 +207,11 @@ public static boolean permissionLevel(ServerCommandSource source, int level) {
207207
public static void register_commands(CommandDispatcher<ServerCommandSource> dispatcher) {
208208
dispatcher.register(literal(CMD)
209209
.requires(source -> {
210-
try {
210+
// #if mc182
211+
// if (net.fabricmc.loader.api.FabricLoader.getInstance().isDevelopmentEnvironment()) return true;
212+
// #endif
213+
214+
try {
211215
return Perm.has(get_player(source), "multiworld.cmd") ||
212216
Perm.has(get_player(source), "multiworld.admin") || permissionLevel(source, 1);
213217
} catch (Exception e) {

Multiworld-Common/src/main/java/me/isaiah/multiworld/Utils.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public static String getWorldName(Identifier id) {
251251
}
252252

253253
public static Path getWorldStoragePath() {
254-
return getWorldStoragePath(MultiworldMod.mc);
254+
return getWorldStoragePath(MultiworldMod.mc, WorldFolderMode.VANILLA);
255255
}
256256

257257
public static Path getWorldStoragePath(MinecraftServer server, WorldFolderMode mode) {
@@ -290,6 +290,7 @@ public static Path getWorldPath(Identifier id, WorldFolderMode mode) {
290290
*/
291291
}
292292

293+
@Deprecated
293294
public static Path getWorldStoragePath(MinecraftServer server) {
294295
Path overworld = ((MinecraftServerAccess) server).getSession().getWorldDirectory(World.OVERWORLD);
295296

@@ -352,11 +353,15 @@ public static List<Path> searchForWorlds() {
352353
return searchForWorlds(storage);
353354
}
354355

356+
/**
357+
* @param storage - Directory
358+
* @return List of Path to found worlds
359+
*/
355360
public static List<Path> searchForWorlds(Path storage) {
356361
List<Path> worldPaths = new ArrayList<>();
357362

358-
System.out.println("DEBUG: " + storage);
359-
363+
MultiworldMod.LOGGER.info("Searching for Worlds in: " + storage);
364+
360365
File fold = storage.toFile();
361366

362367
if (!fold.exists()) {
@@ -368,16 +373,18 @@ public static List<Path> searchForWorlds(Path storage) {
368373
if (!f.isDirectory()) {
369374
continue;
370375
}
371-
376+
372377
Path dirPath = storage.resolve(f.getName());
373-
378+
374379
// File levelData = new File(f, "level.dat");
375380
File multiworldConfig = new File(f, "multiworld-world.yml");
376-
381+
377382
if (/*levelData.exists() ||*/ multiworldConfig.exists()) {
378383
worldPaths.add(dirPath);
384+
continue;
379385
}
380386

387+
worldPaths.addAll( searchForWorlds(f.toPath()) );
381388
}
382389

383390
return worldPaths;

Multiworld-Common/src/main/java/me/isaiah/multiworld/fabric/ICommonHooks.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ public static boolean hasICommon() {
3939

4040
public static World getWorld(PlayerEntity player) {
4141
try {
42+
// #if mc182
43+
// // empty
44+
// #else
4245
World world = ((me.isaiah.common.cmixin.IMixinEntity) player).ic$getWorld();
4346
return world;
47+
// #endif
4448
} catch (Exception | NoSuchMethodError ex) {
4549
// Older version of iCommonLib
4650
}
@@ -67,13 +71,16 @@ public void registerThis() {
6771
MultiworldMod.LOGGER.info("Multiworld: Registered '" + r + "' iCommon events.");
6872
}
6973

74+
// #if mc182
75+
// // TODO: 1.18.2 icommon portal enter event
76+
// #else
7077
@EventHandler
7178
public void onPortalEnter(EntityPortalCollideEvent ev) {
7279
if (!(ev.getEntity() instanceof ServerPlayerEntity)) {
7380
return;
7481
}
7582

76-
// Check if portal
83+
// // Check if portal
7784

7885
boolean is_our_portal = true;
7986

@@ -82,8 +89,6 @@ public void onPortalEnter(EntityPortalCollideEvent ev) {
8289

8390
if (is_our_portal) {
8491
for (Portal p : PortalCommand.KNOWN_PORTALS.values()) {
85-
// boolean canPos = p.blocks.contains(pos);
86-
8792
BlockPos min = p.getMinPos();
8893
BlockPos max = p.getMaxPos();
8994

@@ -111,5 +116,6 @@ public void onPortalEnter(EntityPortalCollideEvent ev) {
111116
}
112117
}
113118
}
119+
// #endif
114120

115121
}

Multiworld-Common/src/main/java/me/isaiah/multiworld/fabric/PermFabric.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@ public static void init() {
2727

2828
@Override
2929
public boolean has_impl(ServerPlayerEntity plr, String perm) {
30-
boolean cyber = FabricLoader.getInstance().getModContainer("cyber-permissions").isPresent();
30+
31+
// #if mc182
32+
// if (FabricLoader.getInstance().isDevelopmentEnvironment()) {
33+
// return true;
34+
// }
35+
// #endif
36+
37+
boolean cyber = FabricLoader.getInstance().getModContainer("cyber-permissions").isPresent();
3138
boolean luck = FabricLoader.getInstance().getModContainer("fabric-permissions-api-v0").isPresent();
3239

3340
boolean res = Perm.permissionLevel(plr, 2); // plr.hasPermissionLevel(2);
3441

3542
if (cyber) {
36-
if (CyberHandler.hasPermission(plr, perm)) res = true;
43+
// if (CyberHandler.hasPermission(plr, perm)) res = true;
3744
}
3845

3946
if (luck) {

fabric/Multiworld-Fabric-1.18.2/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ dependencies {
5151

5252
include("xyz.nucleoid:fantasy:0.4.7+1.18.2")
5353
modImplementation("xyz.nucleoid:fantasy:0.4.7+1.18.2")
54-
modImplementation("curse.maven:cyber-permissions-407695:4640544")
54+
compileOnly("curse.maven:cyber-permissions-407695:4640544")
5555
modImplementation("me.lucko:fabric-permissions-api:0.2-SNAPSHOT")
5656
modImplementation("net.fabricmc.fabric-api:fabric-api:0.76.0+1.18.2")
5757
// modImplementation("net.fabricmc.fabric-api:fabric-api-deprecated:0.76.0+1.18.2")
5858

5959
val ic = DefaultExternalModuleDependency(
6060
"com.javazilla.mods",
61-
"icommon-fabric-1.21.4",
62-
"1.21.4",
61+
"icommon-fabric-1.18.2",
62+
"1.18.2",
6363
null
6464
).apply {
6565
isChanging = true // Make sure we get the latest version of iCommon
6666
}
6767

68-
modImplementation(ic)
68+
compileOnly(ic)
6969
}
7070

7171
// Jabel

fabric/Multiworld-Fabric-1.20.4/src/main/java/me/isaiah/multiworld/fabric/FabricWorldCreator.java

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.isaiah.multiworld.fabric;
22

33
import java.io.IOException;
4+
import java.nio.file.Path;
45
import java.util.Collections;
56
import java.util.HashMap;
67
import java.util.List;
@@ -11,6 +12,8 @@
1112
import dimapi.FabricDimensionInternals;
1213
import me.isaiah.multiworld.ICreator;
1314
import me.isaiah.multiworld.MultiworldMod;
15+
import me.isaiah.multiworld.Utils;
16+
import multiworld.api.WorldFolderMode;
1417
import net.minecraft.registry.Registry;
1518
import net.minecraft.registry.RegistryKey;
1619
import net.minecraft.registry.RegistryKeys;
@@ -101,29 +104,53 @@ public ServerWorld create_world(String id, Identifier dim, ChunkGenerator gen, D
101104
* @throws SymlinkValidationException
102105
*/
103106
public static GameRules readGameRules(Identifier id) throws IOException {
107+
try {
108+
return mw$readGameRules(MultiworldMod.mc, id);
109+
} catch (IOException | SymlinkValidationException e) {
110+
// TODO Auto-generated catch block
111+
// e.printStackTrace();
112+
throw new IOException(e);
113+
}
114+
}
115+
116+
/**
117+
* Reads gamerules from a world's level.dat
118+
*/
119+
public static GameRules mw$readGameRules(MinecraftServer server, Identifier worldId)
120+
throws IOException, SymlinkValidationException {
121+
122+
String name = Utils.getWorldName(worldId);
123+
Path customWorldPath = Utils.getWorldStoragePath();
104124

105-
try (Session session = MultiworldWorld.mw$getSession(MultiworldMod.mc, id)) {
125+
Optional<WorldFolderMode> mode = Utils.getFolderMode(worldId);
126+
if (!mode.isEmpty()) {
127+
customWorldPath = Utils.getWorldPath(worldId, mode.get()).getParent();
128+
129+
if (mode.get() == WorldFolderMode.VANILLA) {
130+
name = worldId.getPath();
131+
}
132+
}
133+
134+
LevelStorage storage = LevelStorage.create(customWorldPath);
135+
136+
try (Session session = storage.createSession(name)) {
106137
Dynamic<?> dynamic = session.readLevelProperties();
107-
108-
RegistryWrapper.WrapperLookup lookup = MultiworldMod.mc.getRegistryManager();
109-
110-
Registry<DimensionOptions> dimensionRegistry = MultiworldMod.mc.getRegistryManager().get(RegistryKeys.DIMENSION);
111-
112-
DataConfiguration dataConfig = MultiworldMod.mc.getSaveProperties().getDataConfiguration();
138+
139+
Registry<DimensionOptions> dimensionRegistry = server.getRegistryManager().get(RegistryKeys.DIMENSION);
140+
DataConfiguration dataConfig = server.getSaveProperties().getDataConfiguration();
113141

114142
SaveProperties props = LevelStorage.parseSaveProperties(
115143
dynamic,
116144
dataConfig,
117145
dimensionRegistry,
118-
MultiworldMod.mc.getRegistryManager()
146+
server.getRegistryManager()
119147
).properties();
120-
148+
121149
if (!(props instanceof LevelProperties levelProps)) {
122150
throw new IllegalStateException("SaveProperties is not a LevelProperties");
123151
}
124-
125-
session.close();
126-
// Return the gamerules object
152+
153+
// Return the gamerules directly
127154
return levelProps.getGameRules();
128155
}
129156
}

fabric/Multiworld-Fabric-1.20.6/src/main/java/me/isaiah/multiworld/fabric/FabricWorldCreator.java

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.isaiah.multiworld.fabric;
22

33
import java.io.IOException;
4+
import java.nio.file.Path;
45
import java.util.Collections;
56
import java.util.HashMap;
67
import java.util.List;
@@ -11,6 +12,8 @@
1112
import dimapi.FabricDimensionInternals;
1213
import me.isaiah.multiworld.ICreator;
1314
import me.isaiah.multiworld.MultiworldMod;
15+
import me.isaiah.multiworld.Utils;
16+
import multiworld.api.WorldFolderMode;
1417
import net.minecraft.registry.Registry;
1518
import net.minecraft.registry.RegistryKey;
1619
import net.minecraft.registry.RegistryKeys;
@@ -25,6 +28,7 @@
2528
import net.minecraft.util.Identifier;
2629
import net.minecraft.util.math.BlockPos;
2730
import net.minecraft.util.math.Vec3d;
31+
import net.minecraft.util.path.SymlinkValidationException;
2832
import net.minecraft.world.Difficulty;
2933
import net.minecraft.world.GameRules;
3034
import net.minecraft.world.SaveProperties;
@@ -88,30 +92,63 @@ public ServerWorld create_world(String id, Identifier dim, ChunkGenerator gen, D
8892
return world;
8993
}
9094

95+
/**
96+
* Reads the gamerules from a level.dat file in the given world folder.
97+
* @param savesDir Path to the root saves directory (e.g. ./saves).
98+
* @param worldName Name of the world folder.
99+
* @param dataFixer The server's DataFixer instance.
100+
* @return A GameRules object containing the rules from level.dat.
101+
* @throws IOException if the file cannot be read.
102+
* @throws SymlinkValidationException
103+
*/
91104
public static GameRules readGameRules(Identifier id) throws IOException {
105+
try {
106+
return mw$readGameRules(MultiworldMod.mc, id);
107+
} catch (IOException | SymlinkValidationException e) {
108+
// TODO Auto-generated catch block
109+
// e.printStackTrace();
110+
throw new IOException(e);
111+
}
112+
}
113+
114+
/**
115+
* Reads gamerules from a world's level.dat
116+
*/
117+
public static GameRules mw$readGameRules(MinecraftServer server, Identifier worldId)
118+
throws IOException, SymlinkValidationException {
119+
120+
String name = Utils.getWorldName(worldId);
121+
Path customWorldPath = Utils.getWorldStoragePath();
92122

93-
try (Session session = MultiworldWorld.mw$getSession(MultiworldMod.mc, id)) {
123+
Optional<WorldFolderMode> mode = Utils.getFolderMode(worldId);
124+
if (!mode.isEmpty()) {
125+
customWorldPath = Utils.getWorldPath(worldId, mode.get()).getParent();
126+
127+
if (mode.get() == WorldFolderMode.VANILLA) {
128+
name = worldId.getPath();
129+
}
130+
}
131+
132+
LevelStorage storage = LevelStorage.create(customWorldPath);
133+
134+
try (Session session = storage.createSession(name)) {
94135
Dynamic<?> dynamic = session.readLevelProperties();
95-
96-
RegistryWrapper.WrapperLookup lookup = MultiworldMod.mc.getRegistryManager();
97-
98-
Registry<DimensionOptions> dimensionRegistry = MultiworldMod.mc.getRegistryManager().get(RegistryKeys.DIMENSION);
99-
100-
DataConfiguration dataConfig = MultiworldMod.mc.getSaveProperties().getDataConfiguration();
136+
137+
Registry<DimensionOptions> dimensionRegistry = server.getRegistryManager().get(RegistryKeys.DIMENSION);
138+
DataConfiguration dataConfig = server.getSaveProperties().getDataConfiguration();
101139

102140
SaveProperties props = LevelStorage.parseSaveProperties(
103141
dynamic,
104142
dataConfig,
105143
dimensionRegistry,
106-
MultiworldMod.mc.getRegistryManager()
144+
server.getRegistryManager()
107145
).properties();
108-
146+
109147
if (!(props instanceof LevelProperties levelProps)) {
110148
throw new IllegalStateException("SaveProperties is not a LevelProperties");
111149
}
112-
113-
session.close();
114-
// Return the gamerules object
150+
151+
// Return the gamerules directly
115152
return levelProps.getGameRules();
116153
}
117154
}

fabric/Multiworld-Fabric-1.21.1/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ configurations.all {
3737
}
3838
}
3939

40-
4140
dependencies {
4241

4342
annotationProcessor("com.pkware.jabel:jabel-javac-plugin:1.0.1-1")
@@ -54,6 +53,7 @@ dependencies {
5453
modImplementation("me.lucko:fabric-permissions-api:0.2-SNAPSHOT")
5554
// modImplementation("net.fabricmc.fabric-api:fabric-api-deprecated:0.100.1+1.21")
5655

56+
modImplementation("net.fabricmc.fabric-api:fabric-api:0.103.0+1.21.1")
5757

5858
setOf(
5959
"fabric-api-base",
@@ -69,8 +69,8 @@ dependencies {
6969

7070
val ic = DefaultExternalModuleDependency(
7171
"com.javazilla.mods",
72-
"icommon-fabric-1.21.8",
73-
"1.21.8",
72+
"icommon-fabric-1.21.1",
73+
"1.21.1",
7474
null
7575
).apply {
7676
isChanging = true // Make sure we get the latest version of iCommon

0 commit comments

Comments
 (0)