So so far I have a MainWorld MMORoom and a Inventory Room which is just a regular basic room. When I join the MainWorld MMO Room I also join the Inventory Room at which point the Inventory Extension creates my Inventory. All of that is working fine. I am trying to figure out the best way to be able to access the Extensions from other extensions. So like the Inventory Extension would have to be accessed from the Combat Extension for example once a Mob is destroyed.
Just to test it out I decided to try and get a copy of the Inventory Extension from the Extension attached to the MainWorld room so I have a ServerReady event which contains the following:
Code: Select all
public class ServerReadyEvent extends BaseServerEventHandler
{
@Override
public void handleServerEvent(ISFSEvent isfse) throws SFSException {
Room InventoryRoom = getParentZone().getRoomByName("Inventory");
ISFSExtension ext = SmartFoxServer.getInstance().getExtensionManager().getRoomExtension(InventoryRoom);
InventoryExt = (InventoryExtension)ext;
trace("Setting Extension up!");
}
}
When that event is called I get an exception:
java.lang.ClassCastException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.ClassCastException
Message: MMOExtensions.InventoryExtension cannot be cast to MMOExtensions.InventoryExtension
Description: Error during event handling: java.lang.ClassCastException: MMOExtensions.InventoryExtension cannot be cast to MMOExtensions.InventoryExtension, Listener: { Ext: MMOExtension, Type: JAVA, Lev: ROOM, { Zone: BasicExamples }, [ MMORoom: MainWorld, Id: 1, Group: default, AOI: (25.0, 25.0, 25.0) ] }
+--- --- ---+
Stack Trace:
+--- --- ---+
MMOExtensions.WorldExtension$ServerReadyEvent.handleServerEvent(WorldExtension.java:42)
com.smartfoxserver.v2.extensions.SFSExtension.handleServerEvent(SFSExtension.java:259)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:769)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchGlobalEvent(SFSExtensionManager.java:670)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:638)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.handleServerEvent(SFSExtensionManager.java:885)
com.smartfoxserver.v2.core.SFSEventManager$SFSEventRunner.run(SFSEventManager.java:66)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I really don't get this. Granted I am not the best at Java but in C# that would have worked just fine. Yes in C# you would want some checks in there to make sure it is actually the type you are expecting it to be but in this case I know what extension is attached to the Inventory room and it should be the InventoryExtension.