mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-06 17:36:43 +00:00
fix mongo support
This commit is contained in:
@ -5,18 +5,12 @@ import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.exception.ConsoleMustDefinePlayerException;
|
||||
import dev.plex.command.exception.ConsoleOnlyException;
|
||||
import dev.plex.command.exception.PlayerNotBannedException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.exception.*;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
@ -25,15 +19,14 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Superclass for all commands
|
||||
*/
|
||||
@ -132,17 +125,22 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
{
|
||||
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
if (getLevel().isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
||||
{
|
||||
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
if (!player.hasPermission(perms.permission()))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!");
|
||||
send(sender, "There is a server misconfiguration. Please alert a developer or the owner");
|
||||
@ -151,13 +149,12 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
}
|
||||
try
|
||||
{
|
||||
Component component = this.execute(sender, isConsole(sender) ? null : (Player)sender, args);
|
||||
Component component = this.execute(sender, isConsole(sender) ? null : (Player) sender, args);
|
||||
if (component != null)
|
||||
{
|
||||
send(sender, component);
|
||||
}
|
||||
}
|
||||
catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException | ConsoleMustDefinePlayerException | PlayerNotBannedException ex)
|
||||
} catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException | ConsoleMustDefinePlayerException | PlayerNotBannedException ex)
|
||||
{
|
||||
send(sender, MiniMessage.miniMessage().deserialize(ex.getMessage()));
|
||||
}
|
||||
@ -181,8 +178,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (params.aliases().split(",").length < 1)
|
||||
} else if (params.aliases().split(",").length < 1)
|
||||
{
|
||||
return getName().equalsIgnoreCase(label);
|
||||
}
|
||||
@ -236,7 +232,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return checkRank((Player)sender, rank, permission);
|
||||
return checkRank((Player) sender, rank, permission);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -263,8 +259,11 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
if (rank.isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
||||
}
|
||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
if (!player.hasPermission(permission))
|
||||
{
|
||||
@ -283,9 +282,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
return plexPlayer.getRankFromString().isAtLeast(rank);
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
|
||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
@ -305,7 +303,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return checkTab((Player)sender, rank, permission);
|
||||
return checkTab((Player) sender, rank, permission);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -324,9 +322,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
return plexPlayer.getRankFromString().isAtLeast(rank);
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
|
||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import dev.plex.event.AdminRemoveEvent;
|
||||
import dev.plex.event.AdminSetRankEvent;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -55,6 +56,11 @@ public class AdminCMD extends PlexCommand
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (targetUUID != null)
|
||||
{
|
||||
PlexLog.debug("Admin Adding UUID: " + targetUUID);
|
||||
}
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
|
@ -39,7 +39,7 @@ public class AdminChatCMD extends PlexCommand
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive())
|
||||
{
|
||||
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
|
||||
}
|
||||
|
@ -9,15 +9,15 @@ import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.freeze")
|
||||
public class FreezeCMD extends PlexCommand
|
||||
@ -43,7 +43,7 @@ public class FreezeCMD extends PlexCommand
|
||||
{
|
||||
assert playerSender != null;
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()))
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()) && getPlexPlayer(player).isAdminActive())
|
||||
{
|
||||
return messageComponent("higherRankThanYou");
|
||||
}
|
||||
|
@ -7,13 +7,8 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.extra.Note;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.storage.StorageType;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
@ -24,6 +19,13 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@CommandParameters(name = "notes", description = "Manage notes for a player", usage = "/<command> <player> <list | add <note> | remove <id> | clear>")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.notes")
|
||||
public class NotesCMD extends PlexCommand
|
||||
@ -45,12 +47,31 @@ public class NotesCMD extends PlexCommand
|
||||
{
|
||||
case "list":
|
||||
{
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
{
|
||||
if (notes.size() == 0)
|
||||
{
|
||||
send(sender, mmString("<red>This player has no notes!"));
|
||||
return;
|
||||
}
|
||||
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());
|
||||
});
|
||||
} else
|
||||
{
|
||||
List<Note> notes = plexPlayer.getNotes();
|
||||
if (notes.size() == 0)
|
||||
{
|
||||
send(sender, mmString("<red>This player has no notes!"));
|
||||
return;
|
||||
return mmString("<red>This player has no notes!");
|
||||
}
|
||||
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
|
||||
for (Note note : notes)
|
||||
@ -61,7 +82,7 @@ public class NotesCMD extends PlexCommand
|
||||
noteList.set(noteList.get().append(noteLine));
|
||||
}
|
||||
send(sender, noteList.get());
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
case "add":
|
||||
@ -75,7 +96,13 @@ public class NotesCMD extends PlexCommand
|
||||
{
|
||||
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), LocalDateTime.now());
|
||||
plexPlayer.getNotes().add(note);
|
||||
plugin.getSqlNotes().addNote(note);
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
plugin.getSqlNotes().addNote(note);
|
||||
} else
|
||||
{
|
||||
DataUtils.update(plexPlayer);
|
||||
}
|
||||
return Component.text("Note added.").color(NamedTextColor.GREEN);
|
||||
}
|
||||
}
|
||||
@ -85,37 +112,55 @@ public class NotesCMD extends PlexCommand
|
||||
try
|
||||
{
|
||||
id = Integer.parseInt(args[2]);
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
} catch (NumberFormatException ignored)
|
||||
{
|
||||
return Component.text("Invalid number: " + args[2]).color(NamedTextColor.RED);
|
||||
}
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
for (Note note : notes)
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
{
|
||||
if (note.getId() == id)
|
||||
for (Note note : notes)
|
||||
{
|
||||
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"));
|
||||
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"));
|
||||
}
|
||||
}
|
||||
plexPlayer.getNotes().removeIf(note -> note.getId() == id);
|
||||
});
|
||||
} else
|
||||
{
|
||||
if (plexPlayer.getNotes().removeIf(note -> note.getId() == id))
|
||||
{
|
||||
return Component.text("Removed note with ID: " + id).color(NamedTextColor.GREEN);
|
||||
}
|
||||
});
|
||||
return mmString("<red>A note with this ID could not be found");
|
||||
}
|
||||
}
|
||||
case "clear":
|
||||
{
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
for (Note note : notes)
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
{
|
||||
plugin.getSqlNotes().deleteNote(note.getId(), plexPlayer.getUuid());
|
||||
}
|
||||
send(sender, Component.text("Cleared " + notes.size() + " note(s).").color(NamedTextColor.GREEN));
|
||||
});
|
||||
for (Note note : notes)
|
||||
{
|
||||
plugin.getSqlNotes().deleteNote(note.getId(), plexPlayer.getUuid());
|
||||
}
|
||||
plexPlayer.getNotes().clear();
|
||||
send(sender, Component.text("Cleared " + notes.size() + " note(s).").color(NamedTextColor.GREEN));
|
||||
});
|
||||
} else {
|
||||
int count = plexPlayer.getNotes().size();
|
||||
plexPlayer.getNotes().clear();
|
||||
DataUtils.update(plexPlayer);
|
||||
return Component.text("Cleared " + count + " note(s).").color(NamedTextColor.GREEN);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
default:
|
||||
|
@ -52,7 +52,7 @@ public class TempbanCMD extends PlexCommand
|
||||
{
|
||||
assert playerSender != null;
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()) && plexPlayer.isAdminActive())
|
||||
{
|
||||
return messageComponent("higherRankThanYou");
|
||||
}
|
||||
|
Reference in New Issue
Block a user