mirror of
https://github.com/plexusorg/Module-Guilds.git
synced 2026-06-04 02:36:54 +00:00
Update for Plex 2.0
This commit is contained in:
+9
-9
@@ -16,21 +16,21 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("org.projectlombok:lombok:1.18.38")
|
compileOnly("org.projectlombok:lombok:1.18.46")
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.38")
|
annotationProcessor("org.projectlombok:lombok:1.18.46")
|
||||||
compileOnly("io.papermc.paper:paper-api:1.21.7-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:26.1.2.build.+")
|
||||||
implementation("org.apache.commons:commons-lang3:3.17.0")
|
implementation("org.apache.commons:commons-lang3:3.20.0")
|
||||||
compileOnly("dev.plex:server:1.5")
|
compileOnly("dev.plex:api:2.0-SNAPSHOT")
|
||||||
compileOnly("org.json:json:20250517")
|
compileOnly("org.json:json:20251224")
|
||||||
implementation("org.jetbrains:annotations:26.0.2")
|
implementation("org.jetbrains:annotations:26.1.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "dev.plex"
|
group = "dev.plex"
|
||||||
version = "1.5"
|
version = "2.0-SNAPSHOT"
|
||||||
description = "The Guilds module for Plex"
|
description = "The Guilds module for Plex"
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
toolchain.languageVersion.set(JavaLanguageVersion.of(25))
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
+3
-1
@@ -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-8.14.3-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
|
||||||
|
|||||||
@@ -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
@@ -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
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import dev.plex.data.SQLGuildManager;
|
|||||||
import dev.plex.data.SQLManager;
|
import dev.plex.data.SQLManager;
|
||||||
import dev.plex.guild.GuildHolder;
|
import dev.plex.guild.GuildHolder;
|
||||||
import dev.plex.module.PlexModule;
|
import dev.plex.module.PlexModule;
|
||||||
import dev.plex.util.PlexLog;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -25,6 +24,8 @@ public class Guilds extends PlexModule
|
|||||||
module = this;
|
module = this;
|
||||||
config = new ModuleConfig(this, "guilds/config.yml", "config.yml");
|
config = new ModuleConfig(this, "guilds/config.yml", "config.yml");
|
||||||
config.load();
|
config.load();
|
||||||
|
loadMessages("guilds/messages.yml");
|
||||||
|
this.registerCommand(new GuildCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -34,56 +35,29 @@ public class Guilds extends PlexModule
|
|||||||
sqlGuildManager = new SQLGuildManager();
|
sqlGuildManager = new SQLGuildManager();
|
||||||
sqlGuildManager.getGuilds().whenComplete((guilds, throwable) ->
|
sqlGuildManager.getGuilds().whenComplete((guilds, throwable) ->
|
||||||
{
|
{
|
||||||
PlexLog.debug("Finished loading {0} guilds", guilds.size());
|
if (throwable != null)
|
||||||
|
{
|
||||||
|
getLogger().error("Failed to load guilds", throwable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (guilds == null)
|
||||||
|
{
|
||||||
|
getLogger().error("Failed to load guilds");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
api().logging().debug("Finished loading {0} guilds", guilds.size());
|
||||||
guilds.forEach(guildHolder::addGuild);
|
guilds.forEach(guildHolder::addGuild);
|
||||||
this.registerCommand(new GuildCommand());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Plex.get().setChat(new ChatHandlerImpl());
|
|
||||||
|
|
||||||
addDefaultMessage("guildsHelpCommand", "<gradient:gold:yellow>======</gradient>Guild Menu<gradient:gold:yellow>======</gradient><newline><newline>{0}", "0 - The commands list");
|
|
||||||
addDefaultMessage("guildsCommandDisplay", "<gold>{0} <yellow>{1}", "0 - The command name", "1 - The command description");
|
|
||||||
addDefaultMessage("guildCommandNotFound", "<red>'<gold>{0}</gold>'<red> is not a valid sub command!", "0 - The sub command");
|
|
||||||
addDefaultMessage("guildNotFound", "<red>You're currently not a part of a guild!");
|
|
||||||
addDefaultMessage("guildInThis", "<red>You're currently a part of this guild!");
|
|
||||||
addDefaultMessage("alreadyInGuild", "<red>You're currently in a guild. Please do <gold>/guild leave<red> if you're a member, or if you're an owner with members, <gold>/guild promote <player><red> then <gold>/guild leave<red>, or just an owner, <gold>/guild disband<red>.");
|
|
||||||
addDefaultMessage("guildNotOwner", "<red>You're not the owner of this guild!");
|
|
||||||
addDefaultMessage("guildMemberNotFound", "<red>This guild member could not be found!");
|
|
||||||
addDefaultMessage("guildOwnerSet", "<green>You have successfully promoted <dark_green>{0}<green> to be the new guild owner. You have been set to a default guild member.");
|
|
||||||
|
|
||||||
addDefaultMessage("guildPrefixSet", "<green>You have changed the guild prefix to '<gold>{0}</gold><green>'", "0 - The new prefix");
|
|
||||||
addDefaultMessage("guildPrefixCleared", "<green>Your guild's prefix has been cleared.");
|
|
||||||
|
|
||||||
addDefaultMessage("guildWarpAlphanumeric", "<red>Warp names may only contain alphabetical and/or numerical characters.");
|
|
||||||
addDefaultMessage("guildWarpExists", "<red>'<gold>{0}</gold>'<red> is already an existing warp!", "0 - The warp name");
|
|
||||||
addDefaultMessage("guildWarpNotFound", "<red>'<gold>{0}</gold>'<red> is not a valid warp!", "0 - The warp name");
|
|
||||||
addDefaultMessage("guildWarpCreated", "<green>You have created a warp called '<dark_green>{0}</dark_green><green>'", "0 - The warp name");
|
|
||||||
|
|
||||||
addDefaultMessage("guildHomeRemoved", "<green>You have removed the guild's home!");
|
|
||||||
addDefaultMessage("guildHomeSet", "<green>You have changed the guild's home!");
|
|
||||||
addDefaultMessage("guildHomeNotFound", "<red>This guild currently has no home set.");
|
|
||||||
|
|
||||||
addDefaultMessage("guildChatMessage", "<blue>[GUILD] <aqua>{0} <yellow>{1}", "0 - The player name", "1 - The message");
|
|
||||||
addDefaultMessage("guildChatToggled", "<green>Your chat has been toggled {0}", "0 - On / Off");
|
|
||||||
addDefaultMessage("guildChatConsoleLog", "<blue>[GUILD - {0}:{1}] <aqua>{2} <yellow>{3}", "0 - The guild name", "1 - The guild unique identifier", "2 - The player name", "3 - The message");
|
|
||||||
|
|
||||||
addDefaultMessage("guildNoInvite", "<red>You don't have any pending invitations!");
|
|
||||||
addDefaultMessage("guildNotValidInvite", "<red>You don't have an invite from this guild!");
|
|
||||||
addDefaultMessage("guildInviteExists", "<red>You've already sent an invite to this person!");
|
|
||||||
addDefaultMessage("guildInviteSent", "<green>You have sent an invite to <dark_green>{0}", "0 - The invitee");
|
|
||||||
addDefaultMessage("guildInviteReceived", "<gold>You have received an invite from <yellow>{0}<gold> for the guild <yellow>{1}<newline><newline><green><bold><click:run_command:/guild invite accept {1}>[ACCEPT]<newline><newline><!bold><gold>You may also run <yellow>/guild invite accept {1}<gold> to accept this invite. It will expire in 5 minutes", "0 - The inviter", "1 - The guild name");
|
|
||||||
addDefaultMessage("guildMemberJoined", "<green>{0} has joined the guild!", "0 - The player who joined");
|
|
||||||
addDefaultMessage("guildMemberLeft", "<green>{0} has left the guild!", "0 - The player who left");
|
|
||||||
addDefaultMessage("guildDisbandNeeded", "<red>You need to disband your guild using <gold>/guild disband<red> or promote a new owner using <gold>/guild owner <player>");
|
|
||||||
addDefaultMessage("guildAutoDisbanded", "<green>Auto-disbanding your guild since there were no members");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable()
|
public void disable()
|
||||||
{
|
{
|
||||||
// Unregistering listeners / commands is handled by Plex
|
// Unregistering listeners / commands is handled by Plex
|
||||||
|
if (sqlGuildManager != null)
|
||||||
|
{
|
||||||
this.getGuildHolder().getGuilds().forEach(sqlGuildManager::updateGuild);
|
this.getGuildHolder().getGuilds().forEach(sqlGuildManager::updateGuild);
|
||||||
//this.getPlex().setChat(new ChatListener.PlexChatRenderer());
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Guilds get()
|
public static Guilds get()
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ package dev.plex.command;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.command.sub.*;
|
import dev.plex.command.sub.*;
|
||||||
import dev.plex.util.GuildUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.event.ClickEvent;
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -20,16 +18,17 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@CommandParameters(name = "guild", description = "Guild menu", aliases = "guilds,g")
|
public class GuildCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(permission = "plex.guilds.guild")
|
|
||||||
public class GuildCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
private final List<PlexCommand> subCommands = Lists.newArrayList();
|
private final List<SimplePlexCommand> subCommands = Lists.newArrayList();
|
||||||
|
|
||||||
public GuildCommand()
|
public GuildCommand()
|
||||||
{
|
{
|
||||||
try
|
super(command("guild")
|
||||||
{
|
.description("Guild menu")
|
||||||
|
.aliases("guilds,g")
|
||||||
|
.permission("plex.guilds.guild")
|
||||||
|
.build());
|
||||||
this.registerSubCommand(new CreateSubCommand());
|
this.registerSubCommand(new CreateSubCommand());
|
||||||
this.registerSubCommand(new InfoSubCommand());
|
this.registerSubCommand(new InfoSubCommand());
|
||||||
this.registerSubCommand(new PrefixSubCommand());
|
this.registerSubCommand(new PrefixSubCommand());
|
||||||
@@ -42,11 +41,6 @@ public class GuildCommand extends PlexCommand
|
|||||||
this.registerSubCommand(new OwnerSubCommand());
|
this.registerSubCommand(new OwnerSubCommand());
|
||||||
this.registerSubCommand(new InviteSubCommand());
|
this.registerSubCommand(new InviteSubCommand());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
GuildUtil.throwExceptionSync(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
|
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
|
||||||
@@ -66,83 +60,78 @@ public class GuildCommand extends PlexCommand
|
|||||||
{
|
{
|
||||||
return messageComponent("guildCommandNotFound", args[1]);
|
return messageComponent("guildCommandNotFound", args[1]);
|
||||||
}
|
}
|
||||||
CommandPermissions permissions = subCommand.getClass().getDeclaredAnnotation(CommandPermissions.class);
|
|
||||||
return mmString("<gradient:gold:yellow>========<newline>").append(mmString("<gold>Command Name: <yellow>" + subCommand.getName())).append(Component.newline())
|
return mmString("<gradient:gold:yellow>========<newline>").append(mmString("<gold>Command Name: <yellow>" + subCommand.getName())).append(Component.newline())
|
||||||
.append(mmString("<gold>Command Aliases: <yellow>" + StringUtils.join(subCommand.getAliases(), ", "))).append(Component.newline())
|
.append(mmString("<gold>Command Aliases: <yellow>" + StringUtils.join(subCommand.getAliases(), ", "))).append(Component.newline())
|
||||||
.append(mmString("<gold>Description: <yellow>" + subCommand.getDescription())).append(Component.newline())
|
.append(mmString("<gold>Description: <yellow>" + subCommand.getDescription())).append(Component.newline())
|
||||||
.append(mmString("<gold>Permission: <yellow>" + permissions.permission())).append(Component.newline())
|
.append(mmString("<gold>Permission: <yellow>" + subCommand.getPermission())).append(Component.newline())
|
||||||
.append(mmString("<gold>Required Source: <yellow>" + permissions.source().name()));
|
.append(mmString("<gold>Required Source: <yellow>" + subCommand.getRequiredSource().name()));
|
||||||
}
|
}
|
||||||
PlexCommand subCommand = getSubCommand(args[0]);
|
SimplePlexCommand subCommand = getSubCommand(args[0]);
|
||||||
if (subCommand == null)
|
if (subCommand == null)
|
||||||
{
|
{
|
||||||
return messageComponent("guildCommandNotFound", args[0]);
|
return messageComponent("guildCommandNotFound", args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandPermissions permissions = subCommand.getClass().getDeclaredAnnotation(CommandPermissions.class);
|
if (subCommand.getRequiredSource() == RequiredCommandSource.CONSOLE && commandSender instanceof Player)
|
||||||
if (permissions.source() == RequiredCommandSource.CONSOLE && commandSender instanceof Player)
|
|
||||||
{
|
{
|
||||||
return messageComponent("noPermissionInGame");
|
return messageComponent("noPermissionInGame");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (permissions.source() == RequiredCommandSource.IN_GAME && commandSender instanceof ConsoleCommandSender)
|
if (subCommand.getRequiredSource() == RequiredCommandSource.IN_GAME && commandSender instanceof ConsoleCommandSender)
|
||||||
{
|
{
|
||||||
return messageComponent("noPermissionConsole");
|
return messageComponent("noPermissionConsole");
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPermission(player, permissions.permission());
|
checkPermission(commandSender, subCommand.getPermission());
|
||||||
|
|
||||||
return subCommand.execute(commandSender, player, Arrays.copyOfRange(args, 1, args.length));
|
return subCommand.execute(commandSender, player, Arrays.copyOfRange(args, 1, args.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlexCommand getSubCommand(String label)
|
private SimplePlexCommand getSubCommand(String label)
|
||||||
{
|
{
|
||||||
return subCommands.stream().filter(cmd ->
|
return subCommands.stream()
|
||||||
{
|
.filter(cmd -> cmd.getName().equalsIgnoreCase(label) || cmd.getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(label)))
|
||||||
CommandParameters commandParameters = cmd.getClass().getDeclaredAnnotation(CommandParameters.class);
|
.findFirst()
|
||||||
return commandParameters.name().equalsIgnoreCase(label) || Arrays.stream(commandParameters.aliases().split(",")).anyMatch(s -> s.equalsIgnoreCase(label));
|
.orElse(null);
|
||||||
}).findFirst().orElse(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerSubCommand(PlexCommand subCommand)
|
private void registerSubCommand(SimplePlexCommand subCommand)
|
||||||
{
|
{
|
||||||
if (!subCommand.getClass().isAnnotationPresent(CommandPermissions.class))
|
if (Guilds.get() != null)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("CommandPermissions annotation for guild sub command " + subCommand.getName() + " could not be found!");
|
subCommand.bindModule(Guilds.get());
|
||||||
|
if (Guilds.get().api() != null)
|
||||||
|
{
|
||||||
|
subCommand.bindApi(Guilds.get().api());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!subCommand.getClass().isAnnotationPresent(CommandParameters.class))
|
|
||||||
{
|
|
||||||
throw new RuntimeException("CommandParameters annotation for guild sub command " + subCommand.getName() + " could not be found!");
|
|
||||||
}
|
}
|
||||||
this.subCommands.add(subCommand);
|
this.subCommands.add(subCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
{
|
{
|
||||||
List<String> possibleCommands = Lists.newArrayList();
|
List<String> possibleCommands = Lists.newArrayList();
|
||||||
if (!args[0].isEmpty())
|
|
||||||
{
|
|
||||||
subCommands.forEach(plexCommand ->
|
subCommands.forEach(plexCommand ->
|
||||||
{
|
{
|
||||||
plexCommand.getAliases().stream().filter(s -> s.toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT))).forEach(possibleCommands::add);
|
plexCommand.getAliases().stream()
|
||||||
|
.filter(s -> s.toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT)))
|
||||||
|
.forEach(possibleCommands::add);
|
||||||
if (plexCommand.getName().toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT)))
|
if (plexCommand.getName().toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT)))
|
||||||
{
|
{
|
||||||
possibleCommands.add(plexCommand.getName());
|
possibleCommands.add(plexCommand.getName());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
return possibleCommands;
|
return possibleCommands;
|
||||||
}
|
}
|
||||||
if (args.length >= 2)
|
if (args.length >= 2)
|
||||||
{
|
{
|
||||||
PlexCommand subCommand = getSubCommand(args[0]);
|
SimplePlexCommand subCommand = getSubCommand(args[0]);
|
||||||
if (subCommand != null)
|
if (subCommand != null)
|
||||||
{
|
{
|
||||||
return subCommand.tabComplete(sender, alias, Arrays.copyOfRange(args, 1, args.length));
|
return subCommand.suggestions(sender, alias, Arrays.copyOfRange(args, 1, args.length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package dev.plex.command.sub;
|
package dev.plex.command.sub;
|
||||||
|
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.SimplePlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.guild.data.Member;
|
import dev.plex.guild.data.Member;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -18,13 +16,16 @@ 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 = "chat", usage = "/guild <command> [message]", description = "Toggles guild chat or sends a guild chat message")
|
public class ChatSubCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.chat")
|
|
||||||
public class ChatSubCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
public ChatSubCommand()
|
public ChatSubCommand()
|
||||||
{
|
{
|
||||||
super(false);
|
super(command("chat")
|
||||||
|
.description("Toggles guild chat or sends a guild chat message")
|
||||||
|
.usage("/guild <command> [message]")
|
||||||
|
.permission("plex.guilds.chat")
|
||||||
|
.source(RequiredCommandSource.IN_GAME)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,7 +45,7 @@ public class ChatSubCommand extends PlexCommand
|
|||||||
{
|
{
|
||||||
send(player1, messageComponent("guildChatMessage", player.getName(), StringUtils.join(args, " ")));
|
send(player1, messageComponent("guildChatMessage", player.getName(), StringUtils.join(args, " ")));
|
||||||
});
|
});
|
||||||
if (Guilds.get().getConfig().isBoolean("guilds.log-chat-message"))
|
if (Guilds.get().getConfig().getBoolean("guilds.log-chat-message"))
|
||||||
{
|
{
|
||||||
send(Bukkit.getConsoleSender(), messageComponent("guildChatConsoleLog", guild.getName(), guild.getGuildUuid(), player.getName(), StringUtils.join(args, " ")));
|
send(Bukkit.getConsoleSender(), messageComponent("guildChatConsoleLog", guild.getName(), guild.getGuildUuid(), player.getName(), StringUtils.join(args, " ")));
|
||||||
}
|
}
|
||||||
@@ -53,7 +54,7 @@ public class ChatSubCommand extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package dev.plex.command.sub;
|
package dev.plex.command.sub;
|
||||||
|
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.SimplePlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.guild.Guild;
|
import dev.plex.guild.Guild;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -15,13 +13,17 @@ 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 = "create", aliases = "make", usage = "/guild <command> <name>", description = "Creates a guild with a specified name")
|
public class CreateSubCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.create")
|
|
||||||
public class CreateSubCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
public CreateSubCommand()
|
public CreateSubCommand()
|
||||||
{
|
{
|
||||||
super(false);
|
super(command("create")
|
||||||
|
.description("Creates a guild with a specified name")
|
||||||
|
.usage("/guild <command> <name>")
|
||||||
|
.aliases("make")
|
||||||
|
.permission("plex.guilds.create")
|
||||||
|
.source(RequiredCommandSource.IN_GAME)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,7 +47,7 @@ public class CreateSubCommand extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package dev.plex.command.sub;
|
package dev.plex.command.sub;
|
||||||
|
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.SimplePlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -13,13 +11,17 @@ 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 = "home", aliases = "spawn", usage = "/guild <command>", description = "Teleports to the guild home")
|
public class HomeSubCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.home")
|
|
||||||
public class HomeSubCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
public HomeSubCommand()
|
public HomeSubCommand()
|
||||||
{
|
{
|
||||||
super(false);
|
super(command("home")
|
||||||
|
.description("Teleports to the guild home")
|
||||||
|
.usage("/guild <command>")
|
||||||
|
.aliases("spawn")
|
||||||
|
.permission("plex.guilds.home")
|
||||||
|
.source(RequiredCommandSource.IN_GAME)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -39,7 +41,7 @@ public class HomeSubCommand extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package dev.plex.command.sub;
|
package dev.plex.command.sub;
|
||||||
|
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.api.player.PlexPlayerView;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.SimplePlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -17,13 +15,17 @@ 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 = "info", aliases = "information", usage = "/guild <command>", description = "Shows the guild's information")
|
public class InfoSubCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.info")
|
|
||||||
public class InfoSubCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
public InfoSubCommand()
|
public InfoSubCommand()
|
||||||
{
|
{
|
||||||
super(false);
|
super(command("info")
|
||||||
|
.description("Shows the guild's information")
|
||||||
|
.usage("/guild <command>")
|
||||||
|
.aliases("information")
|
||||||
|
.permission("plex.guilds.info")
|
||||||
|
.source(RequiredCommandSource.IN_GAME)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a");
|
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a");
|
||||||
@@ -38,26 +40,24 @@ public class InfoSubCommand extends PlexCommand
|
|||||||
{
|
{
|
||||||
send(player, mmString("<gradient:yellow:gold>====<aqua>" + guild.getName() + "<gradient:yellow:gold>===="));
|
send(player, mmString("<gradient:yellow:gold>====<aqua>" + guild.getName() + "<gradient:yellow:gold>===="));
|
||||||
send(player, mmString(""));
|
send(player, mmString(""));
|
||||||
try
|
send(player, mmString("<gold>Owner: <yellow>" + playerName(guild.getOwner().getUuid())));
|
||||||
{
|
List<String> members = guild.getMembers().stream().filter(member -> !member.getUuid().equals(guild.getOwner().getUuid())).map(member -> playerName(member.getUuid())).toList();
|
||||||
send(player, mmString("<gold>Owner: <yellow>" + DataUtils.getPlayer(guild.getOwner().getUuid(), false).getName()));
|
|
||||||
}
|
|
||||||
catch (NullPointerException e)
|
|
||||||
{
|
|
||||||
send(player, mmString("<gold>Owner: <yellow>Unable to load cache..."));
|
|
||||||
}
|
|
||||||
List<String> members = guild.getMembers().stream().filter(member -> !member.getUuid().equals(guild.getOwner().getUuid())).map(member -> DataUtils.getPlayer(member.getUuid(), false).getName()).toList();
|
|
||||||
send(player, mmString("<gold>Members (" + members.size() + "): " + StringUtils.join(members, ", ")));
|
send(player, mmString("<gold>Members (" + members.size() + "): " + StringUtils.join(members, ", ")));
|
||||||
send(player, mmString("<gold>Moderators (" + guild.getModerators().size() + "): " + StringUtils.join(guild.getModerators().stream().map(uuid -> DataUtils.getPlayer(uuid, false).getName()).toList(), ", ")));
|
send(player, mmString("<gold>Moderators (" + guild.getModerators().size() + "): " + StringUtils.join(guild.getModerators().stream().map(this::playerName).toList(), ", ")));
|
||||||
send(player, mmString("<gold>Prefix: " + (guild.getPrefix() == null ? "N/A" : guild.getPrefix())));
|
send(player, mmString("<gold>Prefix: " + (guild.getPrefix() == null ? "N/A" : guild.getPrefix())));
|
||||||
send(player, mmString("<gold>Created At: " + formatter.format(guild.getCreatedAt())));
|
send(player, mmString("<gold>Created At: " + formatter.format(guild.getCreatedAt())));
|
||||||
}, () -> send(player, messageComponent("guildNotFound")));
|
}, () -> send(player, messageComponent("guildNotFound")));
|
||||||
});
|
}, Guilds.get().api().scheduler().asyncExecutor());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String playerName(java.util.UUID uuid)
|
||||||
|
{
|
||||||
|
return api().players().byUuid(uuid).map(PlexPlayerView::name).orElse("Unable to load cache...");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,11 @@ package dev.plex.command.sub;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.SimplePlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.guild.Guild;
|
import dev.plex.guild.Guild;
|
||||||
import dev.plex.guild.GuildHolder;
|
import dev.plex.guild.GuildHolder;
|
||||||
import dev.plex.guild.data.Member;
|
import dev.plex.guild.data.Member;
|
||||||
import dev.plex.util.PlexLog;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -25,13 +22,17 @@ import java.util.stream.Collectors;
|
|||||||
// TODO: 5/9/2022 deny command maybe?
|
// TODO: 5/9/2022 deny command maybe?
|
||||||
// TODO: 5/9/2022 deny members from inviting themselves or existing members in the current guild
|
// TODO: 5/9/2022 deny members from inviting themselves or existing members in the current guild
|
||||||
|
|
||||||
@CommandParameters(name = "invite", aliases = "inv", usage = "/guild <command> <player name>", description = "Invites a player to the guild")
|
public class InviteSubCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.invite")
|
|
||||||
public class InviteSubCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
public InviteSubCommand()
|
public InviteSubCommand()
|
||||||
{
|
{
|
||||||
super(false);
|
super(command("invite")
|
||||||
|
.description("Invites a player to the guild")
|
||||||
|
.usage("/guild <command> <player name>")
|
||||||
|
.aliases("inv")
|
||||||
|
.permission("plex.guilds.invite")
|
||||||
|
.source(RequiredCommandSource.IN_GAME)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -116,7 +117,7 @@ public class InviteSubCommand extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (!(sender instanceof Player player))
|
if (!(sender instanceof Player player))
|
||||||
{
|
{
|
||||||
@@ -132,7 +133,7 @@ public class InviteSubCommand extends PlexCommand
|
|||||||
{
|
{
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
PlexLog.debug("Tab Completing moment");
|
api().logging().debug("Completing pending guild invites");
|
||||||
return GuildHolder.PENDING_INVITES.get(player.getUniqueId()).stream().map(Guild::getName).collect(Collectors.toList());
|
return GuildHolder.PENDING_INVITES.get(player.getUniqueId()).stream().map(Guild::getName).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package dev.plex.command.sub;
|
package dev.plex.command.sub;
|
||||||
|
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.api.player.PlexPlayerView;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.SimplePlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.guild.data.Member;
|
import dev.plex.guild.data.Member;
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -16,13 +13,17 @@ 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 = "owner", aliases = "setowner", usage = "/guild <command> <player name>", description = "Sets the guild owner")
|
public class OwnerSubCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.owner")
|
|
||||||
public class OwnerSubCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
public OwnerSubCommand()
|
public OwnerSubCommand()
|
||||||
{
|
{
|
||||||
super(false);
|
super(command("owner")
|
||||||
|
.description("Sets the guild owner")
|
||||||
|
.usage("/guild <command> <player name>")
|
||||||
|
.aliases("setowner")
|
||||||
|
.permission("plex.guilds.owner")
|
||||||
|
.source(RequiredCommandSource.IN_GAME)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -41,13 +42,13 @@ public class OwnerSubCommand extends PlexCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Member memberSender = guild.getMember(player.getUniqueId());
|
Member memberSender = guild.getMember(player.getUniqueId());
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[0], false);
|
PlexPlayerView plexPlayer = api().players().byName(args[0]).orElse(null);
|
||||||
if (plexPlayer == null)
|
if (plexPlayer == null)
|
||||||
{
|
{
|
||||||
send(player, messageComponent("playerNotFound"));
|
send(player, messageComponent("playerNotFound"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Member member = guild.getMember(plexPlayer.getUuid());
|
Member member = guild.getMember(plexPlayer.uuid());
|
||||||
if (member == null)
|
if (member == null)
|
||||||
{
|
{
|
||||||
send(player, messageComponent("guildMemberNotFound"));
|
send(player, messageComponent("guildMemberNotFound"));
|
||||||
@@ -56,13 +57,13 @@ public class OwnerSubCommand extends PlexCommand
|
|||||||
guild.setOwner(member);
|
guild.setOwner(member);
|
||||||
guild.getMembers().remove(member);
|
guild.getMembers().remove(member);
|
||||||
guild.getMembers().add(memberSender);
|
guild.getMembers().add(memberSender);
|
||||||
send(player, messageComponent("guildOwnerSet", plexPlayer.getName()));
|
send(player, messageComponent("guildOwnerSet", plexPlayer.name()));
|
||||||
}, () -> send(player, messageComponent("guildNotFound")));
|
}, () -> send(player, messageComponent("guildNotFound")));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package dev.plex.command.sub;
|
package dev.plex.command.sub;
|
||||||
|
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.SimplePlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
import dev.plex.util.GuildUtil;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -15,13 +13,17 @@ 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 = "prefix", aliases = "tag,settag,setprefix", usage = "/guild <command> <prefix>", description = "Sets the guild's default prefix")
|
public class PrefixSubCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.prefix")
|
|
||||||
public class PrefixSubCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
public PrefixSubCommand()
|
public PrefixSubCommand()
|
||||||
{
|
{
|
||||||
super(false);
|
super(command("prefix")
|
||||||
|
.description("Sets the guild's default prefix")
|
||||||
|
.usage("/guild <command> <prefix>")
|
||||||
|
.aliases("tag,settag,setprefix")
|
||||||
|
.permission("plex.guilds.prefix")
|
||||||
|
.source(RequiredCommandSource.IN_GAME)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -46,13 +48,13 @@ public class PrefixSubCommand extends PlexCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
guild.setPrefix(StringUtils.join(args, " "));
|
guild.setPrefix(StringUtils.join(args, " "));
|
||||||
send(player, messageComponent("guildPrefixSet", SafeMiniMessage.mmDeserializeWithoutEvents(guild.getPrefix())));
|
send(player, messageComponent("guildPrefixSet", GuildUtil.miniMessageWithoutEvents(guild.getPrefix())));
|
||||||
}, () -> send(player, messageComponent("guildNotFound")));
|
}, () -> send(player, messageComponent("guildNotFound")));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package dev.plex.command.sub;
|
package dev.plex.command.sub;
|
||||||
|
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.SimplePlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.util.CustomLocation;
|
import dev.plex.util.CustomLocation;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -14,13 +12,17 @@ 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 = "sethome", aliases = "setspawn", usage = "/guild <command>", description = "Sets the guild's home")
|
public class SetHomeSubCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.sethome")
|
|
||||||
public class SetHomeSubCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
public SetHomeSubCommand()
|
public SetHomeSubCommand()
|
||||||
{
|
{
|
||||||
super(false);
|
super(command("sethome")
|
||||||
|
.description("Sets the guild's home")
|
||||||
|
.usage("/guild <command>")
|
||||||
|
.aliases("setspawn")
|
||||||
|
.permission("plex.guilds.sethome")
|
||||||
|
.source(RequiredCommandSource.IN_GAME)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -52,7 +54,7 @@ public class SetHomeSubCommand extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package dev.plex.command.sub;
|
package dev.plex.command.sub;
|
||||||
|
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.SimplePlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.util.CustomLocation;
|
import dev.plex.util.CustomLocation;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -16,13 +14,17 @@ 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 = "setwarp", aliases = "makewarp,createwarp", usage = "/guild <command> <name>", description = "Creates a new warp at player's location with a specified name")
|
public class SetWarpSubCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.setwarp")
|
|
||||||
public class SetWarpSubCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
public SetWarpSubCommand()
|
public SetWarpSubCommand()
|
||||||
{
|
{
|
||||||
super(false);
|
super(command("setwarp")
|
||||||
|
.description("Creates a new warp at player's location with a specified name")
|
||||||
|
.usage("/guild <command> <name>")
|
||||||
|
.aliases("makewarp,createwarp")
|
||||||
|
.permission("plex.guilds.setwarp")
|
||||||
|
.source(RequiredCommandSource.IN_GAME)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,7 +65,7 @@ public class SetWarpSubCommand extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ package dev.plex.command.sub;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.SimplePlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.guild.Guild;
|
import dev.plex.guild.Guild;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -16,13 +14,17 @@ 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 = "warps", aliases = "listwarps", usage = "/guild <command>", description = "Displays a clickable list of warps")
|
public class WarpListSubCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warps")
|
|
||||||
public class WarpListSubCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
public WarpListSubCommand()
|
public WarpListSubCommand()
|
||||||
{
|
{
|
||||||
super(false);
|
super(command("warps")
|
||||||
|
.description("Displays a clickable list of warps")
|
||||||
|
.usage("/guild <command>")
|
||||||
|
.aliases("listwarps")
|
||||||
|
.permission("plex.guilds.warps")
|
||||||
|
.source(RequiredCommandSource.IN_GAME)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -55,7 +57,7 @@ public class WarpListSubCommand extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package dev.plex.command.sub;
|
package dev.plex.command.sub;
|
||||||
|
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.SimplePlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -14,13 +12,17 @@ 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 = "warp", aliases = "goto", usage = "/guild <command> <name>", description = "Warps to a specified guild warp")
|
public class WarpSubCommand extends SimplePlexCommand
|
||||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warp")
|
|
||||||
public class WarpSubCommand extends PlexCommand
|
|
||||||
{
|
{
|
||||||
public WarpSubCommand()
|
public WarpSubCommand()
|
||||||
{
|
{
|
||||||
super(false);
|
super(command("warp")
|
||||||
|
.description("Warps to a specified guild warp")
|
||||||
|
.usage("/guild <command> <name>")
|
||||||
|
.aliases("goto")
|
||||||
|
.permission("plex.guilds.warp")
|
||||||
|
.source(RequiredCommandSource.IN_GAME)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,7 +47,7 @@ public class WarpSubCommand extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
protected @NotNull List<String> suggestions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ package dev.plex.data;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
|
import dev.plex.Guilds;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import dev.plex.Plex;
|
|
||||||
import dev.plex.guild.Guild;
|
import dev.plex.guild.Guild;
|
||||||
import dev.plex.guild.data.Member;
|
import dev.plex.guild.data.Member;
|
||||||
import dev.plex.util.CustomLocation;
|
import dev.plex.util.CustomLocation;
|
||||||
import dev.plex.util.GuildUtil;
|
import dev.plex.util.GuildUtil;
|
||||||
import dev.plex.util.PlexLog;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@@ -34,11 +33,10 @@ public class SQLGuildManager
|
|||||||
|
|
||||||
public CompletableFuture<Guild> insertGuild(Guild guild)
|
public CompletableFuture<Guild> insertGuild(Guild guild)
|
||||||
{
|
{
|
||||||
return CompletableFuture.supplyAsync(() ->
|
return supplyStorageAsync(connection ->
|
||||||
{
|
{
|
||||||
try (Connection connection = Plex.get().getSqlConnection().getCon())
|
try (PreparedStatement statement = connection.prepareStatement(INSERT_GUILD))
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(INSERT_GUILD);
|
|
||||||
statement.setString(1, guild.getGuildUuid().toString());
|
statement.setString(1, guild.getGuildUuid().toString());
|
||||||
statement.setString(2, guild.getName());
|
statement.setString(2, guild.getName());
|
||||||
statement.setString(3, GSON.toJson(guild.getOwner()));
|
statement.setString(3, GSON.toJson(guild.getOwner()));
|
||||||
@@ -56,38 +54,28 @@ public class SQLGuildManager
|
|||||||
statement.execute();
|
statement.execute();
|
||||||
return guild;
|
return guild;
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
GuildUtil.throwExceptionSync(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Void> deleteGuild(UUID uuid)
|
public CompletableFuture<Void> deleteGuild(UUID uuid)
|
||||||
{
|
{
|
||||||
return CompletableFuture.runAsync(() ->
|
return supplyStorageAsync(connection ->
|
||||||
{
|
{
|
||||||
try (Connection connection = Plex.get().getSqlConnection().getCon())
|
try (PreparedStatement statement = connection.prepareStatement(DELETE_GUILD))
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(DELETE_GUILD);
|
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
}
|
return null;
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
GuildUtil.throwExceptionSync(e);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Guild> updateGuild(Guild guild)
|
public CompletableFuture<Guild> updateGuild(Guild guild)
|
||||||
{
|
{
|
||||||
return CompletableFuture.supplyAsync(() ->
|
return supplyStorageAsync(connection ->
|
||||||
{
|
{
|
||||||
try (Connection connection = Plex.get().getSqlConnection().getCon())
|
try (PreparedStatement statement = connection.prepareStatement(UPDATE_GUILD))
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(UPDATE_GUILD);
|
|
||||||
statement.setString(1, guild.getName());
|
statement.setString(1, guild.getName());
|
||||||
statement.setString(2, GSON.toJson(guild.getOwner()));
|
statement.setString(2, GSON.toJson(guild.getOwner()));
|
||||||
statement.setString(3, GSON.toJson(guild.getMembers()));
|
statement.setString(3, GSON.toJson(guild.getMembers()));
|
||||||
@@ -104,34 +92,36 @@ public class SQLGuildManager
|
|||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
return guild;
|
return guild;
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
GuildUtil.throwExceptionSync(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Guild> getGuildsSync()
|
private List<Guild> getGuildsSync(Connection connection) throws SQLException
|
||||||
{
|
{
|
||||||
List<Guild> guilds = Lists.newArrayList();
|
List<Guild> guilds = Lists.newArrayList();
|
||||||
try (Connection connection = Plex.get().getSqlConnection().getCon())
|
try (PreparedStatement statement = connection.prepareStatement(SELECT_GUILD);
|
||||||
|
ResultSet set = statement.executeQuery())
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT_GUILD);
|
|
||||||
ResultSet set = statement.executeQuery();
|
|
||||||
while (set.next())
|
while (set.next())
|
||||||
{
|
{
|
||||||
|
String timezone = Guilds.get().api().configuration().mainConfig().getString("server.timezone", "Etc/UTC");
|
||||||
Guild guild = new Guild(UUID.fromString(set.getString("guildUuid")),
|
Guild guild = new Guild(UUID.fromString(set.getString("guildUuid")),
|
||||||
ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("createdAt")), ZoneId.of(Plex.get().config.getString("server.timezone")).getRules().getOffset(Instant.now())));
|
ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("createdAt")), ZoneId.of(timezone).getRules().getOffset(Instant.now())));
|
||||||
guild.setName(set.getString("name"));
|
guild.setName(set.getString("name"));
|
||||||
guild.setOwner(GSON.fromJson(set.getString("owner"), Member.class));
|
guild.setOwner(GSON.fromJson(set.getString("owner"), Member.class));
|
||||||
List<Member> members = new Gson().fromJson(set.getString("members"), new TypeToken<List<Member>>()
|
List<Member> members = new Gson().fromJson(set.getString("members"), new TypeToken<List<Member>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
members.forEach(guild::addMember);
|
if (members != null)
|
||||||
guild.getModerators().addAll(new Gson().fromJson(set.getString("moderators"), new TypeToken<List<String>>()
|
|
||||||
{
|
{
|
||||||
}.getType()));
|
members.forEach(guild::addMember);
|
||||||
|
}
|
||||||
|
List<String> moderators = new Gson().fromJson(set.getString("moderators"), new TypeToken<List<String>>()
|
||||||
|
{
|
||||||
|
}.getType());
|
||||||
|
if (moderators != null)
|
||||||
|
{
|
||||||
|
moderators.stream().map(UUID::fromString).forEach(guild.getModerators()::add);
|
||||||
|
}
|
||||||
guild.setPrefix(set.getString("prefix"));
|
guild.setPrefix(set.getString("prefix"));
|
||||||
guild.setMotd(set.getString("motd"));
|
guild.setMotd(set.getString("motd"));
|
||||||
guild.setHome(GSON.fromJson(set.getString("home"), CustomLocation.class));
|
guild.setHome(GSON.fromJson(set.getString("home"), CustomLocation.class));
|
||||||
@@ -139,24 +129,37 @@ public class SQLGuildManager
|
|||||||
Map<String, CustomLocation> warps = GSON.fromJson(set.getString("warps"), new TypeToken<Map<String, CustomLocation>>()
|
Map<String, CustomLocation> warps = GSON.fromJson(set.getString("warps"), new TypeToken<Map<String, CustomLocation>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
PlexLog.debug("Loaded {0} warps for {1} guild", warps.size(), guild.getName());
|
if (warps != null)
|
||||||
guild.getWarps().putAll(GSON.fromJson(set.getString("warps"), new TypeToken<Map<String, CustomLocation>>()
|
|
||||||
{
|
{
|
||||||
}.getType()));
|
Guilds.get().api().logging().debug("Loaded {0} warps for {1} guild", warps.size(), guild.getName());
|
||||||
|
guild.getWarps().putAll(warps);
|
||||||
|
}
|
||||||
guild.setPublic(set.getBoolean("isPublic"));
|
guild.setPublic(set.getBoolean("isPublic"));
|
||||||
guilds.add(guild);
|
guilds.add(guild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
GuildUtil.throwExceptionSync(e);
|
|
||||||
}
|
|
||||||
return guilds;
|
return guilds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<List<Guild>> getGuilds()
|
public CompletableFuture<List<Guild>> getGuilds()
|
||||||
{
|
{
|
||||||
return CompletableFuture.supplyAsync(this::getGuildsSync);
|
return supplyStorageAsync(this::getGuildsSync);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> CompletableFuture<T> supplyStorageAsync(dev.plex.api.storage.StorageApi.SqlFunction<T> function)
|
||||||
|
{
|
||||||
|
return CompletableFuture.supplyAsync(() ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Guilds.get().api().storage().withConnection(function);
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
GuildUtil.throwExceptionSync(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, Guilds.get().api().scheduler().asyncExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
package dev.plex.data;
|
package dev.plex.data;
|
||||||
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Guilds;
|
||||||
|
import dev.plex.util.GuildUtil;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class SQLManager
|
public class SQLManager
|
||||||
{
|
{
|
||||||
public static void makeTables()
|
public static void makeTables()
|
||||||
{
|
{
|
||||||
try (Connection connection = Plex.get().getSqlConnection().getCon())
|
try
|
||||||
{
|
{
|
||||||
connection.prepareStatement(
|
Guilds.get().api().storage().withConnection(connection ->
|
||||||
|
{
|
||||||
|
try (PreparedStatement statement = connection.prepareStatement(
|
||||||
"CREATE TABLE IF NOT EXISTS `guilds` (" +
|
"CREATE TABLE IF NOT EXISTS `guilds` (" +
|
||||||
"`guildUuid` VARCHAR(46) NOT NULL, " +
|
"`guildUuid` VARCHAR(46) NOT NULL, " +
|
||||||
"`name` VARCHAR(2000) NOT NULL, " +
|
"`name` VARCHAR(2000) NOT NULL, " +
|
||||||
@@ -28,12 +31,16 @@ public class SQLManager
|
|||||||
"`tagEnabled` BOOLEAN, " +
|
"`tagEnabled` BOOLEAN, " +
|
||||||
"`isPublic` BOOLEAN, " +
|
"`isPublic` BOOLEAN, " +
|
||||||
"PRIMARY KEY (`guildUuid`)" +
|
"PRIMARY KEY (`guildUuid`)" +
|
||||||
");"
|
");"))
|
||||||
).execute();
|
{
|
||||||
|
statement.execute();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
GuildUtil.throwExceptionSync(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package dev.plex.guild;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.guild.data.Member;
|
import dev.plex.guild.data.Member;
|
||||||
import dev.plex.guild.data.Rank;
|
import dev.plex.guild.data.Rank;
|
||||||
import dev.plex.util.CustomLocation;
|
import dev.plex.util.CustomLocation;
|
||||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
import dev.plex.util.GuildUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -38,8 +38,9 @@ public class Guild
|
|||||||
|
|
||||||
public static Guild create(Player player, String guildName)
|
public static Guild create(Player player, String guildName)
|
||||||
{
|
{
|
||||||
Guild guild = new Guild(UUID.randomUUID(), ZonedDateTime.now(ZoneId.of(Plex.get().config.getString("server.timezone"))));
|
String timezone = Guilds.get().api().configuration().mainConfig().getString("server.timezone", "Etc/UTC");
|
||||||
guild.setName(PlainTextComponentSerializer.plainText().serialize(SafeMiniMessage.mmDeserialize(guildName)));
|
Guild guild = new Guild(UUID.randomUUID(), ZonedDateTime.now(ZoneId.of(timezone)));
|
||||||
|
guild.setName(PlainTextComponentSerializer.plainText().serialize(GuildUtil.miniMessageWithoutEvents(guildName)));
|
||||||
guild.setOwner(new Member(player.getUniqueId()));
|
guild.setOwner(new Member(player.getUniqueId()));
|
||||||
return guild;
|
return guild;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,96 +1,37 @@
|
|||||||
package dev.plex.handler;
|
package dev.plex.handler;
|
||||||
|
|
||||||
import dev.plex.Guilds;
|
import dev.plex.Guilds;
|
||||||
import dev.plex.Plex;
|
|
||||||
import dev.plex.guild.data.Member;
|
import dev.plex.guild.data.Member;
|
||||||
import dev.plex.hook.VaultHook;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
|
||||||
import io.papermc.paper.chat.ChatRenderer;
|
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import java.util.Objects;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.TextReplacementConfig;
|
|
||||||
import net.kyori.adventure.text.event.ClickEvent;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
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;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import java.util.Objects;
|
public class ChatHandlerImpl implements Listener
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
public class ChatHandlerImpl
|
|
||||||
{
|
{
|
||||||
private final static TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig.builder().match("(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]").replacement((matchResult, builder) -> Component.empty().content(matchResult.group()).clickEvent(ClickEvent.openUrl(matchResult.group()))).build();
|
|
||||||
private final PlexChatRenderer renderer = new PlexChatRenderer();
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void doChat(AsyncChatEvent event)
|
public void doChat(AsyncChatEvent event)
|
||||||
{
|
{
|
||||||
event.renderer(renderer);
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresent(guild ->
|
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresent(guild ->
|
||||||
{
|
{
|
||||||
Member member = guild.getMember(player.getUniqueId());
|
Member member = guild.getMember(player.getUniqueId());
|
||||||
if (member == null)
|
if (member == null || !member.isChat())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!member.isChat())
|
|
||||||
|
String message = PlainTextComponentSerializer.plainText().serialize(event.message());
|
||||||
|
guild.getMembers().stream().map(Member::getPlayer).filter(Objects::nonNull).forEach(memberPlayer ->
|
||||||
|
memberPlayer.sendMessage(Guilds.get().messageComponent("guildChatMessage", player.getName(), message)));
|
||||||
|
if (Guilds.get().getConfig().getBoolean("guilds.log-chat-message"))
|
||||||
{
|
{
|
||||||
return;
|
Bukkit.getConsoleSender().sendMessage(Guilds.get().messageComponent("guildChatConsoleLog", guild.getName(), guild.getGuildUuid(), player.getName(), message));
|
||||||
}
|
|
||||||
guild.getMembers().stream().map(Member::getPlayer).filter(Objects::nonNull).forEach(player1 ->
|
|
||||||
{
|
|
||||||
player1.sendMessage(PlexUtils.messageComponent("guildChatMessage", player.getName(), PlainTextComponentSerializer.plainText().serialize(event.message())));
|
|
||||||
});
|
|
||||||
if (Guilds.get().getConfig().isBoolean("guilds.log-chat-message"))
|
|
||||||
{
|
|
||||||
Bukkit.getConsoleSender().sendMessage(PlexUtils.messageComponent("guildChatConsoleLog", guild.getName(), guild.getGuildUuid(), player.getName(), PlainTextComponentSerializer.plainText().serialize(event.message())));
|
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PlexChatRenderer implements ChatRenderer
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public @NotNull Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer)
|
|
||||||
{
|
|
||||||
String text = PlexUtils.getTextFromComponent(message);
|
|
||||||
|
|
||||||
PlexPlayer plexPlayer = Plex.get().getPlayerCache().getPlexPlayerMap().get(source.getUniqueId());
|
|
||||||
Component prefix = VaultHook.getPrefix(plexPlayer);
|
|
||||||
|
|
||||||
AtomicBoolean guildPrefix = new AtomicBoolean(false);
|
|
||||||
AtomicReference<Component> component = new AtomicReference<>(Component.empty());
|
|
||||||
Guilds.get().getGuildHolder().getGuild(source.getUniqueId()).ifPresent(guild ->
|
|
||||||
{
|
|
||||||
if (guild.getPrefix() != null)
|
|
||||||
{
|
|
||||||
component.set(component.get().append(SafeMiniMessage.mmDeserializeWithoutEvents(guild.getPrefix())));
|
|
||||||
guildPrefix.set(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (prefix != null)
|
|
||||||
{
|
|
||||||
if (guildPrefix.get())
|
|
||||||
{
|
|
||||||
component.set(component.get().append(Component.space()));
|
|
||||||
}
|
|
||||||
component.set(component.get().append(prefix));
|
|
||||||
}
|
|
||||||
|
|
||||||
return component.get().append(Component.space()).append(PlexUtils.mmDeserialize(Plex.get().config.getString("chat.name-color", "<white>") + MiniMessage.builder().tags(TagResolver.resolver(StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition())).build().serialize(sourceDisplayName))).append(Component.space()).append(Component.text("»").color(NamedTextColor.GRAY)).append(Component.space()).append(SafeMiniMessage.mmDeserializeWithoutEvents(text)).replaceText(URL_REPLACEMENT_CONFIG);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,26 @@
|
|||||||
package dev.plex.util;
|
package dev.plex.util;
|
||||||
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Guilds;
|
||||||
import org.bukkit.Bukkit;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
public class GuildUtil
|
public class GuildUtil
|
||||||
{
|
{
|
||||||
|
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
|
||||||
|
|
||||||
public static void throwExceptionSync(Throwable throwable)
|
public static void throwExceptionSync(Throwable throwable)
|
||||||
{
|
{
|
||||||
Bukkit.getScheduler().runTask(Plex.get(), () -> throwable.printStackTrace());
|
if (Guilds.get() != null && Guilds.get().getLogger() != null)
|
||||||
|
{
|
||||||
|
Guilds.get().getLogger().error("Guild module task failed", throwable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throwable.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component miniMessageWithoutEvents(String text)
|
||||||
|
{
|
||||||
|
return MINI_MESSAGE.deserialize(text).clickEvent(null).hoverEvent(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
guildsHelpCommand: "<gradient:gold:yellow>======</gradient>Guild Menu<gradient:gold:yellow>======</gradient><newline><newline>{0}"
|
||||||
|
guildsCommandDisplay: "<gold>{0} <yellow>{1}"
|
||||||
|
guildCommandNotFound: "<red>'<gold>{0}</gold>'<red> is not a valid sub command!"
|
||||||
|
guildNotFound: "<red>You're currently not a part of a guild!"
|
||||||
|
guildInThis: "<red>You're currently a part of this guild!"
|
||||||
|
alreadyInGuild: "<red>You're currently in a guild. Please do <gold>/guild leave<red> if you're a member, or if you're an owner with members, <gold>/guild promote <player><red> then <gold>/guild leave<red>, or just an owner, <gold>/guild disband<red>."
|
||||||
|
guildNotOwner: "<red>You're not the owner of this guild!"
|
||||||
|
guildMemberNotFound: "<red>This guild member could not be found!"
|
||||||
|
guildOwnerSet: "<green>You have successfully promoted <dark_green>{0}<green> to be the new guild owner. You have been set to a default guild member."
|
||||||
|
guildPrefixSet: "<green>You have changed the guild prefix to '<gold>{0}</gold><green>'"
|
||||||
|
guildPrefixCleared: "<green>Your guild's prefix has been cleared."
|
||||||
|
guildWarpAlphanumeric: "<red>Warp names may only contain alphabetical and/or numerical characters."
|
||||||
|
guildWarpExists: "<red>'<gold>{0}</gold>'<red> is already an existing warp!"
|
||||||
|
guildWarpNotFound: "<red>'<gold>{0}</gold>'<red> is not a valid warp!"
|
||||||
|
guildWarpCreated: "<green>You have created a warp called '<dark_green>{0}</dark_green><green>'"
|
||||||
|
guildHomeRemoved: "<green>You have removed the guild's home!"
|
||||||
|
guildHomeSet: "<green>You have changed the guild's home!"
|
||||||
|
guildHomeNotFound: "<red>This guild currently has no home set."
|
||||||
|
guildChatMessage: "<blue>[GUILD] <aqua>{0} <yellow>{1}"
|
||||||
|
guildChatToggled: "<green>Your chat has been toggled {0}"
|
||||||
|
guildChatConsoleLog: "<blue>[GUILD - {0}:{1}] <aqua>{2} <yellow>{3}"
|
||||||
|
guildNoInvite: "<red>You don't have any pending invitations!"
|
||||||
|
guildNotValidInvite: "<red>You don't have an invite from this guild!"
|
||||||
|
guildInviteExists: "<red>You've already sent an invite to this person!"
|
||||||
|
guildInviteSent: "<green>You have sent an invite to <dark_green>{0}"
|
||||||
|
guildInviteReceived: "<gold>You have received an invite from <yellow>{0}<gold> for the guild <yellow>{1}<newline><newline><green><bold><click:run_command:/guild invite accept {1}>[ACCEPT]<newline><newline><!bold><gold>You may also run <yellow>/guild invite accept {1}<gold> to accept this invite. It will expire in 5 minutes"
|
||||||
|
guildMemberJoined: "<green>{0} has joined the guild!"
|
||||||
|
guildMemberLeft: "<green>{0} has left the guild!"
|
||||||
|
guildDisbandNeeded: "<red>You need to disband your guild using <gold>/guild disband<red> or promote a new owner using <gold>/guild owner <player>"
|
||||||
|
guildAutoDisbanded: "<green>Auto-disbanding your guild since there were no members"
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
name: Module-Guilds
|
name: Module-Guilds
|
||||||
main: dev.plex.Guilds
|
main: dev.plex.Guilds
|
||||||
description: The guilds module for Plex
|
description: The guilds module for Plex
|
||||||
version: 1.5
|
version: 2.0-SNAPSHOT
|
||||||
|
apiCompatibility: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user