This commit is contained in:
ayunami2000 2022-04-07 00:02:57 -04:00
commit 262b600b11
13 changed files with 124 additions and 43 deletions

View File

@ -177,7 +177,7 @@ public class Plex extends JavaPlugin
if (plugin.getRankManager().isAdmin(plexPlayer)) if (plugin.getRankManager().isAdmin(plexPlayer))
{ {
plugin.getAdminList().removeFromCache(UUID.fromString(plexPlayer.getUuid())); plugin.getAdminList().removeFromCache(plexPlayer.getUuid());
} }
if (mongoPlayerData != null) //back to mongo checking if (mongoPlayerData != null) //back to mongo checking
@ -215,7 +215,7 @@ public class Plex extends JavaPlugin
PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
if (plugin.getRankManager().isAdmin(plexPlayer)) if (plugin.getRankManager().isAdmin(plexPlayer))
{ {
Admin admin = new Admin(UUID.fromString(plexPlayer.getUuid())); Admin admin = new Admin(plexPlayer.getUuid());
admin.setRank(plexPlayer.getRankFromString()); admin.setRank(plexPlayer.getRankFromString());
plugin.getAdminList().addToCache(admin); plugin.getAdminList().addToCache(admin);

View File

@ -209,7 +209,7 @@ public class SQLPlayerData
statement.setLong(6, player.getCoins()); statement.setLong(6, player.getCoins());
statement.setBoolean(7, player.isVanished()); statement.setBoolean(7, player.isVanished());
statement.setBoolean(8, player.isCommandSpy()); statement.setBoolean(8, player.isCommandSpy());
statement.setString(9, player.getUuid()); statement.setString(9, player.getUuid().toString());
statement.executeUpdate(); statement.executeUpdate();
} }
catch (SQLException throwables) catch (SQLException throwables)
@ -229,7 +229,7 @@ public class SQLPlayerData
try (Connection con = Plex.get().getSqlConnection().getCon()) try (Connection con = Plex.get().getSqlConnection().getCon())
{ {
PreparedStatement statement = con.prepareStatement(INSERT); PreparedStatement statement = con.prepareStatement(INSERT);
statement.setString(1, player.getUuid()); statement.setString(1, player.getUuid().toString());
statement.setString(2, player.getName()); statement.setString(2, player.getName());
statement.setString(3, player.getLoginMessage()); statement.setString(3, player.getLoginMessage());
statement.setString(4, player.getPrefix()); statement.setString(4, player.getPrefix());

View File

@ -79,7 +79,7 @@ public class SQLNotes
try (Connection con = Plex.get().getSqlConnection().getCon()) try (Connection con = Plex.get().getSqlConnection().getCon())
{ {
PreparedStatement statement = con.prepareStatement(INSERT); PreparedStatement statement = con.prepareStatement(INSERT);
statement.setInt(1, notes.size()); statement.setInt(1, notes.size() + 1);
statement.setString(2, note.getUuid().toString()); statement.setString(2, note.getUuid().toString());
statement.setString(3, note.getWrittenBy().toString()); statement.setString(3, note.getWrittenBy().toString());
statement.setString(4, note.getNote()); statement.setString(4, note.getNote());

View File

@ -50,7 +50,7 @@ public class FreezeCMD extends PlexCommand
} }
} }
Punishment punishment = new Punishment(UUID.fromString(punishedPlayer.getUuid()), getUUID(sender)); Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
punishment.setCustomTime(false); punishment.setCustomTime(false);
LocalDateTime date = LocalDateTime.now(); LocalDateTime date = LocalDateTime.now();
punishment.setEndDate(date.plusMinutes(5)); punishment.setEndDate(date.plusMinutes(5));

View File

@ -15,7 +15,7 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "list", description = "Show a list of all online players") @CommandParameters(name = "list", description = "Show a list of all online players", aliases = "lsit")
@CommandPermissions(level = Rank.OP, permission = "plex.list") @CommandPermissions(level = Rank.OP, permission = "plex.list")
@System(value = "ranks") @System(value = "ranks")
public class ListCMD extends PlexCommand public class ListCMD extends PlexCommand

View File

@ -50,7 +50,7 @@ public class MuteCMD extends PlexCommand
} }
} }
Punishment punishment = new Punishment(UUID.fromString(punishedPlayer.getUuid()), getUUID(sender)); Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
punishment.setCustomTime(false); punishment.setCustomTime(false);
LocalDateTime date = LocalDateTime.now(); LocalDateTime date = LocalDateTime.now();
punishment.setEndDate(date.plusMinutes(5)); punishment.setEndDate(date.plusMinutes(5));

View File

@ -1,28 +1,24 @@
package dev.plex.command.impl; package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils; import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.annotation.System;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.punishment.extra.Note; import dev.plex.punishment.extra.Note;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.CompletableFuture;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -49,15 +45,23 @@ public class NotesCMD extends PlexCommand
{ {
case "list": case "list":
{ {
Component noteList = Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN); plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
/*for (Note note : plugin.getSqlNotes().getNotes(UUID.fromString(plexPlayer.getUuid())))
{ {
PlexLog.debug("We got here"); if (notes.size() == 0)
Component noteLine = Component.text(note.getId() + ". " + note.getWrittenBy() + ": " + note.getNote()).color(NamedTextColor.GOLD); {
noteList.append(Component.empty()); send(sender, mmString("<red>This player has no notes!"));
noteList.append(noteLine); return;
}*/ }
send(sender, noteList); AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
for (Note note : notes)
{
Component noteLine = Component.text(note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + DATE_FORMAT.format(note.getTimestamp())).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false);
noteLine = noteLine.append(Component.text(note.getNote())).color(NamedTextColor.GOLD).decoration(TextDecoration.ITALIC, true);
noteList.set(noteList.get().append(Component.newline()));
noteList.set(noteList.get().append(noteLine));
}
send(sender, noteList.get());
});
return null; return null;
} }
case "add": case "add":
@ -69,7 +73,7 @@ public class NotesCMD extends PlexCommand
String content = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " "); String content = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ");
if (playerSender != null) if (playerSender != null)
{ {
Note note = new Note(UUID.fromString(plexPlayer.getUuid()), content, playerSender.getUniqueId(), LocalDateTime.now()); Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), LocalDateTime.now());
plexPlayer.getNotes().add(note); plexPlayer.getNotes().add(note);
plugin.getSqlNotes().addNote(note); plugin.getSqlNotes().addNote(note);
return Component.text("Note added.").color(NamedTextColor.GREEN); return Component.text("Note added.").color(NamedTextColor.GREEN);
@ -77,19 +81,42 @@ public class NotesCMD extends PlexCommand
} }
case "remove": case "remove":
{ {
return null; int id;
try
{
id = Integer.parseInt(args[2]);
}
catch (NumberFormatException ignored)
{
return Component.text("Invalid number: " + args[2]).color(NamedTextColor.RED);
}
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
for (Note note : notes)
{
if (note.getId() == id)
{
plugin.getSqlNotes().deleteNote(id, plexPlayer.getUuid()).whenComplete((notes1, ex1) ->
send(sender, Component.text("Removed note with ID: " + id).color(NamedTextColor.GREEN)));
}
else
{
send(sender, mmString("<red>A note with this ID could not be found"));
}
}
});
} }
case "clear": case "clear":
{ {
int count = plexPlayer.getNotes().size(); plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
final List<Note> notes = plexPlayer.getNotes(); {
for (Note note : notes) for (Note note : notes)
{ {
plexPlayer.getNotes().remove(note); plugin.getSqlNotes().deleteNote(note.getId(), plexPlayer.getUuid());
count++;
} }
DataUtils.update(plexPlayer); send(sender, Component.text("Cleared " + notes.size() + " note(s).").color(NamedTextColor.GREEN));
return Component.text("Cleared " + count + " note(s).").color(NamedTextColor.GREEN); });
return null;
} }
default: default:
{ {

View File

@ -15,9 +15,11 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -88,6 +90,15 @@ public class PlexCMD extends PlexCommand
return componentFromString("All modules reloaded!"); return componentFromString("All modules reloaded!");
} }
} }
else if (args[0].equalsIgnoreCase("update"))
{
if (sender instanceof Player player && !PlexUtils.DEVELOPERS.contains(player.getUniqueId().toString()))
{
return messageComponent("noPermissionConsole");
}
plugin.getUpdateChecker().updateJar();
return null;
}
else else
{ {
return usage(); return usage();

View File

@ -33,7 +33,7 @@ public abstract class PunishedPlayerEvent extends PlayerEvent implements Cancell
*/ */
protected PunishedPlayerEvent(PlexPlayer punishedPlayer) protected PunishedPlayerEvent(PlexPlayer punishedPlayer)
{ {
super(Bukkit.getPlayer(UUID.fromString(punishedPlayer.getUuid()))); super(Bukkit.getPlayer(punishedPlayer.getUuid()));
this.punishedPlayer = punishedPlayer; this.punishedPlayer = punishedPlayer;
} }
} }

View File

@ -92,7 +92,7 @@ public class PlayerListener extends PlexListener
if (plugin.getRankManager().isAdmin(plexPlayer)) if (plugin.getRankManager().isAdmin(plexPlayer))
{ {
plugin.getAdminList().removeFromCache(UUID.fromString(plexPlayer.getUuid())); plugin.getAdminList().removeFromCache(plexPlayer.getUuid());
} }
DataUtils.update(plexPlayer); DataUtils.update(plexPlayer);

View File

@ -38,7 +38,7 @@ public class PlexPlayer
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
@Indexed(options = @IndexOptions(unique = true)) @Indexed(options = @IndexOptions(unique = true))
private String uuid; private UUID uuid;
@Indexed @Indexed
private String name; private String name;
@ -69,9 +69,9 @@ public class PlexPlayer
public PlexPlayer(UUID playerUUID) public PlexPlayer(UUID playerUUID)
{ {
this.uuid = playerUUID.toString(); this.uuid = playerUUID;
this.id = uuid.substring(0, 8); this.id = uuid.toString().substring(0, 8);
this.name = ""; this.name = "";
this.player = Bukkit.getPlayer(name); this.player = Bukkit.getPlayer(name);
@ -95,7 +95,7 @@ public class PlexPlayer
public Rank getRankFromString() public Rank getRankFromString()
{ {
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(uuid)); OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (rank.isEmpty()) if (rank.isEmpty())
{ {
if (player.isOp()) if (player.isOp())
@ -117,7 +117,7 @@ public class PlexPlayer
{ {
if (Plex.get().getStorageType() != StorageType.MONGODB) if (Plex.get().getStorageType() != StorageType.MONGODB)
{ {
this.setPunishments(Plex.get().getSqlPunishment().getPunishments(UUID.fromString(this.getUuid())).stream().filter(punishment -> punishment.getPunished().equals(UUID.fromString(this.getUuid()))).collect(Collectors.toList())); this.setPunishments(Plex.get().getSqlPunishment().getPunishments(this.getUuid()).stream().filter(punishment -> punishment.getPunished().equals(this.getUuid())).collect(Collectors.toList()));
} }
} }
@ -125,7 +125,7 @@ public class PlexPlayer
{ {
if (Plex.get().getStorageType() != StorageType.MONGODB) if (Plex.get().getStorageType() != StorageType.MONGODB)
{ {
return Plex.get().getSqlNotes().getNotes(UUID.fromString(this.getUuid())); return Plex.get().getSqlNotes().getNotes(this.getUuid());
} }
return null; return null;
} }

View File

@ -140,7 +140,7 @@ public class PunishmentManager extends PlexBase
public boolean isBanned(PlexPlayer player) public boolean isBanned(PlexPlayer player)
{ {
return isBanned(UUID.fromString(player.getUuid())); return isBanned(player.getUuid());
} }
public CompletableFuture<List<Punishment>> getActiveBans() public CompletableFuture<List<Punishment>> getActiveBans()
@ -206,7 +206,7 @@ public class PunishmentManager extends PlexBase
return; return;
} }
player.setFrozen(false); player.setFrozen(false);
Bukkit.broadcast(PlexUtils.messageComponent("unfrozePlayer", "Plex", Bukkit.getOfflinePlayer(UUID.fromString(player.getUuid())).getName())); Bukkit.broadcast(PlexUtils.messageComponent("unfrozePlayer", "Plex", Bukkit.getOfflinePlayer(player.getUuid()).getName()));
} }
}.runTaskLater(Plex.get(), 20 * seconds); }.runTaskLater(Plex.get(), 20 * seconds);
} }
@ -227,7 +227,7 @@ public class PunishmentManager extends PlexBase
return; return;
} }
player.setMuted(false); player.setMuted(false);
Bukkit.broadcast(PlexUtils.messageComponent("unmutedPlayer", "Plex", Bukkit.getOfflinePlayer(UUID.fromString(player.getUuid())).getName())); Bukkit.broadcast(PlexUtils.messageComponent("unmutedPlayer", "Plex", Bukkit.getOfflinePlayer(player.getUuid()).getName()));
} }
}.runTaskLater(Plex.get(), 20 * seconds); }.runTaskLater(Plex.get(), 20 * seconds);
} }

View File

@ -7,14 +7,26 @@ import com.google.gson.JsonSyntaxException;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.PlexBase; import dev.plex.PlexBase;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.apache.commons.io.FileUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.util.FileUtil;
import org.json.JSONArray;
import org.json.JSONObject;
public class UpdateChecker extends PlexBase public class UpdateChecker extends PlexBase
{ {
@ -107,8 +119,39 @@ public class UpdateChecker extends PlexBase
default -> { default -> {
sender.sendMessage(Component.text("Your version of Plex is not up to date!", NamedTextColor.RED)); sender.sendMessage(Component.text("Your version of Plex is not up to date!", NamedTextColor.RED));
sender.sendMessage(Component.text("Download a new version at: " + DOWNLOAD_PAGE).color(NamedTextColor.RED)); sender.sendMessage(Component.text("Download a new version at: " + DOWNLOAD_PAGE).color(NamedTextColor.RED));
sender.sendMessage(Component.text("Or run: /plex update").color(NamedTextColor.RED));
return true; return true;
} }
} }
} }
public void updateJar()
{
CloseableHttpClient client = HttpClients.createDefault();
HttpGet get = new HttpGet(DOWNLOAD_PAGE + "lastSuccessfulBuild/api/json");
try
{
HttpResponse response = client.execute(get);
JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0);
String name = artifact.getString("displayPath");
PlexLog.log("Downloading latest Plex jar file: " + name);
CompletableFuture.runAsync(() -> {
try
{
FileUtils.copyURLToFile(
new URL(DOWNLOAD_PAGE + "lastSuccessfulBuild/artifact/build/libs/" + name),
new File(Plex.get().getDataFolder() + File.separator + "..", name)
);
PlexLog.log("Saved new jar. Please restart your server.");
} catch (IOException e)
{
e.printStackTrace();
}
});
} catch (IOException e)
{
e.printStackTrace();
}
}
} }