新增支持外部经济插件
This commit is contained in:
parent
0ec55beee2
commit
c1df7a44c2
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.lunadeer</groupId>
|
||||
<artifactId>MiniPlayerTitle</artifactId>
|
||||
<version>3.0.5</version>
|
||||
<version>3.0.6</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MiniPlayerTitle</name>
|
||||
@ -78,7 +78,7 @@
|
||||
<dependency>
|
||||
<groupId>cn.lunadeer</groupId>
|
||||
<artifactId>MinecraftPluginUtils</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -14,12 +14,13 @@ public final class MiniPlayerTitle extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
new Scheduler(this);
|
||||
notification = new Notification(this);
|
||||
logger = new XLogger(instance);
|
||||
config = new ConfigManager(instance);
|
||||
logger.setDebug(config.isDebug());
|
||||
database = new DatabaseManager(this,
|
||||
config.getDbType().equals("pgsql") ? DatabaseManager.TYPE.POSTGRESQL : DatabaseManager.TYPE.SQLITE,
|
||||
DatabaseManager.TYPE.valueOf(config.getDbType().toUpperCase()),
|
||||
config.getDbHost(),
|
||||
config.getDbPort(),
|
||||
config.getDbName(),
|
||||
@ -27,6 +28,11 @@ public final class MiniPlayerTitle extends JavaPlugin {
|
||||
config.getDbPass());
|
||||
DatabaseTables.migrate();
|
||||
|
||||
if (config.isExternalEco()) {
|
||||
logger.info("已启用外部经济插件");
|
||||
new VaultConnect(this);
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new Events(), this);
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setExecutor(new Commands());
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setTabCompleter(new Commands());
|
||||
|
@ -25,7 +25,7 @@ public class PlayerManage {
|
||||
}
|
||||
if (playerInfo.addCoin(Integer.parseInt(args[2]))) {
|
||||
MiniPlayerTitle.notification.info(sender, "成功给玩家 %s 添加 %s 称号币", playerInfo.getLastUseName(), args[2]);
|
||||
MiniPlayerTitle.notification.info(sender, "玩家 %s 当前余额 %d 称号币", playerInfo.getLastUseName(), playerInfo.getCoin());
|
||||
MiniPlayerTitle.notification.info(sender, "玩家 %s 当前余额 %f 称号币", playerInfo.getLastUseName(), playerInfo.getCoin());
|
||||
} else {
|
||||
MiniPlayerTitle.notification.error(sender, "给玩家添加称号币失败,详细错误请查看控制台日志");
|
||||
}
|
||||
@ -51,7 +51,7 @@ public class PlayerManage {
|
||||
}
|
||||
if (playerInfo.setCoin(Integer.parseInt(args[2]))) {
|
||||
MiniPlayerTitle.notification.info(sender, "成功给玩家 %s 设置 %s 称号币", playerInfo.getLastUseName(), args[2]);
|
||||
MiniPlayerTitle.notification.info(sender, "玩家 %s 当前余额 %d 称号币", playerInfo.getLastUseName(), playerInfo.getCoin());
|
||||
MiniPlayerTitle.notification.info(sender, "玩家 %s 当前余额 %f 称号币", playerInfo.getLastUseName(), playerInfo.getCoin());
|
||||
} else {
|
||||
MiniPlayerTitle.notification.error(sender, "给玩家设置称号币失败,详细错误请查看控制台日志");
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class TitleShopSale {
|
||||
boolean success;
|
||||
switch (args[1]) {
|
||||
case "price":
|
||||
success = titleShop.setPrice(Integer.parseInt(args[3]));
|
||||
success = titleShop.setPrice(Double.parseDouble(args[3]));
|
||||
break;
|
||||
case "days":
|
||||
success = titleShop.setDays(Integer.parseInt(args[3]));
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.lunadeer.miniplayertitle.dtos;
|
||||
|
||||
import cn.lunadeer.minecraftpluginutils.VaultConnect;
|
||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -12,13 +13,13 @@ import java.util.UUID;
|
||||
|
||||
public class PlayerInfoDTO {
|
||||
private UUID uuid;
|
||||
private Integer coin;
|
||||
private Double coin;
|
||||
private TitleDTO using_title;
|
||||
private String last_use_name;
|
||||
|
||||
public static PlayerInfoDTO get(UUID uuid) {
|
||||
String sql = "";
|
||||
sql = "SELECT uuid, coin, using_title_id, last_use_name FROM mplt_player_info WHERE uuid = ?;";
|
||||
sql = "SELECT uuid, coin_d, using_title_id, last_use_name FROM mplt_player_info WHERE uuid = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, uuid)) {
|
||||
if (rs.next()) return getPlayerInfoDTO(rs);
|
||||
else return null;
|
||||
@ -48,7 +49,7 @@ public class PlayerInfoDTO {
|
||||
|
||||
public static PlayerInfoDTO get(String name) {
|
||||
String sql = "";
|
||||
sql = "SELECT uuid, coin, using_title_id, last_use_name FROM mplt_player_info WHERE last_use_name = ?;";
|
||||
sql = "SELECT uuid, coin_d, using_title_id, last_use_name FROM mplt_player_info WHERE last_use_name = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, name)) {
|
||||
if (rs.next()) return getPlayerInfoDTO(rs);
|
||||
else return null;
|
||||
@ -60,7 +61,7 @@ public class PlayerInfoDTO {
|
||||
|
||||
private static PlayerInfoDTO create(Player player) {
|
||||
String sql = "";
|
||||
sql = "INSERT INTO mplt_player_info (uuid, coin, last_use_name) " +
|
||||
sql = "INSERT INTO mplt_player_info (uuid, coin_d, last_use_name) " +
|
||||
"VALUES (?, ?, ?) " +
|
||||
"ON CONFLICT DO NOTHING;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player.getUniqueId(), MiniPlayerTitle.config.getDefaultCoin(), player.getName())) {
|
||||
@ -85,13 +86,17 @@ public class PlayerInfoDTO {
|
||||
private static PlayerInfoDTO getPlayerInfoDTO(ResultSet rs) throws SQLException {
|
||||
PlayerInfoDTO playerInfoDTO = new PlayerInfoDTO();
|
||||
playerInfoDTO.uuid = UUID.fromString(rs.getString("uuid"));
|
||||
playerInfoDTO.coin = rs.getInt("coin");
|
||||
playerInfoDTO.coin = rs.getDouble("coin_d");
|
||||
playerInfoDTO.using_title = TitleDTO.get(rs.getInt("using_title_id"));
|
||||
playerInfoDTO.last_use_name = rs.getString("last_use_name");
|
||||
return playerInfoDTO;
|
||||
}
|
||||
|
||||
public Integer getCoin() {
|
||||
public Double getCoin() {
|
||||
if (MiniPlayerTitle.config.isExternalEco()) {
|
||||
Player player = MiniPlayerTitle.instance.getServer().getPlayer(uuid);
|
||||
return VaultConnect.instance.getBalance(player);
|
||||
}
|
||||
return coin;
|
||||
}
|
||||
|
||||
@ -115,13 +120,28 @@ public class PlayerInfoDTO {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addCoin(Integer coin) {
|
||||
public boolean addCoin(double coin) {
|
||||
if (MiniPlayerTitle.config.isExternalEco()) {
|
||||
Player player = MiniPlayerTitle.instance.getServer().getPlayer(uuid);
|
||||
VaultConnect.instance.depositPlayer(player, coin);
|
||||
return true;
|
||||
}
|
||||
return setCoin(this.coin + coin);
|
||||
}
|
||||
|
||||
public boolean setCoin(Integer coin) {
|
||||
public boolean setCoin(double coin) {
|
||||
if (MiniPlayerTitle.config.isExternalEco()) {
|
||||
Player player = MiniPlayerTitle.instance.getServer().getPlayer(uuid);
|
||||
double balance = VaultConnect.instance.getBalance(player);
|
||||
if (balance < coin) {
|
||||
VaultConnect.instance.depositPlayer(player, coin - balance);
|
||||
} else {
|
||||
VaultConnect.instance.withdrawPlayer(player, balance - coin);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
String sql = "";
|
||||
sql = "UPDATE mplt_player_info SET coin = ? WHERE uuid = ?;";
|
||||
sql = "UPDATE mplt_player_info SET coin_d = ? WHERE uuid = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, coin, uuid)) {
|
||||
this.coin = coin;
|
||||
return true;
|
||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||
public class TitleShopDTO {
|
||||
private Integer id;
|
||||
private TitleDTO title;
|
||||
private Integer price;
|
||||
private Double price;
|
||||
private Integer days;
|
||||
private Integer amount;
|
||||
private LocalDateTime sale_end_at;
|
||||
@ -23,13 +23,13 @@ public class TitleShopDTO {
|
||||
return title;
|
||||
}
|
||||
|
||||
public Integer getPrice() {
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public boolean setPrice(int price) {
|
||||
public boolean setPrice(Double price) {
|
||||
String sql = "";
|
||||
sql += "UPDATE mplt_title_shop SET price = ? WHERE id = ?;";
|
||||
sql += "UPDATE mplt_title_shop SET price_d = ? WHERE id = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, price, id)) {
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
@ -89,7 +89,7 @@ public class TitleShopDTO {
|
||||
|
||||
public static TitleShopDTO get(Integer id) {
|
||||
String sql = "";
|
||||
sql += "SELECT id, title_id, price, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
||||
sql += "SELECT id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
||||
"FROM mplt_title_shop WHERE id = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) {
|
||||
if (rs.next()) {
|
||||
@ -103,7 +103,7 @@ public class TitleShopDTO {
|
||||
|
||||
public static List<TitleShopDTO> getAll() {
|
||||
String sql = "";
|
||||
sql += "SELECT id, title_id, price, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
||||
sql += "SELECT id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
||||
"FROM mplt_title_shop;";
|
||||
List<TitleShopDTO> titleShops = new ArrayList<>();
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
|
||||
@ -121,7 +121,7 @@ public class TitleShopDTO {
|
||||
TitleShopDTO titleShop = new TitleShopDTO();
|
||||
titleShop.id = rs.getInt("id");
|
||||
titleShop.title = TitleDTO.get(rs.getInt("title_id"));
|
||||
titleShop.price = rs.getInt("price");
|
||||
titleShop.price = rs.getDouble("price_d");
|
||||
titleShop.days = rs.getInt("days");
|
||||
titleShop.amount = rs.getInt("amount");
|
||||
int y = rs.getInt("sale_end_at_y");
|
||||
@ -137,10 +137,10 @@ public class TitleShopDTO {
|
||||
|
||||
public static TitleShopDTO create(TitleDTO title) {
|
||||
String sql = "";
|
||||
sql += "INSERT INTO mplt_title_shop (title_id, price, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d) " +
|
||||
sql += "INSERT INTO mplt_title_shop (title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d) " +
|
||||
"VALUES (?, 0, -1, 0, -1, -1, -1) " +
|
||||
"RETURNING " +
|
||||
"id, title_id, price, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d;";
|
||||
"id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title.getId())) {
|
||||
if (rs.next()) {
|
||||
return getTitleShop(rs);
|
||||
|
@ -32,6 +32,7 @@ public class ConfigManager {
|
||||
_custom_cost = _file.getInt("CustomCost.Cost", 1000);
|
||||
_max_length = _file.getInt("CustomCost.MaxLength", 8);
|
||||
_check_update = _file.getBoolean("CheckUpdate", true);
|
||||
_external_eco = _file.getBoolean("ExternalEco", false);
|
||||
}
|
||||
|
||||
public Boolean isDebug() {
|
||||
@ -141,6 +142,10 @@ public class ConfigManager {
|
||||
return _check_update;
|
||||
}
|
||||
|
||||
public Boolean isExternalEco() {
|
||||
return _external_eco;
|
||||
}
|
||||
|
||||
|
||||
private final MiniPlayerTitle _plugin;
|
||||
private FileConfiguration _file;
|
||||
@ -159,4 +164,5 @@ public class ConfigManager {
|
||||
private Integer _custom_cost;
|
||||
private Integer _max_length;
|
||||
private Boolean _check_update;
|
||||
private Boolean _external_eco;
|
||||
}
|
||||
|
@ -108,5 +108,19 @@ public class DatabaseTables {
|
||||
MiniPlayerTitle.database.query(sql);
|
||||
|
||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_info", "last_use_name", "TEXT NOT NULL DEFAULT 'null'");
|
||||
|
||||
// 3.0.6
|
||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_info", "coin_d", "DOUBLE PRECISION NOT NULL DEFAULT 0");
|
||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "price_d", "DOUBLE PRECISION NOT NULL DEFAULT 0");
|
||||
if (MiniPlayerTitle.database.isColumnExist("mplt_player_info", "coin")) {
|
||||
sql = "UPDATE mplt_player_info SET coin_d = coin;";
|
||||
MiniPlayerTitle.database.query(sql);
|
||||
}
|
||||
if (MiniPlayerTitle.database.isColumnExist("mplt_title_shop", "price")) {
|
||||
sql = "UPDATE mplt_title_shop SET price_d = price;";
|
||||
MiniPlayerTitle.database.query(sql);
|
||||
}
|
||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "coin");
|
||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "price");
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ CustomCost:
|
||||
|
||||
DefaultCoin: 0
|
||||
|
||||
ExternalEco: false # 使用外部经济插件 需要Vault支持
|
||||
|
||||
CheckUpdate: true
|
||||
|
||||
Debug: false
|
Loading…
Reference in New Issue
Block a user