This commit is contained in:
parent
f714526248
commit
7e540d1fe5
@ -65,6 +65,9 @@ public class Commands implements TabExecutor {
|
||||
case "set_desc":
|
||||
TitleManage.setTitleDescription(sender, args);
|
||||
break;
|
||||
case "custom_title":
|
||||
TitleManage.customTitle(sender, args);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cn.lunadeer.miniplayertitle.commands;
|
||||
|
||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
|
||||
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
|
||||
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
||||
import cn.lunadeer.miniplayertitle.tuis.AllTitles;
|
||||
import cn.lunadeer.miniplayertitle.tuis.MyTitles;
|
||||
@ -48,7 +49,16 @@ public class TitleManage {
|
||||
MiniPlayerTitle.notification.warn(sender, "用法: /mplt delete_title <称号ID>");
|
||||
return;
|
||||
}
|
||||
TitleDTO.delete(Integer.parseInt(args[1]));
|
||||
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
|
||||
if (title == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "称号不存在");
|
||||
return;
|
||||
}
|
||||
boolean success = title.delete();
|
||||
if (!success) {
|
||||
MiniPlayerTitle.notification.error(sender, "删除称号失败,具体请查看控制台日志");
|
||||
return;
|
||||
}
|
||||
MiniPlayerTitle.notification.info(sender, "已删除称号");
|
||||
if (args.length == 3) {
|
||||
int page = Integer.parseInt(args[2]);
|
||||
@ -155,4 +165,55 @@ public class TitleManage {
|
||||
MyTitles.show(sender, new String[]{"my_titles", String.valueOf(page)});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建自定义称号
|
||||
* mplt custom_title <称号>
|
||||
*
|
||||
* @param sender CommandSender
|
||||
* @param args String[]
|
||||
*/
|
||||
public static void customTitle(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
MiniPlayerTitle.notification.error(sender, "该命令只能由玩家执行");
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (!MiniPlayerTitle.config.isEnableCustom()) {
|
||||
MiniPlayerTitle.notification.error(sender, "自定义称号功能已关闭");
|
||||
return;
|
||||
}
|
||||
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
|
||||
if (playerInfo == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "获取玩家信息时出现错误");
|
||||
return;
|
||||
}
|
||||
if (MiniPlayerTitle.config.getCustomCost() > playerInfo.getCoin()) {
|
||||
MiniPlayerTitle.notification.error(sender, "称号币不足");
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
MiniPlayerTitle.notification.warn(sender, "用法: /mplt custom_title <称号>");
|
||||
return;
|
||||
}
|
||||
TitleDTO title = TitleDTO.create(args[1], player.getName() + "的自定义称号");
|
||||
if (title == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "创建称号失败,具体请查看控制台日志");
|
||||
return;
|
||||
}
|
||||
if (title.getTitlePlainText().length() > MiniPlayerTitle.config.getMaxLength()) {
|
||||
MiniPlayerTitle.notification.error(sender, "称号长度超过限制");
|
||||
title.delete();
|
||||
return;
|
||||
}
|
||||
PlayerTitleDTO created_rec = PlayerTitleDTO.create(player.getUniqueId(), title, null);
|
||||
if (created_rec == null) {
|
||||
MiniPlayerTitle.notification.error(sender, "创建称号记录失败,具体请查看控制台日志");
|
||||
title.delete();
|
||||
return;
|
||||
}
|
||||
playerInfo.setCoin(playerInfo.getCoin() - MiniPlayerTitle.config.getCustomCost());
|
||||
MiniPlayerTitle.notification.info(sender, "成功创建自定义称号");
|
||||
MyTitles.show(sender, new String[]{"my_titles"});
|
||||
}
|
||||
}
|
||||
|
@ -41,13 +41,11 @@ public class TitleDTO {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean delete(int id) {
|
||||
public boolean delete() {
|
||||
String sql = "";
|
||||
sql += "DELETE FROM mplt_title WHERE id = ?;";
|
||||
try (ResultSet rs = MiniPlayerTitle.database.query(sql, id)) {
|
||||
if (rs != null && rs.next()) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
MiniPlayerTitle.database.handleDatabaseError("删除称号失败", e, sql);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class CustomInfo {
|
||||
.append("自定义称号最大长度(不含颜色代码):").append(MiniPlayerTitle.config.getMaxLength().toString());
|
||||
Line line_5 = Line.create()
|
||||
.append("自定义方法:")
|
||||
.append("在聊天框输入 /mplt custom <称号>");
|
||||
.append("在聊天框输入 /mplt custom_title <称号>");
|
||||
Line line_6 = Line.create()
|
||||
.append("可以使用 Minecraft渐变颜色生成器 来生成具有渐变效果的称号")
|
||||
.append(Button.create("点击在浏览器中打开生成器").setOpenURL("https://ssl.lunadeer.cn:14440/").build());
|
||||
|
Loading…
Reference in New Issue
Block a user