Skip to content

Commit

Permalink
增加额外奖励功能
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Josef committed Jun 6, 2020
1 parent dcd4f6e commit 445b88e
Show file tree
Hide file tree
Showing 15 changed files with 316 additions and 56 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>moe.feo</groupId>
<artifactId>BBSToper</artifactId>
<version>3.5.3</version>
<version>3.6</version>
<repositories>
<repository>
<id>spigot-repo</id>
Expand Down
38 changes: 36 additions & 2 deletions resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#项目地址: https://github.com/R-Josef/BBSToper
#MCBBS下载地址: https://www.mcbbs.net/thread-789082-1-1.html
#请定期检查这些网址以获取可用的更新
#Copyright © 2018-2019 R_Josef 版权所有
#Copyright © 2018-2020 R_Josef 版权所有

#数据库设置
database:
Expand Down Expand Up @@ -74,4 +74,38 @@ reward:
#奖励的命令, %PLAYER%代表使用命令的玩家ID
commands:
- 'experience add %PLAYER% 1000'
- 'eco give %PLAYER% 20'
- 'eco give %PLAYER% 20'
#激励奖励
#当玩家在无人顶贴超过一定时间之后顶贴, 这些奖励命令会被执行
incentivereward:
#是否启用
enable: false
#是否为额外奖励(是否还会给与普通的奖励)
extra: true
#间隔时间, 单位为分钟
#距离上一次有人顶贴多久之后会给与激励奖励
period: 30
#奖励命令
commands:
- 'effect give %PLAYER% haste 2'
#休息日奖励
#当玩家在设定好的休息日顶贴, 这些奖励命令会被执行
offdayreward:
#是否启用
enable: false
#是否为额外奖励(是否还会给与普通的奖励)
#注意: 当"休息日奖励"与"激励奖励"的"额外奖励"选项都为false时
#如果"休息日奖励"与"激励奖励"的条件同时满足, 将只有"休息日奖励"会被发放
extra: true
#哪些日期会应用于这项设置
#表示一个星期中的某一天: SUNDAY(周日), MONDAY(周一), TUESDAY(周二)
#WEDNESDAY(周三), THURSDAY(周四), FRIDAY(周五), SATURDAY(周六)
#普通日期格式为MM-dd, 例如10-01表示十月一日
offdays:
- 'SATURDAY'
- 'SUNDAY'
- '10-01'
- '05-01'
#奖励命令
commands:
- 'effect give %PLAYER% speed 2'
7 changes: 7 additions & 0 deletions resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ nopost: '&4您暂未有新的顶帖记录!'
overtime: '&4很抱歉您每天只能领取 &e%REWARDTIMES% &4次奖励!'
waitamin: '&4连续顶帖间隔必须大于一分钟!'
reward: '&b您在 &f%TIME% &b进行的顶帖已得到回报.'
extrareward: '&b您还获得了: %EXTRA%.'
rewardgived: '&a奖励发放完毕!'
broadcast: '&b玩家 &e%PLAYER% &b刚刚领取了顶贴奖励, 大家也快来顶贴吧! '

Expand Down Expand Up @@ -62,6 +63,7 @@ invalid: '&4命令错误!'
invalidnum: '&4无效的数字!'
playercmd: '&4该命令必须由玩家执行!'
pagenotvisible: '&4宣传帖目前处于不可视状态, 如果您看到这条消息请通知管理员!'
none: '&4 无'
failedgetweb: '获取网页时错误, 可能是由于网络波动!'
#failedresolveweb中的信息可能在您的宣传帖被移入审核区时反复出现
#您可以通过留空该项来禁用这项提示, 留空的格式应为-failedresolveweb: ''
Expand All @@ -79,11 +81,14 @@ gui:
bbsid: '&2绑定账号: &e%BBSID%'
posttimes: '&2顶贴次数: &e%TIMES%'
rewards: '&b奖励信息'
incentiverewards: '&b激励奖励'
offdayrewards: '&b休息日奖励'
clickget: '&a点击领取奖励'
tops: '&b顶贴排行'
pagestate: '§b宣传帖状态'
pageid: '&2帖子ID: &f%PAGEID%'
lastpost: '&2上一次顶贴: &f%TIME%'
extrarewards: '&2现在顶贴可获得: %EXTRA%'
pagenotvisible: '&c宣传帖目前处于不可视状态'
clickopen: '&a点击获取链接'
#这里是自定义GUI中的奖励信息, 留空则直接显示奖励命令 ([]表示留空)
Expand All @@ -106,6 +111,8 @@ info:
- '&b本服MCBBS宣传帖链接:'
- '&9%PAGE%'
- '&b对宣传帖使用提升卡将获得丰厚奖励.'
#额外奖励提醒
extrainfo: '&b现在顶贴还可以获得 %EXTRA% 哦.'

#帮助
help:
Expand Down
2 changes: 1 addition & 1 deletion resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: BBSToper
main: moe.feo.bbstoper.BBSToper
version: 3.5.3
version: 3.6
author: Fengshuai(R_Josef)
website: https://www.mcbbs.net/thread-789082-1-1.html
softdepend: [PlaceholderAPI]
Expand Down
14 changes: 1 addition & 13 deletions src/moe/feo/bbstoper/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ public void task() {
sender.sendMessage(Message.PREFIX.getString() + Message.PAGENOTVISIBLE.getString());
return;
}
crawler.kickExpiredData();// 剔除过期数据
String bbsname = poster.getBbsname();
List<String> cache = new ArrayList<>();// 这个缓存是用来判断玩家的顶贴粒度是否小于一分钟
boolean issucceed = false;
Expand Down Expand Up @@ -249,18 +248,7 @@ public void task() {
poster.setRewardtime(0);
}
if (poster.getRewardtime() < Option.REWARD_TIMES.getInt()) {// 奖励次数小于设定值
Bukkit.getScheduler().runTask(BBSToper.getInstance(), new Runnable() {
@Override
public void run() {
for (int x = 0; x < Option.REWARD_COMMANDS.getStringList().size(); x++) {
String cmd = Option.REWARD_COMMANDS.getStringList().get(x)
.replaceAll("%PLAYER%", sender.getName());
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
}
}
});
sender.sendMessage(Message.PREFIX.getString()
+ Message.REWARD.getString().replaceAll("%TIME%", crawler.Time.get(i)));
new Reward((Player) sender, crawler, i).award();
sql.addTopState(poster.getBbsname(), crawler.Time.get(i));
poster.setRewardtime(poster.getRewardtime() + 1);// rewardtime次数加一
issucceed = true;
Expand Down
17 changes: 3 additions & 14 deletions src/moe/feo/bbstoper/Crawler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Crawler {

public Crawler() {
resolveWebData();
kickExpiredData();
}

public void resolveWebData() {
Expand Down Expand Up @@ -122,20 +123,8 @@ public void activeReward() {// 主动给玩家发奖励
if (poster.getRewardtime() >= Option.REWARD_TIMES.getInt()) {
continue;// 如果领奖次数已经大于设定值了,那么跳出循环
}
// 这时候就可以给玩家发奖励了,这里让主线程执行
Bukkit.getScheduler().runTask(BBSToper.getInstance(), new Runnable() {
@Override
public void run() {
for (int x = 0; x < Option.REWARD_COMMANDS.getStringList().size(); x++) {
String cmd = Option.REWARD_COMMANDS.getStringList().get(x)
.replaceAll("%PLAYER%", player.getName());
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
}
}
});
// 给玩家发个消息表示祝贺
player.getPlayer().sendMessage(
Message.PREFIX.getString() + Message.REWARD.getString().replaceAll("%TIME%", time));
// 这时候就可以给玩家发奖励了
new Reward(olplayer, this, i).award();
sql.addTopState(bbsname, time);
poster.setRewardtime(poster.getRewardtime() + 1);
sql.updatePoster(poster);// 把poster储存起来
Expand Down
30 changes: 16 additions & 14 deletions src/moe/feo/bbstoper/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ public enum Message {
POSTERNUM("posternum"), OVERPAGE("overpage"), NOPLAYER("noplayer"), POSTERTIME("postertime"), PAGEINFO("pageinfo"),
NOPOSTER("noposter"), POSTERPLAYER("posterplayer"), POSTERTOTAL("postertotal"), PAGEINFOTOP("pageinfotop"),
NOTBOUND("notbound"), NOPOST("nopost"), OVERTIME("overtime"), WAITAMIN("waitamin"), REWARD("reward"),
REWARDGIVED("rewardgived"), BROADCAST("broadcast"), ENTER("enter"), CANCELED("canceled"), REPEAT("repeat"),
NOTSAME("notsame"), ONCOOLDOWN("oncooldown"), SAMEBIND("samebind"), OWNSAMEBIND("ownsamebind"),
BINDINGSUCCESS("bindingsuccess"), IDOWNER("idowner"), IDNOTFOUND("idnotfound"), OWNERID("ownerid"),
OWNERNOTFOUND("ownernotfound"), NOPERMISSION("nopermission"), INVALID("invalid"), INVALIDNUM("invalidnum"),
PLAYERCMD("playercmd"), PAGENOTVISIBLE("pagenotvisible"), FAILEDGETWEB("failedgetweb"),
FAILEDRESOLVEWEB("failedresolveweb"), FAILEDUNINSTALLMO("faileduninstallmo"), GUI_TITLE("gui.title"),
GUI_FRAME("gui.frame"), GUI_SKULL("gui.skull"), GUI_NOTBOUND("gui.notbound"), GUI_CLICKBOUND("gui.clickbound"),
GUI_CLICKREBOUND("gui.clickrebound"), GUI_BBSID("gui.bbsid"), GUI_POSTTIMES("gui.posttimes"),
GUI_REWARDS("gui.rewards"), GUI_CLICKGET("gui.clickget"), GUI_TOPS("gui.tops"), GUI_PAGESTATE("gui.pagestate"),
GUI_PAGEID("gui.pageid"), GUI_LASTPOST("gui.lastpost"), GUI_PAGENOTVISIBLE("gui.pagenotvisible"),
GUI_CLICKOPEN("gui.clickopen"), GUI_REWARDSINFO("gui.rewardsinfo"), CLICKPOSTICON("clickposticon"),
DELETESUCCESS("deletesuccess"), INFO("info"), HELP_TITLE("help.title"), HELP_HELP("help.help"),
HELP_BINDING("help.binding"), HELP_REWARD("help.reward"), HELP_LIST("help.list"), HELP_TOP("help.top"),
HELP_CHECK("help.check"), HELP_DELETE("help.delete"), HELP_RELOAD("help.reload");
EXTRAREWARD("extrareward"), REWARDGIVED("rewardgived"), BROADCAST("broadcast"), ENTER("enter"),
CANCELED("canceled"), REPEAT("repeat"), NOTSAME("notsame"), ONCOOLDOWN("oncooldown"), SAMEBIND("samebind"),
OWNSAMEBIND("ownsamebind"), BINDINGSUCCESS("bindingsuccess"), IDOWNER("idowner"), IDNOTFOUND("idnotfound"),
OWNERID("ownerid"), OWNERNOTFOUND("ownernotfound"), NOPERMISSION("nopermission"), INVALID("invalid"),
INVALIDNUM("invalidnum"), PLAYERCMD("playercmd"), PAGENOTVISIBLE("pagenotvisible"), NONE("none"),
FAILEDGETWEB("failedgetweb"), FAILEDRESOLVEWEB("failedresolveweb"), FAILEDUNINSTALLMO("faileduninstallmo"),
GUI_TITLE("gui.title"), GUI_FRAME("gui.frame"), GUI_SKULL("gui.skull"), GUI_NOTBOUND("gui.notbound"),
GUI_CLICKBOUND("gui.clickbound"), GUI_CLICKREBOUND("gui.clickrebound"), GUI_BBSID("gui.bbsid"),
GUI_POSTTIMES("gui.posttimes"), GUI_REWARDS("gui.rewards"), GUI_INCENTIVEREWARDS("gui.incentiverewards"),
GUI_OFFDAYREWARDS("gui.offdayrewards"), GUI_CLICKGET("gui.clickget"), GUI_TOPS("gui.tops"),
GUI_PAGESTATE("gui.pagestate"), GUI_PAGEID("gui.pageid"), GUI_LASTPOST("gui.lastpost"),
GUI_EXTRAREWARDS("gui.extrarewards"), GUI_PAGENOTVISIBLE("gui.pagenotvisible"), GUI_CLICKOPEN("gui.clickopen"),
GUI_REWARDSINFO("gui.rewardsinfo"), CLICKPOSTICON("clickposticon"), DELETESUCCESS("deletesuccess"), INFO("info"),
EXTRAINFO("extrainfo"), HELP_TITLE("help.title"), HELP_HELP("help.help"), HELP_BINDING("help.binding"),
HELP_REWARD("help.reward"), HELP_LIST("help.list"), HELP_TOP("help.top"), HELP_CHECK("help.check"),
HELP_DELETE("help.delete"), HELP_RELOAD("help.reload");

public String path;

Expand Down
10 changes: 9 additions & 1 deletion src/moe/feo/bbstoper/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ public enum Option {
MCBBS_JOINMESSAGE("mcbbs.joinmessage"), GUI_TOPPLAYERS("gui.topplayers"),
GUI_DISPLAYHEADSKIN("gui.displayheadskin"), GUI_USECHATGETID("gui.usechatgetid"),
GUI_CANCELKEYWORDS("gui.cancelkeywords"), REWARD_AUTO("reward.auto"), REWARD_PERIOD("reward.period"),
REWARD_TIMES("reward.times"), REWARD_COMMANDS("reward.commands");
REWARD_TIMES("reward.times"), REWARD_COMMANDS("reward.commands"),
REWARD_INCENTIVEREWARD_ENABLE("reward.incentivereward.enable"),
REWARD_INCENTIVEREWARD_EXTRA("reward.incentivereward.extra"),
REWARD_INCENTIVEREWARD_PERIOD("reward.incentivereward.period"),
REWARD_INCENTIVEREWARD_COMMANDS("reward.incentivereward.commands"),
REWARD_OFFDAYREWARD_ENABLE("reward.offdayreward.enable"), REWARD_OFFDAYREWARD_EXTRA("reward.offdayreward.extra"),
REWARD_OFFDAYREWARD_OFFDAYS("reward.offdayreward.offdays"),
REWARD_OFFDAYREWARD_COMMANDS("reward.offdayreward.commands");


private static File file;
private static FileConfiguration config;
Expand Down
7 changes: 7 additions & 0 deletions src/moe/feo/bbstoper/PAPIExpansion.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public String onPlaceholderRequest(Player player, String identifier) {
return Message.GUI_PAGENOTVISIBLE.getString();// 帖子不可视
}
}
if (identifier.equals("extrarewards")) {
String extra = Util.getExtraReward(new Crawler());
if (extra == null) {
extra = Message.NONE.getString();
}
return extra;
}
String pattern = "^top_[1-9]\\d*$";// top_正整数的正则表达式
if (Pattern.matches(pattern, identifier)) {// 如果匹配这种格式
int rank = Integer.parseInt(identifier.split("_")[1]);
Expand Down
18 changes: 13 additions & 5 deletions src/moe/feo/bbstoper/Reminder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package moe.feo.bbstoper;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
Expand All @@ -15,7 +16,7 @@
import moe.feo.bbstoper.sql.SQLer;

public class Reminder implements Listener {

private static SQLer sql;

public Reminder(Plugin plugin) {
Expand All @@ -34,9 +35,10 @@ public void run() {
task();
Util.removeRunningTaskID(this.getTaskId());
}

public void task() {
boolean isbinded = true;
boolean isposted = true;
boolean isbinded = true;// 是否绑定
boolean isposted = true;// 是否有顶贴者
UUID uuid = event.getPlayer().getUniqueId();
Poster poster = sql.getPoster(uuid.toString());
String datenow = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
Expand All @@ -47,7 +49,13 @@ public void task() {
isposted = false;
}
if (!isposted) {// 没有顶贴
List<String> list = Message.INFO.getStringList();
List<String> list = new ArrayList<String>();// 提示的信息
list.addAll(Message.INFO.getStringList());
Crawler crawler = new Crawler();
String extra = Util.getExtraReward(crawler);
if (extra != null) {// 说明有额外奖励信息
list.add(Message.EXTRAINFO.getString().replaceAll("%EXTRA%", extra));
}
String url = "https://www.mcbbs.net/thread-" + Option.MCBBS_URL.getString() + "-1-1.html";
for (String msg : list) {
event.getPlayer().sendMessage(Message.PREFIX.getString() + msg.replaceAll("%PAGE%", url));
Expand All @@ -59,7 +67,7 @@ public void task() {
}
}.runTaskAsynchronously(BBSToper.getInstance());
}

public static void setSQLer(SQLer sql) {
Reminder.sql = sql;
}
Expand Down
Loading

0 comments on commit 445b88e

Please sign in to comment.