Skip to content

Commit

Permalink
Added CMI hook, numbers are no longer displayed in scientific notation.
Browse files Browse the repository at this point in the history
  • Loading branch information
biscuut committed Jul 7, 2019
1 parent 7b2f218 commit 1b76d0b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 8 deletions.
8 changes: 7 additions & 1 deletion SellChestPlugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>SellChestPlugin</artifactId>
<packaging>jar</packaging>
<name>SellChestPlugin</name>
<version>1.1.1-B1</version>
<version>1.1.1</version>

<repositories>
<repository>
Expand Down Expand Up @@ -115,6 +115,12 @@
<version>MC_1_14</version>
<scope>compile</scope>
</dependency>
<dependency>
<artifactId>CMI</artifactId>
<groupId>CMI</groupId>
<version>8.6.5.2</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package codes.biscuit.sellchest.hooks;

import com.Zrips.CMI.Modules.Worth.WorthItem;
import org.bukkit.inventory.ItemStack;
import com.Zrips.CMI.CMI;

class CMIHook {

double getSellPrice(ItemStack sellItem) {
WorthItem worth = CMI.getInstance().getWorthManager().getWorth(sellItem);
if (worth != null) {
return worth.getSellPrice() * sellItem.getAmount();
} else {
return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class EssentialsHook {
}

double getSellPrice(ItemStack sellItem) {
// BigDecimal price = essentials.getWorth().getPrice(sellItem);
try {
Worth worth = essentials.getWorth();
BigDecimal price;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ public HookUtils(SellChest main) {
main.getLogger().info("Hooked into PlotSquared");
enabledHooks.put(Hooks.PLOTSQUARED, new PlotSquaredHook());
}
if (main.getMinecraftVersion() >= 14) {
if (pm.getPlugin("CMI") != null) {
main.getLogger().info("Hooked into CMI");
enabledHooks.put(Hooks.CMI, new CMIHook());
}
if (main.getMinecraftVersion() >= 14) {
enabledHooks.put(Hooks.MINECRAFT_1_14, new Minecraft_1_14());
}
}

public double getValue(ItemStack sellItem, Player p) {
if (main.getConfigValues().essentialsHookEnabled() && enabledHooks.containsKey(Hooks.ESSENTIALS)) {
return ((EssentialsHook)enabledHooks.get(Hooks.ESSENTIALS)).getSellPrice(sellItem);
return ((EssentialsHook) enabledHooks.get(Hooks.ESSENTIALS)).getSellPrice(sellItem);
} else if (main.getConfigValues().cmiHookEnabled() && enabledHooks.containsKey(Hooks.CMI)) {
return ((CMIHook)enabledHooks.get(Hooks.CMI)).getSellPrice(sellItem);
} else if (main.getConfigValues().shopGUIPlusHookEnabled() && enabledHooks.containsKey(Hooks.SHOPGUIPLUS)) {
if (p == null) {
if (main.getConfigValues().workaroundEnabled()) {
Expand Down Expand Up @@ -191,7 +197,8 @@ enum Hooks {
SHOPGUIPLUS,
ASKYBLOCK,
PLOTSQUARED,
MINECRAFT_1_14
MINECRAFT_1_14,
CMI
}

public enum MoneyRecipient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public boolean essentialsHookEnabled() {
return main.getConfig().getBoolean("hooks.essentials");
}

public boolean cmiHookEnabled() {
return main.getConfig().getBoolean("hooks.cmi");
}

public boolean shopGUIPlusHookEnabled() {
return main.getConfig().getBoolean("hooks.shopguiplus");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
Expand Down Expand Up @@ -146,7 +148,7 @@ public void runMessageTimer() {
for (Map.Entry<OfflinePlayer, Double> entry : main.getHookUtils().getMoneyHistory().entrySet()) {
if (entry.getKey().isOnline()) {
Player p = entry.getKey().getPlayer();
main.getUtils().sendMessage(p, ConfigValues.Message.RECENTLY_EARNED, entry.getValue());
main.getUtils().sendMessage(p, ConfigValues.Message.RECENTLY_EARNED, round(entry.getValue()));
}
}
main.getHookUtils().getMoneyHistory().clear();
Expand Down Expand Up @@ -192,7 +194,7 @@ public Set<OfflinePlayer> getBypassPlayers() {
}

public void updateConfig(SellChest main) {
if (main.getConfigValues().getConfigVersion() < 1.3) {
if (main.getConfigValues().getConfigVersion() < 1.4) {
Map<String, Object> oldValues = new HashMap<>();
for (String oldKey : main.getConfig().getKeys(true)) {
oldValues.put(oldKey, main.getConfig().get(oldKey));
Expand All @@ -204,7 +206,7 @@ public void updateConfig(SellChest main) {
main.getConfig().set(newKey, oldValues.get(newKey));
}
}
main.getConfig().set("config-version", 1.3);
main.getConfig().set("config-version", 1.4);
main.saveConfig();
}
}
Expand Down Expand Up @@ -305,4 +307,10 @@ public boolean reachedLimit(Player p) {
}
return false;
}

private double round(double value) {
BigDecimal bd = new BigDecimal(value);
bd = bd.setScale(2, RoundingMode.HALF_UP);
return bd.doubleValue();
}
}
3 changes: 2 additions & 1 deletion SellChestPlugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ hooks:
askyblock: false
factions: true
plotsquared: false
cmi: false

# Allow the plugin to fetch ShopGUI+ prices while the money recipient is offline.
# This workaround will instead take the prices from any random online player. Would only recommend
Expand Down Expand Up @@ -106,4 +107,4 @@ prices:
update-messages: true

# Please do not change this!
config-version: 1.3
config-version: 1.4

0 comments on commit 1b76d0b

Please sign in to comment.