Skip to content

Commit

Permalink
Remove obsolete overhead in fake player init.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnuecke committed Jan 15, 2022
1 parent 8a3add0 commit 5d54c63
Showing 1 changed file with 1 addition and 30 deletions.
31 changes: 1 addition & 30 deletions src/main/java/li/cil/oc2/common/util/FakePlayerUtils.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
package li.cil.oc2.common.util;

import com.mojang.authlib.GameProfile;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import li.cil.oc2.api.API;
import li.cil.oc2.common.Config;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;

import javax.annotation.Nullable;

public final class FakePlayerUtils {
private static final String FAKE_PLAYER_NAME = "[" + API.MOD_ID + "]";

Expand All @@ -33,26 +24,6 @@ public static ServerPlayer getFakePlayer(final ServerLevel level, final Entity e
}

public static ServerPlayer getFakePlayer(final ServerLevel level) {
final FakePlayer player = FakePlayerFactory.get(level, new GameProfile(Config.fakePlayerUUID, FAKE_PLAYER_NAME));

// We need to give our fake player a fake network handler because some events we want
// to use the fake player with will unconditionally access this field.
if (player.connection == null) {
player.connection = new FakeServerPlayNetHandler(player);
}

return player;
}

///////////////////////////////////////////////////////////////////

private static class FakeServerPlayNetHandler extends ServerGamePacketListenerImpl {
public FakeServerPlayNetHandler(final FakePlayer fakePlayer) {
super(fakePlayer.server, new Connection(PacketFlow.CLIENTBOUND), fakePlayer);
}

@Override
public void send(final Packet<?> packetIn, @Nullable final GenericFutureListener<? extends Future<? super Void>> futureListeners) {
}
return FakePlayerFactory.get(level, new GameProfile(Config.fakePlayerUUID, FAKE_PLAYER_NAME));
}
}

0 comments on commit 5d54c63

Please sign in to comment.