Update for Plex 2.0

This commit is contained in:
2026-05-20 16:43:49 -04:00
parent ce80f41282
commit 5f6d79ebd9
12 changed files with 129 additions and 105 deletions
+6 -6
View File
@@ -16,18 +16,18 @@ repositories {
} }
dependencies { dependencies {
compileOnly("org.projectlombok:lombok:1.18.42") compileOnly("org.projectlombok:lombok:1.18.46")
annotationProcessor("org.projectlombok:lombok:1.18.42") annotationProcessor("org.projectlombok:lombok:1.18.46")
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT") compileOnly("io.papermc.paper:paper-api:26.1.2.build.+")
compileOnly("dev.plex:server:1.6") compileOnly("dev.plex:api:2.0-SNAPSHOT")
} }
group = "dev.plex" group = "dev.plex"
version = "1.6" version = "2.0-SNAPSHOT"
description = "Module-NUSH" description = "Module-NUSH"
java { java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21)) toolchain.languageVersion.set(JavaLanguageVersion.of(25))
} }
publishing { publishing {
Binary file not shown.
+3 -1
View File
@@ -1,7 +1,9 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
networkTimeout=10000 networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
Vendored
+5 -9
View File
@@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# Copyright © 2015-2021 the original authors. # Copyright © 2015 the original authors.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@@ -86,8 +86,7 @@ done
# shellcheck disable=SC2034 # shellcheck disable=SC2034
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@@ -115,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;; NONSTOP* ) nonstop=true ;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
@@ -173,7 +171,6 @@ fi
# For Cygwin or MSYS, switch paths to Windows format before running java # For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" ) JAVACMD=$( cygpath --unix "$JAVACMD" )
@@ -206,15 +203,14 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command: # Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped. # and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line. # treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
org.gradle.wrapper.GradleWrapperMain \
"$@" "$@"
# Stop when "xargs" is not available. # Stop when "xargs" is not available.
Vendored
+10 -22
View File
@@ -23,8 +23,8 @@
@rem @rem
@rem ########################################################################## @rem ##########################################################################
@rem Set local scope for the variables with windows NT shell @rem Set local scope for the variables, and ensure extensions are enabled
if "%OS%"=="Windows_NT" setlocal setlocal EnableExtensions
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=. if "%DIRNAME%"=="" set DIRNAME=.
@@ -51,7 +51,7 @@ echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2 echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2 echo location of your Java installation. 1>&2
goto fail "%COMSPEC%" /c exit 1
:findJavaFromJavaHome :findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
@@ -65,30 +65,18 @@ echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2 echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2 echo location of your Java installation. 1>&2
goto fail "%COMSPEC%" /c exit 1
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* @rem endlocal doesn't take effect until after the line is parsed and variables are expanded
@rem which allows us to clear the local environment before executing the java command
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
:end :exitWithErrorLevel
@rem End local scope for the variables with windows NT shell @rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
if %ERRORLEVEL% equ 0 goto mainEnd "%COMSPEC%" /c exit %ERRORLEVEL%
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+27 -16
View File
@@ -5,52 +5,63 @@ import dev.plex.config.ModuleConfig;
import dev.plex.listener.ChatListener; import dev.plex.listener.ChatListener;
import dev.plex.listener.JoinListener; import dev.plex.listener.JoinListener;
import dev.plex.module.PlexModule; import dev.plex.module.PlexModule;
import lombok.Getter;
public class NUSHModule extends PlexModule public class NUSHModule extends PlexModule
{ {
@Getter private ModuleConfig config;
private static NUSHModule module; private boolean enabled;
@Getter private int time;
private static ModuleConfig config;
@Getter
private static boolean enabled;
@Getter
private static int time;
@Override @Override
public void load() public void load()
{ {
config = new ModuleConfig(this, "nush/config.yml", "config.yml"); config = new ModuleConfig(this, "nush/config.yml", "config.yml");
loadMessages("nush/messages.yml");
} }
@Override @Override
public void enable() public void enable()
{ {
module = this;
config.load(); config.load();
enabled = config.getBoolean("server.enabled", false); enabled = config.getBoolean("server.enabled", false);
time = config.getInt("server.wait_time", 2); time = config.getInt("server.wait_time", 2);
registerCommand(new NUSHCommand()); registerCommand(new NUSHCommand(this));
registerListener(new JoinListener()); registerListener(new JoinListener(this));
registerListener(new ChatListener()); registerListener(new ChatListener(this));
} }
@Override @Override
public void disable() public void disable()
{ {
module = null; UserData.clear();
} }
public static void toggle(boolean toggle) public ModuleConfig getConfig()
{
return config;
}
public boolean isEnabled()
{
return enabled;
}
public int getTime()
{
return time;
}
public void toggle(boolean toggle)
{ {
enabled = toggle; enabled = toggle;
config.set("server.enabled", toggle); config.set("server.enabled", toggle);
config.save();
} }
public static void setTime(int minutes) public void setTime(int minutes)
{ {
time = minutes; time = minutes;
config.set("server.wait_time", minutes); config.set("server.wait_time", minutes);
config.save();
} }
} }
+19 -16
View File
@@ -1,36 +1,36 @@
package dev.plex; package dev.plex;
import org.bukkit.Bukkit; import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class UserData public class UserData
{ {
private static final Map<UUID, UserData> USERS_MAP = new HashMap<>(); private static final Map<UUID, UserData> USERS_MAP = new ConcurrentHashMap<>();
private BukkitTask task = null; private ScheduledTask task = null;
public UserData(Player player) public UserData(UUID uuid)
{ {
USERS_MAP.put(player.getUniqueId(), this); USERS_MAP.put(uuid, this);
} }
public static void queueNewPlayer(Player player) public static void queueNewPlayer(NUSHModule module, Player player)
{ {
UserData data = new UserData(player); UUID uuid = player.getUniqueId();
data.task = Bukkit.getScheduler().runTaskLater(NUSHModule.getModule().getPlex(), UserData data = new UserData(uuid);
() -> data.task = module.api().scheduler().runGlobalLater(
scheduledTask ->
{ {
if (data.isValid()) if (data.isValid())
{ {
data.task.cancel(); data.task = null;
USERS_MAP.remove(player.getUniqueId()); USERS_MAP.remove(uuid, data);
} }
}, },
20L * 60L * NUSHModule.getTime()); 20L * 60L * module.getTime());
} }
public static boolean isNewPlayer(Player player) public static boolean isNewPlayer(Player player)
@@ -40,8 +40,11 @@ public class UserData
public static void removePlayer(Player player) public static void removePlayer(Player player)
{ {
USERS_MAP.get(player.getUniqueId()).task.cancel(); UserData data = USERS_MAP.remove(player.getUniqueId());
USERS_MAP.remove(player.getUniqueId()); if (data != null && data.isValid())
{
data.task.cancel();
}
} }
public static void clear() public static void clear()
+26 -19
View File
@@ -2,11 +2,8 @@ package dev.plex.command;
import dev.plex.NUSHModule; import dev.plex.NUSHModule;
import dev.plex.UserData; import dev.plex.UserData;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.SimplePlexCommand;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
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;
@@ -16,10 +13,20 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@CommandParameters(name = "nush", usage = "/<command> <on | off | status | time <minutes> | remove <player>>", description = "The main command to manage the NUSH module") public class NUSHCommand extends SimplePlexCommand
@CommandPermissions(permission = "plex.nush.use")
public class NUSHCommand extends PlexCommand
{ {
private final NUSHModule module;
public NUSHCommand(NUSHModule module)
{
super(command("nush")
.description("The main command to manage the NUSH module")
.usage("/<command> <on | off | status | time <minutes> | remove <player>>")
.permission("plex.nush.use")
.build());
this.module = module;
}
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{ {
@@ -29,20 +36,20 @@ public class NUSHCommand extends PlexCommand
{ {
case "on" -> case "on" ->
{ {
NUSHModule.toggle(true); module.toggle(true);
return MiniMessage.miniMessage().deserialize("<gray>The status for NUSH is now <green>enabled</green>."); return messageComponent("nushEnabled");
} }
case "off" -> case "off" ->
{ {
NUSHModule.toggle(false); module.toggle(false);
UserData.clear(); UserData.clear();
return MiniMessage.miniMessage().deserialize("<gray>The status for NUSH is now <red>disabled</red>."); return messageComponent("nushDisabled");
} }
case "status" -> case "status" ->
{ {
return MiniMessage.miniMessage().deserialize("<gray>The status for NUSH is currently " + (NUSHModule.isEnabled() ? "<green>enabled</green>" : "<red>disabled</red>") + "."); return messageComponent("nushStatus", module.isEnabled() ? "<green>enabled</green>" : "<red>disabled</red>");
} }
default -> default ->
@@ -64,11 +71,11 @@ public class NUSHCommand extends PlexCommand
} }
catch (NumberFormatException ex) catch (NumberFormatException ex)
{ {
return MiniMessage.miniMessage().deserialize("<red>The time must be a number!"); return messageComponent("timeMustBeNumber");
} }
NUSHModule.setTime(time); module.setTime(time);
return MiniMessage.miniMessage().deserialize("<gray>The wait time for new players before they can chat is now set to <yellow>" + time + "</yellow> minutes."); return messageComponent("waitTimeSet", time);
} }
case "remove" -> case "remove" ->
@@ -77,11 +84,11 @@ public class NUSHCommand extends PlexCommand
if (UserData.isNewPlayer(target)) if (UserData.isNewPlayer(target))
{ {
UserData.removePlayer(target); UserData.removePlayer(target);
return MiniMessage.miniMessage().deserialize("<yellow>" + target.getName() + " <gray>has been removed."); return messageComponent("playerRemoved", target.getName());
} }
else else
{ {
return MiniMessage.miniMessage().deserialize("<red>That player is currently not NUSH'd"); return messageComponent("playerNotNushed");
} }
} }
@@ -96,7 +103,7 @@ public class NUSHCommand extends PlexCommand
} }
@Override @Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) protected @NotNull List<String> suggestions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args)
{ {
if (args.length == 1 && silentCheckPermission(sender, this.getPermission())) if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
{ {
@@ -105,7 +112,7 @@ public class NUSHCommand extends PlexCommand
if (args.length == 2 && args[0].equalsIgnoreCase("remove") && silentCheckPermission(sender, this.getPermission())) if (args.length == 2 && args[0].equalsIgnoreCase("remove") && silentCheckPermission(sender, this.getPermission()))
{ {
return PlexUtils.getPlayerNameList(); return onlinePlayerNames();
} }
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -2,10 +2,8 @@ package dev.plex.listener;
import dev.plex.NUSHModule; import dev.plex.NUSHModule;
import dev.plex.UserData; import dev.plex.UserData;
import dev.plex.util.PlexLog;
import io.papermc.paper.event.player.AsyncChatEvent; import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
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;
@@ -13,24 +11,31 @@ import org.bukkit.event.EventPriority;
public class ChatListener extends PlexListener public class ChatListener extends PlexListener
{ {
private final NUSHModule module;
public ChatListener(NUSHModule module)
{
this.module = module;
}
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onChat(AsyncChatEvent event) public void onChat(AsyncChatEvent event)
{ {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (!NUSHModule.isEnabled() || event.isCancelled() || !UserData.isNewPlayer(player)) if (!module.isEnabled() || event.isCancelled() || !UserData.isNewPlayer(player))
{ {
PlexLog.debug("NUSH is disabled, event is cancelled or {0} is not on the list", player.getName()); module.api().logging().debug("NUSH is disabled, event is cancelled or {0} is not on the list", player.getName());
return; return;
} }
PlexLog.debug("Handling event for player {0}", player.getName()); module.api().logging().debug("Handling event for player {0}", player.getName());
event.setCancelled(true); event.setCancelled(true);
player.sendMessage(event.renderer().render(player, player.displayName(), event.message(), player)); player.sendMessage(event.renderer().render(player, player.displayName(), event.message(), player));
Bukkit.getOnlinePlayers().stream().filter(p -> p.hasPermission("plex.nush.view")).forEach(p -> Bukkit.getOnlinePlayers().stream().filter(p -> p.hasPermission("plex.nush.view")).forEach(p ->
{ {
Component message = Component.empty().append(Component.text("[NUSH] ").color(NamedTextColor.YELLOW)) Component message = module.messageComponent("newPlayerChatPrefix")
.append(event.renderer().render(player, player.displayName(), event.message(), p)); .append(event.renderer().render(player, player.displayName(), event.message(), p));
p.sendMessage(message); p.sendMessage(message);
}); });
@@ -2,9 +2,6 @@ package dev.plex.listener;
import dev.plex.NUSHModule; import dev.plex.NUSHModule;
import dev.plex.UserData; import dev.plex.UserData;
import dev.plex.util.PlexLog;
import net.kyori.adventure.text.Component;
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;
@@ -12,18 +9,23 @@ import org.bukkit.event.player.PlayerJoinEvent;
public class JoinListener extends PlexListener public class JoinListener extends PlexListener
{ {
private final NUSHModule module;
public JoinListener(NUSHModule module)
{
this.module = module;
}
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent event) public void onJoin(PlayerJoinEvent event)
{ {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (!player.hasPlayedBefore() && NUSHModule.isEnabled()) if (!player.hasPlayedBefore() && module.isEnabled())
{ {
PlexLog.debug("Adding {0} to the new player list", player.getName()); module.api().logging().debug("Adding {0} to the new player list", player.getName());
UserData.queueNewPlayer(player); UserData.queueNewPlayer(module, player);
Bukkit.getOnlinePlayers().stream().filter(p -> p.hasPermission("plex.nush.view")).forEach(p -> Bukkit.getOnlinePlayers().stream().filter(p -> p.hasPermission("plex.nush.view")).forEach(p ->
p.sendMessage(Component.text("[NUSH] " + player.getName() p.sendMessage(module.messageComponent("newPlayerMarked", player.getName(), module.getTime())));
+ " has been marked as a new player and won't be able to chat normally for " + NUSHModule.getTime() + " minutes.")
.color(NamedTextColor.LIGHT_PURPLE)));
} }
} }
} }
+2 -1
View File
@@ -1,4 +1,5 @@
name: Module-NUSH name: Module-NUSH
main: dev.plex.NUSHModule main: dev.plex.NUSHModule
description: A module to prevent raids from new players description: A module to prevent raids from new players
version: 1.6 version: 2.0-SNAPSHOT
apiCompatibility: 1
+9
View File
@@ -0,0 +1,9 @@
nushEnabled: "<gray>The status for NUSH is now <green>enabled</green>."
nushDisabled: "<gray>The status for NUSH is now <red>disabled</red>."
nushStatus: "<gray>The status for NUSH is currently {0}."
timeMustBeNumber: "<red>The time must be a number!"
waitTimeSet: "<gray>The wait time for new players before they can chat is now set to <yellow>{0}</yellow> minutes."
playerRemoved: "<yellow>{0} <gray>has been removed."
playerNotNushed: "<red>That player is currently not NUSH'd"
newPlayerMarked: "<light_purple>[NUSH] {0} has been marked as a new player and won't be able to chat normally for {1} minutes."
newPlayerChatPrefix: "<yellow>[NUSH] "