Remove LP usage in RccServer.java, move to api space along events
This commit is contained in:
parent
2f3b5fcbc2
commit
d5721935de
9 changed files with 17 additions and 24 deletions
|
@ -8,10 +8,9 @@ import cc.reconnected.server.commands.tell.*;
|
||||||
import cc.reconnected.server.commands.warp.*;
|
import cc.reconnected.server.commands.warp.*;
|
||||||
import cc.reconnected.server.core.*;
|
import cc.reconnected.server.core.*;
|
||||||
import cc.reconnected.server.data.StateManager;
|
import cc.reconnected.server.data.StateManager;
|
||||||
import cc.reconnected.server.database.PlayerData;
|
import cc.reconnected.server.api.events.PlayerUsernameChange;
|
||||||
import cc.reconnected.server.events.PlayerUsernameChange;
|
import cc.reconnected.server.api.events.PlayerWelcome;
|
||||||
import cc.reconnected.server.events.PlayerWelcome;
|
import cc.reconnected.server.api.events.Ready;
|
||||||
import cc.reconnected.server.events.Ready;
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
|
@ -23,7 +22,6 @@ import net.luckperms.api.LuckPerms;
|
||||||
import net.luckperms.api.LuckPermsProvider;
|
import net.luckperms.api.LuckPermsProvider;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.WorldSavePath;
|
import net.minecraft.util.WorldSavePath;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -118,9 +116,7 @@ public class RccServer implements ModInitializer {
|
||||||
|
|
||||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
|
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
|
||||||
var player = handler.getPlayer();
|
var player = handler.getPlayer();
|
||||||
|
|
||||||
var playerState = state.getPlayerState(player.getUuid());
|
var playerState = state.getPlayerState(player.getUuid());
|
||||||
var playerData = PlayerData.getPlayer(player.getUuid());
|
|
||||||
|
|
||||||
if (playerState.firstJoinedDate == null) {
|
if (playerState.firstJoinedDate == null) {
|
||||||
LOGGER.info("Player {} joined for the first time!", player.getGameProfile().getName());
|
LOGGER.info("Player {} joined for the first time!", player.getGameProfile().getName());
|
||||||
|
@ -132,14 +128,11 @@ public class RccServer implements ModInitializer {
|
||||||
if (spawnPosition != null) {
|
if (spawnPosition != null) {
|
||||||
spawnPosition.teleport(player, false);
|
spawnPosition.teleport(player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
playerData.setDate(PlayerData.KEYS.firstJoinedDate, new Date());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerState.username != null && !playerState.username.equals(player.getGameProfile().getName())) {
|
if (playerState.username != null && !playerState.username.equals(player.getGameProfile().getName())) {
|
||||||
LOGGER.info("Player {} has changed their username from {}", player.getGameProfile().getName(), playerState.username);
|
LOGGER.info("Player {} has changed their username from {}", player.getGameProfile().getName(), playerState.username);
|
||||||
PlayerUsernameChange.PLAYER_USERNAME_CHANGE.invoker().changeUsername(player, playerState.username);
|
PlayerUsernameChange.PLAYER_USERNAME_CHANGE.invoker().changeUsername(player, playerState.username);
|
||||||
playerData.set(PlayerData.KEYS.username, player.getName().getString());
|
|
||||||
}
|
}
|
||||||
playerState.username = player.getGameProfile().getName();
|
playerState.username = player.getGameProfile().getName();
|
||||||
state.savePlayerState(player.getUuid(), playerState);
|
state.savePlayerState(player.getUuid(), playerState);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package cc.reconnected.server.database;
|
package cc.reconnected.server.api;
|
||||||
|
|
||||||
import cc.reconnected.server.RccServer;
|
import cc.reconnected.server.RccServer;
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
|
@ -16,7 +16,7 @@ import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PlayerData {
|
public class PlayerMeta {
|
||||||
public static final String nodePrefix = "rcc";
|
public static final String nodePrefix = "rcc";
|
||||||
|
|
||||||
private static LuckPerms luckPerms() {
|
private static LuckPerms luckPerms() {
|
||||||
|
@ -43,7 +43,7 @@ public class PlayerData {
|
||||||
private Set<MetaNode> rawNodes;
|
private Set<MetaNode> rawNodes;
|
||||||
private Map<String, String> nodes;
|
private Map<String, String> nodes;
|
||||||
|
|
||||||
private PlayerData(UUID uuid, User lpUser) {
|
private PlayerMeta(UUID uuid, User lpUser) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.lpUser = lpUser;
|
this.lpUser = lpUser;
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ public class PlayerData {
|
||||||
return lpUser.getPrimaryGroup();
|
return lpUser.getPrimaryGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerData getPlayer(UUID uuid) {
|
public static PlayerMeta getPlayer(UUID uuid) {
|
||||||
var lp = luckPerms();
|
var lp = luckPerms();
|
||||||
var userManager = lp.getUserManager();
|
var userManager = lp.getUserManager();
|
||||||
|
|
||||||
|
@ -154,14 +154,14 @@ public class PlayerData {
|
||||||
// TODO: ouch, not good...
|
// TODO: ouch, not good...
|
||||||
var lpUser = userFuture.join();
|
var lpUser = userFuture.join();
|
||||||
|
|
||||||
var playerData = new PlayerData(uuid, lpUser);
|
var playerData = new PlayerMeta(uuid, lpUser);
|
||||||
playerData.name = lpUser.getUsername();
|
playerData.name = lpUser.getUsername();
|
||||||
return playerData;
|
return playerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerData getPlayer(ServerPlayerEntity player) {
|
public static PlayerMeta getPlayer(ServerPlayerEntity player) {
|
||||||
var user = luckPerms().getPlayerAdapter(ServerPlayerEntity.class).getUser(player);
|
var user = luckPerms().getPlayerAdapter(ServerPlayerEntity.class).getUser(player);
|
||||||
var playerData = new PlayerData(player.getUuid(), user);
|
var playerData = new PlayerMeta(player.getUuid(), user);
|
||||||
playerData.name = player.getEntityName();
|
playerData.name = player.getEntityName();
|
||||||
return playerData;
|
return playerData;
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package cc.reconnected.server.events;
|
package cc.reconnected.server.api.events;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.event.Event;
|
import net.fabricmc.fabric.api.event.Event;
|
||||||
import net.fabricmc.fabric.api.event.EventFactory;
|
import net.fabricmc.fabric.api.event.EventFactory;
|
|
@ -1,4 +1,4 @@
|
||||||
package cc.reconnected.server.events;
|
package cc.reconnected.server.api.events;
|
||||||
|
|
||||||
import cc.reconnected.server.struct.ServerPosition;
|
import cc.reconnected.server.struct.ServerPosition;
|
||||||
import net.fabricmc.fabric.api.event.Event;
|
import net.fabricmc.fabric.api.event.Event;
|
|
@ -1,4 +1,4 @@
|
||||||
package cc.reconnected.server.events;
|
package cc.reconnected.server.api.events;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.event.Event;
|
import net.fabricmc.fabric.api.event.Event;
|
||||||
import net.fabricmc.fabric.api.event.EventFactory;
|
import net.fabricmc.fabric.api.event.EventFactory;
|
|
@ -1,4 +1,4 @@
|
||||||
package cc.reconnected.server.events;
|
package cc.reconnected.server.api.events;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.event.Event;
|
import net.fabricmc.fabric.api.event.Event;
|
||||||
import net.fabricmc.fabric.api.event.EventFactory;
|
import net.fabricmc.fabric.api.event.EventFactory;
|
|
@ -1,4 +1,4 @@
|
||||||
package cc.reconnected.server.events;
|
package cc.reconnected.server.api.events;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.event.Event;
|
import net.fabricmc.fabric.api.event.Event;
|
||||||
import net.fabricmc.fabric.api.event.EventFactory;
|
import net.fabricmc.fabric.api.event.EventFactory;
|
|
@ -1,7 +1,7 @@
|
||||||
package cc.reconnected.server.core;
|
package cc.reconnected.server.core;
|
||||||
|
|
||||||
import cc.reconnected.server.RccServer;
|
import cc.reconnected.server.RccServer;
|
||||||
import cc.reconnected.server.events.PlayerActivityEvents;
|
import cc.reconnected.server.api.events.PlayerActivityEvents;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
import net.fabricmc.fabric.api.event.player.*;
|
import net.fabricmc.fabric.api.event.player.*;
|
||||||
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package cc.reconnected.server.core;
|
package cc.reconnected.server.core;
|
||||||
|
|
||||||
import cc.reconnected.server.events.PlayerTeleport;
|
import cc.reconnected.server.api.events.PlayerTeleport;
|
||||||
import cc.reconnected.server.struct.ServerPosition;
|
import cc.reconnected.server.struct.ServerPosition;
|
||||||
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
|
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
|
|
Loading…
Reference in a new issue