Compare commits
No commits in common. "master" and "v4.2.6" have entirely different histories.
@ -1,4 +1,4 @@
|
|||||||
<div align="center">
|
<div style="text-align: center;">
|
||||||
|
|
||||||
<img src="https://ssl.lunadeer.cn:14437/i/2024/03/28/6604de7db2e6f.png" alt="" width="70%">
|
<img src="https://ssl.lunadeer.cn:14437/i/2024/03/28/6604de7db2e6f.png" alt="" width="70%">
|
||||||
|
|
||||||
|
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.lunadeer</groupId>
|
<groupId>cn.lunadeer</groupId>
|
||||||
<artifactId>MiniPlayerTitle</artifactId>
|
<artifactId>MiniPlayerTitle</artifactId>
|
||||||
<version>4.7.1</version>
|
<version>4.2.6</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>MiniPlayerTitle</name>
|
<name>MiniPlayerTitle</name>
|
||||||
@ -82,7 +82,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.lunadeer</groupId>
|
<groupId>cn.lunadeer</groupId>
|
||||||
<artifactId>MinecraftPluginUtils</artifactId>
|
<artifactId>MinecraftPluginUtils</artifactId>
|
||||||
<version>1.3.7-SNAPSHOT</version>
|
<version>1.3.2-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package cn.lunadeer.miniplayertitle;
|
package cn.lunadeer.miniplayertitle;
|
||||||
|
|
||||||
import cn.lunadeer.miniplayertitle.commands.PlayerManage;
|
import cn.lunadeer.miniplayertitle.commands.PlayerManage;
|
||||||
import cn.lunadeer.miniplayertitle.commands.TitleCard;
|
|
||||||
import cn.lunadeer.miniplayertitle.commands.TitleManage;
|
import cn.lunadeer.miniplayertitle.commands.TitleManage;
|
||||||
import cn.lunadeer.miniplayertitle.commands.TitleShopSale;
|
import cn.lunadeer.miniplayertitle.commands.TitleShopSale;
|
||||||
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||||
@ -82,9 +81,6 @@ public class Commands implements TabExecutor {
|
|||||||
case "grant_title": // mplt grant_title <玩家名称> <称号> <描述> [天数]
|
case "grant_title": // mplt grant_title <玩家名称> <称号> <描述> [天数]
|
||||||
PlayerManage.grantTitle(sender, args);
|
PlayerManage.grantTitle(sender, args);
|
||||||
break;
|
break;
|
||||||
case "get_card": // mplt get_card <商品ID>
|
|
||||||
TitleCard.getTitleCard(sender, args);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -97,7 +93,7 @@ public class Commands implements TabExecutor {
|
|||||||
return Arrays.asList("menu", "all_titles", "my_titles", "shop", "custom_info", "sale_info",
|
return Arrays.asList("menu", "all_titles", "my_titles", "shop", "custom_info", "sale_info",
|
||||||
"create_sale", "set_sale", "delete_sale", "buy_sale", "use_title", "create_title",
|
"create_sale", "set_sale", "delete_sale", "buy_sale", "use_title", "create_title",
|
||||||
"delete_title", "edit_title_name", "edit_title_desc", "custom_title", "add_coin", "set_coin",
|
"delete_title", "edit_title_name", "edit_title_desc", "custom_title", "add_coin", "set_coin",
|
||||||
"grant_title", "get_card"
|
"grant_title"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
@ -105,7 +101,6 @@ public class Commands implements TabExecutor {
|
|||||||
case "sale_info":
|
case "sale_info":
|
||||||
case "delete_sale":
|
case "delete_sale":
|
||||||
case "buy_sale":
|
case "buy_sale":
|
||||||
case "get_card":
|
|
||||||
return Collections.singletonList("<商品ID>");
|
return Collections.singletonList("<商品ID>");
|
||||||
case "create_sale":
|
case "create_sale":
|
||||||
case "delete_title":
|
case "delete_title":
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package cn.lunadeer.miniplayertitle.events;
|
package cn.lunadeer.miniplayertitle;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||||
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||||
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
|
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
|
||||||
import static cn.lunadeer.miniplayertitle.commands.Apis.updateName;
|
import static cn.lunadeer.miniplayertitle.commands.Apis.updateName;
|
||||||
|
|
||||||
public class Events implements Listener {
|
public class Events implements Listener {
|
||||||
@ -33,4 +36,19 @@ public class Events implements Listener {
|
|||||||
updateName(bukkitPlayer, title.getTitle());
|
updateName(bukkitPlayer, title.getTitle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package cn.lunadeer.miniplayertitle;
|
package cn.lunadeer.miniplayertitle;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.XLogger;
|
import cn.lunadeer.minecraftpluginutils.XLogger;
|
||||||
|
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||||
|
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
|
||||||
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -30,11 +32,20 @@ public class Expansion extends PlaceholderExpansion {
|
|||||||
@Override
|
@Override
|
||||||
public String onPlaceholderRequest(Player bukkitPlayer, @NotNull String params) {
|
public String onPlaceholderRequest(Player bukkitPlayer, @NotNull String params) {
|
||||||
if (params.equalsIgnoreCase("player_title")) {
|
if (params.equalsIgnoreCase("player_title")) {
|
||||||
TitleDTO t = MiniPlayerTitle.instance.getPlayerUsingTitle(bukkitPlayer.getUniqueId());
|
PlayerInfoDTO player = PlayerInfoDTO.get(bukkitPlayer);
|
||||||
if (t == null) {
|
if (player == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return t.getTitleColoredBukkit();
|
if (player.getUsingTitle().getId() == -1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
PlayerTitleDTO title = PlayerTitleDTO.get(bukkitPlayer.getUniqueId(), player.getUsingTitle().getId());
|
||||||
|
if (title == null || title.isExpired()) {
|
||||||
|
player.setUsingTitle(null);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
TitleDTO t = title.getTitle();
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', t.getTitleColoredBukkit());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null; //
|
return null; //
|
||||||
@ -52,6 +63,6 @@ public class Expansion extends PlaceholderExpansion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getVersion() {
|
public @NotNull String getVersion() {
|
||||||
return MiniPlayerTitle.instance.getDescription().getVersion();
|
return plugin.getPluginMeta().getVersion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,12 @@
|
|||||||
package cn.lunadeer.miniplayertitle;
|
package cn.lunadeer.miniplayertitle;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.*;
|
import cn.lunadeer.minecraftpluginutils.*;
|
||||||
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.DatabaseType;
|
|
||||||
import cn.lunadeer.miniplayertitle.commands.TitleCard;
|
|
||||||
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
|
||||||
import cn.lunadeer.miniplayertitle.events.Events;
|
|
||||||
import cn.lunadeer.miniplayertitle.events.PaperChat;
|
|
||||||
import cn.lunadeer.miniplayertitle.events.SpigotChat;
|
|
||||||
import cn.lunadeer.miniplayertitle.utils.ConfigManager;
|
import cn.lunadeer.miniplayertitle.utils.ConfigManager;
|
||||||
import cn.lunadeer.miniplayertitle.utils.DatabaseTables;
|
import cn.lunadeer.miniplayertitle.utils.DatabaseTables;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class MiniPlayerTitle extends JavaPlugin {
|
public final class MiniPlayerTitle extends JavaPlugin {
|
||||||
|
|
||||||
@ -30,8 +19,8 @@ public final class MiniPlayerTitle extends JavaPlugin {
|
|||||||
new XLogger(instance);
|
new XLogger(instance);
|
||||||
config = new ConfigManager(instance);
|
config = new ConfigManager(instance);
|
||||||
XLogger.setDebug(config.isDebug());
|
XLogger.setDebug(config.isDebug());
|
||||||
new DatabaseManager(this,
|
database = new DatabaseManager(this,
|
||||||
DatabaseType.valueOf(config.getDbType().toUpperCase()),
|
DatabaseManager.TYPE.valueOf(config.getDbType().toUpperCase()),
|
||||||
config.getDbHost(),
|
config.getDbHost(),
|
||||||
config.getDbPort(),
|
config.getDbPort(),
|
||||||
config.getDbName(),
|
config.getDbName(),
|
||||||
@ -48,12 +37,6 @@ public final class MiniPlayerTitle extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new Events(), this);
|
Bukkit.getPluginManager().registerEvents(new Events(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new TitleCard(), this);
|
|
||||||
if (Common.isPaper()) {
|
|
||||||
Bukkit.getPluginManager().registerEvents(new PaperChat(), this);
|
|
||||||
} else {
|
|
||||||
Bukkit.getPluginManager().registerEvents(new SpigotChat(), this);
|
|
||||||
}
|
|
||||||
Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setExecutor(new Commands());
|
Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setExecutor(new Commands());
|
||||||
Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setTabCompleter(new Commands());
|
Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setTabCompleter(new Commands());
|
||||||
|
|
||||||
@ -66,7 +49,7 @@ public final class MiniPlayerTitle extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
XLogger.info("称号插件已加载");
|
XLogger.info("称号插件已加载");
|
||||||
XLogger.info("版本: " + this.getDescription().getVersion());
|
XLogger.info("版本: " + getPluginMeta().getVersion());
|
||||||
// http://patorjk.com/software/taag/#p=display&f=Big&t=MiniPlayerTitle
|
// http://patorjk.com/software/taag/#p=display&f=Big&t=MiniPlayerTitle
|
||||||
XLogger.info(" __ __ _ _ _____ _ _______ _ _ _");
|
XLogger.info(" __ __ _ _ _____ _ _______ _ _ _");
|
||||||
XLogger.info(" | \\/ (_) (_) __ \\| | |__ __(_) | | |");
|
XLogger.info(" | \\/ (_) (_) __ \\| | |__ __(_) | | |");
|
||||||
@ -81,23 +64,15 @@ public final class MiniPlayerTitle extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Plugin shutdown logic
|
// Plugin shutdown logic
|
||||||
DatabaseManager.instance.close();
|
database.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MiniPlayerTitle instance;
|
public static MiniPlayerTitle instance;
|
||||||
public static ConfigManager config;
|
public static ConfigManager config;
|
||||||
|
public static DatabaseManager database;
|
||||||
private GiteaReleaseCheck giteaReleaseCheck;
|
private GiteaReleaseCheck giteaReleaseCheck;
|
||||||
private Map<UUID, TitleDTO> playerUsingTitle = new HashMap<>();
|
|
||||||
|
|
||||||
public static boolean usingPapi() {
|
public static boolean usingPapi() {
|
||||||
return Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
|
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,10 +1,9 @@
|
|||||||
package cn.lunadeer.miniplayertitle.commands;
|
package cn.lunadeer.miniplayertitle.commands;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.Common;
|
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
|
||||||
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -13,36 +12,44 @@ import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
|
|||||||
|
|
||||||
|
|
||||||
public class Apis {
|
public class Apis {
|
||||||
|
public static boolean notOpOrConsole(CommandSender sender) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if (!player.isOp()) {
|
||||||
|
Notification.warn(player, "你没有权限使用此命令");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static void updateName(Player player, @Nullable TitleDTO title) {
|
public static void updateName(Player player, @Nullable TitleDTO title) {
|
||||||
MiniPlayerTitle.instance.setPlayerUsingTitle(player.getUniqueId(), title);
|
|
||||||
if (usingPapi()) {
|
if (usingPapi()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (title == null || title.getId() == -1) {
|
||||||
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()
|
Component newDisplayName = Component.text()
|
||||||
.append(titleComponent)
|
|
||||||
.append(Component.text("<"))
|
.append(Component.text("<"))
|
||||||
.append(player.name())
|
.append(player.name())
|
||||||
.append(Component.text(">")).build();
|
.append(Component.text("> ")).build();
|
||||||
Component newListName = Component.text()
|
Component newListName = Component.text()
|
||||||
.append(titleComponent)
|
|
||||||
.append(Component.text(" "))
|
|
||||||
.append(player.name()).build();
|
.append(player.name()).build();
|
||||||
player.displayName(newDisplayName);
|
player.displayName(newDisplayName);
|
||||||
player.playerListName(newListName);
|
player.playerListName(newListName);
|
||||||
} else {
|
return;
|
||||||
player.setDisplayName(titleBukkit + "<" + player.getName() + ">");
|
|
||||||
player.setPlayerListName(titleBukkit + " " + player.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
|
||||||
|
|
||||||
public class PlayerManage {
|
public class PlayerManage {
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ public class PlayerManage {
|
|||||||
* @param args String[]
|
* @param args String[]
|
||||||
*/
|
*/
|
||||||
public static void addCoin(CommandSender sender, String[] args) {
|
public static void addCoin(CommandSender sender, String[] args) {
|
||||||
if (!sender.hasPermission("mplt.admin")) return;
|
if (notOpOrConsole(sender)) return;
|
||||||
try {
|
try {
|
||||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
||||||
if (playerInfo == null) {
|
if (playerInfo == null) {
|
||||||
@ -45,7 +46,7 @@ public class PlayerManage {
|
|||||||
* @param args String[]
|
* @param args String[]
|
||||||
*/
|
*/
|
||||||
public static void setCoin(CommandSender sender, String[] args) {
|
public static void setCoin(CommandSender sender, String[] args) {
|
||||||
if (!sender.hasPermission("mplt.admin")) return;
|
if (notOpOrConsole(sender)) return;
|
||||||
try {
|
try {
|
||||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
||||||
if (playerInfo == null) {
|
if (playerInfo == null) {
|
||||||
@ -71,7 +72,7 @@ public class PlayerManage {
|
|||||||
* @param args String[]
|
* @param args String[]
|
||||||
*/
|
*/
|
||||||
public static void grantTitle(CommandSender sender, String[] args) {
|
public static void grantTitle(CommandSender sender, String[] args) {
|
||||||
if (!sender.hasPermission("mplt.admin")) return;
|
if (notOpOrConsole(sender)) return;
|
||||||
try {
|
try {
|
||||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
||||||
if (playerInfo == null) {
|
if (playerInfo == null) {
|
||||||
|
@ -1,135 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -11,6 +11,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
|
||||||
import static cn.lunadeer.miniplayertitle.commands.Apis.updateName;
|
import static cn.lunadeer.miniplayertitle.commands.Apis.updateName;
|
||||||
|
|
||||||
public class TitleManage {
|
public class TitleManage {
|
||||||
@ -22,7 +23,7 @@ public class TitleManage {
|
|||||||
* @param args String[]
|
* @param args String[]
|
||||||
*/
|
*/
|
||||||
public static void createTitle(CommandSender sender, String[] args) {
|
public static void createTitle(CommandSender sender, String[] args) {
|
||||||
if (!sender.hasPermission("mplt.admin")) return;
|
if (notOpOrConsole(sender)) return;
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
Notification.warn(sender, "用法: /mplt create_title <称号名称> [称号描述]");
|
Notification.warn(sender, "用法: /mplt create_title <称号名称> [称号描述]");
|
||||||
return;
|
return;
|
||||||
@ -45,7 +46,7 @@ public class TitleManage {
|
|||||||
*/
|
*/
|
||||||
public static void deleteTitle(CommandSender sender, String[] args) {
|
public static void deleteTitle(CommandSender sender, String[] args) {
|
||||||
try {
|
try {
|
||||||
if (!sender.hasPermission("mplt.admin")) return;
|
if (notOpOrConsole(sender)) return;
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
Notification.warn(sender, "用法: /mplt delete_title <称号ID>");
|
Notification.warn(sender, "用法: /mplt delete_title <称号ID>");
|
||||||
return;
|
return;
|
||||||
@ -79,7 +80,7 @@ public class TitleManage {
|
|||||||
*/
|
*/
|
||||||
public static void editTitleName(CommandSender sender, String[] args) {
|
public static void editTitleName(CommandSender sender, String[] args) {
|
||||||
try {
|
try {
|
||||||
if (!sender.hasPermission("mplt.admin")) return;
|
if (notOpOrConsole(sender)) return;
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
Notification.warn(sender, "用法: /mplt set_title <称号ID> <称号名称>");
|
Notification.warn(sender, "用法: /mplt set_title <称号ID> <称号名称>");
|
||||||
return;
|
return;
|
||||||
@ -109,7 +110,7 @@ public class TitleManage {
|
|||||||
*/
|
*/
|
||||||
public static void editTitleDescription(CommandSender sender, String[] args) {
|
public static void editTitleDescription(CommandSender sender, String[] args) {
|
||||||
try {
|
try {
|
||||||
if (!sender.hasPermission("mplt.admin")) return;
|
if (notOpOrConsole(sender)) return;
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
Notification.warn(sender, "用法: /mplt set_desc <称号ID> <称号描述>");
|
Notification.warn(sender, "用法: /mplt set_desc <称号ID> <称号描述>");
|
||||||
return;
|
return;
|
||||||
@ -142,7 +143,6 @@ public class TitleManage {
|
|||||||
Notification.error(sender, "该命令只能由玩家执行");
|
Notification.error(sender, "该命令只能由玩家执行");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!sender.hasPermission("mplt.command")) return;
|
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
Notification.warn(sender, "用法: /mplt use_title <背包ID> [页码]");
|
Notification.warn(sender, "用法: /mplt use_title <背包ID> [页码]");
|
||||||
return;
|
return;
|
||||||
@ -158,29 +158,29 @@ public class TitleManage {
|
|||||||
Notification.info(sender, "已卸下称号");
|
Notification.info(sender, "已卸下称号");
|
||||||
playerInfo.setUsingTitle(null);
|
playerInfo.setUsingTitle(null);
|
||||||
updateName(player, null);
|
updateName(player, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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 {
|
} else {
|
||||||
PlayerTitleDTO title = PlayerTitleDTO.get(id);
|
Notification.error(sender, "使用称号失败,具体请查看控制台日志");
|
||||||
if (title == null) {
|
|
||||||
Notification.error(sender, "称号不存在");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!title.getPlayerUuid().equals(player.getUniqueId())) {
|
|
||||||
Notification.error(sender, "该称号不属于你");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (title.isExpired()) {
|
|
||||||
Notification.error(sender, "称号 %s 已过期", title.getTitle().getTitlePlainText());
|
|
||||||
playerInfo.setUsingTitle(null);
|
|
||||||
updateName(player, null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
boolean success = playerInfo.setUsingTitle(title.getTitle());
|
|
||||||
if (success) {
|
|
||||||
updateName((Player) sender, title.getTitle());
|
|
||||||
Notification.info(sender, "已使用称号");
|
|
||||||
} else {
|
|
||||||
Notification.error(sender, "使用称号失败,具体请查看控制台日志");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
@ -201,10 +201,6 @@ public class TitleManage {
|
|||||||
Notification.error(sender, "该命令只能由玩家执行");
|
Notification.error(sender, "该命令只能由玩家执行");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!sender.hasPermission("mplt.custom") && !sender.hasPermission("mplt.admin")) {
|
|
||||||
Notification.error(sender, "你没有权限使用该命令");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if (!MiniPlayerTitle.config.isEnableCustom()) {
|
if (!MiniPlayerTitle.config.isEnableCustom()) {
|
||||||
Notification.error(sender, "自定义称号功能已关闭");
|
Notification.error(sender, "自定义称号功能已关闭");
|
||||||
|
@ -16,6 +16,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
|
||||||
import static cn.lunadeer.miniplayertitle.tuis.Apis.getArgPage;
|
import static cn.lunadeer.miniplayertitle.tuis.Apis.getArgPage;
|
||||||
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
|
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ public class TitleShopSale {
|
|||||||
* @param args String[]
|
* @param args String[]
|
||||||
*/
|
*/
|
||||||
public static void setSale(CommandSender sender, String[] args) {
|
public static void setSale(CommandSender sender, String[] args) {
|
||||||
if (!sender.hasPermission("mplt.admin")) return;
|
if (notOpOrConsole(sender)) return;
|
||||||
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[2]));
|
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[2]));
|
||||||
if (titleShop == null) {
|
if (titleShop == null) {
|
||||||
Notification.error(sender, "获取详情时出现错误,详情请查看控制台日志");
|
Notification.error(sender, "获取详情时出现错误,详情请查看控制台日志");
|
||||||
@ -82,7 +83,7 @@ public class TitleShopSale {
|
|||||||
* @param args String[]
|
* @param args String[]
|
||||||
*/
|
*/
|
||||||
public static void createSale(CommandSender sender, String[] args) {
|
public static void createSale(CommandSender sender, String[] args) {
|
||||||
if (!sender.hasPermission("mplt.admin")) return;
|
if (notOpOrConsole(sender)) return;
|
||||||
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
|
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
Notification.error(sender, "获取称号详情时出现错误,详情请查看控制台日志");
|
Notification.error(sender, "获取称号详情时出现错误,详情请查看控制台日志");
|
||||||
@ -107,7 +108,7 @@ public class TitleShopSale {
|
|||||||
* @param args String[]
|
* @param args String[]
|
||||||
*/
|
*/
|
||||||
public static void deleteSale(CommandSender sender, String[] args) {
|
public static void deleteSale(CommandSender sender, String[] args) {
|
||||||
if (!sender.hasPermission("mplt.admin")) return;
|
if (notOpOrConsole(sender)) return;
|
||||||
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
|
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
|
||||||
if (titleShop == null) {
|
if (titleShop == null) {
|
||||||
Notification.error(sender, "获取详情时出现错误");
|
Notification.error(sender, "获取详情时出现错误");
|
||||||
@ -137,7 +138,6 @@ public class TitleShopSale {
|
|||||||
Notification.error(sender, "该命令只能由玩家执行");
|
Notification.error(sender, "该命令只能由玩家执行");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!sender.hasPermission("mplt.command")) return;
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
|
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
|
||||||
if (playerInfo == null) {
|
if (playerInfo == null) {
|
||||||
@ -194,7 +194,6 @@ public class TitleShopSale {
|
|||||||
Notification.info(player, Component.text("成功续续期称号: ").append(had.getTitle().getTitleColored()));
|
Notification.info(player, Component.text("成功续续期称号: ").append(had.getTitle().getTitleColored()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TitleManage.useTitle(player, new String[]{"use_title", String.valueOf(had.getId())});
|
|
||||||
int page = getArgPage(args, 3);
|
int page = getArgPage(args, 3);
|
||||||
MyTitles.show(sender, new String[]{"my_titles", String.valueOf(page)});
|
MyTitles.show(sender, new String[]{"my_titles", String.valueOf(page)});
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package cn.lunadeer.miniplayertitle.dtos;
|
package cn.lunadeer.miniplayertitle.dtos;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
|
import cn.lunadeer.minecraftpluginutils.VaultConnect;
|
||||||
import cn.lunadeer.minecraftpluginutils.XLogger;
|
import cn.lunadeer.minecraftpluginutils.XLogger;
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
|
|
||||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -15,22 +12,20 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
|
||||||
|
|
||||||
public class PlayerInfoDTO {
|
public class PlayerInfoDTO {
|
||||||
private final Field uuid = new Field("uuid", FieldType.UUID);
|
private UUID uuid;
|
||||||
private final Field coin = new Field("coin_d", FieldType.DOUBLE);
|
private Double coin;
|
||||||
private TitleDTO using_title;
|
private TitleDTO using_title;
|
||||||
private final Field last_use_name = new Field("last_use_name", FieldType.STRING);
|
private String last_use_name;
|
||||||
|
|
||||||
public static PlayerInfoDTO get(UUID uuid) {
|
public static PlayerInfoDTO get(UUID uuid) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql = "SELECT uuid, coin_d, using_title_id, last_use_name FROM mplt_player_info WHERE uuid = ?;";
|
sql = "SELECT uuid, coin_d, using_title_id, last_use_name FROM mplt_player_info WHERE uuid = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, uuid)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, uuid)) {
|
||||||
if (rs.next()) return getPlayerInfoDTO(rs);
|
if (rs.next()) return getPlayerInfoDTO(rs);
|
||||||
else return null;
|
else return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("获取玩家信息失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("获取玩家信息失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -56,11 +51,11 @@ public class PlayerInfoDTO {
|
|||||||
public static PlayerInfoDTO get(String name) {
|
public static PlayerInfoDTO get(String name) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql = "SELECT uuid, coin_d, using_title_id, last_use_name FROM mplt_player_info WHERE last_use_name = ?;";
|
sql = "SELECT uuid, coin_d, using_title_id, last_use_name FROM mplt_player_info WHERE last_use_name = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, name)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, name)) {
|
||||||
if (rs.next()) return getPlayerInfoDTO(rs);
|
if (rs.next()) return getPlayerInfoDTO(rs);
|
||||||
else return null;
|
else return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("获取玩家信息失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("获取玩家信息失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -70,10 +65,10 @@ public class PlayerInfoDTO {
|
|||||||
sql = "INSERT INTO mplt_player_info (uuid, coin_d, last_use_name) " +
|
sql = "INSERT INTO mplt_player_info (uuid, coin_d, last_use_name) " +
|
||||||
"VALUES (?, ?, ?) " +
|
"VALUES (?, ?, ?) " +
|
||||||
"ON CONFLICT DO NOTHING;";
|
"ON CONFLICT DO NOTHING;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, player.getUniqueId(), MiniPlayerTitle.config.getDefaultCoin(), player.getName())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player.getUniqueId(), MiniPlayerTitle.config.getDefaultCoin(), player.getName())) {
|
||||||
return get(player.getUniqueId());
|
return get(player.getUniqueId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("创建玩家信息失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("创建玩家信息失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -81,29 +76,29 @@ public class PlayerInfoDTO {
|
|||||||
private static PlayerInfoDTO updateName(Player player) {
|
private static PlayerInfoDTO updateName(Player player) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql = "UPDATE mplt_player_info SET last_use_name = ? WHERE uuid = ?;";
|
sql = "UPDATE mplt_player_info SET last_use_name = ? WHERE uuid = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, player.getName(), player.getUniqueId())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player.getName(), player.getUniqueId())) {
|
||||||
return get(player.getUniqueId());
|
return get(player.getUniqueId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("更新玩家名称失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("更新玩家名称失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PlayerInfoDTO getPlayerInfoDTO(ResultSet rs) throws SQLException {
|
private static PlayerInfoDTO getPlayerInfoDTO(ResultSet rs) throws SQLException {
|
||||||
PlayerInfoDTO playerInfoDTO = new PlayerInfoDTO();
|
PlayerInfoDTO playerInfoDTO = new PlayerInfoDTO();
|
||||||
playerInfoDTO.uuid.value = UUID.fromString(rs.getString("uuid"));
|
playerInfoDTO.uuid = UUID.fromString(rs.getString("uuid"));
|
||||||
playerInfoDTO.coin.value = rs.getDouble("coin_d");
|
playerInfoDTO.coin = rs.getDouble("coin_d");
|
||||||
playerInfoDTO.using_title = TitleDTO.get(rs.getInt("using_title_id"));
|
playerInfoDTO.using_title = TitleDTO.get(rs.getInt("using_title_id"));
|
||||||
playerInfoDTO.last_use_name.value = rs.getString("last_use_name");
|
playerInfoDTO.last_use_name = rs.getString("last_use_name");
|
||||||
return playerInfoDTO;
|
return playerInfoDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getCoin() {
|
public Double getCoin() {
|
||||||
if (MiniPlayerTitle.config.isExternalEco()) {
|
if (MiniPlayerTitle.config.isExternalEco()) {
|
||||||
Player player = MiniPlayerTitle.instance.getServer().getPlayer(getUuid());
|
Player player = MiniPlayerTitle.instance.getServer().getPlayer(uuid);
|
||||||
return VaultConnect.instance.getBalance(player);
|
return VaultConnect.instance.getBalance(player);
|
||||||
}
|
}
|
||||||
return (Double) coin.value;
|
return coin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TitleDTO getUsingTitle() {
|
public TitleDTO getUsingTitle() {
|
||||||
@ -111,37 +106,37 @@ public class PlayerInfoDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getLastUseName() {
|
public String getLastUseName() {
|
||||||
return (String) last_use_name.value;
|
return last_use_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUuid() {
|
public UUID getUuid() {
|
||||||
return (UUID) uuid.value;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setUsingTitle(@Nullable TitleDTO title) {
|
public boolean setUsingTitle(@Nullable TitleDTO title) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql = "UPDATE mplt_player_info SET using_title_id = ? WHERE uuid = ?;";
|
sql = "UPDATE mplt_player_info SET using_title_id = ? WHERE uuid = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, title == null ? -1 : title.getId(), getUuid())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title == null ? -1 : title.getId(), uuid)) {
|
||||||
this.using_title = title == null ? TitleDTO.get(-1) : title;
|
this.using_title = title == null ? TitleDTO.get(-1) : title;
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("设置玩家使用称号失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("设置玩家使用称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addCoin(double coin) {
|
public boolean addCoin(double coin) {
|
||||||
if (MiniPlayerTitle.config.isExternalEco()) {
|
if (MiniPlayerTitle.config.isExternalEco()) {
|
||||||
Player player = MiniPlayerTitle.instance.getServer().getPlayer(getUuid());
|
Player player = MiniPlayerTitle.instance.getServer().getPlayer(uuid);
|
||||||
VaultConnect.instance.depositPlayer(player, coin);
|
VaultConnect.instance.depositPlayer(player, coin);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return setCoin(getCoin() + coin);
|
return setCoin(this.coin + coin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setCoin(double coin) {
|
public boolean setCoin(double coin) {
|
||||||
if (MiniPlayerTitle.config.isExternalEco()) {
|
if (MiniPlayerTitle.config.isExternalEco()) {
|
||||||
Player player = MiniPlayerTitle.instance.getServer().getPlayer(getUuid());
|
Player player = MiniPlayerTitle.instance.getServer().getPlayer(uuid);
|
||||||
double balance = VaultConnect.instance.getBalance(player);
|
double balance = VaultConnect.instance.getBalance(player);
|
||||||
if (balance < coin) {
|
if (balance < coin) {
|
||||||
VaultConnect.instance.depositPlayer(player, coin - balance);
|
VaultConnect.instance.depositPlayer(player, coin - balance);
|
||||||
@ -152,11 +147,11 @@ public class PlayerInfoDTO {
|
|||||||
}
|
}
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql = "UPDATE mplt_player_info SET coin_d = ? WHERE uuid = ?;";
|
sql = "UPDATE mplt_player_info SET coin_d = ? WHERE uuid = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, coin, getUuid())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, coin, uuid)) {
|
||||||
this.coin.value = coin;
|
this.coin = coin;
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("设置玩家金币失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("设置玩家金币失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -165,12 +160,12 @@ public class PlayerInfoDTO {
|
|||||||
String sql = "";
|
String sql = "";
|
||||||
sql = "SELECT last_use_name FROM mplt_player_info;";
|
sql = "SELECT last_use_name FROM mplt_player_info;";
|
||||||
List<String> names = new ArrayList<>();
|
List<String> names = new ArrayList<>();
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
names.add(rs.getString("last_use_name"));
|
names.add(rs.getString("last_use_name"));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("获取玩家名称列表失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("获取玩家名称列表失败", e, sql);
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cn.lunadeer.miniplayertitle.dtos;
|
package cn.lunadeer.miniplayertitle.dtos;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -12,16 +10,14 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
|
||||||
|
|
||||||
public class PlayerTitleDTO {
|
public class PlayerTitleDTO {
|
||||||
private final Field id = new Field("id", FieldType.INT);
|
private Integer id;
|
||||||
private final Field player_uuid = new Field("player_uuid", FieldType.UUID);
|
private UUID player_uuid;
|
||||||
private TitleDTO title;
|
private TitleDTO title;
|
||||||
private LocalDateTime expire_at;
|
private LocalDateTime expire_at;
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return (Integer) id.value;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TitleDTO getTitle() {
|
public TitleDTO getTitle() {
|
||||||
@ -29,7 +25,7 @@ public class PlayerTitleDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public UUID getPlayerUuid() {
|
public UUID getPlayerUuid() {
|
||||||
return (UUID) player_uuid.value;
|
return player_uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getExpireAt() {
|
public LocalDateTime getExpireAt() {
|
||||||
@ -39,14 +35,14 @@ public class PlayerTitleDTO {
|
|||||||
public boolean setExpireAt(LocalDateTime dateTime) {
|
public boolean setExpireAt(LocalDateTime dateTime) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
if (dateTime == null) {
|
if (dateTime == null) {
|
||||||
sql += "UPDATE mplt_player_title SET expire_at_y = -1, expire_at_m = -1, expire_at_d = -1 WHERE id = " + getId() + ";";
|
sql += "UPDATE mplt_player_title SET expire_at_y = -1, expire_at_m = -1, expire_at_d = -1 WHERE id = " + id + ";";
|
||||||
} else {
|
} else {
|
||||||
sql += "UPDATE mplt_player_title SET expire_at_y = " + dateTime.getYear() + ", expire_at_m = " + dateTime.getMonthValue() + ", expire_at_d = " + dateTime.getDayOfMonth() + " WHERE id = " + getId() + ";";
|
sql += "UPDATE mplt_player_title SET expire_at_y = " + dateTime.getYear() + ", expire_at_m = " + dateTime.getMonthValue() + ", expire_at_d = " + dateTime.getDayOfMonth() + " WHERE id = " + id + ";";
|
||||||
}
|
}
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("设置玩家称号过期时间失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("设置玩家称号过期时间失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -62,12 +58,12 @@ public class PlayerTitleDTO {
|
|||||||
}
|
}
|
||||||
sql += "RETURNING " +
|
sql += "RETURNING " +
|
||||||
"id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d;";
|
"id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, player_uuid, title.getId())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player_uuid, title.getId())) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return getRs(rs);
|
return getRs(rs);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("创建玩家称号失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("创建玩家称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -76,12 +72,12 @@ public class PlayerTitleDTO {
|
|||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
||||||
"WHERE id = ?;";
|
"WHERE id = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, id)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return getRs(rs);
|
return getRs(rs);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("获取玩家称号失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("获取玩家称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -90,20 +86,20 @@ public class PlayerTitleDTO {
|
|||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
||||||
"WHERE player_uuid = ? AND title_id = ?;";
|
"WHERE player_uuid = ? AND title_id = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, player, title)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player, title)) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return getRs(rs);
|
return getRs(rs);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("获取玩家称号失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("获取玩家称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PlayerTitleDTO getRs(ResultSet rs) throws SQLException {
|
private static PlayerTitleDTO getRs(ResultSet rs) throws SQLException {
|
||||||
PlayerTitleDTO playerTitle = new PlayerTitleDTO();
|
PlayerTitleDTO playerTitle = new PlayerTitleDTO();
|
||||||
playerTitle.id.value = rs.getInt("id");
|
playerTitle.id = rs.getInt("id");
|
||||||
playerTitle.player_uuid.value = UUID.fromString(rs.getString("player_uuid"));
|
playerTitle.player_uuid = UUID.fromString(rs.getString("player_uuid"));
|
||||||
playerTitle.title = TitleDTO.get(rs.getInt("title_id"));
|
playerTitle.title = TitleDTO.get(rs.getInt("title_id"));
|
||||||
int y = rs.getInt("expire_at_y");
|
int y = rs.getInt("expire_at_y");
|
||||||
int m = rs.getInt("expire_at_m");
|
int m = rs.getInt("expire_at_m");
|
||||||
@ -121,12 +117,12 @@ public class PlayerTitleDTO {
|
|||||||
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
||||||
"WHERE player_uuid = ?;";
|
"WHERE player_uuid = ?;";
|
||||||
List<PlayerTitleDTO> playerTitles = new ArrayList<>();
|
List<PlayerTitleDTO> playerTitles = new ArrayList<>();
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, player_uuid)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player_uuid)) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
playerTitles.add(getRs(rs));
|
playerTitles.add(getRs(rs));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("获取玩家称号失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("获取玩家称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return playerTitles;
|
return playerTitles;
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,31 @@
|
|||||||
package cn.lunadeer.miniplayertitle.dtos;
|
package cn.lunadeer.miniplayertitle.dtos;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.ColorParser;
|
import cn.lunadeer.minecraftpluginutils.XLogger;
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
import cn.lunadeer.miniplayertitle.Color;
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
|
|
||||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class TitleDTO {
|
public class TitleDTO {
|
||||||
private final Field id = new Field("id", FieldType.INT);
|
private int id;
|
||||||
private final Field title = new Field("title", FieldType.STRING);
|
private String title;
|
||||||
private final Field description = new Field("description", FieldType.STRING);
|
private String description;
|
||||||
|
|
||||||
|
|
||||||
public static TitleDTO get(int id) {
|
public static TitleDTO get(int id) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "SELECT id, title, description FROM mplt_title WHERE id = " + id + ";";
|
sql += "SELECT id, title, description FROM mplt_title WHERE id = " + id + ";";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
|
||||||
if (rs.next()) return getTitleDTO(rs);
|
if (rs.next()) return getTitleDTO(rs);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("获取称号失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("获取称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -37,10 +36,10 @@ public class TitleDTO {
|
|||||||
"VALUES (?, ?) " +
|
"VALUES (?, ?) " +
|
||||||
"RETURNING " +
|
"RETURNING " +
|
||||||
"id, title, description;";
|
"id, title, description;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, title, description)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title, description)) {
|
||||||
if (rs.next()) return getTitleDTO(rs);
|
if (rs.next()) return getTitleDTO(rs);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("创建称号失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("创建称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -50,12 +49,12 @@ public class TitleDTO {
|
|||||||
String deleteSql = "DELETE FROM mplt_title WHERE id = ?;";
|
String deleteSql = "DELETE FROM mplt_title WHERE id = ?;";
|
||||||
try {
|
try {
|
||||||
// 执行更新操作
|
// 执行更新操作
|
||||||
DatabaseManager.instance.query(updateSql, getId());
|
MiniPlayerTitle.database.query(updateSql, this.id);
|
||||||
// 执行删除操作
|
// 执行删除操作
|
||||||
DatabaseManager.instance.query(deleteSql, getId());
|
MiniPlayerTitle.database.query(deleteSql, this.id);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("删除称号失败", e, updateSql + " " + deleteSql);
|
MiniPlayerTitle.database.handleDatabaseError("删除称号失败", e, updateSql + " " + deleteSql);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,59 +63,105 @@ public class TitleDTO {
|
|||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "SELECT id, title, description FROM mplt_title;";
|
sql += "SELECT id, title, description FROM mplt_title;";
|
||||||
List<TitleDTO> titleDTOs = new ArrayList<>();
|
List<TitleDTO> titleDTOs = new ArrayList<>();
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
titleDTOs.add(getTitleDTO(rs));
|
titleDTOs.add(getTitleDTO(rs));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("获取称号列表失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("获取称号列表失败", e, sql);
|
||||||
}
|
}
|
||||||
return titleDTOs;
|
return titleDTOs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextComponent getTitleColored() {
|
public TextComponent getTitleColored() {
|
||||||
String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
|
TextComponent prefix = Component.text(MiniPlayerTitle.config.getPrefix(), new Color("#ffffff").getStyle());
|
||||||
return ColorParser.getComponentType(with_pre_suf);
|
TextComponent suffix = Component.text(MiniPlayerTitle.config.getSuffix(), new Color("#ffffff").getStyle());
|
||||||
|
String[] parts = this.title.split("&#");
|
||||||
|
List<TextComponent> components = new ArrayList<>();
|
||||||
|
components.add(prefix);
|
||||||
|
for (String part : parts) {
|
||||||
|
if (part.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取称号的颜色化字符串
|
* 获取称号的颜色化字符串
|
||||||
* 需要使用 ChatColor.translateAlternateColorCodes 方法对返回字符串进行处理
|
* 需要使用 translateAlternateColorCodes 方法对返回字符串进行处理
|
||||||
* &#FFFFFF -> &x&f&f&f&f&f
|
* &#FFFFFF -> &x&f&f&f&f&f
|
||||||
*
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public String getTitleColoredBukkit() {
|
public String getTitleColoredBukkit() {
|
||||||
String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
|
String title = "&f" + MiniPlayerTitle.config.getPrefix() + this.title + "&f" + MiniPlayerTitle.config.getSuffix();
|
||||||
return ColorParser.getBukkitType(with_pre_suf);
|
title = title.replaceAll("&#", "#");
|
||||||
|
Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
|
||||||
|
Matcher matcher = pattern.matcher(title);
|
||||||
|
while (matcher.find()) {
|
||||||
|
String hexCode = matcher.group();
|
||||||
|
StringBuilder builder = new StringBuilder("&x");
|
||||||
|
for (char c : hexCode.substring(1).toCharArray()) {
|
||||||
|
builder.append('&').append(c);
|
||||||
|
}
|
||||||
|
title = title.replace(hexCode, builder.toString());
|
||||||
|
}
|
||||||
|
XLogger.debug("TitleDTO.getTitleColoredBukkit: %s", title);
|
||||||
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitlePlainText() {
|
public String getTitlePlainText() {
|
||||||
return ColorParser.getPlainText(getTitleRaw());
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return (Integer) this.id.value;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return (String) this.description.value;
|
return this.description;
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitleRaw() {
|
|
||||||
return (String) this.title.value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateTitle(String title) {
|
public boolean updateTitle(String title) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "UPDATE mplt_title SET title = ? WHERE id = ?;";
|
sql += "UPDATE mplt_title SET title = ? WHERE id = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, title, getId())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title, this.id)) {
|
||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
this.title.value = title;
|
this.title = title;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("更新称号失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("更新称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -124,22 +169,22 @@ public class TitleDTO {
|
|||||||
public boolean updateDescription(String description) {
|
public boolean updateDescription(String description) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "UPDATE mplt_title SET description = ? WHERE id = ?;";
|
sql += "UPDATE mplt_title SET description = ? WHERE id = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, description, getId())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, description, this.id)) {
|
||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
this.description.value = description;
|
this.description = description;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("更新称号失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("更新称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TitleDTO getTitleDTO(ResultSet rs) throws SQLException {
|
private static TitleDTO getTitleDTO(ResultSet rs) throws SQLException {
|
||||||
TitleDTO titleDTO = new TitleDTO();
|
TitleDTO titleDTO = new TitleDTO();
|
||||||
titleDTO.id.value = rs.getInt("id");
|
titleDTO.id = rs.getInt("id");
|
||||||
titleDTO.title.value = rs.getString("title");
|
titleDTO.title = rs.getString("title");
|
||||||
titleDTO.description.value = rs.getString("description");
|
titleDTO.description = rs.getString("description");
|
||||||
return titleDTO;
|
return titleDTO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,22 @@
|
|||||||
package cn.lunadeer.miniplayertitle.dtos;
|
package cn.lunadeer.miniplayertitle.dtos;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
|
||||||
|
|
||||||
public class TitleShopDTO {
|
public class TitleShopDTO {
|
||||||
|
private Integer id;
|
||||||
private TitleDTO title;
|
private TitleDTO title;
|
||||||
private final Field id = new Field("id", FieldType.INT);
|
private Double price;
|
||||||
private final Field price = new Field("price_d", FieldType.DOUBLE);
|
private Integer days;
|
||||||
private final Field days = new Field("days", FieldType.INT);
|
private Integer amount;
|
||||||
private final Field amount = new Field("amount", FieldType.INT);
|
|
||||||
|
|
||||||
private LocalDateTime sale_end_at;
|
private LocalDateTime sale_end_at;
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return (Integer) id.value;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TitleDTO getTitle() {
|
public TitleDTO getTitle() {
|
||||||
@ -29,49 +24,46 @@ public class TitleShopDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Double getPrice() {
|
public Double getPrice() {
|
||||||
return (Double) price.value;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setPrice(Double price) {
|
public boolean setPrice(Double price) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "UPDATE mplt_title_shop SET price_d = ? WHERE id = ?;";
|
sql += "UPDATE mplt_title_shop SET price_d = ? WHERE id = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, price, getId())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, price, id)) {
|
||||||
this.price.value = price;
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("设置称号商店价格失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("设置称号商店价格失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getDays() {
|
public Integer getDays() {
|
||||||
return (Integer) days.value;
|
return days;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setDays(int days) {
|
public boolean setDays(int days) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "UPDATE mplt_title_shop SET days = ? WHERE id = ?;";
|
sql += "UPDATE mplt_title_shop SET days = ? WHERE id = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, days, getId())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, days, id)) {
|
||||||
this.days.value = days;
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("设置称号商店天数失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("设置称号商店天数失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getAmount() {
|
public Integer getAmount() {
|
||||||
return (Integer) amount.value;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setAmount(int amount) {
|
public boolean setAmount(int amount) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "UPDATE mplt_title_shop SET amount = ? WHERE id = ?;";
|
sql += "UPDATE mplt_title_shop SET amount = ? WHERE id = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, amount, getId())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, amount, id)) {
|
||||||
this.amount.value = amount;
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("设置称号商店数量失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("设置称号商店数量失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -87,10 +79,10 @@ public class TitleShopDTO {
|
|||||||
public boolean setSaleEndAt(int y, int m, int d) {
|
public boolean setSaleEndAt(int y, int m, int d) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "UPDATE mplt_title_shop SET sale_end_at_y = ?, sale_end_at_m = ?, sale_end_at_d = ? WHERE id = ?;";
|
sql += "UPDATE mplt_title_shop SET sale_end_at_y = ?, sale_end_at_m = ?, sale_end_at_d = ? WHERE id = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, y, m, d, getId())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, y, m, d, id)) {
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("设置称号商店销售结束时间失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("设置称号商店销售结束时间失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -99,12 +91,12 @@ public class TitleShopDTO {
|
|||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "SELECT id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
sql += "SELECT id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
||||||
"FROM mplt_title_shop WHERE id = ?;";
|
"FROM mplt_title_shop WHERE id = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, id)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return getTitleShop(rs);
|
return getTitleShop(rs);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("获取称号商店信息失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("获取称号商店信息失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -114,24 +106,24 @@ public class TitleShopDTO {
|
|||||||
sql += "SELECT id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
sql += "SELECT id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d " +
|
||||||
"FROM mplt_title_shop;";
|
"FROM mplt_title_shop;";
|
||||||
List<TitleShopDTO> titleShops = new ArrayList<>();
|
List<TitleShopDTO> titleShops = new ArrayList<>();
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
|
||||||
while (rs != null && rs.next()) {
|
while (rs != null && rs.next()) {
|
||||||
TitleShopDTO titleShop = getTitleShop(rs);
|
TitleShopDTO titleShop = getTitleShop(rs);
|
||||||
titleShops.add(titleShop);
|
titleShops.add(titleShop);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("获取称号商店列表失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("获取称号商店列表失败", e, sql);
|
||||||
}
|
}
|
||||||
return titleShops;
|
return titleShops;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TitleShopDTO getTitleShop(ResultSet rs) throws Exception {
|
private static TitleShopDTO getTitleShop(ResultSet rs) throws Exception {
|
||||||
TitleShopDTO titleShop = new TitleShopDTO();
|
TitleShopDTO titleShop = new TitleShopDTO();
|
||||||
titleShop.id.value = rs.getInt("id");
|
titleShop.id = rs.getInt("id");
|
||||||
titleShop.title = TitleDTO.get(rs.getInt("title_id"));
|
titleShop.title = TitleDTO.get(rs.getInt("title_id"));
|
||||||
titleShop.price.value = rs.getDouble("price_d");
|
titleShop.price = rs.getDouble("price_d");
|
||||||
titleShop.days.value = rs.getInt("days");
|
titleShop.days = rs.getInt("days");
|
||||||
titleShop.amount.value = rs.getInt("amount");
|
titleShop.amount = rs.getInt("amount");
|
||||||
int y = rs.getInt("sale_end_at_y");
|
int y = rs.getInt("sale_end_at_y");
|
||||||
int m = rs.getInt("sale_end_at_m");
|
int m = rs.getInt("sale_end_at_m");
|
||||||
int d = rs.getInt("sale_end_at_d");
|
int d = rs.getInt("sale_end_at_d");
|
||||||
@ -149,12 +141,12 @@ public class TitleShopDTO {
|
|||||||
"VALUES (?, 0, -1, 0, -1, -1, -1) " +
|
"VALUES (?, 0, -1, 0, -1, -1, -1) " +
|
||||||
"RETURNING " +
|
"RETURNING " +
|
||||||
"id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d;";
|
"id, title_id, price_d, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, title.getId())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title.getId())) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return getTitleShop(rs);
|
return getTitleShop(rs);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("创建称号商店失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("创建称号商店失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -162,10 +154,10 @@ public class TitleShopDTO {
|
|||||||
public boolean delete() {
|
public boolean delete() {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "DELETE FROM mplt_title_shop WHERE id = ?;";
|
sql += "DELETE FROM mplt_title_shop WHERE id = ?;";
|
||||||
try (ResultSet rs = DatabaseManager.instance.query(sql, getId())) {
|
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) {
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleDatabaseError("删除称号商店失败", e, sql);
|
MiniPlayerTitle.database.handleDatabaseError("删除称号商店失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
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()
|
Line line = Line.create()
|
||||||
.append(title.getId().toString())
|
.append(title.getId().toString())
|
||||||
.append(title.getTitleColored());
|
.append(title.getTitleColored());
|
||||||
if (player.hasPermission("mplt.admin")) {
|
if (player.isOp()) {
|
||||||
line.append(Button.createRed("删除").setExecuteCommand("/mplt delete_title " + title.getId() + " " + page).build());
|
line.append(Button.createRed("删除").setExecuteCommand("/mplt delete_title " + title.getId() + " " + page).build());
|
||||||
line.append(Button.createGreen("创建商品").setExecuteCommand("/mplt create_sale " + title.getId()).build());
|
line.append(Button.createGreen("创建商品").setExecuteCommand("/mplt create_sale " + title.getId()).build());
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cn.lunadeer.miniplayertitle.tuis;
|
package cn.lunadeer.miniplayertitle.tuis;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||||
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
|
import cn.lunadeer.minecraftpluginutils.VaultConnect;
|
||||||
import cn.lunadeer.minecraftpluginutils.stui.ListView;
|
import cn.lunadeer.minecraftpluginutils.stui.ListView;
|
||||||
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
|
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
|
||||||
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
|
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
|
||||||
@ -58,7 +58,7 @@ public class Menu {
|
|||||||
Line all = Line.create()
|
Line all = Line.create()
|
||||||
.append(Button.create("所有称号").setExecuteCommand("/mplt all_titles").build()).append("查看所有称号");
|
.append(Button.create("所有称号").setExecuteCommand("/mplt all_titles").build()).append("查看所有称号");
|
||||||
|
|
||||||
if (player.hasPermission("mplt.admin")) {
|
if (player.isOp()) {
|
||||||
view.add(Line.create().append(""));
|
view.add(Line.create().append(""));
|
||||||
view.add(Line.create().append("---以下选项仅OP可见---"));
|
view.add(Line.create().append("---以下选项仅OP可见---"));
|
||||||
view.add(all);
|
view.add(all);
|
||||||
|
@ -47,7 +47,7 @@ public class MyTitles {
|
|||||||
} else {
|
} else {
|
||||||
line.append("有效期至: " + title.getExpireAt().getYear() + "年" + title.getExpireAt().getMonthValue() + "月" + title.getExpireAt().getDayOfMonth() + "日");
|
line.append("有效期至: " + title.getExpireAt().getYear() + "年" + title.getExpireAt().getMonthValue() + "月" + title.getExpireAt().getDayOfMonth() + "日");
|
||||||
}
|
}
|
||||||
if (Objects.equals(playerInfo.getUsingTitle().getId(), title.getTitle().getId())) {
|
if (Objects.equals(playerInfo.getUsingTitle().getId(), title.getId())) {
|
||||||
line.append(Button.createRed("卸下").setExecuteCommand("/mplt use_title -1 " + page).build());
|
line.append(Button.createRed("卸下").setExecuteCommand("/mplt use_title -1 " + page).build());
|
||||||
} else {
|
} else {
|
||||||
line.append(Button.createGreen("使用").setExecuteCommand("/mplt use_title " + title.getId() + " " + page).build());
|
line.append(Button.createGreen("使用").setExecuteCommand("/mplt use_title " + title.getId() + " " + page).build());
|
||||||
|
@ -46,11 +46,11 @@ public class SaleInfo {
|
|||||||
Line price = Line.create().append("价格: ");
|
Line price = Line.create().append("价格: ");
|
||||||
if (titleShop.getPrice() <= 0) {
|
if (titleShop.getPrice() <= 0) {
|
||||||
price.append("免费");
|
price.append("免费");
|
||||||
if (player.hasPermission("mplt.admin")) {
|
if (player.isOp()) {
|
||||||
price.append(Button.create("设置价格").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 100 " + page).build());
|
price.append(Button.create("设置价格").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 100 " + page).build());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (player.hasPermission("mplt.admin")) {
|
if (player.isOp()) {
|
||||||
price.append(NumChanger.create(titleShop.getPrice(), "/mplt set_sale price " + titleShop.getId()).setPageNumber(page).build());
|
price.append(NumChanger.create(titleShop.getPrice(), "/mplt set_sale price " + titleShop.getId()).setPageNumber(page).build());
|
||||||
price.append(Button.create("设置为免费").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 0 " + page).build());
|
price.append(Button.create("设置为免费").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 0 " + page).build());
|
||||||
} else {
|
} else {
|
||||||
@ -62,11 +62,11 @@ public class SaleInfo {
|
|||||||
Line day = Line.create().append("购买天数: ");
|
Line day = Line.create().append("购买天数: ");
|
||||||
if (titleShop.getDays() <= 0) {
|
if (titleShop.getDays() <= 0) {
|
||||||
day.append("永久");
|
day.append("永久");
|
||||||
if (player.hasPermission("mplt.admin")) {
|
if (player.isOp()) {
|
||||||
day.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " 7 " + page).build());
|
day.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " 7 " + page).build());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (player.hasPermission("mplt.admin")) {
|
if (player.isOp()) {
|
||||||
day.append(NumChanger.create(titleShop.getDays(), "/mplt set_sale days " + titleShop.getId()).setPageNumber(page).build());
|
day.append(NumChanger.create(titleShop.getDays(), "/mplt set_sale days " + titleShop.getId()).setPageNumber(page).build());
|
||||||
day.append(Button.create("转为永久").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " -1 " + page).build());
|
day.append(Button.create("转为永久").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " -1 " + page).build());
|
||||||
} else {
|
} else {
|
||||||
@ -78,12 +78,12 @@ public class SaleInfo {
|
|||||||
Line amount = Line.create().append("剩余数量: ");
|
Line amount = Line.create().append("剩余数量: ");
|
||||||
if (titleShop.getAmount() == -1) {
|
if (titleShop.getAmount() == -1) {
|
||||||
amount.append("无限");
|
amount.append("无限");
|
||||||
if (player.hasPermission("mplt.admin")) {
|
if (player.isOp()) {
|
||||||
amount.append(Button.create("转为限量").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " 0 " + page).build());
|
amount.append(Button.create("转为限量").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " 0 " + page).build());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (player.hasPermission("mplt.admin")) {
|
if (player.isOp()) {
|
||||||
amount.append(NumChanger.create(titleShop.getAmount(), "/mplt set_sale amount " + titleShop.getId()).setPageNumber(page).build());
|
amount.append(NumChanger.create(titleShop.getAmount(), "/mplt set_sale amount " + titleShop.getId()).setPageNumber(page).build());
|
||||||
amount.append(Button.create("转为无限").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " -1 " + page).build());
|
amount.append(Button.create("转为无限").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " -1 " + page).build());
|
||||||
} else {
|
} else {
|
||||||
@ -95,11 +95,11 @@ public class SaleInfo {
|
|||||||
Line end_at = Line.create().append("售卖结束时间: ");
|
Line end_at = Line.create().append("售卖结束时间: ");
|
||||||
if (titleShop.getSaleEndAt() == null) {
|
if (titleShop.getSaleEndAt() == null) {
|
||||||
end_at.append("常驻");
|
end_at.append("常驻");
|
||||||
if (player.hasPermission("mplt.admin")) {
|
if (player.isOp()) {
|
||||||
end_at.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale end_at " + titleShop.getId() + " " + now_year + ":" + now_month + ":" + now_day + " " + page).build());
|
end_at.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale end_at " + titleShop.getId() + " " + now_year + ":" + now_month + ":" + now_day + " " + page).build());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (player.hasPermission("mplt.admin")) {
|
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("提前10天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 10 " + page).build()
|
||||||
.append(Button.create("-").setPreSufIx("", "").setHoverText("提前1天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 1 " + page).build())
|
.append(Button.create("-").setPreSufIx("", "").setHoverText("提前1天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 1 " + page).build())
|
||||||
.append(Component.text(titleShop.getSaleEndAt().getYear() + "年" + titleShop.getSaleEndAt().getMonthValue() + "月" + titleShop.getSaleEndAt().getDayOfMonth() + "日"))
|
.append(Component.text(titleShop.getSaleEndAt().getYear() + "年" + titleShop.getSaleEndAt().getMonthValue() + "月" + titleShop.getSaleEndAt().getDayOfMonth() + "日"))
|
||||||
@ -120,9 +120,8 @@ public class SaleInfo {
|
|||||||
} else {
|
} else {
|
||||||
operate.append(Button.createGreen("购买").setExecuteCommand("/mplt buy_sale " + titleShop.getId()).build());
|
operate.append(Button.createGreen("购买").setExecuteCommand("/mplt buy_sale " + titleShop.getId()).build());
|
||||||
}
|
}
|
||||||
if (player.hasPermission("mplt.admin")) {
|
if (player.isOp()) {
|
||||||
operate.append(Button.create("删除").setExecuteCommand("/mplt delete_sale " + args[1] + " b").build());
|
operate.append(Button.create("删除").setExecuteCommand("/mplt delete_sale " + args[1] + " b").build());
|
||||||
operate.append(Button.createGreen("导出称号卡").setExecuteCommand("/mplt get_card " + args[1]).build());
|
|
||||||
}
|
}
|
||||||
view.add(Line.create().append("---------------------"));
|
view.add(Line.create().append("---------------------"));
|
||||||
view.add(operate);
|
view.add(operate);
|
||||||
|
@ -1,172 +1,126 @@
|
|||||||
package cn.lunadeer.miniplayertitle.utils;
|
package cn.lunadeer.miniplayertitle.utils;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.TableColumn;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.syntax.AddColumn;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.syntax.CreateTable;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
|
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.syntax.RemoveColumn;
|
|
||||||
|
|
||||||
import static cn.lunadeer.minecraftpluginutils.databse.Common.IsFieldExist;
|
|
||||||
|
|
||||||
public class DatabaseTables {
|
public class DatabaseTables {
|
||||||
|
|
||||||
public static void migrate() {
|
public static void migrate() {
|
||||||
|
String sql = "";
|
||||||
|
|
||||||
// title table
|
// title table
|
||||||
TableColumn mplt_title_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
|
sql = "CREATE TABLE IF NOT EXISTS mplt_title (" +
|
||||||
TableColumn mplt_title_title = new TableColumn("title", FieldType.STRING, false, false, true, false, "'unknown'");
|
" id SERIAL PRIMARY KEY," +
|
||||||
TableColumn mplt_title_description = new TableColumn("description", FieldType.STRING, false, false, true, false, "'unknown'");
|
" title TEXT NOT NULL UNIQUE," +
|
||||||
TableColumn mplt_title_enabled = new TableColumn("enabled", FieldType.BOOLEAN, false, false, true, false, "true");
|
" description TEXT NOT NULL," +
|
||||||
TableColumn mplt_title_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
" enabled BOOLEAN NOT NULL DEFAULT TRUE," +
|
||||||
TableColumn mplt_title_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||||
CreateTable mplt_title = new CreateTable().ifNotExists();
|
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP" +
|
||||||
mplt_title.table("mplt_title")
|
");";
|
||||||
.field(mplt_title_id)
|
MiniPlayerTitle.database.query(sql);
|
||||||
.field(mplt_title_title)
|
|
||||||
.field(mplt_title_description)
|
|
||||||
.field(mplt_title_enabled)
|
|
||||||
.field(mplt_title_created_at)
|
|
||||||
.field(mplt_title_updated_at);
|
|
||||||
mplt_title.execute();
|
|
||||||
|
|
||||||
|
|
||||||
// title shop table
|
// title shop table
|
||||||
TableColumn mplt_title_shop_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
|
sql = "CREATE TABLE IF NOT EXISTS mplt_title_shop (" +
|
||||||
TableColumn mplt_title_shop_title_id = new TableColumn("title_id", FieldType.INT, false, false, true, false, 0);
|
" id SERIAL PRIMARY KEY," +
|
||||||
TableColumn mplt_title_shop_price = new TableColumn("price", FieldType.INT, false, false, true, false, 0);
|
" title_id INTEGER NOT NULL," +
|
||||||
TableColumn mplt_title_shop_days = new TableColumn("days", FieldType.INT, false, false, true, false, 0);
|
" price INTEGER NOT NULL DEFAULT 0," +
|
||||||
TableColumn mplt_title_shop_amount = new TableColumn("amount", FieldType.INT, false, false, true, false, -1);
|
" days INTEGER NOT NULL DEFAULT 0," +
|
||||||
TableColumn mplt_title_shop_sale_end_at = new TableColumn("sale_end_at", FieldType.LONG, false, false, true, false, -1);
|
" amount INTEGER NOT NULL DEFAULT -1," +
|
||||||
TableColumn mplt_title_shop_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
" sale_end_at BIGINT NOT NULL DEFAULT -1," +
|
||||||
TableColumn mplt_title_shop_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||||
CreateTable.ForeignKey mplt_title_shop_title_id_fk = new CreateTable.ForeignKey(mplt_title_shop_title_id, "mplt_title", mplt_title_id, true);
|
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||||
CreateTable mplt_title_shop = new CreateTable().ifNotExists();
|
" FOREIGN KEY (title_id) REFERENCES mplt_title(id) ON DELETE CASCADE" +
|
||||||
mplt_title_shop.table("mplt_title_shop")
|
");";
|
||||||
.field(mplt_title_shop_id)
|
MiniPlayerTitle.database.query(sql);
|
||||||
.field(mplt_title_shop_title_id)
|
|
||||||
.field(mplt_title_shop_price)
|
|
||||||
.field(mplt_title_shop_days)
|
|
||||||
.field(mplt_title_shop_amount)
|
|
||||||
.field(mplt_title_shop_sale_end_at)
|
|
||||||
.field(mplt_title_shop_created_at)
|
|
||||||
.field(mplt_title_shop_updated_at)
|
|
||||||
.foreignKey(mplt_title_shop_title_id_fk);
|
|
||||||
mplt_title_shop.execute();
|
|
||||||
|
|
||||||
// player title info table
|
// player title info table
|
||||||
TableColumn mplt_player_info_uuid = new TableColumn("uuid", FieldType.UUID, true, false, true, false, "'00000000-0000-0000-0000-000000000000'");
|
sql = "CREATE TABLE IF NOT EXISTS mplt_player_info (" +
|
||||||
TableColumn mplt_player_info_coin = new TableColumn("coin", FieldType.INT, false, false, true, false, 0);
|
" uuid UUID PRIMARY KEY," +
|
||||||
TableColumn mplt_player_info_using_title_id = new TableColumn("using_title_id", FieldType.INT, false, false, true, false, -1);
|
" coin INTEGER NOT NULL DEFAULT 0," +
|
||||||
TableColumn mplt_player_info_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
" using_title_id INTEGER NOT NULL DEFAULT -1," +
|
||||||
TableColumn mplt_player_info_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||||
CreateTable.ForeignKey mplt_player_info_using_title_id_fk = new CreateTable.ForeignKey(mplt_player_info_using_title_id, "mplt_title", mplt_title_id, true);
|
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||||
CreateTable mplt_player_info = new CreateTable().ifNotExists();
|
" FOREIGN KEY (using_title_id) REFERENCES mplt_title(id) ON DELETE CASCADE" +
|
||||||
mplt_player_info.table("mplt_player_info")
|
");";
|
||||||
.field(mplt_player_info_uuid)
|
MiniPlayerTitle.database.query(sql);
|
||||||
.field(mplt_player_info_coin)
|
|
||||||
.field(mplt_player_info_using_title_id)
|
|
||||||
.field(mplt_player_info_created_at)
|
|
||||||
.field(mplt_player_info_updated_at)
|
|
||||||
.foreignKey(mplt_player_info_using_title_id_fk);
|
|
||||||
mplt_player_info.execute();
|
|
||||||
|
|
||||||
|
|
||||||
// player title table
|
// player title table
|
||||||
TableColumn mplt_player_title_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
|
sql = "CREATE TABLE IF NOT EXISTS mplt_player_title (" +
|
||||||
TableColumn mplt_player_title_player_uuid = new TableColumn("player_uuid", FieldType.UUID, false, false, true, false, "'00000000-0000-0000-0000-000000000000'");
|
" id SERIAL PRIMARY KEY," +
|
||||||
TableColumn mplt_player_title_title_id = new TableColumn("title_id", FieldType.INT, false, false, true, false, 0);
|
" player_uuid UUID NOT NULL," +
|
||||||
TableColumn mplt_player_title_expire_at = new TableColumn("expire_at", FieldType.LONG, false, false, true, false, -1);
|
" title_id INTEGER NOT NULL," +
|
||||||
TableColumn mplt_player_title_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
" expire_at BIGINT NOT NULL DEFAULT -1," +
|
||||||
TableColumn mplt_player_title_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||||
CreateTable.ForeignKey mplt_player_title_title_id_fk = new CreateTable.ForeignKey(mplt_player_title_title_id, "mplt_title", mplt_title_id, true);
|
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||||
CreateTable.ForeignKey mplt_player_title_player_uuid_fk = new CreateTable.ForeignKey(mplt_player_title_player_uuid, "mplt_player_info", mplt_player_info_uuid, true);
|
" FOREIGN KEY (title_id) REFERENCES mplt_title(id) ON DELETE CASCADE," +
|
||||||
CreateTable mplt_player_title = new CreateTable().ifNotExists();
|
" FOREIGN KEY (player_uuid) REFERENCES mplt_player_info(uuid) ON DELETE CASCADE" +
|
||||||
mplt_player_title.table("mplt_player_title")
|
");";
|
||||||
.field(mplt_player_title_id)
|
MiniPlayerTitle.database.query(sql);
|
||||||
.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();
|
|
||||||
|
|
||||||
new RemoveColumn("expire_at").IfExists().table("mplt_title").execute();
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "created_at");
|
||||||
new RemoveColumn("sale_end_at").IfExists().table("mplt_title_shop").execute();
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "updated_at");
|
||||||
new RemoveColumn("expire_at").IfExists().table("mplt_player_title").execute();
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "enabled");
|
||||||
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();
|
|
||||||
|
|
||||||
TableColumn mplt_title_shop_sale_end_at_y = new TableColumn("sale_end_at_y", FieldType.INT, false, false, true, false, -1);
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "created_at");
|
||||||
TableColumn mplt_title_shop_sale_end_at_m = new TableColumn("sale_end_at_m", FieldType.INT, false, false, true, false, -1);
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "updated_at");
|
||||||
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();
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "created_at");
|
||||||
new AddColumn(mplt_title_shop_sale_end_at_m).table("mplt_title_shop").ifNotExists().execute();
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "updated_at");
|
||||||
new AddColumn(mplt_title_shop_sale_end_at_d).table("mplt_title_shop").ifNotExists().execute();
|
|
||||||
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "created_at");
|
||||||
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "updated_at");
|
||||||
|
|
||||||
|
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_y", "INTEGER NOT NULL DEFAULT -1");
|
||||||
|
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_m", "INTEGER NOT NULL DEFAULT -1");
|
||||||
|
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_d", "INTEGER NOT NULL DEFAULT -1");
|
||||||
// convert sale_end_at(YYYYMMDD) to sale_end_at_y, sale_end_at_m, sale_end_at_d if sale_end_at column exists
|
// convert sale_end_at(YYYYMMDD) to sale_end_at_y, sale_end_at_m, sale_end_at_d if sale_end_at column exists
|
||||||
if (IsFieldExist("mplt_title_shop", "sale_end_at")) {
|
if (MiniPlayerTitle.database.isColumnExist("mplt_title_shop", "sale_end_at")) {
|
||||||
String sql = "UPDATE mplt_title_shop SET " +
|
sql = "UPDATE mplt_title_shop SET " +
|
||||||
"sale_end_at_y = (sale_end_at / 10000), " +
|
"sale_end_at_y = (sale_end_at / 10000), " +
|
||||||
"sale_end_at_m = (sale_end_at % 10000 / 100), " +
|
"sale_end_at_m = (sale_end_at % 10000 / 100), " +
|
||||||
"sale_end_at_d = (sale_end_at % 100) " +
|
"sale_end_at_d = (sale_end_at % 100) " +
|
||||||
"WHERE sale_end_at != -1;";
|
"WHERE sale_end_at != -1;";
|
||||||
DatabaseManager.instance.query(sql);
|
MiniPlayerTitle.database.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");
|
||||||
TableColumn mplt_player_title_expire_at_y = new TableColumn("expire_at_y", FieldType.INT, false, false, true, false, -1);
|
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_m", "INTEGER NOT NULL DEFAULT -1");
|
||||||
TableColumn mplt_player_title_expire_at_m = new TableColumn("expire_at_m", FieldType.INT, false, false, true, false, -1);
|
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_d", "INTEGER NOT NULL DEFAULT -1");
|
||||||
TableColumn mplt_player_title_expire_at_d = new TableColumn("expire_at_d", FieldType.INT, false, false, true, false, -1);
|
if (MiniPlayerTitle.database.isColumnExist("mplt_player_title", "expire_at")) {
|
||||||
new AddColumn(mplt_player_title_expire_at_y).table("mplt_player_title").ifNotExists().execute();
|
sql = "UPDATE mplt_player_title SET " +
|
||||||
new AddColumn(mplt_player_title_expire_at_m).table("mplt_player_title").ifNotExists().execute();
|
|
||||||
new AddColumn(mplt_player_title_expire_at_d).table("mplt_player_title").ifNotExists().execute();
|
|
||||||
|
|
||||||
if (IsFieldExist("mplt_player_title", "expire_at")) {
|
|
||||||
String sql = "UPDATE mplt_player_title SET " +
|
|
||||||
"expire_at_y = (expire_at / 10000), " +
|
"expire_at_y = (expire_at / 10000), " +
|
||||||
"expire_at_m = (expire_at % 10000 / 100), " +
|
"expire_at_m = (expire_at % 10000 / 100), " +
|
||||||
"expire_at_d = (expire_at % 100) " +
|
"expire_at_d = (expire_at % 100) " +
|
||||||
"WHERE expire_at != -1;";
|
"WHERE expire_at != -1;";
|
||||||
DatabaseManager.instance.query(sql);
|
MiniPlayerTitle.database.query(sql);
|
||||||
new RemoveColumn("expire_at").IfExists().table("mplt_player_title").execute();
|
|
||||||
}
|
}
|
||||||
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "expire_at");
|
||||||
|
|
||||||
Field mplt_title_id_field = new Field("id", -1);
|
sql = "INSERT INTO mplt_title (" +
|
||||||
Field mplt_title_title_field = new Field("title", "default");
|
"id, " +
|
||||||
Field mplt_title_description_field = new Field("description", "default");
|
"title, " +
|
||||||
InsertRow mplt_title_default = new InsertRow().table("mplt_title");
|
"description " +
|
||||||
mplt_title_default.field(mplt_title_id_field)
|
") VALUES (" +
|
||||||
.field(mplt_title_title_field)
|
"-1, " +
|
||||||
.field(mplt_title_description_field).onConflictDoNothing(mplt_title_id_field);
|
"'default', " +
|
||||||
mplt_title_default.execute();
|
"'default' " +
|
||||||
|
") ON CONFLICT (id) DO NOTHING;";
|
||||||
|
MiniPlayerTitle.database.query(sql);
|
||||||
|
|
||||||
|
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_info", "last_use_name", "TEXT NOT NULL DEFAULT 'null'");
|
||||||
TableColumn mplt_player_info_last_use_name = new TableColumn("last_use_name", FieldType.STRING, false, false, true, false, "'null'");
|
|
||||||
new AddColumn(mplt_player_info_last_use_name).table("mplt_player_info").ifNotExists().execute();
|
|
||||||
|
|
||||||
// 3.0.6
|
// 3.0.6
|
||||||
TableColumn mplt_player_info_coin_d = new TableColumn("coin_d", FieldType.DOUBLE, false, false, true, false, 0);
|
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_info", "coin_d", "DOUBLE PRECISION NOT NULL DEFAULT 0");
|
||||||
TableColumn mplt_title_shop_price_d = new TableColumn("price_d", FieldType.DOUBLE, false, false, true, false, 0);
|
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "price_d", "DOUBLE PRECISION NOT NULL DEFAULT 0");
|
||||||
new AddColumn(mplt_player_info_coin_d).table("mplt_player_info").ifNotExists().execute();
|
if (MiniPlayerTitle.database.isColumnExist("mplt_player_info", "coin")) {
|
||||||
new AddColumn(mplt_title_shop_price_d).table("mplt_title_shop").ifNotExists().execute();
|
sql = "UPDATE mplt_player_info SET coin_d = coin;";
|
||||||
if (IsFieldExist("mplt_player_info", "coin")) {
|
MiniPlayerTitle.database.query(sql);
|
||||||
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")) {
|
if (MiniPlayerTitle.database.isColumnExist("mplt_title_shop", "price")) {
|
||||||
String sql = "UPDATE mplt_title_shop SET price_d = price;";
|
sql = "UPDATE mplt_title_shop SET price_d = price;";
|
||||||
DatabaseManager.instance.query(sql);
|
MiniPlayerTitle.database.query(sql);
|
||||||
new RemoveColumn("price").IfExists().table("mplt_title_shop").execute();
|
|
||||||
}
|
}
|
||||||
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "coin");
|
||||||
|
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "price");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,20 +5,9 @@ api-version: '1.20'
|
|||||||
description: 称号插件。
|
description: 称号插件。
|
||||||
website: https://lunadeer.cn
|
website: https://lunadeer.cn
|
||||||
folia-supported: true
|
folia-supported: true
|
||||||
softdepend: [ PlaceholderAPI, Vault ]
|
softdepend: [PlaceholderAPI, Vault]
|
||||||
commands:
|
commands:
|
||||||
MiniPlayerTitle:
|
MiniPlayerTitle:
|
||||||
description: 称号插件命令
|
description: 称号插件命令
|
||||||
usage: /mplt <cmd>
|
usage: /mplt <cmd>
|
||||||
aliases: [ mplt ]
|
aliases: [mplt]
|
||||||
permission: mplt.command
|
|
||||||
permissions:
|
|
||||||
mplt.command:
|
|
||||||
description: 普通命令
|
|
||||||
default: true
|
|
||||||
mplt.custom:
|
|
||||||
description: 是否可以自定义称号
|
|
||||||
default: true
|
|
||||||
mplt.admin:
|
|
||||||
description: 是否可以使用管理员命令
|
|
||||||
default: op
|
|
||||||
|
Loading…
Reference in New Issue
Block a user