Skip to content

Commit 1b76d0b

Browse files
committed
Added CMI hook, numbers are no longer displayed in scientific notation.
1 parent 7b2f218 commit 1b76d0b

7 files changed

Lines changed: 52 additions & 8 deletions

File tree

SellChestPlugin/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<artifactId>SellChestPlugin</artifactId>
99
<packaging>jar</packaging>
1010
<name>SellChestPlugin</name>
11-
<version>1.1.1-B1</version>
11+
<version>1.1.1</version>
1212

1313
<repositories>
1414
<repository>
@@ -115,6 +115,12 @@
115115
<version>MC_1_14</version>
116116
<scope>compile</scope>
117117
</dependency>
118+
<dependency>
119+
<artifactId>CMI</artifactId>
120+
<groupId>CMI</groupId>
121+
<version>8.6.5.2</version>
122+
<scope>provided</scope>
123+
</dependency>
118124
</dependencies>
119125

120126
<build>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package codes.biscuit.sellchest.hooks;
2+
3+
import com.Zrips.CMI.Modules.Worth.WorthItem;
4+
import org.bukkit.inventory.ItemStack;
5+
import com.Zrips.CMI.CMI;
6+
7+
class CMIHook {
8+
9+
double getSellPrice(ItemStack sellItem) {
10+
WorthItem worth = CMI.getInstance().getWorthManager().getWorth(sellItem);
11+
if (worth != null) {
12+
return worth.getSellPrice() * sellItem.getAmount();
13+
} else {
14+
return 0;
15+
}
16+
}
17+
}

SellChestPlugin/src/main/java/codes/biscuit/sellchest/hooks/EssentialsHook.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class EssentialsHook {
2020
}
2121

2222
double getSellPrice(ItemStack sellItem) {
23+
// BigDecimal price = essentials.getWorth().getPrice(sellItem);
2324
try {
2425
Worth worth = essentials.getWorth();
2526
BigDecimal price;

SellChestPlugin/src/main/java/codes/biscuit/sellchest/hooks/HookUtils.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,20 @@ public HookUtils(SellChest main) {
4949
main.getLogger().info("Hooked into PlotSquared");
5050
enabledHooks.put(Hooks.PLOTSQUARED, new PlotSquaredHook());
5151
}
52-
if (main.getMinecraftVersion() >= 14) {
52+
if (pm.getPlugin("CMI") != null) {
53+
main.getLogger().info("Hooked into CMI");
54+
enabledHooks.put(Hooks.CMI, new CMIHook());
55+
}
56+
if (main.getMinecraftVersion() >= 14) {
5357
enabledHooks.put(Hooks.MINECRAFT_1_14, new Minecraft_1_14());
5458
}
5559
}
5660

5761
public double getValue(ItemStack sellItem, Player p) {
5862
if (main.getConfigValues().essentialsHookEnabled() && enabledHooks.containsKey(Hooks.ESSENTIALS)) {
59-
return ((EssentialsHook)enabledHooks.get(Hooks.ESSENTIALS)).getSellPrice(sellItem);
63+
return ((EssentialsHook) enabledHooks.get(Hooks.ESSENTIALS)).getSellPrice(sellItem);
64+
} else if (main.getConfigValues().cmiHookEnabled() && enabledHooks.containsKey(Hooks.CMI)) {
65+
return ((CMIHook)enabledHooks.get(Hooks.CMI)).getSellPrice(sellItem);
6066
} else if (main.getConfigValues().shopGUIPlusHookEnabled() && enabledHooks.containsKey(Hooks.SHOPGUIPLUS)) {
6167
if (p == null) {
6268
if (main.getConfigValues().workaroundEnabled()) {
@@ -191,7 +197,8 @@ enum Hooks {
191197
SHOPGUIPLUS,
192198
ASKYBLOCK,
193199
PLOTSQUARED,
194-
MINECRAFT_1_14
200+
MINECRAFT_1_14,
201+
CMI
195202
}
196203

197204
public enum MoneyRecipient {

SellChestPlugin/src/main/java/codes/biscuit/sellchest/utils/ConfigValues.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public boolean essentialsHookEnabled() {
121121
return main.getConfig().getBoolean("hooks.essentials");
122122
}
123123

124+
public boolean cmiHookEnabled() {
125+
return main.getConfig().getBoolean("hooks.cmi");
126+
}
127+
124128
public boolean shopGUIPlusHookEnabled() {
125129
return main.getConfig().getBoolean("hooks.shopguiplus");
126130
}

SellChestPlugin/src/main/java/codes/biscuit/sellchest/utils/Utils.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.io.BufferedReader;
2323
import java.io.IOException;
2424
import java.io.InputStreamReader;
25+
import java.math.BigDecimal;
26+
import java.math.RoundingMode;
2527
import java.net.URL;
2628
import java.net.URLConnection;
2729
import java.util.*;
@@ -146,7 +148,7 @@ public void runMessageTimer() {
146148
for (Map.Entry<OfflinePlayer, Double> entry : main.getHookUtils().getMoneyHistory().entrySet()) {
147149
if (entry.getKey().isOnline()) {
148150
Player p = entry.getKey().getPlayer();
149-
main.getUtils().sendMessage(p, ConfigValues.Message.RECENTLY_EARNED, entry.getValue());
151+
main.getUtils().sendMessage(p, ConfigValues.Message.RECENTLY_EARNED, round(entry.getValue()));
150152
}
151153
}
152154
main.getHookUtils().getMoneyHistory().clear();
@@ -192,7 +194,7 @@ public Set<OfflinePlayer> getBypassPlayers() {
192194
}
193195

194196
public void updateConfig(SellChest main) {
195-
if (main.getConfigValues().getConfigVersion() < 1.3) {
197+
if (main.getConfigValues().getConfigVersion() < 1.4) {
196198
Map<String, Object> oldValues = new HashMap<>();
197199
for (String oldKey : main.getConfig().getKeys(true)) {
198200
oldValues.put(oldKey, main.getConfig().get(oldKey));
@@ -204,7 +206,7 @@ public void updateConfig(SellChest main) {
204206
main.getConfig().set(newKey, oldValues.get(newKey));
205207
}
206208
}
207-
main.getConfig().set("config-version", 1.3);
209+
main.getConfig().set("config-version", 1.4);
208210
main.saveConfig();
209211
}
210212
}
@@ -305,4 +307,10 @@ public boolean reachedLimit(Player p) {
305307
}
306308
return false;
307309
}
310+
311+
private double round(double value) {
312+
BigDecimal bd = new BigDecimal(value);
313+
bd = bd.setScale(2, RoundingMode.HALF_UP);
314+
return bd.doubleValue();
315+
}
308316
}

SellChestPlugin/src/main/resources/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ hooks:
6868
askyblock: false
6969
factions: true
7070
plotsquared: false
71+
cmi: false
7172

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

108109
# Please do not change this!
109-
config-version: 1.3
110+
config-version: 1.4

0 commit comments

Comments
 (0)