|
19 | 19 | import de.minebench.syncinv.messenger.RedisMessenger; |
20 | 20 | import de.minebench.syncinv.messenger.ServerMessenger; |
21 | 21 | import lombok.Getter; |
| 22 | +import org.apache.maven.artifact.versioning.ComparableVersion; |
22 | 23 | import org.bukkit.ChatColor; |
23 | 24 | import org.bukkit.GameRule; |
24 | | -import org.bukkit.Location; |
25 | 25 | import org.bukkit.Material; |
26 | 26 | import org.bukkit.OfflinePlayer; |
27 | 27 | import org.bukkit.Sound; |
28 | 28 | import org.bukkit.Statistic; |
29 | 29 | import org.bukkit.World; |
30 | | -import org.bukkit.WorldCreator; |
31 | | -import org.bukkit.WorldType; |
32 | 30 | import org.bukkit.advancement.Advancement; |
33 | 31 | import org.bukkit.advancement.AdvancementProgress; |
34 | 32 | import org.bukkit.command.Command; |
@@ -169,11 +167,6 @@ public final class SyncInv extends JavaPlugin { |
169 | 167 | // Unknown player storing |
170 | 168 | private Function<GameProfile, OfflinePlayer> getOfflinePlayer = null; |
171 | 169 | 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; |
177 | 170 |
|
178 | 171 | // Offline player health setting |
179 | 172 | private Method methodSetHealth; |
@@ -271,6 +264,14 @@ public void onEnable() { |
271 | 264 | getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); |
272 | 265 | getCommand("syncinv").setExecutor(this); |
273 | 266 | 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 | + |
274 | 275 | OpenInvCommand openInvCommand = (OpenInvCommand) openInv.getCommand("openinv").getExecutor(); |
275 | 276 | CommandExecutor forwarding = (sender, command, label, args) -> { |
276 | 277 | if (sender instanceof Player && args.length > 0 && (!getMessenger().isAllowedToBeAlone() || !getMessenger().isAlone())) { |
@@ -451,22 +452,6 @@ && getConfig().contains("sync-" + syncType.getKey(), true)) { |
451 | 452 | disableSync(SyncType.MAPS); |
452 | 453 | } |
453 | 454 | } |
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 | | - } |
470 | 455 | } |
471 | 456 |
|
472 | 457 | public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { |
@@ -647,49 +632,6 @@ public void applyData(PlayerData data, Runnable finished) { |
647 | 632 | player = getOpenInv().loadPlayer(offlinePlayer); |
648 | 633 | if (player == null) { |
649 | 634 | 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 | | - } |
693 | 635 | } |
694 | 636 | } else if (!getOpenInv().disableSaving() && getOpenInv().isPlayerLoaded(player.getUniqueId())) { |
695 | 637 | Player openInvLoadedPlayer = getOpenInv().loadPlayer(player); |
|
0 commit comments