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