Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check subcommand and new permission #37

Merged
merged 11 commits into from
Oct 16, 2023
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "com.armamc"
version = "1.1.1"
version = "1.2.0-SNAPSHOT"

repositories {
mavenCentral()
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.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
8 changes: 6 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https:/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -130,10 +131,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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.armamc.plugincontrol.PluginControl;
import com.armamc.plugincontrol.commands.subcommands.ActionSubCommand;
import com.armamc.plugincontrol.commands.subcommands.AddSubCommand;
import com.armamc.plugincontrol.commands.subcommands.CheckSubCommand;
import com.armamc.plugincontrol.commands.subcommands.DisableSubCommand;
import com.armamc.plugincontrol.commands.subcommands.EnableSubCommand;
import com.armamc.plugincontrol.commands.subcommands.GroupSubCommand;
Expand Down Expand Up @@ -34,6 +35,7 @@ public MainCommand(@NotNull PluginControl plugin) {
this.message = plugin.getMessageManager();
subCommands.put("enable", new EnableSubCommand(plugin));
subCommands.put("disable", new DisableSubCommand(plugin));
subCommands.put("check", new CheckSubCommand(plugin));
subCommands.put("toggle", new ToggleSubCommand(plugin));
subCommands.put("add", new AddSubCommand(plugin));
subCommands.put("remove", new RemoveSubCommand(plugin));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.armamc.plugincontrol.commands.subcommands;

import com.armamc.plugincontrol.PluginControl;
import com.armamc.plugincontrol.managers.ConfigManager;
import com.armamc.plugincontrol.managers.MessageManager;
import com.armamc.plugincontrol.managers.PluginsManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class CheckSubCommand implements SubCommand {
private final ConfigManager config;
private final MessageManager message;
private final PluginsManager manager;

@Contract(pure = true)
public CheckSubCommand(@NotNull PluginControl plugin) {
this.config = plugin.getConfigManager();
this.message = plugin.getMessageManager();
this.manager = plugin.getPluginsManager();
}

@Override
public void execute(CommandSender sender, Command command, String label, String @NotNull [] args) {
if (config.isEnabled()) {
message.send(sender, message.getCheckingPlugins());
manager.checkPlugins();
} else {
message.send(sender, message.getCheckingDisabled());
}
}

@Override
public List<String> tabComplete(CommandSender sender, Command command, String label, String[] args) {
return List.of();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ public void send(@NotNull CommandSender sender, @NotNull List<String> message, @
}
}

public void send(@NotNull String message, @NotNull TagResolver... tags) {
if (message.isEmpty() || message.isBlank()) return;
List<TagResolver> allTags = new ArrayList<>();
allTags.add(getPrefix());
allTags.addAll(List.of(tags));
var component = MM.deserialize(message, allTags.toArray(new TagResolver[0]));
plugin.adventure().sender(Bukkit.getConsoleSender()).sendMessage(component);
for (var player : Bukkit.getOnlinePlayers()) {
if (!player.hasPermission("plugincontrol.notify")) continue;
plugin.adventure().sender(player).sendMessage(component);
}
}

public @NotNull Component getPluginListComponent(@NotNull Set<String> pluginList) {
var joinConfiguration = JoinConfiguration.separators(
MM.deserialize(getPluginListSeparator()),
Expand Down Expand Up @@ -290,6 +303,10 @@ public String getCheckingMessage() {
return lang.getString("console.checking-plugins");
}

public String getCheckingDisabled() {
return lang.getString("console.plugin-disabled");
}

public String getCheckFinished() {
return lang.getString("console.finished-checking");
}
Expand Down Expand Up @@ -409,4 +426,8 @@ public String getGroupClickRemovePlugin() {
public String getGroupClickInfo() {
return lang.getString("command.group-click-info");
}

public String getCheckingPlugins() {
return lang.getString("command.checking-plugins");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class PluginsManager {
private final ConfigManager config;
private final MessageManager message;
private PlayerListener playerListener;
private final ConsoleCommandSender console = Bukkit.getConsoleSender();

public PluginsManager(@NotNull PluginControl plugin) {
this.plugin = plugin;
Expand All @@ -26,9 +25,12 @@ public PluginsManager(@NotNull PluginControl plugin) {
}

public void checkPlugins() {
if (!config.isEnabled()) return;
if (!config.isEnabled()) {
message.send(message.getCheckingDisabled());
return;
}

message.send(console, message.getCheckingMessage());
message.send(message.getCheckingMessage());

var missingPlugins = new HashSet<String>();
for (var pluginName : config.getPluginList()) {
Expand Down Expand Up @@ -57,7 +59,7 @@ public void checkPlugins() {
if (!missingPlugins.isEmpty() || !missingGroups.isEmpty()) {
registerAction(missingPlugins, missingGroups);
} else {
message.send(console, message.getCheckFinished());
message.send(message.getCheckFinished());
}
}

Expand Down Expand Up @@ -91,19 +93,19 @@ private void handleDisallowPlayerLogin(TagResolver.Single pluginTag, TagResolver

private void shutdownServer(TagResolver.Single pluginTag, TagResolver.Single groupTag) {
logToConsole(pluginTag, groupTag);
message.send(console, message.getDisablingServer());
message.send(message.getDisablingServer());
plugin.getServer().shutdown();
}

private void logToConsole(TagResolver.Single pluginTag, TagResolver.Single groupTag) {
if (pluginTag != null) {
message.send(console, message.getLogToConsolePlugin(), pluginTag);
message.send(message.getLogToConsolePlugin(), pluginTag);
}
if (groupTag != null) {
message.send(console, message.getLogToConsoleGroup(), groupTag);
message.send(message.getLogToConsoleGroup(), groupTag);
}

message.send(console, message.getCheckFinished());
message.send(message.getCheckFinished());
}

public void unregisterListener() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ console:
finished-checking: '<prefix> <green>Plugins verified!'
log-to-console-plugin: '<prefix> <red>Required plugins were not found: <plugins>'
log-to-console-group: '<prefix> <red>Required groups were not found: <groups>'
plugin-disabled: '<prefix> <red>Plugin Control is disabled!'
command:
action-list: '<prefix> <green>Actions available: <yellow><actions>'
action-set: '<prefix> <green>Action set to <yellow><action>'
action-type: '<prefix> <green>Action type: <yellow><action>'
checking-plugins: '<prefix> <green>Checking plugins... See the console for more information.'
command-not-found: '<red>Usage: <yellow>/<command> help <red>to see the available commands'
kick-message: '<prefix> <green>Kick message: <yellow><kick-message>'
kick-message-set: '<prefix> <green>Kick message set to <yellow><kick-message>'
Expand Down
14 changes: 9 additions & 5 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '${version}'
main: com.armamc.plugincontrol.PluginControl
api-version: '1.13'
authors: [ ThiagoROX ]
description: Plugin to check if all important plugins have been successfully loaded.
description: This minecraft plugin allows you to define which plugin has to be successfully enabled after server startup.
website: https:/SrBedrock/PluginControl
libraries:
- "net.kyori:adventure-api:4.14.0"
Expand All @@ -14,14 +14,18 @@ libraries:
commands:
plugincontrol:
description: "Command to manage PluginControl"
usage: "/<command> <add|remove|group|action|kick-message|toggle|enable|disable|list|reload|help>"
aliases: [pc, plcontrol]
usage: "/<command> <add|remove|check|group|action|kick-message|toggle|enable|disable|list|reload|help>"
aliases: [ pc, plcontrol ]
permission: plugincontrol.use
permission-message: "You do not have permission to use this command"

permissions:
plugincontrol.use:
description: "Allow to use PluginControl commands"
description: "Allow using PluginControl commands"
default: op
children:
- plugincontrol.notify
plugincontrol.notify:
description: "Allow seeing the notification when a plugin is not loaded or enabled"
default: op
plugincontrol.bypass:
description: "Bypass block when a plugin is not loaded or enabled"
Expand Down