Skip to content

Commit

Permalink
Read 0.8 notables correctly instead of deleting them. Change /notable…
Browse files Browse the repository at this point in the history
… add --name "Name of notable" into /notable add "Name of notable"
  • Loading branch information
davidcernat committed Jul 13, 2013
1 parent 0abab8a commit 25bff10
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 36 deletions.
22 changes: 12 additions & 10 deletions src/main/java/net/aufdemrand/denizen/CommandHandler.java
Expand Up @@ -961,19 +961,21 @@ public void text(CommandContext args, CommandSender sender, NPC npc) throws Comm

@Command(
aliases = { "notable" }, usage = "add",
desc = "For testing purposes only, use at your own risk!", modifiers = { "add" },
min = 1, max = 3, permission = "notable.basic")
desc = "Adds a new notable to your current location", modifiers = { "add", "save" },
min = 2, max = 2, permission = "notable.basic")
public void addnotable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {

if (!(sender instanceof Player)) return;

if (args.hasValueFlag("name")) {
new dLocation(((Player) sender).getLocation()).rememberAs(args.getFlag("name"));
Messaging.send(sender, "Created new notable called " + args.getFlag("name"));
return;
}
new dLocation(((Player) sender).getLocation()).rememberAs(args.getString(1));
Messaging.send(sender, "Created new notable called " + (args.getString(1)));
}

@Command(
aliases = { "notable" }, usage = "list",
desc = "Lists all notables", modifiers = { "list" },
min = 1, max = 1, permission = "notable.basic")
public void listnotable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {

else Messaging.send(sender, dLocation.uniqueObjects.toString());
Messaging.send(sender, dLocation.uniqueObjects.toString());
}

}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -121,8 +121,11 @@ public String getAttribute(Attribute attribute) {
if (attribute.startsWith("asint")
|| attribute.startsWith("as_int"))
try {
// Round the Double instead of just getting its
// value as an Integer (which would incorrectly
// turn 2.9 into 2)
return new Element(String.valueOf
(Double.valueOf(element).intValue()))
(Math.round(Double.valueOf(element))))
.getAttribute(attribute.fulfill(1)); }
catch (NumberFormatException e) {
dB.echoError("'" + element + "' is not a valid Integer.");
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/net/aufdemrand/denizen/objects/dItem.java
Expand Up @@ -73,9 +73,9 @@ public static dItem valueOf(String string) {
* Gets a Item Object from a string form.
*
* @param string The string or dScript argument String
* @param string The dPlayer to be used for player contexts
* @param dPlayer The dPlayer to be used for player contexts
* where applicable.
* @param string The dNPC to be used for NPC contexts
* @param dNPC The dNPC to be used for NPC contexts
* where applicable.
* @return an Item, or null if incorrectly formatted
*
Expand Down Expand Up @@ -302,9 +302,16 @@ public int comparesTo(ItemStack item) {

// Additional helper methods

public void setDurability(short amt) {
public void setDurability(short value) {
if (item != null)
item.setDurability(amt);
item.setDurability(value);
}

// Additional helper methods

public void setData(byte value) {
if (item != null)
item.getData().setData(value);
}

public boolean isRepairable() {
Expand Down
26 changes: 19 additions & 7 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -19,6 +19,10 @@

public class dLocation extends org.bukkit.Location implements dObject {

// This pattern correctly reads both 0.9 and 0.8 notables
final static Pattern notablePattern =
Pattern.compile("(\\w+)[;,]((-?\\d+\\.?\\d*,){3,5}\\w+)",
Pattern.CASE_INSENSITIVE);

/////////////////////
// STATIC METHODS
Expand Down Expand Up @@ -76,12 +80,20 @@ public static void remove(String id) {
* Called on server startup or /denizen reload locations. Should probably not be called manually.
*/
public static void _recallLocations() {


List<String> loclist = DenizenAPI.getCurrentInstance().getSaves().getStringList("dScript.Locations");
uniqueObjects.clear();
for (String location : loclist) {
String id = location.split(";")[0];
dLocation loc = valueOf(location.split(";")[1]);
uniqueObjects.put(id, loc);

Matcher m = notablePattern.matcher(location);

if (m.matches()) {

String id = m.group(1);
dLocation loc = valueOf(m.group(2));
uniqueObjects.put(id, loc);
}
}
}

Expand Down Expand Up @@ -179,7 +191,7 @@ public static boolean matches(String string) {
return true;

final Pattern location =
Pattern.compile("((-?\\d+(\\.\\d+)?,){3}|(-?\\d+(\\.\\d+)?,){5})\\w+",
Pattern.compile("(-?\\d+\\.?\\d*,){3,5}\\w+",
Pattern.CASE_INSENSITIVE);
m = location.matcher(string);
if (m.matches())
Expand Down Expand Up @@ -545,15 +557,15 @@ else return new Element(String.valueOf(this.distance(toLocation)))
}

if (attribute.startsWith("block.x")) {
return new Element(getBlockX()).getAttribute(attribute.fulfill(1));
return new Element(getBlockX()).getAttribute(attribute.fulfill(2));
}

if (attribute.startsWith("block.y")) {
return new Element(getBlockY()).getAttribute(attribute.fulfill(1));
return new Element(getBlockY()).getAttribute(attribute.fulfill(2));
}

if (attribute.startsWith("block.z")) {
return new Element(getBlockZ()).getAttribute(attribute.fulfill(1));
return new Element(getBlockZ()).getAttribute(attribute.fulfill(2));
}

if (attribute.startsWith("x")) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -6,7 +6,6 @@
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizen.utilities.entity.Rotation;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down
Expand Up @@ -218,7 +218,7 @@ public void registerCoreMembers() {
"OXYGEN", "oxygen (type:maximum/remaining) (mode:set/add/remove) [qty:<#>]", 1);

registerCoreMember(PlayEffectCommand.class,
"PLAYEFFECT", "playeffect [<location>] [effect:<name>] (qty:<#>) (radius:<#.#>) (data:<#.#>) (offset:<#.#>)", 2);
"PLAYEFFECT", "playeffect [<location>] [effect:<name>] (data:<#.#>) (visibility:<#.#>) (qty:<#>) (offset:<#.#>)", 2);

registerCoreMember(PlaySoundCommand.class,
"PLAYSOUND", "playsound [<location>] [sound:<name>] (volume:<#.#>) (pitch:<#.#>)", 2);
Expand Down
Expand Up @@ -21,7 +21,7 @@
* [location:<x,y,z,world>] specifies location of the effect
* [effect:<name>] sets the name of effect to be played
* (data:<#>) sets the special data value of the effect
* (radius:<#>) adjusts the radius within which players will observe the effect
* (visibility:<#>) adjusts the radius within which players can observe the effect
* (qty:<#>) sets the number of times the effect will be played
* (offset:<#>) sets the offset of ParticleEffects.
*
Expand Down Expand Up @@ -60,11 +60,11 @@ else if (arg.matchesEnum(ParticleEffect.values())) {
}
}

else if (!scriptEntry.hasObject("radius")
else if (!scriptEntry.hasObject("visibility")
&& arg.matchesPrimitive(aH.PrimitiveType.Double)
&& arg.matchesPrefix("range, radius, r")) {
&& arg.matchesPrefix("visibility, v, radius, r")) {
// Add value
scriptEntry.addObject("radius", arg.asElement());
scriptEntry.addObject("visibility", arg.asElement());
}

else if (!scriptEntry.hasObject("data")
Expand Down Expand Up @@ -100,14 +100,14 @@ else if (!scriptEntry.hasObject("offset")

// Use default values if necessary

if ((!scriptEntry.hasObject("radius"))) {
scriptEntry.addObject("radius", new Element(5));
}

if ((!scriptEntry.hasObject("data"))) {
scriptEntry.addObject("data", new Element(0));
}

if ((!scriptEntry.hasObject("visibility"))) {
scriptEntry.addObject("visibility", new Element(5));
}

if ((!scriptEntry.hasObject("qty"))) {
scriptEntry.addObject("qty", new Element(1));
}
Expand All @@ -124,7 +124,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dLocation location = (dLocation) scriptEntry.getObject("location");
Effect effect = (Effect) scriptEntry.getObject("effect");
ParticleEffect particleEffect = (ParticleEffect) scriptEntry.getObject("particleeffect");
Element radius = (Element) scriptEntry.getObject("radius");
Element visibility = (Element) scriptEntry.getObject("visibility");
Element data = (Element) scriptEntry.getObject("data");
Element qty = (Element) scriptEntry.getObject("qty");
Element offset = (Element) scriptEntry.getObject("offset");
Expand All @@ -139,7 +139,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
aH.debugObj("effect", effect.name()) :
aH.debugObj("special effect", particleEffect.name())) +
aH.debugObj("location", location.toString()) +
aH.debugObj("radius", radius) +
aH.debugObj("radius", visibility) +
aH.debugObj("data", data) +
aH.debugObj("qty", qty) +
(effect != null ? "" : aH.debugObj("offset", offset)));
Expand All @@ -148,13 +148,13 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
if (effect != null) {

for (int n = 0; n < qty.asInt(); n++) {
location.getWorld().playEffect(location, effect, data.asInt(), radius.asInt());
location.getWorld().playEffect(location, effect, data.asInt(), visibility.asInt());
}
}
// Play a ParticleEffect
else {
ParticleEffect.valueOf(particleEffect.name())
.play(location, radius.asDouble(),
.play(location, visibility.asDouble(),
offset.asFloat(), offset.asFloat(), offset.asFloat(), data.asFloat(), qty.asInt());
}
}
Expand Down

0 comments on commit 25bff10

Please sign in to comment.