mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-18 01:46:44 +01:00
Convert to the superior language system. (pt. 2)
This commit is contained in:
@@ -15,6 +15,8 @@ import io.netty.buffer.Unpooled;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
@SuppressWarnings({"UnusedReturnValue", "BooleanMethodIsAlwaysInverted"})
|
||||
public final class Utils {
|
||||
public static final Random random = new Random();
|
||||
@@ -176,15 +178,15 @@ public final class Utils {
|
||||
|
||||
// Check for resources folder.
|
||||
if(!fileExists(resourcesFolder)) {
|
||||
logger.info(Grasscutter.getLanguage().Create_resources_folder);
|
||||
logger.info(Grasscutter.getLanguage().Place_copy);
|
||||
logger.info(translate("messages.status.create_resources"));
|
||||
logger.info(translate("messages.status.resources_error"));
|
||||
createFolder(resourcesFolder); exit = true;
|
||||
}
|
||||
|
||||
// Check for BinOutput + ExcelBinOuput.
|
||||
// Check for BinOutput + ExcelBinOutput.
|
||||
if(!fileExists(resourcesFolder + "BinOutput") ||
|
||||
!fileExists(resourcesFolder + "ExcelBinOutput")) {
|
||||
logger.info(Grasscutter.getLanguage().Place_copy);
|
||||
logger.info(translate("messages.status.resources_error"));
|
||||
exit = true;
|
||||
}
|
||||
|
||||
@@ -195,7 +197,11 @@ public final class Utils {
|
||||
if(exit) System.exit(1);
|
||||
}
|
||||
|
||||
public static int GetNextTimestampOfThisHour(int hour, String timeZone, int param) {
|
||||
/**
|
||||
* Gets the timestamp of the next hour.
|
||||
* @return The timestamp in UNIX seconds.
|
||||
*/
|
||||
public static int getNextTimestampOfThisHour(int hour, String timeZone, int param) {
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of(timeZone));
|
||||
for (int i = 0; i < param; i ++){
|
||||
if (zonedDateTime.getHour() < hour) {
|
||||
@@ -204,10 +210,14 @@ public final class Utils {
|
||||
zonedDateTime = zonedDateTime.plusDays(1).withHour(hour).withMinute(0).withSecond(0);
|
||||
}
|
||||
}
|
||||
return (int)zonedDateTime.toInstant().atZone(ZoneOffset.UTC).toEpochSecond();
|
||||
return (int) zonedDateTime.toInstant().atZone(ZoneOffset.UTC).toEpochSecond();
|
||||
}
|
||||
|
||||
public static int GetNextTimestampOfThisHourInNextWeek(int hour, String timeZone, int param) {
|
||||
/**
|
||||
* Gets the timestamp of the next hour in a week.
|
||||
* @return The timestamp in UNIX seconds.
|
||||
*/
|
||||
public static int getNextTimestampOfThisHourInNextWeek(int hour, String timeZone, int param) {
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of(timeZone));
|
||||
for (int i = 0; i < param; i++) {
|
||||
if (zonedDateTime.getDayOfWeek() == DayOfWeek.MONDAY && zonedDateTime.getHour() < hour) {
|
||||
@@ -216,10 +226,14 @@ public final class Utils {
|
||||
zonedDateTime = zonedDateTime.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).withHour(hour).withMinute(0).withSecond(0);
|
||||
}
|
||||
}
|
||||
return (int)zonedDateTime.toInstant().atZone(ZoneOffset.UTC).toEpochSecond();
|
||||
return (int) zonedDateTime.toInstant().atZone(ZoneOffset.UTC).toEpochSecond();
|
||||
}
|
||||
|
||||
public static int GetNextTimestampOfThisHourInNextMonth(int hour, String timeZone, int param) {
|
||||
/**
|
||||
* Gets the timestamp of the next hour in a month.
|
||||
* @return The timestamp in UNIX seconds.
|
||||
*/
|
||||
public static int getNextTimestampOfThisHourInNextMonth(int hour, String timeZone, int param) {
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of(timeZone));
|
||||
for (int i = 0; i < param; i++) {
|
||||
if (zonedDateTime.getDayOfMonth() == 1 && zonedDateTime.getHour() < hour) {
|
||||
@@ -228,6 +242,22 @@ public final class Utils {
|
||||
zonedDateTime = zonedDateTime.with(TemporalAdjusters.firstDayOfNextMonth()).withHour(hour).withMinute(0).withSecond(0);
|
||||
}
|
||||
}
|
||||
return (int)zonedDateTime.toInstant().atZone(ZoneOffset.UTC).toEpochSecond();
|
||||
return (int) zonedDateTime.toInstant().atZone(ZoneOffset.UTC).toEpochSecond();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a string from an input stream.
|
||||
* @param stream The input stream.
|
||||
* @return The string.
|
||||
*/
|
||||
public static String readFromInputStream(InputStream stream) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
|
||||
String line; while ((line = reader.readLine()) != null) {
|
||||
stringBuilder.append(line);
|
||||
} stream.close();
|
||||
} catch (IOException e) {
|
||||
Grasscutter.getLogger().warn("Failed to read from input stream.");
|
||||
} return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user