mirror of
https://github.com/carm-outsource/TimeReward.git
synced 2026-06-05 01:08:10 +08:00
feat(time): 尝试支持按日/周/月/总时长判别奖励。
This commit is contained in:
@@ -3,8 +3,9 @@ package cc.carm.plugin.timereward.hooker;
|
||||
import cc.carm.lib.easyplugin.papi.EasyPlaceholder;
|
||||
import cc.carm.lib.easyplugin.papi.handler.PlaceholderHandler;
|
||||
import cc.carm.plugin.timereward.TimeRewardAPI;
|
||||
import cc.carm.plugin.timereward.data.IntervalType;
|
||||
import cc.carm.plugin.timereward.data.RewardContents;
|
||||
import cc.carm.plugin.timereward.data.UserData;
|
||||
import cc.carm.plugin.timereward.user.UserRewardData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -18,7 +19,14 @@ public class PAPIExpansion extends EasyPlaceholder {
|
||||
public PAPIExpansion(@NotNull JavaPlugin plugin, @NotNull String rootIdentifier) {
|
||||
super(plugin, rootIdentifier);
|
||||
|
||||
handle("time", userHandler(UserData::getAllSeconds));
|
||||
handle("time", userHandler((user, args) -> {
|
||||
if (args.length < 1) return "请填写时间类型";
|
||||
IntervalType type = IntervalType.parse(args[0]);
|
||||
|
||||
if (type == null) return "时间类型不存在";
|
||||
|
||||
return user.getOnlineDuration(type).getSeconds();
|
||||
}), Collections.singletonList("<时间类型>"));
|
||||
|
||||
handle("reward",
|
||||
rewardHandler(RewardContents::getDisplayName),
|
||||
@@ -27,7 +35,11 @@ public class PAPIExpansion extends EasyPlaceholder {
|
||||
|
||||
handle("claimed", userHandler((user, args) -> {
|
||||
if (args.length < 1) return "请填写奖励ID";
|
||||
else return user.isClaimed(args[0]);
|
||||
|
||||
RewardContents reward = TimeRewardAPI.getRewardManager().getReward(args[0]);
|
||||
if (reward == null) return "奖励不存在";
|
||||
|
||||
return user.isClaimed(reward);
|
||||
}), Collections.singletonList("<奖励ID>"));
|
||||
|
||||
handle("claimable", (offlinePlayer, args) -> {
|
||||
@@ -43,14 +55,14 @@ public class PAPIExpansion extends EasyPlaceholder {
|
||||
handle("version", (player, args) -> getVersion());
|
||||
}
|
||||
|
||||
protected <R> PlaceholderHandler userHandler(Function<UserData, R> userFunction) {
|
||||
protected <R> PlaceholderHandler userHandler(Function<UserRewardData, R> userFunction) {
|
||||
return userHandler((user, args) -> userFunction.apply(user));
|
||||
}
|
||||
|
||||
protected <R> PlaceholderHandler userHandler(BiFunction<UserData, String[], R> userFunction) {
|
||||
protected <R> PlaceholderHandler userHandler(BiFunction<UserRewardData, String[], R> userFunction) {
|
||||
return (player, args) -> {
|
||||
if (player == null || !player.isOnline()) return "加载中...";
|
||||
return userFunction.apply(TimeRewardAPI.getUserManager().getData((Player) player), args);
|
||||
return userFunction.apply(TimeRewardAPI.getUserManager().get((Player) player), args);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user