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 {
compileOnly("org.projectlombok:lombok:1.18.42")
annotationProcessor("org.projectlombok:lombok:1.18.42")
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
compileOnly("dev.plex:server:1.6")
compileOnly("org.projectlombok:lombok:1.18.46")
annotationProcessor("org.projectlombok:lombok:1.18.46")
compileOnly("io.papermc.paper:paper-api:26.1.2.build.+")
compileOnly("dev.plex:api:2.0-SNAPSHOT")
}
group = "dev.plex"
version = "1.6"
version = "2.0-SNAPSHOT"
description = "Module-NUSH"
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
toolchain.languageVersion.set(JavaLanguageVersion.of(25))
}
publishing {
Binary file not shown.
+3 -1
View File
@@ -1,7 +1,9 @@
distributionBase=GRADLE_USER_HOME
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
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored
+5 -9
View File
@@ -1,7 +1,7 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (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.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -86,8 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# 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
' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -115,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# 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
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
@@ -206,15 +203,14 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# 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.
# * 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.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
Vendored
+10 -22
View File
@@ -23,8 +23,8 @@
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Set local scope for the variables, and ensure extensions are enabled
setlocal EnableExtensions
set DIRNAME=%~dp0
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 location of your Java installation. 1>&2
goto fail
"%COMSPEC%" /c exit 1
:findJavaFromJavaHome
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 location of your Java installation. 1>&2
goto fail
"%COMSPEC%" /c exit 1
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@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
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
: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
:exitWithErrorLevel
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
"%COMSPEC%" /c exit %ERRORLEVEL%
+27 -16
View File
@@ -5,52 +5,63 @@ import dev.plex.config.ModuleConfig;
import dev.plex.listener.ChatListener;
import dev.plex.listener.JoinListener;
import dev.plex.module.PlexModule;
import lombok.Getter;
public class NUSHModule extends PlexModule
{
@Getter
private static NUSHModule module;
@Getter
private static ModuleConfig config;
@Getter
private static boolean enabled;
@Getter
private static int time;
private ModuleConfig config;
private boolean enabled;
private int time;
@Override
public void load()
{
config = new ModuleConfig(this, "nush/config.yml", "config.yml");
loadMessages("nush/messages.yml");
}
@Override
public void enable()
{
module = this;
config.load();
enabled = config.getBoolean("server.enabled", false);
time = config.getInt("server.wait_time", 2);
registerCommand(new NUSHCommand());
registerListener(new JoinListener());
registerListener(new ChatListener());
registerCommand(new NUSHCommand(this));
registerListener(new JoinListener(this));
registerListener(new ChatListener(this));
}
@Override
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;
config.set("server.enabled", toggle);
config.save();
}
public static void setTime(int minutes)
public void setTime(int minutes)
{
time = minutes;
config.set("server.wait_time", minutes);
config.save();
}
}
+19 -16
View File
@@ -1,36 +1,36 @@
package dev.plex;
import org.bukkit.Bukkit;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class UserData
{
private static final Map<UUID, UserData> USERS_MAP = new HashMap<>();
private BukkitTask task = null;
private static final Map<UUID, UserData> USERS_MAP = new ConcurrentHashMap<>();
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);
data.task = Bukkit.getScheduler().runTaskLater(NUSHModule.getModule().getPlex(),
() ->
UUID uuid = player.getUniqueId();
UserData data = new UserData(uuid);
data.task = module.api().scheduler().runGlobalLater(
scheduledTask ->
{
if (data.isValid())
{
data.task.cancel();
USERS_MAP.remove(player.getUniqueId());
data.task = null;
USERS_MAP.remove(uuid, data);
}
},
20L * 60L * NUSHModule.getTime());
20L * 60L * module.getTime());
}
public static boolean isNewPlayer(Player player)
@@ -40,8 +40,11 @@ public class UserData
public static void removePlayer(Player player)
{
USERS_MAP.get(player.getUniqueId()).task.cancel();
USERS_MAP.remove(player.getUniqueId());
UserData data = USERS_MAP.remove(player.getUniqueId());
if (data != null && data.isValid())
{
data.task.cancel();
}
}
public static void clear()
+26 -19
View File
@@ -2,11 +2,8 @@ package dev.plex.command;
import dev.plex.NUSHModule;
import dev.plex.UserData;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.util.PlexUtils;
import dev.plex.command.SimplePlexCommand;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -16,10 +13,20 @@ import java.util.Arrays;
import java.util.Collections;
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")
@CommandPermissions(permission = "plex.nush.use")
public class NUSHCommand extends PlexCommand
public class NUSHCommand extends SimplePlexCommand
{
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
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{
@@ -29,20 +36,20 @@ public class NUSHCommand extends PlexCommand
{
case "on" ->
{
NUSHModule.toggle(true);
return MiniMessage.miniMessage().deserialize("<gray>The status for NUSH is now <green>enabled</green>.");
module.toggle(true);
return messageComponent("nushEnabled");
}
case "off" ->
{
NUSHModule.toggle(false);
module.toggle(false);
UserData.clear();
return MiniMessage.miniMessage().deserialize("<gray>The status for NUSH is now <red>disabled</red>.");
return messageComponent("nushDisabled");
}
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 ->
@@ -64,11 +71,11 @@ public class NUSHCommand extends PlexCommand
}
catch (NumberFormatException ex)
{
return MiniMessage.miniMessage().deserialize("<red>The time must be a number!");
return messageComponent("timeMustBeNumber");
}
NUSHModule.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.");
module.setTime(time);
return messageComponent("waitTimeSet", time);
}
case "remove" ->
@@ -77,11 +84,11 @@ public class NUSHCommand extends PlexCommand
if (UserData.isNewPlayer(target))
{
UserData.removePlayer(target);
return MiniMessage.miniMessage().deserialize("<yellow>" + target.getName() + " <gray>has been removed.");
return messageComponent("playerRemoved", target.getName());
}
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
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()))
{
@@ -105,7 +112,7 @@ public class NUSHCommand extends PlexCommand
if (args.length == 2 && args[0].equalsIgnoreCase("remove") && silentCheckPermission(sender, this.getPermission()))
{
return PlexUtils.getPlayerNameList();
return onlinePlayerNames();
}
return Collections.emptyList();
}
@@ -2,10 +2,8 @@ package dev.plex.listener;
import dev.plex.NUSHModule;
import dev.plex.UserData;
import dev.plex.util.PlexLog;
import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -13,24 +11,31 @@ import org.bukkit.event.EventPriority;
public class ChatListener extends PlexListener
{
private final NUSHModule module;
public ChatListener(NUSHModule module)
{
this.module = module;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(AsyncChatEvent event)
{
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;
}
PlexLog.debug("Handling event for player {0}", player.getName());
module.api().logging().debug("Handling event for player {0}", player.getName());
event.setCancelled(true);
player.sendMessage(event.renderer().render(player, player.displayName(), event.message(), player));
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));
p.sendMessage(message);
});
@@ -2,9 +2,6 @@ package dev.plex.listener;
import dev.plex.NUSHModule;
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.entity.Player;
import org.bukkit.event.EventHandler;
@@ -12,18 +9,23 @@ import org.bukkit.event.player.PlayerJoinEvent;
public class JoinListener extends PlexListener
{
private final NUSHModule module;
public JoinListener(NUSHModule module)
{
this.module = module;
}
@EventHandler
public void onJoin(PlayerJoinEvent event)
{
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());
UserData.queueNewPlayer(player);
module.api().logging().debug("Adding {0} to the new player list", player.getName());
UserData.queueNewPlayer(module, player);
Bukkit.getOnlinePlayers().stream().filter(p -> p.hasPermission("plex.nush.view")).forEach(p ->
p.sendMessage(Component.text("[NUSH] " + player.getName()
+ " has been marked as a new player and won't be able to chat normally for " + NUSHModule.getTime() + " minutes.")
.color(NamedTextColor.LIGHT_PURPLE)));
p.sendMessage(module.messageComponent("newPlayerMarked", player.getName(), module.getTime())));
}
}
}
+2 -1
View File
@@ -1,4 +1,5 @@
name: Module-NUSH
main: dev.plex.NUSHModule
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] "