Search in sources :

Example 1 with ClientboundUpdateAdvancementsPacket

use of net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket in project Denizen-For-Bukkit by DenizenScript.

the class AdvancementHelperImpl method update.

@Override
public void update(Player player) {
    ServerPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    nmsPlayer.connection.send(new ClientboundUpdateAdvancementsPacket(true, Collections.emptySet(), Collections.emptySet(), Collections.emptyMap()));
    PlayerAdvancements data = nmsPlayer.getAdvancements();
    // save progress
    data.save();
    // clear progress
    data.reload(DedicatedServer.getServer().getAdvancements());
    // load progress and update client
    data.flushDirty(nmsPlayer);
}
Also used : ClientboundUpdateAdvancementsPacket(net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket) PlayerAdvancements(net.minecraft.server.PlayerAdvancements) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)

Example 2 with ClientboundUpdateAdvancementsPacket

use of net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket in project Denizen-For-Bukkit by DenizenScript.

the class AdvancementHelperImpl method unregister.

@Override
public void unregister(com.denizenscript.denizen.nms.util.Advancement advancement) {
    if (advancement.temporary || !advancement.registered) {
        return;
    }
    Map<ResourceLocation, Advancement> advancements = getAdvancementDataWorld().advancements.advancements;
    ResourceLocation key = asResourceLocation(advancement.key);
    Advancement nms = advancements.get(key);
    if (advancement.parent == null) {
        Set<Advancement> roots = ReflectionHelper.getFieldValue(AdvancementList.class, ReflectionMappingsInfo.AdvancementList_roots, getAdvancementDataWorld().advancements);
        roots.remove(nms);
    } else {
        Set<Advancement> branches = ReflectionHelper.getFieldValue(AdvancementList.class, ReflectionMappingsInfo.AdvancementList_tasks, getAdvancementDataWorld().advancements);
        branches.remove(nms);
    }
    advancements.remove(key);
    advancement.registered = false;
    ((CraftServer) Bukkit.getServer()).getHandle().sendAll(new ClientboundUpdateAdvancementsPacket(false, Collections.emptySet(), Collections.singleton(key), Collections.emptyMap()), (net.minecraft.world.entity.player.Player) null);
}
Also used : ClientboundUpdateAdvancementsPacket(net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 3 with ClientboundUpdateAdvancementsPacket

use of net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket in project Denizen-For-Bukkit by DenizenScript.

the class AdvancementHelperImpl method grantPartial.

@Override
public void grantPartial(com.denizenscript.denizen.nms.util.Advancement advancement, Player player, int len) {
    if (advancement.length <= 1) {
        grant(advancement, player);
        return;
    }
    if (advancement.temporary) {
        Advancement nmsAdvancement = asNMSCopy(advancement);
        AdvancementProgress progress = new AdvancementProgress();
        Map<String, Criterion> criteria = new HashMap<>();
        String[][] requirements = new String[advancement.length][];
        for (int i = 0; i < advancement.length; i++) {
            criteria.put(IMPOSSIBLE_KEY + i, new Criterion(new ImpossibleTrigger.TriggerInstance()));
            requirements[i] = new String[] { IMPOSSIBLE_KEY + i };
        }
        progress.update(IMPOSSIBLE_CRITERIA, IMPOSSIBLE_REQUIREMENTS);
        for (int i = 0; i < len; i++) {
            // complete impossible criteria
            progress.grantProgress(IMPOSSIBLE_KEY + i);
        }
        PacketHelperImpl.send(player, new ClientboundUpdateAdvancementsPacket(false, Collections.singleton(nmsAdvancement), Collections.emptySet(), Collections.singletonMap(nmsAdvancement.getId(), progress)));
    } else {
        Advancement nmsAdvancement = getAdvancementDataWorld().advancements.advancements.get(asResourceLocation(advancement.key));
        for (int i = 0; i < len; i++) {
            ((CraftPlayer) player).getHandle().getAdvancements().award(nmsAdvancement, IMPOSSIBLE_KEY + i);
        }
    }
}
Also used : ClientboundUpdateAdvancementsPacket(net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket) HashMap(java.util.HashMap) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)

Example 4 with ClientboundUpdateAdvancementsPacket

use of net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket in project Denizen-For-Bukkit by DenizenScript.

the class AdvancementHelperImpl method unregister.

@Override
public void unregister(com.denizenscript.denizen.nms.util.Advancement advancement) {
    if (advancement.temporary || !advancement.registered) {
        return;
    }
    Map<ResourceLocation, Advancement> advancements = getAdvancementDataWorld().advancements.advancements;
    ResourceLocation key = asResourceLocation(advancement.key);
    Advancement nms = advancements.get(key);
    if (advancement.parent == null) {
        Set<Advancement> roots = ReflectionHelper.getFieldValue(AdvancementList.class, ReflectionMappingsInfo.AdvancementList_roots, getAdvancementDataWorld().advancements);
        roots.remove(nms);
    } else {
        Set<Advancement> branches = ReflectionHelper.getFieldValue(AdvancementList.class, ReflectionMappingsInfo.AdvancementList_tasks, getAdvancementDataWorld().advancements);
        branches.remove(nms);
    }
    advancements.remove(key);
    advancement.registered = false;
    ((CraftServer) Bukkit.getServer()).getHandle().broadcastAll(new ClientboundUpdateAdvancementsPacket(false, Collections.emptySet(), Collections.singleton(key), Collections.emptyMap()), (net.minecraft.world.entity.player.Player) null);
}
Also used : ClientboundUpdateAdvancementsPacket(net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 5 with ClientboundUpdateAdvancementsPacket

use of net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket in project Denizen-For-Bukkit by DenizenScript.

the class AdvancementHelperImpl method grant.

@Override
public void grant(com.denizenscript.denizen.nms.util.Advancement advancement, Player player) {
    if (advancement.length > 1) {
        grantPartial(advancement, player, advancement.length);
        return;
    }
    if (advancement.temporary) {
        Advancement nmsAdvancement = asNMSCopy(advancement);
        AdvancementProgress progress = new AdvancementProgress();
        progress.update(IMPOSSIBLE_CRITERIA, IMPOSSIBLE_REQUIREMENTS);
        // complete impossible criteria
        progress.grantProgress(IMPOSSIBLE_KEY);
        PacketHelperImpl.send(player, new ClientboundUpdateAdvancementsPacket(false, Collections.singleton(nmsAdvancement), Collections.emptySet(), Collections.singletonMap(nmsAdvancement.getId(), progress)));
    } else {
        Advancement nmsAdvancement = getAdvancementDataWorld().advancements.advancements.get(asResourceLocation(advancement.key));
        ((CraftPlayer) player).getHandle().getAdvancements().award(nmsAdvancement, IMPOSSIBLE_KEY);
    }
}
Also used : ClientboundUpdateAdvancementsPacket(net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)

Aggregations

ClientboundUpdateAdvancementsPacket (net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket)12 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)4 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)4 HashMap (java.util.HashMap)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 PlayerAdvancements (net.minecraft.server.PlayerAdvancements)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2