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.meta.component;
018
019import net.tridentsdk.base.Block;
020import net.tridentsdk.base.Substance;
021import net.tridentsdk.util.Value;
022
023import javax.annotation.concurrent.ThreadSafe;
024
025/**
026 * Provides metadata values
027 *
028 * @author The TridentSDK Team
029 * @since 0.4-alpha
030 */
031@ThreadSafe
032public interface MetaProvider {
033    /**
034     * Obtains a new instance of a meta value
035     *
036     * @param cls the meta type class
037     * @param <S> the meta owner type
038     * @param <T> the meta value type
039     * @return the new meta value
040     */
041    <S, T extends Meta<S>> T provide(Class<T> cls);
042
043    /**
044     * Puts the meta value into the server meta registry
045     *
046     * @param meta the meta
047     */
048    void register(Meta meta);
049
050    /**
051     * Decodes and applies the byte data to the block as specified in
052     * {@link net.tridentsdk.meta.block.BlockMeta#decodeMeta(Object, byte[])}
053     *
054     * @param block the block
055     * @param substance the type to set the block
056     * @param data  the data
057     * @param result  @return {@code true} if the block can be placed, {@code false} if otherwise
058     */
059    boolean decode(Block block, Value<Substance> substance, byte[] data, Value<Byte> result);
060}