Skip to content

Commit

Permalink
Throw exception when trying to reuse ID
Browse files Browse the repository at this point in the history
  • Loading branch information
jb-aero committed Oct 24, 2018
1 parent 6a594f1 commit 491c18c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/com/laytonsmith/core/functions/Trades.java
Expand Up @@ -203,16 +203,16 @@ public static class create_virtual_merchant extends Recipes.recipeFunction {

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[0];
return new Class[] {CREIllegalArgumentException.class};
}

@Override
public Construct exec(Target t, Environment env, Construct... args) throws ConfigRuntimeException {
if(VIRTUAL_MERCHANTS.containsKey(args[0].val())) {
return CBoolean.FALSE;
throw new CREIllegalArgumentException("There is already a merchant with id " + args[0].val(), t);
} else {
VIRTUAL_MERCHANTS.put(args[0].val(), Static.getServer().createMerchant(args[1].val()));
return CBoolean.TRUE;
return CVoid.VOID;
}
}

Expand All @@ -233,11 +233,11 @@ public Integer[] numArgs() {

@Override
public String docs() {
return "boolean {ID, title} Creates a merchant that can be traded with by players but is not attached to"
+ " a physical entity. Will return true if the ID was newly added, and false if the ID was already"
+ " in use. The ID given should not be a UUID. The title is the text that will display at the top"
+ " of the window while a player is trading with it. This list will persist across recompiles,"
+ " but not across server restarts.";
return "void {ID, title} Creates a merchant that can be traded with by players but is not attached to"
+ " a physical entity. The ID given should not be a UUID. The title is the text that will display"
+ " at the top of the window while a player is trading with it. Created merchants will persist"
+ " across recompiles, but not across server restarts. An exception will be thrown if a merchant"
+ " already exists using the given ID.";
}
}

Expand Down

0 comments on commit 491c18c

Please sign in to comment.