Fix async execution native sync advancements;

feat/data-edit-commands
HarvelsX 3 years ago
parent 81f1cf7642
commit ba4e0ec9b8
No known key found for this signature in database
GPG Key ID: 9637BCFE856BB8F3

@ -163,21 +163,21 @@ public class PlayerSetter {
ArrayList<DataSerializer.AdvancementRecord> advancementRecords ArrayList<DataSerializer.AdvancementRecord> advancementRecords
= DataSerializer.deserializeAdvancementData(data.getSerializedAdvancements()); = DataSerializer.deserializeAdvancementData(data.getSerializedAdvancements());
if (Settings.useNativeImplementation) { if (Settings.useNativeImplementation)
try { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
nativeSyncPlayerAdvancements(player, advancementRecords); try {
} catch (Exception e) { nativeSyncPlayerAdvancements(player, advancementRecords);
plugin.getLogger().log(Level.WARNING, } catch (Exception e) {
"Your server does not support a native implementation of achievements synchronization"); plugin.getLogger().log(Level.WARNING,
plugin.getLogger().log(Level.WARNING, "Your server does not support a native implementation of achievements synchronization");
"Your server version {0}. Please disable using native implementation!", Bukkit.getVersion()); plugin.getLogger().log(Level.WARNING,
"Your server version {0}. Please disable using native implementation!", Bukkit.getVersion());
Settings.useNativeImplementation = false;
setPlayerAdvancements(player, advancementRecords, data); Settings.useNativeImplementation = false;
plugin.getLogger().fine(e.toString()); setPlayerAdvancements(player, advancementRecords, data);
e.printStackTrace(); plugin.getLogger().fine(e.toString());
} }
} });
else setPlayerAdvancements(player, advancementRecords, data); else setPlayerAdvancements(player, advancementRecords, data);
} }
if (Settings.syncInventories) { if (Settings.syncInventories) {
@ -316,6 +316,7 @@ public class PlayerSetter {
AdvancementUtils.startProgress(playerAdvancements, advancement, nativeAdvancementProgress); AdvancementUtils.startProgress(playerAdvancements, advancement, nativeAdvancementProgress);
}); });
AdvancementUtils.markPlayerAdvancementsFirst(playerAdvancements);
AdvancementUtils.ensureAllVisible(playerAdvancements); AdvancementUtils.ensureAllVisible(playerAdvancements);
} }

@ -16,6 +16,7 @@ public class AdvancementUtils {
private final static Field PLAYER_ADVANCEMENTS; private final static Field PLAYER_ADVANCEMENTS;
private final static Field CRITERIA_MAP; private final static Field CRITERIA_MAP;
private final static Field CRITERIA_DATE; private final static Field CRITERIA_DATE;
private final static Field IS_FIRST_PACKET;
private final static Method GET_HANDLE; private final static Method GET_HANDLE;
private final static Method START_PROGRESS; private final static Method START_PROGRESS;
@ -51,6 +52,17 @@ public class AdvancementUtils {
ENSURE_ALL_VISIBLE = ThrowSupplier.get(() -> PLAYER_ADVANCEMENTS.getDeclaredMethod("c")); ENSURE_ALL_VISIBLE = ThrowSupplier.get(() -> PLAYER_ADVANCEMENTS.getDeclaredMethod("c"));
ENSURE_ALL_VISIBLE.setAccessible(true); ENSURE_ALL_VISIBLE.setAccessible(true);
IS_FIRST_PACKET = ThrowSupplier.get(() -> PLAYER_ADVANCEMENTS.getDeclaredField("n"));
IS_FIRST_PACKET.setAccessible(true);
}
public static void markPlayerAdvancementsFirst(Object playerAdvancements) {
try {
IS_FIRST_PACKET.set(playerAdvancements, true);
} catch (IllegalAccessException e) {
throw new RuntimeException(e.getMessage(), e);
}
} }
public static Object getPlayerAdvancements (Player player) { public static Object getPlayerAdvancements (Player player) {

Loading…
Cancel
Save