Search in sources :

Example 51 with CraftPlayer

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.

the class PlatformHelper method playParticleEffect.

/**
 * @param location   the {@link Location} around which players must be to see the effect
 * @param effectName list of effects: https://gist.github.com/riking/5759002
 * @param offsetX    the amount to be randomly offset by in the X axis
 * @param offsetY    the amount to be randomly offset by in the Y axis
 * @param offsetZ    the amount to be randomly offset by in the Z axis
 * @param speed      the speed of the particles
 * @param count      the number of particles
 * @param radius     the radius around the location
 */
public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, int... data) {
    EnumParticle effect;
    try {
        effect = EnumParticle.valueOf(effectName);
    } catch (IllegalArgumentException e) {
        effect = EnumParticle.a(effectName);
    }
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effect, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(effect, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count, data);
    radius = radius * radius;
    for (Player player : location.getWorld().getPlayers()) {
        if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer)

Example 52 with CraftPlayer

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.

the class EntityMyPet method handlePlayerInteraction.

// Obfuscated Method handler ------------------------------------------------------------------------------------
/**
 * Is called when player rightclicks this MyPet
 * return:
 * true: there was a reaction on rightclick
 * false: no reaction on rightclick
 */
public boolean handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
    if (itemStack != null && itemStack.getItem() == Items.LEAD) {
        ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(this, null));
        if (!entityhuman.abilities.canInstantlyBuild) {
            new BukkitRunnable() {

                public void run() {
                    ((EntityPlayer) entityhuman).updateInventory(entityhuman.defaultContainer);
                }
            }.runTaskLater(MyPetApi.getPlugin(), 5);
        }
    }
    if (enumhand == EnumHand.OFF_HAND) {
        return true;
    }
    Player owner = this.getOwner().getPlayer();
    if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
        if (Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack)) {
            if (myPet.getSkills().isSkillActive(Ride.class) && canMove()) {
                if (Permissions.hasExtendedLegacy(owner, "MyPet.extended.ride")) {
                    ((CraftPlayer) owner).getHandle().startRiding(this);
                    return true;
                } else {
                    getOwner().sendMessage(Translation.getString("Message.No.CanUse", myPet.getOwner().getLanguage()));
                }
            }
        }
        if (Configuration.Skilltree.Skill.CONTROL_ITEM.compare(itemStack)) {
            if (myPet.getSkills().isSkillActive(de.Keyle.MyPet.skill.skills.Control.class)) {
                return true;
            }
        }
        if (itemStack != null) {
            if (itemStack.getItem() == Items.NAME_TAG && itemStack.hasName()) {
                if (Permissions.hasLegacy(getOwner(), "MyPet.command.name") && Permissions.hasExtended(getOwner(), "MyPet.extended.nametag")) {
                    final String name = itemStack.getName();
                    getMyPet().setPetName(name);
                    EntityMyPet.super.setCustomName("-");
                    myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Name.New", myPet.getOwner()), name));
                    if (!entityhuman.abilities.canInstantlyBuild) {
                        --itemStack.count;
                    }
                    if (itemStack.count <= 0) {
                        entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
                    }
                    new BukkitRunnable() {

                        public void run() {
                            updateNameTag();
                        }
                    }.runTaskLater(MyPetApi.getPlugin(), 1L);
                    return true;
                }
            }
            if (canEat(itemStack) && canUseItem()) {
                if (owner != null && !Permissions.hasExtendedLegacy(owner, "MyPet.extended.feed")) {
                    return false;
                }
                if (this.petTargetSelector.hasGoal("DuelTarget")) {
                    BehaviorDuelTarget duelTarget = (BehaviorDuelTarget) this.petTargetSelector.getGoal("DuelTarget");
                    if (duelTarget.getDuelOpponent() != null) {
                        return true;
                    }
                }
                boolean used = false;
                double saturation = Configuration.HungerSystem.HUNGER_SYSTEM_SATURATION_PER_FEED;
                if (saturation > 0) {
                    if (myPet.getSaturation() < 100) {
                        MyPetFeedEvent feedEvent = new MyPetFeedEvent(getMyPet(), CraftItemStack.asCraftMirror(itemStack), saturation, MyPetFeedEvent.Result.Eat);
                        Bukkit.getPluginManager().callEvent(feedEvent);
                        if (!feedEvent.isCancelled()) {
                            saturation = feedEvent.getSaturation();
                            double missingSaturation = 100 - myPet.getSaturation();
                            myPet.setSaturation(myPet.getSaturation() + saturation);
                            saturation = Math.max(0, saturation - missingSaturation);
                            used = true;
                        }
                    }
                }
                if (saturation > 0) {
                    if (getHealth() < getMaxHealth()) {
                        MyPetFeedEvent feedEvent = new MyPetFeedEvent(getMyPet(), CraftItemStack.asCraftMirror(itemStack), saturation, MyPetFeedEvent.Result.Heal);
                        Bukkit.getPluginManager().callEvent(feedEvent);
                        if (!feedEvent.isCancelled()) {
                            saturation = feedEvent.getSaturation();
                            float missingHealth = getMaxHealth() - getHealth();
                            this.heal(Math.min((float) saturation, missingHealth), RegainReason.EATING);
                            used = true;
                        }
                    }
                }
                if (used) {
                    if (!entityhuman.abilities.canInstantlyBuild) {
                        if (--itemStack.count <= 0) {
                            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
                        }
                    }
                    MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, getHeadHeight(), 0), "HEART", 0.5F, 0.5F, 0.5F, 0.5F, 5, 20);
                    return true;
                }
            }
        }
    } else {
        if (itemStack != null) {
            if (itemStack.getItem() == Items.NAME_TAG) {
                if (itemStack.hasName()) {
                    EntityMyPet.super.setCustomName("-");
                    new BukkitRunnable() {

                        public void run() {
                            updateNameTag();
                        }
                    }.runTaskLater(MyPetApi.getPlugin(), 1L);
                    return false;
                }
            }
        }
    }
    return false;
}
Also used : Ride(de.Keyle.MyPet.skill.skills.Ride) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MyPetFeedEvent(de.Keyle.MyPet.api.event.MyPetFeedEvent) Ride(de.Keyle.MyPet.skill.skills.Ride)

Example 53 with CraftPlayer

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.

the class PlatformHelper method playParticleEffect.

/**
 * @param location   the {@link Location} around which players must be to see the effect
 * @param effectName list of effects: https://gist.github.com/riking/5759002
 * @param offsetX    the amount to be randomly offset by in the X axis
 * @param offsetY    the amount to be randomly offset by in the Y axis
 * @param offsetZ    the amount to be randomly offset by in the Z axis
 * @param speed      the speed of the particles
 * @param count      the number of particles
 * @param radius     the radius around the location
 */
public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, int... data) {
    EnumParticle effect;
    try {
        effect = EnumParticle.valueOf(effectName);
    } catch (IllegalArgumentException e) {
        effect = EnumParticle.a(effectName);
    }
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effect, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(effect, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count, data);
    radius = radius * radius;
    for (Player player : location.getWorld().getPlayers()) {
        if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer)

Example 54 with CraftPlayer

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.

the class PlatformHelper method getPlayerLanguage.

public String getPlayerLanguage(Player player) {
    if (!(player instanceof CraftPlayer)) {
        return "en_US";
    }
    EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    Object lang = ReflectionUtil.getFieldValue(EntityPlayer_locale_FIELD, entityPlayer);
    if (lang == null) {
        return "en_US";
    }
    return lang.toString();
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) JSONObject(org.json.simple.JSONObject)

Example 55 with CraftPlayer

use of org.bukkit.craftbukkit.v1_18_R2.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.server.v1_16_R3.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.e(customId);
        nmsEntity.a_(customUUID);
    }
    EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
    for (Mechanism mechanism : mechanisms) {
        entity.safeAdjustDuplicate(mechanism);
    }
    nmsEntity.dead = false;
    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) -> {
        EntityPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
        PlayerConnection conn = nmsPlayer.playerConnection;
        final EntityTrackerEntry tracker = new EntityTrackerEntry(world.getHandle(), nmsEntity, 1, true, conn::sendPacket, Collections.singleton(nmsPlayer));
        tracker.b(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.b(((CraftPlayer) player.getPlayerEntity()).getHandle());
                            wasOnline = true;
                        }
                        tracker.a();
                    } 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.a();
            }
        }
    };
    fake.triggerDestroyPacket = () -> {
        for (TrackerData tracker : trackers) {
            if (tracker.player.isOnline()) {
                tracker.tracker.a(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
            }
        }
        trackers.clear();
    };
    return fake;
}
Also used : FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) EntityItemProjectileImpl(com.denizenscript.denizen.nms.v1_16.impl.entities.EntityItemProjectileImpl) CraftFakePlayerImpl(com.denizenscript.denizen.nms.v1_16.impl.entities.CraftFakePlayerImpl) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) Mechanism(com.denizenscript.denizencore.objects.Mechanism) EntityTag(com.denizenscript.denizen.objects.EntityTag) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Aggregations

Player (org.bukkit.entity.Player)250 ServerPlayer (net.minecraft.server.level.ServerPlayer)140 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)113 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)90 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)81 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)81 ItemStack (org.bukkit.inventory.ItemStack)80 Location (org.bukkit.Location)75 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)70 CraftPlayer (org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)66 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)57 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)52 CraftPlayer (org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer)51 GameProfile (com.mojang.authlib.GameProfile)48 EntityPlayer (net.minecraft.server.level.EntityPlayer)47 CraftPlayer (org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer)45 CraftPlayer (org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer)45 Property (com.mojang.authlib.properties.Property)44 CraftPlayer (org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer)42 CraftPlayer (org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer)41