重写了部分TUI

This commit is contained in:
zhangyuheng 2024-05-20 18:02:26 +08:00
parent c3192a1c81
commit f1f58d4498
19 changed files with 1137 additions and 779 deletions

View File

@ -1,280 +1,60 @@
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.minecraftpluginutils.stui.View;
import cn.lunadeer.minecraftpluginutils.stui.ViewStyles;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import cn.lunadeer.miniplayertitle.commands.AdminCommands;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import cn.lunadeer.miniplayertitle.commands.TitleShopSale;
import cn.lunadeer.miniplayertitle.tuis.*;
import cn.lunadeer.miniplayertitle.tuis.Shop;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static cn.lunadeer.miniplayertitle.commands.PlayerCommands.*;
public class Commands implements TabExecutor {
/**
* Executes the given command, returning its success.
* <br>
* If false is returned, then the "usage" plugin.yml entry for this command
* (if defined) will be sent to the player.
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return true if a valid command, otherwise false
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
switch (label) {
case "mplt":
if (args.length == 0) {
home_view(sender);
return true;
}
switch (args[0]) {
case "use":
use(sender, args);
return true;
case "list":
list(sender, args);
return true;
case "shop":
shop(sender, args);
return true;
case "buy":
buy(sender, args);
return true;
case "custom":
custom(sender, args);
return true;
case "custominfo":
custom_info(sender);
return true;
case "create":
AdminCommands.createTitle(sender, args);
return true;
case "delete":
AdminCommands.deleteTitle(sender, args);
return true;
case "setdesc":
AdminCommands.setTitleDescription(sender, args);
return true;
case "setname":
AdminCommands.setTitleName(sender, args);
return true;
case "addshop":
AdminCommands.addShop(sender, args);
return true;
case "removeshop":
AdminCommands.removeShop(sender, args);
return true;
case "setprice":
AdminCommands.setPrice(sender, args);
return true;
case "setamount":
AdminCommands.setAmount(sender, args);
return true;
case "setendat":
AdminCommands.setSaleEndAt(sender, args);
return true;
case "listall":
AdminCommands.listAllTitle(sender, args);
return true;
case "addcoin":
AdminCommands.addCoin(sender, args);
return true;
case "setcoin":
AdminCommands.setCoin(sender, args);
return true;
default:
printHelp(sender);
return true;
}
if (args.length == 0) {
Menu.show(sender, args);
return true;
}
switch (args[0]) {
case "menu":
Menu.show(sender, args);
break;
case "all_titles":
AllTitles.show(sender, args);
break;
case "my_titles":
MyTitles.show(sender, args);
break;
case "shop":
Shop.show(sender, args);
break;
case "custom_info":
CustomInfo.show(sender, args);
break;
case "sale_info":
SaleInfo.show(sender, args);
break;
case "create_sale":
TitleShopSale.createSale(sender, args);
break;
case "set_sale":
TitleShopSale.setSale(sender, args);
break;
case "delete_sale":
TitleShopSale.deleteSale(sender, args);
break;
default:
return false;
}
return true;
}
private static void printHelp(@NotNull CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
MiniPlayerTitle.notification.warn(player, "用法: /mplt <use|list|shop|buy|custom|custominfo>");
if (player.isOp()) {
MiniPlayerTitle.notification.warn(player, "用法: /mplt <create|delete|setdesc|setname|addshop|removeshop|setprice|setamount|setendat|listall>");
}
} else {
MiniPlayerTitle.logger.info("用法: /mplt <use|list|shop|buy|custom>");
MiniPlayerTitle.logger.info("用法: /mplt <create|delete|setdesc|setname|addshop|removeshop|setprice|setamount|setendat|listall>");
}
}
public static void home_view(CommandSender sender) {
if (!(sender instanceof Player)) {
printHelp(sender);
return;
}
View view = View.create();
view.title("称号系统");
Line line_1 = Line.create();
line_1.append(Component.text("当前版本:"));
line_1.append(Component.text(MiniPlayerTitle.instance.getPluginMeta().getVersion()));
Line line_2 = Line.create();
line_2.append(Component.text("帮助文档:"));
line_2.append(Component.text("[点击在浏览器中打开]").clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, "https://ssl.lunadeer.cn:14446/zhangyuheng/MiniPlayerTitle")));
Component backpack = Button.create("称号背包").setExecuteCommand("/mplt list").build();
Component shop = Button.create("称号商店").setExecuteCommand("/mplt shop").build();
Component custom = Button.create("自定义称号").setExecuteCommand("/mplt custominfo").build();
Line line = Line.create();
line.append(backpack).append(shop).append(custom);
view.actionBar(line).addLine(line_1).addLine(line_2);
view.showOn((Player) sender);
}
private void custom_info(CommandSender sender) {
if (!(sender instanceof Player)) {
printHelp(sender);
return;
}
Player player = (Player) sender;
View view = View.create();
view.title("自定义称号帮助");
view.subtitle("当前余额: " + XPlayer.getCoin(player) + "称号币");
Line line_1 = Line.create();
line_1.append("当前自定义称号状态:")
.append(MiniPlayerTitle.config.isEnableCustom() ?
Component.text("开启", ViewStyles.success_color) :
Component.text("关闭", ViewStyles.error_color));
Line line_2 = Line.create();
line_2.append("自定义称号花费:")
.append(MiniPlayerTitle.config.getCustomCost().toString());
Line line_3 = Line.create();
line_3.append("自定义方法:")
.append(Component.text("在聊天框输入 /mplt custom <称号>"));
Line line_4 = Line.create();
line_4.append("可以使用 Minecraft渐变颜色生成器 来生成具有渐变效果的称号")
.append(Component.text("[点击在浏览器中打开生成器]", ViewStyles.action_color)
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, "https://ssl.lunadeer.cn:14440/")));
Line line_5 = Line.create();
line_5.append("最大长度(不含颜色代码):")
.append(MiniPlayerTitle.config.getMaxLength().toString());
view.addLine(line_1)
.addLine(line_2)
.addLine(line_5)
.addLine(line_3)
.addLine(line_4);
view.showOn(player);
}
/**
* Requests a list of possible completions for a command argument.
*
* @param sender Source of the command. For players tab-completing a
* command inside a command block, this will be the player, not
* the command block.
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args The arguments passed to the command, including final
* partial argument to be completed
* @return A List of possible completions for the final argument, or null
* to default to the command executor
*/
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 1) {
String[] player_cmd = {"use", "list", "shop", "buy", "custom", "custominfo"};
String[] admin_cmd = {"create", "delete", "setdesc", "setname", "addshop", "removeshop", "setprice", "setamount", "setendat", "listall", "addcoin", "setcoin"};
List<String> res = new ArrayList<>();
if (sender instanceof Player) {
Player player = (Player) sender;
if (player.isOp()) {
res.addAll(Arrays.asList(player_cmd));
res.addAll(Arrays.asList(admin_cmd));
} else {
res.addAll(Arrays.asList(player_cmd));
}
} else {
res.addAll(Arrays.asList(player_cmd));
res.addAll(Arrays.asList(admin_cmd));
}
return res;
}
if (args.length == 2) {
switch (args[0]) {
case "use":
return Collections.singletonList("要使用的称号ID");
case "custom":
return Collections.singletonList("自定义称号");
case "list":
case "shop":
case "listall":
return Collections.singletonList("页数(可选)");
case "buy":
return Collections.singletonList("要购买的条目ID");
case "create":
return Collections.singletonList("<称号名称> <称号描述>");
case "delete":
case "addshop":
return Collections.singletonList("<称号ID>");
case "setdesc":
return Collections.singletonList("<称号ID> <称号描述>");
case "setname":
return Collections.singletonList("<称号ID> <称号名称>");
case "removeshop":
return Collections.singletonList("<商品ID>");
case "setprice":
return Collections.singletonList("<商品ID> <价格> <天数>(-1为永久)");
case "setamount":
return Collections.singletonList("<商品ID> <数量>(-1为无限)");
case "setendat":
return Collections.singletonList("<商品ID> <结束时间YYYYMMDD>(-1为永久)");
case "addcoin":
case "setcoin":
// return player list
List<String> res = new ArrayList<>();
for (Player player : MiniPlayerTitle.instance.getServer().getOnlinePlayers()) {
res.add(player.getName());
}
return res;
default:
return Arrays.asList("use", "list", "shop", "buy");
}
}
if (args.length == 3) {
switch (args[0]) {
case "addcoin":
case "setcoin":
return Collections.singletonList("<金币数量>");
case "create":
case "setdesc":
return Collections.singletonList("<称号描述>");
case "setname":
return Collections.singletonList("<称号名称>");
case "setprice":
return Collections.singletonList("<价格> <天数>(-1为永久)");
case "setamount":
return Collections.singletonList("<数量>(-1为无限)");
case "setendat":
return Collections.singletonList("<结束时间YYYYMMDD>(-1为永久)");
}
}
if (args.length == 4) {
if (args[0].equals("setprice")) {
return Collections.singletonList("<天数>(-1为永久)");
}
}
return Arrays.asList("use", "list", "shop", "buy", "custom", "custominfo");
return null;
}
}

View File

@ -1,5 +1,6 @@
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
@ -12,8 +13,7 @@ public class Events implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player bukkitPlayer = event.getPlayer();
XPlayer player = new XPlayer(bukkitPlayer);
Commands.home_view(bukkitPlayer);
PlayerInfoDTO player = PlayerInfoDTO.get(bukkitPlayer.getUniqueId());
player.updateName();
}

View File

@ -1,192 +0,0 @@
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.HoverEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
public class Title {
protected Integer _id = null;
protected String _title;
protected String _description;
protected Boolean _enabled;
public static Title create(String title, String description) {
String sql = "";
sql += "INSERT INTO mplt_title (title, description, enabled) VALUES (";
sql += "'" + title + "', ";
sql += "'" + description + "', ";
sql += "true ";
sql += ") RETURNING id;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs != null && rs.next()) {
int titleId = rs.getInt("id");
return new Title(titleId);
}
} catch (Exception e) {
MiniPlayerTitle.logger.err("Title create failed: " + e.getMessage());
}
return null;
}
public static List<Title> all() {
List<Title> titles = new ArrayList<>();
String sql = "";
sql += "SELECT id FROM mplt_title;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs != null) {
while (rs.next()) {
Integer id = rs.getInt("id");
titles.add(new Title(id));
}
}
} catch (Exception e) {
MiniPlayerTitle.logger.err("Title all failed: " + e.getMessage());
}
return titles;
}
public static void listAllTitle(CommandSender sender, Integer page) {
List<Title> titles = all();
if (!(sender instanceof Player)) {
for (Title title : titles) {
Component idx = Component.text("[" + title.getId() + "]");
MiniPlayerTitle.notification.info(sender, idx.append(title.getTitle()));
}
return;
}
Player player = (Player) sender;
ListView view = ListView.create(5, "/mplt listall");
view.title("所有称号");
for (Title title : titles) {
TextComponent idx = Component.text("[" + title.getId() + "] ");
Line line = Line.create();
line.append(idx).append(title.getTitle());
view.add(line);
}
view.showOn(player, page);
}
public Title(Integer id) {
this._id = id;
String sql = "";
sql += "SELECT id, title, description, enabled ";
sql += "FROM mplt_title ";
sql += "WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs != null && rs.next()) {
this._title = rs.getString("title");
this._description = rs.getString("description");
this._enabled = rs.getBoolean("enabled");
}
} catch (Exception e) {
MiniPlayerTitle.logger.err("Title load failed: " + e.getMessage());
}
}
public static void delete(Integer id) {
String sql = "";
sql += "DELETE FROM mplt_title WHERE id = " + id + ";";
MiniPlayerTitle.database.query(sql);
}
private void save() {
String sql = "";
if (this._id == null) {
sql += "INSERT INTO mplt_title (title, description, enabled) VALUES (";
sql += "'" + this._title + "', ";
sql += "'" + this._description + "', ";
sql += this._enabled + " ";
sql += ");";
} else {
sql += "UPDATE mplt_title SET ";
sql += "title = '" + this._title + "', ";
sql += "description = '" + this._description + "', ";
sql += "enabled = " + this._enabled + " ";
sql += "WHERE id = " + this._id + ";";
}
MiniPlayerTitle.database.query(sql);
}
public Integer getId() {
return this._id;
}
public TextComponent getTitle() {
TextComponent prefix = Component.text(MiniPlayerTitle.config.getPrefix());
TextComponent suffix = Component.text(MiniPlayerTitle.config.getSuffix());
String[] parts = this._title.split("&#");
List<TextComponent> components = new ArrayList<>();
components.add(prefix);
for (String part : parts) {
if (part.isEmpty()) {
continue;
}
// match hex regx ^[0-9a-fA-F]{6}$
Color color = new Color("#ffffff");
String content;
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) {
String color_str = part.substring(0, 6);
color = new Color("#" + color_str);
content = part.substring(6);
} else {
content = part;
}
components.add(Component.text(content, color.getStyle()));
}
components.add(suffix);
TextComponent.Builder title_component = Component.text();
for (TextComponent component : components) {
title_component.append(component);
}
return title_component.build().hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, Component.text(this._description)));
}
public String getTitleContent() {
String[] parts = this._title.split("&#");
StringBuilder res = new StringBuilder();
for (String part : parts) {
if (part.isEmpty()) {
continue;
}
String content;
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) {
content = part.substring(6);
} else {
content = part;
}
res.append(content);
}
return res.toString();
}
public void setTitle(String title) {
this._title = title;
this.save();
}
public String getDescription() {
return this._description;
}
public void setDescription(String description) {
this._description = description;
this.save();
}
public Boolean getEnabled() {
return this._enabled;
}
public void setEnabled(Boolean enabled) {
this._enabled = enabled;
this.save();
}
}

View File

@ -1,319 +0,0 @@
package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.SaleTitle;
import cn.lunadeer.miniplayertitle.Title;
import cn.lunadeer.miniplayertitle.XPlayer;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class AdminCommands {
public static void createTitle(CommandSender sender, String[] args) {
if (sender instanceof org.bukkit.entity.Player) {
Player player = (org.bukkit.entity.Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt create <称号名称> <称号描述>");
return;
}
Title title = Title.create(args[1], args[2]);
if (title != null) {
MiniPlayerTitle.notification.info(sender, Component.text("成功创建称号: [" + title.getId() + "]").append(title.getTitle()));
} else {
MiniPlayerTitle.notification.error(sender, "创建称号失败");
}
}
public static void deleteTitle(CommandSender sender, String[] args) {
try {
if (sender instanceof org.bukkit.entity.Player) {
Player player = (org.bukkit.entity.Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
if (args.length != 2) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt delete <称号ID>");
return;
}
Title.delete(Integer.parseInt(args[1]));
MiniPlayerTitle.notification.info(sender, "已删除称号");
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
public static void listAllTitle(CommandSender sender, String[] args) {
try {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
int page = 1;
if (args.length == 2) {
try {
page = Integer.parseInt(args[1]);
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, "页数格式错误");
return;
}
}
Title.listAllTitle(sender, page);
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
public static void setTitleDescription(CommandSender sender, String[] args) {
try {
if (sender instanceof org.bukkit.entity.Player) {
Player player = (org.bukkit.entity.Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt setdesc <称号ID> <称号描述>");
return;
}
Title title = new Title(Integer.parseInt(args[1]));
title.setDescription(args[2]);
MiniPlayerTitle.notification.info(sender, "已设置称号描述");
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
public static void setTitleName(CommandSender sender, String[] args) {
try {
if (sender instanceof org.bukkit.entity.Player) {
Player player = (org.bukkit.entity.Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt setname <称号ID> <称号名称>");
return;
}
Title title = new Title(Integer.parseInt(args[1]));
title.setTitle(args[2]);
MiniPlayerTitle.notification.info(sender, "已设置称号名称");
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
public static void addShop(CommandSender sender, String[] args) {
try {
if (sender instanceof org.bukkit.entity.Player) {
Player player = (org.bukkit.entity.Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
if (args.length != 2) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt addshop <称号ID>");
return;
}
SaleTitle title = SaleTitle.create(Integer.parseInt(args[1]));
if (title == null) {
MiniPlayerTitle.notification.error(sender, "添加商品失败");
} else {
MiniPlayerTitle.notification.info(sender, "已添加称号到商店, 商品ID: " + title.getSaleId());
MiniPlayerTitle.notification.info(sender, title.getTitle());
}
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
public static void removeShop(CommandSender sender, String[] args) {
try {
if (sender instanceof org.bukkit.entity.Player) {
Player player = (org.bukkit.entity.Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
if (args.length != 2) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt removeshop <商品ID>");
return;
}
SaleTitle.delete(Integer.parseInt(args[1]));
MiniPlayerTitle.notification.info(sender, "已从商店移除商品");
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
public static void setPrice(CommandSender sender, String[] args) {
try {
if (sender instanceof org.bukkit.entity.Player) {
Player player = (org.bukkit.entity.Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
if (args.length != 4) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt setprice <商品ID> <价格> <天数>(-1为永久)");
return;
}
int price;
int days;
int id;
try {
price = Integer.parseInt(args[2]);
days = Integer.parseInt(args[3]);
id = Integer.parseInt(args[1]);
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, "价格或天数格式错误");
return;
}
if (price < 0 || days < -1) {
MiniPlayerTitle.notification.error(sender, "价格或天数格式错误");
return;
}
SaleTitle.setPrice(id, price);
SaleTitle.setDays(id, days);
MiniPlayerTitle.notification.info(sender, "已设置商品价格");
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
public static void setAmount(CommandSender sender, String[] args) {
try {
if (sender instanceof org.bukkit.entity.Player) {
Player player = (org.bukkit.entity.Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt setamount <商品ID> <数量>(-1为无限)");
return;
}
int amount;
int id;
try {
amount = Integer.parseInt(args[2]);
id = Integer.parseInt(args[1]);
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, "数量格式错误");
return;
}
SaleTitle.setAmount(id, amount);
MiniPlayerTitle.notification.info(sender, "已设置商品数量");
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
public static void setSaleEndAt(CommandSender sender, String[] args) {
try {
if (sender instanceof org.bukkit.entity.Player) {
Player player = (org.bukkit.entity.Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt setendat <商品ID> <时间YYYYMMDD>(-1为永久)");
return;
}
long time_stamp;
try {
time_stamp = Long.parseLong(args[2]);
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, "时间格式错误");
return;
}
SaleTitle.setSaleEndAt(Integer.parseInt(args[1]), time_stamp);
MiniPlayerTitle.notification.info(sender, "已设置商品结束时间");
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
public static void addCoin(CommandSender sender, String[] args) {
try {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt addcoin <玩家> <数量>");
return;
}
Player target = sender.getServer().getPlayer(args[1]);
if (target == null) {
MiniPlayerTitle.notification.error(sender, "玩家不在线");
return;
}
int amount;
try {
amount = Integer.parseInt(args[2]);
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, "数量格式错误");
return;
}
new XPlayer(target).add_coin(amount);
MiniPlayerTitle.notification.info(sender, "已给予玩家 " + target.getName() + " " + amount + " 称号币");
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
public static void setCoin(CommandSender sender, String[] args) {
try {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限执行该命令");
return;
}
}
if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt setcoin <玩家> <数量>");
return;
}
Player target = sender.getServer().getPlayer(args[1]);
if (target == null) {
MiniPlayerTitle.notification.error(sender, "玩家不在线");
return;
}
int amount;
try {
amount = Integer.parseInt(args[2]);
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, "数量格式错误");
return;
}
new XPlayer(target).set_coin(amount);
MiniPlayerTitle.notification.info(sender, "已设置玩家 " + target.getName() + " 称号币为 " + amount);
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
}

View File

@ -0,0 +1,18 @@
package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Apis {
public static boolean notOpOrConsole(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
MiniPlayerTitle.notification.warn(player, "你没有权限使用此命令");
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,112 @@
package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
public class TitleManage {
/**
* 创建称号
* mplt create_title <称号名称> <称号描述>
*
* @param sender CommandSender
* @param args String[]
*/
public static void createTitle(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt create_title <称号名称> <称号描述>");
return;
}
TitleDTO title = TitleDTO.create(args[1], args[2]);
if (title != null) {
MiniPlayerTitle.notification.info(sender, Component.text("成功创建称号: [" + title.getId() + "]").append(title.getTitleColored()));
} else {
MiniPlayerTitle.notification.error(sender, "创建称号失败,具体请查看控制台日志");
}
}
/**
* 删除称号
* mplt delete_title <称号ID>
*
* @param sender CommandSender
* @param args String[]
*/
public static void deleteTitle(CommandSender sender, String[] args) {
try {
if (notOpOrConsole(sender)) return;
if (args.length != 2) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt delete_title <称号ID>");
return;
}
TitleDTO.delete(Integer.parseInt(args[1]));
MiniPlayerTitle.notification.info(sender, "已删除称号");
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
/**
* 设置称号名称
* mplt set_title <称号ID> <称号名称>
*
* @param sender CommandSender
* @param args String[]
*/
public static void setTitle(CommandSender sender, String[] args) {
try {
if (notOpOrConsole(sender)) return;
if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt set_title <称号ID> <称号名称>");
return;
}
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
if (title == null) {
MiniPlayerTitle.notification.error(sender, "称号不存在");
return;
}
boolean success = title.updateTitle(args[2]);
if (success) {
MiniPlayerTitle.notification.info(sender, "已更新称号名称");
} else {
MiniPlayerTitle.notification.error(sender, "更新称号名称失败,具体请查看控制台日志");
}
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
/**
* 设置称号描述
* mplt set_desc <称号ID> <称号描述>
*
* @param sender CommandSender
* @param args String[]
*/
public static void setTitleDescription(CommandSender sender, String[] args) {
try {
if (notOpOrConsole(sender)) return;
if (args.length != 3) {
MiniPlayerTitle.notification.warn(sender, "用法: /mplt set_desc <称号ID> <称号描述>");
return;
}
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
if (title == null) {
MiniPlayerTitle.notification.error(sender, "称号不存在");
return;
}
boolean success = title.updateDescription(args[2]);
if (success) {
MiniPlayerTitle.notification.info(sender, "已更新称号描述");
} else {
MiniPlayerTitle.notification.error(sender, "更新称号描述失败,具体请查看控制台日志");
}
} catch (Exception e) {
MiniPlayerTitle.notification.error(sender, e.getMessage());
}
}
}

View File

@ -0,0 +1,121 @@
package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO;
import cn.lunadeer.miniplayertitle.tuis.SaleInfo;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
public class TitleShopSale {
/**
* 设置商品信息
* mplt set_sale <price|days|amount|end_at|end_at_y|end_at_m|end_at_d> <商品ID> <> [页数]
*
* @param sender CommandSender
* @param args String[]
*/
public static void setSale(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[2]));
if (titleShop == null) {
MiniPlayerTitle.notification.error(sender, "获取详情时出现错误,详情请查看控制台日志");
return;
}
boolean success;
switch (args[1]) {
case "price":
success = titleShop.setPrice(Integer.parseInt(args[3]));
break;
case "days":
success = titleShop.setDays(Integer.parseInt(args[3]));
break;
case "amount":
success = titleShop.setAmount(Integer.parseInt(args[3]));
break;
case "end_at":
String[] date = args[3].split(":");
int year = Integer.parseInt(date[0]);
int month = Integer.parseInt(date[1]);
int day = Integer.parseInt(date[2]);
success = titleShop.setSaleEndAt(year, month, day);
break;
case "end_at_y":
success = titleShop.setSaleEndAtY(Integer.parseInt(args[3]));
break;
case "end_at_m":
success = titleShop.setSaleEndAtM(Integer.parseInt(args[3]));
break;
case "end_at_d":
success = titleShop.setSaleEndAtD(Integer.parseInt(args[3]));
break;
default:
MiniPlayerTitle.notification.warn(sender, "用法: /mplt set_sale <price|days|amount|end_at|end_at_y|end_at_m|end_at_d> <商品ID> <值> [页数]");
return;
}
if (!success) {
MiniPlayerTitle.notification.error(sender, "设置商品信息时出现错误,详情请查看控制台日志");
}
if (args.length == 5) {
int page = getLastArgsPage(args);
SaleInfo.show(sender, new String[]{"sale_info", args[2], String.valueOf(page)});
}
}
/**
* 创建商品
* mplt create_sale <称号ID>
*
* @param sender CommandSender
* @param args String[]
*/
public static void createSale(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
if (title == null) {
MiniPlayerTitle.notification.error(sender, "获取称号详情时出现错误,详情请查看控制台日志");
return;
}
TitleShopDTO sale = TitleShopDTO.create(title);
if (sale == null) {
MiniPlayerTitle.notification.error(sender, "创建商品时出现错误,详情请查看控制台日志");
return;
}
MiniPlayerTitle.notification.info(sender, "已创建称号商品");
if (sender instanceof Player) {
SaleInfo.show(sender, new String[]{"sale_info", String.valueOf(sale.getId())});
}
}
/**
* 删除商品
* mplt delete_sale <商品ID> [页数]
*
* @param sender CommandSender
* @param args String[]
*/
public static void deleteSale(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
if (titleShop == null) {
MiniPlayerTitle.notification.error(sender, "获取详情时出现错误");
return;
}
boolean success = titleShop.delete();
if (success) {
MiniPlayerTitle.notification.info(sender, "已删除商品");
} else {
MiniPlayerTitle.notification.error(sender, "删除商品时出现错误,详情请查看控制台日志");
}
if (args.length == 3) {
int page = getLastArgsPage(args);
SaleInfo.show(sender, new String[]{"sale_info", args[1], String.valueOf(page)});
}
}
}

View File

@ -0,0 +1,90 @@
package cn.lunadeer.miniplayertitle.dtos;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import org.jetbrains.annotations.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
public class PlayerInfoDTO {
private UUID uuid;
private Integer coin;
private TitleDTO using_title;
public static PlayerInfoDTO get(UUID uuid) {
String sql = "";
sql = "SELECT uuid, coin, using_title_id FROM mplt_player_info WHERE uuid = '" + uuid.toString() + "';";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs.next()) return getPlayerInfoDTO(rs);
else return create(uuid);
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取玩家信息失败", e, sql);
}
return null;
}
private static PlayerInfoDTO create(UUID uuid) {
String sql = "";
sql = "INSERT INTO mplt_player_info (uuid, coin) " +
"VALUES ('" + uuid.toString() + "', " + MiniPlayerTitle.config.getDefaultCoin() + ") " +
"RETURNING " +
"uuid, coin, using_title_id " +
"ON CONFLICT (uuid) DO NOTHING;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs.next()) return getPlayerInfoDTO(rs);
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("创建玩家信息失败", e, sql);
}
return null;
}
private static PlayerInfoDTO getPlayerInfoDTO(ResultSet rs) throws SQLException {
PlayerInfoDTO playerInfoDTO = new PlayerInfoDTO();
playerInfoDTO.uuid = UUID.fromString(rs.getString("uuid"));
playerInfoDTO.coin = rs.getInt("coin");
playerInfoDTO.using_title = TitleDTO.get(rs.getInt("using_title_id"));
return playerInfoDTO;
}
public Integer getCoin() {
return coin;
}
public TitleDTO getUsingTitle() {
return using_title;
}
public boolean setUsingTitle(TitleDTO title) {
String sql = "";
sql = "UPDATE mplt_player_info SET using_title_id = " + title.getId() + " WHERE uuid = '" + uuid.toString() + "';";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs != null && rs.next()) {
using_title = title;
return true;
}
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置玩家使用称号失败", e, sql);
}
return false;
}
public boolean addCoin(Integer coin) {
return setCoin(this.coin + coin);
}
public boolean setCoin(Integer coin) {
String sql = "";
sql = "UPDATE mplt_player_info SET coin = " + coin + " WHERE uuid = '" + uuid.toString() + "';";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs != null && rs.next()) {
this.coin = coin;
return true;
}
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置玩家金币失败", e, sql);
}
return false;
}
}

View File

@ -0,0 +1,163 @@
package cn.lunadeer.miniplayertitle.dtos;
import cn.lunadeer.miniplayertitle.Color;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.HoverEvent;
import org.jetbrains.annotations.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class TitleDTO {
private int id;
private String title;
private String description;
public static TitleDTO get(int id) {
String sql = "";
sql += "SELECT id, title, description FROM mplt_title WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs.next()) return getTitleDTO(rs);
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取称号失败", e, sql);
}
return null;
}
public static TitleDTO create(String title, String description) {
String sql = "";
sql += "INSERT INTO mplt_title (title, description) " +
"VALUES ('" + title + "', '" + description + "') " +
"RETURNING " +
"id, title, description;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs.next()) return getTitleDTO(rs);
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("创建称号失败", e, sql);
}
return null;
}
public static boolean delete(int id) {
String sql = "";
sql += "DELETE FROM mplt_title WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs != null && rs.next()) {
return true;
}
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("删除称号失败", e, sql);
}
return false;
}
public static List<TitleDTO> getAll() {
String sql = "";
sql += "SELECT id, title, description FROM mplt_title;";
List<TitleDTO> titleDTOs = new ArrayList<>();
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
while (rs.next()) {
titleDTOs.add(getTitleDTO(rs));
}
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取称号列表失败", e, sql);
}
return titleDTOs;
}
public TextComponent getTitleColored() {
TextComponent prefix = Component.text(MiniPlayerTitle.config.getPrefix());
TextComponent suffix = Component.text(MiniPlayerTitle.config.getSuffix());
String[] parts = this.title.split("&#");
List<TextComponent> components = new ArrayList<>();
components.add(prefix);
for (String part : parts) {
if (part.isEmpty()) {
continue;
}
// match hex regx ^[0-9a-fA-F]{6}$
Color color = new Color("#ffffff");
String content;
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) {
String color_str = part.substring(0, 6);
color = new Color("#" + color_str);
content = part.substring(6);
} else {
content = part;
}
components.add(Component.text(content, color.getStyle()));
}
components.add(suffix);
TextComponent.Builder title_component = Component.text();
for (TextComponent component : components) {
title_component.append(component);
}
return title_component.build().hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, Component.text(this.description)));
}
public String getTitlePlainText() {
String[] parts = this.title.split("&#");
StringBuilder res = new StringBuilder();
for (String part : parts) {
if (part.isEmpty()) {
continue;
}
String content;
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) {
content = part.substring(6);
} else {
content = part;
}
res.append(content);
}
return res.toString();
}
public Integer getId() {
return this.id;
}
public String getDescription() {
return this.description;
}
public boolean updateTitle(String title) {
String sql = "";
sql += "UPDATE mplt_title SET title = '" + title + "' WHERE id = " + this.id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs != null && rs.next()) {
this.title = title;
return true;
}
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("更新称号失败", e, sql);
}
return false;
}
public boolean updateDescription(String description) {
String sql = "";
sql += "UPDATE mplt_title SET description = '" + description + "' WHERE id = " + this.id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs != null && rs.next()) {
this.description = description;
return true;
}
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("更新称号失败", e, sql);
}
return false;
}
private static TitleDTO getTitleDTO(ResultSet rs) throws SQLException {
TitleDTO titleDTO = new TitleDTO();
titleDTO.id = rs.getInt("id");
titleDTO.title = rs.getString("title");
titleDTO.description = rs.getString("description");
return titleDTO;
}
}

View File

@ -0,0 +1,196 @@
package cn.lunadeer.miniplayertitle.dtos;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
public class TitleShopDTO {
private Integer id;
private TitleDTO title;
private Integer price;
private Integer days;
private Integer amount;
private Integer sale_end_at_y;
private Integer sale_end_at_m;
private Integer sale_end_at_d;
public Integer getId() {
return id;
}
public TitleDTO getTitle() {
return title;
}
public Integer getPrice() {
return price;
}
public boolean setPrice(int price) {
String sql = "";
sql += "UPDATE mplt_title_shop SET price = " + price + " WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
return true;
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置称号商店价格失败", e, sql);
}
return false;
}
public Integer getDays() {
return days;
}
public boolean setDays(int days) {
String sql = "";
sql += "UPDATE mplt_title_shop SET days = " + days + " WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
return true;
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置称号商店天数失败", e, sql);
}
return false;
}
public Integer getAmount() {
return amount;
}
public boolean setAmount(int amount) {
String sql = "";
sql += "UPDATE mplt_title_shop SET amount = " + amount + " WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
return true;
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置称号商店数量失败", e, sql);
}
return false;
}
public Integer getSaleEndAtY() {
return sale_end_at_y;
}
public boolean setSaleEndAtY(int sale_end_at_y) {
String sql = "";
sql += "UPDATE mplt_title_shop SET sale_end_at_y = " + sale_end_at_y + " WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
return true;
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置称号商店销售结束年份失败", e, sql);
}
return false;
}
public Integer getSaleEndAtM() {
return sale_end_at_m;
}
public boolean setSaleEndAtM(int sale_end_at_m) {
String sql = "";
sql += "UPDATE mplt_title_shop SET sale_end_at_m = " + sale_end_at_m + " WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
return true;
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置称号商店销售结束月份失败", e, sql);
}
return false;
}
public Integer getSaleEndAtD() {
return sale_end_at_d;
}
public boolean setSaleEndAtD(int sale_end_at_d) {
String sql = "";
sql += "UPDATE mplt_title_shop SET sale_end_at_d = " + sale_end_at_d + " WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
return true;
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置称号商店销售结束日期失败", e, sql);
}
return false;
}
public boolean setSaleEndAt(int y, int m, int d) {
String sql = "";
sql += "UPDATE mplt_title_shop SET sale_end_at_y = " + y + ", sale_end_at_m = " + m + ", sale_end_at_d = " + d + " WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
return true;
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("设置称号商店销售结束时间失败", e, sql);
}
return false;
}
public static TitleShopDTO get(Integer id) {
String sql = "";
sql += "SELECT id, title_id, price, days, amount, sale_end_at FROM mplt_title_shop WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs.next()) {
return getTitleShop(rs);
}
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取称号商店信息失败", e, sql);
}
return null;
}
public static List<TitleShopDTO> getAll() {
String sql = "";
sql += "SELECT id, title_id, price, days, amount, sale_end_at FROM mplt_title_shop;";
List<TitleShopDTO> titleShops = new ArrayList<>();
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
while (rs != null && rs.next()) {
TitleShopDTO titleShop = getTitleShop(rs);
titleShops.add(titleShop);
}
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("获取称号商店列表失败", e, sql);
}
return titleShops;
}
private static TitleShopDTO getTitleShop(ResultSet rs) throws Exception {
TitleShopDTO titleShop = new TitleShopDTO();
titleShop.id = rs.getInt("id");
titleShop.title = TitleDTO.get(rs.getInt("title_id"));
titleShop.price = rs.getInt("price");
titleShop.days = rs.getInt("days");
titleShop.amount = rs.getInt("amount");
titleShop.sale_end_at_y = rs.getInt("sale_end_at_y");
titleShop.sale_end_at_m = rs.getInt("sale_end_at_m");
titleShop.sale_end_at_d = rs.getInt("sale_end_at_d");
return titleShop;
}
public static TitleShopDTO create(TitleDTO title) {
String sql = "";
sql += "INSERT INTO mplt_title_shop (title_id, price, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d) " +
"VALUES (" + title.getId() + ", 0, -1, 0, -1, -1, -1) " +
"RETURNING " +
"id, title_id, price, days, amount, sale_end_at_y, sale_end_at_m, sale_end_at_d;";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
if (rs.next()) {
return getTitleShop(rs);
}
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("创建称号商店失败", e, sql);
}
return null;
}
public boolean delete() {
String sql = "";
sql += "DELETE FROM mplt_title_shop WHERE id = " + id + ";";
try (ResultSet rs = MiniPlayerTitle.database.query(sql)) {
return true;
} catch (Exception e) {
MiniPlayerTitle.database.handleDatabaseError("删除称号商店失败", e, sql);
}
return false;
}
}

View File

@ -0,0 +1,40 @@
package cn.lunadeer.miniplayertitle.tuis;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
import static cn.lunadeer.miniplayertitle.tuis.Apis.playerOnly;
public class AllTitles {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = getLastArgsPage(args);
List<TitleDTO> titles = TitleDTO.getAll();
ListView view = ListView.create(10, "/mplt all_titles");
view.title("所有称号");
view.navigator(Line.create()
.append(Button.create("主菜单").setExecuteCommand("/mplt menu").build())
.append("所有称号"));
for (TitleDTO title : titles) {
Line line = Line.create()
.append(title.getId().toString())
.append(title.getTitleColored());
if (player.isOp()) {
line.append(Button.createRed("删除").setExecuteCommand("/mplt delete_title " + title.getId() + " " + page).build());
line.append(Button.createGreen("创建商品").setExecuteCommand("/mplt create_sale " + title.getId()).build());
}
view.add(line);
}
view.showOn(player, page);
}
}

View File

@ -0,0 +1,36 @@
package cn.lunadeer.miniplayertitle.tuis;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Apis {
public static Player playerOnly(CommandSender sender) {
if (!(sender instanceof Player)) {
MiniPlayerTitle.notification.error(sender, "该命令只能由玩家执行");
return null;
}
return (Player) sender;
}
public static int getLastArgsPage(String[] args) {
if (args.length == 0) return 1;
int page = 1;
try {
page = Integer.parseInt(args[args.length - 1]);
} catch (Exception ignored) {
}
return page;
}
public static int getArgPage(String[] args, int pos) {
int page = 1;
if (args.length > pos - 1) {
try {
page = Integer.parseInt(args[pos - 1]);
} catch (Exception ignored) {
}
}
return page;
}
}

View File

@ -0,0 +1,55 @@
package cn.lunadeer.miniplayertitle.tuis;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
import static cn.lunadeer.miniplayertitle.tuis.Apis.playerOnly;
public class CustomInfo {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = getLastArgsPage(args);
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
if (playerInfo == null) {
return;
}
ListView view = ListView.create(10, "/mplt custom_info");
view.title("自定义称号帮助");
view.navigator(Line.create()
.append(Button.create("主菜单").setExecuteCommand("/mplt menu").build())
.append("自定义称号"));
Line line_1 = Line.create()
.append("称号币余额:").append(playerInfo.getCoin().toString());
Line line_2 = Line.create()
.append("自定义称号状态:")
.append(MiniPlayerTitle.config.isEnableCustom() ? "开启" : "关闭");
Line line_3 = Line.create()
.append("自定义称号花费:").append(MiniPlayerTitle.config.getCustomCost().toString());
Line line_4 = Line.create()
.append("自定义称号最大长度(不含颜色代码):").append(MiniPlayerTitle.config.getMaxLength().toString());
Line line_5 = Line.create()
.append("自定义方法:")
.append("在聊天框输入 /mplt custom <称号>");
Line line_6 = Line.create()
.append("可以使用 Minecraft渐变颜色生成器 来生成具有渐变效果的称号")
.append(Button.create("点击在浏览器中打开生成器").setOpenURL("https://ssl.lunadeer.cn:14440/").build());
view.add(line_1);
view.add(line_2);
view.add(line_3);
view.add(line_4);
view.add(line_5);
view.add(line_6);
view.showOn(player, page);
}
}

View File

@ -0,0 +1,50 @@
package cn.lunadeer.miniplayertitle.tuis;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
import static cn.lunadeer.miniplayertitle.tuis.Apis.playerOnly;
public class Menu {
public static void show(CommandSender sender, String[] args) {
int page = getLastArgsPage(args);
Player player = playerOnly(sender);
if (player == null) return;
Line backpack = Line.create()
.append(Button.create("称号背包").setExecuteCommand("/mplt my_titles").build()).append("查看你拥有的称号");
Line shop = Line.create()
.append(Button.create("称号商店").setExecuteCommand("/mplt shop").build()).append("购买在售称号");
Line custom = Line.create()
.append(Button.create("自定义称号").setExecuteCommand("/mplt custom_info").build()).append("查看如何自定义称号");
Line manual = Line.create()
.append(Button.create("帮助文档").setOpenURL("https://ssl.lunadeer.cn:14448/doc/2/").build()).append("在浏览器打开帮助文档");
ListView view = ListView.create(10, "/mplt");
view.title("称号系统")
.navigator(Line.create().append("主菜单"))
.add(backpack)
.add(shop)
.add(manual);
if (MiniPlayerTitle.config.isEnableCustom()) {
view.add(custom);
}
Line all = Line.create()
.append(Button.create("所有称号").setExecuteCommand("/mplt all_titles").build()).append("查看所有称号");
if (player.isOp()) {
view.add(Line.create().append(""));
view.add(Line.create().append("---以下选项仅OP可见---"));
view.add(all);
}
view.showOn(player, page);
}
}

View File

@ -0,0 +1,16 @@
package cn.lunadeer.miniplayertitle.tuis;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
import static cn.lunadeer.miniplayertitle.tuis.Apis.playerOnly;
public class MyTitles {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = getLastArgsPage(args);
// todo
}
}

View File

@ -0,0 +1,126 @@
package cn.lunadeer.miniplayertitle.tuis;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import cn.lunadeer.minecraftpluginutils.stui.components.NumChanger;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.time.LocalDateTime;
import static cn.lunadeer.miniplayertitle.tuis.Apis.*;
public class SaleInfo {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = getArgPage(args, 3);
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
if (titleShop == null) {
MiniPlayerTitle.notification.error(player, "获取详情时出现错误");
return;
}
TitleDTO title = titleShop.getTitle();
if (title == null) {
MiniPlayerTitle.notification.error(player, "获取详情时出现错误");
return;
}
int now_year = LocalDateTime.now().getYear();
int now_month = LocalDateTime.now().getMonthValue();
int now_day = LocalDateTime.now().getDayOfMonth();
ListView view = ListView.create(10, "/mplt sale_info " + args[1]);
view.title("销售详情");
view.navigator(Line.create()
.append(Button.create("主菜单").setExecuteCommand("/mplt menu").build())
.append(Button.create("称号商店").setExecuteCommand("/mplt shop").build())
.append("销售详情"));
view.add(Line.create().append("内容: ").append(titleShop.getTitle().getTitleColored()));
view.add(Line.create().append("描述: ").append(titleShop.getTitle().getDescription()));
Line price = Line.create().append("价格: ");
if (titleShop.getPrice() <= 0) {
price.append("免费");
if (player.isOp()) {
price.append(Button.create("设置价格").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 100 " + page).build());
}
} else {
if (player.isOp()) {
price.append(NumChanger.create(titleShop.getPrice(), "/mplt set_sale price " + titleShop.getId()).setPageNumber(page).build());
price.append(Button.create("设置为免费").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 0 " + page).build());
} else {
price.append(titleShop.getPrice().toString());
}
}
view.add(price);
Line day = Line.create().append("购买天数: ");
if (titleShop.getDays() <= 0) {
day.append("永久");
if (player.isOp()) {
day.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " 7 " + page).build());
}
} else {
if (player.isOp()) {
day.append(NumChanger.create(titleShop.getDays(), "/mplt set_sale days " + titleShop.getId()).setPageNumber(page).build());
day.append(Button.create("转为永久").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " -1 " + page).build());
} else {
day.append(titleShop.getDays().toString());
}
}
view.add(day);
Line amount = Line.create().append("剩余数量: ");
if (titleShop.getAmount() == -1) {
amount.append("无限");
if (player.isOp()) {
amount.append(Button.create("转为限量").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " 0 " + page).build());
}
} else {
if (player.isOp()) {
amount.append(NumChanger.create(titleShop.getAmount(), "/mplt set_sale amount " + titleShop.getId()).setPageNumber(page).build());
amount.append(Button.create("转为无限").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " -1 " + page).build());
} else {
amount.append(titleShop.getAmount().toString());
}
}
view.add(amount);
Line end_at = Line.create().append("售卖结束时间: ");
if (titleShop.getSaleEndAtY() == -1 || titleShop.getSaleEndAtM() == -1 || titleShop.getSaleEndAtD() == -1) {
end_at.append("常驻");
if (player.isOp()) {
end_at.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale end_at " + titleShop.getId() + " " + now_year + ":" + now_month + ":" + now_day + " " + page).build());
}
} else {
if (player.isOp()) {
end_at.append(NumChanger.create(titleShop.getSaleEndAtY(), "/mplt set_sale end_at_y " + titleShop.getId()).setPageNumber(page).build().append(Component.text("")));
end_at.append(NumChanger.create(titleShop.getSaleEndAtM(), "/mplt set_sale end_at_m " + titleShop.getId()).setPageNumber(page).build().append(Component.text("")));
end_at.append(NumChanger.create(titleShop.getSaleEndAtD(), "/mplt set_sale end_at_d " + titleShop.getId()).setPageNumber(page).build().append(Component.text("")));
end_at.append(Button.create("转为常驻").setExecuteCommand("/mplt set_sale end_at " + titleShop.getId() + " -1:-1:-1 " + page).build());
} else {
end_at.append(titleShop.getSaleEndAtY() + "" + titleShop.getSaleEndAtM() + "" + titleShop.getSaleEndAtD() + "");
}
}
view.add(end_at);
Line operate = Line.create().append("操作: ");
if (titleShop.getSaleEndAtY() != -1 && titleShop.getSaleEndAtM() != -1 && titleShop.getSaleEndAtD() != -1
&& (now_year > titleShop.getSaleEndAtY() || (now_year == titleShop.getSaleEndAtY() && now_month > titleShop.getSaleEndAtM()) || (now_year == titleShop.getSaleEndAtY() && now_month == titleShop.getSaleEndAtM() && now_day > titleShop.getSaleEndAtD()))) {
operate.append(Button.createRed("已过期").build());
} else if (titleShop.getAmount() == 0) {
operate.append(Button.createRed("已售罄").build());
} else {
operate.append(Button.createGreen("购买").setExecuteCommand("/mplt buy_title " + args[1]).build());
}
if (player.isOp()) {
operate.append(Button.create("删除").setExecuteCommand("/mplt delete_sale " + args[1] + " " + page).build());
}
view.showOn(player, page);
}
}

View File

@ -0,0 +1,45 @@
package cn.lunadeer.miniplayertitle.tuis;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
import static cn.lunadeer.miniplayertitle.tuis.Apis.playerOnly;
public class Shop {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = getLastArgsPage(args);
List<TitleShopDTO> titles = TitleShopDTO.getAll();
ListView view = ListView.create(10, "/mplt shop");
view.title("称号商店");
view.navigator(Line.create()
.append(Button.create("主菜单").setExecuteCommand("/mplt menu").build())
.append("称号商店"));
for (TitleShopDTO title : titles) {
if (title == null) {
continue;
}
if (title.getTitle().getId() == -1) {
continue;
}
Line line = Line.create()
.append(title.getTitle().getTitleColored())
.append(Button.createGreen("详情").setExecuteCommand("/mplt sale_info " + title.getId()).build());
view.add(line);
}
view.showOn(player, page);
}
}

View File

@ -119,15 +119,9 @@ public class ConfigManager {
return _max_length;
}
public void enableCustom(){
public void setCustom(boolean enable) {
_enable_custom = true;
_file.set("CustomCost.Enabled", true);
_plugin.saveConfig();
}
public void disableCustom(){
_enable_custom = false;
_file.set("CustomCost.Enabled", false);
_file.set("CustomCost.Enabled", enable);
_plugin.saveConfig();
}

View File

@ -75,11 +75,38 @@ public class DatabaseTables {
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "created_at");
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "updated_at");
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title", "enabled");
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "created_at");
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "updated_at");
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "created_at");
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_info", "updated_at");
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "created_at");
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "updated_at");
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_y", "INTEGER NOT NULL DEFAULT -1");
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_m", "INTEGER NOT NULL DEFAULT -1");
MiniPlayerTitle.database.addColumnIfNotExists("mplt_title_shop", "sale_end_at_d", "INTEGER NOT NULL DEFAULT -1");
// convert sale_end_at(YYYYMMDD) to sale_end_at_y, sale_end_at_m, sale_end_at_d
sql = "UPDATE mplt_title_shop SET " +
"sale_end_at_y = (sale_end_at / 10000), " +
"sale_end_at_m = (sale_end_at % 10000 / 100), " +
"sale_end_at_d = (sale_end_at % 100) " +
"WHERE sale_end_at != -1;";
MiniPlayerTitle.database.query(sql);
MiniPlayerTitle.database.deleteColumnIfExists("mplt_title_shop", "sale_end_at");
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_y", "INTEGER NOT NULL DEFAULT -1");
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_m", "INTEGER NOT NULL DEFAULT -1");
MiniPlayerTitle.database.addColumnIfNotExists("mplt_player_title", "expire_at_d", "INTEGER NOT NULL DEFAULT -1");
sql = "UPDATE mplt_player_title SET " +
"expire_at_y = (expire_at / 10000), " +
"expire_at_m = (expire_at % 10000 / 100), " +
"expire_at_d = (expire_at % 100) " +
"WHERE expire_at != -1;";
MiniPlayerTitle.database.query(sql);
MiniPlayerTitle.database.deleteColumnIfExists("mplt_player_title", "expire_at");
}
}