From 445b88e703e1e872e953175651a3f8ccab77fb14 Mon Sep 17 00:00:00 2001 From: R-Josef <460257626@qq.com> Date: Sat, 6 Jun 2020 19:38:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A2=9D=E5=A4=96=E5=A5=96?= =?UTF-8?q?=E5=8A=B1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- resources/config.yml | 38 +++++- resources/lang.yml | 7 + resources/plugin.yml | 2 +- src/moe/feo/bbstoper/CLI.java | 14 +- src/moe/feo/bbstoper/Crawler.java | 17 +-- src/moe/feo/bbstoper/Message.java | 30 +++-- src/moe/feo/bbstoper/Option.java | 10 +- src/moe/feo/bbstoper/PAPIExpansion.java | 7 + src/moe/feo/bbstoper/Reminder.java | 18 ++- src/moe/feo/bbstoper/Reward.java | 158 +++++++++++++++++++++++ src/moe/feo/bbstoper/Util.java | 44 ++++++- src/moe/feo/bbstoper/gui/GUI.java | 19 ++- src/moe/feo/bbstoper/gui/GUIManager.java | 4 +- src/moe/feo/bbstoper/gui/IDListener.java | 2 +- 15 files changed, 316 insertions(+), 56 deletions(-) create mode 100644 src/moe/feo/bbstoper/Reward.java diff --git a/pom.xml b/pom.xml index 5106ba4..6f382cf 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 moe.feo BBSToper - 3.5.3 + 3.6 spigot-repo diff --git a/resources/config.yml b/resources/config.yml index 312ddad..1c24062 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -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: @@ -74,4 +74,38 @@ reward: #奖励的命令, %PLAYER%代表使用命令的玩家ID commands: - 'experience add %PLAYER% 1000' - - 'eco give %PLAYER% 20' \ No newline at end of file + - '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' diff --git a/resources/lang.yml b/resources/lang.yml index 80d0082..f9914a4 100644 --- a/resources/lang.yml +++ b/resources/lang.yml @@ -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刚刚领取了顶贴奖励, 大家也快来顶贴吧! ' @@ -62,6 +63,7 @@ invalid: '&4命令错误!' invalidnum: '&4无效的数字!' playercmd: '&4该命令必须由玩家执行!' pagenotvisible: '&4宣传帖目前处于不可视状态, 如果您看到这条消息请通知管理员!' +none: '&4 无' failedgetweb: '获取网页时错误, 可能是由于网络波动!' #failedresolveweb中的信息可能在您的宣传帖被移入审核区时反复出现 #您可以通过留空该项来禁用这项提示, 留空的格式应为-failedresolveweb: '' @@ -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中的奖励信息, 留空则直接显示奖励命令 ([]表示留空) @@ -106,6 +111,8 @@ info: - '&b本服MCBBS宣传帖链接:' - '&9%PAGE%' - '&b对宣传帖使用提升卡将获得丰厚奖励.' +#额外奖励提醒 +extrainfo: '&b现在顶贴还可以获得 %EXTRA% 哦.' #帮助 help: diff --git a/resources/plugin.yml b/resources/plugin.yml index 6aacc0c..d3222f3 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -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] diff --git a/src/moe/feo/bbstoper/CLI.java b/src/moe/feo/bbstoper/CLI.java index 8141ea9..b0731d7 100644 --- a/src/moe/feo/bbstoper/CLI.java +++ b/src/moe/feo/bbstoper/CLI.java @@ -221,7 +221,6 @@ public void task() { sender.sendMessage(Message.PREFIX.getString() + Message.PAGENOTVISIBLE.getString()); return; } - crawler.kickExpiredData();// 剔除过期数据 String bbsname = poster.getBbsname(); List cache = new ArrayList<>();// 这个缓存是用来判断玩家的顶贴粒度是否小于一分钟 boolean issucceed = false; @@ -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; diff --git a/src/moe/feo/bbstoper/Crawler.java b/src/moe/feo/bbstoper/Crawler.java index 9b746f9..a515ff2 100644 --- a/src/moe/feo/bbstoper/Crawler.java +++ b/src/moe/feo/bbstoper/Crawler.java @@ -26,6 +26,7 @@ public class Crawler { public Crawler() { resolveWebData(); + kickExpiredData(); } public void resolveWebData() { @@ -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储存起来 diff --git a/src/moe/feo/bbstoper/Message.java b/src/moe/feo/bbstoper/Message.java index 62bb5cd..cf85c73 100644 --- a/src/moe/feo/bbstoper/Message.java +++ b/src/moe/feo/bbstoper/Message.java @@ -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; diff --git a/src/moe/feo/bbstoper/Option.java b/src/moe/feo/bbstoper/Option.java index 4b791ef..a380bbf 100644 --- a/src/moe/feo/bbstoper/Option.java +++ b/src/moe/feo/bbstoper/Option.java @@ -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; diff --git a/src/moe/feo/bbstoper/PAPIExpansion.java b/src/moe/feo/bbstoper/PAPIExpansion.java index 5daa0c3..14e4bda 100644 --- a/src/moe/feo/bbstoper/PAPIExpansion.java +++ b/src/moe/feo/bbstoper/PAPIExpansion.java @@ -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]); diff --git a/src/moe/feo/bbstoper/Reminder.java b/src/moe/feo/bbstoper/Reminder.java index 674e1dd..287d764 100644 --- a/src/moe/feo/bbstoper/Reminder.java +++ b/src/moe/feo/bbstoper/Reminder.java @@ -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; @@ -15,7 +16,7 @@ import moe.feo.bbstoper.sql.SQLer; public class Reminder implements Listener { - + private static SQLer sql; public Reminder(Plugin plugin) { @@ -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()); @@ -47,7 +49,13 @@ public void task() { isposted = false; } if (!isposted) {// 没有顶贴 - List list = Message.INFO.getStringList(); + List list = new ArrayList();// 提示的信息 + 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)); @@ -59,7 +67,7 @@ public void task() { } }.runTaskAsynchronously(BBSToper.getInstance()); } - + public static void setSQLer(SQLer sql) { Reminder.sql = sql; } diff --git a/src/moe/feo/bbstoper/Reward.java b/src/moe/feo/bbstoper/Reward.java new file mode 100644 index 0000000..a9a88aa --- /dev/null +++ b/src/moe/feo/bbstoper/Reward.java @@ -0,0 +1,158 @@ +package moe.feo.bbstoper; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.regex.Pattern; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class Reward { + private Player player; // 发放奖励的对象 + private Crawler crawler; // 一个爬虫对象 + private int index; // 要发放奖励的那条记录的序号 + + // current指需要判断的时间, before指上一个顶贴的时间 + public static boolean canIncentiveReward(Calendar current, Calendar before) { + boolean result = false; + if (Option.REWARD_INCENTIVEREWARD_ENABLE.getBoolean() == true) {// 开启了激励奖励 + Calendar copyofcurrent = (Calendar) before.clone();// 一个上次顶贴时间的副本 + copyofcurrent.add(Calendar.MINUTE, Option.REWARD_INCENTIVEREWARD_PERIOD.getInt());// 加上设定好的激励时间 + if (copyofcurrent.before(current)) {// 如果这个时间已经处于"当前领奖的记录"之前 + result = true; + } + } + return result; + } + + // current指需要判断的时间 + public static boolean canOffDayReward(Calendar current) { + boolean result = false; + if (Option.REWARD_OFFDAYREWARD_ENABLE.getBoolean() == true) {// 开启了休息日奖励 + for (String day : Option.REWARD_OFFDAYREWARD_OFFDAYS.getStringList()) { + Pattern upcasepattern = Pattern.compile("^[A-Z]+$");// 全大写英文字符串 + Pattern datepattern = Pattern.compile("^\\d{2}-\\d{2}$");// 00-00格式的字符串 + if (upcasepattern.matcher(day).matches()) {// 如果是全大写英文字符 + Class clazz = Calendar.class; + int dayofweek = 0; + try { + // https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html + // 根据Calendar终态静态变量将字符串转换成星期 + dayofweek = clazz.getField(day).getInt(null); + + } catch (IllegalArgumentException e) {// 非法参数 + e.printStackTrace(); + } catch (IllegalAccessException e) {// 非法访问 + e.printStackTrace(); + } catch (NoSuchFieldException e) {// 没有这个属性 + e.printStackTrace(); + } catch (SecurityException e) {// 安全 + e.printStackTrace(); + } + int dayofweekcurrent = current.get(Calendar.DAY_OF_WEEK);// 当前领奖的记录是星期几 + if (dayofweekcurrent == dayofweek) {// 如果当前就是设定的日子 + result = true; + } + } else if (datepattern.matcher(day).matches()) {// 如果是00-00这种字符串 + SimpleDateFormat offdayformat = new SimpleDateFormat("MM-dd"); + Calendar offdaycalendar = Calendar.getInstance();// 设定的假日日期(1970年的...) + try { + Date offdaydate = offdayformat.parse(day); + offdaycalendar.setTime(offdaydate); + } catch (ParseException e) { + e.printStackTrace(); + } + // 如果当前领奖的记录的月份和日号与设定值一样 + if (current.get(Calendar.MONTH) == offdaycalendar.get(Calendar.MONTH) + && current.get(Calendar.DAY_OF_MONTH) == offdaycalendar.get(Calendar.DAY_OF_MONTH)) { + result = true; + } + } + } + } + return result; + } + + public Reward(Player player, Crawler crawler, int index) { + this.player = player; + this.crawler = crawler; + this.index = index; + } + + public void award() { + List cmds = new ArrayList(); + boolean incentive = false;// 是否符合激励奖励条件 + boolean offday = false;// 是否符合休息日奖励条件 + boolean normal = true;// 是否发放普通奖励 + SimpleDateFormat bbsformat = new SimpleDateFormat("yyyy-M-d HH:mm");// mcbbs的日期格式 + Calendar thispost = Calendar.getInstance();// "当前领奖的记录"的时间 + try { + Date thipostdate = bbsformat.parse(crawler.Time.get(index)); + thispost.setTime(thipostdate); + } catch (ParseException e) { + e.printStackTrace(); + } + Calendar lastpost = Calendar.getInstance();// 上一次顶贴的时间 + if (crawler.Time.size() > index + 1) {// 如果有这一次之前的顶贴记录 + try { + Date lastpostdate = bbsformat.parse(crawler.Time.get(index + 1));// 同理这里应该获取之前那一条记录 + lastpost.setTime(lastpostdate); + } catch (ParseException e) { + e.printStackTrace(); + } + } else { + lastpost.setTime(new Date(0));// 没人顶过贴, 将时间设置为1970 + } + if (canIncentiveReward(thispost, lastpost)) { + incentive = true; + } + if (canOffDayReward(thispost)) { + offday = true; + } + String extra = null; + if (incentive) {// 如果激励奖励条件达成 + // 如果休息日奖励也达成了, 并且激励奖励和休息日奖励都不是额外奖励, 不会发放激励奖励(只会发放休息日奖励) + if (!(offday && Option.REWARD_INCENTIVEREWARD_EXTRA.getBoolean() == false + && Option.REWARD_OFFDAYREWARD_EXTRA.getBoolean() == false)) { + cmds.addAll(Option.REWARD_INCENTIVEREWARD_COMMANDS.getStringList()); + extra = new String(Message.GUI_INCENTIVEREWARDS.getString()); + } + if (Option.REWARD_INCENTIVEREWARD_EXTRA.getBoolean() == false) { + // 如果这不是额外奖励, 则普通奖励不会发放 + normal = false; + } + } + if (offday) {// 如果休息日奖励条件达成 + cmds.addAll(Option.REWARD_OFFDAYREWARD_COMMANDS.getStringList()); + if (extra == null) { + extra = new String(Message.GUI_OFFDAYREWARDS.getString()); + } else { + extra = extra + "+" + Message.GUI_OFFDAYREWARDS.getString(); + } + if (Option.REWARD_OFFDAYREWARD_EXTRA.getBoolean() == false) { + // 如果这不是额外奖励, 则普通奖励不会发放 + normal = false; + } + } + if (normal) { + cmds.addAll(Option.REWARD_COMMANDS.getStringList()); + } + // 让主线程执行 + Bukkit.getScheduler().runTask(BBSToper.getInstance(), new Runnable() { + @Override + public void run() { + for (String cmd : cmds) { + cmd = cmd.replaceAll("%PLAYER%", player.getName()); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd); + } + } + }); + // 给玩家发个消息表示祝贺 + player.sendMessage(Message.PREFIX.getString() + Message.REWARD.getString().replaceAll("%TIME%", crawler.Time.get(index))); + player.sendMessage(Message.PREFIX.getString() + Message.EXTRAREWARD.getString().replaceAll("%EXTRA%", extra)); + } +} diff --git a/src/moe/feo/bbstoper/Util.java b/src/moe/feo/bbstoper/Util.java index f06a578..8c3972c 100644 --- a/src/moe/feo/bbstoper/Util.java +++ b/src/moe/feo/bbstoper/Util.java @@ -1,6 +1,10 @@ package moe.feo.bbstoper; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.concurrent.TimeoutException; import org.bukkit.scheduler.BukkitRunnable; @@ -37,7 +41,6 @@ public void task() { Crawler crawler = new Crawler(); if (!crawler.visible) return; - crawler.kickExpiredData(); crawler.activeReward(); } }.runTaskTimerAsynchronously(BBSToper.getInstance(), 0, period); @@ -68,5 +71,44 @@ public static void removeRunningTaskID(int i) { if (runningtaskidlist.contains(i)) runningtaskidlist.remove((Integer) i); } + + public static String getExtraReward(Crawler crawler) {// 获取会获得的额外奖励(可为空) + boolean incentive = false;// 是否符合激励奖励条件 + boolean offday = false;// 是否符合休息日奖励条件 + Calendar current = Calendar.getInstance();// 当前时间 + Calendar lastpost = Calendar.getInstance();// 上一次顶贴的时间 + if (crawler.Time.size() > 0) {// 如果有顶贴记录的话 + SimpleDateFormat bbsformat = new SimpleDateFormat("yyyy-M-d HH:mm");// mcbbs的日期格式 + Date lastpostdate = null; + try { + lastpostdate = bbsformat.parse(crawler.Time.get(0)); + } catch (ParseException e) { + e.printStackTrace(); + } + lastpost.setTime(lastpostdate); + } + if (Reward.canIncentiveReward(current, lastpost)) { + incentive = true; + } + if (Reward.canOffDayReward(current)) { + offday = true; + } + String extra = null; + if (incentive) { + // 如果休息日奖励也达成了, 并且激励奖励和休息日奖励都不是额外奖励, 不会发放激励奖励(只会发放休息日奖励) + if (!(offday && Option.REWARD_INCENTIVEREWARD_EXTRA.getBoolean() == false + && Option.REWARD_OFFDAYREWARD_EXTRA.getBoolean() == false)) { + extra = new String(Message.GUI_INCENTIVEREWARDS.getString()); + } + } + if (offday) { + if (extra == null) { + extra = new String(Message.GUI_OFFDAYREWARDS.getString()); + } else { + extra = extra + "+" + Message.GUI_OFFDAYREWARDS.getString(); + } + } + return extra; + } } diff --git a/src/moe/feo/bbstoper/gui/GUI.java b/src/moe/feo/bbstoper/gui/GUI.java index 04a0de0..11f8a0c 100644 --- a/src/moe/feo/bbstoper/gui/GUI.java +++ b/src/moe/feo/bbstoper/gui/GUI.java @@ -19,6 +19,7 @@ import moe.feo.bbstoper.Message; import moe.feo.bbstoper.Option; import moe.feo.bbstoper.Poster; +import moe.feo.bbstoper.Util; import moe.feo.bbstoper.sql.SQLer; public class GUI { @@ -80,7 +81,15 @@ public void createGui(Player player) { sunflowermeta.setDisplayName(Message.GUI_REWARDS.getString()); List sunflowerlores = new ArrayList(Message.GUI_REWARDSINFO.getStringList());// 自定义奖励信息 if (sunflowerlores.isEmpty()) {// 如果没有自定义奖励信息 - sunflowerlores = Option.REWARD_COMMANDS.getStringList();// 直接显示命令 + sunflowerlores.addAll(Option.REWARD_COMMANDS.getStringList());// 直接显示命令 + if (Option.REWARD_INCENTIVEREWARD_ENABLE.getBoolean()) { + sunflowerlores.add(Message.GUI_INCENTIVEREWARDS.getString());// 激励奖励 + sunflowerlores.addAll(Option.REWARD_INCENTIVEREWARD_COMMANDS.getStringList());// 激励奖励命令 + } + if (Option.REWARD_OFFDAYREWARD_ENABLE.getBoolean()) { + sunflowerlores.add(Message.GUI_OFFDAYREWARDS.getString());// 休息日奖励 + sunflowerlores.addAll(Option.REWARD_OFFDAYREWARD_COMMANDS.getStringList()); // 休息日奖励命令 + } } sunflowerlores.add(Message.GUI_CLICKGET.getString()); sunflowermeta.setLore(sunflowerlores); @@ -116,6 +125,11 @@ public void createGui(Player player) { } else { compasslores.add(Message.GUI_PAGENOTVISIBLE.getString()); } + String extra = Util.getExtraReward(crawler); + if (extra != null) { + String extrarewards = Message.GUI_EXTRAREWARDS.getString().replaceAll("%EXTRA%", extra); + compasslores.add(extrarewards); + } compasslores.add(Message.GUI_CLICKOPEN.getString()); compassmeta.setLore(compasslores); compass.setItemMeta(compassmeta); @@ -124,6 +138,9 @@ public void createGui(Player player) { public ItemStack getRandomPane() {// 获取随机一种颜色的玻璃板 short data = (short)(Math.random()* 16);// 这会随机取出0-15的数据值 + while (data == 8) {// 8号亮灰色染色玻璃板根本没有颜色 + data = (short)(Math.random()* 16); + } ItemStack frame = new ItemStack(Material.STAINED_GLASS_PANE, 1, data); ItemMeta framemeta = frame.getItemMeta(); framemeta.setDisplayName(Message.GUI_FRAME.getString()); diff --git a/src/moe/feo/bbstoper/gui/GUIManager.java b/src/moe/feo/bbstoper/gui/GUIManager.java index 582baac..b3c8734 100644 --- a/src/moe/feo/bbstoper/gui/GUIManager.java +++ b/src/moe/feo/bbstoper/gui/GUIManager.java @@ -38,13 +38,13 @@ public void onInventoryClick(InventoryClickEvent event) { if (rglistener == null) { new IDListener(player.getUniqueId()).register();// 为此玩家创建一个监听器 String keywords = Arrays.toString(Option.GUI_CANCELKEYWORDS.getStringList().toArray()); - player.sendMessage(Message.ENTER.getString().replaceAll("%KEYWORD%", keywords)); + player.sendMessage(Message.PREFIX.getString() + Message.ENTER.getString().replaceAll("%KEYWORD%", keywords)); } } } if (Option.GUI_USECHATGETID.getBoolean() == false) { player.closeInventory(); - player.sendMessage(Message.HELP_BINDING.getString()); + player.sendMessage(Message.PREFIX.getString() + Message.HELP_BINDING.getString()); } } if (event.getRawSlot() == 13) { diff --git a/src/moe/feo/bbstoper/gui/IDListener.java b/src/moe/feo/bbstoper/gui/IDListener.java index 2b3d036..9105c5e 100644 --- a/src/moe/feo/bbstoper/gui/IDListener.java +++ b/src/moe/feo/bbstoper/gui/IDListener.java @@ -115,7 +115,7 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {// 处理事件 if (cancelkeywords.contains(msg)) {// 如果关键词中包含这次输入的消息 unregister();// 取消监听事件 CLI.getInstance().getCache().put(player.getUniqueId().toString(), null);// 清理这个键 - player.sendMessage(Message.CANCELED.getString()); + player.sendMessage(Message.PREFIX.getString() + Message.CANCELED.getString()); return; } List list = new ArrayList<>(Arrays.asList(msg.split("\\s+")));