mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
67a382695a
@ -10,6 +10,7 @@ import dev.plex.util.AshconInfo;
|
|||||||
import dev.plex.util.MojangUtils;
|
import dev.plex.util.MojangUtils;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.TimeUtils;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -47,7 +48,7 @@ public class NameHistoryCMD extends PlexCommand
|
|||||||
historyList.add(
|
historyList.add(
|
||||||
messageComponent("nameHistoryBody",
|
messageComponent("nameHistoryBody",
|
||||||
history.getUsername(),
|
history.getUsername(),
|
||||||
PlexUtils.useTimezone(history.getLocalDateTime())));
|
TimeUtils.useTimezone(history.getLocalDateTime())));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -9,6 +9,7 @@ import dev.plex.punishment.extra.Note;
|
|||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.TimeUtils;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -168,7 +169,7 @@ public class NotesCMD extends PlexCommand
|
|||||||
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
|
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
|
||||||
for (Note note : notes)
|
for (Note note : notes)
|
||||||
{
|
{
|
||||||
Component noteLine = mmString("<gold><!italic>" + note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + PlexUtils.useTimezone(note.getTimestamp()));
|
Component noteLine = mmString("<gold><!italic>" + note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + TimeUtils.useTimezone(note.getTimestamp()));
|
||||||
noteLine = noteLine.append(mmString("<newline><yellow># " + note.getNote()));
|
noteLine = noteLine.append(mmString("<newline><yellow># " + note.getNote()));
|
||||||
noteList.set(noteList.get().append(Component.newline()));
|
noteList.set(noteList.get().append(Component.newline()));
|
||||||
noteList.set(noteList.get().append(noteLine));
|
noteList.set(noteList.get().append(noteLine));
|
||||||
|
@ -2,7 +2,7 @@ package dev.plex.listener.impl;
|
|||||||
|
|
||||||
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
|
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.RandomUtil;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
@ -23,7 +23,7 @@ public class ServerListener extends PlexListener
|
|||||||
final StringBuilder motd = new StringBuilder();
|
final StringBuilder motd = new StringBuilder();
|
||||||
for (final String word : baseMotd.split(" "))
|
for (final String word : baseMotd.split(" "))
|
||||||
{
|
{
|
||||||
motd.append(PlexUtils.randomChatColor()).append(word).append(" ");
|
motd.append(RandomUtil.getRandomColor()).append(word).append(" ");
|
||||||
}
|
}
|
||||||
event.motd(LegacyComponentSerializer.legacyAmpersand().deserialize(motd.toString().trim()));
|
event.motd(LegacyComponentSerializer.legacyAmpersand().deserialize(motd.toString().trim()));
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import dev.morphia.annotations.Entity;
|
|||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.util.MojangUtils;
|
import dev.plex.util.MojangUtils;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.TimeUtils;
|
||||||
import dev.plex.util.adapter.LocalDateTimeDeserializer;
|
import dev.plex.util.adapter.LocalDateTimeDeserializer;
|
||||||
import dev.plex.util.adapter.LocalDateTimeSerializer;
|
import dev.plex.util.adapter.LocalDateTimeSerializer;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -43,9 +44,7 @@ public class Punishment
|
|||||||
|
|
||||||
public static Component generateBanMessage(Punishment punishment)
|
public static Component generateBanMessage(Punishment punishment)
|
||||||
{
|
{
|
||||||
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(),
|
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
|
||||||
PlexUtils.useTimezone(punishment.getEndDate()),
|
|
||||||
punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component generateIndefBanMessage(String type)
|
public static Component generateIndefBanMessage(String type)
|
||||||
|
@ -2,24 +2,17 @@ package dev.plex.util;
|
|||||||
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.PlexBase;
|
import dev.plex.PlexBase;
|
||||||
import dev.plex.cache.DataUtils;
|
|
||||||
import dev.plex.cache.PlayerCache;
|
import dev.plex.cache.PlayerCache;
|
||||||
import dev.plex.permission.Permission;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.Month;
|
import java.time.Month;
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -34,35 +27,16 @@ import org.bukkit.Particle;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.PluginCommandYamlParser;
|
import org.bukkit.command.PluginCommandYamlParser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.PermissionAttachment;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class PlexUtils implements PlexBase
|
public class PlexUtils implements PlexBase
|
||||||
{
|
{
|
||||||
private static final Random RANDOM;
|
|
||||||
public static Map<String, ChatColor> CHAT_COLOR_NAMES;
|
|
||||||
public static List<ChatColor> CHAT_COLOR_POOL;
|
|
||||||
public static List<String> DEVELOPERS =
|
public static List<String> DEVELOPERS =
|
||||||
Arrays.asList("78408086-1991-4c33-a571-d8fa325465b2", // Telesphoreo
|
Arrays.asList("78408086-1991-4c33-a571-d8fa325465b2", // Telesphoreo
|
||||||
"f5cd54c4-3a24-4213-9a56-c06c49594dff", // Taahh
|
"f5cd54c4-3a24-4213-9a56-c06c49594dff", // Taahh
|
||||||
"ca83b658-c03b-4106-9edc-72f70a80656d", // ayunami2000
|
"ca83b658-c03b-4106-9edc-72f70a80656d", // ayunami2000
|
||||||
"2e06e049-24c8-42e4-8bcf-d35372af31e6" //Fleek
|
"2e06e049-24c8-42e4-8bcf-d35372af31e6" //Fleek
|
||||||
);
|
);
|
||||||
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 String TIMEZONE = Plex.get().config.getString("server.timezone");
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
RANDOM = new Random();
|
|
||||||
CHAT_COLOR_NAMES = new HashMap<>();
|
|
||||||
CHAT_COLOR_POOL = Arrays.asList(ChatColor.DARK_RED, ChatColor.RED, ChatColor.GOLD, ChatColor.YELLOW, ChatColor.GREEN, ChatColor.DARK_GREEN, ChatColor.AQUA, ChatColor.DARK_AQUA, ChatColor.BLUE, ChatColor.DARK_BLUE, ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE);
|
|
||||||
for (final ChatColor chatColor : CHAT_COLOR_POOL)
|
|
||||||
{
|
|
||||||
CHAT_COLOR_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T addToArrayList(List<T> list, T object)
|
public static <T> T addToArrayList(List<T> list, T object)
|
||||||
{
|
{
|
||||||
@ -87,11 +61,6 @@ public class PlexUtils implements PlexBase
|
|||||||
players[0].getWorld().playSound(location, org.bukkit.Sound.BLOCK_FIRE_EXTINGUISH, 0.5f, 0.5f);
|
players[0].getWorld().playSound(location, org.bukkit.Sound.BLOCK_FIRE_EXTINGUISH, 0.5f, 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatColor randomChatColor()
|
|
||||||
{
|
|
||||||
return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void testConnections()
|
public static void testConnections()
|
||||||
{
|
{
|
||||||
if (Plex.get().getSqlConnection().getDataSource() != null)
|
if (Plex.get().getSqlConnection().getDataSource() != null)
|
||||||
@ -144,11 +113,6 @@ public class PlexUtils implements PlexBase
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String colorize(final String string)
|
|
||||||
{
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', string);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final MiniMessage safeMessage = MiniMessage.builder().tags(TagResolver.builder().resolvers(
|
private static final MiniMessage safeMessage = MiniMessage.builder().tags(TagResolver.builder().resolvers(
|
||||||
StandardTags.color(),
|
StandardTags.color(),
|
||||||
StandardTags.decorations(),
|
StandardTags.decorations(),
|
||||||
@ -202,17 +166,6 @@ public class PlexUtils implements PlexBase
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String useTimezone(LocalDateTime 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static List<String> getPlayerNameList()
|
public static List<String> getPlayerNameList()
|
||||||
{
|
{
|
||||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||||
@ -235,24 +188,4 @@ public class PlexUtils implements PlexBase
|
|||||||
pl.sendMessage(component);
|
pl.sendMessage(component);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean randomBoolean()
|
|
||||||
{
|
|
||||||
return ThreadLocalRandom.current().nextBoolean();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int randomNum()
|
|
||||||
{
|
|
||||||
return ThreadLocalRandom.current().nextInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int randomNum(int limit)
|
|
||||||
{
|
|
||||||
return ThreadLocalRandom.current().nextInt(limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int randomNum(int start, int limit)
|
|
||||||
{
|
|
||||||
return ThreadLocalRandom.current().nextInt(start, limit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
34
src/main/java/dev/plex/util/RandomUtil.java
Normal file
34
src/main/java/dev/plex/util/RandomUtil.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package dev.plex.util;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
|
public class RandomUtil
|
||||||
|
{
|
||||||
|
|
||||||
|
public static NamedTextColor getRandomColor()
|
||||||
|
{
|
||||||
|
NamedTextColor[] colors = NamedTextColor.NAMES.values().toArray(NamedTextColor[]::new);
|
||||||
|
return colors[randomNum(colors.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean randomBoolean()
|
||||||
|
{
|
||||||
|
return ThreadLocalRandom.current().nextBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int randomNum()
|
||||||
|
{
|
||||||
|
return ThreadLocalRandom.current().nextInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int randomNum(int limit)
|
||||||
|
{
|
||||||
|
return ThreadLocalRandom.current().nextInt(limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int randomNum(int start, int limit)
|
||||||
|
{
|
||||||
|
return ThreadLocalRandom.current().nextInt(start, limit);
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,21 @@
|
|||||||
package dev.plex.util;
|
package dev.plex.util;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TimeZone;
|
||||||
import org.apache.commons.lang.math.NumberUtils;
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
|
|
||||||
public class TimeUtils
|
public class TimeUtils
|
||||||
{
|
{
|
||||||
|
private 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<>()
|
private static final List<String> timeUnits = new ArrayList<>()
|
||||||
{{
|
{{
|
||||||
add("s");
|
add("s");
|
||||||
@ -51,23 +59,13 @@ public class TimeUtils
|
|||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getDateNow()
|
public static String useTimezone(LocalDateTime date)
|
||||||
{
|
{
|
||||||
return new Date().getTime();
|
// Use UTC if the timezone is null or not set correctly
|
||||||
}
|
if (TIMEZONE == null || !TIMEZONES.contains(TIMEZONE))
|
||||||
|
{
|
||||||
public static Date getDateFromLong(long epoch)
|
TIMEZONE = "Etc/UTC";
|
||||||
{
|
}
|
||||||
return new Date(epoch);
|
return DATE_FORMAT.withZone(ZoneId.of(TIMEZONE)).format(date);
|
||||||
}
|
|
||||||
|
|
||||||
public static long hoursToSeconds(long hours)
|
|
||||||
{
|
|
||||||
return hours * 3600;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long minutesToSeconds(long minutes)
|
|
||||||
{
|
|
||||||
return minutes * 60;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user