Skip to content

Commit

Permalink
Fix world script entries never having a null dPlayer. Add ternary ope…
Browse files Browse the repository at this point in the history
…rators to uses of defaultObject()
  • Loading branch information
davidcernat committed Jul 15, 2013
1 parent 35d64bd commit 0fa7ed9
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ else if (!scriptEntry.hasObject("speed")
// Use the NPC or player's locations as the location if one is not specified

scriptEntry.defaultObject("origin",
scriptEntry.getNPC().getLocation(), scriptEntry.getPlayer().getLocation());
scriptEntry.hasPlayer() ? scriptEntry.getPlayer().getLocation() : null,
scriptEntry.hasNPC() ? scriptEntry.getNPC().getLocation() : null);

// Use a default speed of 1.2 if one is not specified

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ else if (!scriptEntry.hasObject("entities")
// Use the NPC or player's locations as the location if one is not specified

scriptEntry.defaultObject("location",
scriptEntry.getNPC().getLocation(), scriptEntry.getPlayer().getLocation());
scriptEntry.hasPlayer() ? scriptEntry.getPlayer().getLocation() : null,
scriptEntry.hasNPC() ? scriptEntry.getNPC().getLocation() : null);

// Check to make sure required arguments have been filled

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ else if (!scriptEntry.hasObject("world")
// world, or default to "world" if necessary

scriptEntry.defaultObject("world",
new dWorld(scriptEntry.getNPC().getWorld()),
new dWorld(scriptEntry.getPlayer().getWorld()),
scriptEntry.hasNPC() ? new dWorld(scriptEntry.getNPC().getWorld()) : null,
scriptEntry.hasPlayer() ? new dWorld(scriptEntry.getPlayer().getWorld()) : null,
dWorld.valueOf("world"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ else if (!scriptEntry.hasObject("script")
// Use the NPC or player's locations as the origin if one is not specified

scriptEntry.defaultObject("origin",
scriptEntry.getNPC().getDenizenEntity(),
scriptEntry.getPlayer().getDenizenEntity());
scriptEntry.hasNPC() ? scriptEntry.getNPC().getDenizenEntity() : null,
scriptEntry.hasPlayer() ? scriptEntry.getPlayer().getDenizenEntity() : null);

// Use a default speed of 1.5 if one is not specified

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ else if (!scriptEntry.hasObject("target")
// Use the NPC or player's locations as the location if one is not specified

scriptEntry.defaultObject("location",
scriptEntry.getNPC().getLocation(), scriptEntry.getPlayer().getLocation());
scriptEntry.hasNPC() ? scriptEntry.getNPC().getLocation() : null,
scriptEntry.hasPlayer() ? scriptEntry.getPlayer().getLocation() : null);

// Check to make sure required arguments have been filled

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ else if (!scriptEntry.hasObject("offset")
// Use default values if necessary

scriptEntry.defaultObject("location",
scriptEntry.getNPC().getLocation(), scriptEntry.getPlayer().getLocation());
scriptEntry.hasNPC() ? scriptEntry.getNPC().getLocation() : null,
scriptEntry.hasPlayer() ? scriptEntry.getPlayer().getLocation() : null);
scriptEntry.defaultObject("data", new Element(0));
scriptEntry.defaultObject("visibility", new Element(5));
scriptEntry.defaultObject("qty", new Element(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ else if (!scriptEntry.hasObject("world")

// If the world has not been specified, try to use the NPC's or player's
// world, or default to "world" if necessary

scriptEntry.defaultObject("world",
new dWorld(scriptEntry.getNPC().getWorld()),
new dWorld(scriptEntry.getPlayer().getWorld()),
scriptEntry.hasNPC() ? new dWorld(scriptEntry.getNPC().getWorld()) : null,
scriptEntry.hasPlayer() ? new dWorld(scriptEntry.getPlayer().getWorld()) : null,
dWorld.valueOf("world"));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.aufdemrand.denizen.scripts.commands.world;

import org.bukkit.Bukkit;
import org.bukkit.WeatherType;

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
Expand Down Expand Up @@ -52,8 +53,8 @@ else if (!scriptEntry.hasObject("value")
// world, or default to "world" if necessary

scriptEntry.defaultObject("world",
new dWorld(scriptEntry.getNPC().getWorld()),
new dWorld(scriptEntry.getPlayer().getWorld()),
scriptEntry.hasNPC() ? new dWorld(scriptEntry.getNPC().getWorld()) : null,
scriptEntry.hasPlayer() ? new dWorld(scriptEntry.getPlayer().getWorld()) : null,
dWorld.valueOf("world"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ public String doEvents(List<String> eventNames, dNPC npc, Player player, Map<Str
if (!script.contains("EVENTS.ON " + eventName.toUpperCase())) continue;

// Fetch script from Event
List<ScriptEntry> entries = script.getEntries(new dPlayer(player), npc, "events.on " + eventName);
//
// Note: a "new dPlayer(null)" will not be null itself,
// so keep a ternary operator here
List<ScriptEntry> entries = script.getEntries
(player != null ? new dPlayer(player) : null,
npc, "events.on " + eventName);
if (entries.isEmpty()) continue;

dB.report("Event",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static boolean isFacingLocation(Entity from, Location at, float degreeLim
location.setYaw(location.getYaw() - 90);
}

return isFacingLocation(from, at, degreeLimit);
return isFacingLocation(location, at, degreeLimit);
}


Expand Down

0 comments on commit 0fa7ed9

Please sign in to comment.