mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Minor clean up
This commit is contained in:
parent
e39f882ea7
commit
77be23faf0
@ -56,9 +56,9 @@ public class KickCMD extends PlexCommand
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
punishment.setReason(reason);
|
||||
}
|
||||
|
||||
punishment.setReason(reason);
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setCustomTime(false);
|
||||
|
@ -17,7 +17,7 @@ public class AdminListener extends PlexListener
|
||||
public void onAdminAdd(AdminAddEvent event)
|
||||
{
|
||||
String userSender = event.getSender().getName();
|
||||
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
|
||||
PlexPlayer target = event.getPlexPlayer();
|
||||
if (target.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("adminReadded", userSender, target.getName(), target.getRankFromString().getReadable()));
|
||||
@ -35,7 +35,7 @@ public class AdminListener extends PlexListener
|
||||
public void onAdminRemove(AdminRemoveEvent event)
|
||||
{
|
||||
String userSender = event.getSender().getName();
|
||||
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
|
||||
PlexPlayer target = event.getPlexPlayer();
|
||||
target.setAdminActive(false);
|
||||
DataUtils.update(target);
|
||||
PlexUtils.broadcast(messageComponent("adminRemoved", userSender, target.getName()));
|
||||
@ -45,8 +45,8 @@ public class AdminListener extends PlexListener
|
||||
public void onAdminSetRank(AdminSetRankEvent event)
|
||||
{
|
||||
String userSender = event.getSender().getName();
|
||||
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
|
||||
Rank newRank = (Rank)event.getRank();
|
||||
PlexPlayer target = event.getPlexPlayer();
|
||||
Rank newRank = event.getRank();
|
||||
target.setRank(newRank.name().toLowerCase());
|
||||
DataUtils.update(target);
|
||||
PlexUtils.broadcast(messageComponent("adminSetRank", userSender, target.getName(), newRank.getReadable()));
|
||||
|
@ -86,7 +86,6 @@ public class BlockListener extends PlexListener
|
||||
if (blockedPlayers.contains(event.getPlayer().getName()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,6 @@ public class MobListener extends PlexListener
|
||||
{
|
||||
clickedBlock.getWorld().spawnEntity(clickedBlock.getLocation().add(event.getBlockFace().getDirection().multiply(0.8)).add(0.5, 0.5, 0.5), eggType);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class PlayerListener<T> extends PlexListener
|
||||
PlexLog.log("A player with this name has not joined the server before, creating new entry.");
|
||||
plexPlayer = new PlexPlayer(player.getUniqueId()); // it doesn't! okay so now create the object
|
||||
plexPlayer.setName(player.getName()); // set the name of the player
|
||||
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); // set the arraylist of ips
|
||||
plexPlayer.setIps(List.of(player.getAddress().getAddress().getHostAddress().trim())); // set the arraylist of ips
|
||||
DataUtils.insert(plexPlayer); // insert data in some wack db
|
||||
}
|
||||
else
|
||||
|
@ -40,7 +40,7 @@ public class ServerListener extends PlexListener
|
||||
if (!samples.isEmpty())
|
||||
{
|
||||
event.getPlayerSample().clear();
|
||||
event.getPlayerSample().addAll(samples.stream().map(string -> string.replace("&", "§")).map(Bukkit::createProfile).collect(Collectors.toList()));
|
||||
event.getPlayerSample().addAll(samples.stream().map(string -> string.replace("&", "§")).map(Bukkit::createProfile).toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class TabListener extends PlexListener
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onAdminAdd(AdminAddEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = (PlexPlayer)event.getPlexPlayer();
|
||||
PlexPlayer plexPlayer = event.getPlexPlayer();
|
||||
Player player = event.getPlexPlayer().getPlayer();
|
||||
if (player == null)
|
||||
{
|
||||
@ -37,7 +37,7 @@ public class TabListener extends PlexListener
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onAdminRemove(AdminRemoveEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = (PlexPlayer)event.getPlexPlayer();
|
||||
PlexPlayer plexPlayer = event.getPlexPlayer();
|
||||
Player player = event.getPlexPlayer().getPlayer();
|
||||
if (player == null)
|
||||
{
|
||||
@ -49,7 +49,7 @@ public class TabListener extends PlexListener
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onAdminSetRank(AdminSetRankEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = (PlexPlayer)event.getPlexPlayer();
|
||||
PlexPlayer plexPlayer = event.getPlexPlayer();
|
||||
Player player = event.getPlexPlayer().getPlayer();
|
||||
if (player == null)
|
||||
{
|
||||
|
@ -167,9 +167,7 @@ public class PunishedPlayerMenu extends AbstractMenu
|
||||
{
|
||||
event.getWhoClicked().sendMessage(Component.text("This player does not exist. Try doing /punishments <player> instead.").color(NamedTextColor.RED));
|
||||
event.getWhoClicked().closeInventory();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,11 +12,10 @@ 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.ZonedDateTimeSerializer;
|
||||
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -136,18 +135,17 @@ public class PlexPlayer
|
||||
}
|
||||
}
|
||||
|
||||
public CompletableFuture<List<Note>> loadNotes()
|
||||
public void loadNotes()
|
||||
{
|
||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
return Plex.get().getSqlNotes().getNotes(this.getUuid());
|
||||
Plex.get().getSqlNotes().getNotes(this.getUuid());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).create().toJson(this);
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
|
@ -1,13 +1,13 @@
|
||||
package dev.plex.punishment;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.util.MojangUtils;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import dev.plex.util.adapter.ZonedDateTimeDeserializer;
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
@ -19,6 +19,7 @@ import net.kyori.adventure.text.Component;
|
||||
@Entity
|
||||
public class Punishment
|
||||
{
|
||||
private static final Gson gson = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).create();
|
||||
private static final String banUrl = Plex.get().config.getString("banning.ban_url");
|
||||
private final UUID punished;
|
||||
private final UUID punisher;
|
||||
@ -54,11 +55,11 @@ public class Punishment
|
||||
|
||||
public static Punishment fromJson(String json)
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeDeserializer()).create().fromJson(json, Punishment.class);
|
||||
return gson.fromJson(json, Punishment.class);
|
||||
}
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
return gson.toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package dev.plex.punishment.extra;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
import lombok.Data;
|
||||
@ -20,6 +20,6 @@ public class Note
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).create().toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ public class BungeeUtil
|
||||
return Bukkit.spigot().getPaperConfig().getBoolean("settings.velocity-support.enabled") && !Bukkit.spigot().getPaperConfig().getString("settings.velocity-support.secret", "").isEmpty();
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public static void kickPlayer(Player player, Component message)
|
||||
{
|
||||
if (isBungeeCord() || isVelocity())
|
||||
|
@ -24,6 +24,7 @@ public class GameRuleUtil
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> void readGameRules(World world, String s)
|
||||
{
|
||||
String gameRule = s.split(";")[0];
|
||||
@ -47,7 +48,7 @@ public class GameRuleUtil
|
||||
return Boolean.parseBoolean(value.toString());
|
||||
}
|
||||
|
||||
if (NumberUtils.isNumber(value.toString()))
|
||||
if (NumberUtils.isCreatable(value.toString()))
|
||||
{
|
||||
return Integer.parseInt(value.toString());
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class PlexUtils implements PlexBase
|
||||
{
|
||||
if (Plex.get().getSqlConnection().getDataSource() != null)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
try (Connection ignored = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MARIADB)
|
||||
{
|
||||
@ -115,7 +115,7 @@ public class PlexUtils implements PlexBase
|
||||
List<Command> cmds = PluginCommandYamlParser.parse(plugin);
|
||||
for (Command pluginCmd : cmds)
|
||||
{
|
||||
List<String> cmdAliases = pluginCmd.getAliases().size() > 0 ? pluginCmd.getAliases().stream().map(String::toLowerCase).collect(Collectors.toList()) : null;
|
||||
List<String> cmdAliases = pluginCmd.getAliases().size() > 0 ? pluginCmd.getAliases().stream().map(String::toLowerCase).toList() : null;
|
||||
if (pluginCmd.getName().equalsIgnoreCase(cmd) || (cmdAliases != null && cmdAliases.contains(cmd.toLowerCase())))
|
||||
{
|
||||
return true;
|
||||
|
@ -11,7 +11,6 @@ import java.util.Set;
|
||||
|
||||
public class ReflectionsUtil
|
||||
{
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public static Set<Class<?>> getClassesFrom(String packageName)
|
||||
{
|
||||
Set<Class<?>> classes = new HashSet<>();
|
||||
|
@ -29,7 +29,7 @@ public class TimeUtils
|
||||
|
||||
private static int parseInteger(String s) throws NumberFormatException
|
||||
{
|
||||
if (!NumberUtils.isNumber(s))
|
||||
if (!NumberUtils.isCreatable(s))
|
||||
{
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package dev.plex.util.adapter;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
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.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public class ZonedDateTimeAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime>
|
||||
{
|
||||
private static final String TIMEZONE = Plex.get().config.getString("server.timezone");
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ZonedDateTime src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
return new JsonPrimitive(src.toInstant().toEpochMilli());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
Instant instant = Instant.ofEpochMilli(json.getAsJsonPrimitive().getAsLong());
|
||||
return ZonedDateTime.ofInstant(instant, ZoneId.of(TIMEZONE));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user