Implement %prettytime% on signs, time in a pretty format. Adds #35
The variable of %prettytime% will be replaced on signs and also a nice format on the status message will be added.
This commit is contained in:
@ -99,16 +99,17 @@ public class Util {
|
||||
|
||||
/** Returns a message with all the possible variables replaced. */
|
||||
public static String replaceAllVariables(Prisoner p, String msg) {
|
||||
msg = msg.replaceAll("%player%", p.getLastKnownName());
|
||||
msg = msg.replaceAll("%uuid%", p.getUUID().toString());
|
||||
msg = msg.replaceAll("%reason%", p.getReason());
|
||||
msg = msg.replaceAll("%jailer", p.getJailer());
|
||||
msg = msg.replaceAll("%afktime%", TimeUnit.MINUTES.convert(p.getAFKTime(), TimeUnit.MILLISECONDS) + " mins");
|
||||
msg = msg.replace("%player%", p.getLastKnownName())
|
||||
.replace("%uuid%", p.getUUID().toString())
|
||||
.replace("%reason%", p.getReason())
|
||||
.replace("%jailer", p.getJailer())
|
||||
.replace("%afktime%", Util.getDurationBreakdown(p.getAFKTime()));
|
||||
|
||||
if(p.getRemainingTime() >= 0) {
|
||||
msg = msg.replaceAll("%timeinminutes%", String.valueOf(p.getRemainingTimeInMinutes()));
|
||||
msg = msg.replace("%timeinminutes%", String.valueOf(p.getRemainingTimeInMinutes()));
|
||||
msg = msg.replace("%prettytime%", Util.getDurationBreakdown(p.getRemainingTime()));
|
||||
}else {
|
||||
msg = msg.replaceAll("%timeinminutes%", Lang.JAILEDFOREVERSIGN.get());
|
||||
msg = msg.replace("%timeinminutes%", Lang.JAILEDFOREVERSIGN.get());
|
||||
}
|
||||
|
||||
return getColorfulMessage(msg);
|
||||
@ -177,6 +178,47 @@ public class Util {
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a millisecond duration to a string format
|
||||
*
|
||||
* @param millis A duration to convert to a string form
|
||||
* @return A string of the form "XdYhZAs".
|
||||
*/
|
||||
public static String getDurationBreakdown(long millis) {
|
||||
if(millis < 0) {
|
||||
throw new IllegalArgumentException("Duration must be greater than zero!");
|
||||
}
|
||||
|
||||
long days = TimeUnit.MILLISECONDS.toDays(millis);
|
||||
millis -= TimeUnit.DAYS.toMillis(days);
|
||||
long hours = TimeUnit.MILLISECONDS.toHours(millis);
|
||||
millis -= TimeUnit.HOURS.toMillis(hours);
|
||||
long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
|
||||
millis -= TimeUnit.MINUTES.toMillis(minutes);
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);
|
||||
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
if(days > 0) {
|
||||
sb.append(days);
|
||||
sb.append("d");
|
||||
}
|
||||
|
||||
if(days > 0 || hours > 0) {
|
||||
sb.append(hours);
|
||||
sb.append("h");
|
||||
}
|
||||
|
||||
if(days > 0 || hours > 0 || minutes > 0) {
|
||||
sb.append(minutes);
|
||||
sb.append("m");
|
||||
}
|
||||
|
||||
sb.append(seconds);
|
||||
sb.append("s");
|
||||
|
||||
return(sb.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the player inventory to a String array of Base64 strings. First string is the content and second string is the armor.
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
@ -25,7 +26,7 @@ public class JailStatusCommand implements Command{
|
||||
if(jm.isPlayerJailed(pl.getUniqueId())) {
|
||||
Prisoner p = jm.getPrisoner(pl.getUniqueId());
|
||||
//They are jailed, so let's tell them some information
|
||||
sender.sendMessage(Lang.STATUS.get(new String[] { p.getReason(), p.getJailer(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
sender.sendMessage(Lang.STATUS.get(new String[] { p.getReason(), p.getJailer(), String.valueOf(p.getRemainingTimeInMinutes()), Util.getDurationBreakdown(p.getRemainingTime()) }));
|
||||
}else {
|
||||
//the sender of the command is not jailed, tell them that
|
||||
sender.sendMessage(Lang.YOUARENOTJAILED.get());
|
||||
|
Reference in New Issue
Block a user