Skip to content

Commit

Permalink
Add server.object_is_valid
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 17, 2015
1 parent 8a224be commit bce96e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ public static dLocation valueOf(String string, TagContext context) {
Double.valueOf(split[0]),
Double.valueOf(split[1]));
} catch (Exception e) {
dB.echoError("valueOf dLocation returning null: " + string + "(internal exception:" + e.getMessage() + ")");
if (context == null || context.debug) {
dB.echoError("valueOf dLocation returning null: " + string + "(internal exception:" + e.getMessage() + ")");
}
return null;
}
if (split.length == 3)
Expand All @@ -157,7 +159,9 @@ public static dLocation valueOf(String string, TagContext context) {
Double.valueOf(split[1]),
Double.valueOf(split[2]));
} catch(Exception e) {
dB.echoError("valueOf dLocation returning null: " + string + "(internal exception:" + e.getMessage() + ")");
if (context == null || context.debug) {
dB.echoError("valueOf dLocation returning null: " + string + "(internal exception:" + e.getMessage() + ")");
}
return null;
}

Expand All @@ -170,7 +174,9 @@ else if (split.length == 4)
Double.valueOf(split[1]),
Double.valueOf(split[2]));
} catch(Exception e) {
dB.echoError("valueOf dLocation returning null: " + string + "(internal exception:" + e.getMessage() + ")");
if (context == null || context.debug) {
dB.echoError("valueOf dLocation returning null: " + string + "(internal exception:" + e.getMessage() + ")");
}
return null;
}

Expand All @@ -188,11 +194,15 @@ else if (split.length == 6)
Float.valueOf(split[4]));

} catch(Exception e) {
dB.echoError("valueOf dLocation returning null: " + string + "(internal exception:" + e.getMessage() + ")");
if (context == null || context.debug) {
dB.echoError("valueOf dLocation returning null: " + string + "(internal exception:" + e.getMessage() + ")");
}
return null;
}

dB.log("valueOf dLocation returning null: " + string);
if (context == null || context.debug) {
dB.log("valueOf dLocation returning null: " + string);
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2868,7 +2868,7 @@ public void registerCoreMembers() {
// @Required 2
// @Stable stable
// @Short Edits a YAML configuration file.
// @Author aufdemrand
// @Author aufdemrand, mcmonkey
// @Group core
// @Description
// Edits a YAML configuration file.
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/aufdemrand/denizen/tags/core/ServerTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.Settings;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizencore.events.OldEventManager;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.objects.*;
Expand Down Expand Up @@ -101,6 +102,18 @@ public void serverTag(ReplaceableTagEvent event) {
if (!event.matches("server", "svr", "global") || event.replaced()) return;
Attribute attribute = event.getAttributes().fulfill(1);

// <--[tag]
// @attribute <server.object_is_valid[<object>]>
// @returns Element(boolean)
// @description
// returns whether the object is a valid object (non-null), as well as not an Element.
// -->
if (attribute.startsWith("object_is_valid")) {
dObject o = ObjectFetcher.pickObjectFor(attribute.getContext(1), new BukkitTagContext(null, null, false, null, false, null));
event.setReplaced(new Element(!(o == null || o instanceof Element)).getAttribute(attribute.fulfill(1)));
return;
}

// <--[tag]
// @attribute <server.has_flag[<flag_name>]>
// @returns Element(boolean)
Expand All @@ -115,6 +128,7 @@ public void serverTag(ReplaceableTagEvent event) {
return;
}
event.setReplaced(new Element(FlagManager.serverHasFlag(flag_name)).getAttribute(attribute.fulfill(1)));
return;
}

// <--[tag]
Expand Down

0 comments on commit bce96e3

Please sign in to comment.