feat/data-edit-commands
Harvels X 3 years ago
parent efc2c0199b
commit 73edc988be
No known key found for this signature in database
GPG Key ID: 9637BCFE856BB8F3

@ -162,18 +162,20 @@ public class PlayerSetter {
= 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 is {0}. Please disable using native implementation!", Bukkit.getVersion()); plugin.getLogger().log(Level.WARNING,
"Your server version is {0}. Please disable using native implementation!", Bukkit.getVersion());
Settings.useNativeImplementation = false;
setPlayerAdvancements(player, advancementRecords, data); Settings.useNativeImplementation = false;
plugin.getLogger().log(Level.SEVERE, e.getMessage(), e); setPlayerAdvancements(player, advancementRecords, data);
} plugin.getLogger().log(Level.SEVERE, e.getMessage(), e);
}
});
} else { } else {
setPlayerAdvancements(player, advancementRecords, data); setPlayerAdvancements(player, advancementRecords, data);
} }
@ -281,6 +283,7 @@ public class PlayerSetter {
// Clear // Clear
AdvancementUtils.clearPlayerAdvancementsMap(playerAdvancements); AdvancementUtils.clearPlayerAdvancementsMap(playerAdvancements);
AdvancementUtils.clearVisibleAdvancementsSet(playerAdvancements);
advancementRecords.forEach(advancementRecord -> { advancementRecords.forEach(advancementRecord -> {
NamespacedKey namespacedKey = Objects.requireNonNull( NamespacedKey namespacedKey = Objects.requireNonNull(
@ -306,8 +309,10 @@ public class PlayerSetter {
AdvancementUtils.startProgress(playerAdvancements, advancement, nativeAdvancementProgress); AdvancementUtils.startProgress(playerAdvancements, advancement, nativeAdvancementProgress);
} }
}); });
AdvancementUtils.ensureAllVisible(playerAdvancements); // Set all completed advancement is visible synchronized (playerAdvancements) {
AdvancementUtils.markPlayerAdvancementsFirst(playerAdvancements); // Mark the sending of visible advancement as the first AdvancementUtils.ensureAllVisible(playerAdvancements); // Set all completed advancement is visible
AdvancementUtils.markPlayerAdvancementsFirst(playerAdvancements); // Mark the sending of visible advancement as the first
}
} }
/** /**

@ -9,19 +9,20 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set;
public class AdvancementUtils { public class AdvancementUtils {
public final static Class<?> PLAYER_ADVANCEMENT;
private final static Field PLAYER_ADVANCEMENTS_MAP; private final static Field PLAYER_ADVANCEMENTS_MAP;
private final static Field PLAYER_VISIBLE_ADVANCEMENTS_SET;
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 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;
private final static Method ENSURE_ALL_VISIBLE; private final static Method ENSURE_ALL_VISIBLE;
private final static Class<?> ADVANCEMENT_PROGRESS; private final static Class<?> ADVANCEMENT_PROGRESS;
private final static Class<?> CRITERION_PROGRESS; private final static Class<?> CRITERION_PROGRESS;
@ -43,10 +44,13 @@ public class AdvancementUtils {
Class<?> ADVANCEMENT = ThrowSupplier.get(() -> Class.forName("net.minecraft.advancements.Advancement")); Class<?> ADVANCEMENT = ThrowSupplier.get(() -> Class.forName("net.minecraft.advancements.Advancement"));
Class<?> PLAYER_ADVANCEMENT = MinecraftVersionUtils.getMinecraftClass("AdvancementDataPlayer"); PLAYER_ADVANCEMENT = MinecraftVersionUtils.getMinecraftClass("AdvancementDataPlayer");
PLAYER_ADVANCEMENTS_MAP = ThrowSupplier.get(() -> PLAYER_ADVANCEMENT.getDeclaredField("h")); PLAYER_ADVANCEMENTS_MAP = ThrowSupplier.get(() -> PLAYER_ADVANCEMENT.getDeclaredField("h"));
PLAYER_ADVANCEMENTS_MAP.setAccessible(true); PLAYER_ADVANCEMENTS_MAP.setAccessible(true);
PLAYER_VISIBLE_ADVANCEMENTS_SET = ThrowSupplier.get(() -> PLAYER_ADVANCEMENT.getDeclaredField("i"));
PLAYER_VISIBLE_ADVANCEMENTS_SET.setAccessible(true);
START_PROGRESS = ThrowSupplier.get(() -> PLAYER_ADVANCEMENT.getDeclaredMethod("a", ADVANCEMENT, ADVANCEMENT_PROGRESS)); START_PROGRESS = ThrowSupplier.get(() -> PLAYER_ADVANCEMENT.getDeclaredMethod("a", ADVANCEMENT, ADVANCEMENT_PROGRESS));
START_PROGRESS.setAccessible(true); START_PROGRESS.setAccessible(true);
@ -57,7 +61,7 @@ public class AdvancementUtils {
IS_FIRST_PACKET.setAccessible(true); IS_FIRST_PACKET.setAccessible(true);
} }
public static void markPlayerAdvancementsFirst(Object playerAdvancements) { public static void markPlayerAdvancementsFirst(final Object playerAdvancements) {
try { try {
IS_FIRST_PACKET.set(playerAdvancements, true); IS_FIRST_PACKET.set(playerAdvancements, true);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -130,4 +134,12 @@ public class AdvancementUtils {
} }
} }
public static void clearVisibleAdvancementsSet(final Object playerAdvancements) {
try {
((Set<?>) PLAYER_VISIBLE_ADVANCEMENTS_SET.get(playerAdvancements))
.clear();
} catch (IllegalAccessException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
} }

Loading…
Cancel
Save