Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Bring over patch for minor currency issues in physical currencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Jul 2, 2020
1 parent 7ea746b commit 5e68ae3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion TNE/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.tnemc</groupId>
<artifactId>TNE</artifactId>
<version>1.1.9.2</version>
<version>1.1.9.3</version>
<packaging>jar</packaging>
<name>The New Economy</name>
<properties>
Expand Down
2 changes: 1 addition & 1 deletion TNE/src/net/tnemc/core/TNE.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class TNE extends TNELib {
//constants
public static final String coreURL = "https://tnemc.net/files/module-version.xml";

public static final String build = "2Beta120";
public static final String build = "1Beta1192";
public final List<String> developers = Collections.singletonList("5bb0dcb3-98ee-47b3-8f66-3eb1cdd1a881");

//Map containing module sub commands to add to our core commands
Expand Down
13 changes: 11 additions & 2 deletions TNE/src/net/tnemc/core/common/currency/ItemCalculations.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -134,11 +135,19 @@ public static void setItems(UUID account, TNECurrency currency, BigDecimal amoun

if(consolidate) split = (amount.toPlainString() + (amount.toPlainString().contains(".")? "" : ".00")).split("\\.");

// Get a string that is exactly as long as there are decimal points.
final String truncatedMinor =
// make it longer
(split[1] + String.join("",
Collections.nCopies(Math.max(0, currency.getDecimalPlaces() - split[1].length()), "0")))
// make it shorter
.substring(0, currency.getDecimalPlaces());

if(consolidate) clearItems(currency, inventory);
BigInteger majorChange = (consolidate)? setMajorConsolidate(account, currency, new BigInteger(split[0]), inventory) :
setMajor(account, currency, new BigInteger(split[0]), add, inventory);
BigInteger minorChange = (consolidate)? setMinorConsolidate(account, currency, new BigInteger(split[1]), inventory) :
setMinor(account, currency, new BigInteger(split[1]), add, inventory);
BigInteger minorChange = (consolidate)? setMinorConsolidate(account, currency, new BigInteger(truncatedMinor), inventory) :
setMinor(account, currency, new BigInteger(truncatedMinor), add, inventory);

TNE.debug("MajorChange: " + majorChange.toString());
TNE.debug("MinorChange: " + minorChange.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collections;
import java.util.LinkedHashMap;

/**
Expand Down Expand Up @@ -107,7 +108,14 @@ public static String parseAmount(TNECurrency currency, String world, String amou
private static BigDecimal parseWeight(TNECurrency currency, BigDecimal decimal) {
String[] amountStr = (decimal.toPlainString() + (decimal.toPlainString().contains(".")? "" : ".00")).split("\\.");
BigInteger major = new BigInteger(amountStr[0]);
BigInteger minor = new BigInteger(String.format("%-" + currency.getDecimalPlaces() + "s", amountStr[1]).replace(' ', '0'));
// Get a string that is exactly as long as there are decimal points.
final String truncatedMinor =
// make it longer
(amountStr[1] + String.join("",
Collections.nCopies(Math.max(0, currency.getDecimalPlaces() - amountStr[1].length()), "0")))
// make it shorter
.substring(0, currency.getDecimalPlaces());
BigInteger minor = new BigInteger(truncatedMinor);
BigInteger majorConversion = minor;
majorConversion = majorConversion.divide(new BigInteger(currency.getMinorWeight() + ""));
major = major.add(majorConversion);
Expand Down

0 comments on commit 5e68ae3

Please sign in to comment.