Search in sources :

Example 96 with CraftPlayer

use of org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer in project Denizen-For-Bukkit by DenizenScript.

the class Handler method getPlayerProfile.

@Override
public PlayerProfile getPlayerProfile(Player player) {
    GameProfile gameProfile = ((CraftPlayer) player).getProfile();
    Property property = Iterables.getFirst(gameProfile.getProperties().get("textures"), null);
    return new PlayerProfile(gameProfile.getName(), gameProfile.getId(), property != null ? property.getValue() : null, property != null ? property.getSignature() : null);
}
Also used : GameProfile(com.mojang.authlib.GameProfile) PlayerProfile(com.denizenscript.denizen.nms.util.PlayerProfile) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) Property(com.mojang.authlib.properties.Property)

Example 97 with CraftPlayer

use of org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer 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)

Example 98 with CraftPlayer

use of org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer 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_18_R1.entity.CraftPlayer)

Example 99 with CraftPlayer

use of org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer in project Denizen-For-Bukkit by DenizenScript.

the class PlayerHelperImpl method stopSound.

@Override
public void stopSound(Player player, String sound, SoundCategory category) {
    ResourceLocation soundKey = sound == null ? null : new ResourceLocation(sound);
    net.minecraft.sounds.SoundSource nmsCategory = category == null ? null : net.minecraft.sounds.SoundSource.valueOf(category.name());
    ((CraftPlayer) player).getHandle().connection.send(new ClientboundStopSoundPacket(soundKey, nmsCategory));
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)

Example 100 with CraftPlayer

use of org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer in project Denizen-For-Bukkit by DenizenScript.

the class PlayerHelperImpl method sendEntitySpawn.

@Override
public FakeEntity sendEntitySpawn(List<PlayerTag> players, DenizenEntityType entityType, LocationTag location, ArrayList<Mechanism> mechanisms, int customId, UUID customUUID, boolean autoTrack) {
    CraftWorld world = ((CraftWorld) location.getWorld());
    net.minecraft.world.entity.Entity nmsEntity;
    if (entityType.isCustom()) {
        if (entityType.customEntityType == CustomEntityType.ITEM_PROJECTILE) {
            org.bukkit.inventory.ItemStack itemStack = new ItemStack(Material.STONE);
            for (Mechanism mechanism : mechanisms) {
                if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
                    itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
                }
            }
            nmsEntity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
        } else if (entityType.customEntityType == CustomEntityType.FAKE_PLAYER) {
            String name = null;
            String skin = null;
            for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
                if (mechanism.matches("name")) {
                    name = mechanism.getValue().asString();
                    mechanisms.remove(mechanism);
                } else if (mechanism.matches("skin")) {
                    skin = mechanism.getValue().asString();
                    mechanisms.remove(mechanism);
                }
                if (name != null && skin != null) {
                    break;
                }
            }
            nmsEntity = ((CraftFakePlayerImpl) CustomEntityHelperImpl.spawnFakePlayer(location, name, skin, false)).getHandle();
        } else {
            throw new IllegalArgumentException("entityType");
        }
    } else {
        nmsEntity = world.createEntity(location, entityType.getBukkitEntityType().getEntityClass());
    }
    if (customUUID != null) {
        nmsEntity.setId(customId);
        nmsEntity.setUUID(customUUID);
    }
    EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
    entity.isFake = true;
    entity.isFakeValid = true;
    for (Mechanism mechanism : mechanisms) {
        entity.safeAdjustDuplicate(mechanism);
    }
    nmsEntity.unsetRemoved();
    FakeEntity fake = new FakeEntity(players, location, entity.getBukkitEntity().getEntityId());
    fake.entity = new EntityTag(entity.getBukkitEntity());
    fake.entity.isFake = true;
    fake.entity.isFakeValid = true;
    List<TrackerData> trackers = new ArrayList<>();
    fake.triggerSpawnPacket = (player) -> {
        ServerPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
        ServerGamePacketListenerImpl conn = nmsPlayer.connection;
        final ServerEntity tracker = new ServerEntity(world.getHandle(), nmsEntity, 1, true, conn::send, Collections.singleton(nmsPlayer.connection));
        tracker.addPairing(nmsPlayer);
        final TrackerData data = new TrackerData();
        data.player = player;
        data.tracker = tracker;
        trackers.add(data);
        if (autoTrack) {
            new BukkitRunnable() {

                boolean wasOnline = true;

                @Override
                public void run() {
                    if (!fake.entity.isFakeValid) {
                        cancel();
                        return;
                    }
                    if (player.isOnline()) {
                        if (!wasOnline) {
                            tracker.addPairing(((CraftPlayer) player.getPlayerEntity()).getHandle());
                            wasOnline = true;
                        }
                        tracker.sendChanges();
                    } else if (wasOnline) {
                        wasOnline = false;
                    }
                }
            }.runTaskTimer(Denizen.getInstance(), 1, 1);
        }
    };
    for (PlayerTag player : players) {
        fake.triggerSpawnPacket.accept(player);
    }
    fake.triggerUpdatePacket = () -> {
        for (TrackerData tracker : trackers) {
            if (tracker.player.isOnline()) {
                tracker.tracker.sendChanges();
            }
        }
    };
    fake.triggerDestroyPacket = () -> {
        for (TrackerData tracker : trackers) {
            if (tracker.player.isOnline()) {
                tracker.tracker.removePairing(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
            }
        }
        trackers.clear();
    };
    return fake;
}
Also used : FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) EntityItemProjectileImpl(com.denizenscript.denizen.nms.v1_18.impl.entities.EntityItemProjectileImpl) CraftFakePlayerImpl(com.denizenscript.denizen.nms.v1_18.impl.entities.CraftFakePlayerImpl) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) Mechanism(com.denizenscript.denizencore.objects.Mechanism) ServerEntity(net.minecraft.server.level.ServerEntity) EntityTag(com.denizenscript.denizen.objects.EntityTag) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Aggregations

Player (org.bukkit.entity.Player)83 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)36 CraftPlayer (org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer)27 CraftPlayer (org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer)26 CraftPlayer (org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer)26 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)24 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)23 Behavior (de.Keyle.MyPet.api.skill.skills.Behavior)21 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)18 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)18 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)18 UUID (java.util.UUID)15 CraftPlayer (org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer)15 GameProfile (com.mojang.authlib.GameProfile)14 CraftPlayer (org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer)14 CraftPlayer (org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer)14 ServerPlayer (net.minecraft.server.level.ServerPlayer)12 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)11 PacketPlayOutTitle (net.minecraft.server.v1_12_R1.PacketPlayOutTitle)10 MyPetFeedEvent (de.Keyle.MyPet.api.event.MyPetFeedEvent)8