Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.whimc</groupId>
<artifactId>WHIMC-ScienceTools</artifactId>
<version>2.4.10</version>
<version>2.4.11</version>
<name>WHIMC Science Tools</name>
<description>Simulate values for scientific tools</description>
<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ public class Conversion {
private String unit;
/* The expression to calculate the passed value in the new unit*/
private JSNumericExpression expression;
/* The decimal precision of the tool. */
private final int precision;

/**
* Constructs a Conversion.
*
* @param name The name of the Conversion.
* @param unit The unit being converted to.
* @param expression The Conversion equation.
* @param precision The number of places after the decimal place to include
*/
protected Conversion(String name, String unit, JSNumericExpression expression) {
protected Conversion(String name, String unit, JSNumericExpression expression, int precision) {
this.name = name;
this.unit = unit;
this.expression = expression;
this.precision = precision;
}

/**
Expand All @@ -52,6 +56,10 @@ public String getUnit() {
return this.unit;
}

public int getPrecision() {
return this.precision;
}

/**
* Sets a new unit and saves it to the config.
*
Expand Down Expand Up @@ -86,7 +94,8 @@ public void sendInfo(CommandSender sender) {
Utils.msg(sender,
getName() + ":",
" Expression: " + getExpression(),
" Unit: " + getUnit());
" Unit: " + getUnit(),
" Precision: " + getPrecision());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import edu.whimc.sciencetools.ScienceTools;
import edu.whimc.sciencetools.javascript.JSNumericExpression;
import edu.whimc.sciencetools.utils.Utils;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import scala.Int;

/**
* Handles operations regarding Conversions (adding, removing, saving, loading).
Expand Down Expand Up @@ -36,9 +36,12 @@ public void loadConversions() {
Utils.log("&b - &f" + conversion);
String expr = config.getString("conversions." + conversion + ".expression");
String unit = config.getString("conversions." + conversion + ".unit");
int precision = config.getInt("conversions." + conversion + ".precision");
//no idea if this needs to go in the log ^

Utils.log("&b\t- Expression: \"&f" + expr + "&b\"");
Utils.log("&b\t- Unit: \"&f" + unit + "&b\"");
Utils.log("&b\t- Precision: \"&f" + precision + "&b\"");

// ensure conversion's expression is valid, skip if not
JSNumericExpression jsExpr = new JSNumericExpression(expr);
Expand All @@ -47,7 +50,7 @@ public void loadConversions() {
continue;
}

loadConversion(conversion, unit, jsExpr);
loadConversion(conversion, unit, jsExpr, precision);
}

Utils.log("&eConversions loaded!");
Expand All @@ -59,10 +62,11 @@ public void loadConversions() {
* @param name The name of the Conversion.
* @param unit The unit being converted to.
* @param expr The Conversion equation.
* @param precision The number of places after the decimal place to include.
* @return The Conversion.
*/
private @NotNull Conversion loadConversion(String name, String unit, JSNumericExpression expr) {
Conversion conversion = new Conversion(name, unit, expr);
private @NotNull Conversion loadConversion(String name, String unit, JSNumericExpression expr, int precision) {
Conversion conversion = new Conversion(name, unit, expr, precision);
conversions.put(name, conversion);
return conversion;
}
Expand All @@ -75,8 +79,8 @@ public void loadConversions() {
* @param expr The Conversion equation.
* @return The Conversion.
*/
public Conversion createConversion(String name, String unit, JSNumericExpression expr) {
Conversion conversion = loadConversion(name, unit, expr);
public Conversion createConversion(String name, String unit, JSNumericExpression expr, int precision) {
Conversion conversion = loadConversion(name, unit, expr, precision);
saveToConfig(conversion);
return conversion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public NumericScienceTool(String toolKey,

// display converted values
for (Conversion conversion : conversions) {
String converted = Utils.trimDecimals(conversion.convert(data), precision);
//conversions now have their own separate precision; not sure what happens if it's left out of the config?
//does an unassigned int in Java have a value of 0? Or is it null and does null == 0 in this case?
String converted = Utils.trimDecimals(conversion.convert(data), conversion.getPrecision());
message += " (" + converted + conversion.getUnit() + ")";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import edu.whimc.sciencetools.models.Measurement;
import edu.whimc.sciencetools.utils.Utils;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import me.pikamug.quests.quests.Quest;
import me.pikamug.quests.module.BukkitCustomObjective;
import me.pikamug.quests.Quests;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;

/**
* A custom objective for the Quests plugin.
Expand Down