mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
Switch UUID in PlexPlayer to an actual UUID and fix notes
This commit is contained in:
parent
00d00eb4e5
commit
5012d0478b
@ -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);
|
||||||
|
@ -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());
|
||||||
|
@ -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());
|
||||||
|
@ -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));
|
||||||
|
@ -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
|
||||||
|
@ -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));
|
||||||
|
@ -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)
|
|
||||||
{
|
{
|
||||||
plexPlayer.getNotes().remove(note);
|
for (Note note : notes)
|
||||||
count++;
|
{
|
||||||
}
|
plugin.getSqlNotes().deleteNote(note.getId(), plexPlayer.getUuid());
|
||||||
DataUtils.update(plexPlayer);
|
}
|
||||||
return Component.text("Cleared " + count + " note(s).").color(NamedTextColor.GREEN);
|
send(sender, Component.text("Cleared " + notes.size() + " note(s).").color(NamedTextColor.GREEN));
|
||||||
|
});
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user