ForgePatch/fml/common/cpw/mods/fml/common/FMLHooks.java

155 lines
3.9 KiB
Java
Raw Normal View History

2012-03-30 14:11:13 +00:00
/*
* The FML Forge Mod Loader suite.
2012-03-30 14:11:13 +00:00
* Copyright (C) 2012 cpw
*
2012-03-30 14:11:13 +00:00
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or any later version.
*
2012-03-30 14:11:13 +00:00
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
2012-03-30 14:11:13 +00:00
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package cpw.mods.fml.common;
2012-04-04 02:45:27 +00:00
import java.io.UnsupportedEncodingException;
2012-04-03 21:04:26 +00:00
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
2012-04-04 02:45:27 +00:00
import net.minecraft.src.EntityPlayer;
2012-03-30 14:11:13 +00:00
public class FMLHooks
{
private static final FMLHooks INSTANCE = new FMLHooks();
private Map<ModContainer, Set<String>> channelList = new HashMap<ModContainer, Set<String>>();
private Map<String, ModContainer> modChannels = new HashMap<String, ModContainer>();
private Map<Object, Set<String>> activeChannels = new HashMap<Object, Set<String>>();
public void gameTickStart()
{
for (ModContainer mod : Loader.getModList())
{
mod.tickStart();
}
}
public void gameTickEnd()
{
for (ModContainer mod : Loader.getModList())
{
mod.tickEnd();
}
}
/**
* @return the instance
*/
public static FMLHooks instance()
{
return INSTANCE;
2012-03-30 14:11:13 +00:00
}
public ModContainer getModForChannel(String channel)
{
return modChannels.get(channel);
2012-03-30 14:11:13 +00:00
}
/**
* @param modLoaderModContainer
* @return
*/
public Set<String> getChannelListFor(ModContainer container)
{
return channelList.get(container);
2012-04-03 21:04:26 +00:00
}
public void registerChannel(ModContainer container, String channelName)
{
if (modChannels.containsKey(channelName))
{
// NOOP
}
Set<String> list = channelList.get(container);
if (list == null)
{
list = new HashSet<String>();
channelList.put(container, list);
}
list.add(channelName);
2012-04-03 21:04:26 +00:00
}
/**
* @param player
*/
public void activateChannel(Object player, String channel)
{
Set<String> active = activeChannels.get(player);
if (active == null)
{
active = new HashSet<String>();
activeChannels.put(player, active);
}
active.add(channel);
2012-04-04 02:45:27 +00:00
}
/**
* @param player
* @param channel
*/
public void deactivateChannel(EntityPlayer player, String channel)
{
Set<String> active = activeChannels.get(player);
if (active == null)
{
active = new HashSet<String>();
activeChannels.put(player, active);
}
active.remove(channel);
2012-04-04 02:45:27 +00:00
}
/**
* @return
*/
public byte[] getPacketRegistry()
{
StringBuffer sb = new StringBuffer();
for (String chan : modChannels.keySet())
{
sb.append(chan).append("\0");
}
try
{
return sb.toString().getBytes("UTF8");
}
catch (UnsupportedEncodingException e)
{
Loader.log.warning("Error building registration list");
Loader.log.throwing("FMLHooks", "getPacketRegistry", e);
return new byte[0];
}
2012-04-04 02:45:27 +00:00
}
/**
* @param channel
* @param player
* @return
*/
public boolean isChannelActive(String channel, Object player)
{
return activeChannels.get(player).contains(channel);
2012-04-04 02:45:27 +00:00
}
2012-03-30 14:11:13 +00:00
}