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,7 +163,8 @@ public class PlayerSetter {
ArrayList<DataSerializer.AdvancementRecord> advancementRecords
= DataSerializer.deserializeAdvancementData(data.getSerializedAdvancements());
if (Settings.useNativeImplementation) {
if (Settings.useNativeImplementation)
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
nativeSyncPlayerAdvancements(player, advancementRecords);
} catch (Exception e) {
@ -175,9 +176,8 @@ public class PlayerSetter {
Settings.useNativeImplementation = false;
setPlayerAdvancements(player, advancementRecords, data);
plugin.getLogger().fine(e.toString());
e.printStackTrace();
}
}
});
else setPlayerAdvancements(player, advancementRecords, data);
}
if (Settings.syncInventories) {
@ -316,6 +316,7 @@ public class PlayerSetter {
AdvancementUtils.startProgress(playerAdvancements, advancement, nativeAdvancementProgress);
});
AdvancementUtils.markPlayerAdvancementsFirst(playerAdvancements);
AdvancementUtils.ensureAllVisible(playerAdvancements);
}

@ -16,6 +16,7 @@ public class AdvancementUtils {
private final static Field PLAYER_ADVANCEMENTS;
private final static Field CRITERIA_MAP;
private final static Field CRITERIA_DATE;
private final static Field IS_FIRST_PACKET;
private final static Method GET_HANDLE;
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.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) {

Loading…
Cancel
Save