mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-16 13:11:19 +01:00
Reseting limits at specific time of the day
This commit is contained in:
parent
9b291b299b
commit
3bfb0f60cc
@ -10,6 +10,7 @@ import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.economy.PaymentData;
|
||||
|
||||
import net.Zrips.CMILib.Locale.LC;
|
||||
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||
import net.Zrips.CMILib.Time.CMITimeManager;
|
||||
|
||||
@ -54,8 +55,10 @@ public class limit implements Cmd {
|
||||
continue;
|
||||
PaymentData limit = JPlayer.getPaymentLimit();
|
||||
|
||||
if (limit.getLeftTime(type) <= 0)
|
||||
if (limit.getLeftTime(type) <= 0) {
|
||||
CMIDebug.d("reset", type);
|
||||
limit.resetLimits(type);
|
||||
}
|
||||
|
||||
if (limit.getLeftTime(type) > 0) {
|
||||
String typeName = type.getName().toLowerCase();
|
||||
|
@ -95,7 +95,8 @@ public class GeneralConfigManager {
|
||||
SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useSilkTouchProtection, UseCustomNames,
|
||||
PreventSlimeSplit, PreventMagmaCubeSplit, PreventHopperFillUps, PreventBrewingStandFillUps, informOnPaymentDisable,
|
||||
BrowseUseNewLook, payExploringWhenGliding = false, resetExploringData = false, disablePaymentIfMaxLevelReached, disablePaymentIfRiding,
|
||||
boostedItemsInOffHand = false, boostedItemsInMainHand, boostedArmorItems, boostedItemsSlotSpecific, multiplyBoostedExtraValues, addPermissionBoost, highestPermissionBoost /*, preventCropResizePayment*/,
|
||||
boostedItemsInOffHand = false, boostedItemsInMainHand, boostedArmorItems, boostedItemsSlotSpecific, multiplyBoostedExtraValues, addPermissionBoost,
|
||||
highestPermissionBoost /*, preventCropResizePayment*/,
|
||||
payItemDurabilityLoss,
|
||||
applyToNegativeIncome, useMinimumOveralPayment, useMinimumOveralPoints, useMinimumOveralExp, useBreederFinder,
|
||||
CancelCowMilking, fixAtMaxLevel, TitleChangeChat, TitleChangeActionBar, LevelChangeChat,
|
||||
@ -702,8 +703,14 @@ public class GeneralConfigManager {
|
||||
Jobs.getPluginLogger().warning("MoneyLimit has an invalid value. Disabling money limit!");
|
||||
limit.setEnabled(false);
|
||||
}
|
||||
|
||||
c.addComment("Economy.Limit.Money.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours");
|
||||
limit.setTimeLimit(c.get("Economy.Limit.Money.TimeLimit", 3600));
|
||||
|
||||
c.addComment("Economy.Limit.Money.ResetTime", "Time in 24 hour format when limit should reset. This will override TimeLimit if defined",
|
||||
"Example: '00:00:00' will reset timer at midnight, '04:30:00' will reset at 4:30 in the morning", "Set to empty field if you want to use TimeLimit");
|
||||
limit.setResetsAt(c.get("Economy.Limit.Money.ResetTime", ""));
|
||||
|
||||
c.addComment("Economy.Limit.Money.AnnouncementDelay", "Delay between announcements about reached money limit",
|
||||
"Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying");
|
||||
limit.setAnnouncementDelay(c.get("Economy.Limit.Money.AnnouncementDelay", 30));
|
||||
@ -736,6 +743,11 @@ public class GeneralConfigManager {
|
||||
}
|
||||
c.addComment("Economy.Limit.Point.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours");
|
||||
limit.setTimeLimit(c.get("Economy.Limit.Point.TimeLimit", 3600));
|
||||
|
||||
c.addComment("Economy.Limit.Point.ResetTime", "Time in 24 hour format when limit should reset. This will override TimeLimit if defined",
|
||||
"Example: '00:00:00' will reset timer at midnight, '04:30:00' will reset at 4:30 in the morning", "Set to empty field if you want to use TimeLimit");
|
||||
limit.setResetsAt(c.get("Economy.Limit.Point.ResetTime", ""));
|
||||
|
||||
c.addComment("Economy.Limit.Point.AnnouncementDelay", "Delay between announcements about reached limit",
|
||||
"Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying");
|
||||
limit.setAnnouncementDelay(c.get("Economy.Limit.Point.AnnouncementDelay", 30));
|
||||
@ -768,6 +780,11 @@ public class GeneralConfigManager {
|
||||
}
|
||||
c.addComment("Economy.Limit.Exp.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours");
|
||||
limit.setTimeLimit(c.get("Economy.Limit.Exp.TimeLimit", 3600));
|
||||
|
||||
c.addComment("Economy.Limit.Exp.ResetTime", "Time in 24 hour format when limit should reset. This will override TimeLimit if defined",
|
||||
"Example: '00:00:00' will reset timer at midnight, '04:30:00' will reset at 4:30 in the morning", "Set to empty field if you want to use TimeLimit");
|
||||
limit.setResetsAt(c.get("Economy.Limit.Exp.ResetTime", ""));
|
||||
|
||||
c.addComment("Economy.Limit.Exp.AnnouncementDelay", "Delay between announcements about reached Exp limit",
|
||||
"Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying");
|
||||
limit.setAnnouncementDelay(c.get("Economy.Limit.Exp.AnnouncementDelay", 30));
|
||||
|
@ -4,12 +4,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.Zrips.CMILib.Equations.Parser;
|
||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||
|
||||
public class CurrencyLimit {
|
||||
|
||||
private boolean enabled;
|
||||
private List<CurrencyType> stopWith;
|
||||
private int timeLimit;
|
||||
private int timeLimit = 0;
|
||||
private resetTime resetsAt = null;
|
||||
private int announcementDelay;
|
||||
private Parser maxEquation;
|
||||
|
||||
@ -66,4 +68,40 @@ public class CurrencyLimit {
|
||||
this.maxEquation = maxEquation;
|
||||
}
|
||||
|
||||
public resetTime getResetsAt() {
|
||||
|
||||
return resetsAt;
|
||||
}
|
||||
|
||||
public void setResetsAt(int hour, int minute, int second) {
|
||||
this.resetsAt = new resetTime(hour, minute, second);
|
||||
}
|
||||
|
||||
public void setResetsAt(String resetsAt) {
|
||||
|
||||
if (resetsAt.isEmpty())
|
||||
return;
|
||||
|
||||
int hour = 0;
|
||||
int minute = 0;
|
||||
int second = 0;
|
||||
|
||||
String[] split = resetsAt.split(":");
|
||||
try {
|
||||
hour = Integer.parseInt(split[0]);
|
||||
|
||||
if (split.length >= 2) {
|
||||
minute = Integer.parseInt(split[1]);
|
||||
}
|
||||
if (split.length >= 3) {
|
||||
second = Integer.parseInt(split[2]);
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
CMIMessages.consoleMessage("Failed to recognize reset time as " + resetsAt);
|
||||
return;
|
||||
}
|
||||
|
||||
setResetsAt(hour, minute, second);
|
||||
}
|
||||
}
|
||||
|
58
src/main/java/com/gamingmesh/jobs/container/resetTime.java
Normal file
58
src/main/java/com/gamingmesh/jobs/container/resetTime.java
Normal file
@ -0,0 +1,58 @@
|
||||
package com.gamingmesh.jobs.container;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class resetTime {
|
||||
|
||||
private int hour = 0;
|
||||
private int minute = 0;
|
||||
private int second = 0;
|
||||
|
||||
public resetTime(int hour, int minute, int second) {
|
||||
this.hour = hour % 24;
|
||||
this.minute = minute % 60;
|
||||
this.second = second % 60;
|
||||
}
|
||||
|
||||
public int getHour() {
|
||||
return hour;
|
||||
}
|
||||
|
||||
public void setHour(int hour) {
|
||||
this.hour = hour;
|
||||
}
|
||||
|
||||
public int getMinute() {
|
||||
return minute;
|
||||
}
|
||||
|
||||
public void setMinute(int minute) {
|
||||
this.minute = minute;
|
||||
}
|
||||
|
||||
public int getSecond() {
|
||||
return second;
|
||||
}
|
||||
|
||||
public void setSecond(int second) {
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public long toMili() {
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
|
||||
calendar.set(Calendar.HOUR_OF_DAY, hour);
|
||||
calendar.set(Calendar.MINUTE, minute);
|
||||
calendar.set(Calendar.SECOND, second);
|
||||
|
||||
if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||
}
|
||||
|
||||
return calendar.getTimeInMillis();
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +1,49 @@
|
||||
package com.gamingmesh.jobs.economy;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.container.CurrencyLimit;
|
||||
import com.gamingmesh.jobs.container.CurrencyType;
|
||||
|
||||
public class LimitsData {
|
||||
private CurrencyType type = null;
|
||||
private double amount = 0D;
|
||||
private long paymentsTime = 0L;
|
||||
private long resetsAt = 0L;
|
||||
private boolean reseted = false;
|
||||
|
||||
@Deprecated
|
||||
public LimitsData(CurrencyType type, long paymentsTime) {
|
||||
this(type, paymentsTime, 0D);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public LimitsData(CurrencyType type, long paymentsTime, double payment) {
|
||||
this.type = type;
|
||||
this.paymentsTime = paymentsTime;
|
||||
CurrencyLimit limit = Jobs.getGCManager().getLimit(type);
|
||||
if (limit.getResetsAt() != null) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
resetsAt = limit.getResetsAt().toMili();
|
||||
} else
|
||||
resetsAt = (limit.getTimeLimit() * 100L) + System.currentTimeMillis();
|
||||
this.amount = payment;
|
||||
}
|
||||
|
||||
public LimitsData(CurrencyType type, double payment) {
|
||||
this.type = type;
|
||||
this.paymentsTime = System.currentTimeMillis();
|
||||
CurrencyLimit limit = Jobs.getGCManager().getLimit(type);
|
||||
|
||||
if (limit.getResetsAt() != null) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
resetsAt = limit.getResetsAt().toMili();
|
||||
} else
|
||||
resetsAt = (limit.getTimeLimit() * 100L) + System.currentTimeMillis();
|
||||
this.amount = payment;
|
||||
}
|
||||
|
||||
@ -54,4 +83,12 @@ public class LimitsData {
|
||||
this.paymentsTime = paymentsTime;
|
||||
}
|
||||
|
||||
public long getResetsAt() {
|
||||
return resetsAt;
|
||||
}
|
||||
|
||||
public void setResetsAt(long resetsAt) {
|
||||
this.resetsAt = resetsAt;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.gamingmesh.jobs.economy;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.container.CurrencyLimit;
|
||||
import com.gamingmesh.jobs.container.CurrencyType;
|
||||
|
||||
public class PaymentData {
|
||||
@ -13,20 +14,20 @@ public class PaymentData {
|
||||
|
||||
private boolean informed = false;
|
||||
|
||||
public PaymentData(Long time, Double Payment, Double Points, Double Exp, Long lastAnnouced, boolean Informed) {
|
||||
payments.put(CurrencyType.EXP, new LimitsData(CurrencyType.EXP, time, Exp));
|
||||
payments.put(CurrencyType.MONEY, new LimitsData(CurrencyType.MONEY, time, Payment));
|
||||
payments.put(CurrencyType.POINTS, new LimitsData(CurrencyType.POINTS, time, Points));
|
||||
this.lastAnnouced = lastAnnouced;
|
||||
this.informed = Informed;
|
||||
}
|
||||
// public PaymentData(Long time, Double Payment, Double Points, Double Exp, Long lastAnnouced, boolean Informed) {
|
||||
// payments.put(CurrencyType.EXP, new LimitsData(CurrencyType.EXP, time, Exp));
|
||||
// payments.put(CurrencyType.MONEY, new LimitsData(CurrencyType.MONEY, time, Payment));
|
||||
// payments.put(CurrencyType.POINTS, new LimitsData(CurrencyType.POINTS, time, Points));
|
||||
// this.lastAnnouced = lastAnnouced;
|
||||
// this.informed = Informed;
|
||||
// }
|
||||
|
||||
public PaymentData(CurrencyType type, Double amount) {
|
||||
for (CurrencyType one : CurrencyType.values()) {
|
||||
if (one != type)
|
||||
payments.put(one, new LimitsData(one, System.currentTimeMillis(), 0D));
|
||||
payments.put(one, new LimitsData(one, 0D));
|
||||
}
|
||||
payments.put(type, new LimitsData(type, System.currentTimeMillis(), amount));
|
||||
payments.put(type, new LimitsData(type, amount));
|
||||
}
|
||||
|
||||
public PaymentData() {
|
||||
@ -74,7 +75,15 @@ public class PaymentData {
|
||||
}
|
||||
|
||||
public void addNewAmount(CurrencyType type, Double Payment, Long time) {
|
||||
payments.put(type, new LimitsData(type, time == null ? System.currentTimeMillis() : time, Payment));
|
||||
|
||||
// payments.put(type, new LimitsData(type, time == null ? System.currentTimeMillis() : time, Payment));
|
||||
|
||||
LimitsData data = new LimitsData(type, Payment);
|
||||
|
||||
if (time != null)
|
||||
data.setPaymentsTime(time);
|
||||
|
||||
payments.put(type, data);
|
||||
}
|
||||
|
||||
public void addAmount(CurrencyType type, double payment) {
|
||||
@ -82,7 +91,16 @@ public class PaymentData {
|
||||
}
|
||||
|
||||
public long getLeftTime(CurrencyType type) {
|
||||
long left = getTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000);
|
||||
|
||||
CurrencyLimit limit = Jobs.getGCManager().getLimit(type);
|
||||
if (limit.getResetsAt() != null) {
|
||||
LimitsData data = payments.get(type);
|
||||
if (data.getResetsAt() < System.currentTimeMillis())
|
||||
return 0L;
|
||||
return data.getResetsAt() - System.currentTimeMillis();
|
||||
}
|
||||
|
||||
long left = getTime(type) + (limit.getTimeLimit() * 1000);
|
||||
return left > System.currentTimeMillis() ? left - System.currentTimeMillis() : 0L;
|
||||
}
|
||||
|
||||
@ -95,7 +113,7 @@ public class PaymentData {
|
||||
}
|
||||
|
||||
public boolean isOverTimeLimit(CurrencyType type) {
|
||||
if (getTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis()) {
|
||||
if (getLeftTime(type) > 0) {
|
||||
return false;
|
||||
}
|
||||
if (informed)
|
||||
|
Loading…
Reference in New Issue
Block a user