Skip to content

Commit

Permalink
delete mail
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXiaoM committed Jan 1, 2025
1 parent 5c8feab commit f104140
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class MenuOutBoxConfig extends AbstractMenuConfig<MenuOutBoxConfig.Gui> {
String iconGetAllRedirect;
IconSlot iconSlot;
int slotsCount;
String messageDeleted;
public MenuOutBoxConfig(SweetMail plugin) {
super(plugin, "menus/outbox.yml");
}
Expand All @@ -47,6 +48,7 @@ public int getSlotsCount() {
@Override
public void reloadConfig(MemoryConfiguration cfg) {
super.reloadConfig(cfg);
messageDeleted = cfg.getString("messages.outbox.deleted", "");

title = config.getString("title", "&0发件箱 ( %page%/%max_page% 页)");
titleOther = config.getString("title-other", "&0%target% 的发件箱 ( %page%/%max_page% 页)");
Expand Down Expand Up @@ -261,6 +263,17 @@ public void onClick(InventoryAction action, ClickType click, InventoryType.SlotT
.open();
return;
}
if (click.equals(ClickType.DROP) && player.hasPermission("sweetmail.admin")) {
player.closeInventory();
plugin.getMailDatabase().deleteMail(mail.uuid);
String sender = mail.senderDisplay.trim().isEmpty()
? Util.getPlayerName(mail.sender) : mail.senderDisplay;
t(player, plugin.prefix() + messageDeleted
.replace("%player%", sender)
.replace("%title%", mail.title)
.replace("%uuid%", mail.uuid));
return;
}
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ public final List<String> getIconLore(Player target, MailWithStatus mail, Pair<S
for (String key : loreContent) {
List<String> list = loreParts.get(key);
if (list != null && !list.isEmpty()) {
lore.addAll(list);
for (String s : list) {
if (s.startsWith("!!") && target.hasPermission("sweetmail.admin")) {
lore.add(s.substring(2));
} else {
lore.add(s);
}
}
} else {
int attachmentCount = 0;
switch (key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ public interface IMailDatabase {
* @param receiver 接收邮件的玩家
*/
void markUsed(List<String> uuidList, String receiver);

/**
* 彻底删除邮件
* @param uuid 邮件 UUID
*/
void deleteMail(String uuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public void markUsed(List<String> uuidList, String receiver) {
database.markUsed(uuidList, receiver);
}

@Override
public void deleteMail(String uuid) {
database.deleteMail(uuid);
}

public MailDatabase reload() {
if (!configFile.exists()) {
plugin.saveResource("database.yml", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,23 @@ public void markUsed(List<String> uuidList, String receiver) {
}
}

@Override
public void deleteMail(String uuid) {
try (Connection conn = getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(
"DELETE FROM `" + TABLE_BOX + "` WHERE `uuid`=?;"
)) {
ps.setString(1, uuid);
ps.execute();
}
try (PreparedStatement ps = conn.prepareStatement(
"DELETE FROM `" + TABLE_STATUS + "` WHERE `uuid`=?;"
)) {
ps.setString(1, uuid);
ps.execute();
}
} catch (SQLException e) {
SweetMail.warn(e);
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ messages:
inbox:
attachments-outdated: '&e该邮件的附件已过期,无法领取'
attachments-fail: '&e有附件领取失败! 请联系管理员查看后台了解详细'
outbox:
deleted: '&a你已成功删除 %player% 的邮件 %title%&7 (%uuid%)'
join:
text: '&e你有 &b%count% &e封未读邮件 &7[&a点击查看&7]'
text-online: '&e你有一封新的未读邮件 &7[&a点击查看&7]'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/menus/outbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ items:
- ''
- '&a左键&7 | &f查看邮件内容'
- '&b右键&7 | &f查看附件'
- '!!&eQ键&7 | &f删除邮件 &c(无需确认且不可逆)'
lore-content:
- part1
- attachments
Expand Down

0 comments on commit f104140

Please sign in to comment.