Tell admins if a player has notes

This commit is contained in:
Telesphoreo 2022-04-12 21:08:12 -05:00
parent 6c09905a8d
commit 81c656c86e
4 changed files with 24 additions and 3 deletions

View File

@ -7,6 +7,9 @@ import dev.plex.player.PlexPlayer;
import dev.plex.storage.StorageType; import dev.plex.storage.StorageType;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -84,6 +87,16 @@ public class PlayerListener<T> extends PlexListener
{ {
plexPlayer.loadNotes(); plexPlayer.loadNotes();
} }
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
String plural = notes.size() == 1 ? "note." : "notes.";
if (!notes.isEmpty())
{
PlexUtils.broadcastToAdmins(Component.text(plexPlayer.getName() + " has " + notes.size() + " " + plural).color(NamedTextColor.GOLD));
PlexUtils.broadcastToAdmins(Component.text("Click to view their " + plural).clickEvent(ClickEvent.runCommand("/notes " + plexPlayer.getName() + " list")).color(NamedTextColor.GOLD));
}
});
} }
// saving the player's data // saving the player's data

View File

@ -43,7 +43,6 @@ 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(),
PlexUtils.useTimezone(punishment.getEndDate()), PlexUtils.useTimezone(punishment.getEndDate()),
punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername()); punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());

View File

@ -96,7 +96,7 @@ public class SQLConnection extends PlexBase
"`uuid` VARCHAR(46) NOT NULL," + "`uuid` VARCHAR(46) NOT NULL," +
"`permission` VARCHAR(1000) NOT NULL," + "`permission` VARCHAR(1000) NOT NULL," +
"`allowed` BOOLEAN" + "`allowed` BOOLEAN" +
");"); ");").execute();
} }
catch (SQLException throwables) catch (SQLException throwables)
{ {

View File

@ -5,6 +5,7 @@ import com.google.common.reflect.ClassPath;
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.DataUtils;
import dev.plex.cache.PlayerCache;
import dev.plex.config.Config; import dev.plex.config.Config;
import dev.plex.permission.Permission; import dev.plex.permission.Permission;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
@ -116,7 +117,8 @@ public class PlexUtils extends PlexBase
public static void updatePermission(PlexPlayer player, String permission, boolean newValue) public static void updatePermission(PlexPlayer player, String permission, boolean newValue)
{ {
player.getPermissions().stream().filter(permission1 -> permission.equalsIgnoreCase(permission)).findFirst().ifPresent(permission1 -> { player.getPermissions().stream().filter(permission1 -> permission.equalsIgnoreCase(permission)).findFirst().ifPresent(permission1 ->
{
Plex.get().getSqlPermissions().updatePermission(permission1, newValue); Plex.get().getSqlPermissions().updatePermission(permission1, newValue);
}); });
player.getPermissions().removeIf(permission1 -> permission1.getPermission().equalsIgnoreCase(permission)); player.getPermissions().removeIf(permission1 -> permission1.getPermission().equalsIgnoreCase(permission));
@ -424,6 +426,13 @@ public class PlexUtils extends PlexBase
Bukkit.broadcast(component); Bukkit.broadcast(component);
} }
public static void broadcastToAdmins(Component component)
{
Bukkit.getOnlinePlayers().stream().filter(pl -> PlayerCache.getPlexPlayer(pl.getUniqueId()).isAdminActive()).forEach(pl ->
Bukkit.broadcast(component));
}
public static Object simpleGET(String url) public static Object simpleGET(String url)
{ {
try try