Search in sources :

Example 46 with CraftPlayer

use of org.bukkit.craftbukkit.v1_15_R1.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_15_R1.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_15_R1.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_15_R1.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_15_R1.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_9_R1.entity.CraftPlayer) JSONObject(org.json.simple.JSONObject)

Aggregations

Player (org.bukkit.entity.Player)85 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