mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-06 11:24:39 +08:00
Add indication of when kit's cannot be used yet, in the /kit output.
This commit is contained in:
parent
293406a603
commit
9dc6e7ad1e
@ -33,13 +33,20 @@ public class Kit
|
||||
else if (user.isAuthorized("essentials.kits." + kitItem.toLowerCase(Locale.ENGLISH)))
|
||||
{
|
||||
String cost = "";
|
||||
String name = capitalCase(kitItem);
|
||||
BigDecimal costPrice = new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user);
|
||||
if (costPrice.signum() > 0)
|
||||
{
|
||||
cost = _("kitCost", Util.displayCurrency(costPrice, ess));
|
||||
}
|
||||
final Map<String, Object> kit = ess.getSettings().getKit(kitItem);
|
||||
|
||||
list.append(" ").append(capitalCase(kitItem)).append(cost);
|
||||
if (Kit.getNextUse(user, kitItem, kit) != 0)
|
||||
{
|
||||
name = _("kitDelay", name);
|
||||
}
|
||||
|
||||
list.append(" ").append(name).append(cost);
|
||||
}
|
||||
}
|
||||
return list.toString().trim();
|
||||
@ -53,58 +60,76 @@ public class Kit
|
||||
|
||||
public static void checkTime(final User user, final String kitName, final Map<String, Object> els) throws Exception
|
||||
{
|
||||
if (user.isAuthorized("essentials.kit.exemptdelay"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Calendar time = new GregorianCalendar();
|
||||
long nextUse = getNextUse(user, kitName, els);
|
||||
|
||||
// Take the current time, and remove the delay from it.
|
||||
double delay = 0;
|
||||
try
|
||||
{
|
||||
// Also make sure delay is valid
|
||||
delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0.0d;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception(_("kitError2"));
|
||||
}
|
||||
final Calendar earliestTime = new GregorianCalendar();
|
||||
earliestTime.add(Calendar.SECOND, -(int)delay);
|
||||
earliestTime.add(Calendar.MILLISECOND, -(int)((delay * 1000.0) % 1000.0));
|
||||
// This value contains the most recent time a kit could have been used that would allow another use.
|
||||
final long earliestLong = earliestTime.getTimeInMillis();
|
||||
|
||||
// When was the last kit used?
|
||||
final long lastTime = user.getKitTimestamp(kitName);
|
||||
|
||||
if (lastTime < earliestLong || lastTime == 0L)
|
||||
if (nextUse == 0L)
|
||||
{
|
||||
user.setKitTimestamp(kitName, time.getTimeInMillis());
|
||||
}
|
||||
else if (lastTime > time.getTimeInMillis())
|
||||
{
|
||||
// This is to make sure time didn't get messed up on last kit use.
|
||||
// If this happens, let's give the user the benifit of the doubt.
|
||||
user.setKitTimestamp(kitName, time.getTimeInMillis());
|
||||
}
|
||||
else if (earliestLong < 0L)
|
||||
else if (nextUse < 0L)
|
||||
{
|
||||
user.sendMessage(_("kitOnce"));
|
||||
throw new NoChargeException();
|
||||
}
|
||||
else
|
||||
{
|
||||
time.setTimeInMillis(lastTime);
|
||||
time.add(Calendar.SECOND, (int)delay);
|
||||
time.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
|
||||
user.sendMessage(_("kitTimed", Util.formatDateDiff(time.getTimeInMillis())));
|
||||
user.sendMessage(_("kitTimed", Util.formatDateDiff(nextUse)));
|
||||
throw new NoChargeException();
|
||||
}
|
||||
}
|
||||
|
||||
public static long getNextUse(final User user, final String kitName, final Map<String, Object> els) throws Exception
|
||||
{
|
||||
if (user.isAuthorized("essentials.kit.exemptdelay"))
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
|
||||
final Calendar time = new GregorianCalendar();
|
||||
|
||||
double delay = 0;
|
||||
try
|
||||
{
|
||||
// Make sure delay is valid
|
||||
delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0.0d;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception(_("kitError2"));
|
||||
}
|
||||
|
||||
// When was the last kit used?
|
||||
final long lastTime = user.getKitTimestamp(kitName);
|
||||
|
||||
// When can be use the kit again?
|
||||
final Calendar delayTime = new GregorianCalendar();
|
||||
delayTime.setTimeInMillis(lastTime);
|
||||
delayTime.add(Calendar.SECOND, (int)delay);
|
||||
delayTime.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
|
||||
|
||||
if (lastTime == 0L || lastTime > time.getTimeInMillis())
|
||||
{
|
||||
// If we have no record of kit use, or its corrupted, give them benifit of the doubt.
|
||||
return 0L;
|
||||
}
|
||||
else if (delay < 0d)
|
||||
{
|
||||
// If the kit has a negative kit time, it can only be used once.
|
||||
return -1;
|
||||
}
|
||||
else if (delayTime.before(time))
|
||||
{
|
||||
// If the kit was used in the past, but outside the delay time, it can be used.
|
||||
return 0L;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the kit has been used recently, return the next time it can be used.
|
||||
return delayTime.getTimeInMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getItems(final User user, final Map<String, Object> kit) throws Exception
|
||||
{
|
||||
if (kit == null)
|
||||
|
@ -217,7 +217,7 @@ kickExempt=\u00a74You can not kick that person.
|
||||
kickedAll=\u00a74Kicked all players from server.
|
||||
kill=\u00a76Killed\u00a7c {0}\u00a76.
|
||||
killExempt=\u00a74You can not kill {0}
|
||||
kitCost=\ ({0})
|
||||
kitCost=\ \u00a77\u00a7o({0})\u00a7r
|
||||
kitError2=\u00a74That kit is improperly defined. Contact an administrator.
|
||||
kitError=\u00a74There are no valid kits.
|
||||
kitErrorHelp=\u00a74Perhaps an item is missing a quantity in the configuration?
|
||||
@ -540,3 +540,4 @@ years=years
|
||||
youAreHealed=\u00a76You have been healed.
|
||||
youHaveNewMail=\u00a76You have\u00a7c {0} \u00a76messages! Type \u00a7c/mail read\u00a76 to view your mail.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -544,3 +544,4 @@ years=roky
|
||||
youAreHealed=\u00a77Byl jsi uzdraven.
|
||||
youHaveNewMail=\u00a7cMas {0} zprav!\u00a7f Napis \u00a77/mail read\u00a7f aby jsi si precetl sve zpravy.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -540,3 +540,4 @@ years=\u00e5r
|
||||
youAreHealed=\u00a77Du er blevet healed. Halleluja!
|
||||
youHaveNewMail=\u00a7cDu har {0} flaskeposter!\u00a7f Type \u00a77/mail read for at se din flaskepost.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -540,3 +540,4 @@ years=Jahre
|
||||
youAreHealed=\u00a77Du wurdest geheilt.
|
||||
youHaveNewMail=\u00a7cDu hast {0} Nachrichten!\u00a7f Schreibe \u00a77/mail read\u00a7f um deine Nachrichten anzuzeigen.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -217,7 +217,7 @@ kickExempt=\u00a74You can not kick that person.
|
||||
kickedAll=\u00a74Kicked all players from server.
|
||||
kill=\u00a76Killed\u00a7c {0}\u00a76.
|
||||
killExempt=\u00a74You can not kill {0}
|
||||
kitCost=\ ({0})
|
||||
kitCost=\ \u00a77\u00a7o({0})\u00a7r
|
||||
kitError2=\u00a74That kit is improperly defined. Contact an administrator.
|
||||
kitError=\u00a74There are no valid kits.
|
||||
kitErrorHelp=\u00a74Perhaps an item is missing a quantity in the configuration?
|
||||
@ -540,3 +540,4 @@ years=years
|
||||
youAreHealed=\u00a76You have been healed.
|
||||
youHaveNewMail=\u00a76You have\u00a7c {0} \u00a76messages! Type \u00a7c/mail read\u00a76 to view your mail.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -540,3 +540,4 @@ years=anos
|
||||
youAreHealed=\u00a77Has sido curado.
|
||||
youHaveNewMail=\u00a7cTienes {0} mensajes!\u00a7f Pon \u00a77/mail read\u00a7f para ver tus emails no leidos!.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -540,3 +540,4 @@ years=vuosia
|
||||
youAreHealed=\u00a77Sinut on parannettu.
|
||||
youHaveNewMail=\u00a7cSinulla on {0} viesti(\u00e4)!\u00a7f Kirjoita \u00a77/mail read\u00a7f lukeaksesi viestit.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -540,3 +540,4 @@ years=ann\u00e9es
|
||||
youAreHealed=\u00a77Vous avez \u00e9t\u00e9 soign\u00e9.
|
||||
youHaveNewMail=\u00a7cVous avez {0} message(s) ! \u00a7fEntrez \u00a77/mail read\u00a7f pour voir votre courrier.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -540,3 +540,4 @@ years=anni
|
||||
youAreHealed=\u00a77Sei stato curato.
|
||||
youHaveNewMail=\u00a7cHai {0} messaggi!\u00a7f digita \u00a77/mail read\u00a7f per consultare la tua mail.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -540,3 +540,4 @@ years=jaren
|
||||
youAreHealed=\u00a77Je bent genezen.
|
||||
youHaveNewMail=\u00a7cJe hebt {0} berichten!\u00a7f Type \u00a77/mail read\u00a7f om je berichten te bekijken.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -540,3 +540,4 @@ years=lat
|
||||
youAreHealed=\u00a77Zostales uleczony.
|
||||
youHaveNewMail=\u00a77Masz\u00a7c {0} \u00a77wiadomosci! Wpisz \u00a7c/mail read\u00a77 aby je przeczytac.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -540,3 +540,4 @@ years=anos
|
||||
youAreHealed=\u00a76Voc\u00c3\u00aa foi curado.
|
||||
youHaveNewMail=\u00a76Voc\u00c3\u00aa tem\u00a7c {0} \u00a76mensagens! Digite \u00a7c/mail read\u00a76 para v\u00c3\u00aa-las.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -540,3 +540,4 @@ years=ani
|
||||
youAreHealed=\u00a76Ai fost vindecat.
|
||||
youHaveNewMail=\u00a76Ai\u00a7c {0} \u00a76mesaje! scrie \u00a7c/mail read\u00a76 pentru a-ti vedea mesajele.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -540,3 +540,4 @@ years=\u00e5r
|
||||
youAreHealed=\u00a77Du har blivit l\u00e4kt.
|
||||
youHaveNewMail=\u00a7cDu har {0} meddelanden!\u00a7f Skriv \u00a77/mail read\u00a7f f\u00f6r att l\u00e4sa dina meddelanden.
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -541,3 +541,4 @@ years=\u5e74
|
||||
youAreHealed=\u00a76\u4f60\u5df2\u88ab\u6cbb\u7597
|
||||
youHaveNewMail=\u00a76\u4f60\u62e5\u6709 \u00a7c{0}\u00a76 \u6761\u6d88\u606f\uff01\u00a7r\u8f93\u5165 \u00a7c/mail read\u00a76 \u6765\u67e5\u770b
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -542,3 +542,4 @@ years=\u5e74
|
||||
youAreHealed=\u00a76\u4f60\u5df2\u88ab\u6cbb\u7642
|
||||
youHaveNewMail=\u00a76\u4f60\u64c1\u6709 \u00a7c{0}\u00a76 \u689d\u6d88\u606f\uff01\u00a7r\u8f38\u5165 \u00a7c/mail read\u00a76 \u4f86\u67e5\u770b
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
@ -542,3 +542,4 @@ years=\u5e74
|
||||
youAreHealed=\u00a76\u4f60\u5df2\u88ab\u6cbb\u7642
|
||||
youHaveNewMail=\u00a76\u4f60\u64c1\u6709 \u00a7c{0}\u00a76 \u689d\u6d88\u606f\uff01\u00a7r\u8f38\u5165 \u00a7c/mail read\u00a76 \u4f86\u67e5\u770b
|
||||
whoisHunger=\u00a76 - Hunger:\u00a7r {0}/20 (+{1} saturation)
|
||||
kitDelay=\u00a7m{0}\u00a7r
|
||||
|
Loading…
Reference in New Issue
Block a user