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.entity; 018 019import net.tridentsdk.meta.nbt.NBTField; 020import net.tridentsdk.meta.nbt.NBTSerializable; 021import net.tridentsdk.meta.nbt.TagType; 022 023import javax.annotation.concurrent.NotThreadSafe; 024import java.util.List; 025 026@NotThreadSafe 027// TODO move to API and fix thread safety 028public class EntityAttribute implements NBTSerializable { 029 @NBTField(name = "Name", type = TagType.STRING) 030 protected String name; 031 @NBTField(name = "Base", type = TagType.DOUBLE) 032 protected double value; 033 @NBTField(name = "Modifiers", type = TagType.LIST) 034 protected List<Modifier> modifiers; 035 036 protected EntityAttribute() { 037 } 038 039 public String name() { 040 return name; 041 } 042 043 public double value() { 044 return value; 045 } 046 047 public List<Modifier> modifiers() { 048 return modifiers; 049 } 050 051 public void setValue(double value) { 052 this.value = value; 053 } 054 055 public void addModifier(Modifier modifier) { 056 modifiers.add(modifier); 057 } 058 059 public void removeModifier(int index) { 060 modifiers.remove(index); 061 } 062 063 public void setModifier(int index, Modifier modifier) { 064 modifiers.set(index, modifier); 065 } 066 067 @NotThreadSafe 068 public static class Modifier implements NBTSerializable { 069 @NBTField(name = "Name", type = TagType.STRING) 070 protected String name; 071 @NBTField(name = "Amount", type = TagType.DOUBLE) 072 protected double amount; 073 @NBTField(name = "Operation", type = TagType.INT) 074 protected int operation; 075 076 public Modifier() {} 077 078 public String name() { 079 return name; 080 } 081 082 public double amount() { 083 return amount; 084 } 085 086 public int operation() { 087 return operation; 088 } 089 } 090}