Skip to content

Commit

Permalink
add specific players into advance receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXiaoM committed Oct 12, 2024
1 parent 34eb4ed commit e2eb4b2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class MenuDraftAdvanceConfig extends AbstractMenuConfig<MenuDraftAdvanceC
String iconReceiversPrompts4TipsStart;
String iconReceiversPrompts4TipsEnd;
String iconReceiversPrompts4Cancel;
String iconReceiversPrompts5Tips;
String iconReceiversPrompts5Cancel;
String iconReceiversUnset;
String iconReceiversBadTimeFormat;
Icon iconTimed;
Expand Down Expand Up @@ -90,6 +92,8 @@ protected boolean loadMainIcon(ConfigurationSection section, String key, Icon lo
iconReceiversPrompts4TipsStart = section.getString(key + ".prompts.4.tips-start", "&7[&e&l邮件&7] &b请在聊天栏发送,&f“在某段时间内上过线的玩家”&b的 &e判定起始时间 &7(格式 &f年-月-日 时:分:秒&7,不输入时分秒部分默认为0。输入 &ccancel &7取消设置)");
iconReceiversPrompts4TipsEnd = section.getString(key + ".prompts.4.tips-end", "&7[&e&l邮件&7] &b请在聊天栏发送,&f“在某段时间内上过线的玩家”&b的 &e判定结束时间 &7(格式 &f年-月-日 时:分:秒&7,不输入时分秒部分默认为0。输入 &ccancel &7取消设置)");
iconReceiversPrompts4Cancel = section.getString(key + ".prompts.4.cancel", "cancel");
iconReceiversPrompts5Tips = section.getString(key + ".prompts.5.tips", "&7[&e&l邮件&7] &b请在聊天栏发送玩家列表,使用逗号分隔 &7(输入 &ccancel &7取消设置)");
iconReceiversPrompts5Cancel = section.getString(key + ".prompts.5.cancel", "cancel");
iconReceiversUnset = section.getString(key + ".unset", "&7未设置");
iconReceiversBadTimeFormat = section.getString(key + ".bad-time-format", "&7[&e&l邮件&7] &f你输入的时间格式不正确!");
return true;
Expand Down Expand Up @@ -299,6 +303,24 @@ public void onClick(InventoryAction action, ClickType click, InventoryType.SlotT
timeStr -> receiver2.accept(timeStr, timestampStart), reopen));
break;
}
case 5: {
player.closeInventory();
Consumer<String> receiver1 = str -> {
String[] split = str.split("[,、;;,]");
for (int i = 0; i < split.length; i++) {
split[i] = split[i].trim();
}
draft.advReceivers = "players " + String.join(",", split);
draft.save();
reopen.run();
};
ChatPrompter.prompt(
plugin, player,
iconReceiversPrompts3Tips,
iconReceiversPrompts3Cancel,
receiver1, reopen);
return;
}
default:
return;
}
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/top/mrxiaom/sweetmail/func/data/Draft.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static List<String> generateReceivers(String advReceivers) {
if (advReceivers.startsWith("last played from ")) {
// 在某段时间区间内,上过线的玩家
String str = advReceivers.substring(17);
String[] split = str.contains(" to ") ? str.split(" to ", 2) : new String[] {advReceivers};
String[] split = str.contains(" to ") ? str.split(" to ", 2) : new String[] { str };
if (split.length == 2) {
Long fromTime = Util.parseLong(split[0]).orElse(null);
Long toTime = Util.parseLong(split[1]).orElse(null);
Expand All @@ -189,6 +189,16 @@ public static List<String> generateReceivers(String advReceivers) {
}
}
}
if (advReceivers.startsWith("players ")) {
// 指定玩家列表
String str = advReceivers.substring(8);
String[] split = str.contains(",") ? str.split(",") : new String[] { str };
for (String s : split) {
OfflinePlayer player = Util.getOfflinePlayer(s).orElse(null);
if (player == null || player.getName() == null) continue;
receivers.add(online ? player.getUniqueId().toString() : player.getName());
}
}
return receivers;
}
}

0 comments on commit e2eb4b2

Please sign in to comment.