The real server side
(not tested)
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
||||
package com.seibel.distanthorizons.common.wrappers.misc;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.world.AbstractDhWorld;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class ServerPlayerWrapper implements IServerPlayerWrapper {
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
private static final ConcurrentMap<ServerPlayer, ServerPlayerWrapper>
|
||||
serverPlayerWrapperMap = new MapMaker().weakKeys().weakValues().makeMap();
|
||||
|
||||
private final ServerPlayer serverPlayer;
|
||||
|
||||
public static ServerPlayerWrapper getWrapper(ServerPlayer serverPlayer)
|
||||
{
|
||||
return serverPlayerWrapperMap.computeIfAbsent(serverPlayer, ServerPlayerWrapper::new);
|
||||
}
|
||||
|
||||
private ServerPlayerWrapper(ServerPlayer serverPlayer) {
|
||||
this.serverPlayer = serverPlayer;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return serverPlayer.getUUID();
|
||||
}
|
||||
|
||||
public IServerLevelWrapper getLevel() {
|
||||
return ServerLevelWrapper.getWrapper(serverPlayer.getLevel());
|
||||
}
|
||||
|
||||
public Object getWrappedMcObject() {
|
||||
return serverPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Wrapped{" + serverPlayer.toString() + "}";
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ dependencies {
|
||||
addModJar(fabricApi.module("fabric-key-binding-api-v1", rootProject.fabric_api_version))
|
||||
addModJar(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version))
|
||||
addModJar(fabricApi.module("fabric-rendering-v1", rootProject.fabric_api_version)) // TODO: Remove this as it is only needed in 1 line (FabricClientProxy)
|
||||
addModJar(fabricApi.module("fabric-networking-api-v1", rootProject.fabric_api_version))
|
||||
addModJar(fabricApi.module("fabric-api-base", rootProject.fabric_api_version))
|
||||
|
||||
// Mod Menu
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.seibel.distanthorizons.fabric;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
||||
@@ -11,6 +12,7 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
@@ -60,7 +62,8 @@ public class FabricServerProxy
|
||||
|
||||
private ClientLevelWrapper getClientLevelWrapper(ClientLevel level) { return ClientLevelWrapper.getWrapper(level); }
|
||||
private ServerLevelWrapper getServerLevelWrapper(ServerLevel level) { return ServerLevelWrapper.getWrapper(level); }
|
||||
|
||||
private ServerPlayerWrapper getServerPlayerWrapper(ServerPlayer player) { return ServerPlayerWrapper.getWrapper(player); }
|
||||
|
||||
/** Registers Fabric Events */
|
||||
public void registerEvents()
|
||||
{
|
||||
@@ -119,5 +122,20 @@ public class FabricServerProxy
|
||||
}
|
||||
});
|
||||
// ServerChunkSaveEvent - Done in MixinChunkMap
|
||||
|
||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) ->
|
||||
{
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverPlayerJoinEvent(getServerPlayerWrapper(handler.player));
|
||||
}
|
||||
});
|
||||
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) ->
|
||||
{
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverPlayerDisconnectEvent(getServerPlayerWrapper(handler.player));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user