Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofpu committed Jun 4, 2023
1 parent 1c88522 commit 7b15908
Show file tree
Hide file tree
Showing 25 changed files with 287 additions and 325 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/artifact-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
java-version: '11'
distribution: 'adopt'

- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ name: Release

on:
release:
types: [published]
types: [ published ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.4.0
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '8'
- name: Build with Gradle
uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7
with:
- uses: actions/checkout@v2.4.0
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '8'
- name: Build with Gradle
uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7
with:
arguments: shadowJar
- name: Upload jar
uses: AButler/upload-release-assets@v2.0
with:
files: ${{ github.workspace }}/build/libs/*.jar
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload jar
uses: AButler/upload-release-assets@v2.0
with:
files: ${{ github.workspace }}/build/libs/*.jar
repo-token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
mavenLocal()
mavenCentral()
// for brigadier
maven("https://libraries.minecraft.net")
maven("https://libraries.minecraft.net")
maven("https://jitpack.io")
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://repo.andrei1058.dev/releases/")
Expand Down Expand Up @@ -63,9 +63,9 @@ dependencies {
//}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract class CommandHandlerBase {
/**
* This method registers the command.
*
* @param plugin The plugin instance
* @param plugin The plugin instance
* @param reloadHandler The reload handler
*/
public abstract void create(final Plugin plugin, final ReloadHandlerBase reloadHandler);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.tofpu.bedwarsswapaddon.model.command;

import io.tofpu.bedwarsswapaddon.model.meta.adventure.AdventureHolder;
import io.tofpu.bedwarsswapaddon.model.command.presenter.HelpPresenterHolder;
import io.tofpu.bedwarsswapaddon.model.configuration.ConfigurationHolder;
import io.tofpu.bedwarsswapaddon.model.configuration.handler.ConfigurationHandler;
import io.tofpu.bedwarsswapaddon.model.meta.adventure.AdventureHolder;
import io.tofpu.bedwarsswapaddon.model.meta.log.LogHandler;
import io.tofpu.bedwarsswapaddon.model.meta.message.MessageHolder;
import io.tofpu.bedwarsswapaddon.model.reload.ReloadHandlerBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
import io.tofpu.messagepresenter.extra.MessagePairPresenter;
import io.tofpu.messagepresenter.extra.MessageTreePresenter;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import revxrsal.commands.annotation.Description;
import revxrsal.commands.annotation.Flag;
import revxrsal.commands.annotation.Optional;
import revxrsal.commands.annotation.Subcommand;
import revxrsal.commands.annotation.Usage;
import revxrsal.commands.annotation.*;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

public class HelpPresenterHolder {
private static HelpPresenterHolder instance;
private static final String TITLE = "<white><bold>%s</bold>";
private static final String KEY_STYLE = "<yellow>%s";
private static final String VALUE_STYLE = "<white>%s";
private static final String COMMAND_STYLE = "<yellow>/swap %s %s<dark_gray>- <white>%s";
private static HelpPresenterHolder instance;
private String result = "";

private HelpPresenterHolder() {
// prevent instantiation
}

public static void generatePresenter(final PluginDescriptionFile description) {
instance = new HelpPresenterHolder();
Expand All @@ -34,10 +33,47 @@ public static HelpPresenterHolder get() {
return instance;
}

private String result = "";
private static String generateUsageOfMethod(final Subcommand subcommand,
final Method method) {
final StringBuilder builder = new StringBuilder();

private HelpPresenterHolder() {
// prevent instantiation
if (method.isAnnotationPresent(Usage.class)) {
return method.getAnnotation(Usage.class).value().replace(subcommand.value()[0] + " ", "") + " ";
}

for (final Parameter parameter : method.getParameters()) {
if (CommandSender.class.isAssignableFrom(parameter.getType())) {
continue;
}

if (builder.length() != 0) {
builder.append(" ");
}

final String name;
switch (parameter.getType().getSimpleName()) {
// add more types here
default:
name = parameter.getName();
}

String startingTag = "<";
String closingTag = ">";
if (parameter.isAnnotationPresent(Optional.class)) {
startingTag = "[";
closingTag = "]";
}

String flag = "";
if (parameter.isAnnotationPresent(Flag.class)) {
final Flag flagAnnotation = parameter.getAnnotation(Flag.class);
flag = "-" + flagAnnotation.value() + " ";
}

builder.append(startingTag).append(flag).append(name).append(closingTag).append(" ");
}

return builder.toString();
}

private void generate(final PluginDescriptionFile description) {
Expand Down Expand Up @@ -82,49 +118,6 @@ private void generate(final PluginDescriptionFile description) {
this.result = holder.getResult();
}

private static String generateUsageOfMethod(final Subcommand subcommand,
final Method method) {
final StringBuilder builder = new StringBuilder();

if (method.isAnnotationPresent(Usage.class)) {
return method.getAnnotation(Usage.class).value().replace(subcommand.value()[0] + " ", "") + " ";
}

for (final Parameter parameter : method.getParameters()) {
if (CommandSender.class.isAssignableFrom(parameter.getType())) {
continue;
}

if (builder.length() != 0) {
builder.append(" ");
}

final String name;
switch (parameter.getType().getSimpleName()) {
// add more types here
default:
name = parameter.getName();
}

String startingTag = "<";
String closingTag = ">";
if (parameter.isAnnotationPresent(Optional.class)) {
startingTag = "[";
closingTag = "]";
}

String flag = "";
if (parameter.isAnnotationPresent(Flag.class)) {
final Flag flagAnnotation = parameter.getAnnotation(Flag.class);
flag = "-" + flagAnnotation.value() + " ";
}

builder.append(startingTag).append(flag).append(name).append(closingTag).append(" ");
}

return builder.toString();
}

public String result() {
return this.result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.tofpu.bedwarsswapaddon.model.configuration;

import io.tofpu.bedwarsswapaddon.model.configuration.handler.ConfigurationHandler;
import io.tofpu.bedwarsswapaddon.model.configuration.section.GeneralSection;
import io.tofpu.bedwarsswapaddon.model.configuration.section.SwapAnnounceSection;
import org.apache.commons.lang.builder.EqualsBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class ConfigurationHandler {
private ConfigurationLoader<?> loader;
private ConfigurationNode node;

private ConfigurationHandler() {}
private ConfigurationHandler() {
}

public static ConfigurationHandler get() {
return INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

public class AdventureHolder {
private static AdventureHolder instance;
private final BukkitAudiences adventure;

public AdventureHolder(final BukkitAudiences adventure) {
this.adventure = adventure;
}

public static AdventureHolder get() {
if (instance == null) {
Expand All @@ -21,12 +26,6 @@ public static void init(final Plugin plugin) {
instance = new AdventureHolder(BukkitAudiences.create(plugin));
}

private final BukkitAudiences adventure;

public AdventureHolder(final BukkitAudiences adventure) {
this.adventure = adventure;
}

public void message(final CommandSender player, final String message) {
message(player, ColorUtil.translate(message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ public class LogHandler {
private ExecutorService executorService;
private boolean debug;

private LogHandler() {
this.executorService = Executors.newSingleThreadExecutor();
this.debug = false;
}

public static LogHandler get() {
if (instance == null) {
throw new IllegalStateException("LogHandler is not initialized");
}
return instance;
}

private LogHandler() {
this.executorService = Executors.newSingleThreadExecutor();
this.debug = false;
public static synchronized void init(final Plugin plugin) {
instance = new LogHandler();
instance.setPlugin(plugin);
}

public void reload() {
init(plugin);
}

public static synchronized void init(final Plugin plugin) {
instance = new LogHandler();
instance.setPlugin(plugin);
}

public void load() {
instance.setDebug(ConfigurationHandler.get()
.getSettingsHolder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,32 @@
public class MessageHolder extends io.tofpu.dynamicmessage.holder.MessageHolder {
@SkipMessage
private static MessageHolder instance;

public static void init() {
instance = DynamicMessage.get()
.create(MessageHolder.class);
}

public static MessageHolder get() {
return instance;
}

public String swapTitleAnnouncement =
wrap("<yellow>", wrap("<obf>", "00 ")) + wrap("<green>", "SWAPPAGE ") +
wrap("<yellow>", wrap("<obf>", "00")) + "\n" + wrap("<gold>", "New team") + ": %team%";

public String swapMessageAnnouncement =
wrap("<yellow>", "Your team swapped to ") + "%team%<yellow>!";

// commands
public String defaultCommand =
"<yellow>This is the default command. Type " + command("/swap help") +
" for more info!";

public String awaitReload = "<yellow>Reloading the plugin...";
public String reload = "<yellow>The plugin has been reloaded!";
public String reloadError = "<red>Something went wrong while reloading the " +
"configuration! Check the console for more information.";

public MessageHolder() {
super(new File(ADDON_DIRECTORY, "messages.yml"));
}

public static void init() {
instance = DynamicMessage.get()
.create(MessageHolder.class);
}

public static MessageHolder get() {
return instance;
}

private String command(final String command) {
return "<hover:show_text:'<yellow>Click to run " +
"%command%'><click:run_command:'%command%'><gold>%command%".replace(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package io.tofpu.bedwarsswapaddon.model.reload;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.*;

public abstract class ReloadHandlerBase {
private final ExecutorService service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

public abstract class SwapHandlerBase {
public abstract void registerArena(IArena arena);

public abstract void unregisterArena(IArena arena);

public abstract void handleRejoin(final Player player, final IArena arena);
Expand Down
Loading

0 comments on commit 7b15908

Please sign in to comment.