mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
add tempban punishment type and swap localdatetime zoneddatetime, as well as reload timezone on /plex reload
This commit is contained in:
parent
bae1e49c5e
commit
a00c6926c4
@ -14,8 +14,11 @@ import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import dev.plex.util.WebUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -84,7 +87,7 @@ public class BanCMD extends PlexCommand
|
||||
punishment.setReason("No reason provided.");
|
||||
}
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
punishment.setEndDate(date.plusDays(1));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(!isAdmin(plexPlayer));
|
||||
|
@ -10,7 +10,11 @@ import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -51,7 +55,7 @@ public class FreezeCMD extends PlexCommand
|
||||
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
punishment.setEndDate(date.plusMinutes(5));
|
||||
punishment.setType(PunishmentType.FREEZE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
|
@ -11,8 +11,11 @@ import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import dev.plex.util.WebUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -57,7 +60,7 @@ public class KickCMD extends PlexCommand
|
||||
}
|
||||
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
punishment.setEndDate(LocalDateTime.now());
|
||||
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(false);
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
|
@ -10,7 +10,11 @@ import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -51,7 +55,7 @@ public class MuteCMD extends PlexCommand
|
||||
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
punishment.setEndDate(date.plusMinutes(5));
|
||||
punishment.setType(PunishmentType.MUTE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
|
@ -43,12 +43,12 @@ public class NameHistoryCMD extends PlexCommand
|
||||
List<Component> historyList = Lists.newArrayList();
|
||||
Arrays.stream(info.getUsernameHistories()).forEach(history ->
|
||||
{
|
||||
if (history.getLocalDateTime() != null)
|
||||
if (history.getZonedDateTime() != null)
|
||||
{
|
||||
historyList.add(
|
||||
messageComponent("nameHistoryBody",
|
||||
history.getUsername(),
|
||||
TimeUtils.useTimezone(history.getLocalDateTime())));
|
||||
TimeUtils.useTimezone(history.getZonedDateTime())));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -11,6 +11,8 @@ import dev.plex.storage.StorageType;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -75,7 +77,7 @@ public class NotesCMD extends PlexCommand
|
||||
String content = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ");
|
||||
if (playerSender != null)
|
||||
{
|
||||
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), LocalDateTime.now());
|
||||
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
plexPlayer.getNotes().add(note);
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@ -15,6 +16,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -63,6 +66,8 @@ public class PlexCMD extends PlexCommand
|
||||
plugin.getServiceManager().endServices();
|
||||
plugin.getServiceManager().startServices();
|
||||
PlexLog.debug("Restarted services");
|
||||
TimeUtils.TIMEZONE = plugin.config.getString("server.timezone");
|
||||
send(sender, "Set timezone to: " + TimeUtils.TIMEZONE);
|
||||
send(sender, "Plex successfully reloaded.");
|
||||
return null;
|
||||
}
|
||||
|
@ -10,8 +10,12 @@ import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.title.Title;
|
||||
@ -125,7 +129,7 @@ public class SmiteCMD extends PlexCommand
|
||||
|
||||
Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setEndDate(LocalDateTime.now());
|
||||
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setType(PunishmentType.SMITE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
|
@ -12,11 +12,13 @@ import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.extra.Note;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.storage.StorageType;
|
||||
import dev.plex.util.adapter.LocalDateTimeSerializer;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -140,6 +142,6 @@ public class PlexPlayer
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).create().toJson(this);
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,11 @@ import dev.plex.Plex;
|
||||
import dev.plex.util.MojangUtils;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import dev.plex.util.adapter.LocalDateTimeDeserializer;
|
||||
import dev.plex.util.adapter.LocalDateTimeSerializer;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.plex.util.adapter.ZonedDateTimeDeserializer;
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -28,7 +29,7 @@ public class Punishment
|
||||
private String reason;
|
||||
private boolean customTime;
|
||||
private boolean active; // Field is only for bans
|
||||
private LocalDateTime endDate;
|
||||
private ZonedDateTime endDate;
|
||||
|
||||
public Punishment()
|
||||
{
|
||||
@ -54,11 +55,11 @@ public class Punishment
|
||||
|
||||
public static Punishment fromJson(String json)
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer()).create().fromJson(json, Punishment.class);
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeDeserializer()).create().fromJson(json, Punishment.class);
|
||||
}
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).create().toJson(this);
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,16 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@ -200,8 +204,8 @@ public class PunishmentManager implements PlexBase
|
||||
if (punishment.getType() == PunishmentType.FREEZE)
|
||||
{
|
||||
player.setFrozen(true);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime then = punishment.getEndDate();
|
||||
ZonedDateTime now = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
ZonedDateTime then = punishment.getEndDate();
|
||||
long seconds = ChronoUnit.SECONDS.between(now, then);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@ -221,8 +225,8 @@ public class PunishmentManager implements PlexBase
|
||||
else if (punishment.getType() == PunishmentType.MUTE)
|
||||
{
|
||||
player.setMuted(true);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime then = punishment.getEndDate();
|
||||
ZonedDateTime now = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
ZonedDateTime then = punishment.getEndDate();
|
||||
long seconds = ChronoUnit.SECONDS.between(now, then);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
@ -2,9 +2,10 @@ package dev.plex.punishment.extra;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.plex.util.adapter.LocalDateTimeSerializer;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ -14,12 +15,12 @@ public class Note
|
||||
private final UUID uuid;
|
||||
private final String note;
|
||||
private final UUID writtenBy;
|
||||
private final LocalDateTime timestamp;
|
||||
private final ZonedDateTime timestamp;
|
||||
|
||||
private int id; // This will be automatically set from addNote
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).create().toJson(this);
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,10 @@ package dev.plex.services.impl;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.services.AbstractService;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@ -20,7 +24,7 @@ public class BanService extends AbstractService
|
||||
{
|
||||
punishments.forEach(punishment ->
|
||||
{
|
||||
if (LocalDateTime.now().isAfter(punishment.getEndDate()))
|
||||
if (ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)).isAfter(punishment.getEndDate()))
|
||||
{
|
||||
Plex.get().getPunishmentManager().unban(punishment);
|
||||
Bukkit.broadcast(Component.text("Plex - Unbanned " + Bukkit.getOfflinePlayer(punishment.getPunished()).getName()));
|
||||
|
@ -3,14 +3,13 @@ package dev.plex.storage.punishment;
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.punishment.extra.Note;
|
||||
import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -37,7 +36,7 @@ public class SQLNotes
|
||||
uuid,
|
||||
set.getString("note"),
|
||||
UUID.fromString(set.getString("written_by")),
|
||||
LocalDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("timestamp")), ZoneId.systemDefault())
|
||||
ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("timestamp")), ZoneId.of(TimeUtils.TIMEZONE))
|
||||
);
|
||||
note.setId(set.getInt("id"));
|
||||
notes.add(note);
|
||||
@ -83,7 +82,7 @@ public class SQLNotes
|
||||
statement.setString(2, note.getUuid().toString());
|
||||
statement.setString(3, note.getWrittenBy().toString());
|
||||
statement.setString(4, note.getNote());
|
||||
statement.setLong(5, note.getTimestamp().toInstant(ZoneOffset.UTC).toEpochMilli());
|
||||
statement.setLong(5, note.getTimestamp().toInstant().toEpochMilli());
|
||||
statement.execute();
|
||||
note.setId(notes.size());
|
||||
}
|
||||
|
@ -5,14 +5,15 @@ import dev.plex.Plex;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -41,13 +42,12 @@ public class SQLPunishment
|
||||
punishment.setType(PunishmentType.valueOf(set.getString("type")));
|
||||
punishment.setCustomTime(set.getBoolean("customTime"));
|
||||
punishment.setPunishedUsername(set.getString("punishedUsername"));
|
||||
punishment.setEndDate(LocalDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("endDate")), ZoneId.systemDefault()));
|
||||
punishment.setEndDate(ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("endDate")), ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setReason(set.getString("reason"));
|
||||
punishment.setIp(set.getString("ip"));
|
||||
punishments.add(punishment);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return punishments;
|
||||
@ -71,13 +71,12 @@ public class SQLPunishment
|
||||
punishment.setType(PunishmentType.valueOf(set.getString("type")));
|
||||
punishment.setCustomTime(set.getBoolean("customTime"));
|
||||
punishment.setPunishedUsername(set.getString("punishedUsername"));
|
||||
punishment.setEndDate(LocalDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("endDate")), ZoneId.systemDefault()));
|
||||
punishment.setEndDate(ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("endDate")), ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setReason(set.getString("reason"));
|
||||
punishment.setIp(set.getString("ip"));
|
||||
punishments.add(punishment);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -101,11 +100,10 @@ public class SQLPunishment
|
||||
statement.setString(6, punishment.getReason());
|
||||
statement.setBoolean(7, punishment.isCustomTime());
|
||||
statement.setBoolean(8, punishment.isActive());
|
||||
statement.setLong(9, punishment.getEndDate().toInstant(ZoneOffset.UTC).toEpochMilli());
|
||||
statement.setLong(9, punishment.getEndDate().toInstant().toEpochMilli());
|
||||
PlexLog.debug("Executing punishment");
|
||||
statement.execute();
|
||||
}
|
||||
catch (SQLException e)
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -121,8 +119,14 @@ public class SQLPunishment
|
||||
statement.setBoolean(2, true);
|
||||
statement.setString(3, uuid.toString());
|
||||
statement.setString(4, PunishmentType.BAN.name());
|
||||
}
|
||||
catch (SQLException e)
|
||||
|
||||
PreparedStatement statement1 = con.prepareStatement(UPDATE_BAN);
|
||||
statement1.setBoolean(1, false);
|
||||
statement1.setBoolean(2, true);
|
||||
statement1.setString(3, uuid.toString());
|
||||
statement1.setString(4, PunishmentType.TEMPBAN.name());
|
||||
statement1.executeUpdate();
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -140,8 +144,14 @@ public class SQLPunishment
|
||||
statement.setString(3, uuid.toString());
|
||||
statement.setString(4, PunishmentType.BAN.name());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException e)
|
||||
|
||||
PreparedStatement statement1 = con.prepareStatement(UPDATE_BAN);
|
||||
statement1.setBoolean(1, false);
|
||||
statement1.setBoolean(2, true);
|
||||
statement1.setString(3, uuid.toString());
|
||||
statement1.setString(4, PunishmentType.TEMPBAN.name());
|
||||
statement1.executeUpdate();
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package dev.plex.util;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@ -25,7 +27,7 @@ public class AshconInfo
|
||||
{
|
||||
private String username;
|
||||
@SerializedName("changed_at")
|
||||
private LocalDateTime localDateTime;
|
||||
private ZonedDateTime zonedDateTime;
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
@ -7,8 +7,11 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
@ -37,16 +40,16 @@ public class MojangUtils
|
||||
return null;
|
||||
}
|
||||
client.close();
|
||||
AshconInfo ashconInfo = new GsonBuilder().registerTypeAdapter(LocalDateTime.class, (JsonDeserializer<LocalDateTime>)(json1, typeOfT, context) ->
|
||||
LocalDateTime.ofInstant(Instant.from(DateTimeFormatter.ISO_INSTANT.parse(json1.getAsJsonPrimitive().getAsString())), ZoneId.systemDefault())).create().fromJson(json, AshconInfo.class);
|
||||
AshconInfo ashconInfo = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, (JsonDeserializer<ZonedDateTime>)(json1, typeOfT, context) ->
|
||||
ZonedDateTime.ofInstant(Instant.from(DateTimeFormatter.ISO_INSTANT.parse(json1.getAsJsonPrimitive().getAsString())), ZoneId.of(Plex.get().config.getString("server.timezone")))).create().fromJson(json, AshconInfo.class);
|
||||
|
||||
Arrays.sort(ashconInfo.getUsernameHistories(), (o1, o2) ->
|
||||
{
|
||||
if (o1.getLocalDateTime() == null || o2.getLocalDateTime() == null)
|
||||
if (o1.getZonedDateTime() == null || o2.getZonedDateTime() == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return o1.getLocalDateTime().compareTo(o2.getLocalDateTime());
|
||||
return o1.getZonedDateTime().compareTo(o2.getZonedDateTime());
|
||||
});
|
||||
|
||||
return ashconInfo;
|
||||
|
@ -8,6 +8,8 @@ import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Month;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -20,6 +22,7 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -133,7 +136,7 @@ public class PlexUtils implements PlexBase
|
||||
{
|
||||
aprilFools = plugin.config.getBoolean("april_fools");
|
||||
}
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
if (aprilFools && date.getMonth() == Month.APRIL && date.getDayOfMonth() == 1)
|
||||
{
|
||||
Component component = MiniMessage.miniMessage().deserialize(input); // removes existing tags
|
||||
|
@ -3,9 +3,9 @@ package dev.plex.util;
|
||||
import dev.plex.Plex;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
@ -13,7 +13,7 @@ import org.apache.commons.lang.math.NumberUtils;
|
||||
|
||||
public class TimeUtils
|
||||
{
|
||||
private static String TIMEZONE = Plex.get().config.getString("server.timezone");
|
||||
public static String TIMEZONE = Plex.get().config.getString("server.timezone");
|
||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mm:ss a z");
|
||||
private static final Set<String> TIMEZONES = Set.of(TimeZone.getAvailableIDs());
|
||||
private static final List<String> timeUnits = new ArrayList<>()
|
||||
@ -36,9 +36,9 @@ public class TimeUtils
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
|
||||
public static LocalDateTime createDate(String arg)
|
||||
public static ZonedDateTime createDate(String arg)
|
||||
{
|
||||
LocalDateTime time = LocalDateTime.now();
|
||||
ZonedDateTime time = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
for (String unit : timeUnits)
|
||||
{
|
||||
if (arg.endsWith(unit))
|
||||
@ -68,4 +68,14 @@ public class TimeUtils
|
||||
}
|
||||
return DATE_FORMAT.withZone(ZoneId.of(TIMEZONE)).format(date);
|
||||
}
|
||||
|
||||
public static String useTimezone(ZonedDateTime date)
|
||||
{
|
||||
// Use UTC if the timezone is null or not set correctly
|
||||
if (TIMEZONE == null || !TIMEZONES.contains(TIMEZONE))
|
||||
{
|
||||
TIMEZONE = "Etc/UTC";
|
||||
}
|
||||
return DATE_FORMAT.withZone(ZoneId.of(TIMEZONE)).format(date);
|
||||
}
|
||||
}
|
||||
|
@ -4,17 +4,21 @@ import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import dev.plex.Plex;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public class LocalDateTimeDeserializer implements JsonDeserializer<LocalDateTime>
|
||||
public class ZonedDateTimeDeserializer implements JsonDeserializer<ZonedDateTime>
|
||||
{
|
||||
private static String TIMEZONE = Plex.get().config.getString("server.timezone");
|
||||
@Override
|
||||
public LocalDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
public ZonedDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
Instant instant = Instant.ofEpochMilli(json.getAsJsonPrimitive().getAsLong());
|
||||
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
|
||||
return ZonedDateTime.ofInstant(instant, ZoneId.of(TIMEZONE));
|
||||
}
|
||||
}
|
@ -4,16 +4,20 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import dev.plex.Plex;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public class LocalDateTimeSerializer implements JsonSerializer<LocalDateTime>
|
||||
public class ZonedDateTimeSerializer implements JsonSerializer<ZonedDateTime>
|
||||
{
|
||||
private static String TIMEZONE = Plex.get().config.getString("server.timezone");
|
||||
@Override
|
||||
public JsonElement serialize(LocalDateTime src, Type typeOfSrc, JsonSerializationContext context)
|
||||
public JsonElement serialize(ZonedDateTime src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
return new JsonPrimitive(src.toInstant(ZoneId.systemDefault().getRules().getOffset(Instant.now())).toEpochMilli());
|
||||
return new JsonPrimitive(src.toInstant().toEpochMilli());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user