Skip to content

Commit

Permalink
Now don't throws exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Khanx committed May 30, 2018
1 parent da10bb1 commit 057de0b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions AdvancedWand/AdvancedWand/Helper/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ private static bool CheckBlock(Players.Player player, ushort block)
if(0 == block) //Air block
return true;

ItemTypes.ItemType type = ItemTypes.GetType(block);
if(!ItemTypes.TryGetType(block, out ItemTypes.ItemType type))
{
Pipliz.Chatting.Chat.Send(player, "<color=red>Block not found</color>");
return false;
}

if(!type.IsPlaceable || type.NeedsBase || !ItemTypes.NotableTypes.Contains(type))
{
Expand All @@ -64,14 +68,9 @@ public static bool GetBlockIndex(Players.Player player, string block, out ushort
{
blockIndex = 0;

try
{
if(int.TryParse(block, out int IDBlock))
blockIndex = (ushort)IDBlock;
else
blockIndex = ItemTypes.IndexLookup.GetIndex(block);
}
catch(System.ArgumentException)
if(int.TryParse(block, out int IDBlock))
blockIndex = (ushort)IDBlock;
else if(!ItemTypes.IndexLookup.TryGetIndex(block, out blockIndex))
{
Pipliz.Chatting.Chat.Send(player, "<color=red>Block not found</color>");
return false;
Expand Down

0 comments on commit 057de0b

Please sign in to comment.