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.data.item; 018 019import java.util.Set; 020 021import com.google.common.collect.Sets; 022 023import net.tridentsdk.meta.item.ItemDisplayProperties; 024import net.tridentsdk.meta.item.ItemMeta; 025import net.tridentsdk.meta.nbt.NBTField; 026import net.tridentsdk.meta.nbt.TagType; 027 028public class ItemMetaImpl implements ItemMeta { 029 @NBTField(name = "display", type = TagType.COMPOUND, asClass = ItemDisplayPropertiesImpl.class) 030 protected ItemDisplayProperties displayProperties; 031 032 @NBTField(name = "HideFlags", type = TagType.INT) 033 protected int flags; 034 035 Set<HiddenModifierFlag> hiddenFlags = Sets.newConcurrentHashSet(); 036 037 @Override 038 public void process() { 039 for (ItemMeta.HiddenModifierFlag flag : ItemMeta.HiddenModifierFlag.values()) { 040 if ((this.flags & flag.modifier()) == flag.modifier()) { 041 this.hiddenFlags.add(flag); 042 } 043 } 044 } 045 046 @Override 047 public ItemDisplayProperties displayProperties() { 048 return this.displayProperties; 049 } 050 051 @Override 052 public void setDisplayProperties(ItemDisplayProperties properties) { 053 this.displayProperties = properties; 054 } 055 056 @Override 057 public Set<HiddenModifierFlag> flags() { 058 return this.hiddenFlags; 059 } 060 061 @Override 062 public void setFlag(HiddenModifierFlag flag, boolean shown) { 063 if (shown) { 064 if (this.hiddenFlags.contains(flag)) { 065 this.hiddenFlags.remove(flag); 066 this.flags -= flag.modifier(); 067 } 068 } else { 069 if (this.hiddenFlags.contains(flag)) { 070 this.hiddenFlags.add(flag); 071 this.flags += flag.modifier(); 072 } 073 } 074 } 075}