externalize patching logic a bit

This commit is contained in:
FalsePattern committed 2022-07-13 20:42:04 +02:00
1 parent 7ccf86928f
commit 3d834429f9
6 files changed
+135 -21

No files matched your search

@@ -0,0 +1,7 @@
package com.falsepattern.endlessids.patching;
public class ClientManager extends CommonManager {
public ClientManager() {
super();
}
}
@@ -0,0 +1,69 @@
package com.falsepattern.endlessids.patching;
import com.falsepattern.endlessids.EndlessIDs;
import com.falsepattern.endlessids.patching.patches.common.Tropicraft;
import lombok.SneakyThrows;
import lombok.val;
import cpw.mods.fml.common.Loader;
import java.util.ArrayList;
import java.util.List;
public class CommonManager {
protected final List<Patch> patches = new ArrayList<>();
public CommonManager() {
patches.add(new Tropicraft());
}
@SneakyThrows
public final void preInit() {
for (val patch : patches) {
if (Loader.isModLoaded(patch.modid)) {
try {
if (patch.preInit()) {
EndlessIDs.LOG.info("Applied preInit patches for " + patch.modid);
}
} catch (Exception e) {
EndlessIDs.LOG.fatal("Failed to apply preInit patches for " + patch.modid, e);
throw e;
}
}
}
}
@SneakyThrows
public final void init() {
for (val patch : patches) {
if (Loader.isModLoaded(patch.modid)) {
try {
if (patch.init()) {
EndlessIDs.LOG.info("Applied init patches for " + patch.modid);
}
} catch (Exception e) {
EndlessIDs.LOG.fatal("Failed to apply init patches for " + patch.modid, e);
throw e;
}
}
}
}
@SneakyThrows
public final void postInit() {
for (val patch : patches) {
if (Loader.isModLoaded(patch.modid)) {
try {
if (patch.postInit()) {
EndlessIDs.LOG.info("Applied postInit patches for " + patch.modid);
}
} catch (Exception e) {
EndlessIDs.LOG.fatal("Failed to apply postInit patches for " + patch.modid, e);
throw e;
}
}
}
}
}
@@ -0,0 +1,23 @@
package com.falsepattern.endlessids.patching;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class Patch {
public final String modid;
@SuppressWarnings("RedundantThrows")
public boolean preInit() throws Exception {
return false;
}
@SuppressWarnings("RedundantThrows")
public boolean init() throws Exception {
return false;
}
@SuppressWarnings("RedundantThrows")
public boolean postInit() throws Exception {
return false;
}
}
@@ -0,0 +1,7 @@
package com.falsepattern.endlessids.patching;
public class ServerManager extends CommonManager {
public ServerManager() {
super();
}
}
@@ -0,0 +1,15 @@
package com.falsepattern.endlessids.patching.patches.common;
import com.falsepattern.endlessids.patching.Patch;
public class Tropicraft extends Patch {
public Tropicraft() {
super("tropicraft");
}
@Override
public boolean init() throws ClassNotFoundException {
Class.forName("net.tropicraft.world.biomes.BiomeGenTropicraft");
return true;
}
}