1
mirror of https://github.com/carm-outsource/TimeReward.git synced 2024-09-19 19:25:49 +00:00

feat(auto): 支持针对单间物品的自动领取配置以支持”按时提醒“功能。

This commit is contained in:
Carm Jos 2023-04-06 19:59:46 +08:00
parent 7e598d1912
commit 6585f7f21d
5 changed files with 29 additions and 37 deletions

View File

@ -11,14 +11,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<deps.easyplugin.version>1.5.2</deps.easyplugin.version>
<deps.easysql.version>0.4.6</deps.easysql.version>
<deps.mineconfig.version>2.4.0</deps.mineconfig.version>
<deps.easyplugin.version>1.5.5</deps.easyplugin.version>
<deps.easysql.version>0.4.7</deps.easysql.version>
<deps.mineconfig.version>2.5.1</deps.mineconfig.version>
</properties>
<groupId>cc.carm.plugin</groupId>
<artifactId>timereward</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>
<name>TimeReward</name>
<description>在线时长自动领奖插件通过指令发放奖励基于EasyPlugin实现。</description>

View File

@ -1,17 +0,0 @@
package cc.carm.plugin.timereward.conf;
import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.configuration.core.annotation.HeaderComment;
import cc.carm.lib.configuration.core.value.ConfigValue;
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
public class FunctionConfig extends ConfigurationRoot {
@HeaderComment({
"是否启用自动领取",
"启用后,玩家将会在满足奖励领取条件时自动领取奖励。",
"若关闭,则玩家需要手动输入指令领取奖励。"
})
public static final ConfigValue<Boolean> AUTO_CLAIM = ConfiguredValue.of(Boolean.class, true);
}

View File

@ -23,9 +23,7 @@ public class PluginConfig extends ConfigurationRoot {
"检查更新为异步操作,绝不会影响性能与使用体验。"
})
public static final ConfigValue<Boolean> CHECK_UPDATE = ConfiguredValue.of(Boolean.class, true);
public static final Class<?> FUNCTIONS = FunctionConfig.class;
@HeaderComment({"奖励相关设定,包含以下设定:",
" [id] 配置键名即奖励ID支持英文、数字与下划线。",
" | 确定后请不要更改,因为该键值用于存储玩家是否领取的数据",
@ -36,7 +34,9 @@ public class PluginConfig extends ConfigurationRoot {
" [permission] 领取奖励时后台执行的指令",
" | 支持PlaceholderAPI变量指令中可以使用 %(name) 来获取该奖励的名称。",
" [commands] 该奖励领取权限,可以不设置。",
" | 若为空则所有人都可以领取;若不为空,则需要拥有该权限的玩家才能领取。"
" | 若为空则所有人都可以领取;若不为空,则需要拥有该权限的玩家才能领取。",
" [auto] 该奖励是否自动领取可以不设置默认为true。",
" | 若关闭自动领取,则需要玩家手动输入/tr claim 领取奖励。",
})
public static final ConfigValue<RewardContents.Group> REWARDS = ConfigValue.builder()
.asValue(RewardContents.Group.class).fromSection()

View File

@ -3,7 +3,6 @@ package cc.carm.plugin.timereward.manager;
import cc.carm.lib.easyplugin.utils.MessageUtils;
import cc.carm.plugin.timereward.Main;
import cc.carm.plugin.timereward.TimeRewardAPI;
import cc.carm.plugin.timereward.conf.FunctionConfig;
import cc.carm.plugin.timereward.conf.PluginConfig;
import cc.carm.plugin.timereward.storage.RewardContents;
import cc.carm.plugin.timereward.storage.UserData;
@ -27,17 +26,18 @@ public class RewardManager {
this.runnable = new BukkitRunnable() {
@Override
public void run() {
if (!FunctionConfig.AUTO_CLAIM.getNotNull()) return;
if (Bukkit.getOnlinePlayers().isEmpty()) return;
for (Player player : Bukkit.getOnlinePlayers()) {
List<RewardContents> unclaimedRewards = getUnclaimedRewards(player);
if (unclaimedRewards.isEmpty()) continue;
List<RewardContents> rewards = getUnclaimedRewards(player).stream()
.filter(RewardContents::isAutoClaimed)
.collect(Collectors.toList());
if (rewards.isEmpty()) continue;
main.getScheduler().run(() -> unclaimedRewards.forEach(
// 在同步进程中为玩家发放奖励
unclaimedReward -> claimReward(player, unclaimedReward, false)
));
main.getScheduler().run(() -> rewards.forEach(r -> {
// 在同步进程中为玩家发放奖励
claimReward(player, r, true); // 二次检查避免重复发奖
}));
}
}
};
@ -68,7 +68,6 @@ public class RewardManager {
.collect(Collectors.toList());
}
public boolean isClaimable(Player player, RewardContents reward) {
UserData user = TimeRewardAPI.getUserManager().getData(player);
return !user.isClaimed(reward.getRewardID()) // 未曾领取

View File

@ -18,15 +18,18 @@ public class RewardContents {
private final @Nullable String permission;
private final @NotNull List<String> commands;
private final boolean auto;
public RewardContents(@NotNull String id, long time,
@Nullable String name, @Nullable String permission,
@NotNull List<String> commands) {
@NotNull List<String> commands, boolean auto) {
this.id = id;
this.time = time;
this.name = name;
this.permission = permission;
this.commands = commands;
this.auto = auto;
}
public String getRewardID() {
@ -53,6 +56,10 @@ public class RewardContents {
return commands;
}
public boolean isAutoClaimed() {
return auto;
}
public boolean checkPermission(@NotNull Player player) {
return permission == null || player.hasPermission(permission);
}
@ -67,6 +74,7 @@ public class RewardContents {
if (getName() != null) map.put("name", getName());
if (getPermission() != null) map.put("permission", getPermission());
map.put("commands", getCommands());
map.put("auto", auto);
return map;
}
@ -81,7 +89,8 @@ public class RewardContents {
id, time,
section.getString("name"),
section.getString("permission"),
section.getStringList("commands")
section.getStringList("commands"),
section.getBoolean("auto", false)
);
}
@ -89,7 +98,8 @@ public class RewardContents {
return new RewardContents(
id, 7200,
"&f[初级奖励] &e总在线时长 2小时", "TimeReward.vip",
Collections.singletonList("say &f恭喜 &b%player_name% &f领取了奖励 &r%(name) &f")
Collections.singletonList("say &f恭喜 &b%player_name% &f领取了奖励 &r%(name) &f"),
true
);
}