bind tracker to server instead of static instance
This commit is contained in:
parent
9058aa58fe
commit
53983ae5c7
@ -256,7 +256,7 @@ public class Claim implements IPermissionContainer {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
return false;
|
||||
}
|
||||
if(ConfigHandler.config.offlineProtectActivation != -1 && (LogoutTracker.getInstance().justLoggedOut(this.getOwner()) || this.getOwnerPlayer().isPresent())) {
|
||||
if(ConfigHandler.config.offlineProtectActivation != -1 && (LogoutTracker.getInstance(this.world.getServer()).justLoggedOut(this.getOwner()) || this.getOwnerPlayer().isPresent())) {
|
||||
return global == Config.GlobalType.NONE || global.getValue();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public class PlayerEvents {
|
||||
}
|
||||
|
||||
public static void onLogout(PlayerEntity player) {
|
||||
LogoutTracker.getInstance().track(player.getUuid());
|
||||
if(player.getServer() != null)
|
||||
LogoutTracker.getInstance(player.getServer()).track(player.getUuid());
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.LightningEntity;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@ -94,7 +95,7 @@ public class WorldEvents {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void serverTick() {
|
||||
LogoutTracker.getInstance().tick();
|
||||
public static void serverTick(MinecraftServer server) {
|
||||
LogoutTracker.getInstance(server).tick();
|
||||
}
|
||||
}
|
||||
|
@ -18,36 +18,36 @@ import java.util.UUID;
|
||||
public abstract class ItemEntityMixin implements IOwnedItem {
|
||||
|
||||
@Unique
|
||||
private UUID playerOrigin;
|
||||
private UUID flanPlayerOrigin;
|
||||
@Unique
|
||||
private UUID deathPlayerOrigin;
|
||||
private UUID flanDeathPlayerOrigin;
|
||||
|
||||
@Inject(method = "readCustomDataFromTag", at = @At("RETURN"))
|
||||
private void readData(CompoundTag tag, CallbackInfo info) {
|
||||
if (tag.contains("Flan:PlayerOrigin"))
|
||||
this.playerOrigin = tag.getUuid("Flan:PlayerOrigin");
|
||||
this.flanPlayerOrigin = tag.getUuid("Flan:PlayerOrigin");
|
||||
}
|
||||
|
||||
@Inject(method = "writeCustomDataToTag", at = @At("RETURN"))
|
||||
private void writeData(CompoundTag tag, CallbackInfo info) {
|
||||
if (this.playerOrigin != null)
|
||||
tag.putUuid("Flan:PlayerOrigin", this.playerOrigin);
|
||||
if (this.flanPlayerOrigin != null)
|
||||
tag.putUuid("Flan:PlayerOrigin", this.flanPlayerOrigin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOriginPlayer(PlayerEntity player) {
|
||||
this.playerOrigin = player.getUuid();
|
||||
this.flanPlayerOrigin = player.getUuid();
|
||||
if (player instanceof ServerPlayerEntity && PlayerClaimData.get((ServerPlayerEntity) player).setDeathItemOwner())
|
||||
this.deathPlayerOrigin = this.playerOrigin;
|
||||
this.flanDeathPlayerOrigin = this.flanPlayerOrigin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getDeathPlayer() {
|
||||
return this.deathPlayerOrigin;
|
||||
return this.flanDeathPlayerOrigin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getPlayerOrigin() {
|
||||
return this.playerOrigin;
|
||||
return this.flanPlayerOrigin;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.player.LogoutImpl;
|
||||
import io.github.flemmli97.flan.player.LogoutTracker;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public abstract class MinecraftServerMixin implements LogoutImpl {
|
||||
|
||||
@Unique
|
||||
private final LogoutTracker flanLogout = new LogoutTracker();
|
||||
|
||||
@Override
|
||||
public LogoutTracker getInstance() {
|
||||
return this.flanLogout;
|
||||
}
|
||||
}
|
@ -16,17 +16,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public abstract class PlayerClaimMixin implements IPlayerClaimImpl {
|
||||
|
||||
@Unique
|
||||
private PlayerClaimData claimData;
|
||||
private PlayerClaimData flanClaimData;
|
||||
|
||||
@Unique
|
||||
private Claim currentClaim;
|
||||
private Claim flanCurrentClaim;
|
||||
|
||||
@Shadow
|
||||
private MinecraftServer server;
|
||||
|
||||
@Inject(method = "<init>*", at = @At("RETURN"))
|
||||
private void initData(CallbackInfo info) {
|
||||
this.claimData = new PlayerClaimData((ServerPlayerEntity) (Object) this);
|
||||
this.flanClaimData = new PlayerClaimData((ServerPlayerEntity) (Object) this);
|
||||
}
|
||||
|
||||
/*@Inject(method = "readCustomDataFromTag", at = @At("RETURN"))
|
||||
@ -41,21 +41,21 @@ public abstract class PlayerClaimMixin implements IPlayerClaimImpl {
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"))
|
||||
private void tickData(CallbackInfo info) {
|
||||
this.claimData.tick(this.currentClaim, claim -> this.currentClaim = claim);
|
||||
this.flanClaimData.tick(this.flanCurrentClaim, claim -> this.flanCurrentClaim = claim);
|
||||
}
|
||||
|
||||
@Inject(method = "copyFrom", at = @At("RETURN"))
|
||||
private void copyOld(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
|
||||
this.claimData.clone(PlayerClaimData.get(oldPlayer));
|
||||
this.flanClaimData.clone(PlayerClaimData.get(oldPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerClaimData get() {
|
||||
return this.claimData;
|
||||
return this.flanClaimData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Claim getCurrentClaim() {
|
||||
return this.currentClaim;
|
||||
return this.flanCurrentClaim;
|
||||
}
|
||||
}
|
||||
|
@ -12,22 +12,22 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(ServerWorld.class)
|
||||
public abstract class ServerWorldMixin implements IClaimStorage {
|
||||
@Unique
|
||||
private ClaimStorage claimData;
|
||||
private ClaimStorage flanClaimData;
|
||||
|
||||
@Inject(method = "<init>*", at = @At("RETURN"))
|
||||
private void initData(CallbackInfo info) {
|
||||
ServerWorld world = ((ServerWorld) (Object) this);
|
||||
this.claimData = new ClaimStorage(world.getServer(), world);
|
||||
this.flanClaimData = new ClaimStorage(world.getServer(), world);
|
||||
}
|
||||
|
||||
@Inject(method = "saveLevel()V", at = @At("RETURN"))
|
||||
private void saveClaimData(CallbackInfo info) {
|
||||
ServerWorld world = ((ServerWorld) (Object) this);
|
||||
this.claimData.save(world.getServer(), world.getRegistryKey());
|
||||
this.flanClaimData.save(world.getServer(), world.getRegistryKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClaimStorage get() {
|
||||
return this.claimData;
|
||||
return this.flanClaimData;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package io.github.flemmli97.flan.player;
|
||||
|
||||
public interface LogoutImpl {
|
||||
|
||||
LogoutTracker getInstance();
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package io.github.flemmli97.flan.player;
|
||||
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@ -9,13 +10,11 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class LogoutTracker {
|
||||
|
||||
private static final LogoutTracker INSTANCE = new LogoutTracker();
|
||||
|
||||
private final Set<LogoutTicket> tracker = new HashSet<>();
|
||||
private final Set<UUID> trackerUUID = new HashSet<>();
|
||||
|
||||
public static LogoutTracker getInstance() {
|
||||
return INSTANCE;
|
||||
public static LogoutTracker getInstance(MinecraftServer server) {
|
||||
return ((LogoutImpl)server).getInstance();
|
||||
}
|
||||
|
||||
public void track(UUID player) {
|
||||
|
@ -23,7 +23,8 @@
|
||||
"IHungerAccessor",
|
||||
"FrostWalkerMixin",
|
||||
"LightningFireEntityMixin",
|
||||
"BannedEntryAccessor"
|
||||
"BannedEntryAccessor",
|
||||
"MinecraftServerMixin"
|
||||
],
|
||||
"server": [
|
||||
],
|
||||
|
@ -36,7 +36,7 @@ public class FlanFabric implements ModInitializer {
|
||||
UseItemCallback.EVENT.register(ItemInteractEvents::useItem);
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(FlanFabric::serverLoad);
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(FlanFabric::serverFinishLoad);
|
||||
ServerTickEvents.START_SERVER_TICK.register(server->WorldEvents.serverTick());
|
||||
ServerTickEvents.START_SERVER_TICK.register(WorldEvents::serverTick);
|
||||
ServerPlayConnectionEvents.DISCONNECT.register((handler,server)->PlayerEvents.onLogout(handler.player));
|
||||
CommandRegistrationCallback.EVENT.register(CommandClaim::register);
|
||||
|
||||
|
@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(LightningEntity.class)
|
||||
public class LightningHitMixin {
|
||||
public abstract class LightningHitMixin {
|
||||
|
||||
@ModifyVariable(method = "tick", at = @At(value = "INVOKE", target = "Ljava/util/List;iterator()Ljava/util/Iterator;"), require = 1)
|
||||
private List<Entity> affectedEntities(List<Entity> list) {
|
||||
|
@ -7,6 +7,7 @@ import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.event.PlayerEvents;
|
||||
import io.github.flemmli97.flan.player.LogoutTracker;
|
||||
import io.github.flemmli97.flan.player.PlayerDataHandler;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
@ -41,8 +42,8 @@ public class ServerEvents {
|
||||
PlayerEvents.onLogout(event.getPlayer());
|
||||
}
|
||||
|
||||
public static void serverTick(TickEvent.ServerTickEvent event) {
|
||||
if(event.phase == TickEvent.Phase.START)
|
||||
LogoutTracker.getInstance().tick();
|
||||
public static void serverTick(TickEvent.WorldTickEvent event) {
|
||||
if(event.phase == TickEvent.Phase.START && event.world.getServer() != null && event.world.getRegistryKey() == World.OVERWORLD)
|
||||
LogoutTracker.getInstance(event.world.getServer()).tick();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user