rename project

This commit is contained in:
zhangyuheng 2024-01-09 01:30:03 +08:00
parent 7b41d0f591
commit 52805b0720
22 changed files with 256 additions and 251 deletions

View File

@ -1,2 +1,2 @@
# NewbTitle
# MiniPlayerTitle

View File

@ -5,11 +5,11 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cn.lunadeer</groupId>
<artifactId>NewbTitle</artifactId>
<version>0.36-alpha</version>
<artifactId>MiniPlayerTitle</artifactId>
<version>1.2-beta</version>
<packaging>jar</packaging>
<name>NewbTitle</name>
<name>MiniPlayerTitle</name>
<properties>
<java.version>1.8</java.version>

View File

@ -1,6 +1,6 @@
package cn.lunadeer.newbtitle;
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.newbtitle.utils.XLogger;
import cn.lunadeer.miniplayertitle.utils.XLogger;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;

View File

@ -1,8 +1,8 @@
package cn.lunadeer.newbtitle;
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.newbtitle.commands.AdminCommands;
import cn.lunadeer.newbtitle.utils.Notification;
import cn.lunadeer.newbtitle.utils.XLogger;
import cn.lunadeer.miniplayertitle.commands.AdminCommands;
import cn.lunadeer.miniplayertitle.utils.Notification;
import cn.lunadeer.miniplayertitle.utils.XLogger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@ -15,7 +15,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static cn.lunadeer.newbtitle.commands.PlayerCommands.*;
import static cn.lunadeer.miniplayertitle.commands.PlayerCommands.*;
public class Commands implements TabExecutor {
/**
@ -33,7 +33,7 @@ public class Commands implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
switch (label) {
case "nt":
case "mplt":
if (args.length == 0) {
printHelp(sender);
return true;
@ -79,13 +79,13 @@ public class Commands implements TabExecutor {
private void printHelp(@NotNull CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
Notification.warn(player, "用法: /nt <use|list|shop|buy>");
if (player.isOp()){
Notification.warn(player, "用法: /nt <create|delete|setdesc|setname|addshop|removeshop|setprice|setamount|setendat|listall>");
Notification.warn(player, "用法: /mplt <use|list|shop|buy>");
if (player.isOp()) {
Notification.warn(player, "用法: /mplt <create|delete|setdesc|setname|addshop|removeshop|setprice|setamount|setendat|listall>");
}
} else {
XLogger.info("用法: /nt <use|list|shop|buy>");
XLogger.info("用法: /nt <create|delete|setdesc|setname|addshop|removeshop|setprice|setamount|setendat|listall>");
} else {
XLogger.info("用法: /mplt <use|list|shop|buy>");
XLogger.info("用法: /mplt <create|delete|setdesc|setname|addshop|removeshop|setprice|setamount|setendat|listall>");
}
}
@ -104,57 +104,53 @@ public class Commands implements TabExecutor {
*/
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
switch (label) {
case "nt":
if (args.length == 0) {
String[] player_cmd = {"use", "list", "shop", "buy"};
String[] admin_cmd = {"create", "delete", "setdesc", "setname", "addshop", "removeshop", "setprice", "setamount", "setendat", "listall"};
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 == 1) {
String[] player_cmd = {"use", "list", "shop", "buy"};
String[] admin_cmd = {"create", "delete", "setdesc", "setname", "addshop", "removeshop", "setprice", "setamount", "setendat", "listall"};
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));
}
switch (args[0]) {
case "use":
return Collections.singletonList("要使用的称号ID");
case "list":
case "shop":
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> <结束时间戳>(-1为永久)");
default:
return Arrays.asList("use", "list", "shop", "buy");
}
default:
return null;
} else {
res.addAll(Arrays.asList(player_cmd));
res.addAll(Arrays.asList(admin_cmd));
}
return res;
}
switch (args[0]) {
case "use":
return Collections.singletonList("要使用的称号ID");
case "list":
case "shop":
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> <结束时间戳>(-1为永久)");
default:
return Arrays.asList("use", "list", "shop", "buy");
}
}

View File

@ -1,4 +1,4 @@
package cn.lunadeer.newbtitle;
package cn.lunadeer.miniplayertitle;
import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.text.Component;
@ -27,14 +27,15 @@ public class Events implements Listener {
.append(chatComponent).build();
event.setCancelled(true);
event.getPlayer().getServer().sendMessage(newChatComponent);
} else {
Component titleComponent = title.getTitle();
Component newChatComponent = Component.text().append(titleComponent)
.append(Component.text("<"))
.append(nameComponent)
.append(Component.text("> "))
.append(chatComponent).build();
event.setCancelled(true);
event.getPlayer().getServer().sendMessage(newChatComponent);
}
Component titleComponent = title.getTitle();
Component newChatComponent = Component.text().append(titleComponent)
.append(Component.text("<"))
.append(nameComponent)
.append(Component.text("> "))
.append(chatComponent).build();
event.setCancelled(true);
event.getPlayer().getServer().sendMessage(newChatComponent);
}
}

View File

@ -1,14 +1,14 @@
package cn.lunadeer.newbtitle;
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.newbtitle.utils.ConfigManager;
import cn.lunadeer.newbtitle.utils.Database;
import cn.lunadeer.newbtitle.utils.XLogger;
import cn.lunadeer.miniplayertitle.utils.ConfigManager;
import cn.lunadeer.miniplayertitle.utils.Database;
import cn.lunadeer.miniplayertitle.utils.XLogger;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Objects;
public final class NewbTitle extends JavaPlugin {
public final class MiniPlayerTitle extends JavaPlugin {
@Override
public void onEnable() {
@ -18,8 +18,8 @@ public final class NewbTitle extends JavaPlugin {
Database.migrate();
Bukkit.getPluginManager().registerEvents(new Events(), this);
Objects.requireNonNull(Bukkit.getPluginCommand("NewbTitle")).setExecutor(new Commands());
Objects.requireNonNull(Bukkit.getPluginCommand("NewbTitle")).setTabCompleter(new Commands());
Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setExecutor(new Commands());
Objects.requireNonNull(Bukkit.getPluginCommand("MiniPlayerTitle")).setTabCompleter(new Commands());
XLogger.info("NewbTitle 称号插件已加载");
}
@ -29,6 +29,6 @@ public final class NewbTitle extends JavaPlugin {
// Plugin shutdown logic
}
public static NewbTitle instance;
public static MiniPlayerTitle instance;
public static ConfigManager config;
}

View File

@ -1,6 +1,6 @@
package cn.lunadeer.newbtitle;
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.newbtitle.utils.Database;
import cn.lunadeer.miniplayertitle.utils.Database;
import java.sql.ResultSet;
import java.util.UUID;
@ -17,15 +17,15 @@ public class PlayerTitle extends Title {
public static PlayerTitle create(Integer title_id, UUID player_uuid) {
String sql = "";
sql += "INSERT INTO nt_player_title (title_id, player_uuid, expire_at) ";
sql += "VALUES (" + title_id + ", '" + player_uuid.toString() + "', -1) ";
sql += "INSERT INTO mplt_player_title (title_id, player_uuid, expire_at) ";
sql += "VALUES (" + title_id + ", '" + player_uuid.toString() + "', " + System.currentTimeMillis() + ") ";
sql += "RETURNING id;";
try (ResultSet rs = Database.query(sql)) {
if (rs != null && rs.next()) {
return new PlayerTitle(title_id, player_uuid, -1L);
}
} catch (Exception e) {
cn.lunadeer.newbtitle.utils.XLogger.err("PlayerTitle create failed: " + e.getMessage());
cn.lunadeer.miniplayertitle.utils.XLogger.err("PlayerTitle create failed: " + e.getMessage());
}
return null;
}
@ -59,7 +59,7 @@ public class PlayerTitle extends Title {
private void save() {
String sql = "";
sql += "UPDATE nt_player_title ";
sql += "UPDATE mplt_player_title ";
sql += "SET expire_at = " + this._expire_at + ", ";
sql += "updated_at = CURRENT_TIMESTAMP ";
sql += "WHERE player_uuid = '" + _player_uuid.toString() + "', ";

View File

@ -1,8 +1,8 @@
package cn.lunadeer.newbtitle;
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.newbtitle.utils.Database;
import cn.lunadeer.newbtitle.utils.XLogger;
import cn.lunadeer.miniplayertitle.utils.Database;
import cn.lunadeer.miniplayertitle.utils.XLogger;
import java.sql.ResultSet;
@ -25,7 +25,7 @@ public class SaleTitle extends Title {
public static SaleTitle create(Integer title_id) {
String sql = "";
sql += "INSERT INTO nt_title_shop (title_id, price, days, amount, sale_end_at) ";
sql += "INSERT INTO mplt_title_shop (title_id, price, days, amount, sale_end_at) ";
sql += "VALUES (" + title_id + ", 0, 0, 0, -1) ";
sql += "RETURNING id;";
try (ResultSet rs = Database.query(sql)) {
@ -109,9 +109,13 @@ public class SaleTitle extends Title {
}
}
public Integer getSaleId(){
return this._sale_id;
}
private void save() {
String sql = "";
sql += "UPDATE nt_title_shop ";
sql += "UPDATE mplt_title_shop ";
sql += "SET title_id = " + this._id + ", ";
sql += "price = " + this._price + ", ";
sql += "days = " + this._days + ", ";

View File

@ -1,14 +1,13 @@
package cn.lunadeer.newbtitle;
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.newbtitle.utils.Database;
import cn.lunadeer.newbtitle.utils.Notification;
import cn.lunadeer.newbtitle.utils.STUI.Button;
import cn.lunadeer.newbtitle.utils.STUI.Line;
import cn.lunadeer.newbtitle.utils.STUI.View;
import cn.lunadeer.newbtitle.utils.XLogger;
import cn.lunadeer.miniplayertitle.utils.Database;
import cn.lunadeer.miniplayertitle.utils.Notification;
import cn.lunadeer.miniplayertitle.utils.STUI.Button;
import cn.lunadeer.miniplayertitle.utils.STUI.Line;
import cn.lunadeer.miniplayertitle.utils.STUI.View;
import cn.lunadeer.miniplayertitle.utils.XLogger;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -20,9 +19,9 @@ public class Shop {
public static void open(CommandSender sender, Integer page) {
Map<Integer, SaleTitle> titles = getSaleTitles();
if (!(sender instanceof Player)) {
for (Integer title_sale_id : titles.keySet()) {
SaleTitle title = titles.get(title_sale_id);
XLogger.info("[" + title_sale_id + "] " + title.getTitle().toString() + " price:" + title.getPrice() + " days:" + title.getDays() + " amount:" + title.getAmount());
for (SaleTitle title : titles.values()) {
Notification.info(sender, "[" + title.getSaleId() + "]");
Notification.info(sender, title.getTitle());
}
return;
}
@ -34,6 +33,7 @@ public class Shop {
}
View view = View.create();
view.title("称号商店");
view.subtitle("当前余额: " + XPlayer.getCoin(player) + "金币");
for (int i = offset; i < offset + 4; i++) {
if (i >= titles.size()) {
break;
@ -42,22 +42,22 @@ public class Shop {
TextComponent idx = Component.text("[" + title_sale_id + "] ");
SaleTitle title = titles.get(title_sale_id);
Line line = Line.create();
Component button = Button.create("购买", "/nt buy " + title_sale_id);
Component button = Button.create("购买", "/mplt buy " + title_sale_id);
line.append(idx)
.append(title.getTitle())
.append("价格:" + title.getPrice() + " 有效期:" + title.getDays() + "")
.append("价格:" + title.getPrice() + " 有效期:" + (title.getDays()==-1?"永久":title.getDays() + ""))
.append("售卖截止:" + title.getSaleEndAt())
.append("剩余:" + ((title.getAmount() == -1) ? "无限" : title.getAmount()))
.append(button);
view.set(i, line);
}
view.set(View.Slot.ACTIONBAR, View.pagination(page, titles.size(), "/nt shop"));
view.set(View.Slot.ACTIONBAR, View.pagination(page, titles.size(), "/mplt shop"));
view.showOn(player);
}
public static void deleteTitle(Integer id) {
String sql = "";
sql += "DELETE FROM nt_title_shop WHERE id = " + id + ";";
sql += "DELETE FROM mplt_title_shop WHERE id = " + id + ";";
Database.query(sql);
}
@ -70,7 +70,7 @@ public class Shop {
sql += "days, ";
sql += "amount, ";
sql += "sale_end_at ";
sql += "FROM nt_title_shop;";
sql += "FROM mplt_title_shop;";
Map<Integer, SaleTitle> titles = new HashMap<>();
try (ResultSet rs = Database.query(sql)) {
while (rs != null && rs.next()) {
@ -88,31 +88,4 @@ public class Shop {
}
return titles;
}
public static SaleTitle getSaleTitle(Integer sale_id) {
String sql = "";
sql += "SELECT ";
sql += "id, ";
sql += "title_id, ";
sql += "price, ";
sql += "days, ";
sql += "amount, ";
sql += "sale_end_at ";
sql += "FROM nt_title_shop ";
sql += "WHERE id = " + sale_id + ";";
try (ResultSet rs = Database.query(sql)) {
if (rs != null && rs.next()) {
Integer id = rs.getInt("id");
Integer title_id = rs.getInt("title_id");
Integer price = rs.getInt("price");
Integer days = rs.getInt("days");
Integer amount = rs.getInt("amount");
Long sale_end_at = rs.getLong("sale_end_at");
return new SaleTitle(id, title_id, price, days, amount, sale_end_at);
}
} catch (Exception e) {
XLogger.err("XPlayer getTitles failed: " + e.getMessage());
}
return null;
}
}

View File

@ -1,14 +1,13 @@
package cn.lunadeer.newbtitle;
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.newbtitle.utils.Database;
import cn.lunadeer.newbtitle.utils.Notification;
import cn.lunadeer.newbtitle.utils.STUI.Line;
import cn.lunadeer.newbtitle.utils.STUI.View;
import cn.lunadeer.newbtitle.utils.XLogger;
import cn.lunadeer.miniplayertitle.utils.Database;
import cn.lunadeer.miniplayertitle.utils.Notification;
import cn.lunadeer.miniplayertitle.utils.STUI.Line;
import cn.lunadeer.miniplayertitle.utils.STUI.View;
import cn.lunadeer.miniplayertitle.utils.XLogger;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -26,7 +25,7 @@ public class Title {
public static Title create(String title, String description) {
String sql = "";
sql += "INSERT INTO nt_title (title, description, enabled) VALUES (";
sql += "INSERT INTO mplt_title (title, description, enabled) VALUES (";
sql += "'" + title + "', ";
sql += "'" + description + "', ";
sql += "true ";
@ -45,7 +44,7 @@ public class Title {
public static List<Title> all() {
List<Title> titles = new ArrayList<>();
String sql = "";
sql += "SELECT id FROM nt_title;";
sql += "SELECT id FROM mplt_title;";
try (ResultSet rs = Database.query(sql)) {
if (rs != null) {
while (rs.next()) {
@ -63,7 +62,8 @@ public class Title {
List<Title> titles = all();
if (!(sender instanceof Player)) {
for (Title title : titles) {
Notification.info(sender, title.getId() + " " + title.getTitle().toString());
Notification.info(sender, "[" + title.getId() + "]");
Notification.info(sender, title.getTitle());
}
return;
}
@ -84,7 +84,7 @@ public class Title {
line.append(idx).append(titles.get(i).getTitle());
view.set(i, line);
}
view.set(View.Slot.ACTIONBAR, View.pagination(page, titles.size(), "/nt listall"));
view.set(View.Slot.ACTIONBAR, View.pagination(page, titles.size(), "/mplt listall"));
view.showOn(player);
}
@ -92,7 +92,7 @@ public class Title {
this._id = id;
String sql = "";
sql += "SELECT id, title, description, enabled ";
sql += "FROM nt_title ";
sql += "FROM mplt_title ";
sql += "WHERE id = " + id + ";";
try (ResultSet rs = Database.query(sql)) {
if (rs != null && rs.next()) {
@ -107,20 +107,20 @@ public class Title {
public static void delete(Integer id) {
String sql = "";
sql += "DELETE FROM nt_title WHERE id = " + id + ";";
sql += "DELETE FROM mplt_title WHERE id = " + id + ";";
Database.query(sql);
}
private void save() {
String sql = "";
if (this._id == null) {
sql += "INSERT INTO nt_title (title, description, enabled) VALUES (";
sql += "INSERT INTO mplt_title (title, description, enabled) VALUES (";
sql += "'" + this._title + "', ";
sql += "'" + this._description + "', ";
sql += this._enabled + " ";
sql += ");";
} else {
sql += "UPDATE nt_title SET ";
sql += "UPDATE mplt_title SET ";
sql += "title = '" + this._title + "', ";
sql += "description = '" + this._description + "', ";
sql += "enabled = " + this._enabled + " ";
@ -135,8 +135,8 @@ public class Title {
}
public Component getTitle() {
TextComponent prefix = Component.text(NewbTitle.config.getPrefix());
TextComponent suffix = Component.text(NewbTitle.config.getSuffix());
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);

View File

@ -1,14 +1,13 @@
package cn.lunadeer.newbtitle;
package cn.lunadeer.miniplayertitle;
import cn.lunadeer.newbtitle.utils.Database;
import cn.lunadeer.newbtitle.utils.Notification;
import cn.lunadeer.newbtitle.utils.STUI.Button;
import cn.lunadeer.newbtitle.utils.STUI.Line;
import cn.lunadeer.newbtitle.utils.STUI.View;
import cn.lunadeer.newbtitle.utils.XLogger;
import cn.lunadeer.miniplayertitle.utils.Database;
import cn.lunadeer.miniplayertitle.utils.Notification;
import cn.lunadeer.miniplayertitle.utils.STUI.Button;
import cn.lunadeer.miniplayertitle.utils.STUI.Line;
import cn.lunadeer.miniplayertitle.utils.STUI.View;
import cn.lunadeer.miniplayertitle.utils.XLogger;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import org.bukkit.entity.Player;
import java.sql.ResultSet;
@ -56,14 +55,14 @@ public class XPlayer {
PlayerTitle title = titles.get(title_id);
Line line = Line.create();
boolean is_using = Objects.equals(title.getId(), _current_title_id);
Component button = Button.create(is_using ? "卸下" : "使用", "/nt use " + (is_using ? -1 : title.getId()));
Component button = Button.create(is_using ? "卸下" : "使用", "/mplt use " + (is_using ? -1 : title.getId()));
line.append(idx)
.append(title.getTitle())
.append(Component.text("有效期至:" + title.getExpireAt()))
.append(button);
view.set(i, line);
}
view.set(View.Slot.ACTIONBAR, View.pagination(page, titles.size(), "/nt list"));
view.set(View.Slot.ACTIONBAR, View.pagination(page, titles.size(), "/mplt list"));
view.showOn(_player);
}
@ -74,7 +73,7 @@ public class XPlayer {
return;
}
String sql = "";
sql += "UPDATE nt_player_using_title ";
sql += "UPDATE mplt_player_using_title ";
sql += "SET title_id = " + _current_title_id + ", ";
sql += "updated_at = CURRENT_TIMESTAMP ";
sql += "WHERE uuid = '" + _player.getUniqueId().toString() + "';";
@ -103,7 +102,7 @@ public class XPlayer {
public void set_coin(Integer coin) {
_coin = coin;
String sql = "";
sql += "UPDATE nt_player_coin ";
sql += "UPDATE mplt_player_coin ";
sql += "SET coin = " + coin + ", ";
sql += "updated_at = CURRENT_TIMESTAMP ";
sql += "WHERE uuid = '" + _player.getUniqueId().toString() + "';";
@ -114,11 +113,20 @@ public class XPlayer {
set_coin(_coin + coin);
}
public Integer get_coin() {
return _coin;
}
public static Integer getCoin(Player player) {
XPlayer xplayer = new XPlayer(player);
return xplayer.get_coin();
}
private static Map<Integer, PlayerTitle> getTitles(UUID uuid) {
String sql = "";
sql += "SELECT ";
sql += "title_id, expire_at ";
sql += "FROM nt_player_title ";
sql += "FROM mplt_player_title ";
sql += "WHERE player_uuid = '" + uuid.toString() + "';";
Map<Integer, PlayerTitle> titles = new HashMap<>();
try (ResultSet rs = Database.query(sql)) {
@ -137,7 +145,7 @@ public class XPlayer {
private static Integer getCurrentTitleId(UUID uuid) {
String sql = "";
sql += "SELECT title_id ";
sql += "FROM nt_player_using_title ";
sql += "FROM mplt_player_using_title ";
sql += "WHERE uuid = '" + uuid.toString() + "';";
Integer current_title_id = null;
try (ResultSet rs = Database.query(sql)) {
@ -146,7 +154,7 @@ public class XPlayer {
} else {
current_title_id = -1;
sql = "";
sql += "INSERT INTO nt_player_using_title (uuid, title_id) VALUES (";
sql += "INSERT INTO mplt_player_using_title (uuid, title_id) VALUES (";
sql += "'" + uuid + "', ";
sql += current_title_id + ");";
Database.query(sql);
@ -160,7 +168,7 @@ public class XPlayer {
private static Integer getCoin(UUID uuid) {
String sql = "";
sql += "SELECT coin ";
sql += "FROM nt_player_coin ";
sql += "FROM mplt_player_coin ";
sql += "WHERE uuid = '" + uuid.toString() + "';";
Integer coin = null;
try (ResultSet rs = Database.query(sql)) {
@ -169,7 +177,7 @@ public class XPlayer {
} else {
coin = 0;
sql = "";
sql += "INSERT INTO nt_player_coin (uuid, coin) VALUES (";
sql += "INSERT INTO mplt_player_coin (uuid, coin) VALUES (";
sql += "'" + uuid + "', ";
sql += coin + ");";
Database.query(sql);
@ -181,7 +189,7 @@ public class XPlayer {
}
public void buyTitle(SaleTitle title) {
if (title.isSaleExpired()) {
if (title.isSaleExpired() || title.getDays() == 0) {
Notification.error(_player, "此称号已停止销售");
return;
}
@ -211,7 +219,7 @@ public class XPlayer {
if (title_bought.isExpired()) {
title_bought.setExpireAtTimestamp(System.currentTimeMillis() + title.getDays() * 24 * 60 * 60 * 1000L);
Notification.info(_player, title.getTitle());
Notification.info(_player, "称号已重新激活,有效期至 " + title_bought.getExpireAt());
Notification.info(_player, "称号已激活,有效期至 " + title_bought.getExpireAt());
} else {
title_bought.setExpireAtTimestamp(title_bought.getExpireAtTimestamp() + title.getDays() * 24 * 60 * 60 * 1000L);
Notification.info(_player, title.getTitle());

View File

@ -1,9 +1,9 @@
package cn.lunadeer.newbtitle.commands;
package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.newbtitle.SaleTitle;
import cn.lunadeer.newbtitle.Title;
import cn.lunadeer.newbtitle.utils.Notification;
import cn.lunadeer.newbtitle.utils.XLogger;
import cn.lunadeer.miniplayertitle.SaleTitle;
import cn.lunadeer.miniplayertitle.Title;
import cn.lunadeer.miniplayertitle.utils.Notification;
import cn.lunadeer.miniplayertitle.utils.XLogger;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -17,7 +17,7 @@ public class AdminCommands {
}
}
if (args.length != 3) {
Notification.warn(sender, "用法: /nt create <称号名称> <称号描述>");
Notification.warn(sender, "用法: /mplt create <称号名称> <称号描述>");
return true;
}
Title.create(args[1], args[2]);
@ -33,7 +33,7 @@ public class AdminCommands {
}
}
if (args.length != 2) {
Notification.warn(sender, "用法: /nt delete <称号ID>");
Notification.warn(sender, "用法: /mplt delete <称号ID>");
return true;
}
Title.delete(Integer.parseInt(args[1]));
@ -70,7 +70,7 @@ public class AdminCommands {
}
}
if (args.length != 3) {
Notification.warn(sender, "用法: /nt setdesc <称号ID> <称号描述>");
Notification.warn(sender, "用法: /mplt setdesc <称号ID> <称号描述>");
return true;
}
Title title = new Title(Integer.parseInt(args[1]));
@ -87,7 +87,7 @@ public class AdminCommands {
}
}
if (args.length != 3) {
Notification.warn(sender, "用法: /nt setname <称号ID> <称号名称>");
Notification.warn(sender, "用法: /mplt setname <称号ID> <称号名称>");
return true;
}
Title title = new Title(Integer.parseInt(args[1]));
@ -104,7 +104,7 @@ public class AdminCommands {
}
}
if (args.length != 2) {
Notification.warn(sender, "用法: /nt addshop <称号ID>");
Notification.warn(sender, "用法: /mplt addshop <称号ID>");
return true;
}
SaleTitle title = SaleTitle.create(Integer.parseInt(args[1]));
@ -126,7 +126,7 @@ public class AdminCommands {
}
}
if (args.length != 2) {
Notification.warn(sender, "用法: /nt removeshop <商品ID>");
Notification.warn(sender, "用法: /mplt removeshop <商品ID>");
return true;
}
SaleTitle.delete(Integer.parseInt(args[1]));
@ -142,7 +142,7 @@ public class AdminCommands {
}
}
if (args.length != 4) {
Notification.warn(sender, "用法: /nt setprice <商品ID> <价格> <天数>(-1为永久)");
Notification.warn(sender, "用法: /mplt setprice <商品ID> <价格> <天数>(-1为永久)");
return true;
}
SaleTitle.setPrice(Integer.parseInt(args[1]), Integer.parseInt(args[2]));
@ -159,7 +159,7 @@ public class AdminCommands {
}
}
if (args.length != 3) {
Notification.warn(sender, "用法: /nt setamount <商品ID> <数量>(-1为无限)");
Notification.warn(sender, "用法: /mplt setamount <商品ID> <数量>(-1为无限)");
return true;
}
SaleTitle.setAmount(Integer.parseInt(args[1]), Integer.parseInt(args[2]));
@ -175,7 +175,7 @@ public class AdminCommands {
}
}
if (args.length != 3) {
Notification.warn(sender, "用法: /nt setendat <商品ID> <时间YYYYMMDD>(-1为永久)");
Notification.warn(sender, "用法: /mplt setendat <商品ID> <时间YYYYMMDD>(-1为永久)");
return true;
}
long time_stamp;

View File

@ -1,10 +1,10 @@
package cn.lunadeer.newbtitle.commands;
package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.newbtitle.SaleTitle;
import cn.lunadeer.newbtitle.Shop;
import cn.lunadeer.newbtitle.XPlayer;
import cn.lunadeer.newbtitle.utils.Notification;
import cn.lunadeer.newbtitle.utils.XLogger;
import cn.lunadeer.miniplayertitle.SaleTitle;
import cn.lunadeer.miniplayertitle.Shop;
import cn.lunadeer.miniplayertitle.XPlayer;
import cn.lunadeer.miniplayertitle.utils.Notification;
import cn.lunadeer.miniplayertitle.utils.XLogger;
import org.bukkit.command.CommandSender;
public class PlayerCommands {
@ -15,7 +15,7 @@ public class PlayerCommands {
}
org.bukkit.entity.Player player = (org.bukkit.entity.Player) sender;
if (args.length != 2) {
Notification.warn(player, "用法: /nt use <称号ID>");
Notification.warn(player, "用法: /mplt use <称号ID>");
return true;
}
@ -64,12 +64,12 @@ public class PlayerCommands {
}
org.bukkit.entity.Player player = (org.bukkit.entity.Player) sender;
if (args.length != 2) {
Notification.warn(player, "用法: /nt buy <称号ID>");
Notification.warn(player, "用法: /mplt buy <称号ID>");
return true;
}
XPlayer xPlayer = new XPlayer(player);
Integer sale_id = Integer.parseInt(args[1]);
SaleTitle saleTitle = Shop.getSaleTitle(sale_id);
SaleTitle saleTitle = Shop.getSaleTitles().get(sale_id);
if (saleTitle == null) {
Notification.error(player, "该称号不存在");
return true;

View File

@ -1,10 +1,10 @@
package cn.lunadeer.newbtitle.utils;
package cn.lunadeer.miniplayertitle.utils;
import cn.lunadeer.newbtitle.NewbTitle;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import org.bukkit.configuration.file.FileConfiguration;
public class ConfigManager {
public ConfigManager(NewbTitle plugin) {
public ConfigManager(MiniPlayerTitle plugin) {
_plugin = plugin;
_plugin.saveDefaultConfig();
reload();
@ -94,7 +94,7 @@ public class ConfigManager {
}
private final NewbTitle _plugin;
private final MiniPlayerTitle _plugin;
private FileConfiguration _file;
private Boolean _debug;

View File

@ -1,6 +1,6 @@
package cn.lunadeer.newbtitle.utils;
package cn.lunadeer.miniplayertitle.utils;
import cn.lunadeer.newbtitle.NewbTitle;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import java.sql.*;
@ -9,7 +9,7 @@ public class Database {
private static Connection getConnection() {
try {
Class.forName("org.postgresql.Driver");
return DriverManager.getConnection(NewbTitle.config.getDBConnectionUrl(), NewbTitle.config.getDbUser(), NewbTitle.config.getDbPass());
return DriverManager.getConnection(MiniPlayerTitle.config.getDBConnectionUrl(), MiniPlayerTitle.config.getDbUser(), MiniPlayerTitle.config.getDbPass());
} catch (ClassNotFoundException | SQLException e) {
XLogger.err("Database connection failed: " + e.getMessage());
return null;
@ -23,7 +23,12 @@ public class Database {
}
try {
Statement stmt = conn.createStatement();
return stmt.executeQuery(sql);
// if query with no result return null
if (stmt.execute(sql)) {
return stmt.getResultSet();
} else {
return null;
}
} catch (SQLException e) {
XLogger.err("Database query failed: " + e.getMessage());
XLogger.err("SQL: " + sql);
@ -35,7 +40,7 @@ public class Database {
String sql = "";
// title table
sql += "CREATE TABLE IF NOT EXISTS nt_title (" +
sql += "CREATE TABLE IF NOT EXISTS mplt_title (" +
" id SERIAL PRIMARY KEY," +
" title TEXT NOT NULL," +
" description TEXT NOT NULL," +
@ -45,7 +50,7 @@ public class Database {
");";
// title shop table
sql += "CREATE TABLE IF NOT EXISTS nt_title_shop (" +
sql += "CREATE TABLE IF NOT EXISTS mplt_title_shop (" +
" id SERIAL PRIMARY KEY," +
" title_id INTEGER NOT NULL," +
" price INTEGER NOT NULL DEFAULT 0," +
@ -54,11 +59,11 @@ public class Database {
" sale_end_at BIGINT NOT NULL DEFAULT -1," +
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
" FOREIGN KEY (title_id) REFERENCES nt_title(id) ON DELETE CASCADE" +
" FOREIGN KEY (title_id) REFERENCES mplt_title(id) ON DELETE CASCADE" +
");";
// player coin table
sql += "CREATE TABLE IF NOT EXISTS nt_player_coin (" +
sql += "CREATE TABLE IF NOT EXISTS mplt_player_coin (" +
" uuid UUID PRIMARY KEY," +
" coin INTEGER NOT NULL DEFAULT 0," +
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
@ -66,26 +71,26 @@ public class Database {
");";
// player title table
sql += "CREATE TABLE IF NOT EXISTS nt_player_title (" +
sql += "CREATE TABLE IF NOT EXISTS mplt_player_title (" +
" id SERIAL PRIMARY KEY," +
" player_uuid UUID NOT NULL," +
" title_id INTEGER NOT NULL," +
" expire_at BIGINT NOT NULL DEFAULT -1," +
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
" FOREIGN KEY (title_id) REFERENCES nt_title(id) ON DELETE CASCADE" +
" FOREIGN KEY (title_id) REFERENCES mplt_title(id) ON DELETE CASCADE" +
");";
// player using title table
sql += "CREATE TABLE IF NOT EXISTS nt_player_using_title (" +
sql += "CREATE TABLE IF NOT EXISTS mplt_player_using_title (" +
" uuid UUID PRIMARY KEY," +
" title_id INTEGER NOT NULL," +
" created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
" FOREIGN KEY (title_id) REFERENCES nt_title(id) ON DELETE CASCADE" +
" FOREIGN KEY (title_id) REFERENCES mplt_title(id) ON DELETE CASCADE" +
");";
sql += "INSERT INTO nt_title (" +
sql += "INSERT INTO mplt_title (" +
"id, " +
"title, " +
"description," +

View File

@ -1,4 +1,4 @@
package cn.lunadeer.newbtitle.utils;
package cn.lunadeer.miniplayertitle.utils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.Style;
@ -11,51 +11,53 @@ public class Notification {
private static final Style w_style = Style.style(TextColor.color(255, 185, 69));
private static final Style e_style = Style.style(TextColor.color(255, 96, 72));
private static final String prefix = "[MiniPlayerTitle] ";
public static void info(Player player, String msg) {
player.sendMessage(Component.text("[NewbTitle] " + msg, i_style));
player.sendMessage(Component.text(prefix + msg, i_style));
}
public static void warn(Player player, String msg) {
player.sendMessage(Component.text("[NewbTitle] " + msg, w_style));
player.sendMessage(Component.text(prefix + msg, w_style));
}
public static void error(Player player, String msg) {
player.sendMessage(Component.text("[NewbTitle] " + msg, e_style));
player.sendMessage(Component.text(prefix + msg, e_style));
}
public static void info(CommandSender sender, String msg) {
sender.sendMessage(Component.text("[NewbTitle] " + msg, i_style));
sender.sendMessage(Component.text(prefix + msg, i_style));
}
public static void warn(CommandSender sender, String msg) {
sender.sendMessage(Component.text("[NewbTitle] " + msg, w_style));
sender.sendMessage(Component.text(prefix + msg, w_style));
}
public static void error(CommandSender sender, String msg) {
sender.sendMessage(Component.text("[NewbTitle] " + msg, e_style));
sender.sendMessage(Component.text(prefix + msg, e_style));
}
public static void info(Player player, Component msg) {
player.sendMessage(Component.text("[NewbTitle] ", i_style).append(msg));
player.sendMessage(Component.text(prefix, i_style).append(msg));
}
public static void warn(Player player, Component msg) {
player.sendMessage(Component.text("[NewbTitle] " + msg, w_style).append(msg));
player.sendMessage(Component.text(prefix + msg, w_style).append(msg));
}
public static void error(Player player, Component msg) {
player.sendMessage(Component.text("[NewbTitle] " + msg, e_style).append(msg));
player.sendMessage(Component.text(prefix + msg, e_style).append(msg));
}
public static void info(CommandSender player, Component msg) {
player.sendMessage(Component.text("[NewbTitle] ", i_style).append(msg));
player.sendMessage(Component.text(prefix, i_style).append(msg));
}
public static void warn(CommandSender player, Component msg) {
player.sendMessage(Component.text("[NewbTitle] " + msg, w_style).append(msg));
player.sendMessage(Component.text(prefix + msg, w_style).append(msg));
}
public static void error(CommandSender player, Component msg) {
player.sendMessage(Component.text("[NewbTitle] " + msg, e_style).append(msg));
player.sendMessage(Component.text(prefix + msg, e_style).append(msg));
}
}

View File

@ -1,4 +1,4 @@
package cn.lunadeer.newbtitle.utils.STUI;
package cn.lunadeer.miniplayertitle.utils.STUI;
import net.kyori.adventure.text.Component;

View File

@ -1,4 +1,4 @@
package cn.lunadeer.newbtitle.utils.STUI;
package cn.lunadeer.miniplayertitle.utils.STUI;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;

View File

@ -1,8 +1,7 @@
package cn.lunadeer.newbtitle.utils.STUI;
package cn.lunadeer.miniplayertitle.utils.STUI;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.entity.Player;
@ -82,6 +81,21 @@ public class View {
return this;
}
public View title(TextComponent title) {
this.title = title;
return this;
}
public View subtitle(String subtitle) {
this.subtitle = Component.text(subtitle);
return this;
}
public View subtitle(TextComponent subtitle) {
this.subtitle = subtitle;
return this;
}
public View set(Slot line, TextComponent component) {
switch (line) {
case SUBTITLE:

View File

@ -1,17 +1,19 @@
package cn.lunadeer.newbtitle.utils;
package cn.lunadeer.miniplayertitle.utils;
import cn.lunadeer.newbtitle.NewbTitle;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import org.bukkit.entity.Player;
import java.util.logging.Logger;
public class XLogger {
private static final NewbTitle _plugin = NewbTitle.instance;
private static final MiniPlayerTitle _plugin = MiniPlayerTitle.instance;
private static final Logger _logger = _plugin.getLogger();
private static final String prefix = "[MiniPlayerTitle] ";
public static void info(Player player, String message) {
Notification.info(player, "NewbTitle I | " + message);
if (NewbTitle.config.isDebug())
Notification.info(player, prefix + "I | " + message);
if (MiniPlayerTitle.config.isDebug())
debug("来自玩家[ " + player.getName() + " ] 的信息 | " + message);
}
@ -20,8 +22,8 @@ public class XLogger {
}
public static void warn(Player player, String message) {
Notification.warn(player, "NewbTitle W | " + message);
if (NewbTitle.config.isDebug())
Notification.warn(player, prefix + "W | " + message);
if (MiniPlayerTitle.config.isDebug())
debug("来自玩家[ " + player.getName() + " ] 的警告 | " + message);
}
@ -30,8 +32,8 @@ public class XLogger {
}
public static void err(Player player, String message) {
Notification.error(player, "NewbTitle E | " + message);
if (NewbTitle.config.isDebug())
Notification.error(player, prefix + "E | " + message);
if (MiniPlayerTitle.config.isDebug())
debug("来自玩家[ " + player.getName() + " ] 的报错 | " + message);
}
@ -40,15 +42,15 @@ public class XLogger {
}
public static void debug(Player player, String message) {
if (!NewbTitle.config.isDebug()) return;
if (!MiniPlayerTitle.config.isDebug()) return;
if (player.isOp())
Notification.info(player, "NewbTitle D | " + message);
Notification.info(player, prefix + "D | " + message);
else
debug("来自玩家[ " + player.getName() + " ] 的调试 | " + message);
}
public static void debug(String message) {
if (!NewbTitle.config.isDebug()) return;
if (!MiniPlayerTitle.config.isDebug()) return;
_logger.info(" D | " + message);
}
}

View File

@ -1,9 +1,9 @@
Database:
Host: localhost
Port: 5432
Name: newbtitle
User: postgres
Pass: postgres
Name: miniplayertitle
User: miniplayertitle
Pass: miniplayertitle
Prefix: "["
Suffix: "]"

View File

@ -1,12 +1,12 @@
name: NewbTitle
name: MiniPlayerTitle
version: '${project.version}'
main: cn.lunadeer.newbtitle.NewbTitle
main: cn.lunadeer.miniplayertitle.MiniPlayerTitle
api-version: '1.20'
description: 称号插件。
website: https://lunadeer.cn
folia-supported: true
commands:
NewbTitle:
MiniPlayerTitle:
description: 称号插件命令
usage: /nt <cmd>
aliases: [nt]
usage: /mplt <cmd>
aliases: [mplt]