Skip to content

Commit e0837b6

Browse files
committed
Update compat for Paper 1.21.10 and 1.21.11.
1 parent 034e901 commit e0837b6

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

InvSee++_Platforms/Impl_1_21_11_R7/src/main/java/com/janboerman/invsee/spigot/impl_1_21_11_R7/HybridServerSupport.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import net.minecraft.world.entity.player.Player;
2323
import net.minecraft.world.inventory.PlayerEnderChestContainer;
2424
import net.minecraft.world.item.ItemStack;
25+
import net.minecraft.world.level.Level;
2526
import net.minecraft.world.level.storage.PlayerDataStorage;
2627
import net.minecraft.world.level.storage.TagValueInput;
2728
import net.minecraft.world.level.storage.ValueInput;
@@ -142,4 +143,21 @@ public static Optional<CompoundTag> loadPlayerData(PlayerDataStorage worldNbtSto
142143
}
143144
}
144145

146+
public static void spawnIn(FakeEntityPlayer fakeEntityPlayer, Level world) {
147+
try {
148+
fakeEntityPlayer.spawnIn(world, true/*ignore respawn anchor charge*/); //note: not only sets the ServerLevel, also sets x/y/z coordinates and gamemode.
149+
} catch (NoSuchMethodError e1) {
150+
try {
151+
Method[] methods = FuzzyReflection.getMethodOfType(ServerPlayer.class, void.class, Level.class);
152+
methods[0].invoke(fakeEntityPlayer, world); //on Paper the boolean parameter for respawn anchor charge does not exist.
153+
} catch (ArrayIndexOutOfBoundsException | ReflectiveOperationException e2) {
154+
RuntimeException ex = new RuntimeException("No method known to set the player's location.");
155+
ex.addSuppressed(e1);
156+
ex.addSuppressed(e2);
157+
throw ex;
158+
}
159+
}
160+
}
161+
162+
145163
}

InvSee++_Platforms/Impl_1_21_11_R7/src/main/java/com/janboerman/invsee/spigot/impl_1_21_11_R7/InvseeImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private void loadWorldDataAndGameMode(CraftServer server, FakeEntityPlayer fakeE
318318
level = server.getHandle().getServer().getLevel(levelResourceKey);
319319

320320
if (level != null) {
321-
fakeEntityPlayer.spawnIn(level, true/*ignore respawn anchor charge*/); //note: not only sets the ServerLevel, also sets x/y/z coordinates and gamemode.
321+
HybridServerSupport.spawnIn(fakeEntityPlayer, level);
322322
}
323323
}
324324

InvSee++_Platforms/Impl_1_21_9_R6/src/main/java/com/janboerman/invsee/spigot/impl_1_21_9_R6/HybridServerSupport.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import net.minecraft.world.entity.player.Player;
2323
import net.minecraft.world.inventory.PlayerEnderChestContainer;
2424
import net.minecraft.world.item.ItemStack;
25+
import net.minecraft.world.level.Level;
2526
import net.minecraft.world.level.storage.PlayerDataStorage;
2627
import net.minecraft.world.level.storage.TagValueInput;
2728
import net.minecraft.world.level.storage.ValueInput;
@@ -142,4 +143,20 @@ public static Optional<CompoundTag> loadPlayerData(PlayerDataStorage worldNbtSto
142143
}
143144
}
144145

146+
public static void spawnIn(FakeEntityPlayer fakeEntityPlayer, Level world) {
147+
try {
148+
fakeEntityPlayer.spawnIn(world, true/*ignore respawn anchor charge*/); //note: not only sets the ServerLevel, also sets x/y/z coordinates and gamemode.
149+
} catch (NoSuchMethodError e1) {
150+
try {
151+
Method[] methods = FuzzyReflection.getMethodOfType(ServerPlayer.class, void.class, Level.class);
152+
methods[0].invoke(fakeEntityPlayer, world); //on Paper the boolean parameter for respawn anchor charge does not exist.
153+
} catch (ArrayIndexOutOfBoundsException | ReflectiveOperationException e2) {
154+
RuntimeException ex = new RuntimeException("No method known to set the player's location.");
155+
ex.addSuppressed(e1);
156+
ex.addSuppressed(e2);
157+
throw ex;
158+
}
159+
}
160+
}
161+
145162
}

InvSee++_Platforms/Impl_1_21_9_R6/src/main/java/com/janboerman/invsee/spigot/impl_1_21_9_R6/InvseeImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private void loadWorldDataAndGameMode(CraftServer server, FakeEntityPlayer fakeE
318318
level = server.getHandle().getServer().getLevel(levelResourceKey);
319319

320320
if (level != null) {
321-
fakeEntityPlayer.spawnIn(level, true/*ignore respawn anchor charge*/); //note: not only sets the ServerLevel, also sets x/y/z coordinates and gamemode.
321+
HybridServerSupport.spawnIn(fakeEntityPlayer, level);
322322
}
323323
}
324324

0 commit comments

Comments
 (0)