Permalink
Browse files

Return success + error message instead of throwing an exception

Closes #328
  • Loading branch information...
SquidDev committed Jun 27, 2017
1 parent ae78a8f commit 1d9cd080b7031adb0c939acead5697f938da55d2
Showing with 9 additions and 7 deletions.
  1. +9 −7 src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java
@@ -75,12 +75,12 @@ public void shutdown()
{
if( !(m_computer.getEntity() instanceof EntityPlayer) )
{
throw new LuaException( "Cannot find player" );
return new Object[] { false, "Cannot find player" };
}
EntityPlayer player = (EntityPlayer) m_computer.getEntity();
InventoryPlayer inventory = player.inventory;
if( !m_computer.inInventory() ) throw new LuaException( "Not in an inventory" );
if( !m_computer.inInventory() ) return new Object[] { false, "Not in an inventory" };
IPocketUpgrade previousUpgrade = m_computer.getUpgrade();
@@ -91,7 +91,7 @@ public void shutdown()
{
newUpgrade = findUpgrade( inventory.offHandInventory, 0, previousUpgrade );
}
if( newUpgrade == null ) throw new LuaException( "Cannot find a valid upgrade" );
if( newUpgrade == null ) return new Object[] { false, "Cannot find a valid upgrade" };
// Remove the current upgrade
if( previousUpgrade != null )
@@ -110,7 +110,7 @@ public void shutdown()
// Set the new upgrade
m_computer.setUpgrade( newUpgrade );
return null;
return new Object[] { true };
} );
case 1:
@@ -119,15 +119,15 @@ public void shutdown()
{
if( !(m_computer.getEntity() instanceof EntityPlayer) )
{
throw new LuaException( "Cannot find player" );
return new Object[] { false, "Cannot find player" };
}
EntityPlayer player = (EntityPlayer) m_computer.getEntity();
InventoryPlayer inventory = player.inventory;
if( !m_computer.inInventory() ) throw new LuaException( "Not in an inventory" );
if( !m_computer.inInventory() ) return new Object[] { false, "Not in an inventory" };
IPocketUpgrade previousUpgrade = m_computer.getUpgrade();
if( previousUpgrade == null ) throw new LuaException( "Nothing to unequip" );
if( previousUpgrade == null ) return new Object[] { false, "Nothing to unequip" };
m_computer.setUpgrade( null );
@@ -139,6 +139,8 @@ public void shutdown()
{
WorldUtil.dropItemStack( stack, player.getEntityWorld(), player.posX, player.posY, player.posZ );
}
return new Object[] { true };
}
return null;

0 comments on commit 1d9cd08

Please sign in to comment.