Skip to content

Commit

Permalink
meet code standards
Browse files Browse the repository at this point in the history
  • Loading branch information
Shweit committed Aug 30, 2024
1 parent a82b8d6 commit 765301d
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/shweit/serverapi/MinecraftServerAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public final void onEnable() {

new RegisterEndpoints(server).registerEndpoints();

RegisterWebHooks.registerWebHooks(config);
new RegisterWebHooks().registerWebHooks(config);

new RegisterCommands(this).register();

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/shweit/serverapi/commands/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
import java.util.ArrayList;
import java.util.List;

public class CommandManager implements TabExecutor {
public final class CommandManager implements TabExecutor {

private ArrayList<SubCommand> subcommands = new ArrayList<>();
private final ArrayList<SubCommand> subcommands = new ArrayList<>();

public CommandManager(List<SubCommand> subcommands){
this.subcommands.addAll(subcommands);
public CommandManager(final List<SubCommand> subCommandList) {
this.subcommands.addAll(subCommandList);
}

public ArrayList<SubCommand> getSubCommands(){
public ArrayList<SubCommand> getSubCommands() {
return subcommands;
}

@Override
public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
public boolean onCommand(final CommandSender commandSender, final Command command, final String label, final String[] args) {
if (args.length > 0) {
for (int i = 0; i < getSubCommands().size(); i++){
if (args[0].equalsIgnoreCase(getSubCommands().get(i).getName())){
for (int i = 0; i < getSubCommands().size(); i++) {
if (args[0].equalsIgnoreCase(getSubCommands().get(i).getName())) {
getSubCommands().get(i).perform(commandSender, command, label, args);
}
}
Expand All @@ -34,13 +34,13 @@ public boolean onCommand(CommandSender commandSender, Command command, String la
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
public List<String> onTabComplete(final CommandSender sender, final Command command, final String alias, final String[] args) {
if (args.length == 1) {
List<String> subcommands = new ArrayList<>();
List<String> subcommandsList = new ArrayList<>();
for (SubCommand subCommand : getSubCommands()) {
subcommands.add(subCommand.getName());
subcommandsList.add(subCommand.getName());
}
return subcommands;
return subcommandsList;
} else if (args.length > 1) {
for (SubCommand subCommand : getSubCommands()) {
if (args[0].equalsIgnoreCase(subCommand.getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import com.shweit.serverapi.commands.webHook.DisableWebHookCommand;
import com.shweit.serverapi.commands.webHook.EnableWebHookCommand;
import com.shweit.serverapi.commands.webHook.ListWebHook;
import com.shweit.serverapi.utils.Logger;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.List;

public class RegisterCommands {
public final class RegisterCommands {
private JavaPlugin plugin;

public RegisterCommands(JavaPlugin plugin) {
this.plugin = plugin;
public RegisterCommands(final JavaPlugin javaPlugin) {
this.plugin = javaPlugin;
}

public void register() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

import java.util.Collections;
import java.util.List;

public class DisableWebHookCommand extends SubCommand {
public final class DisableWebHookCommand extends SubCommand {
@Override
public String getName() {
return "disable";
Expand All @@ -27,7 +26,7 @@ public String getSyntax() {
}

@Override
public void perform(CommandSender commandSender, Command command, String label, String[] args) {
public void perform(final CommandSender commandSender, final Command command, final String label, final String[] args) {
// Check the length of the arguments
if (args.length != 2) {
commandSender.sendMessage(ChatColor.RED + "Usage: /webhooks disable <webhook>");
Expand All @@ -49,7 +48,7 @@ public void perform(CommandSender commandSender, Command command, String label,
}

@Override
public List<String> getSubcommandArguments(CommandSender commandSender, Command command, String label, String[] args) {
public List<String> getSubcommandArguments(final CommandSender commandSender, final Command command, final String label, final String[] args) {
if (args.length == 2) {
return WebHookEnum.getValidHookList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

import java.util.Collections;
import java.util.List;

public class EnableWebHookCommand extends SubCommand {
public final class EnableWebHookCommand extends SubCommand {
@Override
public String getName() {
return "enable";
Expand All @@ -27,7 +26,7 @@ public String getSyntax() {
}

@Override
public void perform(CommandSender commandSender, Command command, String label, String[] args) {
public void perform(final CommandSender commandSender, final Command command, final String label, final String[] args) {
// Check the length of the arguments
if (args.length != 2) {
commandSender.sendMessage(ChatColor.RED + "Usage: /webhooks enable <webhook>");
Expand All @@ -49,7 +48,7 @@ public void perform(CommandSender commandSender, Command command, String label,
}

@Override
public List<String> getSubcommandArguments(CommandSender commandSender, Command command, String label, String[] args) {
public List<String> getSubcommandArguments(final CommandSender commandSender, final Command command, final String label, final String[] args) {
if (args.length == 2) {
return WebHookEnum.getValidHookList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.ArrayList;
import java.util.List;

public class ListWebHook extends SubCommand {
public final class ListWebHook extends SubCommand {
private static final int ENTRIES_PER_PAGE = 10;

@Override
Expand All @@ -29,7 +29,7 @@ public String getSyntax() {
}

@Override
public void perform(CommandSender commandSender, Command command, String label, String[] args) {
public void perform(final CommandSender commandSender, final Command command, final String label, final String[] args) {
int page = 1;

if (args.length == 2) {
Expand All @@ -48,7 +48,11 @@ public void perform(CommandSender commandSender, Command command, String label,
return;
}

commandSender.sendMessage(ChatColor.GRAY + "--------------------[" + ChatColor.LIGHT_PURPLE + " WebHooks - Page " + page + "/" + totalPages + ChatColor.GRAY + " ]--------------------");
commandSender.sendMessage(
ChatColor.GRAY + "--------------------["
+ ChatColor.LIGHT_PURPLE + " WebHooks - Page " + page + "/" + totalPages + ChatColor.GRAY
+ " ]--------------------"
);
commandSender.sendMessage("");
commandSender.sendMessage(ChatColor.WHITE + "Registered WebHooks (" + WebHookEnum.values().length + "):");
commandSender.sendMessage("");
Expand All @@ -64,11 +68,15 @@ public void perform(CommandSender commandSender, Command command, String label,
}

commandSender.sendMessage("");
commandSender.sendMessage(ChatColor.GRAY + "--------------------[" + ChatColor.LIGHT_PURPLE + " Page " + page + " of " + totalPages + ChatColor.GRAY + " ]--------------------");
commandSender.sendMessage(
ChatColor.GRAY + "--------------------["
+ ChatColor.LIGHT_PURPLE + " Page " + page + " of " + totalPages + ChatColor.GRAY
+ " ]--------------------"
);
}

@Override
public List<String> getSubcommandArguments(CommandSender commandSender, Command command, String label, String[] args) {
public List<String> getSubcommandArguments(final CommandSender commandSender, final Command command, final String label, final String[] args) {
// Calculate the number of pages
int totalPages = (int) Math.ceil((double) WebHookEnum.values().length / ENTRIES_PER_PAGE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import java.net.URL;
import java.util.List;

public class RegisterWebHooks {
public final class RegisterWebHooks {
private static List<String> urls;
private static FileConfiguration configuration;

public static void registerWebHooks(FileConfiguration config) {
public void registerWebHooks(final FileConfiguration config) {

urls = config.getStringList("webhooks.urls");
configuration = config;
Expand All @@ -39,7 +39,7 @@ public static void registerWebHooks(FileConfiguration config) {
Logger.debug("Registered plugin_enable WebHook");
}

public static void sendToAllUrls(JSONObject jsonObject) {
public static void sendToAllUrls(final JSONObject jsonObject) {
if (urls == null || urls.isEmpty()) {
Logger.warning("No WebHook URL's found in config.yml");
return;
Expand Down Expand Up @@ -70,7 +70,7 @@ public static void sendToAllUrls(JSONObject jsonObject) {
}
}

public static boolean doActivateWebhook(String eventName) {
public static boolean doActivateWebhook(final String eventName) {
String eventPath = "webhooks." + eventName;

return configuration.getBoolean(eventPath, true);
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/com/shweit/serverapi/webhooks/WebHookEnum.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.shweit.serverapi.webhooks;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public enum WebHookEnum {
SERVER_START("server_start", "Triggered when the server starts"),
SERVER_STOP("server_stop", "Triggered when the server stops"),
PLUGIN_DISABLE("plugin_disable", "Triggered when a plugin is disabled"),
PLUGIN_ENABLE("plugin_enable", "Triggered when a plugin is enabled"),
;
PLUGIN_ENABLE("plugin_enable", "Triggered when a plugin is enabled"),;

public final String label;
public final String description;

private WebHookEnum(String label, String description) {
this.label = label;
this.description = description;
WebHookEnum(final String enumLabel, final String enumDescription) {
this.label = enumLabel;
this.description = enumDescription;
}

public String getLabel() {
Expand All @@ -27,7 +25,7 @@ public String getDescription() {
return description;
}

public static boolean isValid(String webhookName) {
public static boolean isValid(final String webhookName) {
for (WebHookEnum hook : values()) {
if (hook.label.equalsIgnoreCase(webhookName)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.bukkit.event.server.PluginDisableEvent;
import org.json.JSONObject;

public class PluginDisable implements WebHook, Listener {
public final class PluginDisable implements WebHook, Listener {

private final String eventName = WebHookEnum.PLUGIN_DISABLE.label;

Expand All @@ -22,7 +22,7 @@ public void register() {
}

@EventHandler
public void onPluginDisable(PluginDisableEvent event) {
public void onPluginDisable(final PluginDisableEvent event) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("event", eventName);
jsonObject.put("plugin_name", event.getPlugin().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.bukkit.event.server.PluginEnableEvent;
import org.json.JSONObject;

public class PluginEnable implements WebHook, Listener {
public final class PluginEnable implements WebHook, Listener {

private final String eventName = WebHookEnum.PLUGIN_ENABLE.label;

Expand All @@ -22,7 +22,7 @@ public void register() {
}

@EventHandler
public void onPluginEnable(PluginEnableEvent event) {
public void onPluginEnable(final PluginEnableEvent event) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("event", eventName);
jsonObject.put("plugin_name", event.getPlugin().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.bukkit.event.server.ServerLoadEvent;
import org.json.JSONObject;

public class ServerStart implements WebHook, Listener {
public final class ServerStart implements WebHook, Listener {

private final String eventName = WebHookEnum.SERVER_START.label;

Expand All @@ -22,7 +22,7 @@ public void register() {
}

@EventHandler
public void onServerLoad(ServerLoadEvent event) {
public void onServerLoad(final ServerLoadEvent event) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("event", eventName);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.shweit.serverapi.webhooks.server;

import com.shweit.serverapi.MinecraftServerAPI;
import com.shweit.serverapi.webhooks.WebHook;
import com.shweit.serverapi.webhooks.RegisterWebHooks;
import com.shweit.serverapi.webhooks.WebHookEnum;
import org.json.JSONObject;

public class ServerStop implements WebHook {
public final class ServerStop implements WebHook {

private final String eventName = WebHookEnum.SERVER_STOP.label;

Expand Down

0 comments on commit 765301d

Please sign in to comment.