Use TimeUnit for time calculations
This commit is contained in:
@@ -27,6 +27,8 @@ import client.Client;
|
||||
import client.command.Command;
|
||||
import net.server.Server;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.*;
|
||||
|
||||
public class UptimeCommand extends Command {
|
||||
{
|
||||
setDescription("Show server online time.");
|
||||
@@ -35,10 +37,10 @@ public class UptimeCommand extends Command {
|
||||
@Override
|
||||
public void execute(Client c, String[] params) {
|
||||
long milliseconds = System.currentTimeMillis() - Server.uptime;
|
||||
int seconds = (int) (milliseconds / 1000) % 60;
|
||||
int minutes = (int) ((milliseconds / (1000 * 60)) % 60);
|
||||
int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24);
|
||||
int days = (int) ((milliseconds / (1000 * 60 * 60 * 24)));
|
||||
int seconds = (int) (milliseconds / SECONDS.toMillis(1)) % 60;
|
||||
int minutes = (int) ((milliseconds / MINUTES.toMillis(1)) % 60);
|
||||
int hours = (int) ((milliseconds / HOURS.toMillis(1)) % 24);
|
||||
int days = (int) ((milliseconds / DAYS.toMillis(1)));
|
||||
c.getPlayer().yellowMessage("Server has been online for " + days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ import config.YamlConfig;
|
||||
import constants.inventory.ItemConstants;
|
||||
import server.ItemInformationProvider;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.DAYS;
|
||||
|
||||
public class ItemCommand extends Command {
|
||||
{
|
||||
setDescription("Spawn an item into your inventory.");
|
||||
@@ -68,7 +70,7 @@ public class ItemCommand extends Command {
|
||||
if (params.length >= 2) { // thanks to istreety & TacoBell
|
||||
quantity = 1;
|
||||
long days = Math.max(1, Integer.parseInt(params[1]));
|
||||
long expiration = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000);
|
||||
long expiration = System.currentTimeMillis() + DAYS.toMillis(days);
|
||||
int petid = Pet.createPet(itemId);
|
||||
|
||||
InventoryManipulator.addById(c, itemId, quantity, player.getName(), petid, expiration);
|
||||
|
||||
@@ -33,6 +33,8 @@ import config.YamlConfig;
|
||||
import constants.inventory.ItemConstants;
|
||||
import server.ItemInformationProvider;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.DAYS;
|
||||
|
||||
public class ItemDropCommand extends Command {
|
||||
{
|
||||
setDescription("Spawn an item onto the ground.");
|
||||
@@ -69,7 +71,7 @@ public class ItemDropCommand extends Command {
|
||||
if (params.length >= 2) { // thanks to istreety & TacoBell
|
||||
quantity = 1;
|
||||
long days = Math.max(1, Integer.parseInt(params[1]));
|
||||
long expiration = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000);
|
||||
long expiration = System.currentTimeMillis() + DAYS.toMillis(days);
|
||||
int petid = Pet.createPet(itemId);
|
||||
|
||||
Item toDrop = new Item(itemId, (short) 0, quantity, petid);
|
||||
|
||||
@@ -29,6 +29,8 @@ import client.command.Command;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.Portal;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
|
||||
public class JailCommand extends Command {
|
||||
{
|
||||
setDescription("Move a player to the jail.");
|
||||
@@ -53,7 +55,7 @@ public class JailCommand extends Command {
|
||||
|
||||
Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]);
|
||||
if (victim != null) {
|
||||
victim.addJailExpirationTime(minutesJailed * 60 * 1000);
|
||||
victim.addJailExpirationTime(MINUTES.toMillis(minutesJailed));
|
||||
|
||||
int mapid = 300000012;
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ import net.server.Server;
|
||||
import net.server.world.World;
|
||||
import server.TimerManager;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.*;
|
||||
|
||||
public class ShutdownCommand extends Command {
|
||||
{
|
||||
setDescription("Shut down the server.");
|
||||
@@ -51,10 +53,10 @@ public class ShutdownCommand extends Command {
|
||||
}
|
||||
|
||||
if (time > 1) {
|
||||
int seconds = (time / 1000) % 60;
|
||||
int minutes = (time / (1000 * 60)) % 60;
|
||||
int hours = (time / (1000 * 60 * 60)) % 24;
|
||||
int days = (time / (1000 * 60 * 60 * 24));
|
||||
int seconds = (time / (int) SECONDS.toMillis(1)) % 60;
|
||||
int minutes = (time / (int) MINUTES.toMillis(1)) % 60;
|
||||
int hours = (time / (int) HOURS.toMillis(1)) % 24;
|
||||
int days = (time / (int) DAYS.toMillis(1));
|
||||
|
||||
String strTime = "";
|
||||
if (days > 0) {
|
||||
|
||||
Reference in New Issue
Block a user