|
2 | 2 |
|
3 | 3 | import java.io.File; |
4 | 4 | import java.text.DecimalFormat; |
| 5 | +import java.time.DayOfWeek; |
5 | 6 | import java.time.LocalDateTime; |
| 7 | +import java.time.Month; |
6 | 8 | import java.util.ArrayList; |
7 | 9 | import java.util.Collections; |
8 | 10 | import java.util.Comparator; |
|
48 | 50 | import com.bencodez.advancedcore.api.rewards.editbuttons.RewardEditAdvancedWorld; |
49 | 51 | import com.bencodez.advancedcore.api.rewards.editbuttons.RewardEditBossBar; |
50 | 52 | import com.bencodez.advancedcore.api.rewards.editbuttons.RewardEditChoices; |
| 53 | +import com.bencodez.advancedcore.api.rewards.editbuttons.RewardEditDate; |
51 | 54 | import com.bencodez.advancedcore.api.rewards.editbuttons.RewardEditEXP; |
52 | 55 | import com.bencodez.advancedcore.api.rewards.editbuttons.RewardEditEXPLevels; |
53 | 56 | import com.bencodez.advancedcore.api.rewards.editbuttons.RewardEditEffect; |
@@ -1072,6 +1075,104 @@ public void onValidate(Reward reward, RequirementInject inject, ConfigurationSec |
1072 | 1075 | } |
1073 | 1076 | })); |
1074 | 1077 |
|
| 1078 | + injectedRequirements.add(new RequirementInjectConfigurationSection("Date") { |
| 1079 | + @Override |
| 1080 | + public boolean onRequirementsRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, |
| 1081 | + RewardOptions rewardOptions) { |
| 1082 | + LocalDateTime now = LocalDateTime.now(); |
| 1083 | + |
| 1084 | + // Validate WeekDay |
| 1085 | + if (section.isString("WeekDay")) { |
| 1086 | + String requiredWeekDay = section.getString("WeekDay").toUpperCase(); |
| 1087 | + if (!now.getDayOfWeek().name().equals(requiredWeekDay)) { |
| 1088 | + debug("WeekDay does not match: " + requiredWeekDay); |
| 1089 | + return false; |
| 1090 | + } |
| 1091 | + } else if (section.isInt("WeekDay")) { |
| 1092 | + int requiredWeekDay = section.getInt("WeekDay"); |
| 1093 | + if (now.getDayOfWeek().getValue() != requiredWeekDay) { |
| 1094 | + debug("WeekDay does not match: " + requiredWeekDay); |
| 1095 | + return false; |
| 1096 | + } |
| 1097 | + } |
| 1098 | + |
| 1099 | + // Validate DayOfMonth |
| 1100 | + if (section.isInt("DayOfMonth")) { |
| 1101 | + int requiredDayOfMonth = section.getInt("DayOfMonth"); |
| 1102 | + if (now.getDayOfMonth() != requiredDayOfMonth) { |
| 1103 | + debug("DayOfMonth does not match: " + requiredDayOfMonth); |
| 1104 | + return false; |
| 1105 | + } |
| 1106 | + } |
| 1107 | + |
| 1108 | + // Validate Month |
| 1109 | + if (section.isString("Month")) { |
| 1110 | + String requiredMonth = section.getString("Month").toUpperCase(); |
| 1111 | + if (!now.getMonth().name().equals(requiredMonth)) { |
| 1112 | + debug("Month does not match: " + requiredMonth); |
| 1113 | + return false; |
| 1114 | + } |
| 1115 | + } |
| 1116 | + |
| 1117 | + return true; |
| 1118 | + } |
| 1119 | + }.priority(90).validator(new RequirementInjectValidator() { |
| 1120 | + @Override |
| 1121 | + public void onValidate(Reward reward, RequirementInject inject, ConfigurationSection data) { |
| 1122 | + if (!data.isConfigurationSection("Date")) { |
| 1123 | + return; |
| 1124 | + } |
| 1125 | + |
| 1126 | + ConfigurationSection section = data.getConfigurationSection("Date"); |
| 1127 | + |
| 1128 | + // Validate WeekDay |
| 1129 | + if (section.isString("WeekDay")) { |
| 1130 | + try { |
| 1131 | + DayOfWeek.valueOf(section.getString("WeekDay").toUpperCase()); |
| 1132 | + } catch (IllegalArgumentException e) { |
| 1133 | + warning(reward, inject, "Invalid WeekDay: " + section.getString("WeekDay")); |
| 1134 | + } |
| 1135 | + } else if (section.isInt("WeekDay")) { |
| 1136 | + int weekDay = section.getInt("WeekDay"); |
| 1137 | + if (weekDay < 1 || weekDay > 7) { |
| 1138 | + warning(reward, inject, "Invalid WeekDay: " + weekDay); |
| 1139 | + } |
| 1140 | + } |
| 1141 | + |
| 1142 | + // Validate DayOfMonth |
| 1143 | + if (section.isInt("DayOfMonth")) { |
| 1144 | + int day = section.getInt("DayOfMonth"); |
| 1145 | + if (day < 1 || day > 31) { |
| 1146 | + warning(reward, inject, "Invalid DayOfMonth: " + day); |
| 1147 | + } |
| 1148 | + } |
| 1149 | + |
| 1150 | + // Validate Month |
| 1151 | + if (section.isString("Month")) { |
| 1152 | + try { |
| 1153 | + Month.valueOf(section.getString("Month").toUpperCase()); |
| 1154 | + } catch (IllegalArgumentException e) { |
| 1155 | + warning(reward, inject, "Invalid Month: " + section.getString("Month")); |
| 1156 | + } |
| 1157 | + } |
| 1158 | + } |
| 1159 | + }).addEditButton(new EditGUIButton(new ItemBuilder("PAPER"), new EditGUIValueInventory("Date") { |
| 1160 | + |
| 1161 | + @Override |
| 1162 | + public void openInventory(ClickEvent clickEvent) { |
| 1163 | + RewardEditData reward = (RewardEditData) getInv().getData("Reward"); |
| 1164 | + new RewardEditDate() { |
| 1165 | + |
| 1166 | + @Override |
| 1167 | + public void setVal(String key, Object value) { |
| 1168 | + RewardEditData reward = (RewardEditData) getInv().getData("Reward"); |
| 1169 | + reward.setValue(key, value); |
| 1170 | + plugin.reloadAdvancedCore(false); |
| 1171 | + } |
| 1172 | + }.open(clickEvent.getPlayer(), reward); |
| 1173 | + } |
| 1174 | + }.addLore("Edit date-based requirements for the reward")))); |
| 1175 | + |
1075 | 1176 | injectedRequirements.add(new RequirementInjectConfigurationSection("LocationDistance") { |
1076 | 1177 | @Override |
1077 | 1178 | public boolean onRequirementsRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, |
|
0 commit comments