Skip to content

Commit

Permalink
Throw invalidargumentsexception if all defaultObject objects are null.
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Aug 8, 2013
1 parent f20616c commit 2da8b85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/main/java/net/aufdemrand/denizen/scripts/ScriptEntry.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package net.aufdemrand.denizen.scripts;

import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.exceptions.ScriptEntryCreationException;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.scripts.queues.ScriptQueue;
import net.aufdemrand.denizen.utilities.debugging.dB;

import java.util.*;

Expand Down Expand Up @@ -90,17 +92,17 @@ public ScriptEntry addObject(String key, Object object) {
*
*/

public ScriptEntry defaultObject(String key, Object... objects) {

if (this.hasObject(key) == false) {
for (Object obj : objects) {
public ScriptEntry defaultObject(String key, Object... objects) throws InvalidArgumentsException {
if (!hasObject(key))
for (Object obj : objects)
if (obj != null) {
this.addObject(key, obj);
break;
}
}
}
return this;
// Check if the object has been filled. If not, throw new Invalid Arguments Exception.
if (!hasObject(key)) throw new InvalidArgumentsException(dB.Messages.ERROR_MISSING_OTHER, key);
else
return this;
}

public List<String> getArguments() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ else if (!scriptEntry.hasObject("duration")
scriptEntry.addObject("duration", arg.asType(Duration.class));
}

if (!scriptEntry.hasObject("script"))
scriptEntry.addObject("script", scriptEntry.getScript());
scriptEntry.defaultObject("script", scriptEntry.getScript());

if (!scriptEntry.hasPlayer() || !scriptEntry.getPlayer().isValid())
throw new InvalidArgumentsException("Must have player context!");
Expand Down

0 comments on commit 2da8b85

Please sign in to comment.