Search in sources :

Example 46 with CraftPlayer

use of org.bukkit.craftbukkit.v1_4_5.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();
    try {
        Field field = entityPlayer.getClass().getDeclaredField("locale");
        String lang = field.get(entityPlayer).toString();
        if (lang == null) {
            return "en_US";
        }
        return lang;
    } catch (Exception e) {
        return "en_US";
    }
}
Also used : Field(java.lang.reflect.Field) CraftPlayer(org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer)

Example 47 with CraftPlayer

use of org.bukkit.craftbukkit.v1_4_5.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) {
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effectName, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(effectName, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
    radius = radius * radius;
    for (Player player : location.getWorld().getPlayers()) {
        if (MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    }
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer) Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer)

Example 48 with CraftPlayer

use of org.bukkit.craftbukkit.v1_4_5.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();
    try {
        Field field = entityPlayer.getClass().getDeclaredField("locale");
        String lang = field.get(entityPlayer).toString();
        if (lang == null) {
            return "en_US";
        }
        return lang;
    } catch (Exception e) {
        return "en_US";
    }
}
Also used : Field(java.lang.reflect.Field) CraftPlayer(org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer)

Example 49 with CraftPlayer

use of org.bukkit.craftbukkit.v1_4_5.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_12_R1.entity.CraftPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)

Example 50 with CraftPlayer

use of org.bukkit.craftbukkit.v1_4_5.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.subtract(1);
                    }
                    if (itemStack.getCount() <= 0) {
                        entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.a);
                    }
                    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) {
                        itemStack.subtract(1);
                        if (itemStack.getCount() <= 0) {
                            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.a);
                        }
                    }
                    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_12_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)

Aggregations

Player (org.bukkit.entity.Player)76 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)32 CraftPlayer (org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer)26 CraftPlayer (org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer)26 CraftPlayer (org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer)23 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)19 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)15 CraftPlayer (org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer)15 CraftPlayer (org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer)14 CraftPlayer (org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer)14 UUID (java.util.UUID)12 PacketPlayOutTitle (net.minecraft.server.v1_12_R1.PacketPlayOutTitle)10 PacketPlayOutTitle (net.minecraft.server.v1_8_R3.PacketPlayOutTitle)10 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)10 GameProfile (com.mojang.authlib.GameProfile)8 HashSet (java.util.HashSet)8 Set (java.util.Set)8 PacketPlayOutTitle (net.minecraft.server.v1_10_R1.PacketPlayOutTitle)8 PacketPlayOutTitle (net.minecraft.server.v1_11_R1.PacketPlayOutTitle)8 PacketPlayOutTitle (net.minecraft.server.v1_8_R1.PacketPlayOutTitle)8