This commit is contained in:
AlgorithmX2
2014-04-09 20:12:49 -05:00
14 changed files with 61 additions and 21 deletions
+26 -3
View File
@@ -201,7 +201,15 @@ public enum GuiBridge implements IGuiHandler
Constructor[] c = Container.getConstructors();
if ( c.length == 0 )
throw new AppEngException( "Invalid Gui Class" );
return findConstructor( c, inventory, tE ).newInstance( inventory, tE );
Constructor target = findConstructor( c, inventory, tE );
if ( target == null )
{
throw new RuntimeException( "Cannot find " + Container.getName() + "( " + typeName( inventory ) + ", " + typeName( tE ) + " )" );
}
return target.newInstance( inventory, tE );
}
catch (Throwable t)
{
@@ -217,7 +225,14 @@ public enum GuiBridge implements IGuiHandler
if ( c.length == 0 )
throw new AppEngException( "Invalid Gui Class" );
return findConstructor( c, inventory, tE ).newInstance( inventory, tE );
Constructor target = findConstructor( c, inventory, tE );
if ( target == null )
{
throw new RuntimeException( "Cannot find " + Container.getName() + "( " + typeName( inventory ) + ", " + typeName( tE ) + " )" );
}
return target.newInstance( inventory, tE );
}
catch (Throwable t)
{
@@ -225,6 +240,14 @@ public enum GuiBridge implements IGuiHandler
}
}
private String typeName(Object inventory)
{
if ( inventory == null )
return "NULL";
return inventory.getClass().getName();
}
private Constructor findConstructor(Constructor[] c, InventoryPlayer inventory, Object tE)
{
for (Constructor con : c)
@@ -232,7 +255,7 @@ public enum GuiBridge implements IGuiHandler
Class[] types = con.getParameterTypes();
if ( types.length == 2 )
{
if ( types[0] == inventory.getClass() && types[1].isAssignableFrom( tE.getClass() ) )
if ( types[0].isAssignableFrom( inventory.getClass() ) && types[1].isAssignableFrom( tE.getClass() ) )
return con;
}
}