Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
40e561bff1 | |||
11856a29a6 | |||
78de7dca65 | |||
466dd84fac | |||
283e435b70 | |||
2981ac0183 | |||
02d44610c6 | |||
31a1d409b7 | |||
9de1b5cced | |||
d629b1daf7 | |||
b52fce2479 | |||
3ffab50c9b | |||
a007966d70 | |||
ddf5ae711a | |||
f5fe78f4d1 | |||
25fe5fbb09 | |||
fc5f167587 | |||
706ea9a5a5 | |||
c4d25b79cf | |||
8ef1c9a7d0 | |||
c7d8baf885 | |||
1e661badc2 | |||
8280383e4b | |||
eb1aee7949 | |||
8b218538c6 | |||
9898566a77 | |||
b17f951e7d | |||
118a4e72d0 | |||
c1df7a44c2 | |||
0ec55beee2 | |||
3432c29116 | |||
20cd4278ad | |||
3c54272686 | |||
56d0266f23 | |||
eda8a8f22f |
@ -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%">
|
||||
|
||||
### [开源地址](https://ssl.lunadeer.cn:14446/zhangyuheng/MiniPlayerTitle) | [文档地址](https://ssl.lunadeer.cn:14448/doc/2/)
|
||||
|
||||
### [下载页面](https://ssl.lunadeer.cn:14446/zhangyuheng/MiniPlayerTitle/releases)
|
||||
|
||||
### [统计页面](https://bstats.org/plugin/bukkit/MiniPlayerTitle/21444) | [Hangar](https://hangar.papermc.io/zhangyuheng/MiniPlayerTitle)
|
||||
|
||||
</div>
|
||||
@ -26,10 +28,12 @@
|
||||
- 本插件使用 **TUI** 作为简易的交互方式,非 PlayerTitle 的箱子UI
|
||||
- 支持设置称号**限量销售、限时销售**
|
||||
- 支持玩家使用称号币自定义称号
|
||||
- 支持外部经济系统(需要 Vault 前置支持)(3.0.6+)
|
||||
- 支持 PlaceholderAPI (4.0.0+)
|
||||
|
||||
## 支持版本
|
||||
|
||||
- 1.20.1+ (Paper、Folia)
|
||||
- 1.20.1+ (Bukkit、Spigot、Paper、Folia)
|
||||
|
||||
## TODO
|
||||
|
||||
|
14
pom.xml
14
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.lunadeer</groupId>
|
||||
<artifactId>MiniPlayerTitle</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>4.7.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MiniPlayerTitle</name>
|
||||
@ -66,6 +66,10 @@
|
||||
<id>lunadeer-repo</id>
|
||||
<url>https://ssl.lunadeer.cn:14454/repository/maven-snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -78,7 +82,13 @@
|
||||
<dependency>
|
||||
<groupId>cn.lunadeer</groupId>
|
||||
<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>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.lunadeer.miniplayertitle;
|
||||
|
||||
import cn.lunadeer.minecraftpluginutils.XLogger;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
@ -27,7 +28,7 @@ public class Color {
|
||||
this.g = 0;
|
||||
this.b = 0;
|
||||
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.b = 0;
|
||||
this.hex = "#000000";
|
||||
MiniPlayerTitle.logger.err("Invalid color: " + hex);
|
||||
XLogger.err("Invalid color: " + hex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
package cn.lunadeer.miniplayertitle;
|
||||
|
||||
import cn.lunadeer.miniplayertitle.commands.PlayerManage;
|
||||
import cn.lunadeer.miniplayertitle.commands.TitleCard;
|
||||
import cn.lunadeer.miniplayertitle.commands.TitleManage;
|
||||
import cn.lunadeer.miniplayertitle.commands.TitleShopSale;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||
import cn.lunadeer.miniplayertitle.tuis.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -9,6 +12,8 @@ import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Commands implements TabExecutor {
|
||||
@ -20,54 +25,66 @@ public class Commands implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
switch (args[0]) {
|
||||
case "menu":
|
||||
case "menu": // mplt menu [页数]
|
||||
Menu.show(sender, args);
|
||||
break;
|
||||
case "all_titles":
|
||||
case "all_titles": // mplt all_titles [页数]
|
||||
AllTitles.show(sender, args);
|
||||
break;
|
||||
case "my_titles":
|
||||
case "my_titles": // mplt my_titles [页数]
|
||||
MyTitles.show(sender, args);
|
||||
break;
|
||||
case "shop":
|
||||
case "shop": // mplt shop [页数]
|
||||
Shop.show(sender, args);
|
||||
break;
|
||||
case "custom_info":
|
||||
case "custom_info": // mplt custom_info
|
||||
CustomInfo.show(sender, args);
|
||||
break;
|
||||
case "sale_info":
|
||||
case "sale_info": // mplt sale_info <商品ID>
|
||||
SaleInfo.show(sender, args);
|
||||
break;
|
||||
case "create_sale":
|
||||
case "create_sale": // mplt create_sale <称号ID>
|
||||
TitleShopSale.createSale(sender, args);
|
||||
break;
|
||||
case "set_sale":
|
||||
case "set_sale": // mplt set_sale <price|days|amount|end_at|more_end_at|less_end_at> <商品ID> <值> [页数]
|
||||
TitleShopSale.setSale(sender, args);
|
||||
break;
|
||||
case "delete_sale":
|
||||
case "delete_sale": // mplt delete_sale <商品ID> [页数]
|
||||
TitleShopSale.deleteSale(sender, args);
|
||||
break;
|
||||
case "buy_sale":
|
||||
case "buy_sale": // mplt buy_sale <商品ID>
|
||||
TitleShopSale.buySale(sender, args);
|
||||
break;
|
||||
case "use_title":
|
||||
case "use_title": // mplt use_title <背包ID> [页码]
|
||||
TitleManage.useTitle(sender, args);
|
||||
break;
|
||||
case "create_title":
|
||||
case "create_title": // mplt create_title <称号名称> [称号描述]
|
||||
TitleManage.createTitle(sender, args);
|
||||
break;
|
||||
case "delete_title":
|
||||
case "delete_title": // mplt delete_title <称号ID> [页码]
|
||||
TitleManage.deleteTitle(sender, args);
|
||||
break;
|
||||
case "set_title":
|
||||
TitleManage.setTitle(sender, args);
|
||||
case "edit_title_name": // mplt edit_title_name <称号ID> <称号名称>
|
||||
TitleManage.editTitleName(sender, args);
|
||||
break;
|
||||
case "set_desc":
|
||||
TitleManage.setTitleDescription(sender, args);
|
||||
case "edit_title_desc": // mplt edit_title_desc <称号ID> <称号描述>
|
||||
TitleManage.editTitleDescription(sender, args);
|
||||
break;
|
||||
case "custom_title":
|
||||
case "custom_title": // mplt custom_title <称号>
|
||||
TitleManage.customTitle(sender, args);
|
||||
break;
|
||||
case "add_coin": // mplt add_coin <玩家名称> <称号币数量>
|
||||
PlayerManage.addCoin(sender, args);
|
||||
break;
|
||||
case "set_coin": // mplt set_coin <玩家名称> <称号币数量>
|
||||
PlayerManage.setCoin(sender, args);
|
||||
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:
|
||||
return false;
|
||||
}
|
||||
@ -76,6 +93,77 @@ public class Commands implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
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",
|
||||
"delete_title", "edit_title_name", "edit_title_desc", "custom_title", "add_coin", "set_coin",
|
||||
"grant_title", "get_card"
|
||||
);
|
||||
}
|
||||
if (args.length == 2) {
|
||||
switch (args[0]) {
|
||||
case "sale_info":
|
||||
case "delete_sale":
|
||||
case "buy_sale":
|
||||
case "get_card":
|
||||
return Collections.singletonList("<商品ID>");
|
||||
case "create_sale":
|
||||
case "delete_title":
|
||||
case "edit_title_name":
|
||||
case "edit_title_desc":
|
||||
return Collections.singletonList("<称号ID>");
|
||||
case "use_title":
|
||||
return Collections.singletonList("<背包ID>");
|
||||
case "set_sale":
|
||||
return Arrays.asList("price", "days", "amount", "end_at", "more_end_at", "less_end_at");
|
||||
case "custom_title":
|
||||
case "create_title":
|
||||
return Collections.singletonList("<称号内容>");
|
||||
case "add_coin":
|
||||
case "set_coin":
|
||||
case "grant_title":
|
||||
return PlayerInfoDTO.playerNameList();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (args.length == 3) {
|
||||
switch (args[0]) {
|
||||
case "set_sale":
|
||||
return Collections.singletonList("<商品ID>");
|
||||
case "edit_title_desc":
|
||||
return Collections.singletonList("<新的称号描述>");
|
||||
case "edit_title_name":
|
||||
return Collections.singletonList("<新的称号名称>");
|
||||
case "create_title":
|
||||
return Collections.singletonList("<称号描述>");
|
||||
case "add_coin":
|
||||
case "set_coin":
|
||||
return Collections.singletonList("<数量>");
|
||||
case "grant_title":
|
||||
return Collections.singletonList("<称号>");
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (args.length == 4) {
|
||||
switch (args[0]) {
|
||||
case "set_sale":
|
||||
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:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
package cn.lunadeer.miniplayertitle;
|
||||
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import static cn.lunadeer.miniplayertitle.commands.Apis.updateName;
|
||||
|
||||
public class Events implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player bukkitPlayer = event.getPlayer();
|
||||
PlayerInfoDTO player = PlayerInfoDTO.get(bukkitPlayer.getUniqueId());
|
||||
if (player == null) {
|
||||
MiniPlayerTitle.notification.error(bukkitPlayer, "获取玩家信息时出现错误,请联系管理员");
|
||||
return;
|
||||
}
|
||||
updateName(bukkitPlayer, player.getUsingTitle());
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
57
src/main/java/cn/lunadeer/miniplayertitle/Expansion.java
Normal file
57
src/main/java/cn/lunadeer/miniplayertitle/Expansion.java
Normal 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();
|
||||
}
|
||||
}
|
@ -1,12 +1,23 @@
|
||||
package cn.lunadeer.miniplayertitle;
|
||||
|
||||
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.DatabaseTables;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class MiniPlayerTitle extends JavaPlugin {
|
||||
|
||||
@ -14,20 +25,35 @@ public final class MiniPlayerTitle extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
notification = new Notification(this);
|
||||
logger = new XLogger(instance);
|
||||
new Scheduler(this);
|
||||
new Notification(this);
|
||||
new XLogger(instance);
|
||||
config = new ConfigManager(instance);
|
||||
logger.setDebug(config.isDebug());
|
||||
database = new DatabaseManager(this,
|
||||
config.getDbType().equals("pgsql") ? DatabaseManager.TYPE.POSTGRESQL : DatabaseManager.TYPE.SQLITE,
|
||||
XLogger.setDebug(config.isDebug());
|
||||
new DatabaseManager(this,
|
||||
DatabaseType.valueOf(config.getDbType().toUpperCase()),
|
||||
config.getDbHost(),
|
||||
config.getDbPort(),
|
||||
config.getDbName(),
|
||||
config.getDbUser(),
|
||||
config.getDbPass());
|
||||
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 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")).setTabCompleter(new Commands());
|
||||
|
||||
@ -39,28 +65,39 @@ public final class MiniPlayerTitle extends JavaPlugin {
|
||||
"MiniPlayerTitle");
|
||||
}
|
||||
|
||||
logger.info("称号插件已加载");
|
||||
logger.info("版本: " + getPluginMeta().getVersion());
|
||||
XLogger.info("称号插件已加载");
|
||||
XLogger.info("版本: " + this.getDescription().getVersion());
|
||||
// http://patorjk.com/software/taag/#p=display&f=Big&t=MiniPlayerTitle
|
||||
logger.info(" __ __ _ _ _____ _ _______ _ _ _");
|
||||
logger.info(" | \\/ (_) (_) __ \\| | |__ __(_) | | |");
|
||||
logger.info(" | \\ / |_ _ __ _| |__) | | __ _ _ _ ___ _ __| | _| |_| | ___");
|
||||
logger.info(" | |\\/| | | '_ \\| | ___/| |/ _` | | | |/ _ \\ '__| | | | __| |/ _ \\");
|
||||
logger.info(" | | | | | | | | | | | | (_| | |_| | __/ | | | | | |_| | __/");
|
||||
logger.info(" |_| |_|_|_| |_|_|_| |_|\\__,_|\\__, |\\___|_| |_| |_|\\__|_|\\___|");
|
||||
logger.info(" __/ |");
|
||||
logger.info(" |___/");
|
||||
XLogger.info(" __ __ _ _ _____ _ _______ _ _ _");
|
||||
XLogger.info(" | \\/ (_) (_) __ \\| | |__ __(_) | | |");
|
||||
XLogger.info(" | \\ / |_ _ __ _| |__) | | __ _ _ _ ___ _ __| | _| |_| | ___");
|
||||
XLogger.info(" | |\\/| | | '_ \\| | ___/| |/ _` | | | |/ _ \\ '__| | | | __| |/ _ \\");
|
||||
XLogger.info(" | | | | | | | | | | | | (_| | |_| | __/ | | | | | |_| | __/");
|
||||
XLogger.info(" |_| |_|_|_| |_|_|_| |_|\\__,_|\\__, |\\___|_| |_| |_|\\__|_|\\___|");
|
||||
XLogger.info(" __/ |");
|
||||
XLogger.info(" |___/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
DatabaseManager.instance.close();
|
||||
}
|
||||
|
||||
public static MiniPlayerTitle instance;
|
||||
public static ConfigManager config;
|
||||
public static DatabaseManager database;
|
||||
public static XLogger logger;
|
||||
public static Notification notification;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +1,48 @@
|
||||
package cn.lunadeer.miniplayertitle.commands;
|
||||
|
||||
import cn.lunadeer.minecraftpluginutils.Common;
|
||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
|
||||
|
||||
|
||||
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) {
|
||||
if (title == null || title.getId() == -1) {
|
||||
Component newDisplayName = Component.text()
|
||||
.append(Component.text("<"))
|
||||
.append(player.name())
|
||||
.append(Component.text("> ")).build();
|
||||
Component newListName = Component.text()
|
||||
.append(player.name()).build();
|
||||
player.displayName(newDisplayName);
|
||||
player.playerListName(newListName);
|
||||
MiniPlayerTitle.instance.setPlayerUsingTitle(player.getUniqueId(), title);
|
||||
if (usingPapi()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Component titleComponent = title.getTitleColored();
|
||||
Component newDisplayName = Component.text()
|
||||
.append(titleComponent)
|
||||
.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);
|
||||
Component titleComponent = Component.text("");
|
||||
String titleBukkit = "";
|
||||
|
||||
if (title != null && title.getId() != -1) {
|
||||
titleComponent = title.getTitleColored();
|
||||
titleBukkit = ChatColor.translateAlternateColorCodes('&', title.getTitleColoredBukkit());
|
||||
}
|
||||
|
||||
if (Common.isPaper()) {
|
||||
Component newDisplayName = Component.text()
|
||||
.append(titleComponent)
|
||||
.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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,101 @@
|
||||
package cn.lunadeer.miniplayertitle.commands;
|
||||
|
||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
|
||||
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
public class PlayerManage {
|
||||
|
||||
/**
|
||||
* 给玩家添加称号币
|
||||
* mplt add_coin <玩家名称> <称号币数量>
|
||||
*
|
||||
* @param sender CommandSender
|
||||
* @param args String[]
|
||||
*/
|
||||
public static void addCoin(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("mplt.admin")) return;
|
||||
try {
|
||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
||||
if (playerInfo == null) {
|
||||
Notification.error(sender, "玩家不存在");
|
||||
return;
|
||||
}
|
||||
if (playerInfo.addCoin(Integer.parseInt(args[2]))) {
|
||||
Notification.info(sender, "成功给玩家 %s 添加 %s 称号币", playerInfo.getLastUseName(), args[2]);
|
||||
Notification.info(sender, "玩家 %s 当前余额 %f 称号币", playerInfo.getLastUseName(), playerInfo.getCoin());
|
||||
} else {
|
||||
Notification.error(sender, "给玩家添加称号币失败,详细错误请查看控制台日志");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Notification.error(sender, "给玩家添加称号币时出错:%s", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给玩家设置称号币余额
|
||||
* mplt set_coin <玩家名称> <称号币数量>
|
||||
*
|
||||
* @param sender CommandSender
|
||||
* @param args String[]
|
||||
*/
|
||||
public static void setCoin(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("mplt.admin")) return;
|
||||
try {
|
||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
||||
if (playerInfo == null) {
|
||||
Notification.error(sender, "玩家不存在");
|
||||
return;
|
||||
}
|
||||
if (playerInfo.setCoin(Integer.parseInt(args[2]))) {
|
||||
Notification.info(sender, "成功给玩家 %s 设置 %s 称号币", playerInfo.getLastUseName(), args[2]);
|
||||
Notification.info(sender, "玩家 %s 当前余额 %f 称号币", playerInfo.getLastUseName(), playerInfo.getCoin());
|
||||
} else {
|
||||
Notification.error(sender, "给玩家设置称号币失败,详细错误请查看控制台日志");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package cn.lunadeer.miniplayertitle.commands;
|
||||
|
||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
|
||||
@ -10,154 +11,176 @@ import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
|
||||
import static cn.lunadeer.miniplayertitle.commands.Apis.updateName;
|
||||
|
||||
public class TitleManage {
|
||||
/**
|
||||
* 创建称号
|
||||
* mplt create_title <称号名称> <称号描述>
|
||||
* mplt create_title <称号名称> [称号描述]
|
||||
*
|
||||
* @param sender CommandSender
|
||||
* @param args String[]
|
||||
*/
|
||||
public static void createTitle(CommandSender sender, String[] args) {
|
||||
if (notOpOrConsole(sender)) return;
|
||||
if (args.length != 3) {
|
||||
MiniPlayerTitle.notification.warn(sender, "用法: /mplt create_title <称号名称> <称号描述>");
|
||||
if (!sender.hasPermission("mplt.admin")) return;
|
||||
if (args.length < 2) {
|
||||
Notification.warn(sender, "用法: /mplt create_title <称号名称> [称号描述]");
|
||||
return;
|
||||
}
|
||||
TitleDTO title = TitleDTO.create(args[1], args[2]);
|
||||
TitleDTO title = TitleDTO.create(args[1], args.length == 3 ? args[2] : "这是一个管理员创建的称号");
|
||||
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"});
|
||||
} else {
|
||||
MiniPlayerTitle.notification.error(sender, "创建称号失败,具体请查看控制台日志");
|
||||
Notification.error(sender, "创建称号失败,具体请查看控制台日志");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除称号
|
||||
* mplt delete_title <称号ID>
|
||||
* mplt delete_title <称号ID> [页码]
|
||||
*
|
||||
* @param sender CommandSender
|
||||
* @param args String[]
|
||||
*/
|
||||
public static void deleteTitle(CommandSender sender, String[] args) {
|
||||
try {
|
||||
if (notOpOrConsole(sender)) return;
|
||||
if (!sender.hasPermission("mplt.admin")) return;
|
||||
if (args.length < 2) {
|
||||
MiniPlayerTitle.notification.warn(sender, "用法: /mplt delete_title <称号ID>");
|
||||
Notification.warn(sender, "用法: /mplt delete_title <称号ID>");
|
||||
return;
|
||||
}
|
||||
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
|
||||
if (title == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "称号不存在");
|
||||
Notification.error(sender, "称号不存在");
|
||||
return;
|
||||
}
|
||||
boolean success = title.delete();
|
||||
if (!success) {
|
||||
MiniPlayerTitle.notification.error(sender, "删除称号失败,具体请查看控制台日志");
|
||||
Notification.error(sender, "删除称号失败,具体请查看控制台日志");
|
||||
return;
|
||||
}
|
||||
MiniPlayerTitle.notification.info(sender, "已删除称号");
|
||||
Notification.info(sender, "已删除称号");
|
||||
if (args.length == 3) {
|
||||
int page = Integer.parseInt(args[2]);
|
||||
AllTitles.show(sender, new String[]{"all_titles", String.valueOf(page)});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.notification.error(sender, e.getMessage());
|
||||
Notification.error(sender, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置称号名称
|
||||
* mplt set_title <称号ID> <称号名称>
|
||||
* mplt edit_title_name <称号ID> <称号名称>
|
||||
*
|
||||
* @param sender CommandSender
|
||||
* @param args String[]
|
||||
*/
|
||||
public static void setTitle(CommandSender sender, String[] args) {
|
||||
public static void editTitleName(CommandSender sender, String[] args) {
|
||||
try {
|
||||
if (notOpOrConsole(sender)) return;
|
||||
if (!sender.hasPermission("mplt.admin")) return;
|
||||
if (args.length != 3) {
|
||||
MiniPlayerTitle.notification.warn(sender, "用法: /mplt set_title <称号ID> <称号名称>");
|
||||
Notification.warn(sender, "用法: /mplt set_title <称号ID> <称号名称>");
|
||||
return;
|
||||
}
|
||||
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
|
||||
if (title == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "称号不存在");
|
||||
Notification.error(sender, "称号不存在");
|
||||
return;
|
||||
}
|
||||
boolean success = title.updateTitle(args[2]);
|
||||
if (success) {
|
||||
MiniPlayerTitle.notification.info(sender, "已更新称号名称");
|
||||
Notification.info(sender, "已更新称号名称");
|
||||
} else {
|
||||
MiniPlayerTitle.notification.error(sender, "更新称号名称失败,具体请查看控制台日志");
|
||||
Notification.error(sender, "更新称号名称失败,具体请查看控制台日志");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.notification.error(sender, e.getMessage());
|
||||
Notification.error(sender, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置称号描述
|
||||
* mplt set_desc <称号ID> <称号描述>
|
||||
* mplt edit_title_desc <称号ID> <称号描述>
|
||||
*
|
||||
* @param sender CommandSender
|
||||
* @param args String[]
|
||||
*/
|
||||
public static void setTitleDescription(CommandSender sender, String[] args) {
|
||||
public static void editTitleDescription(CommandSender sender, String[] args) {
|
||||
try {
|
||||
if (notOpOrConsole(sender)) return;
|
||||
if (!sender.hasPermission("mplt.admin")) return;
|
||||
if (args.length != 3) {
|
||||
MiniPlayerTitle.notification.warn(sender, "用法: /mplt set_desc <称号ID> <称号描述>");
|
||||
Notification.warn(sender, "用法: /mplt set_desc <称号ID> <称号描述>");
|
||||
return;
|
||||
}
|
||||
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
|
||||
if (title == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "称号不存在");
|
||||
Notification.error(sender, "称号不存在");
|
||||
return;
|
||||
}
|
||||
boolean success = title.updateDescription(args[2]);
|
||||
if (success) {
|
||||
MiniPlayerTitle.notification.info(sender, "已更新称号描述");
|
||||
Notification.info(sender, "已更新称号描述");
|
||||
} else {
|
||||
MiniPlayerTitle.notification.error(sender, "更新称号描述失败,具体请查看控制台日志");
|
||||
Notification.error(sender, "更新称号描述失败,具体请查看控制台日志");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.notification.error(sender, e.getMessage());
|
||||
Notification.error(sender, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用称号
|
||||
* mplt use_title <称号ID> [页码]
|
||||
* mplt use_title <背包ID> [页码]
|
||||
*
|
||||
* @param sender CommandSender
|
||||
* @param args String[]
|
||||
*/
|
||||
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) {
|
||||
MiniPlayerTitle.notification.warn(sender, "用法: /mplt use_title <称号ID> [页码]");
|
||||
Notification.warn(sender, "用法: /mplt use_title <背包ID> [页码]");
|
||||
return;
|
||||
}
|
||||
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
|
||||
if (title == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "称号不存在");
|
||||
return;
|
||||
}
|
||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(((Player) sender).getUniqueId());
|
||||
Player player = (Player) sender;
|
||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get((player).getUniqueId());
|
||||
if (playerInfo == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "获取玩家信息时出现错误");
|
||||
Notification.error(sender, "获取玩家信息时出现错误");
|
||||
return;
|
||||
}
|
||||
boolean success = playerInfo.setUsingTitle(title);
|
||||
if (success) {
|
||||
updateName((Player) sender, title);
|
||||
MiniPlayerTitle.notification.info(sender, "已使用称号");
|
||||
int id = Integer.parseInt(args[1]);
|
||||
if (id == -1) {
|
||||
Notification.info(sender, "已卸下称号");
|
||||
playerInfo.setUsingTitle(null);
|
||||
updateName(player, null);
|
||||
} 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) {
|
||||
@ -168,52 +191,56 @@ public class TitleManage {
|
||||
|
||||
/**
|
||||
* 创建自定义称号
|
||||
* mplt custom_title <称号>
|
||||
* mplt custom_title <称号内容>
|
||||
*
|
||||
* @param sender CommandSender
|
||||
* @param args String[]
|
||||
*/
|
||||
public static void customTitle(CommandSender sender, String[] args) {
|
||||
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;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (!MiniPlayerTitle.config.isEnableCustom()) {
|
||||
MiniPlayerTitle.notification.error(sender, "自定义称号功能已关闭");
|
||||
Notification.error(sender, "自定义称号功能已关闭");
|
||||
return;
|
||||
}
|
||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
|
||||
if (playerInfo == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "获取玩家信息时出现错误");
|
||||
Notification.error(sender, "获取玩家信息时出现错误");
|
||||
return;
|
||||
}
|
||||
if (MiniPlayerTitle.config.getCustomCost() > playerInfo.getCoin()) {
|
||||
MiniPlayerTitle.notification.error(sender, "称号币不足");
|
||||
Notification.error(sender, "称号币不足");
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
MiniPlayerTitle.notification.warn(sender, "用法: /mplt custom_title <称号>");
|
||||
Notification.warn(sender, "用法: /mplt custom_title <称号>");
|
||||
return;
|
||||
}
|
||||
TitleDTO title = TitleDTO.create(args[1], player.getName() + "的自定义称号");
|
||||
if (title == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "创建称号失败,具体请查看控制台日志");
|
||||
Notification.error(sender, "创建称号失败,具体请查看控制台日志");
|
||||
return;
|
||||
}
|
||||
if (title.getTitlePlainText().length() > MiniPlayerTitle.config.getMaxLength()) {
|
||||
MiniPlayerTitle.notification.error(sender, "称号长度超过限制");
|
||||
Notification.error(sender, "称号长度超过限制");
|
||||
title.delete();
|
||||
return;
|
||||
}
|
||||
PlayerTitleDTO created_rec = PlayerTitleDTO.create(player.getUniqueId(), title, null);
|
||||
if (created_rec == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "创建称号记录失败,具体请查看控制台日志");
|
||||
Notification.error(sender, "创建称号记录失败,具体请查看控制台日志");
|
||||
title.delete();
|
||||
return;
|
||||
}
|
||||
playerInfo.setCoin(playerInfo.getCoin() - MiniPlayerTitle.config.getCustomCost());
|
||||
MiniPlayerTitle.notification.info(sender, "成功创建自定义称号");
|
||||
Notification.info(sender, "成功创建自定义称号");
|
||||
MyTitles.show(sender, new String[]{"my_titles"});
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
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.PlayerTitleDTO;
|
||||
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
||||
@ -16,7 +16,6 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
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.getLastArgsPage;
|
||||
|
||||
@ -24,22 +23,22 @@ public class TitleShopSale {
|
||||
|
||||
/**
|
||||
* 设置商品信息
|
||||
* mplt set_sale <price|days|amount|end_at|end_at_y|end_at_m|end_at_d> <商品ID> <值> [页数]
|
||||
* mplt set_sale <price|days|amount|end_at|more_end_at|less_end_at> <商品ID> <值> [页数]
|
||||
*
|
||||
* @param sender CommandSender
|
||||
* @param args String[]
|
||||
*/
|
||||
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]));
|
||||
if (titleShop == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "获取详情时出现错误,详情请查看控制台日志");
|
||||
Notification.error(sender, "获取详情时出现错误,详情请查看控制台日志");
|
||||
return;
|
||||
}
|
||||
boolean success;
|
||||
switch (args[1]) {
|
||||
case "price":
|
||||
success = titleShop.setPrice(Integer.parseInt(args[3]));
|
||||
success = titleShop.setPrice(Double.parseDouble(args[3]));
|
||||
break;
|
||||
case "days":
|
||||
success = titleShop.setDays(Integer.parseInt(args[3]));
|
||||
@ -63,11 +62,11 @@ public class TitleShopSale {
|
||||
success = titleShop.setSaleEndAt(titleShop.getSaleEndAt().minusDays(days2));
|
||||
break;
|
||||
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;
|
||||
}
|
||||
if (!success) {
|
||||
MiniPlayerTitle.notification.error(sender, "设置商品信息时出现错误,详情请查看控制台日志");
|
||||
Notification.error(sender, "设置商品信息时出现错误,详情请查看控制台日志");
|
||||
}
|
||||
if (args.length == 5) {
|
||||
int page = getLastArgsPage(args);
|
||||
@ -83,18 +82,18 @@ public class TitleShopSale {
|
||||
* @param args String[]
|
||||
*/
|
||||
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]));
|
||||
if (title == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "获取称号详情时出现错误,详情请查看控制台日志");
|
||||
Notification.error(sender, "获取称号详情时出现错误,详情请查看控制台日志");
|
||||
return;
|
||||
}
|
||||
TitleShopDTO sale = TitleShopDTO.create(title);
|
||||
if (sale == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "创建商品时出现错误,详情请查看控制台日志");
|
||||
Notification.error(sender, "创建商品时出现错误,详情请查看控制台日志");
|
||||
return;
|
||||
}
|
||||
MiniPlayerTitle.notification.info(sender, "已创建称号商品");
|
||||
Notification.info(sender, "已创建称号商品");
|
||||
if (sender instanceof Player) {
|
||||
SaleInfo.show(sender, new String[]{"sale_info", String.valueOf(sale.getId())});
|
||||
}
|
||||
@ -108,17 +107,17 @@ public class TitleShopSale {
|
||||
* @param args String[]
|
||||
*/
|
||||
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]));
|
||||
if (titleShop == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "获取详情时出现错误");
|
||||
Notification.error(sender, "获取详情时出现错误");
|
||||
return;
|
||||
}
|
||||
boolean success = titleShop.delete();
|
||||
if (success) {
|
||||
MiniPlayerTitle.notification.info(sender, "已删除商品");
|
||||
Notification.info(sender, "已删除商品");
|
||||
} else {
|
||||
MiniPlayerTitle.notification.error(sender, "删除商品时出现错误,详情请查看控制台日志");
|
||||
Notification.error(sender, "删除商品时出现错误,详情请查看控制台日志");
|
||||
}
|
||||
|
||||
if (args.length == 3) {
|
||||
@ -135,31 +134,32 @@ public class TitleShopSale {
|
||||
*/
|
||||
public static void buySale(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
MiniPlayerTitle.notification.error(sender, "该命令只能由玩家执行");
|
||||
Notification.error(sender, "该命令只能由玩家执行");
|
||||
return;
|
||||
}
|
||||
if (!sender.hasPermission("mplt.command")) return;
|
||||
Player player = (Player) sender;
|
||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
|
||||
if (playerInfo == null) {
|
||||
MiniPlayerTitle.notification.error(player, "获取玩家信息时出现错误,详情请查看控制台日志");
|
||||
Notification.error(player, "获取玩家信息时出现错误,详情请查看控制台日志");
|
||||
return;
|
||||
}
|
||||
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
|
||||
if (titleShop == null) {
|
||||
MiniPlayerTitle.notification.error(player, "获取详情时出现错误,详情请查看控制台日志");
|
||||
Notification.error(player, "获取详情时出现错误,详情请查看控制台日志");
|
||||
return;
|
||||
}
|
||||
|
||||
if (titleShop.isExpired() || titleShop.getDays() == 0) {
|
||||
MiniPlayerTitle.notification.error(player, "此称号已停止销售");
|
||||
Notification.error(player, "此称号已停止销售");
|
||||
return;
|
||||
}
|
||||
if (titleShop.getAmount() != -1 && titleShop.getAmount() <= 0) {
|
||||
MiniPlayerTitle.notification.error(player, "此称号已售罄");
|
||||
Notification.error(player, "此称号已售罄");
|
||||
return;
|
||||
}
|
||||
if (titleShop.getPrice() > playerInfo.getCoin()) {
|
||||
MiniPlayerTitle.notification.error(player, "你的余额不足");
|
||||
Notification.error(player, "你的余额不足");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -175,21 +175,26 @@ public class TitleShopSale {
|
||||
if (had == null) {
|
||||
had = PlayerTitleDTO.create(player.getUniqueId(), titleShop.getTitle(), titleShop.getDays() == -1 ? null : LocalDateTime.now().plusDays(titleShop.getDays()));
|
||||
if (had == null) {
|
||||
MiniPlayerTitle.notification.error(player, "购买称号时出现错误,详情请查看控制台日志");
|
||||
Notification.error(player, "购买称号时出现错误,详情请查看控制台日志");
|
||||
return;
|
||||
}
|
||||
titleShop.setAmount(titleShop.getAmount() - 1);
|
||||
if (titleShop.getAmount() >= 1) {
|
||||
titleShop.setAmount(titleShop.getAmount() - 1);
|
||||
}
|
||||
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()) {
|
||||
MiniPlayerTitle.notification.warn(player, "你已拥有此称号,在过期前无法再次购买");
|
||||
Notification.warn(player, "你已拥有此称号,在过期前无法再次购买");
|
||||
} else {
|
||||
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());
|
||||
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);
|
||||
MyTitles.show(sender, new String[]{"my_titles", String.valueOf(page)});
|
||||
}
|
||||
|
@ -1,82 +1,178 @@
|
||||
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 org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
||||
|
||||
public class PlayerInfoDTO {
|
||||
private UUID uuid;
|
||||
private Integer coin;
|
||||
private final Field uuid = new Field("uuid", FieldType.UUID);
|
||||
private final Field coin = new Field("coin_d", FieldType.DOUBLE);
|
||||
private TitleDTO using_title;
|
||||
private final Field last_use_name = new Field("last_use_name", FieldType.STRING);
|
||||
|
||||
public static PlayerInfoDTO get(UUID uuid) {
|
||||
String sql = "";
|
||||
sql = "SELECT uuid, coin, using_title_id FROM mplt_player_info WHERE uuid = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, uuid)) {
|
||||
sql = "SELECT uuid, coin_d, using_title_id, last_use_name FROM mplt_player_info WHERE uuid = ?;";
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql, uuid)) {
|
||||
if (rs.next()) return getPlayerInfoDTO(rs);
|
||||
else return create(uuid);
|
||||
else return null;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("获取玩家信息失败", e, sql);
|
||||
handleDatabaseError("获取玩家信息失败", e, sql);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PlayerInfoDTO create(UUID uuid) {
|
||||
public static PlayerInfoDTO get(Player player) {
|
||||
PlayerInfoDTO info = get(player.getUniqueId());
|
||||
if (info == null) {
|
||||
info = create(player);
|
||||
if (info == null) {
|
||||
XLogger.err("创建玩家信息时失败");
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
info = updateName(player);
|
||||
if (info == null) {
|
||||
XLogger.err("更新玩家名称时失败");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public static PlayerInfoDTO get(String name) {
|
||||
String sql = "";
|
||||
sql = "INSERT INTO mplt_player_info (uuid, coin) " +
|
||||
"VALUES (?, ?) " +
|
||||
"ON CONFLICT DO NOTHING;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, uuid, MiniPlayerTitle.config.getDefaultCoin())) {
|
||||
return get(uuid);
|
||||
sql = "SELECT uuid, coin_d, using_title_id, last_use_name FROM mplt_player_info WHERE last_use_name = ?;";
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql, name)) {
|
||||
if (rs.next()) return getPlayerInfoDTO(rs);
|
||||
else return null;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("创建玩家信息失败", e, sql);
|
||||
handleDatabaseError("获取玩家信息失败", e, sql);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PlayerInfoDTO create(Player player) {
|
||||
String sql = "";
|
||||
sql = "INSERT INTO mplt_player_info (uuid, coin_d, last_use_name) " +
|
||||
"VALUES (?, ?, ?) " +
|
||||
"ON CONFLICT DO NOTHING;";
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql, player.getUniqueId(), MiniPlayerTitle.config.getDefaultCoin(), player.getName())) {
|
||||
return get(player.getUniqueId());
|
||||
} catch (Exception e) {
|
||||
handleDatabaseError("创建玩家信息失败", e, sql);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PlayerInfoDTO updateName(Player player) {
|
||||
String sql = "";
|
||||
sql = "UPDATE mplt_player_info SET last_use_name = ? WHERE uuid = ?;";
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql, player.getName(), player.getUniqueId())) {
|
||||
return get(player.getUniqueId());
|
||||
} catch (Exception e) {
|
||||
handleDatabaseError("更新玩家名称失败", e, sql);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PlayerInfoDTO getPlayerInfoDTO(ResultSet rs) throws SQLException {
|
||||
PlayerInfoDTO playerInfoDTO = new PlayerInfoDTO();
|
||||
playerInfoDTO.uuid = UUID.fromString(rs.getString("uuid"));
|
||||
playerInfoDTO.coin = rs.getInt("coin");
|
||||
playerInfoDTO.uuid.value = UUID.fromString(rs.getString("uuid"));
|
||||
playerInfoDTO.coin.value = rs.getDouble("coin_d");
|
||||
playerInfoDTO.using_title = TitleDTO.get(rs.getInt("using_title_id"));
|
||||
playerInfoDTO.last_use_name.value = rs.getString("last_use_name");
|
||||
return playerInfoDTO;
|
||||
}
|
||||
|
||||
public Integer getCoin() {
|
||||
return coin;
|
||||
public Double getCoin() {
|
||||
if (MiniPlayerTitle.config.isExternalEco()) {
|
||||
Player player = MiniPlayerTitle.instance.getServer().getPlayer(getUuid());
|
||||
return VaultConnect.instance.getBalance(player);
|
||||
}
|
||||
return (Double) coin.value;
|
||||
}
|
||||
|
||||
public TitleDTO getUsingTitle() {
|
||||
return using_title;
|
||||
}
|
||||
|
||||
public boolean setUsingTitle(TitleDTO title) {
|
||||
public String getLastUseName() {
|
||||
return (String) last_use_name.value;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return (UUID) uuid.value;
|
||||
}
|
||||
|
||||
public boolean setUsingTitle(@Nullable TitleDTO title) {
|
||||
String sql = "";
|
||||
sql = "UPDATE mplt_player_info SET using_title_id = ? WHERE uuid = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, 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;
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("设置玩家使用称号失败", e, sql);
|
||||
handleDatabaseError("设置玩家使用称号失败", e, sql);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addCoin(Integer coin) {
|
||||
return setCoin(this.coin + coin);
|
||||
public boolean addCoin(double 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 = "";
|
||||
sql = "UPDATE mplt_player_info SET coin = ? WHERE uuid = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, coin, uuid)) {
|
||||
this.coin = coin;
|
||||
sql = "UPDATE mplt_player_info SET coin_d = ? WHERE uuid = ?;";
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql, coin, getUuid())) {
|
||||
this.coin.value = coin;
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("设置玩家金币失败", e, sql);
|
||||
handleDatabaseError("设置玩家金币失败", e, sql);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<String> playerNameList() {
|
||||
String sql = "";
|
||||
sql = "SELECT last_use_name FROM mplt_player_info;";
|
||||
List<String> names = new ArrayList<>();
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
||||
while (rs.next()) {
|
||||
names.add(rs.getString("last_use_name"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handleDatabaseError("获取玩家名称列表失败", e, sql);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
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 java.sql.ResultSet;
|
||||
@ -10,22 +12,24 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
||||
|
||||
public class PlayerTitleDTO {
|
||||
private Integer id;
|
||||
private UUID player_uuid;
|
||||
private final Field id = new Field("id", FieldType.INT);
|
||||
private final Field player_uuid = new Field("player_uuid", FieldType.UUID);
|
||||
private TitleDTO title;
|
||||
private LocalDateTime expire_at;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
return (Integer) id.value;
|
||||
}
|
||||
|
||||
public TitleDTO getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public UUID getPlayer_uuid() {
|
||||
return player_uuid;
|
||||
public UUID getPlayerUuid() {
|
||||
return (UUID) player_uuid.value;
|
||||
}
|
||||
|
||||
public LocalDateTime getExpireAt() {
|
||||
@ -35,14 +39,14 @@ public class PlayerTitleDTO {
|
||||
public boolean setExpireAt(LocalDateTime dateTime) {
|
||||
String sql = "";
|
||||
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 {
|
||||
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;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("设置玩家称号过期时间失败", e, sql);
|
||||
handleDatabaseError("设置玩家称号过期时间失败", e, sql);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -58,12 +62,12 @@ public class PlayerTitleDTO {
|
||||
}
|
||||
sql += "RETURNING " +
|
||||
"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()) {
|
||||
return getRs(rs);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("创建玩家称号失败", e, sql);
|
||||
handleDatabaseError("创建玩家称号失败", e, sql);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -72,20 +76,34 @@ public class PlayerTitleDTO {
|
||||
String sql = "";
|
||||
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
||||
"WHERE id = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) {
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql, id)) {
|
||||
if (rs.next()) {
|
||||
return getRs(rs);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("获取玩家称号失败", e, sql);
|
||||
handleDatabaseError("获取玩家称号失败", e, sql);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PlayerTitleDTO get(UUID player, Integer title) {
|
||||
String sql = "";
|
||||
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 = ?;";
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql, player, title)) {
|
||||
if (rs.next()) {
|
||||
return getRs(rs);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handleDatabaseError("获取玩家称号失败", e, sql);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PlayerTitleDTO getRs(ResultSet rs) throws SQLException {
|
||||
PlayerTitleDTO playerTitle = new PlayerTitleDTO();
|
||||
playerTitle.id = rs.getInt("id");
|
||||
playerTitle.player_uuid = UUID.fromString(rs.getString("player_uuid"));
|
||||
playerTitle.id.value = rs.getInt("id");
|
||||
playerTitle.player_uuid.value = UUID.fromString(rs.getString("player_uuid"));
|
||||
playerTitle.title = TitleDTO.get(rs.getInt("title_id"));
|
||||
int y = rs.getInt("expire_at_y");
|
||||
int m = rs.getInt("expire_at_m");
|
||||
@ -103,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 " +
|
||||
"WHERE player_uuid = ?;";
|
||||
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()) {
|
||||
playerTitles.add(getRs(rs));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("获取玩家称号失败", e, sql);
|
||||
handleDatabaseError("获取玩家称号失败", e, sql);
|
||||
}
|
||||
return playerTitles;
|
||||
}
|
||||
|
@ -1,28 +1,32 @@
|
||||
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 net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
||||
|
||||
public class TitleDTO {
|
||||
private int id;
|
||||
private String title;
|
||||
private String description;
|
||||
private final Field id = new Field("id", FieldType.INT);
|
||||
private final Field title = new Field("title", FieldType.STRING);
|
||||
private final Field description = new Field("description", FieldType.STRING);
|
||||
|
||||
|
||||
public static TitleDTO get(int id) {
|
||||
String sql = "";
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("获取称号失败", e, sql);
|
||||
handleDatabaseError("获取称号失败", e, sql);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -33,105 +37,86 @@ public class TitleDTO {
|
||||
"VALUES (?, ?) " +
|
||||
"RETURNING " +
|
||||
"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);
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("创建称号失败", e, sql);
|
||||
handleDatabaseError("创建称号失败", e, sql);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean delete() {
|
||||
String sql = "";
|
||||
sql += "DELETE FROM mplt_title WHERE id = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) {
|
||||
String updateSql = "UPDATE mplt_player_info SET using_title_id = -1 WHERE using_title_id = ?;";
|
||||
String deleteSql = "DELETE FROM mplt_title WHERE id = ?;";
|
||||
try {
|
||||
// 执行更新操作
|
||||
DatabaseManager.instance.query(updateSql, getId());
|
||||
// 执行删除操作
|
||||
DatabaseManager.instance.query(deleteSql, getId());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("删除称号失败", e, sql);
|
||||
handleDatabaseError("删除称号失败", e, updateSql + " " + deleteSql);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<TitleDTO> getAll() {
|
||||
String sql = "";
|
||||
sql += "SELECT id, title, description FROM mplt_title;";
|
||||
List<TitleDTO> titleDTOs = new ArrayList<>();
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
||||
while (rs.next()) {
|
||||
titleDTOs.add(getTitleDTO(rs));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("获取称号列表失败", e, sql);
|
||||
handleDatabaseError("获取称号列表失败", e, sql);
|
||||
}
|
||||
return titleDTOs;
|
||||
}
|
||||
|
||||
public TextComponent getTitleColored() {
|
||||
TextComponent prefix = Component.text(MiniPlayerTitle.config.getPrefix());
|
||||
TextComponent suffix = Component.text(MiniPlayerTitle.config.getSuffix());
|
||||
String[] parts = this.title.split("&#");
|
||||
List<TextComponent> components = new ArrayList<>();
|
||||
components.add(prefix);
|
||||
for (String part : parts) {
|
||||
if (part.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
// match hex regx ^[0-9a-fA-F]{6}$
|
||||
Color color = new Color("#ffffff");
|
||||
String content;
|
||||
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) {
|
||||
String color_str = part.substring(0, 6);
|
||||
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)));
|
||||
String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
|
||||
return ColorParser.getComponentType(with_pre_suf);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取称号的颜色化字符串
|
||||
* 需要使用 ChatColor.translateAlternateColorCodes 方法对返回字符串进行处理
|
||||
* &#FFFFFF -> &x&f&f&f&f&f
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getTitleColoredBukkit() {
|
||||
String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
|
||||
return ColorParser.getBukkitType(with_pre_suf);
|
||||
}
|
||||
|
||||
public String getTitlePlainText() {
|
||||
String[] parts = this.title.split("&#");
|
||||
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();
|
||||
return ColorParser.getPlainText(getTitleRaw());
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return this.id;
|
||||
return (Integer) this.id.value;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
return (String) this.description.value;
|
||||
}
|
||||
|
||||
public String getTitleRaw() {
|
||||
return (String) this.title.value;
|
||||
}
|
||||
|
||||
public boolean updateTitle(String title) {
|
||||
String sql = "";
|
||||
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()) {
|
||||
this.title = title;
|
||||
this.title.value = title;
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("更新称号失败", e, sql);
|
||||
handleDatabaseError("更新称号失败", e, sql);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -139,22 +124,22 @@ public class TitleDTO {
|
||||
public boolean updateDescription(String description) {
|
||||
String sql = "";
|
||||
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()) {
|
||||
this.description = description;
|
||||
this.description.value = description;
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("更新称号失败", e, sql);
|
||||
handleDatabaseError("更新称号失败", e, sql);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static TitleDTO getTitleDTO(ResultSet rs) throws SQLException {
|
||||
TitleDTO titleDTO = new TitleDTO();
|
||||
titleDTO.id = rs.getInt("id");
|
||||
titleDTO.title = rs.getString("title");
|
||||
titleDTO.description = rs.getString("description");
|
||||
titleDTO.id.value = rs.getInt("id");
|
||||
titleDTO.title.value = rs.getString("title");
|
||||
titleDTO.description.value = rs.getString("description");
|
||||
return titleDTO;
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +1,77 @@
|
||||
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.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
||||
|
||||
public class TitleShopDTO {
|
||||
private Integer id;
|
||||
private TitleDTO title;
|
||||
private Integer price;
|
||||
private Integer days;
|
||||
private Integer amount;
|
||||
private final Field id = new Field("id", FieldType.INT);
|
||||
private final Field price = new Field("price_d", FieldType.DOUBLE);
|
||||
private final Field days = new Field("days", FieldType.INT);
|
||||
private final Field amount = new Field("amount", FieldType.INT);
|
||||
|
||||
private LocalDateTime sale_end_at;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
return (Integer) id.value;
|
||||
}
|
||||
|
||||
public TitleDTO getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public Integer getPrice() {
|
||||
return price;
|
||||
public Double getPrice() {
|
||||
return (Double) price.value;
|
||||
}
|
||||
|
||||
public boolean setPrice(int price) {
|
||||
public boolean setPrice(Double price) {
|
||||
String sql = "";
|
||||
sql += "UPDATE mplt_title_shop SET price = ? WHERE id = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, price, id)) {
|
||||
sql += "UPDATE mplt_title_shop SET price_d = ? WHERE id = ?;";
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql, price, getId())) {
|
||||
this.price.value = price;
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("设置称号商店价格失败", e, sql);
|
||||
handleDatabaseError("设置称号商店价格失败", e, sql);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Integer getDays() {
|
||||
return days;
|
||||
return (Integer) days.value;
|
||||
}
|
||||
|
||||
public boolean setDays(int days) {
|
||||
String sql = "";
|
||||
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;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("设置称号商店天数失败", e, sql);
|
||||
handleDatabaseError("设置称号商店天数失败", e, sql);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Integer getAmount() {
|
||||
return amount;
|
||||
return (Integer) amount.value;
|
||||
}
|
||||
|
||||
public boolean setAmount(int amount) {
|
||||
String sql = "";
|
||||
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;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("设置称号商店数量失败", e, sql);
|
||||
handleDatabaseError("设置称号商店数量失败", e, sql);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -79,51 +87,51 @@ public class TitleShopDTO {
|
||||
public boolean setSaleEndAt(int y, int m, int d) {
|
||||
String sql = "";
|
||||
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;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("设置称号商店销售结束时间失败", e, sql);
|
||||
handleDatabaseError("设置称号商店销售结束时间失败", e, sql);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static TitleShopDTO get(Integer id) {
|
||||
String sql = "";
|
||||
sql += "SELECT id, title_id, price, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
||||
sql += "SELECT id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
||||
"FROM mplt_title_shop WHERE id = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) {
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql, id)) {
|
||||
if (rs.next()) {
|
||||
return getTitleShop(rs);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("获取称号商店信息失败", e, sql);
|
||||
handleDatabaseError("获取称号商店信息失败", e, sql);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<TitleShopDTO> getAll() {
|
||||
String sql = "";
|
||||
sql += "SELECT id, title_id, price, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
||||
sql += "SELECT id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
||||
"FROM mplt_title_shop;";
|
||||
List<TitleShopDTO> titleShops = new ArrayList<>();
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
||||
while (rs != null && rs.next()) {
|
||||
TitleShopDTO titleShop = getTitleShop(rs);
|
||||
titleShops.add(titleShop);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("获取称号商店列表失败", e, sql);
|
||||
handleDatabaseError("获取称号商店列表失败", e, sql);
|
||||
}
|
||||
return titleShops;
|
||||
}
|
||||
|
||||
private static TitleShopDTO getTitleShop(ResultSet rs) throws Exception {
|
||||
TitleShopDTO titleShop = new TitleShopDTO();
|
||||
titleShop.id = rs.getInt("id");
|
||||
titleShop.id.value = rs.getInt("id");
|
||||
titleShop.title = TitleDTO.get(rs.getInt("title_id"));
|
||||
titleShop.price = rs.getInt("price");
|
||||
titleShop.days = rs.getInt("days");
|
||||
titleShop.amount = rs.getInt("amount");
|
||||
titleShop.price.value = rs.getDouble("price_d");
|
||||
titleShop.days.value = rs.getInt("days");
|
||||
titleShop.amount.value = rs.getInt("amount");
|
||||
int y = rs.getInt("sale_end_at_y");
|
||||
int m = rs.getInt("sale_end_at_m");
|
||||
int d = rs.getInt("sale_end_at_d");
|
||||
@ -137,16 +145,16 @@ public class TitleShopDTO {
|
||||
|
||||
public static TitleShopDTO create(TitleDTO title) {
|
||||
String sql = "";
|
||||
sql += "INSERT INTO mplt_title_shop (title_id, price, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d) " +
|
||||
sql += "INSERT INTO mplt_title_shop (title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d) " +
|
||||
"VALUES (?, 0, -1, 0, -1, -1, -1) " +
|
||||
"RETURNING " +
|
||||
"id, title_id, price, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title.getId())) {
|
||||
"id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d;";
|
||||
try (ResultSet rs = DatabaseManager.instance.query(sql, title.getId())) {
|
||||
if (rs.next()) {
|
||||
return getTitleShop(rs);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("创建称号商店失败", e, sql);
|
||||
handleDatabaseError("创建称号商店失败", e, sql);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -154,10 +162,10 @@ public class TitleShopDTO {
|
||||
public boolean delete() {
|
||||
String sql = "";
|
||||
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;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("删除称号商店失败", e, sql);
|
||||
handleDatabaseError("删除称号商店失败", e, sql);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
36
src/main/java/cn/lunadeer/miniplayertitle/events/Events.java
Normal file
36
src/main/java/cn/lunadeer/miniplayertitle/events/Events.java
Normal file
@ -0,0 +1,36 @@
|
||||
package cn.lunadeer.miniplayertitle.events;
|
||||
|
||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import static cn.lunadeer.miniplayertitle.commands.Apis.updateName;
|
||||
|
||||
public class Events implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player bukkitPlayer = event.getPlayer();
|
||||
PlayerInfoDTO player = PlayerInfoDTO.get(bukkitPlayer);
|
||||
if (player == null) {
|
||||
Notification.error(bukkitPlayer, "获取玩家信息时出现错误,请联系管理员");
|
||||
return;
|
||||
}
|
||||
if (player.getUsingTitle().getId() == -1) {
|
||||
updateName(bukkitPlayer, null);
|
||||
return;
|
||||
}
|
||||
PlayerTitleDTO title = PlayerTitleDTO.get(bukkitPlayer.getUniqueId(), player.getUsingTitle().getId());
|
||||
if (title == null || title.isExpired()) {
|
||||
Notification.warn(bukkitPlayer, "你当前使用的称号 %s 已过期", player.getUsingTitle().getTitlePlainText());
|
||||
player.setUsingTitle(null);
|
||||
updateName(bukkitPlayer, null);
|
||||
} else {
|
||||
updateName(bukkitPlayer, title.getTitle());
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ public class AllTitles {
|
||||
Line line = Line.create()
|
||||
.append(title.getId().toString())
|
||||
.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.createGreen("创建商品").setExecuteCommand("/mplt create_sale " + title.getId()).build());
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package cn.lunadeer.miniplayertitle.tuis;
|
||||
|
||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Apis {
|
||||
public static Player playerOnly(CommandSender sender) {
|
||||
if (!(sender instanceof Player)) {
|
||||
MiniPlayerTitle.notification.error(sender, "该命令只能由玩家执行");
|
||||
Notification.error(sender, "该命令只能由玩家执行");
|
||||
return null;
|
||||
}
|
||||
return (Player) sender;
|
||||
|
@ -1,9 +1,12 @@
|
||||
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.components.Button;
|
||||
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
|
||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -16,6 +19,20 @@ public class Menu {
|
||||
|
||||
Player player = playerOnly(sender);
|
||||
if (player == null) return;
|
||||
|
||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
|
||||
if (playerInfo == null) {
|
||||
Notification.error(player, "获取玩家信息时出现错误");
|
||||
return;
|
||||
}
|
||||
Line balance;
|
||||
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()
|
||||
.append(Button.create("称号背包").setExecuteCommand("/mplt my_titles").build()).append("查看你拥有的称号");
|
||||
Line shop = Line.create()
|
||||
@ -28,6 +45,8 @@ public class Menu {
|
||||
ListView view = ListView.create(10, "/mplt");
|
||||
view.title("称号系统")
|
||||
.navigator(Line.create().append("主菜单"))
|
||||
.add(balance)
|
||||
.add(Line.create())
|
||||
.add(backpack)
|
||||
.add(shop)
|
||||
.add(manual);
|
||||
@ -39,7 +58,7 @@ public class Menu {
|
||||
Line all = Line.create()
|
||||
.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("---以下选项仅OP可见---"));
|
||||
view.add(all);
|
||||
|
@ -1,14 +1,15 @@
|
||||
package cn.lunadeer.miniplayertitle.tuis;
|
||||
|
||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||
import cn.lunadeer.minecraftpluginutils.stui.ListView;
|
||||
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
|
||||
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
|
||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -23,7 +24,7 @@ public class MyTitles {
|
||||
|
||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
|
||||
if (playerInfo == null) {
|
||||
MiniPlayerTitle.notification.error(player, "获取玩家信息时出现错误,详情请查看控制台日志");
|
||||
Notification.error(player, "获取玩家信息时出现错误,详情请查看控制台日志");
|
||||
return;
|
||||
}
|
||||
List<PlayerTitleDTO> titles = PlayerTitleDTO.getAllOf(player.getUniqueId());
|
||||
@ -41,10 +42,12 @@ public class MyTitles {
|
||||
.append(title.getTitle().getTitleColored());
|
||||
if (title.getExpireAt() == null) {
|
||||
line.append("永久");
|
||||
} else if (title.getExpireAt().isBefore(LocalDateTime.now())) {
|
||||
line.append("已过期");
|
||||
} else {
|
||||
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());
|
||||
} else {
|
||||
line.append(Button.createGreen("使用").setExecuteCommand("/mplt use_title " + title.getId() + " " + page).build());
|
||||
|
@ -1,12 +1,13 @@
|
||||
package cn.lunadeer.miniplayertitle.tuis;
|
||||
|
||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||
import cn.lunadeer.minecraftpluginutils.stui.ListView;
|
||||
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
|
||||
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
|
||||
import cn.lunadeer.minecraftpluginutils.stui.components.NumChanger;
|
||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
||||
import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -22,12 +23,12 @@ public class SaleInfo {
|
||||
int page = getArgPage(args, 3);
|
||||
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
|
||||
if (titleShop == null) {
|
||||
MiniPlayerTitle.notification.error(player, "获取详情时出现错误");
|
||||
Notification.error(player, "获取详情时出现错误");
|
||||
return;
|
||||
}
|
||||
TitleDTO title = titleShop.getTitle();
|
||||
if (title == null) {
|
||||
MiniPlayerTitle.notification.error(player, "获取详情时出现错误");
|
||||
Notification.error(player, "获取详情时出现错误");
|
||||
return;
|
||||
}
|
||||
int now_year = LocalDateTime.now().getYear();
|
||||
@ -45,11 +46,11 @@ public class SaleInfo {
|
||||
Line price = Line.create().append("价格: ");
|
||||
if (titleShop.getPrice() <= 0) {
|
||||
price.append("免费");
|
||||
if (player.isOp()) {
|
||||
if (player.hasPermission("mplt.admin")) {
|
||||
price.append(Button.create("设置价格").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 100 " + page).build());
|
||||
}
|
||||
} 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(Button.create("设置为免费").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 0 " + page).build());
|
||||
} else {
|
||||
@ -61,11 +62,11 @@ public class SaleInfo {
|
||||
Line day = Line.create().append("购买天数: ");
|
||||
if (titleShop.getDays() <= 0) {
|
||||
day.append("永久");
|
||||
if (player.isOp()) {
|
||||
if (player.hasPermission("mplt.admin")) {
|
||||
day.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " 7 " + page).build());
|
||||
}
|
||||
} 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(Button.create("转为永久").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " -1 " + page).build());
|
||||
} else {
|
||||
@ -77,12 +78,12 @@ public class SaleInfo {
|
||||
Line amount = Line.create().append("剩余数量: ");
|
||||
if (titleShop.getAmount() == -1) {
|
||||
amount.append("无限");
|
||||
if (player.isOp()) {
|
||||
if (player.hasPermission("mplt.admin")) {
|
||||
amount.append(Button.create("转为限量").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " 0 " + page).build());
|
||||
}
|
||||
} 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(Button.create("转为无限").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " -1 " + page).build());
|
||||
} else {
|
||||
@ -94,16 +95,16 @@ public class SaleInfo {
|
||||
Line end_at = Line.create().append("售卖结束时间: ");
|
||||
if (titleShop.getSaleEndAt() == null) {
|
||||
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());
|
||||
}
|
||||
} else {
|
||||
if (player.isOp()) {
|
||||
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("提前1天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 1 " + page).build());
|
||||
end_at.append(titleShop.getSaleEndAt().getYear() + "年" + titleShop.getSaleEndAt().getMonthValue() + "月" + titleShop.getSaleEndAt().getDayOfMonth() + "日");
|
||||
end_at.append(Button.create("+").setPreSufIx("", "").setHoverText("延后1天").setExecuteCommand("/mplt set_sale more_end_at " + titleShop.getId() + " 1 " + page).build());
|
||||
end_at.append(Button.create(">>").setPreSufIx("", "").setHoverText("延后10天").setExecuteCommand("/mplt set_sale more_end_at " + titleShop.getId() + " 10 " + page).build());
|
||||
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()
|
||||
.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(Button.create("+").setPreSufIx("", "").setHoverText("延后1天").setExecuteCommand("/mplt set_sale more_end_at " + titleShop.getId() + " 1 " + page).build())
|
||||
.append(Button.create(">>").setPreSufIx("", "").setHoverText("延后10天").setExecuteCommand("/mplt set_sale more_end_at " + titleShop.getId() + " 10 " + page).build()));
|
||||
end_at.append(Button.create("转为常驻").setExecuteCommand("/mplt set_sale end_at " + titleShop.getId() + " -1:-1:-1 " + page).build());
|
||||
} else {
|
||||
end_at.append(titleShop.getSaleEndAt().getYear() + "年" + titleShop.getSaleEndAt().getMonthValue() + "月" + titleShop.getSaleEndAt().getDayOfMonth() + "日");
|
||||
@ -119,8 +120,9 @@ public class SaleInfo {
|
||||
} else {
|
||||
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.createGreen("导出称号卡").setExecuteCommand("/mplt get_card " + args[1]).build());
|
||||
}
|
||||
view.add(Line.create().append("---------------------"));
|
||||
view.add(operate);
|
||||
|
@ -33,6 +33,7 @@ public class Shop {
|
||||
continue;
|
||||
}
|
||||
Line line = Line.create()
|
||||
.append(title.getId().toString())
|
||||
.append(title.getTitle().getTitleColored())
|
||||
.append(Button.createGreen("详情").setExecuteCommand("/mplt sale_info " + title.getId()).build());
|
||||
view.add(line);
|
||||
|
@ -16,10 +16,6 @@ public class ConfigManager {
|
||||
_file = _plugin.getConfig();
|
||||
_debug = _file.getBoolean("Debug", false);
|
||||
_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_port = _file.getString("Database.Port", "5432");
|
||||
_db_name = _file.getString("Database.Name", "miniplayertitle");
|
||||
@ -32,6 +28,7 @@ public class ConfigManager {
|
||||
_custom_cost = _file.getInt("CustomCost.Cost", 1000);
|
||||
_max_length = _file.getInt("CustomCost.MaxLength", 8);
|
||||
_check_update = _file.getBoolean("CheckUpdate", true);
|
||||
_external_eco = _file.getBoolean("ExternalEco", false);
|
||||
}
|
||||
|
||||
public Boolean isDebug() {
|
||||
@ -141,6 +138,10 @@ public class ConfigManager {
|
||||
return _check_update;
|
||||
}
|
||||
|
||||
public Boolean isExternalEco() {
|
||||
return _external_eco;
|
||||
}
|
||||
|
||||
|
||||
private final MiniPlayerTitle _plugin;
|
||||
private FileConfiguration _file;
|
||||
@ -159,4 +160,5 @@ public class ConfigManager {
|
||||
private Integer _custom_cost;
|
||||
private Integer _max_length;
|
||||
private Boolean _check_update;
|
||||
private Boolean _external_eco;
|
||||
}
|
||||
|
@ -1,110 +1,172 @@
|
||||
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 static void migrate() {
|
||||
String sql = "";
|
||||
|
||||
// title table
|
||||
sql = "CREATE TABLE IF NOT EXISTS mplt_title (" +
|
||||
" id SERIAL PRIMARY KEY," +
|
||||
" title TEXT NOT NULL UNIQUE," +
|
||||
" description TEXT NOT NULL," +
|
||||
" enabled BOOLEAN NOT NULL DEFAULT TRUE," +
|
||||
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP" +
|
||||
");";
|
||||
MiniPlayerTitle.database.query(sql);
|
||||
TableColumn mplt_title_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
|
||||
TableColumn mplt_title_title = new TableColumn("title", FieldType.STRING, false, false, true, false, "'unknown'");
|
||||
TableColumn mplt_title_description = new TableColumn("description", FieldType.STRING, false, false, true, false, "'unknown'");
|
||||
TableColumn mplt_title_enabled = new TableColumn("enabled", FieldType.BOOLEAN, false, false, true, false, "true");
|
||||
TableColumn mplt_title_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||
TableColumn mplt_title_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||
CreateTable mplt_title = new CreateTable().ifNotExists();
|
||||
mplt_title.table("mplt_title")
|
||||
.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
|
||||
sql = "CREATE TABLE IF NOT EXISTS mplt_title_shop (" +
|
||||
" id SERIAL PRIMARY KEY," +
|
||||
" title_id INTEGER NOT NULL," +
|
||||
" price INTEGER NOT NULL DEFAULT 0," +
|
||||
" days INTEGER NOT NULL DEFAULT 0," +
|
||||
" amount INTEGER NOT NULL DEFAULT -1," +
|
||||
" sale_end_at BIGINT NOT NULL DEFAULT -1," +
|
||||
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||
" FOREIGN KEY (title_id) REFERENCES mplt_title(id) ON DELETE CASCADE" +
|
||||
");";
|
||||
MiniPlayerTitle.database.query(sql);
|
||||
TableColumn mplt_title_shop_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
|
||||
TableColumn mplt_title_shop_title_id = new TableColumn("title_id", FieldType.INT, false, false, true, false, 0);
|
||||
TableColumn mplt_title_shop_price = new TableColumn("price", FieldType.INT, false, false, true, false, 0);
|
||||
TableColumn mplt_title_shop_days = new TableColumn("days", FieldType.INT, false, false, true, false, 0);
|
||||
TableColumn mplt_title_shop_amount = new TableColumn("amount", FieldType.INT, false, false, true, false, -1);
|
||||
TableColumn mplt_title_shop_sale_end_at = new TableColumn("sale_end_at", FieldType.LONG, false, false, true, false, -1);
|
||||
TableColumn mplt_title_shop_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||
TableColumn mplt_title_shop_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||
CreateTable.ForeignKey mplt_title_shop_title_id_fk = new CreateTable.ForeignKey(mplt_title_shop_title_id, "mplt_title", mplt_title_id, true);
|
||||
CreateTable mplt_title_shop = new CreateTable().ifNotExists();
|
||||
mplt_title_shop.table("mplt_title_shop")
|
||||
.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
|
||||
sql = "CREATE TABLE IF NOT EXISTS mplt_player_info (" +
|
||||
" uuid UUID PRIMARY KEY," +
|
||||
" coin INTEGER NOT NULL DEFAULT 0," +
|
||||
" using_title_id INTEGER NOT NULL DEFAULT -1," +
|
||||
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||
" FOREIGN KEY (using_title_id) REFERENCES mplt_title(id) ON DELETE CASCADE" +
|
||||
");";
|
||||
MiniPlayerTitle.database.query(sql);
|
||||
TableColumn mplt_player_info_uuid = new TableColumn("uuid", FieldType.UUID, true, false, true, false, "'00000000-0000-0000-0000-000000000000'");
|
||||
TableColumn mplt_player_info_coin = new TableColumn("coin", FieldType.INT, false, false, true, false, 0);
|
||||
TableColumn mplt_player_info_using_title_id = new TableColumn("using_title_id", FieldType.INT, false, false, true, false, -1);
|
||||
TableColumn mplt_player_info_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||
TableColumn mplt_player_info_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "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);
|
||||
CreateTable mplt_player_info = new CreateTable().ifNotExists();
|
||||
mplt_player_info.table("mplt_player_info")
|
||||
.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
|
||||
sql = "CREATE TABLE IF NOT EXISTS mplt_player_title (" +
|
||||
" id SERIAL PRIMARY KEY," +
|
||||
" player_uuid UUID NOT NULL," +
|
||||
" title_id INTEGER NOT NULL," +
|
||||
" expire_at BIGINT NOT NULL DEFAULT -1," +
|
||||
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||
" FOREIGN KEY (title_id) REFERENCES mplt_title(id) ON DELETE CASCADE," +
|
||||
" FOREIGN KEY (player_uuid) REFERENCES mplt_player_info(uuid) ON DELETE CASCADE" +
|
||||
");";
|
||||
MiniPlayerTitle.database.query(sql);
|
||||
TableColumn mplt_player_title_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
|
||||
TableColumn mplt_player_title_player_uuid = new TableColumn("player_uuid", FieldType.UUID, false, false, true, false, "'00000000-0000-0000-0000-000000000000'");
|
||||
TableColumn mplt_player_title_title_id = new TableColumn("title_id", FieldType.INT, false, false, true, false, 0);
|
||||
TableColumn mplt_player_title_expire_at = new TableColumn("expire_at", FieldType.LONG, false, false, true, false, -1);
|
||||
TableColumn mplt_player_title_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||
TableColumn mplt_player_title_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||
CreateTable.ForeignKey mplt_player_title_title_id_fk = new CreateTable.ForeignKey(mplt_player_title_title_id, "mplt_title", mplt_title_id, true);
|
||||
CreateTable.ForeignKey mplt_player_title_player_uuid_fk = new CreateTable.ForeignKey(mplt_player_title_player_uuid, "mplt_player_info", mplt_player_info_uuid, true);
|
||||
CreateTable mplt_player_title = new CreateTable().ifNotExists();
|
||||
mplt_player_title.table("mplt_player_title")
|
||||
.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");
|
||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "updated_at");
|
||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "enabled");
|
||||
new RemoveColumn("expire_at").IfExists().table("mplt_title").execute();
|
||||
new RemoveColumn("sale_end_at").IfExists().table("mplt_title_shop").execute();
|
||||
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");
|
||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "updated_at");
|
||||
|
||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "created_at");
|
||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "updated_at");
|
||||
|
||||
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");
|
||||
TableColumn mplt_title_shop_sale_end_at_y = new TableColumn("sale_end_at_y", FieldType.INT, false, false, true, false, -1);
|
||||
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);
|
||||
new AddColumn(mplt_title_shop_sale_end_at_y).table("mplt_title_shop").ifNotExists().execute();
|
||||
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();
|
||||
// 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")) {
|
||||
sql = "UPDATE mplt_title_shop SET " +
|
||||
if (IsFieldExist("mplt_title_shop", "sale_end_at")) {
|
||||
String sql = "UPDATE mplt_title_shop SET " +
|
||||
"sale_end_at_y = (sale_end_at / 10000), " +
|
||||
"sale_end_at_m = (sale_end_at % 10000 / 100), " +
|
||||
"sale_end_at_d = (sale_end_at % 100) " +
|
||||
"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");
|
||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_d", "INTEGER NOT NULL DEFAULT -1");
|
||||
if (MiniPlayerTitle.database.isColumnExist("mplt_player_title", "expire_at")) {
|
||||
sql = "UPDATE mplt_player_title SET " +
|
||||
|
||||
TableColumn mplt_player_title_expire_at_y = new TableColumn("expire_at_y", FieldType.INT, false, false, true, false, -1);
|
||||
TableColumn mplt_player_title_expire_at_m = new TableColumn("expire_at_m", FieldType.INT, false, false, true, false, -1);
|
||||
TableColumn mplt_player_title_expire_at_d = new TableColumn("expire_at_d", FieldType.INT, false, false, true, false, -1);
|
||||
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_m = (expire_at % 10000 / 100), " +
|
||||
"expire_at_d = (expire_at % 100) " +
|
||||
"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 (" +
|
||||
"id, " +
|
||||
"title, " +
|
||||
"description " +
|
||||
") VALUES (" +
|
||||
"-1, " +
|
||||
"'default', " +
|
||||
"'default' " +
|
||||
") ON CONFLICT (id) DO NOTHING;";
|
||||
MiniPlayerTitle.database.query(sql);
|
||||
Field mplt_title_id_field = new Field("id", -1);
|
||||
Field mplt_title_title_field = new Field("title", "default");
|
||||
Field mplt_title_description_field = new Field("description", "default");
|
||||
InsertRow mplt_title_default = new InsertRow().table("mplt_title");
|
||||
mplt_title_default.field(mplt_title_id_field)
|
||||
.field(mplt_title_title_field)
|
||||
.field(mplt_title_description_field).onConflictDoNothing(mplt_title_id_field);
|
||||
mplt_title_default.execute();
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ CustomCost:
|
||||
|
||||
DefaultCoin: 0
|
||||
|
||||
ExternalEco: false # 使用外部经济插件 需要Vault支持
|
||||
|
||||
CheckUpdate: true
|
||||
|
||||
Debug: false
|
@ -5,8 +5,20 @@ api-version: '1.20'
|
||||
description: 称号插件。
|
||||
website: https://lunadeer.cn
|
||||
folia-supported: true
|
||||
softdepend: [ PlaceholderAPI, Vault ]
|
||||
commands:
|
||||
MiniPlayerTitle:
|
||||
description: 称号插件命令
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user