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 */
017
018package net.tridentsdk.server.entity.ai;
019
020
021import net.tridentsdk.entity.living.ai.AiHandler;
022import net.tridentsdk.entity.living.ai.AiModule;
023import net.tridentsdk.entity.types.EntityType;
024
025import java.util.HashMap;
026import java.util.Map;
027import java.util.concurrent.ConcurrentHashMap;
028
029/**
030 * Implementation of interface
031 *
032 * @author The TridentSDK Team
033 */
034public class TridentAiHandler implements AiHandler {
035    private final Map<EntityType, AiModule> modules = new ConcurrentHashMap<>();
036    private final Map<EntityType, AiModule> nativeModules = new HashMap<>();
037
038    public TridentAiHandler() {
039        // TODO add default AIs
040        nativeModules.put(EntityType.CREEPER, new CreeperAiModule());
041    }
042
043    @Override
044    public AiModule defaultAiFor(EntityType type) {
045        if (modules.get(type) == null) {
046            return nativeModules.get(type);
047        } else {
048            return modules.get(type);
049        }
050    }
051
052    @Override
053    public void setDefaultAiFor(EntityType type, AiModule module) {
054        modules.put(type, module);
055    }
056
057    @Override
058    public AiModule nativeAIFor(EntityType type) {
059        return nativeModules.get(type);
060    }
061}