Skip to content

Commit

Permalink
Compatibility with newer versions of Plex
Browse files Browse the repository at this point in the history
  • Loading branch information
Telesphoreo committed Sep 8, 2023
1 parent 3929141 commit c1d1be2
Show file tree
Hide file tree
Showing 27 changed files with 109 additions and 138 deletions.
35 changes: 3 additions & 32 deletions .idea/codeStyles/Plexus_Code_Style.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -43,7 +42,7 @@ publishing {
}

tasks.getByName<Jar>("jar") {
archiveBaseName.set("Plex-Guilds")
archiveBaseName.set("Module-Guilds")
archiveVersion.set("")
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
12 changes: 8 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
25 changes: 7 additions & 18 deletions src/main/java/dev/plex/Guilds.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
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
{
Expand All @@ -33,22 +30,14 @@ public void load()
@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());

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/dev/plex/command/GuildCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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;
Expand All @@ -22,7 +21,7 @@
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<PlexCommand> subCommands = Lists.newArrayList();
Expand All @@ -42,7 +41,8 @@ public GuildCommand()
this.registerSubCommand(new HomeSubCommand());
this.registerSubCommand(new OwnerSubCommand());
this.registerSubCommand(new InviteSubCommand());
} catch (Exception e)
}
catch (Exception e)
{
GuildUtil.throwExceptionSync(e);
}
Expand Down Expand Up @@ -71,7 +71,6 @@ protected Component execute(@NotNull CommandSender commandSender, @Nullable Play
.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>Permission: <yellow>" + permissions.permission())).append(Component.newline())
.append(mmString("<gold>Required Rank: <yellow>" + permissions.level().name())).append(Component.newline())
.append(mmString("<gold>Required Source: <yellow>" + permissions.source().name()));
}
PlexCommand subCommand = getSubCommand(args[0]);
Expand All @@ -91,7 +90,7 @@ protected Component execute(@NotNull CommandSender commandSender, @Nullable Play
return messageComponent("noPermissionConsole");
}

checkRank(player, permissions.level(), permissions.permission());
checkPermission(player, permissions.permission());

return subCommand.execute(commandSender, player, Arrays.copyOfRange(args, 1, args.length));
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/dev/plex/command/sub/ChatSubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
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;
Expand All @@ -20,7 +18,7 @@
import java.util.Objects;

@CommandParameters(name = "chat", usage = "/guild <command> [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()
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/dev/plex/command/sub/CreateSubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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;
Expand All @@ -15,13 +14,14 @@
import org.jetbrains.annotations.Nullable;

@CommandParameters(name = "create", aliases = "make", usage = "/guild <command> <name>", 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)
{
Expand All @@ -34,7 +34,8 @@ protected Component execute(@NotNull CommandSender commandSender, @Nullable Play
{
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()));
});
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/dev/plex/command/sub/HomeSubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
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 <command>", 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"));
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/dev/plex/command/sub/InfoSubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.CommandSender;
Expand All @@ -17,10 +16,9 @@
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 <command>", 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()
Expand All @@ -43,7 +41,8 @@ protected Component execute(@NotNull CommandSender commandSender, @Nullable Play
try
{
send(player, mmString("<gold>Owner: <yellow>" + DataUtils.getPlayer(guild.getOwner().getUuid(), false).getName()));
} catch (NullPointerException e)
}
catch (NullPointerException e)
{
send(player, mmString("<gold>Owner: <yellow>Unable to load cache..."));
}
Expand Down
Loading

0 comments on commit c1d1be2

Please sign in to comment.