Skip to content

Commit 876c9d0

Browse files
FireInstallPhoenix616
authored andcommitted
Bump OpenInv dependency up to at least 5.1.7 and therefor minimum Minecraft version to 1.21.1
This in turn lets us drop setting the Location of offline players who never played on the server before. Openinv will safely set them to the spawn location of the server wherever that may be (com.lishid.openinv.internal.common.player.PlayerManager#spawnInDefaultWorld) Note: OpenInv restructured its building process in the very same version. And currently isn't able to publish anything other than it's API automatically to a maven repo. Internally everything we do access directly remains unchanged, so it's fine to keep the compile time version Note: For future reference, a player .dat needs at least one tag, it doesn't need to be valid. However, older minecraft versions will keep junk data. So I opted for the player unused brain system. Any tag without impact will do, really. Adding a DataVersion tag potentially will run the DFU and may print messages in the console but also should be fine to use.
1 parent 2373033 commit 876c9d0

6 files changed

Lines changed: 18 additions & 74 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Provided without any (implied) support nor warranty! (See [GPLv3 license](https:
66
## Requirements
77

88
- At least Java 21
9-
- [Paper](https://papermc.io) Minecraft server software (tested on 1.20.6+, should be the same version on all synced
9+
- [Paper](https://papermc.io) Minecraft server software (tested on 1.21.1+, should be the same version on all synced
1010
servers)
1111
- [redis](https://redis.io) pub-sub
12-
- [OpenInv](https://github.com/jikoo/OpenInv) (optionally, for a more smooth experience)
12+
- [OpenInv 5.1.7+](https://github.com/jikoo/OpenInv) (optionally, for a more smooth experience)
1313

1414
## Setup
1515

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
<dependency>
5151
<groupId>com.lishid</groupId>
5252
<artifactId>openinvplugin</artifactId>
53+
<!--
54+
Note: currently there is a discrepancy between run and compile time version!
55+
Since OpenInv isn't able to publish anything else than it's API to maven, we remain
56+
on 5.1.1 to compile against.
57+
However, runtime dependency has moved on to 5.1.7+!
58+
-->
5359
<version>5.1.1</version>
5460
<scope>provided</scope>
5561
</dependency>

src/main/java/de/minebench/syncinv/SyncInv.java

Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@
1919
import de.minebench.syncinv.messenger.RedisMessenger;
2020
import de.minebench.syncinv.messenger.ServerMessenger;
2121
import lombok.Getter;
22+
import org.apache.maven.artifact.versioning.ComparableVersion;
2223
import org.bukkit.ChatColor;
2324
import org.bukkit.GameRule;
24-
import org.bukkit.Location;
2525
import org.bukkit.Material;
2626
import org.bukkit.OfflinePlayer;
2727
import org.bukkit.Sound;
2828
import org.bukkit.Statistic;
2929
import org.bukkit.World;
30-
import org.bukkit.WorldCreator;
31-
import org.bukkit.WorldType;
3230
import org.bukkit.advancement.Advancement;
3331
import org.bukkit.advancement.AdvancementProgress;
3432
import org.bukkit.command.Command;
@@ -169,11 +167,6 @@ public final class SyncInv extends JavaPlugin {
169167
// Unknown player storing
170168
private Function<GameProfile, OfflinePlayer> getOfflinePlayer = null;
171169
private Method methodGetHandle = null;
172-
private Method methodSetPositionRaw;
173-
private Field fieldYaw = null;
174-
private Field fieldPitch = null;
175-
private Method methodSetYaw = null;
176-
private Method methodSetPitch = null;
177170

178171
// Offline player health setting
179172
private Method methodSetHealth;
@@ -271,6 +264,14 @@ public void onEnable() {
271264
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
272265
getCommand("syncinv").setExecutor(this);
273266
if (openInv != null) {
267+
// ensure minimum OpenInv version is present.
268+
if (storeUnknownPlayers && new ComparableVersion(openInv.getPluginMeta().getVersion()).compareTo(new ComparableVersion("5.1.7")) < 0) {
269+
getLogger().severe(
270+
"Warning: You are using a not supported Version of OpenInv! " +
271+
"Please update to Version 5.1.7 or higher! " +
272+
"With the wrong version version present storing unknown players will fail!");
273+
}
274+
274275
OpenInvCommand openInvCommand = (OpenInvCommand) openInv.getCommand("openinv").getExecutor();
275276
CommandExecutor forwarding = (sender, command, label, args) -> {
276277
if (sender instanceof Player && args.length > 0 && (!getMessenger().isAllowedToBeAlone() || !getMessenger().isAlone())) {
@@ -451,22 +452,6 @@ && getConfig().contains("sync-" + syncType.getKey(), true)) {
451452
disableSync(SyncType.MAPS);
452453
}
453454
}
454-
455-
// Make sure the world "world" exists so that we can store unknown players without issues
456-
if (storeUnknownPlayers && getServer().getWorld("world") == null && getConfig().getBoolean("create-world")) {
457-
getLogger().log(Level.INFO, "No world with the name 'world' exists while 'store-unknown-players' is enabled. This world is needed for that functionality to work correctly, creating it... (can be disabled with 'create-world' in the config)");
458-
World world = getServer().createWorld(new WorldCreator("world")
459-
.type(WorldType.FLAT)
460-
.generateStructures(false));
461-
world.setAutoSave(false);
462-
world.setViewDistance(2);
463-
world.setKeepSpawnInMemory(false);
464-
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
465-
world.setGameRule(GameRule.DO_MOB_SPAWNING, false);
466-
world.setGameRule(GameRule.DO_FIRE_TICK, false);
467-
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
468-
world.setGameRule(GameRule.DISABLE_RAIDS, true);
469-
}
470455
}
471456

472457
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
@@ -647,49 +632,6 @@ public void applyData(PlayerData data, Runnable finished) {
647632
player = getOpenInv().loadPlayer(offlinePlayer);
648633
if (player == null) {
649634
logDebug("Unable to load player " + offlinePlayer.getName() + "/" + offlinePlayer.getUniqueId() + " data with OpenInv");
650-
} else if (createdNewFile) {
651-
try {
652-
if (methodGetHandle == null) {
653-
methodGetHandle = player.getClass().getMethod("getHandle");
654-
}
655-
Object entity = methodGetHandle.invoke(player);
656-
if (methodSetPositionRaw == null || (fieldYaw == null && methodSetYaw == null) || (fieldPitch == null || methodSetPitch == null)) {
657-
try {
658-
// should be the "go-to" since 1.20.5+ for paper
659-
methodSetPositionRaw = entity.getClass().getMethod("setPositionRaw", double.class, double.class, double.class);
660-
} catch (NoSuchMethodException e) {
661-
// TODO: Better obfuscation support <-- use paper's userDev
662-
// 1.18-1.18.2 was "e", would become "o" until 1.19.2 and is now (1.20.6 when not Moj-Mapped) "p"
663-
methodSetPositionRaw = entity.getClass().getMethod("p", double.class, double.class, double.class);
664-
}
665-
try {
666-
fieldYaw = entity.getClass().getField("yaw");
667-
fieldPitch = entity.getClass().getField("pitch");
668-
} catch (NoSuchFieldException e) {
669-
try {
670-
methodSetYaw = entity.getClass().getMethod("setYRot", float.class);
671-
methodSetPitch = entity.getClass().getMethod("setYRot", float.class);
672-
} catch (NoSuchMethodException ignored) {}
673-
}
674-
}
675-
Location spawn = getServer().getWorlds().get(0).getSpawnLocation();
676-
methodSetPositionRaw.invoke(entity, spawn.getX(), spawn.getY(), spawn.getZ());
677-
if (fieldYaw != null) {
678-
fieldYaw.set(entity, spawn.getYaw());
679-
} else if (methodSetYaw != null) {
680-
methodSetYaw.invoke(entity, spawn.getYaw());
681-
}
682-
if (fieldPitch != null) {
683-
fieldPitch.set(entity, spawn.getPitch());
684-
} else if (methodSetPitch != null) {
685-
methodSetPitch.invoke(entity, spawn.getPitch());
686-
}
687-
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
688-
getLogger().log(Level.WARNING, "Error while trying to set location of an unknown player. Disabling unknown player storage it!", e);
689-
storeUnknownPlayers = false;
690-
player = null;
691-
getOpenInv().unload(offlinePlayer);
692-
}
693635
}
694636
} else if (!getOpenInv().disableSaving() && getOpenInv().isPlayerLoaded(player.getUniqueId())) {
695637
Player openInvLoadedPlayer = getOpenInv().loadPlayer(player);

src/main/resources/config.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ sync-with-group-on-logout: true
3838
# breaks first join detection of other plugins
3939
store-unknown-players: true
4040

41-
# Whether to create a missing 'world' world which is required
42-
# for unknown player storage to work
43-
create-world: true
44-
4541
# The amount of seconds we should maximally wait for all servers to
4642
# respond to a query
4743
query-timeout: 15

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: ${project.name}
22
version: '${minecraft.plugin.version}'
3-
api-version: '1.20'
3+
api-version: '1.21.1'
44
main: de.minebench.syncinv.SyncInv
55
softdepend: [OpenInv]
66
authors: [Phoenix616]
13 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)