mirror of
https://github.com/CarmJos/UltraDepository.git
synced 2026-06-04 16:48:21 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6bf8e261d0 | |||
| fcdda893f1 | |||
| 27ad14c7ab | |||
| b6a6502713 | |||
| d8d589ba76 |
@@ -176,6 +176,9 @@
|
||||
# UltraDepository.use
|
||||
- 超级仓库的基本使用权限 (默认所有人都有)
|
||||
|
||||
# UltraDepository.silent
|
||||
- 拥有该权限将不再接收到放入背包的提示。
|
||||
|
||||
# UltraDepository.Command.Sell
|
||||
- 玩家使用Sell指令的权限
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<artifactId>ultradepository</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1.7</version>
|
||||
<version>1.1.8</version>
|
||||
|
||||
<name>UltraDepository</name>
|
||||
<description>超级仓库插件,支持设定不同物品的存储仓库。</description>
|
||||
@@ -261,6 +261,9 @@
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>LICENSE</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
@@ -147,6 +147,11 @@ public class UltraDepository extends EasyPlugin {
|
||||
return depositoryManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugging() {
|
||||
return PluginConfig.DEBUG.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void outputInfo() {
|
||||
log(" ",
|
||||
|
||||
+15
-4
@@ -42,10 +42,21 @@ public class DepositoryCapacity {
|
||||
}
|
||||
|
||||
public int getPlayerCapacity(Player player) {
|
||||
return getPermissions().entrySet().stream()
|
||||
.filter(entry -> player.hasPermission(entry.getKey()))
|
||||
.mapToInt(Map.Entry::getValue)
|
||||
.max().orElse(defaultCapacity);
|
||||
if (defaultCapacity == -1) return -1;
|
||||
|
||||
int capacity = defaultCapacity;
|
||||
for (Map.Entry<String, Integer> entry : getPermissions().entrySet()) {
|
||||
if (player.hasPermission(entry.getKey())) {
|
||||
int value = entry.getValue();
|
||||
if (value == -1) {
|
||||
return -1;
|
||||
} else if (value > capacity) {
|
||||
capacity = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||
"%UltraDepository_amount_<BackpackID>_<ItemTypeID>%",
|
||||
"%UltraDepository_sold_<BackpackID>_<ItemTypeID>%",
|
||||
"%UltraDepository_price_<BackpackID>_<ItemTypeID>%",
|
||||
"%UltraDepository_reUltraDepository_<BackpackID>_<ItemTypeID>%",
|
||||
"%UltraDepository_remain_<BackpackID>_<ItemTypeID>%",
|
||||
"%UltraDepository_capacity_<BackpackID>%",
|
||||
"%UltraDepository_used_<BackpackID>%",
|
||||
"%UltraDepository_usable_<BackpackID>%"
|
||||
@@ -80,7 +80,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||
if (sold == null) return "Depository or Item not exists";
|
||||
else return sold.toString();
|
||||
}
|
||||
case "reUltraDepository": {
|
||||
case "remain": {
|
||||
if (args.length < 2) return "Error Params";
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||
if (depository == null) return "Depository not exists";
|
||||
@@ -106,7 +106,8 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||
if (args.length < 2) return "Error Params";
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||
if (depository == null) return "Depository not exists";
|
||||
return Integer.toString(depository.getCapacity().getPlayerCapacity(player));
|
||||
int capacity = depository.getCapacity().getPlayerCapacity(player);
|
||||
return capacity < 0 ? "∞" : Integer.toString(capacity);
|
||||
}
|
||||
case "used": {
|
||||
if (args.length < 2) return "Error Params";
|
||||
@@ -118,8 +119,9 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||
if (args.length < 2) return "Error Params";
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||
if (depository == null) return "Depository not exists";
|
||||
int max = depository.getCapacity().getPlayerCapacity(player);
|
||||
int used = data.getDepositoryData(depository).getUsedCapacity();
|
||||
return Integer.toString(depository.getCapacity().getPlayerCapacity(player) - used);
|
||||
return max < 0 ? "∞" : Integer.toString(max - used);
|
||||
}
|
||||
case "version": {
|
||||
return getVersion();
|
||||
|
||||
@@ -115,7 +115,7 @@ public class DepositoryManager {
|
||||
return getItemDepositories(itemStack).stream().filter(configuration -> {
|
||||
int used = UltraDepository.getUserManager().getData(player).getDepositoryData(configuration).getUsedCapacity();
|
||||
int max = configuration.getCapacity().getPlayerCapacity(player);
|
||||
return used + itemStack.getAmount() <= max;
|
||||
return max < 0 || used + itemStack.getAmount() <= max;
|
||||
}).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@@ -165,11 +165,13 @@ public class DepositoryManager {
|
||||
int finalAmount = collectItemEvent.getItemAmount();
|
||||
|
||||
collectItemEvent.getUserData().addItemAmount(depository.getIdentifier(), typeID, finalAmount);
|
||||
if (!player.hasPermission("UltraDepository.silent")) {
|
||||
PluginMessages.COLLECTED.send(player, new Object[]{
|
||||
depository.getItems().get(typeID).getName(),
|
||||
finalAmount, depository.getName()
|
||||
});
|
||||
PluginConfig.Sounds.COLLECT.play(player);
|
||||
}
|
||||
UltraDepository.getInstance().debug("Item collected successfully.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ import cc.carm.plugin.ultradepository.hooker.VaultHooker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class EconomyManager {
|
||||
|
||||
VaultHooker hooker;
|
||||
@@ -35,9 +38,9 @@ public class EconomyManager {
|
||||
|
||||
public double sell(Player player, double price, int amount) {
|
||||
if (!isInitialized()) return 0D;
|
||||
double money = price * amount;
|
||||
getHooker().addMoney(player, money);
|
||||
return money;
|
||||
BigDecimal money = BigDecimal.valueOf(price * amount).setScale(2, RoundingMode.DOWN);
|
||||
getHooker().addMoney(player, money.doubleValue());
|
||||
return money.doubleValue();
|
||||
}
|
||||
|
||||
public void sellAllItem(Player player, UserData userData) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import cc.carm.lib.easyplugin.database.api.SQLManager;
|
||||
import cc.carm.lib.easyplugin.database.api.action.query.PreparedQueryAction;
|
||||
import cc.carm.lib.easyplugin.database.api.action.query.SQLQuery;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||
import cc.carm.plugin.ultradepository.data.DepositoryData;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
@@ -62,7 +61,7 @@ public class MySQLStorage extends JSONStorage {
|
||||
try {
|
||||
UltraDepository.getInstance().log(" 尝试连接到数据库...");
|
||||
this.sqlManager = EasySQL.createManager(DRIVER_NAME.get(), URL.get(), USERNAME.get(), PASSWORD.get());
|
||||
this.sqlManager.setDebugMode(PluginConfig.DEBUG.get());
|
||||
this.sqlManager.setDebugMode(UltraDepository.getInstance().isDebugging());
|
||||
} catch (Exception exception) {
|
||||
UltraDepository.getInstance().error("无法连接到数据库,请检查配置文件。");
|
||||
UltraDepository.getInstance().error("Could not connect to the database, please check the configuration.");
|
||||
|
||||
@@ -30,6 +30,9 @@ permissions:
|
||||
description: "超级仓库的基本使用权限"
|
||||
default: true
|
||||
|
||||
"UltraDepository.silent":
|
||||
description: "超级仓库的安静模式权限,拥有该权限将不再接收到放入背包的提示。"
|
||||
|
||||
"UltraDepository.auto":
|
||||
description: "超级仓库的自动收集权限"
|
||||
default: op
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class MoneyTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
System.out.println(get(1.2, 100));
|
||||
System.out.println(get(0.55, 10));
|
||||
System.out.println(get(0.21, 5));
|
||||
}
|
||||
|
||||
|
||||
public double get(double price, int amount) {
|
||||
BigDecimal money = BigDecimal.valueOf(price * amount).setScale(2, RoundingMode.DOWN);
|
||||
return money.doubleValue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user