Search in sources :

Example 96 with CraftPlayer

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

the class BehaviorDuelTarget method shouldFinish.

@Override
public boolean shouldFinish() {
    if (!petEntity.canMove()) {
        return true;
    } else if (!petEntity.hasTarget()) {
        return true;
    }
    LivingEntity target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle();
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (behaviorSkill.getBehavior() != BehaviorMode.Duel) {
        return true;
    } else if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return true;
    } else if (target.level != petEntity.level) {
        return true;
    } else if (petEntity.distanceToSqr(target) > 400) {
        return true;
    } else
        return petEntity.distanceToSqr(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600;
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftLivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftLivingEntity) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 97 with CraftPlayer

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

Example 98 with CraftPlayer

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

the class CustomInventory method open.

@Override
public void open(Player player) {
    ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        MenuType<?> customSize = MenuType.GENERIC_9x1;
        switch(this.getContainerSize()) {
            case 18:
                customSize = MenuType.GENERIC_9x2;
                break;
            case 27:
                customSize = MenuType.GENERIC_9x3;
                break;
            case 36:
                customSize = MenuType.GENERIC_9x4;
                break;
            case 45:
                customSize = MenuType.GENERIC_9x5;
                break;
            case 54:
                customSize = MenuType.GENERIC_9x6;
                break;
        }
        entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
        entityPlayer.containerMenu = container;
        entityPlayer.initMenu(container);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftContainer)

Example 99 with CraftPlayer

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

the class BehaviorFarmTarget method shouldFinish.

@Override
public boolean shouldFinish() {
    if (!petEntity.canMove()) {
        return true;
    }
    if (!this.petEntity.hasTarget()) {
        return true;
    }
    EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle();
    if (!target.isAlive()) {
        return true;
    }
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (behaviorSkill.getBehavior() != BehaviorMode.Farm) {
        return true;
    } else if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return true;
    } else if (target.world != petEntity.world) {
        return true;
    } else if (petEntity.h(target) > 400) {
        return true;
    } else if (petEntity.h(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600) {
        return true;
    }
    return false;
}
Also used : EntityLiving(net.minecraft.server.v1_8_R3.EntityLiving) CraftLivingEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 100 with CraftPlayer

use of org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer in project solinia3-core by mixxit.

the class ForgeUtils method sendForgeMessage.

public static void sendForgeMessage(Player player, String channelName, byte discriminator, String message) throws Exception {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    DataOutputStream dataOut = new DataOutputStream(stream);
    try {
        // diesieben07 - Forge uses an unsigned byte for the discriminator, for a start
        // dataOut.writeInt(discriminator);
        dataOut.writeByte(discriminator);
        // diesieben07 - But you should really send some kind of length prefix
        // and then only read that much of the string
        // You're already using DataOuput, it has writeUTFString
        // dataOut.write(message.getBytes(StandardCharsets.UTF_8));
        dataOut.writeUTF(message);
        PacketPlayOutCustomPayload packet = new PacketPlayOutCustomPayload(new MinecraftKey(channelName), new PacketDataSerializer(Unpooled.wrappedBuffer(stream.toByteArray())));
        ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    } finally {
        dataOut.close();
        stream.close();
    }
}
Also used : PacketDataSerializer(net.minecraft.server.v1_15_R1.PacketDataSerializer) DataOutputStream(java.io.DataOutputStream) PacketPlayOutCustomPayload(net.minecraft.server.v1_15_R1.PacketPlayOutCustomPayload) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MinecraftKey(net.minecraft.server.v1_15_R1.MinecraftKey)

Aggregations

Player (org.bukkit.entity.Player)224 ServerPlayer (net.minecraft.server.level.ServerPlayer)126 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)101 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)74 Location (org.bukkit.Location)68 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)62 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)60 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)57 CraftPlayer (org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)50 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)49 CraftPlayer (org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer)47 CraftPlayer (org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer)41 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)41 CraftPlayer (org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer)41 Property (com.mojang.authlib.properties.Property)40 GameProfile (com.mojang.authlib.GameProfile)37 CraftPlayer (org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer)36 CraftPlayer (org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer)35 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)24 EntityPlayer (net.minecraft.server.level.EntityPlayer)24