001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package net.tridentsdk.server.effect.entity;
018
019import net.tridentsdk.effect.entity.EntityStatusEffect;
020import net.tridentsdk.effect.entity.EntityStatusEffectType;
021import net.tridentsdk.entity.Entity;
022import net.tridentsdk.entity.LivingEntity;
023import net.tridentsdk.server.effect.TridentEffect;
024import net.tridentsdk.server.entity.TridentEntity;
025import net.tridentsdk.server.netty.packet.OutPacket;
026import net.tridentsdk.server.packets.play.out.PacketPlayOutEntityStatus;
027
028/**
029 * Implements the entity status effect
030 *
031 * @author The TridentSDK Team
032 */
033public class TridentEntityStatusEffect extends TridentEffect<EntityStatusEffectType> implements EntityStatusEffect {
034    private PacketPlayOutEntityStatus packet = new PacketPlayOutEntityStatus();
035
036    public TridentEntityStatusEffect(LivingEntity entity, EntityStatusEffectType type){
037        packet.set("entityId", entity.entityId());
038        packet.set("status", type);
039    }
040
041    @Override
042    public EntityStatusEffectType type(){
043        return packet.status();
044    }
045
046    @Override
047    public void setType(EntityStatusEffectType type){
048        packet.set("status", type);
049    }
050
051    @Override
052    public void setEntity(Entity entity){
053        packet.set("entityId", entity.entityId());
054    }
055
056    @Override
057    public Entity entity(){
058        return TridentEntity.HANDLER.entityBy(packet.entityId());
059    }
060
061    @Override
062    public OutPacket getPacket(){
063        return packet;
064    }
065}