mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-18 03:25:35 +00:00
fix: release stale modifier-key player references
This commit is contained in:
1 parent
001d25d0d6
commit
3b10a37bb3
4 files changed
+51
No files matched your search
+25
@@ -4,16 +4,24 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent.Clone;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import codechicken.multipart.ControlKeyModifer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent;
|
||||
|
||||
/**
|
||||
* isControlDown needs a player with a world to pick its branch. On a dedicated server the world is never remote, so
|
||||
@@ -22,6 +30,23 @@ import codechicken.multipart.ControlKeyModifer;
|
||||
*/
|
||||
class ControlKeyModiferFunctionalTest {
|
||||
|
||||
@Test
|
||||
void replacementAndLogoutReleaseOldPlayerReferences() {
|
||||
EntityPlayer original = player();
|
||||
EntityPlayer replacement = FakePlayerFactory.get(
|
||||
(WorldServer) original.worldObj,
|
||||
new GameProfile(UUID.fromString("5f09d0b1-0aa8-4bc2-a362-5dd96d81eb55"), "modifier-test"));
|
||||
record(original, true);
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new Clone(replacement, original, true));
|
||||
assertFalse(ControlKeyModifer.map().containsKey(original));
|
||||
assertTrue(ControlKeyModifer.isControlDown(replacement));
|
||||
|
||||
FMLCommonHandler.instance().bus().post(new PlayerLoggedOutEvent(replacement));
|
||||
assertFalse(ControlKeyModifer.map().containsKey(replacement));
|
||||
assertFalse(ControlKeyModifer.isControlDown(replacement));
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
@AfterEach
|
||||
void clearRecordedPlayers() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraftforge.event.world.ChunkWatchEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
import codechicken.multipart.BlockMultipart;
|
||||
import codechicken.multipart.ControlKeyModifer;
|
||||
import codechicken.multipart.TileCache;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
@@ -26,6 +27,19 @@ public final class MultipartEventHandler$ {
|
||||
|
||||
private MultipartEventHandler$() {}
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerLoggedOut(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
ControlKeyModifer.map().remove(event.player);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerCloned(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
|
||||
Boolean pressed = ControlKeyModifer.map().remove(event.original);
|
||||
if (pressed != null) {
|
||||
ControlKeyModifer.map().put(event.entityPlayer, pressed);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void tileEntityLoad(ChunkDataEvent.Load event) {
|
||||
MultipartSaveLoad.loadTiles(event.getChunk());
|
||||
|
||||
@@ -15,6 +15,16 @@ public final class MultipartEventHandler {
|
||||
|
||||
private MultipartEventHandler() {}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void playerLoggedOut(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
MultipartEventHandler$.MODULE$.playerLoggedOut(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void playerCloned(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
|
||||
MultipartEventHandler$.MODULE$.playerCloned(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public static void tileEntityLoad(ChunkDataEvent.Load event) {
|
||||
MultipartEventHandler$.MODULE$.tileEntityLoad(event);
|
||||
|
||||
+2
@@ -26,6 +26,8 @@ class MultipartEventHandlerCharacterizationTest {
|
||||
|
||||
private static final Set<String> EVENT_METHODS = new TreeSet<>(
|
||||
Arrays.asList(
|
||||
"playerLoggedOut(Lcpw/mods/fml/common/gameevent/PlayerEvent$PlayerLoggedOutEvent;)V",
|
||||
"playerCloned(Lnet/minecraftforge/event/entity/player/PlayerEvent$Clone;)V",
|
||||
"chunkUnWatch(Lnet/minecraftforge/event/world/ChunkWatchEvent$UnWatch;)V",
|
||||
"chunkWatch(Lnet/minecraftforge/event/world/ChunkWatchEvent$Watch;)V",
|
||||
"drawBlockHighlight(Lnet/minecraftforge/client/event/DrawBlockHighlightEvent;)V",
|
||||
|
||||
Reference in new issue
Block a user