diff --git a/src/main/java/net/aufdemrand/denizen/CommandHandler.java b/src/main/java/net/aufdemrand/denizen/CommandHandler.java index 49245b12a0..cfae23d197 100644 --- a/src/main/java/net/aufdemrand/denizen/CommandHandler.java +++ b/src/main/java/net/aufdemrand/denizen/CommandHandler.java @@ -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()); } } diff --git a/src/main/java/net/aufdemrand/denizen/objects/Element.java b/src/main/java/net/aufdemrand/denizen/objects/Element.java index c9a55a8749..a0b9bf4434 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/Element.java +++ b/src/main/java/net/aufdemrand/denizen/objects/Element.java @@ -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."); diff --git a/src/main/java/net/aufdemrand/denizen/objects/dItem.java b/src/main/java/net/aufdemrand/denizen/objects/dItem.java index e781e5f075..fe87667cf2 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dItem.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dItem.java @@ -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 * @@ -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() { diff --git a/src/main/java/net/aufdemrand/denizen/objects/dLocation.java b/src/main/java/net/aufdemrand/denizen/objects/dLocation.java index 6760ceeb28..63ab74ab6d 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dLocation.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dLocation.java @@ -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 @@ -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 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); + } } } @@ -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()) @@ -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")) { diff --git a/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java b/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java index 3f3813d8c2..86f5e2addc 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java @@ -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; diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java index 41c8b84402..0ba9eda012 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java @@ -218,7 +218,7 @@ public void registerCoreMembers() { "OXYGEN", "oxygen (type:maximum/remaining) (mode:set/add/remove) [qty:<#>]", 1); registerCoreMember(PlayEffectCommand.class, - "PLAYEFFECT", "playeffect [] [effect:] (qty:<#>) (radius:<#.#>) (data:<#.#>) (offset:<#.#>)", 2); + "PLAYEFFECT", "playeffect [] [effect:] (data:<#.#>) (visibility:<#.#>) (qty:<#>) (offset:<#.#>)", 2); registerCoreMember(PlaySoundCommand.class, "PLAYSOUND", "playsound [] [sound:] (volume:<#.#>) (pitch:<#.#>)", 2); diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlayEffectCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlayEffectCommand.java index 524bb854c6..128ff0491c 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlayEffectCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlayEffectCommand.java @@ -21,7 +21,7 @@ * [location:] specifies location of the effect * [effect:] 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. * @@ -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") @@ -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)); } @@ -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"); @@ -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))); @@ -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()); } }