Compare commits

..

32 Commits

Author SHA1 Message Date
40e561bff1 修复了在spigot相关核心下无法连接papi的问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 15m20s
2024-09-29 00:31:18 +08:00
11856a29a6 更新 README.md 2024-08-19 10:36:18 +08:00
78de7dca65 支持渐变语法
All checks were successful
Java CI-CD with Maven / build (push) Successful in 10m56s
2024-08-12 16:42:54 +08:00
466dd84fac 修复称号卡可能会被用于其他物品的问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 21m27s
2024-07-26 17:48:12 +08:00
283e435b70 增加生成称号卡时的逻辑检查
All checks were successful
Java CI-CD with Maven / build (push) Successful in 18m48s
2024-07-26 17:23:35 +08:00
2981ac0183 新增称号卡支持
All checks were successful
Java CI-CD with Maven / build (push) Successful in 25m27s
2024-07-26 17:16:52 +08:00
02d44610c6 新增对VaultUnlocked支持
All checks were successful
Java CI-CD with Maven / build (push) Successful in 9m50s
2024-07-21 14:57:00 +08:00
31a1d409b7 对Spigot进行了重新适配
All checks were successful
Java CI-CD with Maven / build (push) Successful in 8m45s
2024-07-18 17:14:48 +08:00
9de1b5cced 修复op无法自定义称号问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 35m48s
2024-07-14 21:49:07 +08:00
d629b1daf7 新增op可无视自定义权限节点
All checks were successful
Java CI-CD with Maven / build (push) Successful in 11m49s
2024-07-12 21:09:56 +08:00
b52fce2479 新增权限节点配置,允许通过权限节点控制玩家行为 2024-07-12 17:39:31 +08:00
3ffab50c9b 优化在使用papi情况下的性能
All checks were successful
Java CI-CD with Maven / build (push) Successful in 8m10s
2024-07-05 14:57:54 +08:00
a007966d70 修复了称号背包展示逻辑错误问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 9m16s
2024-07-01 14:40:12 +08:00
ddf5ae711a 修复了称号前后缀颜色不定问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 9m1s
2024-07-01 10:51:06 +08:00
f5fe78f4d1 修复了菜单中称号前缀后缀未被解析问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 8m2s
2024-07-01 01:40:28 +08:00
25fe5fbb09 修复了无法卸下称号的问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 9m41s
2024-07-01 00:28:45 +08:00
fc5f167587 修复了在没有papi的情况下无法加载插件的bug
All checks were successful
Java CI-CD with Maven / build (push) Successful in 28m39s
2024-06-27 16:26:27 +08:00
706ea9a5a5 修复了在购买不限量称号时可能产生-2的bug
All checks were successful
Java CI-CD with Maven / build (push) Successful in 8m36s
2024-06-27 16:13:02 +08:00
c4d25b79cf 实现了papi彩色字称号
All checks were successful
Java CI-CD with Maven / build (push) Successful in 7m53s
2024-06-24 17:53:43 +08:00
8ef1c9a7d0 更新文档
All checks were successful
Java CI-CD with Maven / build (push) Successful in 8m50s
2024-06-24 16:20:30 +08:00
c7d8baf885 新增授予玩家称号指令 2024-06-24 16:10:43 +08:00
1e661badc2 实现了支持papi(暂时不支持彩色) 2024-06-24 15:58:16 +08:00
8280383e4b 修复了某些情况下无法hook到经济插件的问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 9m7s
2024-06-18 15:53:18 +08:00
eb1aee7949 新增数据库关闭逻辑,确保数据写入完整 2024-06-18 11:08:47 +08:00
8b218538c6 新增数据库关闭逻辑,确保数据写入完整 2024-06-18 11:08:32 +08:00
9898566a77 新增数据库关闭逻辑,确保数据写入完整 2024-06-18 11:07:58 +08:00
b17f951e7d 新增数据库关闭逻辑,确保数据写入完整 2024-06-18 11:05:23 +08:00
118a4e72d0 升级工具库版本 2024-06-18 10:37:05 +08:00
c1df7a44c2 新增支持外部经济插件 2024-06-18 10:30:02 +08:00
0ec55beee2 修复删除称号时回意外删除mplt玩家信息导致提示无法获取玩家信息的问题 2024-06-18 09:49:30 +08:00
3432c29116 修复玩家无法使用称号的问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 7m1s
2024-06-11 15:27:31 +08:00
20cd4278ad 修复了使用永久称号时报错的问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 7m59s
2024-06-08 15:38:45 +08:00
27 changed files with 906 additions and 436 deletions

View File

@ -1,9 +1,11 @@
<div style="text-align: center;"> <div align="center">
<img src="https://ssl.lunadeer.cn:14437/i/2024/03/28/6604de7db2e6f.png" alt="" width="70%"> <img src="https://ssl.lunadeer.cn:14437/i/2024/03/28/6604de7db2e6f.png" alt="" width="70%">
### [开源地址](https://ssl.lunadeer.cn:14446/zhangyuheng/MiniPlayerTitle) | [文档地址](https://ssl.lunadeer.cn:14448/doc/2/) ### [开源地址](https://ssl.lunadeer.cn:14446/zhangyuheng/MiniPlayerTitle) | [文档地址](https://ssl.lunadeer.cn:14448/doc/2/)
### [下载页面](https://ssl.lunadeer.cn:14446/zhangyuheng/MiniPlayerTitle/releases) ### [下载页面](https://ssl.lunadeer.cn:14446/zhangyuheng/MiniPlayerTitle/releases)
### [统计页面](https://bstats.org/plugin/bukkit/MiniPlayerTitle/21444) | [Hangar](https://hangar.papermc.io/zhangyuheng/MiniPlayerTitle) ### [统计页面](https://bstats.org/plugin/bukkit/MiniPlayerTitle/21444) | [Hangar](https://hangar.papermc.io/zhangyuheng/MiniPlayerTitle)
</div> </div>
@ -26,10 +28,12 @@
- 本插件使用 **TUI** 作为简易的交互方式,非 PlayerTitle 的箱子UI - 本插件使用 **TUI** 作为简易的交互方式,非 PlayerTitle 的箱子UI
- 支持设置称号**限量销售、限时销售** - 支持设置称号**限量销售、限时销售**
- 支持玩家使用称号币自定义称号 - 支持玩家使用称号币自定义称号
- 支持外部经济系统(需要 Vault 前置支持3.0.6+
- 支持 PlaceholderAPI (4.0.0+)
## 支持版本 ## 支持版本
- 1.20.1+ (Paper、Folia) - 1.20.1+ (Bukkit、Spigot、Paper、Folia)
## TODO ## TODO

14
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId> <groupId>cn.lunadeer</groupId>
<artifactId>MiniPlayerTitle</artifactId> <artifactId>MiniPlayerTitle</artifactId>
<version>3.0.3</version> <version>4.7.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>MiniPlayerTitle</name> <name>MiniPlayerTitle</name>
@ -66,6 +66,10 @@
<id>lunadeer-repo</id> <id>lunadeer-repo</id>
<url>https://ssl.lunadeer.cn:14454/repository/maven-snapshots/</url> <url>https://ssl.lunadeer.cn:14454/repository/maven-snapshots/</url>
</repository> </repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -78,7 +82,13 @@
<dependency> <dependency>
<groupId>cn.lunadeer</groupId> <groupId>cn.lunadeer</groupId>
<artifactId>MinecraftPluginUtils</artifactId> <artifactId>MinecraftPluginUtils</artifactId>
<version>1.2.0-SNAPSHOT</version> <version>1.3.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.6</version>
<scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,5 +1,6 @@
package cn.lunadeer.miniplayertitle; package cn.lunadeer.miniplayertitle;
import cn.lunadeer.minecraftpluginutils.XLogger;
import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
@ -27,7 +28,7 @@ public class Color {
this.g = 0; this.g = 0;
this.b = 0; this.b = 0;
this.hex = "#000000"; this.hex = "#000000";
MiniPlayerTitle.logger.err("Invalid color: " + r + ", " + g + ", " + b); XLogger.err("Invalid color: " + r + ", " + g + ", " + b);
} }
} }
@ -42,7 +43,7 @@ public class Color {
this.g = 0; this.g = 0;
this.b = 0; this.b = 0;
this.hex = "#000000"; this.hex = "#000000";
MiniPlayerTitle.logger.err("Invalid color: " + hex); XLogger.err("Invalid color: " + hex);
} }
} }

View File

@ -1,6 +1,7 @@
package cn.lunadeer.miniplayertitle; package cn.lunadeer.miniplayertitle;
import cn.lunadeer.miniplayertitle.commands.PlayerManage; import cn.lunadeer.miniplayertitle.commands.PlayerManage;
import cn.lunadeer.miniplayertitle.commands.TitleCard;
import cn.lunadeer.miniplayertitle.commands.TitleManage; import cn.lunadeer.miniplayertitle.commands.TitleManage;
import cn.lunadeer.miniplayertitle.commands.TitleShopSale; import cn.lunadeer.miniplayertitle.commands.TitleShopSale;
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
@ -66,7 +67,7 @@ public class Commands implements TabExecutor {
case "edit_title_name": // mplt edit_title_name <称号ID> <称号名称> case "edit_title_name": // mplt edit_title_name <称号ID> <称号名称>
TitleManage.editTitleName(sender, args); TitleManage.editTitleName(sender, args);
break; break;
case "edit_title_desc": // mplt set_title_desc <称号ID> <称号描述> case "edit_title_desc": // mplt edit_title_desc <称号ID> <称号描述>
TitleManage.editTitleDescription(sender, args); TitleManage.editTitleDescription(sender, args);
break; break;
case "custom_title": // mplt custom_title <称号> case "custom_title": // mplt custom_title <称号>
@ -78,6 +79,12 @@ public class Commands implements TabExecutor {
case "set_coin": // mplt set_coin <玩家名称> <称号币数量> case "set_coin": // mplt set_coin <玩家名称> <称号币数量>
PlayerManage.setCoin(sender, args); PlayerManage.setCoin(sender, args);
break; break;
case "grant_title": // mplt grant_title <玩家名称> <称号> <描述> [天数]
PlayerManage.grantTitle(sender, args);
break;
case "get_card": // mplt get_card <商品ID>
TitleCard.getTitleCard(sender, args);
break;
default: default:
return false; return false;
} }
@ -89,13 +96,16 @@ public class Commands implements TabExecutor {
if (args.length == 1) { if (args.length == 1) {
return Arrays.asList("menu", "all_titles", "my_titles", "shop", "custom_info", "sale_info", return Arrays.asList("menu", "all_titles", "my_titles", "shop", "custom_info", "sale_info",
"create_sale", "set_sale", "delete_sale", "buy_sale", "use_title", "create_title", "create_sale", "set_sale", "delete_sale", "buy_sale", "use_title", "create_title",
"delete_title", "edit_title_name", "edit_title_desc", "custom_title", "add_coin", "set_coin"); "delete_title", "edit_title_name", "edit_title_desc", "custom_title", "add_coin", "set_coin",
"grant_title", "get_card"
);
} }
if (args.length == 2) { if (args.length == 2) {
switch (args[0]) { switch (args[0]) {
case "sale_info": case "sale_info":
case "delete_sale": case "delete_sale":
case "buy_sale": case "buy_sale":
case "get_card":
return Collections.singletonList("<商品ID>"); return Collections.singletonList("<商品ID>");
case "create_sale": case "create_sale":
case "delete_title": case "delete_title":
@ -111,6 +121,7 @@ public class Commands implements TabExecutor {
return Collections.singletonList("<称号内容>"); return Collections.singletonList("<称号内容>");
case "add_coin": case "add_coin":
case "set_coin": case "set_coin":
case "grant_title":
return PlayerInfoDTO.playerNameList(); return PlayerInfoDTO.playerNameList();
default: default:
return null; return null;
@ -129,6 +140,8 @@ public class Commands implements TabExecutor {
case "add_coin": case "add_coin":
case "set_coin": case "set_coin":
return Collections.singletonList("<数量>"); return Collections.singletonList("<数量>");
case "grant_title":
return Collections.singletonList("<称号>");
default: default:
return null; return null;
} }
@ -137,6 +150,16 @@ public class Commands implements TabExecutor {
switch (args[0]) { switch (args[0]) {
case "set_sale": case "set_sale":
return Collections.singletonList("<值>"); return Collections.singletonList("<值>");
case "grant_title":
return Collections.singletonList("<描述>");
default:
return null;
}
}
if (args.length == 5) {
switch (args[0]) {
case "grant_title":
return Collections.singletonList("<天数(默认永久)>");
default: default:
return null; return null;
} }

View File

@ -0,0 +1,57 @@
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
public class Expansion extends PlaceholderExpansion {
private final JavaPlugin plugin;
public static Expansion instance;
public Expansion(JavaPlugin plugin) {
this.plugin = plugin;
if (usingPapi()) {
XLogger.info("PlaceholderAPI is enabled, registering expansion...");
this.register();
} else {
XLogger.warn("PlaceholderAPI is not enabled, using self impl of placeholders...");
}
instance = this;
}
@Override
public String onPlaceholderRequest(Player bukkitPlayer, @NotNull String params) {
if (params.equalsIgnoreCase("player_title")) {
TitleDTO t = MiniPlayerTitle.instance.getPlayerUsingTitle(bukkitPlayer.getUniqueId());
if (t == null) {
return "";
}
return t.getTitleColoredBukkit();
}
return null; //
}
@Override
public @NotNull String getIdentifier() {
return "mplt";
}
@Override
public @NotNull String getAuthor() {
return "zhangyuheng";
}
@Override
public @NotNull String getVersion() {
return MiniPlayerTitle.instance.getDescription().getVersion();
}
}

View File

@ -1,12 +1,23 @@
package cn.lunadeer.miniplayertitle; package cn.lunadeer.miniplayertitle;
import cn.lunadeer.minecraftpluginutils.*; import cn.lunadeer.minecraftpluginutils.*;
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseType;
import cn.lunadeer.miniplayertitle.commands.TitleCard;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import cn.lunadeer.miniplayertitle.events.Events;
import cn.lunadeer.miniplayertitle.events.PaperChat;
import cn.lunadeer.miniplayertitle.events.SpigotChat;
import cn.lunadeer.miniplayertitle.utils.ConfigManager; import cn.lunadeer.miniplayertitle.utils.ConfigManager;
import cn.lunadeer.miniplayertitle.utils.DatabaseTables; import cn.lunadeer.miniplayertitle.utils.DatabaseTables;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.UUID;
public final class MiniPlayerTitle extends JavaPlugin { public final class MiniPlayerTitle extends JavaPlugin {
@ -14,20 +25,35 @@ public final class MiniPlayerTitle extends JavaPlugin {
public void onEnable() { public void onEnable() {
// Plugin startup logic // Plugin startup logic
instance = this; instance = this;
notification = new Notification(this); new Scheduler(this);
logger = new XLogger(instance); new Notification(this);
new XLogger(instance);
config = new ConfigManager(instance); config = new ConfigManager(instance);
logger.setDebug(config.isDebug()); XLogger.setDebug(config.isDebug());
database = new DatabaseManager(this, new DatabaseManager(this,
config.getDbType().equals("pgsql") ? DatabaseManager.TYPE.POSTGRESQL : DatabaseManager.TYPE.SQLITE, DatabaseType.valueOf(config.getDbType().toUpperCase()),
config.getDbHost(), config.getDbHost(),
config.getDbPort(), config.getDbPort(),
config.getDbName(), config.getDbName(),
config.getDbUser(), config.getDbUser(),
config.getDbPass()); config.getDbPass());
DatabaseTables.migrate(); DatabaseTables.migrate();
if (config.isExternalEco()) {
XLogger.info("已启用外部经济插件");
new VaultConnect(this);
}
if (usingPapi()) {
new Expansion(this);
}
Bukkit.getPluginManager().registerEvents(new Events(), this); Bukkit.getPluginManager().registerEvents(new Events(), this);
Bukkit.getPluginManager().registerEvents(new TitleCard(), this);
if (Common.isPaper()) {
Bukkit.getPluginManager().registerEvents(new PaperChat(), this);
} else {
Bukkit.getPluginManager().registerEvents(new SpigotChat(), this);
}
Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setExecutor(new Commands()); Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setExecutor(new Commands());
Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setTabCompleter(new Commands()); Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setTabCompleter(new Commands());
@ -39,28 +65,39 @@ public final class MiniPlayerTitle extends JavaPlugin {
"MiniPlayerTitle"); "MiniPlayerTitle");
} }
logger.info("称号插件已加载"); XLogger.info("称号插件已加载");
logger.info("版本: " + getPluginMeta().getVersion()); XLogger.info("版本: " + this.getDescription().getVersion());
// http://patorjk.com/software/taag/#p=display&f=Big&t=MiniPlayerTitle // http://patorjk.com/software/taag/#p=display&f=Big&t=MiniPlayerTitle
logger.info(" __ __ _ _ _____ _ _______ _ _ _"); XLogger.info(" __ __ _ _ _____ _ _______ _ _ _");
logger.info(" | \\/ (_) (_) __ \\| | |__ __(_) | | |"); XLogger.info(" | \\/ (_) (_) __ \\| | |__ __(_) | | |");
logger.info(" | \\ / |_ _ __ _| |__) | | __ _ _ _ ___ _ __| | _| |_| | ___"); XLogger.info(" | \\ / |_ _ __ _| |__) | | __ _ _ _ ___ _ __| | _| |_| | ___");
logger.info(" | |\\/| | | '_ \\| | ___/| |/ _` | | | |/ _ \\ '__| | | | __| |/ _ \\"); XLogger.info(" | |\\/| | | '_ \\| | ___/| |/ _` | | | |/ _ \\ '__| | | | __| |/ _ \\");
logger.info(" | | | | | | | | | | | | (_| | |_| | __/ | | | | | |_| | __/"); XLogger.info(" | | | | | | | | | | | | (_| | |_| | __/ | | | | | |_| | __/");
logger.info(" |_| |_|_|_| |_|_|_| |_|\\__,_|\\__, |\\___|_| |_| |_|\\__|_|\\___|"); XLogger.info(" |_| |_|_|_| |_|_|_| |_|\\__,_|\\__, |\\___|_| |_| |_|\\__|_|\\___|");
logger.info(" __/ |"); XLogger.info(" __/ |");
logger.info(" |___/"); XLogger.info(" |___/");
} }
@Override @Override
public void onDisable() { public void onDisable() {
// Plugin shutdown logic // Plugin shutdown logic
DatabaseManager.instance.close();
} }
public static MiniPlayerTitle instance; public static MiniPlayerTitle instance;
public static ConfigManager config; public static ConfigManager config;
public static DatabaseManager database;
public static XLogger logger;
public static Notification notification;
private GiteaReleaseCheck giteaReleaseCheck; private GiteaReleaseCheck giteaReleaseCheck;
private Map<UUID, TitleDTO> playerUsingTitle = new HashMap<>();
public static boolean usingPapi() {
return Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
}
public void setPlayerUsingTitle(UUID uuid, TitleDTO title) {
playerUsingTitle.put(uuid, title);
}
public TitleDTO getPlayerUsingTitle(UUID uuid) {
return playerUsingTitle.get(uuid);
}
} }

View File

@ -1,49 +1,48 @@
package cn.lunadeer.miniplayertitle.commands; package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.minecraftpluginutils.Common;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle; import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO; import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
public class Apis { public class Apis {
public static boolean notOpOrConsole(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限使用此命令");
return true;
}
}
return false;
}
public static void updateName(Player player, @Nullable TitleDTO title) { public static void updateName(Player player, @Nullable TitleDTO title) {
if (title == null || title.getId() == -1) { MiniPlayerTitle.instance.setPlayerUsingTitle(player.getUniqueId(), title);
Component newDisplayName = Component.text() if (usingPapi()) {
.append(Component.text("<"))
.append(player.name())
.append(Component.text("> ")).build();
Component newListName = Component.text()
.append(player.name()).build();
player.displayName(newDisplayName);
player.playerListName(newListName);
return; return;
} }
Component titleComponent = title.getTitleColored(); Component titleComponent = Component.text("");
Component newDisplayName = Component.text() String titleBukkit = "";
.append(titleComponent)
.append(Component.text("<")) if (title != null && title.getId() != -1) {
.append(player.name()) titleComponent = title.getTitleColored();
.append(Component.text(">")).build(); titleBukkit = ChatColor.translateAlternateColorCodes('&', title.getTitleColoredBukkit());
Component newListName = Component.text() }
.append(titleComponent)
.append(Component.text(" ")) if (Common.isPaper()) {
.append(player.name()).build(); Component newDisplayName = Component.text()
player.displayName(newDisplayName); .append(titleComponent)
player.playerListName(newListName); .append(Component.text("<"))
.append(player.name())
.append(Component.text(">")).build();
Component newListName = Component.text()
.append(titleComponent)
.append(Component.text(" "))
.append(player.name()).build();
player.displayName(newDisplayName);
player.playerListName(newListName);
} else {
player.setDisplayName(titleBukkit + "<" + player.getName() + ">");
player.setPlayerListName(titleBukkit + " " + player.getName());
}
} }
} }

View File

@ -1,10 +1,13 @@
package cn.lunadeer.miniplayertitle.commands; package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle; import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole; import java.time.LocalDateTime;
public class PlayerManage { public class PlayerManage {
@ -16,21 +19,21 @@ public class PlayerManage {
* @param args String[] * @param args String[]
*/ */
public static void addCoin(CommandSender sender, String[] args) { public static void addCoin(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return; if (!sender.hasPermission("mplt.admin")) return;
try { try {
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]); PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
if (playerInfo == null) { if (playerInfo == null) {
MiniPlayerTitle.notification.error(sender, "玩家不存在"); Notification.error(sender, "玩家不存在");
return; return;
} }
if (playerInfo.addCoin(Integer.parseInt(args[2]))) { if (playerInfo.addCoin(Integer.parseInt(args[2]))) {
MiniPlayerTitle.notification.info(sender, "成功给玩家 %s 添加 %s 称号币", playerInfo.getLastUseName(), args[2]); Notification.info(sender, "成功给玩家 %s 添加 %s 称号币", playerInfo.getLastUseName(), args[2]);
MiniPlayerTitle.notification.info(sender, "玩家 %s 当前余额 %d 称号币", playerInfo.getLastUseName(), playerInfo.getCoin()); Notification.info(sender, "玩家 %s 当前余额 %f 称号币", playerInfo.getLastUseName(), playerInfo.getCoin());
} else { } else {
MiniPlayerTitle.notification.error(sender, "给玩家添加称号币失败,详细错误请查看控制台日志"); Notification.error(sender, "给玩家添加称号币失败,详细错误请查看控制台日志");
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.notification.error(sender, "给玩家添加称号币时出错:%s", e.getMessage()); Notification.error(sender, "给玩家添加称号币时出错:%s", e.getMessage());
} }
} }
@ -42,21 +45,57 @@ public class PlayerManage {
* @param args String[] * @param args String[]
*/ */
public static void setCoin(CommandSender sender, String[] args) { public static void setCoin(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return; if (!sender.hasPermission("mplt.admin")) return;
try { try {
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]); PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
if (playerInfo == null) { if (playerInfo == null) {
MiniPlayerTitle.notification.error(sender, "玩家不存在"); Notification.error(sender, "玩家不存在");
return; return;
} }
if (playerInfo.setCoin(Integer.parseInt(args[2]))) { if (playerInfo.setCoin(Integer.parseInt(args[2]))) {
MiniPlayerTitle.notification.info(sender, "成功给玩家 %s 设置 %s 称号币", playerInfo.getLastUseName(), args[2]); Notification.info(sender, "成功给玩家 %s 设置 %s 称号币", playerInfo.getLastUseName(), args[2]);
MiniPlayerTitle.notification.info(sender, "玩家 %s 当前余额 %d 称号币", playerInfo.getLastUseName(), playerInfo.getCoin()); Notification.info(sender, "玩家 %s 当前余额 %f 称号币", playerInfo.getLastUseName(), playerInfo.getCoin());
} else { } else {
MiniPlayerTitle.notification.error(sender, "给玩家设置称号币失败,详细错误请查看控制台日志"); Notification.error(sender, "给玩家设置称号币失败,详细错误请查看控制台日志");
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.notification.error(sender, "给玩家设置称号币时出错:%s", e.getMessage()); Notification.error(sender, "给玩家设置称号币时出错:%s", e.getMessage());
}
}
/**
* 直接授予玩家某称号
* mplt grant_title <玩家名称> <称号> <描述> [天数]
*
* @param sender CommandSender
* @param args String[]
*/
public static void grantTitle(CommandSender sender, String[] args) {
if (!sender.hasPermission("mplt.admin")) return;
try {
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
if (playerInfo == null) {
Notification.error(sender, "玩家不存在");
return;
}
String title = args[2];
String description = args[3];
int days = args.length == 5 ? Integer.parseInt(args[4]) : -1;
TitleDTO titleDTO = TitleDTO.create(title, description);
if (titleDTO == null) {
Notification.error(sender, "创建称号失败,详细错误请查看控制台日志");
return;
}
LocalDateTime expire = days == -1 ? null : LocalDateTime.now().plusDays(days);
PlayerTitleDTO playerTitle = PlayerTitleDTO.create(playerInfo.getUuid(), titleDTO, expire);
if (playerTitle == null) {
Notification.error(sender, "授予玩家称号失败,详细错误请查看控制台日志");
return;
}
playerInfo.setUsingTitle(titleDTO);
Notification.info(sender, "成功给玩家 %s 授予称号 %s", playerInfo.getLastUseName(), titleDTO.getTitlePlainText());
} catch (Exception e) {
Notification.error(sender, "授予玩家称号时出错:%s", e.getMessage());
} }
} }
} }

View File

@ -0,0 +1,135 @@
package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO;
import net.kyori.adventure.text.Component;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class TitleCard implements Listener {
public static void getTitleCard(CommandSender sender, String[] args) {
try {
if (!sender.hasPermission("mplt.admin")) return;
if (!(sender instanceof Player)) {
Notification.error(sender, "该命令只能由玩家执行");
return;
}
if (args.length != 2) {
Notification.warn(sender, "用法: /mplt get_card <销售ID>");
return;
}
int saleId = Integer.parseInt(args[1]);
TitleShopDTO titleShop = TitleShopDTO.get(saleId);
if (titleShop == null) {
Notification.error(sender, "获取销售详情时出现错误");
return;
}
if (titleShop.getDays() == 0) {
Notification.error(sender, "不可以生成天数为0的称号卡");
return;
}
ItemStack card = TitleCard.create(titleShop);
Player player = (Player) sender;
player.getInventory().addItem(card);
Notification.info(player, "成功创建称号卡");
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
@EventHandler
public void useTitleCard(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (player.getInventory().getItemInMainHand().getType() != Material.NAME_TAG) {
return;
}
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getItemMeta() == null || item.getItemMeta().getLore() == null || item.getItemMeta().getLore().size() != 5) {
return;
}
use(player, item);
player.getInventory().removeItem(item);
event.setCancelled(true);
}
private static ItemStack create(@NotNull TitleShopDTO saleInfo) {
ItemStack card = new ItemStack(Material.NAME_TAG);
TitleDTO title = saleInfo.getTitle();
card.editMeta(meta -> {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', title.getTitleColoredBukkit()));
meta.setLore(
Arrays.asList(
"称号ID: " + title.getId(),
"使用后获得天数: " + (saleInfo.getDays() == -1 ? "永久" : saleInfo.getDays()),
"称号描述: " + title.getDescription(),
"",
ChatColor.GRAY + "【右键使用】"
)
);
});
return card;
}
private static void use(@NotNull Player player, @NotNull ItemStack item) {
try {
if (item.getType() != Material.NAME_TAG) {
return;
}
List<String> lore = item.getLore();
if (lore == null || lore.size() != 5) {
return;
}
int titleId = Integer.parseInt(lore.get(0).split(": ")[1]);
int day = lore.get(1).split(": ")[1].equals("永久") ? -1 : Integer.parseInt(lore.get(1).split(": ")[1]);
List<PlayerTitleDTO> playerTitles = PlayerTitleDTO.getAllOf(player.getUniqueId());
PlayerTitleDTO had = null;
for (PlayerTitleDTO playerTitle : playerTitles) {
if (Objects.equals(playerTitle.getTitle().getId(), titleId)) {
had = playerTitle;
break;
}
}
TitleDTO title = TitleDTO.get(titleId);
if (title == null) {
Notification.error(player, "称号不存在");
return;
}
if (had == null) {
had = PlayerTitleDTO.create(player.getUniqueId(), title, day == -1 ? null : LocalDateTime.now().plusDays(day));
if (had == null) {
Notification.error(player, "购买称号时出现错误,详情请查看控制台日志");
return;
}
Notification.info(player, Component.text("成功使用称号卡: ").append(had.getTitle().getTitleColored()));
} else if (!had.isExpired()) {
Notification.warn(player, "你已拥有此称号,在过期前无法使用称号卡");
} else {
had.setExpireAt(day == -1 ? null : LocalDateTime.now().plusDays(day));
Notification.info(player, Component.text("成功续续期称号: ").append(had.getTitle().getTitleColored()));
}
TitleManage.useTitle(player, new String[]{"use_title", String.valueOf(had.getId())});
} catch (Exception e) {
Notification.error(player, "使用称号卡时出现错误: %s", e.getMessage());
}
}
}

View File

@ -1,5 +1,6 @@
package cn.lunadeer.miniplayertitle.commands; package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle; import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
@ -10,9 +11,6 @@ import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.time.LocalDateTime;
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
import static cn.lunadeer.miniplayertitle.commands.Apis.updateName; import static cn.lunadeer.miniplayertitle.commands.Apis.updateName;
public class TitleManage { public class TitleManage {
@ -24,17 +22,17 @@ public class TitleManage {
* @param args String[] * @param args String[]
*/ */
public static void createTitle(CommandSender sender, String[] args) { public static void createTitle(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return; if (!sender.hasPermission("mplt.admin")) return;
if (args.length < 2) { if (args.length < 2) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt create_title <称号名称> [称号描述]"); Notification.warn(sender, "用法: /mplt create_title <称号名称> [称号描述]");
return; return;
} }
TitleDTO title = TitleDTO.create(args[1], args.length == 3 ? args[2] : "这是一个管理员创建的称号"); TitleDTO title = TitleDTO.create(args[1], args.length == 3 ? args[2] : "这是一个管理员创建的称号");
if (title != null) { if (title != null) {
MiniPlayerTitle.notification.info(sender, Component.text("成功创建称号: [" + title.getId() + "]").append(title.getTitleColored())); Notification.info(sender, Component.text("成功创建称号: [" + title.getId() + "]").append(title.getTitleColored()));
AllTitles.show(sender, new String[]{"all_titles"}); AllTitles.show(sender, new String[]{"all_titles"});
} else { } else {
MiniPlayerTitle.notification.error(sender, "创建称号失败,具体请查看控制台日志"); Notification.error(sender, "创建称号失败,具体请查看控制台日志");
} }
} }
@ -47,28 +45,28 @@ public class TitleManage {
*/ */
public static void deleteTitle(CommandSender sender, String[] args) { public static void deleteTitle(CommandSender sender, String[] args) {
try { try {
if (notOpOrConsole(sender)) return; if (!sender.hasPermission("mplt.admin")) return;
if (args.length < 2) { if (args.length < 2) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt delete_title <称号ID>"); Notification.warn(sender, "用法: /mplt delete_title <称号ID>");
return; return;
} }
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1])); TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
if (title == null) { if (title == null) {
MiniPlayerTitle.notification.error(sender, "称号不存在"); Notification.error(sender, "称号不存在");
return; return;
} }
boolean success = title.delete(); boolean success = title.delete();
if (!success) { if (!success) {
MiniPlayerTitle.notification.error(sender, "删除称号失败,具体请查看控制台日志"); Notification.error(sender, "删除称号失败,具体请查看控制台日志");
return; return;
} }
MiniPlayerTitle.notification.info(sender, "已删除称号"); Notification.info(sender, "已删除称号");
if (args.length == 3) { if (args.length == 3) {
int page = Integer.parseInt(args[2]); int page = Integer.parseInt(args[2]);
AllTitles.show(sender, new String[]{"all_titles", String.valueOf(page)}); AllTitles.show(sender, new String[]{"all_titles", String.valueOf(page)});
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage()); Notification.error(sender, e.getMessage());
} }
} }
@ -81,24 +79,24 @@ public class TitleManage {
*/ */
public static void editTitleName(CommandSender sender, String[] args) { public static void editTitleName(CommandSender sender, String[] args) {
try { try {
if (notOpOrConsole(sender)) return; if (!sender.hasPermission("mplt.admin")) return;
if (args.length != 3) { if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt set_title <称号ID> <称号名称>"); Notification.warn(sender, "用法: /mplt set_title <称号ID> <称号名称>");
return; return;
} }
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1])); TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
if (title == null) { if (title == null) {
MiniPlayerTitle.notification.error(sender, "称号不存在"); Notification.error(sender, "称号不存在");
return; return;
} }
boolean success = title.updateTitle(args[2]); boolean success = title.updateTitle(args[2]);
if (success) { if (success) {
MiniPlayerTitle.notification.info(sender, "已更新称号名称"); Notification.info(sender, "已更新称号名称");
} else { } else {
MiniPlayerTitle.notification.error(sender, "更新称号名称失败,具体请查看控制台日志"); Notification.error(sender, "更新称号名称失败,具体请查看控制台日志");
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage()); Notification.error(sender, e.getMessage());
} }
} }
@ -111,24 +109,24 @@ public class TitleManage {
*/ */
public static void editTitleDescription(CommandSender sender, String[] args) { public static void editTitleDescription(CommandSender sender, String[] args) {
try { try {
if (notOpOrConsole(sender)) return; if (!sender.hasPermission("mplt.admin")) return;
if (args.length != 3) { if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt set_desc <称号ID> <称号描述>"); Notification.warn(sender, "用法: /mplt set_desc <称号ID> <称号描述>");
return; return;
} }
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1])); TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
if (title == null) { if (title == null) {
MiniPlayerTitle.notification.error(sender, "称号不存在"); Notification.error(sender, "称号不存在");
return; return;
} }
boolean success = title.updateDescription(args[2]); boolean success = title.updateDescription(args[2]);
if (success) { if (success) {
MiniPlayerTitle.notification.info(sender, "已更新称号描述"); Notification.info(sender, "已更新称号描述");
} else { } else {
MiniPlayerTitle.notification.error(sender, "更新称号描述失败,具体请查看控制台日志"); Notification.error(sender, "更新称号描述失败,具体请查看控制台日志");
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage()); Notification.error(sender, e.getMessage());
} }
} }
@ -140,38 +138,49 @@ public class TitleManage {
* @param args String[] * @param args String[]
*/ */
public static void useTitle(CommandSender sender, String[] args) { public static void useTitle(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return; if (!(sender instanceof Player)) {
Notification.error(sender, "该命令只能由玩家执行");
return;
}
if (!sender.hasPermission("mplt.command")) return;
if (args.length < 2) { if (args.length < 2) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt use_title <背包ID> [页码]"); Notification.warn(sender, "用法: /mplt use_title <背包ID> [页码]");
return; return;
} }
Player player = (Player) sender; Player player = (Player) sender;
PlayerTitleDTO title = PlayerTitleDTO.get(Integer.parseInt(args[1]));
if (title == null) {
MiniPlayerTitle.notification.error(sender, "称号不存在");
return;
}
if (!title.getPlayerUuid().equals(player.getUniqueId())) {
MiniPlayerTitle.notification.error(sender, "该称号不属于你");
return;
}
PlayerInfoDTO playerInfo = PlayerInfoDTO.get((player).getUniqueId()); PlayerInfoDTO playerInfo = PlayerInfoDTO.get((player).getUniqueId());
if (playerInfo == null) { if (playerInfo == null) {
MiniPlayerTitle.notification.error(sender, "获取玩家信息时出现错误"); Notification.error(sender, "获取玩家信息时出现错误");
return; return;
} }
if (title.getExpireAt().isBefore(LocalDateTime.now())) { int id = Integer.parseInt(args[1]);
MiniPlayerTitle.notification.error(sender, "称号 %s 已过期", title.getTitle().getTitlePlainText()); if (id == -1) {
Notification.info(sender, "已卸下称号");
playerInfo.setUsingTitle(null); playerInfo.setUsingTitle(null);
updateName(player, null); updateName(player, null);
return;
}
boolean success = playerInfo.setUsingTitle(title.getTitle());
if (success) {
updateName((Player) sender, title.getTitle());
MiniPlayerTitle.notification.info(sender, "已使用称号");
} else { } else {
MiniPlayerTitle.notification.error(sender, "使用称号失败,具体请查看控制台日志"); PlayerTitleDTO title = PlayerTitleDTO.get(id);
if (title == null) {
Notification.error(sender, "称号不存在");
return;
}
if (!title.getPlayerUuid().equals(player.getUniqueId())) {
Notification.error(sender, "该称号不属于你");
return;
}
if (title.isExpired()) {
Notification.error(sender, "称号 %s 已过期", title.getTitle().getTitlePlainText());
playerInfo.setUsingTitle(null);
updateName(player, null);
return;
}
boolean success = playerInfo.setUsingTitle(title.getTitle());
if (success) {
updateName((Player) sender, title.getTitle());
Notification.info(sender, "已使用称号");
} else {
Notification.error(sender, "使用称号失败,具体请查看控制台日志");
}
} }
if (args.length == 3) { if (args.length == 3) {
@ -189,45 +198,49 @@ public class TitleManage {
*/ */
public static void customTitle(CommandSender sender, String[] args) { public static void customTitle(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
MiniPlayerTitle.notification.error(sender, "该命令只能由玩家执行"); Notification.error(sender, "该命令只能由玩家执行");
return;
}
if (!sender.hasPermission("mplt.custom") && !sender.hasPermission("mplt.admin")) {
Notification.error(sender, "你没有权限使用该命令");
return; return;
} }
Player player = (Player) sender; Player player = (Player) sender;
if (!MiniPlayerTitle.config.isEnableCustom()) { if (!MiniPlayerTitle.config.isEnableCustom()) {
MiniPlayerTitle.notification.error(sender, "自定义称号功能已关闭"); Notification.error(sender, "自定义称号功能已关闭");
return; return;
} }
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId()); PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
if (playerInfo == null) { if (playerInfo == null) {
MiniPlayerTitle.notification.error(sender, "获取玩家信息时出现错误"); Notification.error(sender, "获取玩家信息时出现错误");
return; return;
} }
if (MiniPlayerTitle.config.getCustomCost() > playerInfo.getCoin()) { if (MiniPlayerTitle.config.getCustomCost() > playerInfo.getCoin()) {
MiniPlayerTitle.notification.error(sender, "称号币不足"); Notification.error(sender, "称号币不足");
return; return;
} }
if (args.length < 2) { if (args.length < 2) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt custom_title <称号>"); Notification.warn(sender, "用法: /mplt custom_title <称号>");
return; return;
} }
TitleDTO title = TitleDTO.create(args[1], player.getName() + "的自定义称号"); TitleDTO title = TitleDTO.create(args[1], player.getName() + "的自定义称号");
if (title == null) { if (title == null) {
MiniPlayerTitle.notification.error(sender, "创建称号失败,具体请查看控制台日志"); Notification.error(sender, "创建称号失败,具体请查看控制台日志");
return; return;
} }
if (title.getTitlePlainText().length() > MiniPlayerTitle.config.getMaxLength()) { if (title.getTitlePlainText().length() > MiniPlayerTitle.config.getMaxLength()) {
MiniPlayerTitle.notification.error(sender, "称号长度超过限制"); Notification.error(sender, "称号长度超过限制");
title.delete(); title.delete();
return; return;
} }
PlayerTitleDTO created_rec = PlayerTitleDTO.create(player.getUniqueId(), title, null); PlayerTitleDTO created_rec = PlayerTitleDTO.create(player.getUniqueId(), title, null);
if (created_rec == null) { if (created_rec == null) {
MiniPlayerTitle.notification.error(sender, "创建称号记录失败,具体请查看控制台日志"); Notification.error(sender, "创建称号记录失败,具体请查看控制台日志");
title.delete(); title.delete();
return; return;
} }
playerInfo.setCoin(playerInfo.getCoin() - MiniPlayerTitle.config.getCustomCost()); playerInfo.setCoin(playerInfo.getCoin() - MiniPlayerTitle.config.getCustomCost());
MiniPlayerTitle.notification.info(sender, "成功创建自定义称号"); Notification.info(sender, "成功创建自定义称号");
MyTitles.show(sender, new String[]{"my_titles"}); MyTitles.show(sender, new String[]{"my_titles"});
} }
} }

View File

@ -1,6 +1,6 @@
package cn.lunadeer.miniplayertitle.commands; package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle; import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO; import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
@ -16,7 +16,6 @@ import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
import static cn.lunadeer.miniplayertitle.tuis.Apis.getArgPage; import static cn.lunadeer.miniplayertitle.tuis.Apis.getArgPage;
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage; import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
@ -30,16 +29,16 @@ public class TitleShopSale {
* @param args String[] * @param args String[]
*/ */
public static void setSale(CommandSender sender, String[] args) { public static void setSale(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return; if (!sender.hasPermission("mplt.admin")) return;
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[2])); TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[2]));
if (titleShop == null) { if (titleShop == null) {
MiniPlayerTitle.notification.error(sender, "获取详情时出现错误,详情请查看控制台日志"); Notification.error(sender, "获取详情时出现错误,详情请查看控制台日志");
return; return;
} }
boolean success; boolean success;
switch (args[1]) { switch (args[1]) {
case "price": case "price":
success = titleShop.setPrice(Integer.parseInt(args[3])); success = titleShop.setPrice(Double.parseDouble(args[3]));
break; break;
case "days": case "days":
success = titleShop.setDays(Integer.parseInt(args[3])); success = titleShop.setDays(Integer.parseInt(args[3]));
@ -63,11 +62,11 @@ public class TitleShopSale {
success = titleShop.setSaleEndAt(titleShop.getSaleEndAt().minusDays(days2)); success = titleShop.setSaleEndAt(titleShop.getSaleEndAt().minusDays(days2));
break; break;
default: default:
MiniPlayerTitle.notification.warn(sender, "用法: /mplt set_sale <price|days|amount|end_at|end_at_y|end_at_m|end_at_d> <商品ID> <值> [页数]"); Notification.warn(sender, "用法: /mplt set_sale <price|days|amount|end_at|end_at_y|end_at_m|end_at_d> <商品ID> <值> [页数]");
return; return;
} }
if (!success) { if (!success) {
MiniPlayerTitle.notification.error(sender, "设置商品信息时出现错误,详情请查看控制台日志"); Notification.error(sender, "设置商品信息时出现错误,详情请查看控制台日志");
} }
if (args.length == 5) { if (args.length == 5) {
int page = getLastArgsPage(args); int page = getLastArgsPage(args);
@ -83,18 +82,18 @@ public class TitleShopSale {
* @param args String[] * @param args String[]
*/ */
public static void createSale(CommandSender sender, String[] args) { public static void createSale(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return; if (!sender.hasPermission("mplt.admin")) return;
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1])); TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
if (title == null) { if (title == null) {
MiniPlayerTitle.notification.error(sender, "获取称号详情时出现错误,详情请查看控制台日志"); Notification.error(sender, "获取称号详情时出现错误,详情请查看控制台日志");
return; return;
} }
TitleShopDTO sale = TitleShopDTO.create(title); TitleShopDTO sale = TitleShopDTO.create(title);
if (sale == null) { if (sale == null) {
MiniPlayerTitle.notification.error(sender, "创建商品时出现错误,详情请查看控制台日志"); Notification.error(sender, "创建商品时出现错误,详情请查看控制台日志");
return; return;
} }
MiniPlayerTitle.notification.info(sender, "已创建称号商品"); Notification.info(sender, "已创建称号商品");
if (sender instanceof Player) { if (sender instanceof Player) {
SaleInfo.show(sender, new String[]{"sale_info", String.valueOf(sale.getId())}); SaleInfo.show(sender, new String[]{"sale_info", String.valueOf(sale.getId())});
} }
@ -108,17 +107,17 @@ public class TitleShopSale {
* @param args String[] * @param args String[]
*/ */
public static void deleteSale(CommandSender sender, String[] args) { public static void deleteSale(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return; if (!sender.hasPermission("mplt.admin")) return;
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1])); TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
if (titleShop == null) { if (titleShop == null) {
MiniPlayerTitle.notification.error(sender, "获取详情时出现错误"); Notification.error(sender, "获取详情时出现错误");
return; return;
} }
boolean success = titleShop.delete(); boolean success = titleShop.delete();
if (success) { if (success) {
MiniPlayerTitle.notification.info(sender, "已删除商品"); Notification.info(sender, "已删除商品");
} else { } else {
MiniPlayerTitle.notification.error(sender, "删除商品时出现错误,详情请查看控制台日志"); Notification.error(sender, "删除商品时出现错误,详情请查看控制台日志");
} }
if (args.length == 3) { if (args.length == 3) {
@ -135,31 +134,32 @@ public class TitleShopSale {
*/ */
public static void buySale(CommandSender sender, String[] args) { public static void buySale(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
MiniPlayerTitle.notification.error(sender, "该命令只能由玩家执行"); Notification.error(sender, "该命令只能由玩家执行");
return; return;
} }
if (!sender.hasPermission("mplt.command")) return;
Player player = (Player) sender; Player player = (Player) sender;
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId()); PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
if (playerInfo == null) { if (playerInfo == null) {
MiniPlayerTitle.notification.error(player, "获取玩家信息时出现错误,详情请查看控制台日志"); Notification.error(player, "获取玩家信息时出现错误,详情请查看控制台日志");
return; return;
} }
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1])); TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
if (titleShop == null) { if (titleShop == null) {
MiniPlayerTitle.notification.error(player, "获取详情时出现错误,详情请查看控制台日志"); Notification.error(player, "获取详情时出现错误,详情请查看控制台日志");
return; return;
} }
if (titleShop.isExpired() || titleShop.getDays() == 0) { if (titleShop.isExpired() || titleShop.getDays() == 0) {
MiniPlayerTitle.notification.error(player, "此称号已停止销售"); Notification.error(player, "此称号已停止销售");
return; return;
} }
if (titleShop.getAmount() != -1 && titleShop.getAmount() <= 0) { if (titleShop.getAmount() != -1 && titleShop.getAmount() <= 0) {
MiniPlayerTitle.notification.error(player, "此称号已售罄"); Notification.error(player, "此称号已售罄");
return; return;
} }
if (titleShop.getPrice() > playerInfo.getCoin()) { if (titleShop.getPrice() > playerInfo.getCoin()) {
MiniPlayerTitle.notification.error(player, "你的余额不足"); Notification.error(player, "你的余额不足");
return; return;
} }
@ -175,21 +175,26 @@ public class TitleShopSale {
if (had == null) { if (had == null) {
had = PlayerTitleDTO.create(player.getUniqueId(), titleShop.getTitle(), titleShop.getDays() == -1 ? null : LocalDateTime.now().plusDays(titleShop.getDays())); had = PlayerTitleDTO.create(player.getUniqueId(), titleShop.getTitle(), titleShop.getDays() == -1 ? null : LocalDateTime.now().plusDays(titleShop.getDays()));
if (had == null) { if (had == null) {
MiniPlayerTitle.notification.error(player, "购买称号时出现错误,详情请查看控制台日志"); Notification.error(player, "购买称号时出现错误,详情请查看控制台日志");
return; return;
} }
titleShop.setAmount(titleShop.getAmount() - 1); if (titleShop.getAmount() >= 1) {
titleShop.setAmount(titleShop.getAmount() - 1);
}
playerInfo.setCoin(playerInfo.getCoin() - titleShop.getPrice()); playerInfo.setCoin(playerInfo.getCoin() - titleShop.getPrice());
MiniPlayerTitle.notification.info(player, Component.text("成功购买称号: ").append(had.getTitle().getTitleColored())); Notification.info(player, Component.text("成功购买称号: ").append(had.getTitle().getTitleColored()));
} else if (!had.isExpired()) { } else if (!had.isExpired()) {
MiniPlayerTitle.notification.warn(player, "你已拥有此称号,在过期前无法再次购买"); Notification.warn(player, "你已拥有此称号,在过期前无法再次购买");
} else { } else {
had.setExpireAt(titleShop.getDays() == -1 ? null : LocalDateTime.now().plusDays(titleShop.getDays())); had.setExpireAt(titleShop.getDays() == -1 ? null : LocalDateTime.now().plusDays(titleShop.getDays()));
titleShop.setAmount(titleShop.getAmount() - 1); if (titleShop.getAmount() >= 1) {
titleShop.setAmount(titleShop.getAmount() - 1);
}
playerInfo.setCoin(playerInfo.getCoin() - titleShop.getPrice()); playerInfo.setCoin(playerInfo.getCoin() - titleShop.getPrice());
MiniPlayerTitle.notification.info(player, Component.text("成功续续期称号: ").append(had.getTitle().getTitleColored())); Notification.info(player, Component.text("成功续续期称号: ").append(had.getTitle().getTitleColored()));
} }
TitleManage.useTitle(player, new String[]{"use_title", String.valueOf(had.getId())});
int page = getArgPage(args, 3); int page = getArgPage(args, 3);
MyTitles.show(sender, new String[]{"my_titles", String.valueOf(page)}); MyTitles.show(sender, new String[]{"my_titles", String.valueOf(page)});
} }

View File

@ -1,5 +1,10 @@
package cn.lunadeer.miniplayertitle.dtos; package cn.lunadeer.miniplayertitle.dtos;
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle; import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -10,20 +15,22 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
public class PlayerInfoDTO { public class PlayerInfoDTO {
private UUID uuid; private final Field uuid = new Field("uuid", FieldType.UUID);
private Integer coin; private final Field coin = new Field("coin_d", FieldType.DOUBLE);
private TitleDTO using_title; private TitleDTO using_title;
private String last_use_name; private final Field last_use_name = new Field("last_use_name", FieldType.STRING);
public static PlayerInfoDTO get(UUID uuid) { public static PlayerInfoDTO get(UUID uuid) {
String sql = ""; 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)) { try (ResultSet rs = DatabaseManager.instance.query(sql, uuid)) {
if (rs.next()) return getPlayerInfoDTO(rs); if (rs.next()) return getPlayerInfoDTO(rs);
else return null; else return null;
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取玩家信息失败", e, sql); handleDatabaseError("获取玩家信息失败", e, sql);
} }
return null; return null;
} }
@ -33,13 +40,13 @@ public class PlayerInfoDTO {
if (info == null) { if (info == null) {
info = create(player); info = create(player);
if (info == null) { if (info == null) {
MiniPlayerTitle.logger.err("创建玩家信息时失败"); XLogger.err("创建玩家信息时失败");
return null; return null;
} }
} else { } else {
info = updateName(player); info = updateName(player);
if (info == null) { if (info == null) {
MiniPlayerTitle.logger.err("更新玩家名称时失败"); XLogger.err("更新玩家名称时失败");
return null; return null;
} }
} }
@ -48,25 +55,25 @@ public class PlayerInfoDTO {
public static PlayerInfoDTO get(String name) { public static PlayerInfoDTO get(String name) {
String sql = ""; 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)) { try (ResultSet rs = DatabaseManager.instance.query(sql, name)) {
if (rs.next()) return getPlayerInfoDTO(rs); if (rs.next()) return getPlayerInfoDTO(rs);
else return null; else return null;
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取玩家信息失败", e, sql); handleDatabaseError("获取玩家信息失败", e, sql);
} }
return null; return null;
} }
private static PlayerInfoDTO create(Player player) { private static PlayerInfoDTO create(Player player) {
String sql = ""; 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 (?, ?, ?) " + "VALUES (?, ?, ?) " +
"ON CONFLICT DO NOTHING;"; "ON CONFLICT DO NOTHING;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player.getUniqueId(), MiniPlayerTitle.config.getDefaultCoin(), player.getName())) { try (ResultSet rs = DatabaseManager.instance.query(sql, player.getUniqueId(), MiniPlayerTitle.config.getDefaultCoin(), player.getName())) {
return get(player.getUniqueId()); return get(player.getUniqueId());
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("创建玩家信息失败", e, sql); handleDatabaseError("创建玩家信息失败", e, sql);
} }
return null; return null;
} }
@ -74,25 +81,29 @@ public class PlayerInfoDTO {
private static PlayerInfoDTO updateName(Player player) { private static PlayerInfoDTO updateName(Player player) {
String sql = ""; String sql = "";
sql = "UPDATE mplt_player_info SET last_use_name = ? WHERE uuid = ?;"; sql = "UPDATE mplt_player_info SET last_use_name = ? WHERE uuid = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player.getName(), player.getUniqueId())) { try (ResultSet rs = DatabaseManager.instance.query(sql, player.getName(), player.getUniqueId())) {
return get(player.getUniqueId()); return get(player.getUniqueId());
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("更新玩家名称失败", e, sql); handleDatabaseError("更新玩家名称失败", e, sql);
} }
return null; return null;
} }
private static PlayerInfoDTO getPlayerInfoDTO(ResultSet rs) throws SQLException { private static PlayerInfoDTO getPlayerInfoDTO(ResultSet rs) throws SQLException {
PlayerInfoDTO playerInfoDTO = new PlayerInfoDTO(); PlayerInfoDTO playerInfoDTO = new PlayerInfoDTO();
playerInfoDTO.uuid = UUID.fromString(rs.getString("uuid")); playerInfoDTO.uuid.value = UUID.fromString(rs.getString("uuid"));
playerInfoDTO.coin = rs.getInt("coin"); playerInfoDTO.coin.value = rs.getDouble("coin_d");
playerInfoDTO.using_title = TitleDTO.get(rs.getInt("using_title_id")); playerInfoDTO.using_title = TitleDTO.get(rs.getInt("using_title_id"));
playerInfoDTO.last_use_name = rs.getString("last_use_name"); playerInfoDTO.last_use_name.value = rs.getString("last_use_name");
return playerInfoDTO; return playerInfoDTO;
} }
public Integer getCoin() { public Double getCoin() {
return coin; if (MiniPlayerTitle.config.isExternalEco()) {
Player player = MiniPlayerTitle.instance.getServer().getPlayer(getUuid());
return VaultConnect.instance.getBalance(player);
}
return (Double) coin.value;
} }
public TitleDTO getUsingTitle() { public TitleDTO getUsingTitle() {
@ -100,33 +111,52 @@ public class PlayerInfoDTO {
} }
public String getLastUseName() { public String getLastUseName() {
return last_use_name; return (String) last_use_name.value;
}
public UUID getUuid() {
return (UUID) uuid.value;
} }
public boolean setUsingTitle(@Nullable TitleDTO title) { public boolean setUsingTitle(@Nullable TitleDTO title) {
String sql = ""; String sql = "";
sql = "UPDATE mplt_player_info SET using_title_id = ? WHERE uuid = ?;"; sql = "UPDATE mplt_player_info SET using_title_id = ? WHERE uuid = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title == null ? -1 : title.getId(), uuid)) { try (ResultSet rs = DatabaseManager.instance.query(sql, title == null ? -1 : title.getId(), getUuid())) {
this.using_title = title == null ? TitleDTO.get(-1) : title; this.using_title = title == null ? TitleDTO.get(-1) : title;
return true; return true;
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置玩家使用称号失败", e, sql); handleDatabaseError("设置玩家使用称号失败", e, sql);
} }
return false; return false;
} }
public boolean addCoin(Integer coin) { public boolean addCoin(double coin) {
return setCoin(this.coin + coin); if (MiniPlayerTitle.config.isExternalEco()) {
Player player = MiniPlayerTitle.instance.getServer().getPlayer(getUuid());
VaultConnect.instance.depositPlayer(player, coin);
return true;
}
return setCoin(getCoin() + coin);
} }
public boolean setCoin(Integer coin) { public boolean setCoin(double coin) {
if (MiniPlayerTitle.config.isExternalEco()) {
Player player = MiniPlayerTitle.instance.getServer().getPlayer(getUuid());
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 = ""; 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)) { try (ResultSet rs = DatabaseManager.instance.query(sql, coin, getUuid())) {
this.coin = coin; this.coin.value = coin;
return true; return true;
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置玩家金币失败", e, sql); handleDatabaseError("设置玩家金币失败", e, sql);
} }
return false; return false;
} }
@ -135,12 +165,12 @@ public class PlayerInfoDTO {
String sql = ""; String sql = "";
sql = "SELECT last_use_name FROM mplt_player_info;"; sql = "SELECT last_use_name FROM mplt_player_info;";
List<String> names = new ArrayList<>(); List<String> names = new ArrayList<>();
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) { try (ResultSet rs = DatabaseManager.instance.query(sql)) {
while (rs.next()) { while (rs.next()) {
names.add(rs.getString("last_use_name")); names.add(rs.getString("last_use_name"));
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取玩家名称列表失败", e, sql); handleDatabaseError("获取玩家名称列表失败", e, sql);
} }
return names; return names;
} }

View File

@ -1,6 +1,8 @@
package cn.lunadeer.miniplayertitle.dtos; package cn.lunadeer.miniplayertitle.dtos;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -10,14 +12,16 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
public class PlayerTitleDTO { public class PlayerTitleDTO {
private Integer id; private final Field id = new Field("id", FieldType.INT);
private UUID player_uuid; private final Field player_uuid = new Field("player_uuid", FieldType.UUID);
private TitleDTO title; private TitleDTO title;
private LocalDateTime expire_at; private LocalDateTime expire_at;
public Integer getId() { public Integer getId() {
return id; return (Integer) id.value;
} }
public TitleDTO getTitle() { public TitleDTO getTitle() {
@ -25,7 +29,7 @@ public class PlayerTitleDTO {
} }
public UUID getPlayerUuid() { public UUID getPlayerUuid() {
return player_uuid; return (UUID) player_uuid.value;
} }
public LocalDateTime getExpireAt() { public LocalDateTime getExpireAt() {
@ -35,14 +39,14 @@ public class PlayerTitleDTO {
public boolean setExpireAt(LocalDateTime dateTime) { public boolean setExpireAt(LocalDateTime dateTime) {
String sql = ""; String sql = "";
if (dateTime == null) { if (dateTime == null) {
sql += "UPDATE mplt_player_title SET expire_at_y = -1, expire_at_m = -1, expire_at_d = -1 WHERE id = " + id + ";"; sql += "UPDATE mplt_player_title SET expire_at_y = -1, expire_at_m = -1, expire_at_d = -1 WHERE id = " + getId() + ";";
} else { } else {
sql += "UPDATE mplt_player_title SET expire_at_y = " + dateTime.getYear() + ", expire_at_m = " + dateTime.getMonthValue() + ", expire_at_d = " + dateTime.getDayOfMonth() + " WHERE id = " + id + ";"; sql += "UPDATE mplt_player_title SET expire_at_y = " + dateTime.getYear() + ", expire_at_m = " + dateTime.getMonthValue() + ", expire_at_d = " + dateTime.getDayOfMonth() + " WHERE id = " + getId() + ";";
} }
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) { try (ResultSet rs = DatabaseManager.instance.query(sql)) {
return true; return true;
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置玩家称号过期时间失败", e, sql); handleDatabaseError("设置玩家称号过期时间失败", e, sql);
} }
return false; return false;
} }
@ -58,12 +62,12 @@ public class PlayerTitleDTO {
} }
sql += "RETURNING " + sql += "RETURNING " +
"id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d;"; "id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player_uuid, title.getId())) { try (ResultSet rs = DatabaseManager.instance.query(sql, player_uuid, title.getId())) {
if (rs.next()) { if (rs.next()) {
return getRs(rs); return getRs(rs);
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("创建玩家称号失败", e, sql); handleDatabaseError("创建玩家称号失败", e, sql);
} }
return null; return null;
} }
@ -72,12 +76,12 @@ public class PlayerTitleDTO {
String sql = ""; String sql = "";
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " + sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
"WHERE id = ?;"; "WHERE id = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) { try (ResultSet rs = DatabaseManager.instance.query(sql, id)) {
if (rs.next()) { if (rs.next()) {
return getRs(rs); return getRs(rs);
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取玩家称号失败", e, sql); handleDatabaseError("获取玩家称号失败", e, sql);
} }
return null; return null;
} }
@ -86,20 +90,20 @@ public class PlayerTitleDTO {
String sql = ""; String sql = "";
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " + sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
"WHERE player_uuid = ? AND title_id = ?;"; "WHERE player_uuid = ? AND title_id = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player, title)) { try (ResultSet rs = DatabaseManager.instance.query(sql, player, title)) {
if (rs.next()) { if (rs.next()) {
return getRs(rs); return getRs(rs);
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取玩家称号失败", e, sql); handleDatabaseError("获取玩家称号失败", e, sql);
} }
return null; return null;
} }
private static PlayerTitleDTO getRs(ResultSet rs) throws SQLException { private static PlayerTitleDTO getRs(ResultSet rs) throws SQLException {
PlayerTitleDTO playerTitle = new PlayerTitleDTO(); PlayerTitleDTO playerTitle = new PlayerTitleDTO();
playerTitle.id = rs.getInt("id"); playerTitle.id.value = rs.getInt("id");
playerTitle.player_uuid = UUID.fromString(rs.getString("player_uuid")); playerTitle.player_uuid.value = UUID.fromString(rs.getString("player_uuid"));
playerTitle.title = TitleDTO.get(rs.getInt("title_id")); playerTitle.title = TitleDTO.get(rs.getInt("title_id"));
int y = rs.getInt("expire_at_y"); int y = rs.getInt("expire_at_y");
int m = rs.getInt("expire_at_m"); int m = rs.getInt("expire_at_m");
@ -117,12 +121,12 @@ public class PlayerTitleDTO {
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " + sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
"WHERE player_uuid = ?;"; "WHERE player_uuid = ?;";
List<PlayerTitleDTO> playerTitles = new ArrayList<>(); List<PlayerTitleDTO> playerTitles = new ArrayList<>();
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player_uuid)) { try (ResultSet rs = DatabaseManager.instance.query(sql, player_uuid)) {
while (rs.next()) { while (rs.next()) {
playerTitles.add(getRs(rs)); playerTitles.add(getRs(rs));
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取玩家称号失败", e, sql); handleDatabaseError("获取玩家称号失败", e, sql);
} }
return playerTitles; return playerTitles;
} }

View File

@ -1,28 +1,32 @@
package cn.lunadeer.miniplayertitle.dtos; package cn.lunadeer.miniplayertitle.dtos;
import cn.lunadeer.miniplayertitle.Color; import cn.lunadeer.minecraftpluginutils.ColorParser;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle; import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.HoverEvent;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
public class TitleDTO { public class TitleDTO {
private int id; private final Field id = new Field("id", FieldType.INT);
private String title; private final Field title = new Field("title", FieldType.STRING);
private String description; private final Field description = new Field("description", FieldType.STRING);
public static TitleDTO get(int id) { public static TitleDTO get(int id) {
String sql = ""; String sql = "";
sql += "SELECT id, title, description FROM mplt_title WHERE id = " + id + ";"; sql += "SELECT id, title, description FROM mplt_title WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) { try (ResultSet rs = DatabaseManager.instance.query(sql)) {
if (rs.next()) return getTitleDTO(rs); if (rs.next()) return getTitleDTO(rs);
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取称号失败", e, sql); handleDatabaseError("获取称号失败", e, sql);
} }
return null; return null;
} }
@ -33,105 +37,86 @@ public class TitleDTO {
"VALUES (?, ?) " + "VALUES (?, ?) " +
"RETURNING " + "RETURNING " +
"id, title, description;"; "id, title, description;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title, description)) { try (ResultSet rs = DatabaseManager.instance.query(sql, title, description)) {
if (rs.next()) return getTitleDTO(rs); if (rs.next()) return getTitleDTO(rs);
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("创建称号失败", e, sql); handleDatabaseError("创建称号失败", e, sql);
} }
return null; return null;
} }
public boolean delete() { public boolean delete() {
String sql = ""; String updateSql = "UPDATE mplt_player_info SET using_title_id = -1 WHERE using_title_id = ?;";
sql += "DELETE FROM mplt_title WHERE id = ?;"; String deleteSql = "DELETE FROM mplt_title WHERE id = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) { try {
// 执行更新操作
DatabaseManager.instance.query(updateSql, getId());
// 执行删除操作
DatabaseManager.instance.query(deleteSql, getId());
return true; return true;
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("删除称号失败", e, sql); handleDatabaseError("删除称号失败", e, updateSql + " " + deleteSql);
return false;
} }
return false;
} }
public static List<TitleDTO> getAll() { public static List<TitleDTO> getAll() {
String sql = ""; String sql = "";
sql += "SELECT id, title, description FROM mplt_title;"; sql += "SELECT id, title, description FROM mplt_title;";
List<TitleDTO> titleDTOs = new ArrayList<>(); List<TitleDTO> titleDTOs = new ArrayList<>();
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) { try (ResultSet rs = DatabaseManager.instance.query(sql)) {
while (rs.next()) { while (rs.next()) {
titleDTOs.add(getTitleDTO(rs)); titleDTOs.add(getTitleDTO(rs));
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取称号列表失败", e, sql); handleDatabaseError("获取称号列表失败", e, sql);
} }
return titleDTOs; return titleDTOs;
} }
public TextComponent getTitleColored() { public TextComponent getTitleColored() {
TextComponent prefix = Component.text(MiniPlayerTitle.config.getPrefix()); String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
TextComponent suffix = Component.text(MiniPlayerTitle.config.getSuffix()); return ColorParser.getComponentType(with_pre_suf);
String[] parts = this.title.split("&#"); }
List<TextComponent> components = new ArrayList<>();
components.add(prefix); /**
for (String part : parts) { * 获取称号的颜色化字符串
if (part.isEmpty()) { * 需要使用 ChatColor.translateAlternateColorCodes 方法对返回字符串进行处理
continue; * &#FFFFFF -> &x&f&f&f&f&f
} *
// match hex regx ^[0-9a-fA-F]{6}$ * @return String
Color color = new Color("#ffffff"); */
String content; public String getTitleColoredBukkit() {
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) { String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
String color_str = part.substring(0, 6); return ColorParser.getBukkitType(with_pre_suf);
color = new Color("#" + color_str);
content = part.substring(6);
} else {
content = part;
}
components.add(Component.text(content, color.getStyle()));
}
components.add(suffix);
TextComponent.Builder title_component = Component.text();
for (TextComponent component : components) {
title_component.append(component);
}
return title_component.build().hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, Component.text(this.description)));
} }
public String getTitlePlainText() { public String getTitlePlainText() {
String[] parts = this.title.split("&#"); return ColorParser.getPlainText(getTitleRaw());
StringBuilder res = new StringBuilder();
for (String part : parts) {
if (part.isEmpty()) {
continue;
}
String content;
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) {
content = part.substring(6);
} else {
content = part;
}
res.append(content);
}
return res.toString();
} }
public Integer getId() { public Integer getId() {
return this.id; return (Integer) this.id.value;
} }
public String getDescription() { public String getDescription() {
return this.description; return (String) this.description.value;
}
public String getTitleRaw() {
return (String) this.title.value;
} }
public boolean updateTitle(String title) { public boolean updateTitle(String title) {
String sql = ""; String sql = "";
sql += "UPDATE mplt_title SET title = ? WHERE id = ?;"; sql += "UPDATE mplt_title SET title = ? WHERE id = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title, this.id)) { try (ResultSet rs = DatabaseManager.instance.query(sql, title, getId())) {
if (rs != null && rs.next()) { if (rs != null && rs.next()) {
this.title = title; this.title.value = title;
return true; return true;
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("更新称号失败", e, sql); handleDatabaseError("更新称号失败", e, sql);
} }
return false; return false;
} }
@ -139,22 +124,22 @@ public class TitleDTO {
public boolean updateDescription(String description) { public boolean updateDescription(String description) {
String sql = ""; String sql = "";
sql += "UPDATE mplt_title SET description = ? WHERE id = ?;"; sql += "UPDATE mplt_title SET description = ? WHERE id = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, description, this.id)) { try (ResultSet rs = DatabaseManager.instance.query(sql, description, getId())) {
if (rs != null && rs.next()) { if (rs != null && rs.next()) {
this.description = description; this.description.value = description;
return true; return true;
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("更新称号失败", e, sql); handleDatabaseError("更新称号失败", e, sql);
} }
return false; return false;
} }
private static TitleDTO getTitleDTO(ResultSet rs) throws SQLException { private static TitleDTO getTitleDTO(ResultSet rs) throws SQLException {
TitleDTO titleDTO = new TitleDTO(); TitleDTO titleDTO = new TitleDTO();
titleDTO.id = rs.getInt("id"); titleDTO.id.value = rs.getInt("id");
titleDTO.title = rs.getString("title"); titleDTO.title.value = rs.getString("title");
titleDTO.description = rs.getString("description"); titleDTO.description.value = rs.getString("description");
return titleDTO; return titleDTO;
} }
} }

View File

@ -1,69 +1,77 @@
package cn.lunadeer.miniplayertitle.dtos; package cn.lunadeer.miniplayertitle.dtos;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
public class TitleShopDTO { public class TitleShopDTO {
private Integer id;
private TitleDTO title; private TitleDTO title;
private Integer price; private final Field id = new Field("id", FieldType.INT);
private Integer days; private final Field price = new Field("price_d", FieldType.DOUBLE);
private Integer amount; private final Field days = new Field("days", FieldType.INT);
private final Field amount = new Field("amount", FieldType.INT);
private LocalDateTime sale_end_at; private LocalDateTime sale_end_at;
public Integer getId() { public Integer getId() {
return id; return (Integer) id.value;
} }
public TitleDTO getTitle() { public TitleDTO getTitle() {
return title; return title;
} }
public Integer getPrice() { public Double getPrice() {
return price; return (Double) price.value;
} }
public boolean setPrice(int price) { public boolean setPrice(Double price) {
String sql = ""; 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)) { try (ResultSet rs = DatabaseManager.instance.query(sql, price, getId())) {
this.price.value = price;
return true; return true;
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置称号商店价格失败", e, sql); handleDatabaseError("设置称号商店价格失败", e, sql);
} }
return false; return false;
} }
public Integer getDays() { public Integer getDays() {
return days; return (Integer) days.value;
} }
public boolean setDays(int days) { public boolean setDays(int days) {
String sql = ""; String sql = "";
sql += "UPDATE mplt_title_shop SET days = ? WHERE id = ?;"; sql += "UPDATE mplt_title_shop SET days = ? WHERE id = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, days, id)) { try (ResultSet rs = DatabaseManager.instance.query(sql, days, getId())) {
this.days.value = days;
return true; return true;
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置称号商店天数失败", e, sql); handleDatabaseError("设置称号商店天数失败", e, sql);
} }
return false; return false;
} }
public Integer getAmount() { public Integer getAmount() {
return amount; return (Integer) amount.value;
} }
public boolean setAmount(int amount) { public boolean setAmount(int amount) {
String sql = ""; String sql = "";
sql += "UPDATE mplt_title_shop SET amount = ? WHERE id = ?;"; sql += "UPDATE mplt_title_shop SET amount = ? WHERE id = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, amount, id)) { try (ResultSet rs = DatabaseManager.instance.query(sql, amount, getId())) {
this.amount.value = amount;
return true; return true;
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置称号商店数量失败", e, sql); handleDatabaseError("设置称号商店数量失败", e, sql);
} }
return false; return false;
} }
@ -79,51 +87,51 @@ public class TitleShopDTO {
public boolean setSaleEndAt(int y, int m, int d) { public boolean setSaleEndAt(int y, int m, int d) {
String sql = ""; String sql = "";
sql += "UPDATE mplt_title_shop SET sale_end_at_y = ?, sale_end_at_m = ?, sale_end_at_d = ? WHERE id = ?;"; sql += "UPDATE mplt_title_shop SET sale_end_at_y = ?, sale_end_at_m = ?, sale_end_at_d = ? WHERE id = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, y, m, d, id)) { try (ResultSet rs = DatabaseManager.instance.query(sql, y, m, d, getId())) {
return true; return true;
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置称号商店销售结束时间失败", e, sql); handleDatabaseError("设置称号商店销售结束时间失败", e, sql);
} }
return false; return false;
} }
public static TitleShopDTO get(Integer id) { public static TitleShopDTO get(Integer id) {
String sql = ""; 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 = ?;"; "FROM mplt_title_shop WHERE id = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) { try (ResultSet rs = DatabaseManager.instance.query(sql, id)) {
if (rs.next()) { if (rs.next()) {
return getTitleShop(rs); return getTitleShop(rs);
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取称号商店信息失败", e, sql); handleDatabaseError("获取称号商店信息失败", e, sql);
} }
return null; return null;
} }
public static List<TitleShopDTO> getAll() { public static List<TitleShopDTO> getAll() {
String sql = ""; 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;"; "FROM mplt_title_shop;";
List<TitleShopDTO> titleShops = new ArrayList<>(); List<TitleShopDTO> titleShops = new ArrayList<>();
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) { try (ResultSet rs = DatabaseManager.instance.query(sql)) {
while (rs != null && rs.next()) { while (rs != null && rs.next()) {
TitleShopDTO titleShop = getTitleShop(rs); TitleShopDTO titleShop = getTitleShop(rs);
titleShops.add(titleShop); titleShops.add(titleShop);
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取称号商店列表失败", e, sql); handleDatabaseError("获取称号商店列表失败", e, sql);
} }
return titleShops; return titleShops;
} }
private static TitleShopDTO getTitleShop(ResultSet rs) throws Exception { private static TitleShopDTO getTitleShop(ResultSet rs) throws Exception {
TitleShopDTO titleShop = new TitleShopDTO(); TitleShopDTO titleShop = new TitleShopDTO();
titleShop.id = rs.getInt("id"); titleShop.id.value = rs.getInt("id");
titleShop.title = TitleDTO.get(rs.getInt("title_id")); titleShop.title = TitleDTO.get(rs.getInt("title_id"));
titleShop.price = rs.getInt("price"); titleShop.price.value = rs.getDouble("price_d");
titleShop.days = rs.getInt("days"); titleShop.days.value = rs.getInt("days");
titleShop.amount = rs.getInt("amount"); titleShop.amount.value = rs.getInt("amount");
int y = rs.getInt("sale_end_at_y"); int y = rs.getInt("sale_end_at_y");
int m = rs.getInt("sale_end_at_m"); int m = rs.getInt("sale_end_at_m");
int d = rs.getInt("sale_end_at_d"); int d = rs.getInt("sale_end_at_d");
@ -137,16 +145,16 @@ public class TitleShopDTO {
public static TitleShopDTO create(TitleDTO title) { public static TitleShopDTO create(TitleDTO title) {
String sql = ""; 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) " + "VALUES (?, 0, -1, 0, -1, -1, -1) " +
"RETURNING " + "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())) { try (ResultSet rs = DatabaseManager.instance.query(sql, title.getId())) {
if (rs.next()) { if (rs.next()) {
return getTitleShop(rs); return getTitleShop(rs);
} }
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("创建称号商店失败", e, sql); handleDatabaseError("创建称号商店失败", e, sql);
} }
return null; return null;
} }
@ -154,10 +162,10 @@ public class TitleShopDTO {
public boolean delete() { public boolean delete() {
String sql = ""; String sql = "";
sql += "DELETE FROM mplt_title_shop WHERE id = ?;"; sql += "DELETE FROM mplt_title_shop WHERE id = ?;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) { try (ResultSet rs = DatabaseManager.instance.query(sql, getId())) {
return true; return true;
} catch (Exception e) { } catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("删除称号商店失败", e, sql); handleDatabaseError("删除称号商店失败", e, sql);
} }
return false; return false;
} }

View File

@ -1,9 +1,8 @@
package cn.lunadeer.miniplayertitle; package cn.lunadeer.miniplayertitle.events;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -18,28 +17,20 @@ public class Events implements Listener {
Player bukkitPlayer = event.getPlayer(); Player bukkitPlayer = event.getPlayer();
PlayerInfoDTO player = PlayerInfoDTO.get(bukkitPlayer); PlayerInfoDTO player = PlayerInfoDTO.get(bukkitPlayer);
if (player == null) { if (player == null) {
MiniPlayerTitle.notification.error(bukkitPlayer, "获取玩家信息时出现错误,请联系管理员"); Notification.error(bukkitPlayer, "获取玩家信息时出现错误,请联系管理员");
return;
}
if (player.getUsingTitle().getId() == -1) {
updateName(bukkitPlayer, null);
return; return;
} }
PlayerTitleDTO title = PlayerTitleDTO.get(bukkitPlayer.getUniqueId(), player.getUsingTitle().getId()); PlayerTitleDTO title = PlayerTitleDTO.get(bukkitPlayer.getUniqueId(), player.getUsingTitle().getId());
if (title == null || title.isExpired()) { if (title == null || title.isExpired()) {
MiniPlayerTitle.notification.warn(bukkitPlayer, "你当前使用的称号 %s 已过期", player.getUsingTitle().getTitlePlainText()); Notification.warn(bukkitPlayer, "你当前使用的称号 %s 已过期", player.getUsingTitle().getTitlePlainText());
player.setUsingTitle(null); player.setUsingTitle(null);
updateName(bukkitPlayer, null); updateName(bukkitPlayer, null);
} else { } else {
updateName(bukkitPlayer, title.getTitle()); updateName(bukkitPlayer, title.getTitle());
} }
} }
@EventHandler
public void onPlayerSendChat(AsyncChatEvent event) {
Component nameComponent = event.getPlayer().displayName();
Component chatComponent = event.message();
Component newChatComponent = Component.text()
.append(nameComponent)
.append(Component.text(" "))
.append(chatComponent).build();
event.setCancelled(true);
event.getPlayer().getServer().sendMessage(newChatComponent);
}
} }

View File

@ -0,0 +1,25 @@
package cn.lunadeer.miniplayertitle.events;
import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.text.Component;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
public class PaperChat implements Listener {
@EventHandler
public void onPlayerSendChat(AsyncChatEvent event) {
if (usingPapi()) {
return;
}
Component nameComponent = event.getPlayer().displayName();
Component chatComponent = event.message();
Component newChatComponent = Component.text()
.append(nameComponent)
.append(Component.text(" "))
.append(chatComponent).build();
event.setCancelled(true);
event.getPlayer().getServer().sendMessage(newChatComponent);
}
}

View File

@ -0,0 +1,19 @@
package cn.lunadeer.miniplayertitle.events;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;
import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
public class SpigotChat implements Listener {
@EventHandler
public void onPlayerSendChat(PlayerChatEvent event) {
if (usingPapi()) {
return;
}
event.setCancelled(true);
MiniPlayerTitle.instance.getServer().broadcastMessage(event.getPlayer().getDisplayName() + " " + event.getMessage());
}
}

View File

@ -32,7 +32,7 @@ public class AllTitles {
Line line = Line.create() Line line = Line.create()
.append(title.getId().toString()) .append(title.getId().toString())
.append(title.getTitleColored()); .append(title.getTitleColored());
if (player.isOp()) { if (player.hasPermission("mplt.admin")) {
line.append(Button.createRed("删除").setExecuteCommand("/mplt delete_title " + title.getId() + " " + page).build()); line.append(Button.createRed("删除").setExecuteCommand("/mplt delete_title " + title.getId() + " " + page).build());
line.append(Button.createGreen("创建商品").setExecuteCommand("/mplt create_sale " + title.getId()).build()); line.append(Button.createGreen("创建商品").setExecuteCommand("/mplt create_sale " + title.getId()).build());
} }

View File

@ -1,13 +1,13 @@
package cn.lunadeer.miniplayertitle.tuis; package cn.lunadeer.miniplayertitle.tuis;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle; import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class Apis { public class Apis {
public static Player playerOnly(CommandSender sender) { public static Player playerOnly(CommandSender sender) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
MiniPlayerTitle.notification.error(sender, "该命令只能由玩家执行"); Notification.error(sender, "该命令只能由玩家执行");
return null; return null;
} }
return (Player) sender; return (Player) sender;

View File

@ -1,5 +1,7 @@
package cn.lunadeer.miniplayertitle.tuis; package cn.lunadeer.miniplayertitle.tuis;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
import cn.lunadeer.minecraftpluginutils.stui.ListView; import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button; import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line; import cn.lunadeer.minecraftpluginutils.stui.components.Line;
@ -20,11 +22,17 @@ public class Menu {
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId()); PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
if (playerInfo == null) { if (playerInfo == null) {
MiniPlayerTitle.notification.error(player, "获取玩家信息时出现错误"); Notification.error(player, "获取玩家信息时出现错误");
return; return;
} }
Line balance = Line.create() Line balance;
.append("称号币余额: ").append(playerInfo.getCoin().toString()); if (!MiniPlayerTitle.config.isExternalEco()) {
balance = Line.create()
.append("称号币余额: ").append(playerInfo.getCoin().toString());
} else {
balance = Line.create()
.append("余额: ").append(playerInfo.getCoin().toString()).append(VaultConnect.instance.currencyNamePlural());
}
Line backpack = Line.create() Line backpack = Line.create()
.append(Button.create("称号背包").setExecuteCommand("/mplt my_titles").build()).append("查看你拥有的称号"); .append(Button.create("称号背包").setExecuteCommand("/mplt my_titles").build()).append("查看你拥有的称号");
Line shop = Line.create() Line shop = Line.create()
@ -50,7 +58,7 @@ public class Menu {
Line all = Line.create() Line all = Line.create()
.append(Button.create("所有称号").setExecuteCommand("/mplt all_titles").build()).append("查看所有称号"); .append(Button.create("所有称号").setExecuteCommand("/mplt all_titles").build()).append("查看所有称号");
if (player.isOp()) { if (player.hasPermission("mplt.admin")) {
view.add(Line.create().append("")); view.add(Line.create().append(""));
view.add(Line.create().append("---以下选项仅OP可见---")); view.add(Line.create().append("---以下选项仅OP可见---"));
view.add(all); view.add(all);

View File

@ -1,9 +1,9 @@
package cn.lunadeer.miniplayertitle.tuis; package cn.lunadeer.miniplayertitle.tuis;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.stui.ListView; import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button; import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line; import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -24,7 +24,7 @@ public class MyTitles {
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId()); PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
if (playerInfo == null) { if (playerInfo == null) {
MiniPlayerTitle.notification.error(player, "获取玩家信息时出现错误,详情请查看控制台日志"); Notification.error(player, "获取玩家信息时出现错误,详情请查看控制台日志");
return; return;
} }
List<PlayerTitleDTO> titles = PlayerTitleDTO.getAllOf(player.getUniqueId()); List<PlayerTitleDTO> titles = PlayerTitleDTO.getAllOf(player.getUniqueId());
@ -47,7 +47,7 @@ public class MyTitles {
} else { } else {
line.append("有效期至: " + title.getExpireAt().getYear() + "" + title.getExpireAt().getMonthValue() + "" + title.getExpireAt().getDayOfMonth() + ""); line.append("有效期至: " + title.getExpireAt().getYear() + "" + title.getExpireAt().getMonthValue() + "" + title.getExpireAt().getDayOfMonth() + "");
} }
if (Objects.equals(playerInfo.getUsingTitle().getId(), title.getId())) { if (Objects.equals(playerInfo.getUsingTitle().getId(), title.getTitle().getId())) {
line.append(Button.createRed("卸下").setExecuteCommand("/mplt use_title -1 " + page).build()); line.append(Button.createRed("卸下").setExecuteCommand("/mplt use_title -1 " + page).build());
} else { } else {
line.append(Button.createGreen("使用").setExecuteCommand("/mplt use_title " + title.getId() + " " + page).build()); line.append(Button.createGreen("使用").setExecuteCommand("/mplt use_title " + title.getId() + " " + page).build());

View File

@ -1,10 +1,10 @@
package cn.lunadeer.miniplayertitle.tuis; package cn.lunadeer.miniplayertitle.tuis;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.stui.ListView; import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button; import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line; import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import cn.lunadeer.minecraftpluginutils.stui.components.NumChanger; import cn.lunadeer.minecraftpluginutils.stui.components.NumChanger;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO; import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO; import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -23,12 +23,12 @@ public class SaleInfo {
int page = getArgPage(args, 3); int page = getArgPage(args, 3);
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1])); TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
if (titleShop == null) { if (titleShop == null) {
MiniPlayerTitle.notification.error(player, "获取详情时出现错误"); Notification.error(player, "获取详情时出现错误");
return; return;
} }
TitleDTO title = titleShop.getTitle(); TitleDTO title = titleShop.getTitle();
if (title == null) { if (title == null) {
MiniPlayerTitle.notification.error(player, "获取详情时出现错误"); Notification.error(player, "获取详情时出现错误");
return; return;
} }
int now_year = LocalDateTime.now().getYear(); int now_year = LocalDateTime.now().getYear();
@ -46,11 +46,11 @@ public class SaleInfo {
Line price = Line.create().append("价格: "); Line price = Line.create().append("价格: ");
if (titleShop.getPrice() <= 0) { if (titleShop.getPrice() <= 0) {
price.append("免费"); price.append("免费");
if (player.isOp()) { if (player.hasPermission("mplt.admin")) {
price.append(Button.create("设置价格").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 100 " + page).build()); price.append(Button.create("设置价格").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 100 " + page).build());
} }
} else { } else {
if (player.isOp()) { if (player.hasPermission("mplt.admin")) {
price.append(NumChanger.create(titleShop.getPrice(), "/mplt set_sale price " + titleShop.getId()).setPageNumber(page).build()); price.append(NumChanger.create(titleShop.getPrice(), "/mplt set_sale price " + titleShop.getId()).setPageNumber(page).build());
price.append(Button.create("设置为免费").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 0 " + page).build()); price.append(Button.create("设置为免费").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 0 " + page).build());
} else { } else {
@ -62,11 +62,11 @@ public class SaleInfo {
Line day = Line.create().append("购买天数: "); Line day = Line.create().append("购买天数: ");
if (titleShop.getDays() <= 0) { if (titleShop.getDays() <= 0) {
day.append("永久"); day.append("永久");
if (player.isOp()) { if (player.hasPermission("mplt.admin")) {
day.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " 7 " + page).build()); day.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " 7 " + page).build());
} }
} else { } else {
if (player.isOp()) { if (player.hasPermission("mplt.admin")) {
day.append(NumChanger.create(titleShop.getDays(), "/mplt set_sale days " + titleShop.getId()).setPageNumber(page).build()); day.append(NumChanger.create(titleShop.getDays(), "/mplt set_sale days " + titleShop.getId()).setPageNumber(page).build());
day.append(Button.create("转为永久").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " -1 " + page).build()); day.append(Button.create("转为永久").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " -1 " + page).build());
} else { } else {
@ -78,12 +78,12 @@ public class SaleInfo {
Line amount = Line.create().append("剩余数量: "); Line amount = Line.create().append("剩余数量: ");
if (titleShop.getAmount() == -1) { if (titleShop.getAmount() == -1) {
amount.append("无限"); amount.append("无限");
if (player.isOp()) { if (player.hasPermission("mplt.admin")) {
amount.append(Button.create("转为限量").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " 0 " + page).build()); amount.append(Button.create("转为限量").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " 0 " + page).build());
} }
} else { } else {
if (player.isOp()) { if (player.hasPermission("mplt.admin")) {
amount.append(NumChanger.create(titleShop.getAmount(), "/mplt set_sale amount " + titleShop.getId()).setPageNumber(page).build()); amount.append(NumChanger.create(titleShop.getAmount(), "/mplt set_sale amount " + titleShop.getId()).setPageNumber(page).build());
amount.append(Button.create("转为无限").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " -1 " + page).build()); amount.append(Button.create("转为无限").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " -1 " + page).build());
} else { } else {
@ -95,11 +95,11 @@ public class SaleInfo {
Line end_at = Line.create().append("售卖结束时间: "); Line end_at = Line.create().append("售卖结束时间: ");
if (titleShop.getSaleEndAt() == null) { if (titleShop.getSaleEndAt() == null) {
end_at.append("常驻"); end_at.append("常驻");
if (player.isOp()) { if (player.hasPermission("mplt.admin")) {
end_at.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale end_at " + titleShop.getId() + " " + now_year + ":" + now_month + ":" + now_day + " " + page).build()); end_at.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale end_at " + titleShop.getId() + " " + now_year + ":" + now_month + ":" + now_day + " " + page).build());
} }
} else { } else {
if (player.isOp()) { if (player.hasPermission("mplt.admin")) {
end_at.append(Button.create("<<").setPreSufIx("", "").setHoverText("提前10天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 10 " + page).build() end_at.append(Button.create("<<").setPreSufIx("", "").setHoverText("提前10天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 10 " + page).build()
.append(Button.create("-").setPreSufIx("", "").setHoverText("提前1天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 1 " + page).build()) .append(Button.create("-").setPreSufIx("", "").setHoverText("提前1天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 1 " + page).build())
.append(Component.text(titleShop.getSaleEndAt().getYear() + "" + titleShop.getSaleEndAt().getMonthValue() + "" + titleShop.getSaleEndAt().getDayOfMonth() + "")) .append(Component.text(titleShop.getSaleEndAt().getYear() + "" + titleShop.getSaleEndAt().getMonthValue() + "" + titleShop.getSaleEndAt().getDayOfMonth() + ""))
@ -120,8 +120,9 @@ public class SaleInfo {
} else { } else {
operate.append(Button.createGreen("购买").setExecuteCommand("/mplt buy_sale " + titleShop.getId()).build()); operate.append(Button.createGreen("购买").setExecuteCommand("/mplt buy_sale " + titleShop.getId()).build());
} }
if (player.isOp()) { if (player.hasPermission("mplt.admin")) {
operate.append(Button.create("删除").setExecuteCommand("/mplt delete_sale " + args[1] + " b").build()); operate.append(Button.create("删除").setExecuteCommand("/mplt delete_sale " + args[1] + " b").build());
operate.append(Button.createGreen("导出称号卡").setExecuteCommand("/mplt get_card " + args[1]).build());
} }
view.add(Line.create().append("---------------------")); view.add(Line.create().append("---------------------"));
view.add(operate); view.add(operate);

View File

@ -16,10 +16,6 @@ public class ConfigManager {
_file = _plugin.getConfig(); _file = _plugin.getConfig();
_debug = _file.getBoolean("Debug", false); _debug = _file.getBoolean("Debug", false);
_db_type = _file.getString("Database.Type", "sqlite"); _db_type = _file.getString("Database.Type", "sqlite");
if (!_db_type.equals("pgsql") && !_db_type.equals("sqlite")) {
MiniPlayerTitle.logger.err("当前数据库只支持 pgsql 或 sqlite已重置为 sqlite");
setDbType("sqlite");
}
_db_host = _file.getString("Database.Host", "localhost"); _db_host = _file.getString("Database.Host", "localhost");
_db_port = _file.getString("Database.Port", "5432"); _db_port = _file.getString("Database.Port", "5432");
_db_name = _file.getString("Database.Name", "miniplayertitle"); _db_name = _file.getString("Database.Name", "miniplayertitle");
@ -32,6 +28,7 @@ public class ConfigManager {
_custom_cost = _file.getInt("CustomCost.Cost", 1000); _custom_cost = _file.getInt("CustomCost.Cost", 1000);
_max_length = _file.getInt("CustomCost.MaxLength", 8); _max_length = _file.getInt("CustomCost.MaxLength", 8);
_check_update = _file.getBoolean("CheckUpdate", true); _check_update = _file.getBoolean("CheckUpdate", true);
_external_eco = _file.getBoolean("ExternalEco", false);
} }
public Boolean isDebug() { public Boolean isDebug() {
@ -141,6 +138,10 @@ public class ConfigManager {
return _check_update; return _check_update;
} }
public Boolean isExternalEco() {
return _external_eco;
}
private final MiniPlayerTitle _plugin; private final MiniPlayerTitle _plugin;
private FileConfiguration _file; private FileConfiguration _file;
@ -159,4 +160,5 @@ public class ConfigManager {
private Integer _custom_cost; private Integer _custom_cost;
private Integer _max_length; private Integer _max_length;
private Boolean _check_update; private Boolean _check_update;
private Boolean _external_eco;
} }

View File

@ -1,112 +1,172 @@
package cn.lunadeer.miniplayertitle.utils; package cn.lunadeer.miniplayertitle.utils;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
import cn.lunadeer.minecraftpluginutils.databse.TableColumn;
import cn.lunadeer.minecraftpluginutils.databse.syntax.AddColumn;
import cn.lunadeer.minecraftpluginutils.databse.syntax.CreateTable;
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
import cn.lunadeer.minecraftpluginutils.databse.syntax.RemoveColumn;
import static cn.lunadeer.minecraftpluginutils.databse.Common.IsFieldExist;
public class DatabaseTables { public class DatabaseTables {
public static void migrate() { public static void migrate() {
String sql = "";
// title table // title table
sql = "CREATE TABLE IF NOT EXISTS mplt_title (" + TableColumn mplt_title_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
" id SERIAL PRIMARY KEY," + TableColumn mplt_title_title = new TableColumn("title", FieldType.STRING, false, false, true, false, "'unknown'");
" title TEXT NOT NULL UNIQUE," + TableColumn mplt_title_description = new TableColumn("description", FieldType.STRING, false, false, true, false, "'unknown'");
" description TEXT NOT NULL," + TableColumn mplt_title_enabled = new TableColumn("enabled", FieldType.BOOLEAN, false, false, true, false, "true");
" enabled BOOLEAN NOT NULL DEFAULT TRUE," + TableColumn mplt_title_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," + TableColumn mplt_title_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP" + CreateTable mplt_title = new CreateTable().ifNotExists();
");"; mplt_title.table("mplt_title")
MiniPlayerTitle.database.query(sql); .field(mplt_title_id)
.field(mplt_title_title)
.field(mplt_title_description)
.field(mplt_title_enabled)
.field(mplt_title_created_at)
.field(mplt_title_updated_at);
mplt_title.execute();
// title shop table // title shop table
sql = "CREATE TABLE IF NOT EXISTS mplt_title_shop (" + TableColumn mplt_title_shop_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
" id SERIAL PRIMARY KEY," + TableColumn mplt_title_shop_title_id = new TableColumn("title_id", FieldType.INT, false, false, true, false, 0);
" title_id INTEGER NOT NULL," + TableColumn mplt_title_shop_price = new TableColumn("price", FieldType.INT, false, false, true, false, 0);
" price INTEGER NOT NULL DEFAULT 0," + TableColumn mplt_title_shop_days = new TableColumn("days", FieldType.INT, false, false, true, false, 0);
" days INTEGER NOT NULL DEFAULT 0," + TableColumn mplt_title_shop_amount = new TableColumn("amount", FieldType.INT, false, false, true, false, -1);
" amount INTEGER NOT NULL DEFAULT -1," + TableColumn mplt_title_shop_sale_end_at = new TableColumn("sale_end_at", FieldType.LONG, false, false, true, false, -1);
" sale_end_at BIGINT NOT NULL DEFAULT -1," + TableColumn mplt_title_shop_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," + TableColumn mplt_title_shop_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," + CreateTable.ForeignKey mplt_title_shop_title_id_fk = new CreateTable.ForeignKey(mplt_title_shop_title_id, "mplt_title", mplt_title_id, true);
" FOREIGN KEY (title_id) REFERENCES mplt_title(id) ON DELETE CASCADE" + CreateTable mplt_title_shop = new CreateTable().ifNotExists();
");"; mplt_title_shop.table("mplt_title_shop")
MiniPlayerTitle.database.query(sql); .field(mplt_title_shop_id)
.field(mplt_title_shop_title_id)
.field(mplt_title_shop_price)
.field(mplt_title_shop_days)
.field(mplt_title_shop_amount)
.field(mplt_title_shop_sale_end_at)
.field(mplt_title_shop_created_at)
.field(mplt_title_shop_updated_at)
.foreignKey(mplt_title_shop_title_id_fk);
mplt_title_shop.execute();
// player title info table // player title info table
sql = "CREATE TABLE IF NOT EXISTS mplt_player_info (" + TableColumn mplt_player_info_uuid = new TableColumn("uuid", FieldType.UUID, true, false, true, false, "'00000000-0000-0000-0000-000000000000'");
" uuid UUID PRIMARY KEY," + TableColumn mplt_player_info_coin = new TableColumn("coin", FieldType.INT, false, false, true, false, 0);
" coin INTEGER NOT NULL DEFAULT 0," + TableColumn mplt_player_info_using_title_id = new TableColumn("using_title_id", FieldType.INT, false, false, true, false, -1);
" using_title_id INTEGER NOT NULL DEFAULT -1," + TableColumn mplt_player_info_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," + TableColumn mplt_player_info_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," + CreateTable.ForeignKey mplt_player_info_using_title_id_fk = new CreateTable.ForeignKey(mplt_player_info_using_title_id, "mplt_title", mplt_title_id, true);
" FOREIGN KEY (using_title_id) REFERENCES mplt_title(id) ON DELETE CASCADE" + CreateTable mplt_player_info = new CreateTable().ifNotExists();
");"; mplt_player_info.table("mplt_player_info")
MiniPlayerTitle.database.query(sql); .field(mplt_player_info_uuid)
.field(mplt_player_info_coin)
.field(mplt_player_info_using_title_id)
.field(mplt_player_info_created_at)
.field(mplt_player_info_updated_at)
.foreignKey(mplt_player_info_using_title_id_fk);
mplt_player_info.execute();
// player title table // player title table
sql = "CREATE TABLE IF NOT EXISTS mplt_player_title (" + TableColumn mplt_player_title_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
" id SERIAL PRIMARY KEY," + TableColumn mplt_player_title_player_uuid = new TableColumn("player_uuid", FieldType.UUID, false, false, true, false, "'00000000-0000-0000-0000-000000000000'");
" player_uuid UUID NOT NULL," + TableColumn mplt_player_title_title_id = new TableColumn("title_id", FieldType.INT, false, false, true, false, 0);
" title_id INTEGER NOT NULL," + TableColumn mplt_player_title_expire_at = new TableColumn("expire_at", FieldType.LONG, false, false, true, false, -1);
" expire_at BIGINT NOT NULL DEFAULT -1," + TableColumn mplt_player_title_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," + TableColumn mplt_player_title_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," + CreateTable.ForeignKey mplt_player_title_title_id_fk = new CreateTable.ForeignKey(mplt_player_title_title_id, "mplt_title", mplt_title_id, true);
" FOREIGN KEY (title_id) REFERENCES mplt_title(id) ON DELETE CASCADE," + CreateTable.ForeignKey mplt_player_title_player_uuid_fk = new CreateTable.ForeignKey(mplt_player_title_player_uuid, "mplt_player_info", mplt_player_info_uuid, true);
" FOREIGN KEY (player_uuid) REFERENCES mplt_player_info(uuid) ON DELETE CASCADE" + CreateTable mplt_player_title = new CreateTable().ifNotExists();
");"; mplt_player_title.table("mplt_player_title")
MiniPlayerTitle.database.query(sql); .field(mplt_player_title_id)
.field(mplt_player_title_player_uuid)
.field(mplt_player_title_title_id)
.field(mplt_player_title_expire_at)
.field(mplt_player_title_created_at)
.field(mplt_player_title_updated_at)
.foreignKey(mplt_player_title_title_id_fk)
.foreignKey(mplt_player_title_player_uuid_fk);
mplt_player_title.execute();
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "created_at"); new RemoveColumn("expire_at").IfExists().table("mplt_title").execute();
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "updated_at"); new RemoveColumn("sale_end_at").IfExists().table("mplt_title_shop").execute();
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "enabled"); new RemoveColumn("expire_at").IfExists().table("mplt_player_title").execute();
new RemoveColumn("created_at").IfExists().table("mplt_title").execute();
new RemoveColumn("updated_at").IfExists().table("mplt_title").execute();
new RemoveColumn("created_at").IfExists().table("mplt_player_info").execute();
new RemoveColumn("updated_at").IfExists().table("mplt_player_info").execute();
new RemoveColumn("created_at").IfExists().table("mplt_player_title").execute();
new RemoveColumn("updated_at").IfExists().table("mplt_player_title").execute();
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "created_at"); TableColumn mplt_title_shop_sale_end_at_y = new TableColumn("sale_end_at_y", FieldType.INT, false, false, true, false, -1);
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "updated_at"); TableColumn mplt_title_shop_sale_end_at_m = new TableColumn("sale_end_at_m", FieldType.INT, false, false, true, false, -1);
TableColumn mplt_title_shop_sale_end_at_d = new TableColumn("sale_end_at_d", FieldType.INT, false, false, true, false, -1);
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "created_at"); new AddColumn(mplt_title_shop_sale_end_at_y).table("mplt_title_shop").ifNotExists().execute();
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "updated_at"); new AddColumn(mplt_title_shop_sale_end_at_m).table("mplt_title_shop").ifNotExists().execute();
new AddColumn(mplt_title_shop_sale_end_at_d).table("mplt_title_shop").ifNotExists().execute();
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "created_at");
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "updated_at");
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_y", "INTEGER NOT NULL DEFAULT -1");
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_m", "INTEGER NOT NULL DEFAULT -1");
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_d", "INTEGER NOT NULL DEFAULT -1");
// convert sale_end_at(YYYYMMDD) to sale_end_at_y, sale_end_at_m, sale_end_at_d if sale_end_at column exists // convert sale_end_at(YYYYMMDD) to sale_end_at_y, sale_end_at_m, sale_end_at_d if sale_end_at column exists
if (MiniPlayerTitle.database.isColumnExist("mplt_title_shop", "sale_end_at")) { if (IsFieldExist("mplt_title_shop", "sale_end_at")) {
sql = "UPDATE mplt_title_shop SET " + String sql = "UPDATE mplt_title_shop SET " +
"sale_end_at_y = (sale_end_at / 10000), " + "sale_end_at_y = (sale_end_at / 10000), " +
"sale_end_at_m = (sale_end_at % 10000 / 100), " + "sale_end_at_m = (sale_end_at % 10000 / 100), " +
"sale_end_at_d = (sale_end_at % 100) " + "sale_end_at_d = (sale_end_at % 100) " +
"WHERE sale_end_at != -1;"; "WHERE sale_end_at != -1;";
MiniPlayerTitle.database.query(sql); DatabaseManager.instance.query(sql);
new RemoveColumn("sale_end_at").IfExists().table("mplt_title_shop").execute();
} }
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "sale_end_at");
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_y", "INTEGER NOT NULL DEFAULT -1");
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_m", "INTEGER NOT NULL DEFAULT -1"); TableColumn mplt_player_title_expire_at_y = new TableColumn("expire_at_y", FieldType.INT, false, false, true, false, -1);
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_d", "INTEGER NOT NULL DEFAULT -1"); TableColumn mplt_player_title_expire_at_m = new TableColumn("expire_at_m", FieldType.INT, false, false, true, false, -1);
if (MiniPlayerTitle.database.isColumnExist("mplt_player_title", "expire_at")) { TableColumn mplt_player_title_expire_at_d = new TableColumn("expire_at_d", FieldType.INT, false, false, true, false, -1);
sql = "UPDATE mplt_player_title SET " + new AddColumn(mplt_player_title_expire_at_y).table("mplt_player_title").ifNotExists().execute();
new AddColumn(mplt_player_title_expire_at_m).table("mplt_player_title").ifNotExists().execute();
new AddColumn(mplt_player_title_expire_at_d).table("mplt_player_title").ifNotExists().execute();
if (IsFieldExist("mplt_player_title", "expire_at")) {
String sql = "UPDATE mplt_player_title SET " +
"expire_at_y = (expire_at / 10000), " + "expire_at_y = (expire_at / 10000), " +
"expire_at_m = (expire_at % 10000 / 100), " + "expire_at_m = (expire_at % 10000 / 100), " +
"expire_at_d = (expire_at % 100) " + "expire_at_d = (expire_at % 100) " +
"WHERE expire_at != -1;"; "WHERE expire_at != -1;";
MiniPlayerTitle.database.query(sql); DatabaseManager.instance.query(sql);
new RemoveColumn("expire_at").IfExists().table("mplt_player_title").execute();
} }
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "expire_at");
sql = "INSERT INTO mplt_title (" + Field mplt_title_id_field = new Field("id", -1);
"id, " + Field mplt_title_title_field = new Field("title", "default");
"title, " + Field mplt_title_description_field = new Field("description", "default");
"description " + InsertRow mplt_title_default = new InsertRow().table("mplt_title");
") VALUES (" + mplt_title_default.field(mplt_title_id_field)
"-1, " + .field(mplt_title_title_field)
"'default', " + .field(mplt_title_description_field).onConflictDoNothing(mplt_title_id_field);
"'default' " + mplt_title_default.execute();
") ON CONFLICT (id) DO NOTHING;";
MiniPlayerTitle.database.query(sql);
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_info", "last_use_name", "TEXT NOT NULL DEFAULT 'null'");
TableColumn mplt_player_info_last_use_name = new TableColumn("last_use_name", FieldType.STRING, false, false, true, false, "'null'");
new AddColumn(mplt_player_info_last_use_name).table("mplt_player_info").ifNotExists().execute();
// 3.0.6
TableColumn mplt_player_info_coin_d = new TableColumn("coin_d", FieldType.DOUBLE, false, false, true, false, 0);
TableColumn mplt_title_shop_price_d = new TableColumn("price_d", FieldType.DOUBLE, false, false, true, false, 0);
new AddColumn(mplt_player_info_coin_d).table("mplt_player_info").ifNotExists().execute();
new AddColumn(mplt_title_shop_price_d).table("mplt_title_shop").ifNotExists().execute();
if (IsFieldExist("mplt_player_info", "coin")) {
String sql = "UPDATE mplt_player_info SET coin_d = coin;";
DatabaseManager.instance.query(sql);
new RemoveColumn("coin").IfExists().table("mplt_player_info").execute();
}
if (IsFieldExist("mplt_title_shop", "price")) {
String sql = "UPDATE mplt_title_shop SET price_d = price;";
DatabaseManager.instance.query(sql);
new RemoveColumn("price").IfExists().table("mplt_title_shop").execute();
}
} }
} }

View File

@ -16,6 +16,8 @@ CustomCost:
DefaultCoin: 0 DefaultCoin: 0
ExternalEco: false # 使用外部经济插件 需要Vault支持
CheckUpdate: true CheckUpdate: true
Debug: false Debug: false

View File

@ -5,8 +5,20 @@ api-version: '1.20'
description: 称号插件。 description: 称号插件。
website: https://lunadeer.cn website: https://lunadeer.cn
folia-supported: true folia-supported: true
softdepend: [ PlaceholderAPI, Vault ]
commands: commands:
MiniPlayerTitle: MiniPlayerTitle:
description: 称号插件命令 description: 称号插件命令
usage: /mplt <cmd> usage: /mplt <cmd>
aliases: [mplt] aliases: [ mplt ]
permission: mplt.command
permissions:
mplt.command:
description: 普通命令
default: true
mplt.custom:
description: 是否可以自定义称号
default: true
mplt.admin:
description: 是否可以使用管理员命令
default: op