diff --git a/.idea/codeStyles/Plexus_Code_Style.xml b/.idea/codeStyles/Plexus_Code_Style.xml index a7db3e4..3dc4a27 100644 --- a/.idea/codeStyles/Plexus_Code_Style.xml +++ b/.idea/codeStyles/Plexus_Code_Style.xml @@ -1,33 +1,8 @@ - - - - - - - - + + \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a6199f6..fb967e9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,24 +1,37 @@ -For those who are wanting to contribute, we fully encourage doing so. There are a few rules we require following when contributing however. +For those who are wanting to contribute, we fully encourage doing so. There are a few rules we require following when +contributing however. ## Steps + 1. Make an issue and get feedback. It's important to know if your idea will be accepted before writing any code. + - If it is a feature request, describe the feature and be extremely specific. - If it is a bug report, ensure you include how to reproduce the bug and the expected outcome - If it is an enhancement, describe your proposed changes. Ensure you are extremely specific. + 2. Fork this project -3. Create a new branch that describes the new feature, enhancement, or bug fix. For example, this is good: `feature/add-xyz`. This is bad: `fix-this-lol`. +3. Create a new branch that describes the new feature, enhancement, or bug fix. For example, this is + good: `feature/add-xyz`. This is bad: `fix-this-lol`. 4. Write the code that addresses your change. -- Keep in mind that it **must** be formatted correctly. If you are using IntelliJ, there is a `codeStyle.xml` file that tells IntelliJ how to format your code. Check this link for information on how to use the file: https://www.jetbrains.com/help/idea/configuring-code-style.html#import-export-schemes -- If you are not using IntelliJ, that is fine. We use the Plexus Code Style (which is almost the same as Allman) so please format your code accordingly. + +- Keep in mind that it **must** be formatted correctly. If you are using IntelliJ, there is a `codeStyle.xml` file that + tells IntelliJ how to format your code. Check this link for information on how to use the + file: https://www.jetbrains.com/help/idea/configuring-code-style.html#import-export-schemes +- If you are not using IntelliJ, that is fine. We use the Plexus Code Style (which is almost the same as Allman) so + please format your code accordingly. + 6. Push your changes to your new branch and make a PR based off of that branch. ## Requirements for a PR + - The issue must be marked as approved - It must only address each specific issue. Don't make one PR for multiple issues. - Your PR must compile and work. If it does not compile or work, your PR will most likely be rejected. ## Code requirements -- Most importantly, your code must be efficient. Your pull request may be rejected if your code is deemed inefficient or sloppy. + +- Most importantly, your code must be efficient. Your pull request may be rejected if your code is deemed inefficient or + sloppy. - Do not repeat yourself. Create functions as needed if you're using large blocks of code over and over again. - Do not use an excessive amount of commits when making your PR. It makes the master branch look messy. - Your code must be consistent with Plex's codebase. If a function already exists, use it. \ No newline at end of file diff --git a/README.md b/README.md index af60730..31f271c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # Module-Guilds [![Build Status](https://ci.plex.us.org/job/Module-Guilds/badge/icon)](https://ci.plex.us.org/job/Module-Guilds/) + The Guilds module for Plex diff --git a/build.gradle.kts b/build.gradle.kts index 1a793b4..6d6659f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,14 +20,13 @@ dependencies { annotationProcessor("org.projectlombok:lombok:1.18.28") compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") implementation("org.apache.commons:commons-lang3:3.12.0") - compileOnly("dev.plex:server:1.3") - compileOnly("dev.morphia.morphia:morphia-core:2.3.5") + compileOnly("dev.plex:server:1.4-SNAPSHOT") compileOnly("org.json:json:20230618") implementation("org.jetbrains:annotations:24.0.1") } group = "dev.plex" -version = "1.3" +version = "1.4-SNAPSHOT" description = "The Guilds module for Plex" java { @@ -43,7 +42,7 @@ publishing { } tasks.getByName("jar") { - archiveBaseName.set("Plex-Guilds") + archiveBaseName.set("Module-Guilds") archiveVersion.set("") } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ccebba7..033e24c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 17a8ddc..ac72c34 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 79a61d4..fcb6fca 100755 --- a/gradlew +++ b/gradlew @@ -85,9 +85,6 @@ done APP_BASE_NAME=${0##*/} APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +130,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in diff --git a/src/main/java/dev/plex/Guilds.java b/src/main/java/dev/plex/Guilds.java index 9a74268..7be02f8 100644 --- a/src/main/java/dev/plex/Guilds.java +++ b/src/main/java/dev/plex/Guilds.java @@ -4,14 +4,11 @@ import dev.plex.command.GuildCommand; import dev.plex.config.ModuleConfig; import dev.plex.data.SQLGuildManager; import dev.plex.data.SQLManager; -import dev.plex.guild.Guild; import dev.plex.guild.GuildHolder; import dev.plex.module.PlexModule; -import dev.plex.storage.StorageType; import dev.plex.util.PlexLog; import lombok.Getter; -//TODO: Implement mongodb @Getter public class Guilds extends PlexModule { @@ -33,22 +30,14 @@ public class Guilds extends PlexModule @Override public void enable() { - if (Plex.get().getStorageType() == StorageType.MONGODB) + SQLManager.makeTables(); + sqlGuildManager = new SQLGuildManager(); + sqlGuildManager.getGuilds().whenComplete((guilds, throwable) -> { - Plex.get().getMongoConnection().getDatastore().getMapper().map(Guild.class); - Plex.get().getMongoConnection().getDatastore().ensureIndexes(); - } - else - { - SQLManager.makeTables(); - sqlGuildManager = new SQLGuildManager(); - sqlGuildManager.getGuilds().whenComplete((guilds, throwable) -> - { - PlexLog.debug("Finished loading {0} guilds", guilds.size()); - guilds.forEach(guildHolder::addGuild); - this.registerCommand(new GuildCommand()); - }); - } + PlexLog.debug("Finished loading {0} guilds", guilds.size()); + guilds.forEach(guildHolder::addGuild); + this.registerCommand(new GuildCommand()); + }); //Plex.get().setChat(new ChatHandlerImpl()); diff --git a/src/main/java/dev/plex/command/GuildCommand.java b/src/main/java/dev/plex/command/GuildCommand.java index ea98d0a..4bd492b 100644 --- a/src/main/java/dev/plex/command/GuildCommand.java +++ b/src/main/java/dev/plex/command/GuildCommand.java @@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.sub.*; -import dev.plex.rank.enums.Rank; import dev.plex.util.GuildUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; @@ -22,7 +21,7 @@ import java.util.List; import java.util.Locale; @CommandParameters(name = "guild", description = "Guild menu", aliases = "guilds,g") -@CommandPermissions(level = Rank.OP, permission = "plex.guilds.guild") +@CommandPermissions(permission = "plex.guilds.guild") public class GuildCommand extends PlexCommand { private final List subCommands = Lists.newArrayList(); @@ -42,7 +41,8 @@ public class GuildCommand extends PlexCommand this.registerSubCommand(new HomeSubCommand()); this.registerSubCommand(new OwnerSubCommand()); this.registerSubCommand(new InviteSubCommand()); - } catch (Exception e) + } + catch (Exception e) { GuildUtil.throwExceptionSync(e); } @@ -71,7 +71,6 @@ public class GuildCommand extends PlexCommand .append(mmString("Command Aliases: " + StringUtils.join(subCommand.getAliases(), ", "))).append(Component.newline()) .append(mmString("Description: " + subCommand.getDescription())).append(Component.newline()) .append(mmString("Permission: " + permissions.permission())).append(Component.newline()) - .append(mmString("Required Rank: " + permissions.level().name())).append(Component.newline()) .append(mmString("Required Source: " + permissions.source().name())); } PlexCommand subCommand = getSubCommand(args[0]); @@ -91,7 +90,7 @@ public class GuildCommand extends PlexCommand return messageComponent("noPermissionConsole"); } - checkRank(player, permissions.level(), permissions.permission()); + checkPermission(player, permissions.permission()); return subCommand.execute(commandSender, player, Arrays.copyOfRange(args, 1, args.length)); } diff --git a/src/main/java/dev/plex/command/sub/ChatSubCommand.java b/src/main/java/dev/plex/command/sub/ChatSubCommand.java index add2e4a..46ee597 100644 --- a/src/main/java/dev/plex/command/sub/ChatSubCommand.java +++ b/src/main/java/dev/plex/command/sub/ChatSubCommand.java @@ -6,8 +6,6 @@ import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; import dev.plex.guild.data.Member; -import dev.plex.rank.enums.Rank; -import dev.plex.util.PlexLog; import net.kyori.adventure.text.Component; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; @@ -20,7 +18,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Objects; @CommandParameters(name = "chat", usage = "/guild [message]", description = "Toggles guild chat or sends a guild chat message") -@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.chat") +@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.chat") public class ChatSubCommand extends PlexCommand { public ChatSubCommand() diff --git a/src/main/java/dev/plex/command/sub/CreateSubCommand.java b/src/main/java/dev/plex/command/sub/CreateSubCommand.java index 7a97a85..a11cac0 100644 --- a/src/main/java/dev/plex/command/sub/CreateSubCommand.java +++ b/src/main/java/dev/plex/command/sub/CreateSubCommand.java @@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; import dev.plex.guild.Guild; -import dev.plex.rank.enums.Rank; import net.kyori.adventure.text.Component; import org.apache.commons.lang3.StringUtils; import org.bukkit.command.CommandSender; @@ -15,13 +14,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @CommandParameters(name = "create", aliases = "make", usage = "/guild ", description = "Creates a guild with a specified name") -@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.create") +@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.create") public class CreateSubCommand extends PlexCommand { public CreateSubCommand() { super(false); } + @Override protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args) { @@ -34,7 +34,8 @@ public class CreateSubCommand extends PlexCommand { return messageComponent("alreadyInGuild"); } - Guilds.get().getSqlGuildManager().insertGuild(Guild.create(player, StringUtils.join(args, " "))).whenComplete((guild, throwable) -> { + Guilds.get().getSqlGuildManager().insertGuild(Guild.create(player, StringUtils.join(args, " "))).whenComplete((guild, throwable) -> + { Guilds.get().getGuildHolder().addGuild(guild); send(player, mmString("Created guild named " + guild.getName())); }); diff --git a/src/main/java/dev/plex/command/sub/HomeSubCommand.java b/src/main/java/dev/plex/command/sub/HomeSubCommand.java index 46e8b02..fca8e9f 100644 --- a/src/main/java/dev/plex/command/sub/HomeSubCommand.java +++ b/src/main/java/dev/plex/command/sub/HomeSubCommand.java @@ -5,27 +5,27 @@ import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; -import dev.plex.rank.enums.Rank; import net.kyori.adventure.text.Component; -import org.apache.commons.lang3.StringUtils; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @CommandParameters(name = "home", aliases = "spawn", usage = "/guild ", description = "Teleports to the guild home") -@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.home") +@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.home") public class HomeSubCommand extends PlexCommand { public HomeSubCommand() { super(false); } + @Override protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args) { assert player != null; - Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> { + Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> + { if (guild.getHome() == null) { send(player, messageComponent("guildHomeNotFound")); diff --git a/src/main/java/dev/plex/command/sub/InfoSubCommand.java b/src/main/java/dev/plex/command/sub/InfoSubCommand.java index 95e60b9..50c5439 100644 --- a/src/main/java/dev/plex/command/sub/InfoSubCommand.java +++ b/src/main/java/dev/plex/command/sub/InfoSubCommand.java @@ -6,7 +6,6 @@ import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; -import dev.plex.rank.enums.Rank; import net.kyori.adventure.text.Component; import org.apache.commons.lang3.StringUtils; import org.bukkit.command.CommandSender; @@ -17,10 +16,9 @@ import org.jetbrains.annotations.Nullable; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; @CommandParameters(name = "info", aliases = "information", usage = "/guild ", description = "Shows the guild's information") -@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.info") +@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.info") public class InfoSubCommand extends PlexCommand { public InfoSubCommand() @@ -43,7 +41,8 @@ public class InfoSubCommand extends PlexCommand try { send(player, mmString("Owner: " + DataUtils.getPlayer(guild.getOwner().getUuid(), false).getName())); - } catch (NullPointerException e) + } + catch (NullPointerException e) { send(player, mmString("Owner: Unable to load cache...")); } diff --git a/src/main/java/dev/plex/command/sub/InviteSubCommand.java b/src/main/java/dev/plex/command/sub/InviteSubCommand.java index 8d2cbf3..c7b5be0 100644 --- a/src/main/java/dev/plex/command/sub/InviteSubCommand.java +++ b/src/main/java/dev/plex/command/sub/InviteSubCommand.java @@ -9,7 +9,6 @@ import dev.plex.command.source.RequiredCommandSource; import dev.plex.guild.Guild; import dev.plex.guild.GuildHolder; import dev.plex.guild.data.Member; -import dev.plex.rank.enums.Rank; import dev.plex.util.PlexLog; import net.kyori.adventure.text.Component; import org.apache.commons.lang3.StringUtils; @@ -27,7 +26,7 @@ import java.util.stream.Collectors; // TODO: 5/9/2022 deny members from inviting themselves or existing members in the current guild @CommandParameters(name = "invite", aliases = "inv", usage = "/guild ", description = "Invites a player to the guild") -@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.invite") +@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.invite") public class InviteSubCommand extends PlexCommand { public InviteSubCommand() @@ -68,7 +67,8 @@ public class InviteSubCommand extends PlexCommand send(player, messageComponent("guildDisbandNeeded")); continueCheck.set(false); return; - } else + } + else { Guilds.get().getSqlGuildManager().deleteGuild(guild1.getGuildUuid()).whenComplete((unused, throwable) -> { @@ -118,8 +118,14 @@ public class InviteSubCommand extends PlexCommand @Override public @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException { - if (!(sender instanceof Player player)) return ImmutableList.of(); - if (args.length == 0) return ImmutableList.of(); + if (!(sender instanceof Player player)) + { + return ImmutableList.of(); + } + if (args.length == 0) + { + return ImmutableList.of(); + } if (args[0].equalsIgnoreCase("accept") && args.length == 2) { if (!GuildHolder.PENDING_INVITES.containsKey(player.getUniqueId())) diff --git a/src/main/java/dev/plex/command/sub/OwnerSubCommand.java b/src/main/java/dev/plex/command/sub/OwnerSubCommand.java index 61e1e43..598bd70 100644 --- a/src/main/java/dev/plex/command/sub/OwnerSubCommand.java +++ b/src/main/java/dev/plex/command/sub/OwnerSubCommand.java @@ -8,7 +8,6 @@ import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; import dev.plex.guild.data.Member; import dev.plex.player.PlexPlayer; -import dev.plex.rank.enums.Rank; import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,7 +15,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @CommandParameters(name = "owner", aliases = "setowner", usage = "/guild ", description = "Sets the guild owner") -@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.owner") +@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.owner") public class OwnerSubCommand extends PlexCommand { public OwnerSubCommand() diff --git a/src/main/java/dev/plex/command/sub/PrefixSubCommand.java b/src/main/java/dev/plex/command/sub/PrefixSubCommand.java index f8fca25..e139878 100644 --- a/src/main/java/dev/plex/command/sub/PrefixSubCommand.java +++ b/src/main/java/dev/plex/command/sub/PrefixSubCommand.java @@ -5,14 +5,8 @@ import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; -import dev.plex.guild.Guild; -import dev.plex.rank.enums.Rank; -import dev.plex.util.PlexUtils; import dev.plex.util.minimessage.SafeMiniMessage; import net.kyori.adventure.text.Component; -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 org.apache.commons.lang3.StringUtils; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -20,13 +14,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @CommandParameters(name = "prefix", aliases = "tag,settag,setprefix", usage = "/guild ", description = "Sets the guild's default prefix") -@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.prefix") +@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.prefix") public class PrefixSubCommand extends PlexCommand { public PrefixSubCommand() { super(false); } + @Override protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args) { @@ -35,7 +30,8 @@ public class PrefixSubCommand extends PlexCommand return usage(); } assert player != null; - Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> { + Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> + { if (!guild.getOwner().getUuid().equals(player.getUniqueId())) { send(player, messageComponent("guildNotOwner")); diff --git a/src/main/java/dev/plex/command/sub/SetHomeSubCommand.java b/src/main/java/dev/plex/command/sub/SetHomeSubCommand.java index fdd3432..0fff11b 100644 --- a/src/main/java/dev/plex/command/sub/SetHomeSubCommand.java +++ b/src/main/java/dev/plex/command/sub/SetHomeSubCommand.java @@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; -import dev.plex.rank.enums.Rank; import dev.plex.util.CustomLocation; import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; @@ -14,10 +13,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @CommandParameters(name = "sethome", aliases = "setspawn", usage = "/guild ", description = "Sets the guild's home") -@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.sethome") +@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.sethome") public class SetHomeSubCommand extends PlexCommand { - public SetHomeSubCommand() { super(false); diff --git a/src/main/java/dev/plex/command/sub/SetWarpSubCommand.java b/src/main/java/dev/plex/command/sub/SetWarpSubCommand.java index d913db6..39b89ea 100644 --- a/src/main/java/dev/plex/command/sub/SetWarpSubCommand.java +++ b/src/main/java/dev/plex/command/sub/SetWarpSubCommand.java @@ -5,9 +5,7 @@ import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; -import dev.plex.rank.enums.Rank; import dev.plex.util.CustomLocation; -import dev.plex.util.minimessage.SafeMiniMessage; import net.kyori.adventure.text.Component; import org.apache.commons.lang3.StringUtils; import org.bukkit.command.CommandSender; @@ -16,17 +14,16 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Locale; -import java.util.regex.Pattern; @CommandParameters(name = "setwarp", aliases = "makewarp,createwarp", usage = "/guild ", description = "Creates a new warp at player's location with a specified name") -@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.setwarp") +@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.setwarp") public class SetWarpSubCommand extends PlexCommand { - public SetWarpSubCommand() { super(false); } + @Override protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args) { @@ -35,7 +32,8 @@ public class SetWarpSubCommand extends PlexCommand return usage(); } assert player != null; - Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> { + Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> + { if (!guild.getOwner().getUuid().equals(player.getUniqueId())) { send(player, messageComponent("guildNotOwner")); diff --git a/src/main/java/dev/plex/command/sub/WarpListSubCommand.java b/src/main/java/dev/plex/command/sub/WarpListSubCommand.java index 1cdb6b5..ba54903 100644 --- a/src/main/java/dev/plex/command/sub/WarpListSubCommand.java +++ b/src/main/java/dev/plex/command/sub/WarpListSubCommand.java @@ -7,10 +7,7 @@ import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; import dev.plex.guild.Guild; -import dev.plex.rank.enums.Rank; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.minimessage.MiniMessage; -import org.apache.commons.lang3.StringUtils; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -20,7 +17,7 @@ import java.util.List; import java.util.Set; @CommandParameters(name = "warps", aliases = "listwarps", usage = "/guild ", description = "Displays a clickable list of warps") -@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warps") +@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warps") public class WarpListSubCommand extends PlexCommand { public WarpListSubCommand() diff --git a/src/main/java/dev/plex/command/sub/WarpSubCommand.java b/src/main/java/dev/plex/command/sub/WarpSubCommand.java index 36e6809..c206785 100644 --- a/src/main/java/dev/plex/command/sub/WarpSubCommand.java +++ b/src/main/java/dev/plex/command/sub/WarpSubCommand.java @@ -5,8 +5,6 @@ import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; -import dev.plex.rank.enums.Rank; -import dev.plex.util.CustomLocation; import net.kyori.adventure.text.Component; import org.apache.commons.lang3.StringUtils; import org.bukkit.command.CommandSender; @@ -15,13 +13,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @CommandParameters(name = "warp", aliases = "goto", usage = "/guild ", description = "Warps to a specified guild warp") -@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warp") +@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warp") public class WarpSubCommand extends PlexCommand { public WarpSubCommand() { super(false); } + @Override protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args) { @@ -30,7 +29,8 @@ public class WarpSubCommand extends PlexCommand return usage(); } assert player != null; - Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> { + Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> + { String warpName = StringUtils.join(args, " "); if (!guild.getWarps().containsKey(warpName.toLowerCase())) { diff --git a/src/main/java/dev/plex/data/SQLGuildManager.java b/src/main/java/dev/plex/data/SQLGuildManager.java index fc9f672..ae8ae44 100644 --- a/src/main/java/dev/plex/data/SQLGuildManager.java +++ b/src/main/java/dev/plex/data/SQLGuildManager.java @@ -55,7 +55,8 @@ public class SQLGuildManager statement.setBoolean(14, guild.isPublic()); statement.execute(); return guild; - } catch (SQLException e) + } + catch (SQLException e) { GuildUtil.throwExceptionSync(e); return null; @@ -72,7 +73,8 @@ public class SQLGuildManager PreparedStatement statement = connection.prepareStatement(DELETE_GUILD); statement.setString(1, uuid.toString()); statement.execute(); - } catch (SQLException e) + } + catch (SQLException e) { GuildUtil.throwExceptionSync(e); } @@ -101,7 +103,8 @@ public class SQLGuildManager statement.setString(13, guild.getGuildUuid().toString()); statement.executeUpdate(); return guild; - } catch (SQLException e) + } + catch (SQLException e) { GuildUtil.throwExceptionSync(e); return null; @@ -143,7 +146,8 @@ public class SQLGuildManager guild.setPublic(set.getBoolean("isPublic")); guilds.add(guild); } - } catch (SQLException e) + } + catch (SQLException e) { GuildUtil.throwExceptionSync(e); } diff --git a/src/main/java/dev/plex/data/SQLManager.java b/src/main/java/dev/plex/data/SQLManager.java index 005ae34..f932b4b 100644 --- a/src/main/java/dev/plex/data/SQLManager.java +++ b/src/main/java/dev/plex/data/SQLManager.java @@ -1,7 +1,6 @@ package dev.plex.data; import dev.plex.Plex; -import dev.plex.storage.StorageType; import java.sql.Connection; import java.sql.SQLException; @@ -10,11 +9,6 @@ public class SQLManager { public static void makeTables() { - if (Plex.get().getStorageType() == StorageType.MONGODB) - { - return; - } - try (Connection connection = Plex.get().getSqlConnection().getCon()) { connection.prepareStatement( @@ -36,10 +30,10 @@ public class SQLManager "PRIMARY KEY (`guildUuid`)" + ");" ).execute(); - } catch (SQLException e) + } + catch (SQLException e) { e.printStackTrace(); } } - } diff --git a/src/main/java/dev/plex/guild/Guild.java b/src/main/java/dev/plex/guild/Guild.java index 84e77aa..a1a7f64 100644 --- a/src/main/java/dev/plex/guild/Guild.java +++ b/src/main/java/dev/plex/guild/Guild.java @@ -2,8 +2,6 @@ package dev.plex.guild; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import dev.morphia.annotations.Entity; -import dev.morphia.annotations.Transient; import dev.plex.Plex; import dev.plex.guild.data.Member; import dev.plex.guild.data.Rank; @@ -15,10 +13,11 @@ import org.bukkit.entity.Player; import java.time.ZoneId; import java.time.ZonedDateTime; -import java.util.*; +import java.util.List; +import java.util.Map; +import java.util.UUID; @Data -@Entity("guilds") public class Guild { private final UUID guildUuid; diff --git a/src/main/java/dev/plex/guild/GuildHolder.java b/src/main/java/dev/plex/guild/GuildHolder.java index 8bb8c93..094b7fe 100644 --- a/src/main/java/dev/plex/guild/GuildHolder.java +++ b/src/main/java/dev/plex/guild/GuildHolder.java @@ -20,7 +20,9 @@ public class GuildHolder if (PENDING_INVITES.containsKey(uuid)) { PENDING_INVITES.get(uuid).add(guild); - } else { + } + else + { PENDING_INVITES.put(uuid, Lists.newArrayList(guild)); } return true; @@ -38,7 +40,7 @@ public class GuildHolder public Optional getGuild(UUID uuid) { - return GUILDS.stream().filter(guild -> (guild.getOwner() != null && guild.getOwner().getUuid().equals(uuid)) || guild.getMembers().stream().map(Member::getUuid).toList().contains(uuid)).findFirst(); + return GUILDS.stream().filter(guild -> (guild.getOwner() != null && guild.getOwner().getUuid().equals(uuid)) || guild.getMembers().stream().map(Member::getUuid).toList().contains(uuid)).findFirst(); } public Collection getGuilds() diff --git a/src/main/java/dev/plex/handler/ChatHandlerImpl.java b/src/main/java/dev/plex/handler/ChatHandlerImpl.java index aa2034d..4808304 100644 --- a/src/main/java/dev/plex/handler/ChatHandlerImpl.java +++ b/src/main/java/dev/plex/handler/ChatHandlerImpl.java @@ -3,14 +3,12 @@ package dev.plex.handler; import dev.plex.Guilds; import dev.plex.Plex; 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 java.util.Objects; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextReplacementConfig; @@ -25,6 +23,10 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.jetbrains.annotations.NotNull; +import java.util.Objects; +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(); @@ -66,7 +68,7 @@ public class ChatHandlerImpl String text = PlexUtils.getTextFromComponent(message); PlexPlayer plexPlayer = Plex.get().getPlayerCache().getPlexPlayerMap().get(source.getUniqueId()); - Component prefix = Plex.get().getRankManager().getPrefix(plexPlayer); + Component prefix = VaultHook.getPrefix(plexPlayer); AtomicBoolean guildPrefix = new AtomicBoolean(false); AtomicReference component = new AtomicReference<>(Component.empty()); diff --git a/src/main/java/dev/plex/util/CustomLocation.java b/src/main/java/dev/plex/util/CustomLocation.java index 0932242..707b660 100644 --- a/src/main/java/dev/plex/util/CustomLocation.java +++ b/src/main/java/dev/plex/util/CustomLocation.java @@ -10,6 +10,7 @@ public class CustomLocation private final String worldName; private final double x, y, z; private final float yaw, pitch; + public static CustomLocation fromLocation(Location location) { return new CustomLocation(location.getWorld().getName(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); diff --git a/src/main/resources/module.yml b/src/main/resources/module.yml index eb389c6..2d0c7e0 100644 --- a/src/main/resources/module.yml +++ b/src/main/resources/module.yml @@ -1,4 +1,4 @@ name: Module-Guilds main: dev.plex.Guilds description: The guilds module for Plex -version: 1.3 \ No newline at end of file +version: 1.4-SNAPSHOT \ No newline at end of file