Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
40e561bff1 | |||
11856a29a6 | |||
78de7dca65 | |||
466dd84fac | |||
283e435b70 | |||
2981ac0183 | |||
02d44610c6 | |||
31a1d409b7 | |||
9de1b5cced | |||
d629b1daf7 | |||
b52fce2479 | |||
3ffab50c9b | |||
a007966d70 |
@ -1,4 +1,4 @@
|
|||||||
<div style="text-align: center;">
|
<div align="center">
|
||||||
|
|
||||||
<img src="https://ssl.lunadeer.cn:14437/i/2024/03/28/6604de7db2e6f.png" alt="" width="70%">
|
<img src="https://ssl.lunadeer.cn:14437/i/2024/03/28/6604de7db2e6f.png" alt="" width="70%">
|
||||||
|
|
||||||
|
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.2.6</version>
|
<version>4.7.1</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.2-SNAPSHOT</version>
|
<version>1.3.7-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.lunadeer.miniplayertitle;
|
package cn.lunadeer.miniplayertitle;
|
||||||
|
|
||||||
import cn.lunadeer.miniplayertitle.commands.PlayerManage;
|
import cn.lunadeer.miniplayertitle.commands.PlayerManage;
|
||||||
|
import cn.lunadeer.miniplayertitle.commands.TitleCard;
|
||||||
import cn.lunadeer.miniplayertitle.commands.TitleManage;
|
import cn.lunadeer.miniplayertitle.commands.TitleManage;
|
||||||
import cn.lunadeer.miniplayertitle.commands.TitleShopSale;
|
import cn.lunadeer.miniplayertitle.commands.TitleShopSale;
|
||||||
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||||
@ -81,6 +82,9 @@ 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;
|
||||||
}
|
}
|
||||||
@ -93,7 +97,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"
|
"grant_title", "get_card"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
@ -101,6 +105,7 @@ 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,8 +1,6 @@
|
|||||||
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;
|
||||||
@ -32,20 +30,11 @@ 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")) {
|
||||||
PlayerInfoDTO player = PlayerInfoDTO.get(bukkitPlayer);
|
TitleDTO t = MiniPlayerTitle.instance.getPlayerUsingTitle(bukkitPlayer.getUniqueId());
|
||||||
if (player == null) {
|
if (t == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
if (player.getUsingTitle().getId() == -1) {
|
return t.getTitleColoredBukkit();
|
||||||
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; //
|
||||||
@ -63,6 +52,6 @@ public class Expansion extends PlaceholderExpansion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getVersion() {
|
public @NotNull String getVersion() {
|
||||||
return plugin.getPluginMeta().getVersion();
|
return MiniPlayerTitle.instance.getDescription().getVersion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,23 @@
|
|||||||
package cn.lunadeer.miniplayertitle;
|
package cn.lunadeer.miniplayertitle;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.*;
|
import cn.lunadeer.minecraftpluginutils.*;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.DatabaseType;
|
||||||
|
import cn.lunadeer.miniplayertitle.commands.TitleCard;
|
||||||
|
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
||||||
|
import cn.lunadeer.miniplayertitle.events.Events;
|
||||||
|
import cn.lunadeer.miniplayertitle.events.PaperChat;
|
||||||
|
import cn.lunadeer.miniplayertitle.events.SpigotChat;
|
||||||
import cn.lunadeer.miniplayertitle.utils.ConfigManager;
|
import cn.lunadeer.miniplayertitle.utils.ConfigManager;
|
||||||
import cn.lunadeer.miniplayertitle.utils.DatabaseTables;
|
import cn.lunadeer.miniplayertitle.utils.DatabaseTables;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class MiniPlayerTitle extends JavaPlugin {
|
public final class MiniPlayerTitle extends JavaPlugin {
|
||||||
|
|
||||||
@ -19,8 +30,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());
|
||||||
database = new DatabaseManager(this,
|
new DatabaseManager(this,
|
||||||
DatabaseManager.TYPE.valueOf(config.getDbType().toUpperCase()),
|
DatabaseType.valueOf(config.getDbType().toUpperCase()),
|
||||||
config.getDbHost(),
|
config.getDbHost(),
|
||||||
config.getDbPort(),
|
config.getDbPort(),
|
||||||
config.getDbName(),
|
config.getDbName(),
|
||||||
@ -37,6 +48,12 @@ 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());
|
||||||
|
|
||||||
@ -49,7 +66,7 @@ public final class MiniPlayerTitle extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
XLogger.info("称号插件已加载");
|
XLogger.info("称号插件已加载");
|
||||||
XLogger.info("版本: " + getPluginMeta().getVersion());
|
XLogger.info("版本: " + this.getDescription().getVersion());
|
||||||
// http://patorjk.com/software/taag/#p=display&f=Big&t=MiniPlayerTitle
|
// http://patorjk.com/software/taag/#p=display&f=Big&t=MiniPlayerTitle
|
||||||
XLogger.info(" __ __ _ _ _____ _ _______ _ _ _");
|
XLogger.info(" __ __ _ _ _____ _ _______ _ _ _");
|
||||||
XLogger.info(" | \\/ (_) (_) __ \\| | |__ __(_) | | |");
|
XLogger.info(" | \\/ (_) (_) __ \\| | |__ __(_) | | |");
|
||||||
@ -64,15 +81,23 @@ public final class MiniPlayerTitle extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Plugin shutdown logic
|
// Plugin shutdown logic
|
||||||
database.close();
|
DatabaseManager.instance.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,9 +1,10 @@
|
|||||||
package cn.lunadeer.miniplayertitle.commands;
|
package cn.lunadeer.miniplayertitle.commands;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
import cn.lunadeer.minecraftpluginutils.Common;
|
||||||
|
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||||
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -12,34 +13,22 @@ 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 newDisplayName = Component.text()
|
Component titleComponent = Component.text("");
|
||||||
.append(Component.text("<"))
|
String titleBukkit = "";
|
||||||
.append(player.name())
|
|
||||||
.append(Component.text("> ")).build();
|
if (title != null && title.getId() != -1) {
|
||||||
Component newListName = Component.text()
|
titleComponent = title.getTitleColored();
|
||||||
.append(player.name()).build();
|
titleBukkit = ChatColor.translateAlternateColorCodes('&', title.getTitleColoredBukkit());
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newListName);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Component titleComponent = title.getTitleColored();
|
if (Common.isPaper()) {
|
||||||
Component newDisplayName = Component.text()
|
Component newDisplayName = Component.text()
|
||||||
.append(titleComponent)
|
.append(titleComponent)
|
||||||
.append(Component.text("<"))
|
.append(Component.text("<"))
|
||||||
@ -51,5 +40,9 @@ public class Apis {
|
|||||||
.append(player.name()).build();
|
.append(player.name()).build();
|
||||||
player.displayName(newDisplayName);
|
player.displayName(newDisplayName);
|
||||||
player.playerListName(newListName);
|
player.playerListName(newListName);
|
||||||
|
} else {
|
||||||
|
player.setDisplayName(titleBukkit + "<" + player.getName() + ">");
|
||||||
|
player.setPlayerListName(titleBukkit + " " + player.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ 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 {
|
||||||
|
|
||||||
@ -20,7 +19,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 (notOpOrConsole(sender)) return;
|
if (!sender.hasPermission("mplt.admin")) return;
|
||||||
try {
|
try {
|
||||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
||||||
if (playerInfo == null) {
|
if (playerInfo == null) {
|
||||||
@ -46,7 +45,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 (notOpOrConsole(sender)) return;
|
if (!sender.hasPermission("mplt.admin")) return;
|
||||||
try {
|
try {
|
||||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
||||||
if (playerInfo == null) {
|
if (playerInfo == null) {
|
||||||
@ -72,7 +71,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 (notOpOrConsole(sender)) return;
|
if (!sender.hasPermission("mplt.admin")) return;
|
||||||
try {
|
try {
|
||||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
|
||||||
if (playerInfo == null) {
|
if (playerInfo == null) {
|
||||||
|
@ -0,0 +1,135 @@
|
|||||||
|
package cn.lunadeer.miniplayertitle.commands;
|
||||||
|
|
||||||
|
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||||
|
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
|
||||||
|
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
||||||
|
import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class TitleCard implements Listener {
|
||||||
|
|
||||||
|
public static void getTitleCard(CommandSender sender, String[] args) {
|
||||||
|
try {
|
||||||
|
if (!sender.hasPermission("mplt.admin")) return;
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
Notification.error(sender, "该命令只能由玩家执行");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.length != 2) {
|
||||||
|
Notification.warn(sender, "用法: /mplt get_card <销售ID>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int saleId = Integer.parseInt(args[1]);
|
||||||
|
TitleShopDTO titleShop = TitleShopDTO.get(saleId);
|
||||||
|
if (titleShop == null) {
|
||||||
|
Notification.error(sender, "获取销售详情时出现错误");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (titleShop.getDays() == 0) {
|
||||||
|
Notification.error(sender, "不可以生成天数为0的称号卡!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemStack card = TitleCard.create(titleShop);
|
||||||
|
Player player = (Player) sender;
|
||||||
|
player.getInventory().addItem(card);
|
||||||
|
Notification.info(player, "成功创建称号卡");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Notification.error(sender, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void useTitleCard(PlayerInteractEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.getInventory().getItemInMainHand().getType() != Material.NAME_TAG) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemStack item = player.getInventory().getItemInMainHand();
|
||||||
|
if (item.getItemMeta() == null || item.getItemMeta().getLore() == null || item.getItemMeta().getLore().size() != 5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
use(player, item);
|
||||||
|
player.getInventory().removeItem(item);
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack create(@NotNull TitleShopDTO saleInfo) {
|
||||||
|
ItemStack card = new ItemStack(Material.NAME_TAG);
|
||||||
|
TitleDTO title = saleInfo.getTitle();
|
||||||
|
card.editMeta(meta -> {
|
||||||
|
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', title.getTitleColoredBukkit()));
|
||||||
|
meta.setLore(
|
||||||
|
Arrays.asList(
|
||||||
|
"称号ID: " + title.getId(),
|
||||||
|
"使用后获得天数: " + (saleInfo.getDays() == -1 ? "永久" : saleInfo.getDays()),
|
||||||
|
"称号描述: " + title.getDescription(),
|
||||||
|
"",
|
||||||
|
ChatColor.GRAY + "【右键使用】"
|
||||||
|
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void use(@NotNull Player player, @NotNull ItemStack item) {
|
||||||
|
try {
|
||||||
|
if (item.getType() != Material.NAME_TAG) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> lore = item.getLore();
|
||||||
|
if (lore == null || lore.size() != 5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int titleId = Integer.parseInt(lore.get(0).split(": ")[1]);
|
||||||
|
int day = lore.get(1).split(": ")[1].equals("永久") ? -1 : Integer.parseInt(lore.get(1).split(": ")[1]);
|
||||||
|
|
||||||
|
List<PlayerTitleDTO> playerTitles = PlayerTitleDTO.getAllOf(player.getUniqueId());
|
||||||
|
PlayerTitleDTO had = null;
|
||||||
|
for (PlayerTitleDTO playerTitle : playerTitles) {
|
||||||
|
if (Objects.equals(playerTitle.getTitle().getId(), titleId)) {
|
||||||
|
had = playerTitle;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TitleDTO title = TitleDTO.get(titleId);
|
||||||
|
if (title == null) {
|
||||||
|
Notification.error(player, "称号不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (had == null) {
|
||||||
|
had = PlayerTitleDTO.create(player.getUniqueId(), title, day == -1 ? null : LocalDateTime.now().plusDays(day));
|
||||||
|
if (had == null) {
|
||||||
|
Notification.error(player, "购买称号时出现错误,详情请查看控制台日志");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Notification.info(player, Component.text("成功使用称号卡: ").append(had.getTitle().getTitleColored()));
|
||||||
|
} else if (!had.isExpired()) {
|
||||||
|
Notification.warn(player, "你已拥有此称号,在过期前无法使用称号卡");
|
||||||
|
} else {
|
||||||
|
had.setExpireAt(day == -1 ? null : LocalDateTime.now().plusDays(day));
|
||||||
|
Notification.info(player, Component.text("成功续续期称号: ").append(had.getTitle().getTitleColored()));
|
||||||
|
}
|
||||||
|
TitleManage.useTitle(player, new String[]{"use_title", String.valueOf(had.getId())});
|
||||||
|
} catch (Exception e) {
|
||||||
|
Notification.error(player, "使用称号卡时出现错误: %s", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -11,7 +11,6 @@ import net.kyori.adventure.text.Component;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import 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 {
|
||||||
@ -23,7 +22,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 (notOpOrConsole(sender)) return;
|
if (!sender.hasPermission("mplt.admin")) return;
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
Notification.warn(sender, "用法: /mplt create_title <称号名称> [称号描述]");
|
Notification.warn(sender, "用法: /mplt create_title <称号名称> [称号描述]");
|
||||||
return;
|
return;
|
||||||
@ -46,7 +45,7 @@ public class TitleManage {
|
|||||||
*/
|
*/
|
||||||
public static void deleteTitle(CommandSender sender, String[] args) {
|
public static void deleteTitle(CommandSender sender, String[] args) {
|
||||||
try {
|
try {
|
||||||
if (notOpOrConsole(sender)) return;
|
if (!sender.hasPermission("mplt.admin")) return;
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
Notification.warn(sender, "用法: /mplt delete_title <称号ID>");
|
Notification.warn(sender, "用法: /mplt delete_title <称号ID>");
|
||||||
return;
|
return;
|
||||||
@ -80,7 +79,7 @@ public class TitleManage {
|
|||||||
*/
|
*/
|
||||||
public static void editTitleName(CommandSender sender, String[] args) {
|
public static void editTitleName(CommandSender sender, String[] args) {
|
||||||
try {
|
try {
|
||||||
if (notOpOrConsole(sender)) return;
|
if (!sender.hasPermission("mplt.admin")) return;
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
Notification.warn(sender, "用法: /mplt set_title <称号ID> <称号名称>");
|
Notification.warn(sender, "用法: /mplt set_title <称号ID> <称号名称>");
|
||||||
return;
|
return;
|
||||||
@ -110,7 +109,7 @@ public class TitleManage {
|
|||||||
*/
|
*/
|
||||||
public static void editTitleDescription(CommandSender sender, String[] args) {
|
public static void editTitleDescription(CommandSender sender, String[] args) {
|
||||||
try {
|
try {
|
||||||
if (notOpOrConsole(sender)) return;
|
if (!sender.hasPermission("mplt.admin")) return;
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
Notification.warn(sender, "用法: /mplt set_desc <称号ID> <称号描述>");
|
Notification.warn(sender, "用法: /mplt set_desc <称号ID> <称号描述>");
|
||||||
return;
|
return;
|
||||||
@ -143,6 +142,7 @@ 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,8 +158,7 @@ public class TitleManage {
|
|||||||
Notification.info(sender, "已卸下称号");
|
Notification.info(sender, "已卸下称号");
|
||||||
playerInfo.setUsingTitle(null);
|
playerInfo.setUsingTitle(null);
|
||||||
updateName(player, null);
|
updateName(player, null);
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
PlayerTitleDTO title = PlayerTitleDTO.get(id);
|
PlayerTitleDTO title = PlayerTitleDTO.get(id);
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
Notification.error(sender, "称号不存在");
|
Notification.error(sender, "称号不存在");
|
||||||
@ -182,6 +181,7 @@ public class TitleManage {
|
|||||||
} else {
|
} else {
|
||||||
Notification.error(sender, "使用称号失败,具体请查看控制台日志");
|
Notification.error(sender, "使用称号失败,具体请查看控制台日志");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
int page = Integer.parseInt(args[2]);
|
int page = Integer.parseInt(args[2]);
|
||||||
@ -201,6 +201,10 @@ 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,7 +16,6 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
|
|
||||||
import static cn.lunadeer.miniplayertitle.tuis.Apis.getArgPage;
|
import static cn.lunadeer.miniplayertitle.tuis.Apis.getArgPage;
|
||||||
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
|
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
|
||||||
|
|
||||||
@ -30,7 +29,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 (notOpOrConsole(sender)) return;
|
if (!sender.hasPermission("mplt.admin")) return;
|
||||||
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[2]));
|
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[2]));
|
||||||
if (titleShop == null) {
|
if (titleShop == null) {
|
||||||
Notification.error(sender, "获取详情时出现错误,详情请查看控制台日志");
|
Notification.error(sender, "获取详情时出现错误,详情请查看控制台日志");
|
||||||
@ -83,7 +82,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 (notOpOrConsole(sender)) return;
|
if (!sender.hasPermission("mplt.admin")) return;
|
||||||
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
|
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
Notification.error(sender, "获取称号详情时出现错误,详情请查看控制台日志");
|
Notification.error(sender, "获取称号详情时出现错误,详情请查看控制台日志");
|
||||||
@ -108,7 +107,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 (notOpOrConsole(sender)) return;
|
if (!sender.hasPermission("mplt.admin")) return;
|
||||||
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
|
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
|
||||||
if (titleShop == null) {
|
if (titleShop == null) {
|
||||||
Notification.error(sender, "获取详情时出现错误");
|
Notification.error(sender, "获取详情时出现错误");
|
||||||
@ -138,6 +137,7 @@ 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,6 +194,7 @@ 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,7 +1,10 @@
|
|||||||
package cn.lunadeer.miniplayertitle.dtos;
|
package cn.lunadeer.miniplayertitle.dtos;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.VaultConnect;
|
import cn.lunadeer.minecraftpluginutils.VaultConnect.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;
|
||||||
|
|
||||||
@ -12,20 +15,22 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
||||||
|
|
||||||
public class PlayerInfoDTO {
|
public class PlayerInfoDTO {
|
||||||
private UUID uuid;
|
private final Field uuid = new Field("uuid", FieldType.UUID);
|
||||||
private Double coin;
|
private final Field coin = new Field("coin_d", FieldType.DOUBLE);
|
||||||
private TitleDTO using_title;
|
private TitleDTO using_title;
|
||||||
private String last_use_name;
|
private final Field last_use_name = new Field("last_use_name", FieldType.STRING);
|
||||||
|
|
||||||
public static PlayerInfoDTO get(UUID uuid) {
|
public static PlayerInfoDTO get(UUID uuid) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql = "SELECT uuid, coin_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 = MiniPlayerTitle.database.query(sql, uuid)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, uuid)) {
|
||||||
if (rs.next()) return getPlayerInfoDTO(rs);
|
if (rs.next()) return getPlayerInfoDTO(rs);
|
||||||
else return null;
|
else return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("获取玩家信息失败", e, sql);
|
handleDatabaseError("获取玩家信息失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -51,11 +56,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 = MiniPlayerTitle.database.query(sql, name)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, name)) {
|
||||||
if (rs.next()) return getPlayerInfoDTO(rs);
|
if (rs.next()) return getPlayerInfoDTO(rs);
|
||||||
else return null;
|
else return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("获取玩家信息失败", e, sql);
|
handleDatabaseError("获取玩家信息失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -65,10 +70,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 = MiniPlayerTitle.database.query(sql, player.getUniqueId(), MiniPlayerTitle.config.getDefaultCoin(), player.getName())) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, player.getUniqueId(), MiniPlayerTitle.config.getDefaultCoin(), player.getName())) {
|
||||||
return get(player.getUniqueId());
|
return get(player.getUniqueId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("创建玩家信息失败", e, sql);
|
handleDatabaseError("创建玩家信息失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -76,29 +81,29 @@ public class PlayerInfoDTO {
|
|||||||
private static PlayerInfoDTO updateName(Player player) {
|
private static PlayerInfoDTO updateName(Player player) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql = "UPDATE mplt_player_info SET last_use_name = ? WHERE uuid = ?;";
|
sql = "UPDATE mplt_player_info SET last_use_name = ? WHERE uuid = ?;";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player.getName(), player.getUniqueId())) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, player.getName(), player.getUniqueId())) {
|
||||||
return get(player.getUniqueId());
|
return get(player.getUniqueId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("更新玩家名称失败", e, sql);
|
handleDatabaseError("更新玩家名称失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PlayerInfoDTO getPlayerInfoDTO(ResultSet rs) throws SQLException {
|
private static PlayerInfoDTO getPlayerInfoDTO(ResultSet rs) throws SQLException {
|
||||||
PlayerInfoDTO playerInfoDTO = new PlayerInfoDTO();
|
PlayerInfoDTO playerInfoDTO = new PlayerInfoDTO();
|
||||||
playerInfoDTO.uuid = UUID.fromString(rs.getString("uuid"));
|
playerInfoDTO.uuid.value = UUID.fromString(rs.getString("uuid"));
|
||||||
playerInfoDTO.coin = rs.getDouble("coin_d");
|
playerInfoDTO.coin.value = rs.getDouble("coin_d");
|
||||||
playerInfoDTO.using_title = TitleDTO.get(rs.getInt("using_title_id"));
|
playerInfoDTO.using_title = TitleDTO.get(rs.getInt("using_title_id"));
|
||||||
playerInfoDTO.last_use_name = rs.getString("last_use_name");
|
playerInfoDTO.last_use_name.value = rs.getString("last_use_name");
|
||||||
return playerInfoDTO;
|
return playerInfoDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getCoin() {
|
public Double getCoin() {
|
||||||
if (MiniPlayerTitle.config.isExternalEco()) {
|
if (MiniPlayerTitle.config.isExternalEco()) {
|
||||||
Player player = MiniPlayerTitle.instance.getServer().getPlayer(uuid);
|
Player player = MiniPlayerTitle.instance.getServer().getPlayer(getUuid());
|
||||||
return VaultConnect.instance.getBalance(player);
|
return VaultConnect.instance.getBalance(player);
|
||||||
}
|
}
|
||||||
return coin;
|
return (Double) coin.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TitleDTO getUsingTitle() {
|
public TitleDTO getUsingTitle() {
|
||||||
@ -106,37 +111,37 @@ public class PlayerInfoDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getLastUseName() {
|
public String getLastUseName() {
|
||||||
return last_use_name;
|
return (String) last_use_name.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUuid() {
|
public UUID getUuid() {
|
||||||
return uuid;
|
return (UUID) uuid.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setUsingTitle(@Nullable TitleDTO title) {
|
public boolean setUsingTitle(@Nullable TitleDTO title) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql = "UPDATE mplt_player_info SET using_title_id = ? WHERE uuid = ?;";
|
sql = "UPDATE mplt_player_info SET using_title_id = ? WHERE uuid = ?;";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title == null ? -1 : title.getId(), uuid)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, title == null ? -1 : title.getId(), getUuid())) {
|
||||||
this.using_title = title == null ? TitleDTO.get(-1) : title;
|
this.using_title = title == null ? TitleDTO.get(-1) : title;
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("设置玩家使用称号失败", e, sql);
|
handleDatabaseError("设置玩家使用称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addCoin(double coin) {
|
public boolean addCoin(double coin) {
|
||||||
if (MiniPlayerTitle.config.isExternalEco()) {
|
if (MiniPlayerTitle.config.isExternalEco()) {
|
||||||
Player player = MiniPlayerTitle.instance.getServer().getPlayer(uuid);
|
Player player = MiniPlayerTitle.instance.getServer().getPlayer(getUuid());
|
||||||
VaultConnect.instance.depositPlayer(player, coin);
|
VaultConnect.instance.depositPlayer(player, coin);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return setCoin(this.coin + coin);
|
return setCoin(getCoin() + 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(uuid);
|
Player player = MiniPlayerTitle.instance.getServer().getPlayer(getUuid());
|
||||||
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);
|
||||||
@ -147,11 +152,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 = MiniPlayerTitle.database.query(sql, coin, uuid)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, coin, getUuid())) {
|
||||||
this.coin = coin;
|
this.coin.value = coin;
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("设置玩家金币失败", e, sql);
|
handleDatabaseError("设置玩家金币失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -160,12 +165,12 @@ public class PlayerInfoDTO {
|
|||||||
String sql = "";
|
String sql = "";
|
||||||
sql = "SELECT last_use_name FROM mplt_player_info;";
|
sql = "SELECT last_use_name FROM mplt_player_info;";
|
||||||
List<String> names = new ArrayList<>();
|
List<String> names = new ArrayList<>();
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
names.add(rs.getString("last_use_name"));
|
names.add(rs.getString("last_use_name"));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("获取玩家名称列表失败", e, sql);
|
handleDatabaseError("获取玩家名称列表失败", e, sql);
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package cn.lunadeer.miniplayertitle.dtos;
|
package cn.lunadeer.miniplayertitle.dtos;
|
||||||
|
|
||||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -10,14 +12,16 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
||||||
|
|
||||||
public class PlayerTitleDTO {
|
public class PlayerTitleDTO {
|
||||||
private Integer id;
|
private final Field id = new Field("id", FieldType.INT);
|
||||||
private UUID player_uuid;
|
private final Field player_uuid = new Field("player_uuid", FieldType.UUID);
|
||||||
private TitleDTO title;
|
private TitleDTO title;
|
||||||
private LocalDateTime expire_at;
|
private LocalDateTime expire_at;
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return (Integer) id.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TitleDTO getTitle() {
|
public TitleDTO getTitle() {
|
||||||
@ -25,7 +29,7 @@ public class PlayerTitleDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public UUID getPlayerUuid() {
|
public UUID getPlayerUuid() {
|
||||||
return player_uuid;
|
return (UUID) player_uuid.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getExpireAt() {
|
public LocalDateTime getExpireAt() {
|
||||||
@ -35,14 +39,14 @@ public class PlayerTitleDTO {
|
|||||||
public boolean setExpireAt(LocalDateTime dateTime) {
|
public boolean setExpireAt(LocalDateTime dateTime) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
if (dateTime == null) {
|
if (dateTime == null) {
|
||||||
sql += "UPDATE mplt_player_title SET expire_at_y = -1, expire_at_m = -1, expire_at_d = -1 WHERE id = " + id + ";";
|
sql += "UPDATE mplt_player_title SET expire_at_y = -1, expire_at_m = -1, expire_at_d = -1 WHERE id = " + getId() + ";";
|
||||||
} else {
|
} else {
|
||||||
sql += "UPDATE mplt_player_title SET expire_at_y = " + dateTime.getYear() + ", expire_at_m = " + dateTime.getMonthValue() + ", expire_at_d = " + dateTime.getDayOfMonth() + " WHERE id = " + id + ";";
|
sql += "UPDATE mplt_player_title SET expire_at_y = " + dateTime.getYear() + ", expire_at_m = " + dateTime.getMonthValue() + ", expire_at_d = " + dateTime.getDayOfMonth() + " WHERE id = " + getId() + ";";
|
||||||
}
|
}
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("设置玩家称号过期时间失败", e, sql);
|
handleDatabaseError("设置玩家称号过期时间失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -58,12 +62,12 @@ public class PlayerTitleDTO {
|
|||||||
}
|
}
|
||||||
sql += "RETURNING " +
|
sql += "RETURNING " +
|
||||||
"id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d;";
|
"id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d;";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player_uuid, title.getId())) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, player_uuid, title.getId())) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return getRs(rs);
|
return getRs(rs);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("创建玩家称号失败", e, sql);
|
handleDatabaseError("创建玩家称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -72,12 +76,12 @@ public class PlayerTitleDTO {
|
|||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
||||||
"WHERE id = ?;";
|
"WHERE id = ?;";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, id)) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return getRs(rs);
|
return getRs(rs);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("获取玩家称号失败", e, sql);
|
handleDatabaseError("获取玩家称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -86,20 +90,20 @@ public class PlayerTitleDTO {
|
|||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
||||||
"WHERE player_uuid = ? AND title_id = ?;";
|
"WHERE player_uuid = ? AND title_id = ?;";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player, title)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, player, title)) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return getRs(rs);
|
return getRs(rs);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("获取玩家称号失败", e, sql);
|
handleDatabaseError("获取玩家称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PlayerTitleDTO getRs(ResultSet rs) throws SQLException {
|
private static PlayerTitleDTO getRs(ResultSet rs) throws SQLException {
|
||||||
PlayerTitleDTO playerTitle = new PlayerTitleDTO();
|
PlayerTitleDTO playerTitle = new PlayerTitleDTO();
|
||||||
playerTitle.id = rs.getInt("id");
|
playerTitle.id.value = rs.getInt("id");
|
||||||
playerTitle.player_uuid = UUID.fromString(rs.getString("player_uuid"));
|
playerTitle.player_uuid.value = UUID.fromString(rs.getString("player_uuid"));
|
||||||
playerTitle.title = TitleDTO.get(rs.getInt("title_id"));
|
playerTitle.title = TitleDTO.get(rs.getInt("title_id"));
|
||||||
int y = rs.getInt("expire_at_y");
|
int y = rs.getInt("expire_at_y");
|
||||||
int m = rs.getInt("expire_at_m");
|
int m = rs.getInt("expire_at_m");
|
||||||
@ -117,12 +121,12 @@ public class PlayerTitleDTO {
|
|||||||
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
sql += "SELECT id, player_uuid, title_id, expire_at_y, expire_at_m, expire_at_d FROM mplt_player_title " +
|
||||||
"WHERE player_uuid = ?;";
|
"WHERE player_uuid = ?;";
|
||||||
List<PlayerTitleDTO> playerTitles = new ArrayList<>();
|
List<PlayerTitleDTO> playerTitles = new ArrayList<>();
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, player_uuid)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, player_uuid)) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
playerTitles.add(getRs(rs));
|
playerTitles.add(getRs(rs));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("获取玩家称号失败", e, sql);
|
handleDatabaseError("获取玩家称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return playerTitles;
|
return playerTitles;
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,32 @@
|
|||||||
package cn.lunadeer.miniplayertitle.dtos;
|
package cn.lunadeer.miniplayertitle.dtos;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.XLogger;
|
import cn.lunadeer.minecraftpluginutils.ColorParser;
|
||||||
import cn.lunadeer.miniplayertitle.Color;
|
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
|
||||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.event.HoverEvent;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
||||||
|
|
||||||
public class TitleDTO {
|
public class TitleDTO {
|
||||||
private int id;
|
private final Field id = new Field("id", FieldType.INT);
|
||||||
private String title;
|
private final Field title = new Field("title", FieldType.STRING);
|
||||||
private String description;
|
private final Field description = new Field("description", FieldType.STRING);
|
||||||
|
|
||||||
|
|
||||||
public static TitleDTO get(int id) {
|
public static TitleDTO get(int id) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "SELECT id, title, description FROM mplt_title WHERE id = " + id + ";";
|
sql += "SELECT id, title, description FROM mplt_title WHERE id = " + id + ";";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
||||||
if (rs.next()) return getTitleDTO(rs);
|
if (rs.next()) return getTitleDTO(rs);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("获取称号失败", e, sql);
|
handleDatabaseError("获取称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -36,10 +37,10 @@ public class TitleDTO {
|
|||||||
"VALUES (?, ?) " +
|
"VALUES (?, ?) " +
|
||||||
"RETURNING " +
|
"RETURNING " +
|
||||||
"id, title, description;";
|
"id, title, description;";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title, description)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, title, description)) {
|
||||||
if (rs.next()) return getTitleDTO(rs);
|
if (rs.next()) return getTitleDTO(rs);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("创建称号失败", e, sql);
|
handleDatabaseError("创建称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -49,12 +50,12 @@ public class TitleDTO {
|
|||||||
String deleteSql = "DELETE FROM mplt_title WHERE id = ?;";
|
String deleteSql = "DELETE FROM mplt_title WHERE id = ?;";
|
||||||
try {
|
try {
|
||||||
// 执行更新操作
|
// 执行更新操作
|
||||||
MiniPlayerTitle.database.query(updateSql, this.id);
|
DatabaseManager.instance.query(updateSql, getId());
|
||||||
// 执行删除操作
|
// 执行删除操作
|
||||||
MiniPlayerTitle.database.query(deleteSql, this.id);
|
DatabaseManager.instance.query(deleteSql, getId());
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("删除称号失败", e, updateSql + " " + deleteSql);
|
handleDatabaseError("删除称号失败", e, updateSql + " " + deleteSql);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,105 +64,59 @@ 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 = MiniPlayerTitle.database.query(sql)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
titleDTOs.add(getTitleDTO(rs));
|
titleDTOs.add(getTitleDTO(rs));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("获取称号列表失败", e, sql);
|
handleDatabaseError("获取称号列表失败", e, sql);
|
||||||
}
|
}
|
||||||
return titleDTOs;
|
return titleDTOs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextComponent getTitleColored() {
|
public TextComponent getTitleColored() {
|
||||||
TextComponent prefix = Component.text(MiniPlayerTitle.config.getPrefix(), new Color("#ffffff").getStyle());
|
String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
|
||||||
TextComponent suffix = Component.text(MiniPlayerTitle.config.getSuffix(), new Color("#ffffff").getStyle());
|
return ColorParser.getComponentType(with_pre_suf);
|
||||||
String[] parts = this.title.split("&#");
|
|
||||||
List<TextComponent> components = new ArrayList<>();
|
|
||||||
components.add(prefix);
|
|
||||||
for (String part : parts) {
|
|
||||||
if (part.isEmpty()) {
|
|
||||||
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)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取称号的颜色化字符串
|
* 获取称号的颜色化字符串
|
||||||
* 需要使用 translateAlternateColorCodes 方法对返回字符串进行处理
|
* 需要使用 ChatColor.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 title = "&f" + MiniPlayerTitle.config.getPrefix() + this.title + "&f" + MiniPlayerTitle.config.getSuffix();
|
String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
|
||||||
title = title.replaceAll("&#", "#");
|
return ColorParser.getBukkitType(with_pre_suf);
|
||||||
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() {
|
||||||
String[] parts = this.title.split("&#");
|
return ColorParser.getPlainText(getTitleRaw());
|
||||||
StringBuilder res = new StringBuilder();
|
|
||||||
for (String part : parts) {
|
|
||||||
if (part.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String content;
|
|
||||||
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) {
|
|
||||||
content = part.substring(6);
|
|
||||||
} else {
|
|
||||||
content = part;
|
|
||||||
}
|
|
||||||
res.append(content);
|
|
||||||
}
|
|
||||||
return res.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return this.id;
|
return (Integer) this.id.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return this.description;
|
return (String) this.description.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitleRaw() {
|
||||||
|
return (String) this.title.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateTitle(String title) {
|
public boolean updateTitle(String title) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "UPDATE mplt_title SET title = ? WHERE id = ?;";
|
sql += "UPDATE mplt_title SET title = ? WHERE id = ?;";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, title, this.id)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, title, getId())) {
|
||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
this.title = title;
|
this.title.value = title;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("更新称号失败", e, sql);
|
handleDatabaseError("更新称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -169,22 +124,22 @@ public class TitleDTO {
|
|||||||
public boolean updateDescription(String description) {
|
public boolean updateDescription(String description) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "UPDATE mplt_title SET description = ? WHERE id = ?;";
|
sql += "UPDATE mplt_title SET description = ? WHERE id = ?;";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, description, this.id)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, description, getId())) {
|
||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
this.description = description;
|
this.description.value = description;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("更新称号失败", e, sql);
|
handleDatabaseError("更新称号失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TitleDTO getTitleDTO(ResultSet rs) throws SQLException {
|
private static TitleDTO getTitleDTO(ResultSet rs) throws SQLException {
|
||||||
TitleDTO titleDTO = new TitleDTO();
|
TitleDTO titleDTO = new TitleDTO();
|
||||||
titleDTO.id = rs.getInt("id");
|
titleDTO.id.value = rs.getInt("id");
|
||||||
titleDTO.title = rs.getString("title");
|
titleDTO.title.value = rs.getString("title");
|
||||||
titleDTO.description = rs.getString("description");
|
titleDTO.description.value = rs.getString("description");
|
||||||
return titleDTO;
|
return titleDTO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,27 @@
|
|||||||
package cn.lunadeer.miniplayertitle.dtos;
|
package cn.lunadeer.miniplayertitle.dtos;
|
||||||
|
|
||||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
|
||||||
|
|
||||||
public class TitleShopDTO {
|
public class TitleShopDTO {
|
||||||
private Integer id;
|
|
||||||
private TitleDTO title;
|
private TitleDTO title;
|
||||||
private Double price;
|
private final Field id = new Field("id", FieldType.INT);
|
||||||
private Integer days;
|
private final Field price = new Field("price_d", FieldType.DOUBLE);
|
||||||
private Integer amount;
|
private final Field days = new Field("days", FieldType.INT);
|
||||||
|
private final Field amount = new Field("amount", FieldType.INT);
|
||||||
|
|
||||||
private LocalDateTime sale_end_at;
|
private LocalDateTime sale_end_at;
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return (Integer) id.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TitleDTO getTitle() {
|
public TitleDTO getTitle() {
|
||||||
@ -24,46 +29,49 @@ public class TitleShopDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Double getPrice() {
|
public Double getPrice() {
|
||||||
return price;
|
return (Double) price.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = MiniPlayerTitle.database.query(sql, price, id)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, price, getId())) {
|
||||||
|
this.price.value = price;
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("设置称号商店价格失败", e, sql);
|
handleDatabaseError("设置称号商店价格失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getDays() {
|
public Integer getDays() {
|
||||||
return days;
|
return (Integer) days.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setDays(int days) {
|
public boolean setDays(int days) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "UPDATE mplt_title_shop SET days = ? WHERE id = ?;";
|
sql += "UPDATE mplt_title_shop SET days = ? WHERE id = ?;";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, days, id)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, days, getId())) {
|
||||||
|
this.days.value = days;
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("设置称号商店天数失败", e, sql);
|
handleDatabaseError("设置称号商店天数失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getAmount() {
|
public Integer getAmount() {
|
||||||
return amount;
|
return (Integer) amount.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setAmount(int amount) {
|
public boolean setAmount(int amount) {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "UPDATE mplt_title_shop SET amount = ? WHERE id = ?;";
|
sql += "UPDATE mplt_title_shop SET amount = ? WHERE id = ?;";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, amount, id)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, amount, getId())) {
|
||||||
|
this.amount.value = amount;
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("设置称号商店数量失败", e, sql);
|
handleDatabaseError("设置称号商店数量失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -79,10 +87,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 = MiniPlayerTitle.database.query(sql, y, m, d, id)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, y, m, d, getId())) {
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("设置称号商店销售结束时间失败", e, sql);
|
handleDatabaseError("设置称号商店销售结束时间失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -91,12 +99,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 = MiniPlayerTitle.database.query(sql, id)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, id)) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return getTitleShop(rs);
|
return getTitleShop(rs);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("获取称号商店信息失败", e, sql);
|
handleDatabaseError("获取称号商店信息失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -106,24 +114,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 = MiniPlayerTitle.database.query(sql)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
|
||||||
while (rs != null && rs.next()) {
|
while (rs != null && rs.next()) {
|
||||||
TitleShopDTO titleShop = getTitleShop(rs);
|
TitleShopDTO titleShop = getTitleShop(rs);
|
||||||
titleShops.add(titleShop);
|
titleShops.add(titleShop);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("获取称号商店列表失败", e, sql);
|
handleDatabaseError("获取称号商店列表失败", e, sql);
|
||||||
}
|
}
|
||||||
return titleShops;
|
return titleShops;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TitleShopDTO getTitleShop(ResultSet rs) throws Exception {
|
private static TitleShopDTO getTitleShop(ResultSet rs) throws Exception {
|
||||||
TitleShopDTO titleShop = new TitleShopDTO();
|
TitleShopDTO titleShop = new TitleShopDTO();
|
||||||
titleShop.id = rs.getInt("id");
|
titleShop.id.value = rs.getInt("id");
|
||||||
titleShop.title = TitleDTO.get(rs.getInt("title_id"));
|
titleShop.title = TitleDTO.get(rs.getInt("title_id"));
|
||||||
titleShop.price = rs.getDouble("price_d");
|
titleShop.price.value = rs.getDouble("price_d");
|
||||||
titleShop.days = rs.getInt("days");
|
titleShop.days.value = rs.getInt("days");
|
||||||
titleShop.amount = rs.getInt("amount");
|
titleShop.amount.value = rs.getInt("amount");
|
||||||
int y = rs.getInt("sale_end_at_y");
|
int y = rs.getInt("sale_end_at_y");
|
||||||
int m = rs.getInt("sale_end_at_m");
|
int m = rs.getInt("sale_end_at_m");
|
||||||
int d = rs.getInt("sale_end_at_d");
|
int d = rs.getInt("sale_end_at_d");
|
||||||
@ -141,12 +149,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 = MiniPlayerTitle.database.query(sql, title.getId())) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, title.getId())) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return getTitleShop(rs);
|
return getTitleShop(rs);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("创建称号商店失败", e, sql);
|
handleDatabaseError("创建称号商店失败", e, sql);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -154,10 +162,10 @@ public class TitleShopDTO {
|
|||||||
public boolean delete() {
|
public boolean delete() {
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "DELETE FROM mplt_title_shop WHERE id = ?;";
|
sql += "DELETE FROM mplt_title_shop WHERE id = ?;";
|
||||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) {
|
try (ResultSet rs = DatabaseManager.instance.query(sql, getId())) {
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MiniPlayerTitle.database.handleDatabaseError("删除称号商店失败", e, sql);
|
handleDatabaseError("删除称号商店失败", e, sql);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
package cn.lunadeer.miniplayertitle;
|
package cn.lunadeer.miniplayertitle.events;
|
||||||
|
|
||||||
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 {
|
||||||
@ -36,19 +33,4 @@ 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package cn.lunadeer.miniplayertitle.events;
|
||||||
|
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
|
||||||
|
|
||||||
|
public class PaperChat implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerSendChat(AsyncChatEvent event) {
|
||||||
|
if (usingPapi()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Component nameComponent = event.getPlayer().displayName();
|
||||||
|
Component chatComponent = event.message();
|
||||||
|
Component newChatComponent = Component.text()
|
||||||
|
.append(nameComponent)
|
||||||
|
.append(Component.text(" "))
|
||||||
|
.append(chatComponent).build();
|
||||||
|
event.setCancelled(true);
|
||||||
|
event.getPlayer().getServer().sendMessage(newChatComponent);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package cn.lunadeer.miniplayertitle.events;
|
||||||
|
|
||||||
|
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
|
|
||||||
|
import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
|
||||||
|
|
||||||
|
public class SpigotChat implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerSendChat(PlayerChatEvent event) {
|
||||||
|
if (usingPapi()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
MiniPlayerTitle.instance.getServer().broadcastMessage(event.getPlayer().getDisplayName() + " " + event.getMessage());
|
||||||
|
}
|
||||||
|
}
|
@ -32,7 +32,7 @@ public class AllTitles {
|
|||||||
Line line = Line.create()
|
Line line = Line.create()
|
||||||
.append(title.getId().toString())
|
.append(title.getId().toString())
|
||||||
.append(title.getTitleColored());
|
.append(title.getTitleColored());
|
||||||
if (player.isOp()) {
|
if (player.hasPermission("mplt.admin")) {
|
||||||
line.append(Button.createRed("删除").setExecuteCommand("/mplt delete_title " + title.getId() + " " + page).build());
|
line.append(Button.createRed("删除").setExecuteCommand("/mplt delete_title " + title.getId() + " " + page).build());
|
||||||
line.append(Button.createGreen("创建商品").setExecuteCommand("/mplt create_sale " + title.getId()).build());
|
line.append(Button.createGreen("创建商品").setExecuteCommand("/mplt create_sale " + title.getId()).build());
|
||||||
}
|
}
|
||||||
|
@ -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;
|
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
|
||||||
import cn.lunadeer.minecraftpluginutils.stui.ListView;
|
import cn.lunadeer.minecraftpluginutils.stui.ListView;
|
||||||
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
|
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
|
||||||
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
|
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
|
||||||
@ -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.isOp()) {
|
if (player.hasPermission("mplt.admin")) {
|
||||||
view.add(Line.create().append(""));
|
view.add(Line.create().append(""));
|
||||||
view.add(Line.create().append("---以下选项仅OP可见---"));
|
view.add(Line.create().append("---以下选项仅OP可见---"));
|
||||||
view.add(all);
|
view.add(all);
|
||||||
|
@ -47,7 +47,7 @@ public class MyTitles {
|
|||||||
} else {
|
} else {
|
||||||
line.append("有效期至: " + title.getExpireAt().getYear() + "年" + title.getExpireAt().getMonthValue() + "月" + title.getExpireAt().getDayOfMonth() + "日");
|
line.append("有效期至: " + title.getExpireAt().getYear() + "年" + title.getExpireAt().getMonthValue() + "月" + title.getExpireAt().getDayOfMonth() + "日");
|
||||||
}
|
}
|
||||||
if (Objects.equals(playerInfo.getUsingTitle().getId(), title.getId())) {
|
if (Objects.equals(playerInfo.getUsingTitle().getId(), title.getTitle().getId())) {
|
||||||
line.append(Button.createRed("卸下").setExecuteCommand("/mplt use_title -1 " + page).build());
|
line.append(Button.createRed("卸下").setExecuteCommand("/mplt use_title -1 " + page).build());
|
||||||
} else {
|
} else {
|
||||||
line.append(Button.createGreen("使用").setExecuteCommand("/mplt use_title " + title.getId() + " " + page).build());
|
line.append(Button.createGreen("使用").setExecuteCommand("/mplt use_title " + title.getId() + " " + page).build());
|
||||||
|
@ -46,11 +46,11 @@ public class SaleInfo {
|
|||||||
Line price = Line.create().append("价格: ");
|
Line price = Line.create().append("价格: ");
|
||||||
if (titleShop.getPrice() <= 0) {
|
if (titleShop.getPrice() <= 0) {
|
||||||
price.append("免费");
|
price.append("免费");
|
||||||
if (player.isOp()) {
|
if (player.hasPermission("mplt.admin")) {
|
||||||
price.append(Button.create("设置价格").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 100 " + page).build());
|
price.append(Button.create("设置价格").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 100 " + page).build());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (player.isOp()) {
|
if (player.hasPermission("mplt.admin")) {
|
||||||
price.append(NumChanger.create(titleShop.getPrice(), "/mplt set_sale price " + titleShop.getId()).setPageNumber(page).build());
|
price.append(NumChanger.create(titleShop.getPrice(), "/mplt set_sale price " + titleShop.getId()).setPageNumber(page).build());
|
||||||
price.append(Button.create("设置为免费").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 0 " + page).build());
|
price.append(Button.create("设置为免费").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 0 " + page).build());
|
||||||
} else {
|
} else {
|
||||||
@ -62,11 +62,11 @@ public class SaleInfo {
|
|||||||
Line day = Line.create().append("购买天数: ");
|
Line day = Line.create().append("购买天数: ");
|
||||||
if (titleShop.getDays() <= 0) {
|
if (titleShop.getDays() <= 0) {
|
||||||
day.append("永久");
|
day.append("永久");
|
||||||
if (player.isOp()) {
|
if (player.hasPermission("mplt.admin")) {
|
||||||
day.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " 7 " + page).build());
|
day.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " 7 " + page).build());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (player.isOp()) {
|
if (player.hasPermission("mplt.admin")) {
|
||||||
day.append(NumChanger.create(titleShop.getDays(), "/mplt set_sale days " + titleShop.getId()).setPageNumber(page).build());
|
day.append(NumChanger.create(titleShop.getDays(), "/mplt set_sale days " + titleShop.getId()).setPageNumber(page).build());
|
||||||
day.append(Button.create("转为永久").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " -1 " + page).build());
|
day.append(Button.create("转为永久").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " -1 " + page).build());
|
||||||
} else {
|
} else {
|
||||||
@ -78,12 +78,12 @@ public class SaleInfo {
|
|||||||
Line amount = Line.create().append("剩余数量: ");
|
Line amount = Line.create().append("剩余数量: ");
|
||||||
if (titleShop.getAmount() == -1) {
|
if (titleShop.getAmount() == -1) {
|
||||||
amount.append("无限");
|
amount.append("无限");
|
||||||
if (player.isOp()) {
|
if (player.hasPermission("mplt.admin")) {
|
||||||
amount.append(Button.create("转为限量").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " 0 " + page).build());
|
amount.append(Button.create("转为限量").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " 0 " + page).build());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (player.isOp()) {
|
if (player.hasPermission("mplt.admin")) {
|
||||||
amount.append(NumChanger.create(titleShop.getAmount(), "/mplt set_sale amount " + titleShop.getId()).setPageNumber(page).build());
|
amount.append(NumChanger.create(titleShop.getAmount(), "/mplt set_sale amount " + titleShop.getId()).setPageNumber(page).build());
|
||||||
amount.append(Button.create("转为无限").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " -1 " + page).build());
|
amount.append(Button.create("转为无限").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " -1 " + page).build());
|
||||||
} else {
|
} else {
|
||||||
@ -95,11 +95,11 @@ public class SaleInfo {
|
|||||||
Line end_at = Line.create().append("售卖结束时间: ");
|
Line end_at = Line.create().append("售卖结束时间: ");
|
||||||
if (titleShop.getSaleEndAt() == null) {
|
if (titleShop.getSaleEndAt() == null) {
|
||||||
end_at.append("常驻");
|
end_at.append("常驻");
|
||||||
if (player.isOp()) {
|
if (player.hasPermission("mplt.admin")) {
|
||||||
end_at.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale end_at " + titleShop.getId() + " " + now_year + ":" + now_month + ":" + now_day + " " + page).build());
|
end_at.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale end_at " + titleShop.getId() + " " + now_year + ":" + now_month + ":" + now_day + " " + page).build());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (player.isOp()) {
|
if (player.hasPermission("mplt.admin")) {
|
||||||
end_at.append(Button.create("<<").setPreSufIx("", "").setHoverText("提前10天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 10 " + page).build()
|
end_at.append(Button.create("<<").setPreSufIx("", "").setHoverText("提前10天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 10 " + page).build()
|
||||||
.append(Button.create("-").setPreSufIx("", "").setHoverText("提前1天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 1 " + page).build())
|
.append(Button.create("-").setPreSufIx("", "").setHoverText("提前1天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 1 " + page).build())
|
||||||
.append(Component.text(titleShop.getSaleEndAt().getYear() + "年" + titleShop.getSaleEndAt().getMonthValue() + "月" + titleShop.getSaleEndAt().getDayOfMonth() + "日"))
|
.append(Component.text(titleShop.getSaleEndAt().getYear() + "年" + titleShop.getSaleEndAt().getMonthValue() + "月" + titleShop.getSaleEndAt().getDayOfMonth() + "日"))
|
||||||
@ -120,8 +120,9 @@ public class SaleInfo {
|
|||||||
} else {
|
} else {
|
||||||
operate.append(Button.createGreen("购买").setExecuteCommand("/mplt buy_sale " + titleShop.getId()).build());
|
operate.append(Button.createGreen("购买").setExecuteCommand("/mplt buy_sale " + titleShop.getId()).build());
|
||||||
}
|
}
|
||||||
if (player.isOp()) {
|
if (player.hasPermission("mplt.admin")) {
|
||||||
operate.append(Button.create("删除").setExecuteCommand("/mplt delete_sale " + args[1] + " b").build());
|
operate.append(Button.create("删除").setExecuteCommand("/mplt delete_sale " + args[1] + " b").build());
|
||||||
|
operate.append(Button.createGreen("导出称号卡").setExecuteCommand("/mplt get_card " + args[1]).build());
|
||||||
}
|
}
|
||||||
view.add(Line.create().append("---------------------"));
|
view.add(Line.create().append("---------------------"));
|
||||||
view.add(operate);
|
view.add(operate);
|
||||||
|
@ -1,126 +1,172 @@
|
|||||||
package cn.lunadeer.miniplayertitle.utils;
|
package cn.lunadeer.miniplayertitle.utils;
|
||||||
|
|
||||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.TableColumn;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.syntax.AddColumn;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.syntax.CreateTable;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.syntax.RemoveColumn;
|
||||||
|
|
||||||
|
import static cn.lunadeer.minecraftpluginutils.databse.Common.IsFieldExist;
|
||||||
|
|
||||||
public class DatabaseTables {
|
public class DatabaseTables {
|
||||||
|
|
||||||
public static void migrate() {
|
public static void migrate() {
|
||||||
String sql = "";
|
|
||||||
|
|
||||||
// title table
|
// title table
|
||||||
sql = "CREATE TABLE IF NOT EXISTS mplt_title (" +
|
TableColumn mplt_title_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
|
||||||
" id SERIAL PRIMARY KEY," +
|
TableColumn mplt_title_title = new TableColumn("title", FieldType.STRING, false, false, true, false, "'unknown'");
|
||||||
" title TEXT NOT NULL UNIQUE," +
|
TableColumn mplt_title_description = new TableColumn("description", FieldType.STRING, false, false, true, false, "'unknown'");
|
||||||
" description TEXT NOT NULL," +
|
TableColumn mplt_title_enabled = new TableColumn("enabled", FieldType.BOOLEAN, false, false, true, false, "true");
|
||||||
" enabled BOOLEAN NOT NULL DEFAULT TRUE," +
|
TableColumn mplt_title_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||||
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
TableColumn mplt_title_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||||
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP" +
|
CreateTable mplt_title = new CreateTable().ifNotExists();
|
||||||
");";
|
mplt_title.table("mplt_title")
|
||||||
MiniPlayerTitle.database.query(sql);
|
.field(mplt_title_id)
|
||||||
|
.field(mplt_title_title)
|
||||||
|
.field(mplt_title_description)
|
||||||
|
.field(mplt_title_enabled)
|
||||||
|
.field(mplt_title_created_at)
|
||||||
|
.field(mplt_title_updated_at);
|
||||||
|
mplt_title.execute();
|
||||||
|
|
||||||
|
|
||||||
// title shop table
|
// title shop table
|
||||||
sql = "CREATE TABLE IF NOT EXISTS mplt_title_shop (" +
|
TableColumn mplt_title_shop_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
|
||||||
" id SERIAL PRIMARY KEY," +
|
TableColumn mplt_title_shop_title_id = new TableColumn("title_id", FieldType.INT, false, false, true, false, 0);
|
||||||
" title_id INTEGER NOT NULL," +
|
TableColumn mplt_title_shop_price = new TableColumn("price", FieldType.INT, false, false, true, false, 0);
|
||||||
" price INTEGER NOT NULL DEFAULT 0," +
|
TableColumn mplt_title_shop_days = new TableColumn("days", FieldType.INT, false, false, true, false, 0);
|
||||||
" days INTEGER NOT NULL DEFAULT 0," +
|
TableColumn mplt_title_shop_amount = new TableColumn("amount", FieldType.INT, false, false, true, false, -1);
|
||||||
" amount INTEGER NOT NULL DEFAULT -1," +
|
TableColumn mplt_title_shop_sale_end_at = new TableColumn("sale_end_at", FieldType.LONG, false, false, true, false, -1);
|
||||||
" sale_end_at BIGINT NOT NULL DEFAULT -1," +
|
TableColumn mplt_title_shop_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||||
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
TableColumn mplt_title_shop_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||||
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
CreateTable.ForeignKey mplt_title_shop_title_id_fk = new CreateTable.ForeignKey(mplt_title_shop_title_id, "mplt_title", mplt_title_id, true);
|
||||||
" FOREIGN KEY (title_id) REFERENCES mplt_title(id) ON DELETE CASCADE" +
|
CreateTable mplt_title_shop = new CreateTable().ifNotExists();
|
||||||
");";
|
mplt_title_shop.table("mplt_title_shop")
|
||||||
MiniPlayerTitle.database.query(sql);
|
.field(mplt_title_shop_id)
|
||||||
|
.field(mplt_title_shop_title_id)
|
||||||
|
.field(mplt_title_shop_price)
|
||||||
|
.field(mplt_title_shop_days)
|
||||||
|
.field(mplt_title_shop_amount)
|
||||||
|
.field(mplt_title_shop_sale_end_at)
|
||||||
|
.field(mplt_title_shop_created_at)
|
||||||
|
.field(mplt_title_shop_updated_at)
|
||||||
|
.foreignKey(mplt_title_shop_title_id_fk);
|
||||||
|
mplt_title_shop.execute();
|
||||||
|
|
||||||
// player title info table
|
// player title info table
|
||||||
sql = "CREATE TABLE IF NOT EXISTS mplt_player_info (" +
|
TableColumn mplt_player_info_uuid = new TableColumn("uuid", FieldType.UUID, true, false, true, false, "'00000000-0000-0000-0000-000000000000'");
|
||||||
" uuid UUID PRIMARY KEY," +
|
TableColumn mplt_player_info_coin = new TableColumn("coin", FieldType.INT, false, false, true, false, 0);
|
||||||
" coin INTEGER NOT NULL DEFAULT 0," +
|
TableColumn mplt_player_info_using_title_id = new TableColumn("using_title_id", FieldType.INT, false, false, true, false, -1);
|
||||||
" using_title_id INTEGER NOT NULL DEFAULT -1," +
|
TableColumn mplt_player_info_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||||
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
TableColumn mplt_player_info_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||||
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
CreateTable.ForeignKey mplt_player_info_using_title_id_fk = new CreateTable.ForeignKey(mplt_player_info_using_title_id, "mplt_title", mplt_title_id, true);
|
||||||
" FOREIGN KEY (using_title_id) REFERENCES mplt_title(id) ON DELETE CASCADE" +
|
CreateTable mplt_player_info = new CreateTable().ifNotExists();
|
||||||
");";
|
mplt_player_info.table("mplt_player_info")
|
||||||
MiniPlayerTitle.database.query(sql);
|
.field(mplt_player_info_uuid)
|
||||||
|
.field(mplt_player_info_coin)
|
||||||
|
.field(mplt_player_info_using_title_id)
|
||||||
|
.field(mplt_player_info_created_at)
|
||||||
|
.field(mplt_player_info_updated_at)
|
||||||
|
.foreignKey(mplt_player_info_using_title_id_fk);
|
||||||
|
mplt_player_info.execute();
|
||||||
|
|
||||||
|
|
||||||
// player title table
|
// player title table
|
||||||
sql = "CREATE TABLE IF NOT EXISTS mplt_player_title (" +
|
TableColumn mplt_player_title_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
|
||||||
" id SERIAL PRIMARY KEY," +
|
TableColumn mplt_player_title_player_uuid = new TableColumn("player_uuid", FieldType.UUID, false, false, true, false, "'00000000-0000-0000-0000-000000000000'");
|
||||||
" player_uuid UUID NOT NULL," +
|
TableColumn mplt_player_title_title_id = new TableColumn("title_id", FieldType.INT, false, false, true, false, 0);
|
||||||
" title_id INTEGER NOT NULL," +
|
TableColumn mplt_player_title_expire_at = new TableColumn("expire_at", FieldType.LONG, false, false, true, false, -1);
|
||||||
" expire_at BIGINT NOT NULL DEFAULT -1," +
|
TableColumn mplt_player_title_created_at = new TableColumn("created_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||||
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
TableColumn mplt_player_title_updated_at = new TableColumn("updated_at", FieldType.DATETIME, false, false, true, false, "CURRENT_TIMESTAMP");
|
||||||
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
CreateTable.ForeignKey mplt_player_title_title_id_fk = new CreateTable.ForeignKey(mplt_player_title_title_id, "mplt_title", mplt_title_id, true);
|
||||||
" FOREIGN KEY (title_id) REFERENCES mplt_title(id) ON DELETE CASCADE," +
|
CreateTable.ForeignKey mplt_player_title_player_uuid_fk = new CreateTable.ForeignKey(mplt_player_title_player_uuid, "mplt_player_info", mplt_player_info_uuid, true);
|
||||||
" FOREIGN KEY (player_uuid) REFERENCES mplt_player_info(uuid) ON DELETE CASCADE" +
|
CreateTable mplt_player_title = new CreateTable().ifNotExists();
|
||||||
");";
|
mplt_player_title.table("mplt_player_title")
|
||||||
MiniPlayerTitle.database.query(sql);
|
.field(mplt_player_title_id)
|
||||||
|
.field(mplt_player_title_player_uuid)
|
||||||
|
.field(mplt_player_title_title_id)
|
||||||
|
.field(mplt_player_title_expire_at)
|
||||||
|
.field(mplt_player_title_created_at)
|
||||||
|
.field(mplt_player_title_updated_at)
|
||||||
|
.foreignKey(mplt_player_title_title_id_fk)
|
||||||
|
.foreignKey(mplt_player_title_player_uuid_fk);
|
||||||
|
mplt_player_title.execute();
|
||||||
|
|
||||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "created_at");
|
new RemoveColumn("expire_at").IfExists().table("mplt_title").execute();
|
||||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "updated_at");
|
new RemoveColumn("sale_end_at").IfExists().table("mplt_title_shop").execute();
|
||||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "enabled");
|
new RemoveColumn("expire_at").IfExists().table("mplt_player_title").execute();
|
||||||
|
new RemoveColumn("created_at").IfExists().table("mplt_title").execute();
|
||||||
|
new RemoveColumn("updated_at").IfExists().table("mplt_title").execute();
|
||||||
|
new RemoveColumn("created_at").IfExists().table("mplt_player_info").execute();
|
||||||
|
new RemoveColumn("updated_at").IfExists().table("mplt_player_info").execute();
|
||||||
|
new RemoveColumn("created_at").IfExists().table("mplt_player_title").execute();
|
||||||
|
new RemoveColumn("updated_at").IfExists().table("mplt_player_title").execute();
|
||||||
|
|
||||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "created_at");
|
TableColumn mplt_title_shop_sale_end_at_y = new TableColumn("sale_end_at_y", FieldType.INT, false, false, true, false, -1);
|
||||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "updated_at");
|
TableColumn mplt_title_shop_sale_end_at_m = new TableColumn("sale_end_at_m", FieldType.INT, false, false, true, false, -1);
|
||||||
|
TableColumn mplt_title_shop_sale_end_at_d = new TableColumn("sale_end_at_d", FieldType.INT, false, false, true, false, -1);
|
||||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "created_at");
|
new AddColumn(mplt_title_shop_sale_end_at_y).table("mplt_title_shop").ifNotExists().execute();
|
||||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "updated_at");
|
new AddColumn(mplt_title_shop_sale_end_at_m).table("mplt_title_shop").ifNotExists().execute();
|
||||||
|
new AddColumn(mplt_title_shop_sale_end_at_d).table("mplt_title_shop").ifNotExists().execute();
|
||||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "created_at");
|
|
||||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "updated_at");
|
|
||||||
|
|
||||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_y", "INTEGER NOT NULL DEFAULT -1");
|
|
||||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_m", "INTEGER NOT NULL DEFAULT -1");
|
|
||||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_d", "INTEGER NOT NULL DEFAULT -1");
|
|
||||||
// convert sale_end_at(YYYYMMDD) to sale_end_at_y, sale_end_at_m, sale_end_at_d if sale_end_at column exists
|
// convert sale_end_at(YYYYMMDD) to sale_end_at_y, sale_end_at_m, sale_end_at_d if sale_end_at column exists
|
||||||
if (MiniPlayerTitle.database.isColumnExist("mplt_title_shop", "sale_end_at")) {
|
if (IsFieldExist("mplt_title_shop", "sale_end_at")) {
|
||||||
sql = "UPDATE mplt_title_shop SET " +
|
String sql = "UPDATE mplt_title_shop SET " +
|
||||||
"sale_end_at_y = (sale_end_at / 10000), " +
|
"sale_end_at_y = (sale_end_at / 10000), " +
|
||||||
"sale_end_at_m = (sale_end_at % 10000 / 100), " +
|
"sale_end_at_m = (sale_end_at % 10000 / 100), " +
|
||||||
"sale_end_at_d = (sale_end_at % 100) " +
|
"sale_end_at_d = (sale_end_at % 100) " +
|
||||||
"WHERE sale_end_at != -1;";
|
"WHERE sale_end_at != -1;";
|
||||||
MiniPlayerTitle.database.query(sql);
|
DatabaseManager.instance.query(sql);
|
||||||
|
new RemoveColumn("sale_end_at").IfExists().table("mplt_title_shop").execute();
|
||||||
}
|
}
|
||||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "sale_end_at");
|
|
||||||
|
|
||||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_y", "INTEGER NOT NULL DEFAULT -1");
|
|
||||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_m", "INTEGER NOT NULL DEFAULT -1");
|
TableColumn mplt_player_title_expire_at_y = new TableColumn("expire_at_y", FieldType.INT, false, false, true, false, -1);
|
||||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_d", "INTEGER NOT NULL DEFAULT -1");
|
TableColumn mplt_player_title_expire_at_m = new TableColumn("expire_at_m", FieldType.INT, false, false, true, false, -1);
|
||||||
if (MiniPlayerTitle.database.isColumnExist("mplt_player_title", "expire_at")) {
|
TableColumn mplt_player_title_expire_at_d = new TableColumn("expire_at_d", FieldType.INT, false, false, true, false, -1);
|
||||||
sql = "UPDATE mplt_player_title SET " +
|
new AddColumn(mplt_player_title_expire_at_y).table("mplt_player_title").ifNotExists().execute();
|
||||||
|
new AddColumn(mplt_player_title_expire_at_m).table("mplt_player_title").ifNotExists().execute();
|
||||||
|
new AddColumn(mplt_player_title_expire_at_d).table("mplt_player_title").ifNotExists().execute();
|
||||||
|
|
||||||
|
if (IsFieldExist("mplt_player_title", "expire_at")) {
|
||||||
|
String sql = "UPDATE mplt_player_title SET " +
|
||||||
"expire_at_y = (expire_at / 10000), " +
|
"expire_at_y = (expire_at / 10000), " +
|
||||||
"expire_at_m = (expire_at % 10000 / 100), " +
|
"expire_at_m = (expire_at % 10000 / 100), " +
|
||||||
"expire_at_d = (expire_at % 100) " +
|
"expire_at_d = (expire_at % 100) " +
|
||||||
"WHERE expire_at != -1;";
|
"WHERE expire_at != -1;";
|
||||||
MiniPlayerTitle.database.query(sql);
|
DatabaseManager.instance.query(sql);
|
||||||
|
new RemoveColumn("expire_at").IfExists().table("mplt_player_title").execute();
|
||||||
}
|
}
|
||||||
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "expire_at");
|
|
||||||
|
|
||||||
sql = "INSERT INTO mplt_title (" +
|
Field mplt_title_id_field = new Field("id", -1);
|
||||||
"id, " +
|
Field mplt_title_title_field = new Field("title", "default");
|
||||||
"title, " +
|
Field mplt_title_description_field = new Field("description", "default");
|
||||||
"description " +
|
InsertRow mplt_title_default = new InsertRow().table("mplt_title");
|
||||||
") VALUES (" +
|
mplt_title_default.field(mplt_title_id_field)
|
||||||
"-1, " +
|
.field(mplt_title_title_field)
|
||||||
"'default', " +
|
.field(mplt_title_description_field).onConflictDoNothing(mplt_title_id_field);
|
||||||
"'default' " +
|
mplt_title_default.execute();
|
||||||
") ON CONFLICT (id) DO NOTHING;";
|
|
||||||
MiniPlayerTitle.database.query(sql);
|
|
||||||
|
|
||||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_info", "last_use_name", "TEXT NOT NULL DEFAULT 'null'");
|
|
||||||
|
TableColumn mplt_player_info_last_use_name = new TableColumn("last_use_name", FieldType.STRING, false, false, true, false, "'null'");
|
||||||
|
new AddColumn(mplt_player_info_last_use_name).table("mplt_player_info").ifNotExists().execute();
|
||||||
|
|
||||||
// 3.0.6
|
// 3.0.6
|
||||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_info", "coin_d", "DOUBLE PRECISION NOT NULL DEFAULT 0");
|
TableColumn mplt_player_info_coin_d = new TableColumn("coin_d", FieldType.DOUBLE, false, false, true, false, 0);
|
||||||
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "price_d", "DOUBLE PRECISION NOT NULL DEFAULT 0");
|
TableColumn mplt_title_shop_price_d = new TableColumn("price_d", FieldType.DOUBLE, false, false, true, false, 0);
|
||||||
if (MiniPlayerTitle.database.isColumnExist("mplt_player_info", "coin")) {
|
new AddColumn(mplt_player_info_coin_d).table("mplt_player_info").ifNotExists().execute();
|
||||||
sql = "UPDATE mplt_player_info SET coin_d = coin;";
|
new AddColumn(mplt_title_shop_price_d).table("mplt_title_shop").ifNotExists().execute();
|
||||||
MiniPlayerTitle.database.query(sql);
|
if (IsFieldExist("mplt_player_info", "coin")) {
|
||||||
|
String sql = "UPDATE mplt_player_info SET coin_d = coin;";
|
||||||
|
DatabaseManager.instance.query(sql);
|
||||||
|
new RemoveColumn("coin").IfExists().table("mplt_player_info").execute();
|
||||||
}
|
}
|
||||||
if (MiniPlayerTitle.database.isColumnExist("mplt_title_shop", "price")) {
|
if (IsFieldExist("mplt_title_shop", "price")) {
|
||||||
sql = "UPDATE mplt_title_shop SET price_d = price;";
|
String sql = "UPDATE mplt_title_shop SET price_d = price;";
|
||||||
MiniPlayerTitle.database.query(sql);
|
DatabaseManager.instance.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,9 +5,20 @@ api-version: '1.20'
|
|||||||
description: 称号插件。
|
description: 称号插件。
|
||||||
website: https://lunadeer.cn
|
website: https://lunadeer.cn
|
||||||
folia-supported: true
|
folia-supported: true
|
||||||
softdepend: [PlaceholderAPI, Vault]
|
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