Backport 1.20 changes and improvements
This commit is contained in:
parent
e4b59167f6
commit
15bca9670b
87 changed files with 10114 additions and 587 deletions
|
@ -3,32 +3,39 @@ package dev.zontreck.libzontreck;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||
import dev.zontreck.eventsbus.Bus;
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUIRegistry;
|
||||
import dev.zontreck.libzontreck.config.ServerConfig;
|
||||
import dev.zontreck.libzontreck.currency.Bank;
|
||||
import dev.zontreck.libzontreck.currency.CurrencyHelper;
|
||||
import dev.zontreck.libzontreck.events.BlockRestoreQueueRegistrationEvent;
|
||||
import dev.zontreck.libzontreck.items.ModItems;
|
||||
import dev.zontreck.libzontreck.memory.world.BlockRestoreQueue;
|
||||
import dev.zontreck.libzontreck.memory.world.BlockRestoreQueueRegistry;
|
||||
import dev.zontreck.libzontreck.memory.world.DatabaseMigrations;
|
||||
import dev.zontreck.libzontreck.memory.world.DatabaseWrapper;
|
||||
import dev.zontreck.libzontreck.menus.ChestGUIScreen;
|
||||
import dev.zontreck.libzontreck.types.ModMenuTypes;
|
||||
import dev.zontreck.libzontreck.networking.NetworkEvents;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
|
||||
import dev.zontreck.libzontreck.commands.Commands;
|
||||
import dev.zontreck.libzontreck.events.ForgeEventHandlers;
|
||||
import dev.zontreck.libzontreck.memory.VolatilePlayerStorage;
|
||||
import dev.zontreck.libzontreck.memory.player.VolatilePlayerStorage;
|
||||
import dev.zontreck.libzontreck.networking.ModMessages;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.util.FileTreeDatastore;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||
import net.minecraftforge.event.server.ServerStoppingEvent;
|
||||
|
@ -45,7 +52,6 @@ public class LibZontreck {
|
|||
public static final Logger LOGGER = LogUtils.getLogger();
|
||||
public static final String MOD_ID = "libzontreck";
|
||||
public static final Map<String, Profile> PROFILES;
|
||||
public static MinecraftServer THE_SERVER;
|
||||
public static VolatilePlayerStorage playerStorage;
|
||||
public static boolean ALIVE=true;
|
||||
public static final String FILESTORE = FileTreeDatastore.get();
|
||||
|
@ -55,6 +61,7 @@ public class LibZontreck {
|
|||
public static final UUID NULL_ID;
|
||||
|
||||
public static boolean LIBZONTRECK_SERVER_AVAILABLE=false;
|
||||
public static ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||
|
||||
|
||||
public static LogicalSide CURRENT_SIDE;
|
||||
|
@ -81,6 +88,8 @@ public class LibZontreck {
|
|||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
// Register the setup method for modloading
|
||||
bus.addListener(this::setup);
|
||||
|
||||
ServerConfig.init();
|
||||
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
@ -89,14 +98,14 @@ public class LibZontreck {
|
|||
MinecraftForge.EVENT_BUS.register(new NetworkEvents());
|
||||
MinecraftForge.EVENT_BUS.register(ChestGUIRegistry.class);
|
||||
|
||||
Bus.Reset();
|
||||
|
||||
ModMenuTypes.REGISTRY.register(bus);
|
||||
//CreativeModeTabs.register(bus);
|
||||
ModItems.register(bus);
|
||||
|
||||
Bus.Register(CurrencyHelper.class, null);
|
||||
Bus.Register(Bank.class, null);
|
||||
MinecraftForge.EVENT_BUS.register(CurrencyHelper.class);
|
||||
MinecraftForge.EVENT_BUS.register(Bank.class);
|
||||
|
||||
}
|
||||
|
||||
private void setup(final FMLCommonSetupEvent event)
|
||||
|
@ -108,16 +117,39 @@ public class LibZontreck {
|
|||
@SubscribeEvent
|
||||
public void onServerStarted(final ServerStartedEvent event)
|
||||
{
|
||||
THE_SERVER = event.getServer();
|
||||
ALIVE=true;
|
||||
|
||||
ServerConfig.init();
|
||||
try {
|
||||
DatabaseWrapper.start();
|
||||
}catch(RuntimeException e) {
|
||||
LOGGER.warn("Database not configured properly, it will not be available.");
|
||||
DatabaseWrapper.invalidate();
|
||||
}
|
||||
|
||||
CURRENT_SIDE = LogicalSide.SERVER;
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new BlockRestoreQueueRegistrationEvent());
|
||||
|
||||
for(ServerLevel level : event.getServer().getAllLevels())
|
||||
{
|
||||
// Queues have been registered, but we now need to initialize the queue's data from saveddata
|
||||
BlockRestoreQueueRegistry.init(level);
|
||||
}
|
||||
|
||||
if(!DatabaseWrapper.hasDB)return;
|
||||
|
||||
try {
|
||||
DatabaseMigrations.initMigrations();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onServerStopping(final ServerStoppingEvent ev)
|
||||
{
|
||||
ALIVE=false;
|
||||
DelayedExecutorService.stop();
|
||||
|
||||
Iterator<Profile> iProfile = PROFILES.values().iterator();
|
||||
while(iProfile.hasNext())
|
||||
|
|
Reference in a new issue