mirror of
https://github.com/tjtanjin/QuickTax.git
synced 2024-11-25 06:35:11 +01:00
feat: Add papi placeholder for last amount collected in a schedule
This commit is contained in:
parent
4f108c41ea
commit
a85285781d
2
pom.xml
2
pom.xml
@ -7,7 +7,7 @@
|
||||
|
||||
<groupId>quicktax</groupId>
|
||||
<artifactId>quicktax</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8.0</version>
|
||||
|
||||
<name>QuickTax</name>
|
||||
|
||||
|
@ -76,7 +76,14 @@ public class PlayerHeadHelper {
|
||||
BlockState state = skullAboveSign.getState();
|
||||
Skull skull = (Skull) state;
|
||||
skull.setOwningPlayer(player);
|
||||
skull.update();
|
||||
try {
|
||||
skull.update();
|
||||
} catch (NullPointerException ignored) {
|
||||
// note: exception thrown for a purpur server owner, not yet reported by others
|
||||
// functionality is supposedly not affected, so adding this just to mute the
|
||||
// error messages - might be worth revisiting if more people report this in future
|
||||
// though purpur is not officially supported by this plugin so not a high priority
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,17 @@ public class PapiManager extends PlaceholderExpansion {
|
||||
}
|
||||
}
|
||||
|
||||
if (params.startsWith("schedule_last_collected_")) {
|
||||
String[] args = params.split("_", 4);
|
||||
String scheduleName = args[3];
|
||||
Schedule schedule = ScheduleManager.getSchedule(scheduleName);
|
||||
if (schedule != null) {
|
||||
return String.valueOf(schedule.getLastCollected());
|
||||
} else {
|
||||
return "None";
|
||||
}
|
||||
}
|
||||
|
||||
if (params.startsWith("schedule_timezone_")) {
|
||||
String[] args = params.split("_", 3);
|
||||
String scheduleName = args[2];
|
||||
|
@ -37,6 +37,7 @@ public class Schedule {
|
||||
int frequency;
|
||||
String type;
|
||||
String nextRunTime = "None";
|
||||
double lastCollected = 0;
|
||||
boolean updateLeaderboardOnRun;
|
||||
List<String> commands;
|
||||
|
||||
@ -151,7 +152,7 @@ public class Schedule {
|
||||
} else {
|
||||
taxManager.collectBal(Bukkit.getConsoleSender());
|
||||
}
|
||||
this.updateNextRunTime(main);
|
||||
this.updateScheduleInfo(main, taxManager.getTotalTaxCollected());
|
||||
this.runPostCollectionCommands(main);
|
||||
if (updateLeaderboardOnRun) {
|
||||
main.getStatsManager().manualUpdateLeaderboard(Bukkit.getConsoleSender());
|
||||
@ -161,16 +162,20 @@ public class Schedule {
|
||||
/**
|
||||
* Updates the next run time of the schedule.
|
||||
*
|
||||
* @param main plugin class
|
||||
*/
|
||||
public void updateNextRunTime(Main main) {
|
||||
public String calculateNextRunTime() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.SECOND, frequency);
|
||||
Date date = cal.getTime();
|
||||
DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy | HH:mm:ss");
|
||||
sdf.setTimeZone(TimeZone.getTimeZone(timezone));
|
||||
this.nextRunTime = sdf.format(date);
|
||||
this.updateScheduleTimeFile(main, this, this.nextRunTime);
|
||||
return sdf.format(date);
|
||||
}
|
||||
|
||||
public void updateScheduleInfo(Main main, double totalTaxCollected) {
|
||||
String calculatedTime = calculateNextRunTime();
|
||||
this.nextRunTime = calculatedTime;
|
||||
this.saveScheduleInfoToFile(main, this, this.nextRunTime, totalTaxCollected);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,6 +192,24 @@ public class Schedule {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last tax collected for this schedule.
|
||||
*/
|
||||
public void populateLastCollected(Main main) {
|
||||
File scheduleTimeFile = new File(main.getDataFolder() + "/schedules", this.getName() + ".yml");
|
||||
if (!scheduleTimeFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
FileConfiguration scheduleTimeConfig = new YamlConfiguration();
|
||||
try {
|
||||
scheduleTimeConfig.load(scheduleTimeFile);
|
||||
this.lastCollected = scheduleTimeConfig.getDouble("last-collected", 0);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uniquely identifies a schedule by its fields.
|
||||
*/
|
||||
@ -228,18 +251,20 @@ public class Schedule {
|
||||
/**
|
||||
* Updates schedule time file and creates it if it does not exist.
|
||||
*
|
||||
* @param main plugin instance
|
||||
* @param schedule schedule to update time in file for
|
||||
* @param time time for schedule's next run
|
||||
* @param totalTaxCollected the tax collected for this schedule run
|
||||
*/
|
||||
public void updateScheduleTimeFile(Main main, Schedule schedule, String time) {
|
||||
File scheduleTimeFile = new File(main.getDataFolder() + "/schedules", schedule.getName() + ".yml");
|
||||
FileConfiguration scheduleTimeConfig = new YamlConfiguration();
|
||||
if (!scheduleTimeFile.exists()) {
|
||||
scheduleTimeFile.getParentFile().mkdirs();
|
||||
public void saveScheduleInfoToFile(Main main, Schedule schedule, String time, double totalTaxCollected) {
|
||||
File scheduleInfoFile = new File(main.getDataFolder() + "/schedules", schedule.getName() + ".yml");
|
||||
FileConfiguration scheduleInfoConfig = new YamlConfiguration();
|
||||
if (!scheduleInfoFile.exists()) {
|
||||
scheduleInfoFile.getParentFile().mkdirs();
|
||||
String identifier = schedule.getUniqueIdentifier();
|
||||
scheduleTimeConfig.set(identifier, time);
|
||||
scheduleInfoConfig.set(identifier, time);
|
||||
try {
|
||||
scheduleTimeConfig.save(scheduleTimeFile);
|
||||
scheduleInfoConfig.save(scheduleInfoFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -247,8 +272,9 @@ public class Schedule {
|
||||
|
||||
try {
|
||||
String identifier = schedule.getUniqueIdentifier();
|
||||
scheduleTimeConfig.set(identifier, time);
|
||||
scheduleTimeConfig.save(scheduleTimeFile);
|
||||
scheduleInfoConfig.set(identifier, time);
|
||||
scheduleInfoConfig.set("last-collected", totalTaxCollected);
|
||||
scheduleInfoConfig.save(scheduleInfoFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -317,4 +343,8 @@ public class Schedule {
|
||||
public String getNextRunTime() {
|
||||
return this.nextRunTime;
|
||||
}
|
||||
|
||||
public double getLastCollected() {
|
||||
return this.lastCollected;
|
||||
}
|
||||
}
|
@ -183,6 +183,7 @@ public class ScheduleManager {
|
||||
|
||||
for (Schedule schedule : schedules.values()) {
|
||||
if (schedule.isEnabled()) {
|
||||
schedule.populateLastCollected(main);
|
||||
setUpSchedule(main, schedule);
|
||||
}
|
||||
}
|
||||
|
@ -21,12 +21,13 @@ import tk.taverncraft.quicktax.Main;
|
||||
* TaxManager handles all logic and action for collecting tax from players.
|
||||
*/
|
||||
public class TaxManager {
|
||||
Main main;
|
||||
ValidationManager validationManager;
|
||||
double totalTaxCollected;
|
||||
public static boolean isCollecting;
|
||||
public static Runnable task;
|
||||
|
||||
Main main;
|
||||
ValidationManager validationManager;
|
||||
private double totalTaxCollected;
|
||||
|
||||
// permission nodes for tax exemptions
|
||||
private final String exemptFullPerm = "quicktax.exempt.*";
|
||||
private final String exemptCollectNamePerm = "quicktax.exempt.collectname";
|
||||
@ -43,6 +44,10 @@ public class TaxManager {
|
||||
this.validationManager = new ValidationManager(main);
|
||||
}
|
||||
|
||||
public double getTotalTaxCollected() {
|
||||
return this.totalTaxCollected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logic for collecting tax from an individual.
|
||||
*
|
||||
|
@ -207,5 +207,6 @@ activity-bracket:
|
||||
# %qtax_schedule_freq_{scheduleName}% - get the schedule frequency (seconds)
|
||||
# %qtax_schedule_next_run_{scheduleName}% - get the time for schedule's next run
|
||||
# %qtax_schedule_timezone_{scheduleName}% - get the schedule timezone
|
||||
# %qtax_schedule_last_collected_{scheduleName}% - get the last collected tax amount for schedule
|
||||
# %qtax_top_name_{rank}% - get the player name at specified rank
|
||||
# %qtax_top_tax_{rank}% - get the player total tax paid at specified rank
|
Loading…
Reference in New Issue
Block a user