Search in sources :

Example 16 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project MyPet by xXKeyleXx.

the class ControlTarget method shouldStart.

@Override
public boolean shouldStart() {
    if (controlPathfinderGoal == null) {
        if (petEntity.getPathfinder().hasGoal("Control")) {
            controlPathfinderGoal = (Control) petEntity.getPathfinder().getGoal("Control");
        }
    }
    if (controlPathfinderGoal == null) {
        return false;
    }
    if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return false;
    }
    if (controlPathfinderGoal.moveTo != null && petEntity.canMove()) {
        Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
        if (behaviorSkill.isActive()) {
            if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
                return false;
            }
        }
        for (net.minecraft.world.entity.LivingEntity entityLiving : this.petEntity.level.getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, this.petEntity.getBoundingBox().inflate(this.range, 4.0D, this.range))) {
            if (entityLiving != petEntity && !(entityLiving instanceof ArmorStand)) {
                if (entityLiving instanceof ServerPlayer) {
                    Player targetPlayer = (Player) entityLiving.getBukkitEntity();
                    if (myPet.getOwner().equals(targetPlayer)) {
                        continue;
                    } else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
                        continue;
                    }
                } else if (entityLiving instanceof TamableAnimal) {
                    TamableAnimal tameable = (TamableAnimal) entityLiving;
                    if (tameable.isTame() && tameable.getOwner() != null) {
                        Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
                        if (myPet.getOwner().equals(tameableOwner)) {
                            continue;
                        } else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), tameableOwner, true)) {
                            continue;
                        }
                    }
                } else if (entityLiving instanceof EntityMyPet) {
                    MyPet targetMyPet = ((EntityMyPet) entityLiving).getMyPet();
                    if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
                        continue;
                    }
                }
                if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), entityLiving.getBukkitEntity())) {
                    continue;
                }
                if (behaviorSkill != null) {
                    if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
                        if (entityLiving instanceof TamableAnimal) {
                            continue;
                        } else if (entityLiving instanceof EntityMyPet) {
                            continue;
                        } else if (entityLiving instanceof ServerPlayer) {
                            continue;
                        }
                    }
                }
                controlPathfinderGoal.stopControl();
                this.target = entityLiving;
                return true;
            }
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ServerPlayer(net.minecraft.server.level.ServerPlayer) EntityMyPet(de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet) ArmorStand(net.minecraft.world.entity.decoration.ArmorStand) TamableAnimal(net.minecraft.world.entity.TamableAnimal) MyPet(de.Keyle.MyPet.api.entity.MyPet) EntityMyPet(de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet) ServerPlayer(net.minecraft.server.level.ServerPlayer) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 17 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project MyPet by xXKeyleXx.

the class OwnerHurtByTarget method shouldStart.

@Override
public boolean shouldStart() {
    if (!petEntity.canMove()) {
        return false;
    }
    if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return false;
    }
    this.lastDamager = owner.getLastHurtByMob();
    if (this.lastDamager == null || !lastDamager.isAlive()) {
        return false;
    }
    if (lastDamager instanceof ArmorStand) {
        return false;
    }
    if (lastDamager == petEntity) {
        return false;
    }
    if (lastDamager instanceof ServerPlayer) {
        if (owner == lastDamager) {
            return false;
        }
        Player targetPlayer = (Player) lastDamager.getBukkitEntity();
        if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
            return false;
        }
    } else if (lastDamager instanceof EntityMyPet) {
        MyPet targetMyPet = ((EntityMyPet) lastDamager).getMyPet();
        if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
            return false;
        }
    } else if (lastDamager instanceof TamableAnimal) {
        TamableAnimal tameable = (TamableAnimal) lastDamager;
        if (tameable.isTame() && tameable.getOwner() != null) {
            Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
            if (myPet.getOwner().equals(tameableOwner)) {
                return false;
            }
        }
    }
    if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), lastDamager.getBukkitEntity())) {
        return false;
    }
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (behaviorSkill != null && behaviorSkill.isActive()) {
        if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
            return false;
        }
        if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
            if (lastDamager instanceof TamableAnimal && ((TamableAnimal) lastDamager).isTame()) {
                return false;
            }
            if (lastDamager instanceof EntityMyPet) {
                return false;
            }
            return !(lastDamager instanceof ServerPlayer);
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ServerPlayer(net.minecraft.server.level.ServerPlayer) EntityMyPet(de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet) ArmorStand(net.minecraft.world.entity.decoration.ArmorStand) TamableAnimal(net.minecraft.world.entity.TamableAnimal) MyPet(de.Keyle.MyPet.api.entity.MyPet) EntityMyPet(de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet) ServerPlayer(net.minecraft.server.level.ServerPlayer) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 18 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer 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 19 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project SpongeCommon by SpongePowered.

the class EntityMixin method impl$updateVanishState.

@SuppressWarnings({ "ConstantConditions", "RedundantCast" })
@Inject(method = "tick", at = @At("RETURN"))
private void impl$updateVanishState(final CallbackInfo callbackInfo) {
    if (this.impl$pendingVisibilityUpdate && !this.level.isClientSide) {
        final ChunkMap_TrackedEntityAccessor trackerAccessor = ((ChunkMapAccessor) ((ServerWorld) this.level).chunkManager()).accessor$entityMap().get(this.shadow$getId());
        if (trackerAccessor != null && this.impl$visibilityTicks % 4 == 0) {
            if (this.bridge$vanishState().invisible()) {
                for (final ServerPlayer entityPlayerMP : trackerAccessor.accessor$seenBy()) {
                    entityPlayerMP.connection.send(new ClientboundRemoveEntitiesPacket(this.shadow$getId()));
                    if ((Entity) (Object) this instanceof ServerPlayer) {
                        entityPlayerMP.connection.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, (ServerPlayer) (Object) this));
                    }
                }
            } else {
                this.impl$visibilityTicks = 1;
                this.impl$pendingVisibilityUpdate = false;
                for (final ServerPlayer entityPlayerMP : SpongeCommon.server().getPlayerList().getPlayers()) {
                    if ((Entity) (Object) this == entityPlayerMP) {
                        continue;
                    }
                    if ((Entity) (Object) this instanceof ServerPlayer) {
                        final Packet<?> packet = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, (ServerPlayer) (Object) this);
                        entityPlayerMP.connection.send(packet);
                    }
                    trackerAccessor.accessor$updatePlayer(entityPlayerMP);
                }
            }
        }
        if (this.impl$visibilityTicks > 0) {
            this.impl$visibilityTicks--;
        } else {
            this.impl$pendingVisibilityUpdate = false;
        }
    }
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) ChunkMap_TrackedEntityAccessor(org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 20 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project SpongeCommon by SpongePowered.

the class IndirectEntityDamageSourceMixin method onConstruct.

@Inject(method = "<init>", at = @At("RETURN"))
private void onConstruct(final CallbackInfo callbackInfo) {
    if (this.entity != null) {
        // sources can be null
        final Entity mcEntity = this.shadow$getEntity();
        this.impl$creatorUUID = mcEntity instanceof CreatorTrackedBridge ? ((CreatorTrackedBridge) mcEntity).tracker$getCreatorUUID().orElse(null) : null;
        if (this.owner == null && this.impl$creatorUUID != null) {
            final ServerPlayer player = SpongeCommon.server().getPlayerList().getPlayer(this.impl$creatorUUID);
            if (player != null) {
                this.owner = player;
            }
        }
    }
}
Also used : Entity(net.minecraft.world.entity.Entity) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) ServerPlayer(net.minecraft.server.level.ServerPlayer) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ServerPlayer (net.minecraft.server.level.ServerPlayer)71 TamableAnimal (net.minecraft.world.entity.TamableAnimal)12 Behavior (de.Keyle.MyPet.api.skill.skills.Behavior)11 ServerLevel (net.minecraft.server.level.ServerLevel)11 ArmorStand (net.minecraft.world.entity.decoration.ArmorStand)11 ItemStack (net.minecraft.world.item.ItemStack)10 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)10 Player (org.bukkit.entity.Player)10 MyPet (de.Keyle.MyPet.api.entity.MyPet)8 EntityMyPet (de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet)8 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)8 Player (net.minecraft.world.entity.player.Player)7 EntityMyPet (de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet)6 ArrayList (java.util.ArrayList)6 ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)6 ChunkMap (net.minecraft.server.level.ChunkMap)6 ServerGamePacketListenerImpl (net.minecraft.server.network.ServerGamePacketListenerImpl)6 LivingEntity (net.minecraft.world.entity.LivingEntity)6 ItemEntity (net.minecraft.world.entity.item.ItemEntity)6 PlayerEntityTagMessage (com.wuest.prefab.proxy.messages.PlayerEntityTagMessage)5