fix: basic functionality are now working.
This commit is contained in:
10 files changed
+32
-13
No files matched your search
@@ -6,6 +6,6 @@ public interface Lifecycle {
|
||||
void onStateChange(State state);
|
||||
|
||||
enum State {
|
||||
ENABLED, DISABLED,ERROR;
|
||||
ENABLED, DISABLED,ERROR
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,9 @@ package io.ib67.sfcraft;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.inject.*;
|
||||
import io.ib67.sfcraft.module.chat.ChatPingModule;
|
||||
import io.ib67.sfcraft.module.chat.ChatSendLocModule;
|
||||
import io.ib67.sfcraft.module.randomevt.LongNightModule;
|
||||
import io.ib67.sfcraft.registry.chat.SimpleMessageDecorator;
|
||||
import io.ib67.sfcraft.registry.event.SFRandomEventRegistry;
|
||||
import io.ib67.sfcraft.init.GuiceModInitializer;
|
||||
@@ -43,6 +46,10 @@ public class SFCraftInitializer extends GuiceModInitializer {
|
||||
registerFeature(PlayLimitModule.class);
|
||||
registerFeature(BackModule.class);
|
||||
registerFeature(ManagementModule.class);
|
||||
|
||||
registerFeature(ChatPingModule.class);
|
||||
registerFeature(ChatSendLocModule.class);
|
||||
registerFeature(LongNightModule.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,13 +59,14 @@ public class SFCraftInitializer extends GuiceModInitializer {
|
||||
SFCraft.server = minecraftServer;
|
||||
SFCraft.injector = getInjector();
|
||||
getModuleManager().switchGlobalState(Lifecycle.State.ENABLED);
|
||||
log.info("Load completed! "+getModuleManager().getModules().size()+" modules were loaded.");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Injector onInit() {
|
||||
return Guice.createInjector(
|
||||
this,
|
||||
new SFCraft()
|
||||
new SFCraft(),
|
||||
this
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public abstract class ServerModule extends AbstractModule implements Lifecycle {
|
||||
}
|
||||
this.state = state;
|
||||
} catch (Exception exception) {
|
||||
log.error("An error occurred when " + getName() + " is changing its state into " + state);
|
||||
log.error("An error occurred when " + getName() + " is changing its state into " + state,exception);
|
||||
this.state = State.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class Utility {
|
||||
}
|
||||
|
||||
static <T, A> Optional<A> anyMatch(T[] ts, Function<T, A> function, Predicate<A> failurePredicate) {
|
||||
A r = null;
|
||||
A r;
|
||||
for (T handler : ts) {
|
||||
r = function.apply(handler);
|
||||
if (failurePredicate.test(r)) {
|
||||
|
||||
@@ -27,13 +27,11 @@ import static java.net.http.HttpResponse.BodyHandlers.ofFile;
|
||||
@Singleton
|
||||
public class MaxMindGeoIPService implements Module, GeoIPService {
|
||||
private static final URI GEOIP_DOWNLOAD_URL = URI.create("http://sfclub.cc/GeoLite2-City.mmdb");
|
||||
@Inject
|
||||
@ConfigRoot
|
||||
private Path configRoot;
|
||||
private Path mmdbPath;
|
||||
private final DatabaseReader databaseReader;
|
||||
|
||||
public MaxMindGeoIPService() throws InterruptedException {
|
||||
@Inject
|
||||
public MaxMindGeoIPService(@ConfigRoot Path configRoot) throws InterruptedException {
|
||||
mmdbPath = configRoot.resolve("GeoLite2-City.mmdb");
|
||||
databaseReader = loadData();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.ib67.sfcraft.module.manager.ModuleManager;
|
||||
import io.ib67.sfcraft.module.manager.SimpleModuleManager;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
@@ -20,6 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Log4j2
|
||||
public abstract class GuiceModInitializer extends AbstractModule implements ModInitializer {
|
||||
public static AtomicBoolean initialized = new AtomicBoolean(false);
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
@@ -33,15 +35,20 @@ public abstract class GuiceModInitializer extends AbstractModule implements ModI
|
||||
ServerPlayConnectionEvents.JOIN.register(handler::defend);
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(this::onServerStarted);
|
||||
injector = onInit();
|
||||
}
|
||||
|
||||
private void onServerStarted(MinecraftServer server) {
|
||||
var map = new HashMap<String, ServerModule>();
|
||||
for (Class<? extends ServerModule> registeredFeature : registeredFeatures) {
|
||||
var module = injector.getInstance(registeredFeature);
|
||||
try {
|
||||
module.onInitialize();
|
||||
map.put(module.getName(), module);
|
||||
} catch (Exception e) {
|
||||
log.error("Cannot initialize module " + module.getName(), e);
|
||||
}
|
||||
}
|
||||
moduleManager = new SimpleModuleManager(ImmutableMap.copyOf(map));
|
||||
}
|
||||
|
||||
private void onServerStarted(MinecraftServer server) {
|
||||
onReady(server);
|
||||
initialized.set(true);
|
||||
}
|
||||
@@ -57,5 +64,6 @@ public abstract class GuiceModInitializer extends AbstractModule implements ModI
|
||||
|
||||
protected void registerFeature(Class<? extends ServerModule> featureClass) {
|
||||
binder().bind(featureClass).in(Singleton.class);
|
||||
registeredFeatures.add(featureClass);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
@Mixin(AbstractFurnaceBlock.class)
|
||||
public abstract class AbstractFurnaceBlockMixin extends BlockWithEntity {
|
||||
@@ -32,6 +33,7 @@ public abstract class AbstractFurnaceBlockMixin extends BlockWithEntity {
|
||||
return world.isClient ? null : BlockWithEntity.validateTicker(givenType, expectedType, AbstractFurnaceBlockMixin::tickMultiple);
|
||||
}
|
||||
|
||||
@Unique
|
||||
private static void tickMultiple(World world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity) {
|
||||
AbstractFurnaceBlockEntity.tick(world, pos, state, blockEntity);
|
||||
int i = world.getGameRules().getInt(GameRules.PLAYERS_SLEEPING_PERCENTAGE);
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.network.QueryableServer;
|
||||
import net.minecraft.network.handler.LegacyQueryHandler;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@@ -16,6 +17,7 @@ import java.util.Locale;
|
||||
|
||||
@Mixin(LegacyQueryHandler.class)
|
||||
public class LegacyQueryHandlerMixin {
|
||||
@Unique
|
||||
SocketAddress address;
|
||||
|
||||
@Inject(method = "channelRead", at = @At("HEAD"))
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class SleepManagerMixin {
|
||||
cir.setReturnValue(false);
|
||||
return;
|
||||
}
|
||||
var world = players.get(0).getServerWorld();
|
||||
var world = players.getFirst().getServerWorld();
|
||||
if (world.getTimeOfDay() % 24000 >= 12544) {
|
||||
if(!world.isRaining()){
|
||||
cir.setReturnValue(false);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"client": [
|
||||
],
|
||||
"server": [
|
||||
"server.MinecraftServerMixin",
|
||||
"server.ServerPlayNetworkHandlerMixin",
|
||||
"server.bridge.ServerWorldBridge",
|
||||
"server.SleepManagerMixin",
|
||||
|
||||
Reference in new issue
Block a user