This commit is contained in:
parent
08ea2c9a5a
commit
874d90d2be
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.lunadeer</groupId>
|
<groupId>cn.lunadeer</groupId>
|
||||||
<artifactId>MiniPlayerTitle</artifactId>
|
<artifactId>MiniPlayerTitle</artifactId>
|
||||||
<version>1.2-beta</version>
|
<version>1.12-beta</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>MiniPlayerTitle</name>
|
<name>MiniPlayerTitle</name>
|
||||||
|
@ -2,7 +2,12 @@ package cn.lunadeer.miniplayertitle;
|
|||||||
|
|
||||||
import cn.lunadeer.miniplayertitle.commands.AdminCommands;
|
import cn.lunadeer.miniplayertitle.commands.AdminCommands;
|
||||||
import cn.lunadeer.miniplayertitle.utils.Notification;
|
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 cn.lunadeer.miniplayertitle.utils.XLogger;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
@ -35,7 +40,7 @@ public class Commands implements TabExecutor {
|
|||||||
switch (label) {
|
switch (label) {
|
||||||
case "mplt":
|
case "mplt":
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
printHelp(sender);
|
home_view(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
@ -89,6 +94,21 @@ public class Commands implements TabExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void home_view(CommandSender sender){
|
||||||
|
if (!(sender instanceof Player)){
|
||||||
|
printHelp(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
View view = View.create();
|
||||||
|
view.title("称号系统");
|
||||||
|
Component backpack = Button.create("称号背包", "/mplt list");
|
||||||
|
Component shop = Button.create("称号商店", "/mplt shop");
|
||||||
|
Line line = Line.create();
|
||||||
|
line.append(backpack).append(shop);
|
||||||
|
view.set(View.Slot.ACTIONBAR, line);
|
||||||
|
view.showOn((Player) sender);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests a list of possible completions for a command argument.
|
* Requests a list of possible completions for a command argument.
|
||||||
*
|
*
|
||||||
@ -146,7 +166,7 @@ public class Commands implements TabExecutor {
|
|||||||
case "setamount":
|
case "setamount":
|
||||||
return Collections.singletonList("<商品ID> <数量> (-1为无限)");
|
return Collections.singletonList("<商品ID> <数量> (-1为无限)");
|
||||||
case "setendat":
|
case "setendat":
|
||||||
return Collections.singletonList("<商品ID> <结束时间戳>(-1为永久)");
|
return Collections.singletonList("<商品ID> <结束时间YYYYMMDD>(-1为永久)");
|
||||||
default:
|
default:
|
||||||
return Arrays.asList("use", "list", "shop", "buy");
|
return Arrays.asList("use", "list", "shop", "buy");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.lunadeer.miniplayertitle;
|
package cn.lunadeer.miniplayertitle;
|
||||||
|
|
||||||
import cn.lunadeer.miniplayertitle.utils.Database;
|
import cn.lunadeer.miniplayertitle.utils.Database;
|
||||||
|
import cn.lunadeer.miniplayertitle.utils.Time;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -30,29 +31,25 @@ public class PlayerTitle extends Title {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExpireAt() {
|
public String getExpireAtStr() {
|
||||||
if (this._expire_at == -1L) {
|
if (this._expire_at == -1L) {
|
||||||
return "永久";
|
return "永久";
|
||||||
} else if (this._expire_at < System.currentTimeMillis()) {
|
} else if (this._expire_at < Time.getCurrent()) {
|
||||||
return "已过期";
|
return "已过期";
|
||||||
} else {
|
} else {
|
||||||
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date(this._expire_at));
|
return this._expire_at.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getExpireAtTimestamp() {
|
|
||||||
return this._expire_at;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isExpired() {
|
public Boolean isExpired() {
|
||||||
if (this._expire_at == -1L) {
|
if (this._expire_at == -1L) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return this._expire_at < System.currentTimeMillis();
|
return this._expire_at < Time.getCurrent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExpireAtTimestamp(Long expire_at) {
|
public void setExpireAt(Long expire_at) {
|
||||||
this._expire_at = expire_at;
|
this._expire_at = expire_at;
|
||||||
this.save();
|
this.save();
|
||||||
}
|
}
|
||||||
@ -62,7 +59,7 @@ public class PlayerTitle extends Title {
|
|||||||
sql += "UPDATE mplt_player_title ";
|
sql += "UPDATE mplt_player_title ";
|
||||||
sql += "SET expire_at = " + this._expire_at + ", ";
|
sql += "SET expire_at = " + this._expire_at + ", ";
|
||||||
sql += "updated_at = CURRENT_TIMESTAMP ";
|
sql += "updated_at = CURRENT_TIMESTAMP ";
|
||||||
sql += "WHERE player_uuid = '" + _player_uuid.toString() + "', ";
|
sql += "WHERE player_uuid = '" + _player_uuid.toString() + "' ";
|
||||||
sql += "AND title_id = " + this._id + ";";
|
sql += "AND title_id = " + this._id + ";";
|
||||||
Database.query(sql);
|
Database.query(sql);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package cn.lunadeer.miniplayertitle;
|
|||||||
|
|
||||||
|
|
||||||
import cn.lunadeer.miniplayertitle.utils.Database;
|
import cn.lunadeer.miniplayertitle.utils.Database;
|
||||||
|
import cn.lunadeer.miniplayertitle.utils.Time;
|
||||||
import cn.lunadeer.miniplayertitle.utils.XLogger;
|
import cn.lunadeer.miniplayertitle.utils.XLogger;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -31,7 +32,7 @@ public class SaleTitle extends Title {
|
|||||||
try (ResultSet rs = Database.query(sql)) {
|
try (ResultSet rs = Database.query(sql)) {
|
||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
Integer id = rs.getInt("id");
|
Integer id = rs.getInt("id");
|
||||||
return new SaleTitle(id, title_id, 0, 0, -1, System.currentTimeMillis());
|
return new SaleTitle(id, title_id, 0, 0, 0, -1L);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
XLogger.err("SaleTitle create failed: " + e.getMessage());
|
XLogger.err("SaleTitle create failed: " + e.getMessage());
|
||||||
@ -84,10 +85,10 @@ public class SaleTitle extends Title {
|
|||||||
public String getSaleEndAt() {
|
public String getSaleEndAt() {
|
||||||
if (this._sale_end_at == -1L) {
|
if (this._sale_end_at == -1L) {
|
||||||
return "常驻";
|
return "常驻";
|
||||||
} else if (this._sale_end_at < System.currentTimeMillis()) {
|
} else if (this._sale_end_at < Time.getCurrent()) {
|
||||||
return "已停售";
|
return "已停售";
|
||||||
} else {
|
} else {
|
||||||
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date(this._sale_end_at));
|
return this._sale_end_at.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ public class SaleTitle extends Title {
|
|||||||
if (this._sale_end_at == -1L) {
|
if (this._sale_end_at == -1L) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return this._sale_end_at < System.currentTimeMillis();
|
return this._sale_end_at < Time.getCurrent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import cn.lunadeer.miniplayertitle.utils.Notification;
|
|||||||
import cn.lunadeer.miniplayertitle.utils.STUI.Button;
|
import cn.lunadeer.miniplayertitle.utils.STUI.Button;
|
||||||
import cn.lunadeer.miniplayertitle.utils.STUI.Line;
|
import cn.lunadeer.miniplayertitle.utils.STUI.Line;
|
||||||
import cn.lunadeer.miniplayertitle.utils.STUI.View;
|
import cn.lunadeer.miniplayertitle.utils.STUI.View;
|
||||||
|
import cn.lunadeer.miniplayertitle.utils.Time;
|
||||||
import cn.lunadeer.miniplayertitle.utils.XLogger;
|
import cn.lunadeer.miniplayertitle.utils.XLogger;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
@ -58,7 +59,7 @@ public class XPlayer {
|
|||||||
Component button = Button.create(is_using ? "卸下" : "使用", "/mplt use " + (is_using ? -1 : title.getId()));
|
Component button = Button.create(is_using ? "卸下" : "使用", "/mplt use " + (is_using ? -1 : title.getId()));
|
||||||
line.append(idx)
|
line.append(idx)
|
||||||
.append(title.getTitle())
|
.append(title.getTitle())
|
||||||
.append(Component.text("有效期至:" + title.getExpireAt()))
|
.append(Component.text("有效期至:" + title.getExpireAtStr()))
|
||||||
.append(button);
|
.append(button);
|
||||||
view.set(i, line);
|
view.set(i, line);
|
||||||
}
|
}
|
||||||
@ -69,15 +70,16 @@ public class XPlayer {
|
|||||||
public void updateUsingTitle(Integer title_id) {
|
public void updateUsingTitle(Integer title_id) {
|
||||||
_current_title_id = title_id;
|
_current_title_id = title_id;
|
||||||
checkTitleValid();
|
checkTitleValid();
|
||||||
if (_current_title_id == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String sql = "";
|
String sql = "";
|
||||||
sql += "UPDATE mplt_player_using_title ";
|
sql += "UPDATE mplt_player_using_title ";
|
||||||
sql += "SET title_id = " + _current_title_id + ", ";
|
sql += "SET title_id = " + _current_title_id + ", ";
|
||||||
sql += "updated_at = CURRENT_TIMESTAMP ";
|
sql += "updated_at = CURRENT_TIMESTAMP ";
|
||||||
sql += "WHERE uuid = '" + _player.getUniqueId().toString() + "';";
|
sql += "WHERE uuid = '" + _player.getUniqueId().toString() + "';";
|
||||||
Database.query(sql);
|
Database.query(sql);
|
||||||
|
if (_current_title_id == -1) {
|
||||||
|
Notification.info(_player, "成功卸下称号");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Notification.info(_player, "成功使用称号: ");
|
Notification.info(_player, "成功使用称号: ");
|
||||||
Notification.info(_player, _titles.get(_current_title_id).getTitle());
|
Notification.info(_player, _titles.get(_current_title_id).getTitle());
|
||||||
}
|
}
|
||||||
@ -201,30 +203,35 @@ public class XPlayer {
|
|||||||
Notification.error(_player, "你的余额不足");
|
Notification.error(_player, "你的余额不足");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!_titles.containsKey(title.getId())) {
|
PlayerTitle title_bought = null;
|
||||||
_titles.put(title.getId(), PlayerTitle.create(title.getId(), _player.getUniqueId()));
|
if (_titles.containsKey(title.getId())) {
|
||||||
} else if (_titles.get(title.getId()).getExpireAtTimestamp() == -1) {
|
if (!_titles.get(title.getId()).isExpired()) {
|
||||||
Notification.warn(_player, "你已经拥有此称号");
|
Notification.warn(_player, "你已经拥有此称号");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlayerTitle title_bought = _titles.get(title.getId());
|
title_bought = _titles.get(title.getId());
|
||||||
|
} else {
|
||||||
|
title_bought = PlayerTitle.create(title.getId(), _player.getUniqueId());
|
||||||
|
}
|
||||||
|
if (title_bought == null) {
|
||||||
|
Notification.error(_player, "购买失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
set_coin(_coin - title.getPrice());
|
set_coin(_coin - title.getPrice());
|
||||||
SaleTitle.setAmount(title.getId(), title.getAmount() - 1);
|
SaleTitle.setAmount(title.getId(), title.getAmount() - 1);
|
||||||
Notification.info(_player, "成功购买称号: ");
|
Notification.info(_player, "成功购买称号: ");
|
||||||
Notification.info(_player, title.getTitle());
|
Notification.info(_player, title.getTitle());
|
||||||
|
|
||||||
if (title.getDays() == -1) {
|
if (title.getDays() == -1) {
|
||||||
title_bought.setExpireAtTimestamp(-1L);
|
title_bought.setExpireAt(-1L);
|
||||||
|
Notification.info(_player, "称号已购买至永久");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (title_bought.isExpired()) {
|
Long timestamp = System.currentTimeMillis() + title.getDays() * 24 * 60 * 60 * 1000L;
|
||||||
title_bought.setExpireAtTimestamp(System.currentTimeMillis() + title.getDays() * 24 * 60 * 60 * 1000L);
|
title_bought.setExpireAt((long) Time.getFromTimestamp(timestamp));
|
||||||
Notification.info(_player, title.getTitle());
|
Notification.info(_player, title.getTitle());
|
||||||
Notification.info(_player, "称号已激活,有效期至 " + title_bought.getExpireAt());
|
Notification.info(_player, "称号已购买至 " + title_bought.getExpireAtStr());
|
||||||
} else {
|
|
||||||
title_bought.setExpireAtTimestamp(title_bought.getExpireAtTimestamp() + title.getDays() * 24 * 60 * 60 * 1000L);
|
|
||||||
Notification.info(_player, title.getTitle());
|
|
||||||
Notification.info(_player, "称号已续期至 " + title_bought.getExpireAt());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(Integer title_id, Long expire_at) {
|
public void setTitle(Integer title_id, Long expire_at) {
|
||||||
@ -232,8 +239,8 @@ public class XPlayer {
|
|||||||
_titles.put(title_id, PlayerTitle.create(title_id, _player.getUniqueId()));
|
_titles.put(title_id, PlayerTitle.create(title_id, _player.getUniqueId()));
|
||||||
}
|
}
|
||||||
PlayerTitle title = _titles.get(title_id);
|
PlayerTitle title = _titles.get(title_id);
|
||||||
title.setExpireAtTimestamp(expire_at);
|
title.setExpireAt(expire_at);
|
||||||
Notification.info(_player, title.getTitle());
|
Notification.info(_player, title.getTitle());
|
||||||
Notification.info(_player, "获得称号,有效期至 " + title.getExpireAt());
|
Notification.info(_player, "获得称号,有效期至 " + title.getExpireAtStr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,19 +179,13 @@ public class AdminCommands {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
long time_stamp;
|
long time_stamp;
|
||||||
if (Integer.parseInt(args[2]) == -1) {
|
|
||||||
time_stamp = -1;
|
|
||||||
} else {
|
|
||||||
// 字符串转时间戳
|
|
||||||
java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat("yyyyMMdd");
|
|
||||||
try {
|
try {
|
||||||
java.util.Date date = simpleDateFormat.parse(args[2]);
|
time_stamp = Long.parseLong(args[2]);
|
||||||
time_stamp = date.getTime();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Notification.error(sender, "时间格式错误");
|
Notification.error(sender, "时间格式错误");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
SaleTitle.setSaleEndAt(Integer.parseInt(args[1]), time_stamp);
|
SaleTitle.setSaleEndAt(Integer.parseInt(args[1]), time_stamp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,11 @@ public class Notification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void warn(Player player, Component msg) {
|
public static void warn(Player player, Component msg) {
|
||||||
player.sendMessage(Component.text(prefix + msg, w_style).append(msg));
|
player.sendMessage(Component.text(prefix, w_style).append(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void error(Player player, Component msg) {
|
public static void error(Player player, Component msg) {
|
||||||
player.sendMessage(Component.text(prefix + msg, e_style).append(msg));
|
player.sendMessage(Component.text(prefix, e_style).append(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void info(CommandSender player, Component msg) {
|
public static void info(CommandSender player, Component msg) {
|
||||||
@ -54,10 +54,10 @@ public class Notification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void warn(CommandSender player, Component msg) {
|
public static void warn(CommandSender player, Component msg) {
|
||||||
player.sendMessage(Component.text(prefix + msg, w_style).append(msg));
|
player.sendMessage(Component.text(prefix, w_style).append(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void error(CommandSender player, Component msg) {
|
public static void error(CommandSender player, Component msg) {
|
||||||
player.sendMessage(Component.text(prefix + msg, e_style).append(msg));
|
player.sendMessage(Component.text(prefix, e_style).append(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ public class View {
|
|||||||
player.sendMessage(Component.text().append(line_decorate).append(content_line4).build());
|
player.sendMessage(Component.text().append(line_decorate).append(content_line4).build());
|
||||||
player.sendMessage(Component.text().append(action_decorate).append(actionbar).build());
|
player.sendMessage(Component.text().append(action_decorate).append(actionbar).build());
|
||||||
player.sendMessage(bottom_decorate);
|
player.sendMessage(bottom_decorate);
|
||||||
|
player.sendMessage(Component.text(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static View create() {
|
public static View create() {
|
||||||
|
13
src/main/java/cn/lunadeer/miniplayertitle/utils/Time.java
Normal file
13
src/main/java/cn/lunadeer/miniplayertitle/utils/Time.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package cn.lunadeer.miniplayertitle.utils;
|
||||||
|
|
||||||
|
public class Time {
|
||||||
|
|
||||||
|
public static Integer getCurrent() {
|
||||||
|
// return YYYYMMDD
|
||||||
|
return Integer.parseInt(new java.text.SimpleDateFormat("yyyyMMdd").format(new java.util.Date()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getFromTimestamp(Long timestamp_ms) {
|
||||||
|
return Integer.parseInt(new java.text.SimpleDateFormat("yyyyMMdd").format(new java.util.Date(timestamp_ms)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user