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.potion;
018
019import net.tridentsdk.effect.potion.PotionEffect;
020import net.tridentsdk.effect.potion.PotionEffectType;
021import net.tridentsdk.meta.nbt.NBTField;
022import net.tridentsdk.meta.nbt.TagType;
023
024/**
025 * Represents a potion effect
026 *
027 * @author The TridentSDK Team
028 */
029public class TridentPotionEffect implements PotionEffect {
030    @NBTField(name = "id", type = TagType.BYTE)
031    protected byte id;
032    @NBTField(name = "Amplifier", type = TagType.BYTE)
033    protected byte amplifier;
034    @NBTField(name = "Duration", type = TagType.INT)
035    protected int duration;
036    @NBTField(name = "Ambient", type = TagType.BYTE)
037    protected byte ambient;
038    @NBTField(name = "ShowParticles", type = TagType.BYTE)
039    protected byte showParticles;
040
041    @Override
042    public PotionEffectType effectType() {
043        return PotionEffectType.fromId(id);
044    }
045
046    @Override
047    public void setEffectType(PotionEffectType type) {
048        this.id = type.id();
049    }
050
051    @Override
052    public byte amplifier() {
053        return amplifier;
054    }
055
056    @Override
057    public void setAmplifier(byte b) {
058        this.amplifier = b;
059    }
060
061    @Override
062    public int duration() {
063        return duration;
064    }
065
066    @Override
067    public void setDuration(int duration) {
068        this.duration = duration;
069    }
070
071    @Override
072    public boolean isAmbient() {
073        return ambient == 1;
074    }
075
076    @Override
077    public void setAmbient(boolean ambient) {
078        this.ambient = (byte) (ambient ? 1 : 0);
079    }
080
081    @Override
082    public boolean showParticles() {
083        return showParticles == 1;
084    }
085
086    @Override
087    public void setShowParticles(boolean showParticles) {
088        this.showParticles = (byte) (showParticles ? 1 : 0);
089    }
090}