Add in more "Player" related events. Fix up some MLProp stuff

This commit is contained in:
Christian Weeks 2012-04-09 10:18:24 -04:00
parent f92149aef5
commit 2ae31bddd2
7 changed files with 152 additions and 27 deletions

View File

@ -281,4 +281,24 @@ public class FMLModContainer implements ModContainer
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#wantsPlayerTracking()
*/
@Override
public boolean wantsPlayerTracking()
{
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getPlayerTracker()
*/
@Override
public IPlayerTracker getPlayerTracker()
{
// TODO Auto-generated method stub
return null;
}
}

View File

@ -21,5 +21,4 @@ public interface INetworkHandler
{
boolean onChat(Object... data);
void onPacket250Packet(Object... data);
void onLogin(Object... data);
}

View File

@ -0,0 +1,26 @@
/*
* The FML Forge Mod Loader suite.
* Copyright (C) 2012 cpw
*
* 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.
*
* 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.
*
* 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;
/**
* @author cpw
*
*/
public interface IPlayerTracker
{
void onPlayerLogin(Object player);
void onPlayerLogout(Object player);
void onPlayerChangedDimension(Object player);
}

View File

@ -164,4 +164,8 @@ public interface ModContainer
boolean wantsConsoleCommands();
IConsoleHandler getConsoleHandler();
boolean wantsPlayerTracking();
IPlayerTracker getPlayerTracker();
}

View File

@ -25,6 +25,7 @@ import net.minecraft.src.BiomeGenBase;
import net.minecraft.src.CommonRegistry;
import net.minecraft.src.EntityItem;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EntityPlayerMP;
import net.minecraft.src.IChunkProvider;
import net.minecraft.src.ICommandListener;
import net.minecraft.src.IInventory;
@ -408,9 +409,9 @@ public class FMLServerHandler implements IFMLSidedHandler
public void announceLogin(EntityPlayer player) {
for (ModContainer mod : Loader.getModList())
{
if (mod.wantsNetworkPackets())
if (mod.wantsPlayerTracking())
{
mod.getNetworkHandler().onLogin(player);
mod.getPlayerTracker().onPlayerLogin(player);
}
}
}
@ -455,4 +456,32 @@ public class FMLServerHandler implements IFMLSidedHandler
}
return false;
}
/**
* @param player
*/
public void announceLogout(EntityPlayer player)
{
for (ModContainer mod : Loader.getModList())
{
if (mod.wantsPlayerTracking())
{
mod.getPlayerTracker().onPlayerLogout(player);
}
}
}
/**
* @param p_28168_1_
*/
public void announceDimensionChange(EntityPlayer player)
{
for (ModContainer mod : Loader.getModList())
{
if (mod.wantsPlayerTracking())
{
mod.getPlayerTracker().onPlayerChangedDimension(player);
}
}
}
}

View File

@ -32,6 +32,7 @@ import cpw.mods.fml.common.ICraftingHandler;
import cpw.mods.fml.common.IDispenseHandler;
import cpw.mods.fml.common.INetworkHandler;
import cpw.mods.fml.common.IPickupNotifier;
import cpw.mods.fml.common.IPlayerTracker;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.LoaderException;
@ -193,7 +194,7 @@ public class ModLoaderModContainer implements ModContainer
{
return (String)val;
}
else if (type.isAssignableFrom(Boolean.TYPE))
else if (type.isAssignableFrom(Boolean.TYPE) || type.isAssignableFrom(Boolean.class))
{
return Boolean.parseBoolean(val);
}
@ -201,27 +202,27 @@ public class ModLoaderModContainer implements ModContainer
{
Number n = null;
if (type.isAssignableFrom(Double.TYPE))
if (Double.class.isAssignableFrom(type))
{
n = Double.parseDouble(val);
}
else if (type.isAssignableFrom(Float.TYPE))
if (Float.class.isAssignableFrom(type))
{
n = Float.parseFloat(val);
}
else if (type.isAssignableFrom(Long.TYPE))
if (Long.class.isAssignableFrom(type))
{
n = Long.parseLong(val);
}
else if (type.isAssignableFrom(Integer.TYPE))
if (Integer.class.isAssignableFrom(type))
{
n = Integer.parseInt(val);
}
else if (type.isAssignableFrom(Short.TYPE))
if (Short.class.isAssignableFrom(type))
{
n = Short.parseShort(val);
}
else if (type.isAssignableFrom(Byte.TYPE))
if (Byte.class.isAssignableFrom(type))
{
n = Byte.parseByte(val);
}
@ -248,7 +249,7 @@ public class ModLoaderModContainer implements ModContainer
{
return (String)value;
}
else if (Number.class.isInstance(value))
else if (Number.class.isInstance(value) || Boolean.class.isInstance(value))
{
return String.valueOf(value);
}
@ -505,4 +506,16 @@ public class ModLoaderModContainer implements ModContainer
{
return mod;
}
@Override
public boolean wantsPlayerTracking()
{
return true;
}
@Override
public IPlayerTracker getPlayerTracker()
{
return mod;
}
}

View File

@ -20,9 +20,10 @@ import cpw.mods.fml.common.ICraftingHandler;
import cpw.mods.fml.common.IDispenseHandler;
import cpw.mods.fml.common.INetworkHandler;
import cpw.mods.fml.common.IPickupNotifier;
import cpw.mods.fml.common.IPlayerTracker;
import cpw.mods.fml.common.IWorldGenerator;
public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler, IConsoleHandler
public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler, IConsoleHandler, IPlayerTracker
{
// CALLBACK MECHANISMS
@Override
@ -48,9 +49,21 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp
return onChatMessageReceived((EntityPlayer)data[1], (Packet3Chat)data[0]);
}
@Override
public final void onLogin(Object... data)
public final void onPlayerLogin(Object player)
{
onClientLogin((EntityPlayer) data[0]);
onClientLogin((EntityPlayer) player);
}
@Override
public void onPlayerLogout(Object player)
{
onClientLogout((EntityPlayer)player);
}
@Override
public void onPlayerChangedDimension(Object player)
{
onClientDimensionChanged((EntityPlayer)player);
}
@Override
@ -253,9 +266,28 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp
}
/**
* Called when a new client logs in. Make sure modloader knows about your channels
* @param login
* @param data
* Called when a chat message is received. Return true to stop further processing
* @param source
* @param chat
* @return true if you want to consume the message so it is not available for further processing
*/
public boolean onChatMessageReceived(EntityPlayer source, Packet3Chat chat)
{
return false;
}
/**
* Called when a server command is received
* @param command
* @return true if you want to consume the message so it is not available for further processing
*/
public boolean onServerCommand(String command, String sender, ICommandListener listener)
{
return false;
}
/**
* Called when a new client logs in.
*
* @param player
*/
public void onClientLogin(EntityPlayer player)
@ -263,22 +295,24 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp
}
/**
* Called when a chat message is received. Return true to stop further processing
* @param source
* @param chat
* @return
* Called when a client logs out of the server.
*
* @param player
*/
public boolean onChatMessageReceived(EntityPlayer source, Packet3Chat chat)
public void onClientLogout(EntityPlayer player)
{
return false;
}
/**
* @param command
* @return
*
* Called when a client changes dimensions on the server.
*
* @param player
*/
public boolean onServerCommand(String command, String sender, ICommandListener listener)
public void onClientDimensionChanged(EntityPlayer player)
{
return false;
}
// Spare client junk