Search in sources :

Example 91 with CraftPlayer

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

the class BehaviorAggressiveTarget method shouldFinish.

@Override
public boolean shouldFinish() {
    if (!petEntity.canMove()) {
        return true;
    } else if (petEntity.getMyPetTarget() == null) {
        return true;
    }
    EntityLiving target = ((CraftLivingEntity) petEntity.getMyPetTarget()).getHandle();
    if (!target.isAlive()) {
        return true;
    }
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (behaviorSkill.getBehavior() != BehaviorMode.Aggressive) {
        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_9_R2.EntityLiving) CraftLivingEntity(org.bukkit.craftbukkit.v1_9_R2.entity.CraftLivingEntity) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 92 with CraftPlayer

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

the class CustomInventory method open.

@Override
public void open(Player player) {
    EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    Container container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        Containers customSize = Containers.GENERIC_9X1;
        switch(this.getSize()) {
            case 18:
                customSize = Containers.GENERIC_9X2;
                break;
            case 27:
                customSize = Containers.GENERIC_9X3;
                break;
            case 36:
                customSize = Containers.GENERIC_9X4;
                break;
            case 45:
                customSize = Containers.GENERIC_9X5;
                break;
            case 54:
                customSize = Containers.GENERIC_9X6;
                break;
        }
        entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, customSize, new ChatComponentText(this.getName())));
        entityPlayer.activeContainer = container;
        entityPlayer.activeContainer.addSlotListener(entityPlayer);
    }
}
Also used : CraftContainer(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer)

Example 93 with CraftPlayer

use of org.bukkit.craftbukkit.v1_18_R2.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_17_R1.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftContainer)

Example 94 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
 */
@Override
public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat<Object> data) {
    ParticleType effect = Registry.PARTICLE_TYPE.get(new ResourceLocation(effectName));
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effect, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    ParticleOptions particle = null;
    if (effect.getDeserializer() != null && data != null) {
        try {
            particle = effect.getDeserializer().fromCommand(effect, new StringReader(" " + data.get().toString()));
        } catch (CommandSyntaxException e) {
            e.printStackTrace();
        }
    } else if (effect instanceof SimpleParticleType) {
        particle = (SimpleParticleType) effect;
    }
    if (particle == null) {
        return;
    }
    ClientboundLevelParticlesPacket packet = new ClientboundLevelParticlesPacket(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
    radius = radius * radius;
    for (Player player : location.getWorld().getPlayers()) {
        if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
            ((CraftPlayer) player).getHandle().connection.send(packet);
        }
    }
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) ParticleOptions(net.minecraft.core.particles.ParticleOptions) ResourceLocation(net.minecraft.resources.ResourceLocation) StringReader(com.mojang.brigadier.StringReader) ParticleType(net.minecraft.core.particles.ParticleType) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) ClientboundLevelParticlesPacket(net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 95 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
 */
@Override
public void playParticleEffect(Player player, Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat<Object> data) {
    ParticleType effect = Registry.PARTICLE_TYPE.get(new ResourceLocation(effectName));
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effect, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    ParticleOptions particle = null;
    if (effect.getDeserializer() != null && data != null) {
        try {
            particle = effect.getDeserializer().fromCommand(effect, new StringReader(" " + data.get().toString()));
        } catch (CommandSyntaxException e) {
            e.printStackTrace();
        }
    } else if (effect instanceof SimpleParticleType) {
        particle = (SimpleParticleType) effect;
    }
    if (particle == null) {
        return;
    }
    ClientboundLevelParticlesPacket packet = new ClientboundLevelParticlesPacket(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
    if (MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
        ((CraftPlayer) player).getHandle().connection.send(packet);
    }
}
Also used : ParticleOptions(net.minecraft.core.particles.ParticleOptions) ResourceLocation(net.minecraft.resources.ResourceLocation) StringReader(com.mojang.brigadier.StringReader) ParticleType(net.minecraft.core.particles.ParticleType) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) ClientboundLevelParticlesPacket(net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

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