Skip to content

Commit

Permalink
Documentationa and checkstyle changes
Browse files Browse the repository at this point in the history
Fixes #80

Other changes:
- checkstyle: max_line_length reduced to 100 for better readability
- added some missing file headers
  • Loading branch information
MrIvanPlays committed Dec 22, 2021
1 parent 148213e commit 85fe6cc
Show file tree
Hide file tree
Showing 52 changed files with 654 additions and 550 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 130
max_line_length = 100
tab_width = 4
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public class AccountTransactionEvent extends AccountEvent implements Cancellable
private final EconomyTransaction economyTransaction;
private boolean isCancelled = false;

public AccountTransactionEvent(@NotNull final EconomyTransaction economyTransaction, @NotNull final Account account) {
public AccountTransactionEvent(
@NotNull final EconomyTransaction economyTransaction, @NotNull final Account account
) {
super(account);
this.economyTransaction = economyTransaction;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
*/
public class NonPlayerAccountTransactionEvent extends AccountTransactionEvent {

public NonPlayerAccountTransactionEvent(@NotNull EconomyTransaction economyTransaction, @NotNull NonPlayerAccount account) {
public NonPlayerAccountTransactionEvent(
@NotNull EconomyTransaction economyTransaction, @NotNull NonPlayerAccount account
) {
super(economyTransaction, account);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
*/
public class PlayerAccountTransactionEvent extends AccountTransactionEvent {

public PlayerAccountTransactionEvent(@NotNull EconomyTransaction economyTransaction, @NotNull PlayerAccount account) {
public PlayerAccountTransactionEvent(
@NotNull EconomyTransaction economyTransaction, @NotNull PlayerAccount account
) {
super(economyTransaction, account);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* This file is/was part of Treasury. To read more information about Treasury such as its licensing, see <https://github.com/lokka30/Treasury>.
*/

package me.lokka30.treasury.api.common.response;

import java.util.Objects;
Expand Down Expand Up @@ -32,4 +36,5 @@ static FailureReason of(@NotNull String description) {
* @since {@link me.lokka30.treasury.api.economy.misc.EconomyAPIVersion#v1_0 v1.0}
*/
@NotNull String getDescription();

}
131 changes: 81 additions & 50 deletions api/src/main/java/me/lokka30/treasury/api/economy/EconomyProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import me.lokka30.treasury.api.economy.account.Account;
import me.lokka30.treasury.api.economy.account.NonPlayerAccount;
import me.lokka30.treasury.api.economy.account.AccountPermission;
import me.lokka30.treasury.api.economy.account.NonPlayerAccount;
import me.lokka30.treasury.api.economy.account.PlayerAccount;
import me.lokka30.treasury.api.economy.currency.Currency;
import me.lokka30.treasury.api.economy.misc.EconomyAPIVersion;
import me.lokka30.treasury.api.economy.misc.OptionalEconomyApiFeature;
import me.lokka30.treasury.api.economy.response.EconomyException;
import me.lokka30.treasury.api.economy.response.EconomySubscriber;
import me.lokka30.treasury.api.economy.response.EconomyFailureReason;
import me.lokka30.treasury.api.economy.response.EconomySubscriber;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -29,7 +29,7 @@
* which implements this interface to be registered in
* the specific platform they're implementing it for.
*
* @author lokka30, Jikoo, MrIvanPlays, NoahvdAa
* @author lokka30, Jikoo, MrIvanPlays, NoahvdAa, creatorfromhell
* @since {@link me.lokka30.treasury.api.economy.misc.EconomyAPIVersion#v1_0 v1.0}
*/
public interface EconomyProvider {
Expand Down Expand Up @@ -77,7 +77,9 @@ public interface EconomyProvider {
* @author Jikoo
* @since {@link me.lokka30.treasury.api.economy.misc.EconomyAPIVersion#v1_0 v1.0}
*/
void hasPlayerAccount(@NotNull UUID accountId, @NotNull EconomySubscriber<Boolean> subscription);
void hasPlayerAccount(
@NotNull UUID accountId, @NotNull EconomySubscriber<Boolean> subscription
);

/**
* Request an existing {@link PlayerAccount} for a user.
Expand All @@ -87,7 +89,9 @@ public interface EconomyProvider {
* @author Jikoo
* @since {@link me.lokka30.treasury.api.economy.misc.EconomyAPIVersion#v1_0 v1.0}
*/
void retrievePlayerAccount(@NotNull UUID accountId, @NotNull EconomySubscriber<PlayerAccount> subscription);
void retrievePlayerAccount(
@NotNull UUID accountId, @NotNull EconomySubscriber<PlayerAccount> subscription
);

/**
* Request the creation of a {@link PlayerAccount} for a user.
Expand All @@ -97,7 +101,9 @@ public interface EconomyProvider {
* @author Jikoo
* @since {@link me.lokka30.treasury.api.economy.misc.EconomyAPIVersion#v1_0 v1.0}
*/
void createPlayerAccount(@NotNull UUID accountId, @NotNull EconomySubscriber<PlayerAccount> subscription);
void createPlayerAccount(
@NotNull UUID accountId, @NotNull EconomySubscriber<PlayerAccount> subscription
);

/**
* Request all {@link UUID UUIDs} with associated {@link PlayerAccount PlayerAccounts}.
Expand All @@ -110,12 +116,12 @@ public interface EconomyProvider {

/**
* Request whether an identifier has an associated {@link Account}.
*
* <p>
* This method is safe for {@link NonPlayerAccount non-player accounts}.
*
* <p>
* This could return an {@link NonPlayerAccount} or an {@link PlayerAccount}.
*
* @param identifier the identifier of the account
* @param identifier the identifier of the account
* @param subscription the {@link EconomySubscriber} accepting the resulting value
* @author Jikoo
* @since {@link me.lokka30.treasury.api.economy.misc.EconomyAPIVersion#v1_0 v1.0}
Expand All @@ -124,49 +130,57 @@ public interface EconomyProvider {

/**
* Request an existing {@link Account} for a specific identifier.
*
* <p>
* This method is safe for {@link NonPlayerAccount non-player accounts}.
*
* <p>
* This could return an {@link NonPlayerAccount} or an {@link PlayerAccount}.
*
* @param identifier the identifier of the account
* @param identifier the identifier of the account
* @param subscription the {@link EconomySubscriber} accepting the resulting value
* @author Jikoo
* @since {@link me.lokka30.treasury.api.economy.misc.EconomyAPIVersion#v1_0 v1.0}
*/
void retrieveAccount(@NotNull String identifier, @NotNull EconomySubscriber<Account> subscription);
void retrieveAccount(
@NotNull String identifier, @NotNull EconomySubscriber<Account> subscription
);

/**
* Request the creation of a {@link Account} for a specific identifier.
*
* <p>
* This method is safe for {@link NonPlayerAccount non-player accounts}.
*
* <p>
* This could return an {@link NonPlayerAccount} or an {@link PlayerAccount}.
*
* @param identifier the identifier of the account
* @param identifier the identifier of the account
* @param subscription the {@link EconomySubscriber} accepting the resulting value
* @author Jikoo
* @since {@link me.lokka30.treasury.api.economy.misc.EconomyAPIVersion#v1_0 v1.0}
*/
default void createAccount(@NotNull String identifier, @NotNull EconomySubscriber<Account> subscription) {
default void createAccount(
@NotNull String identifier, @NotNull EconomySubscriber<Account> subscription
) {
createAccount(null, identifier, subscription);
}

/**
* Request the creation of a {@link Account} for a specific identifier {@code identifier} with {@link String} {@code
* name}.
*
* <p>
* This method is safe for {@link NonPlayerAccount non-player accounts}.
*
* <p>
* This could return an {@link NonPlayerAccount} or an {@link PlayerAccount}.
*
* @param name the human readable name of the account
* @param identifier the unique identifier of the account
* @param identifier the unique identifier of the account
* @param subscription the {@link EconomySubscriber} accepting the resulting value
* @author MrIvanPlays, Jikoo
* @since {@link EconomyAPIVersion#v1_0 v1.0}
*/
void createAccount(@Nullable String name, @NotNull String identifier,
@NotNull EconomySubscriber<Account> subscription);
void createAccount(
@Nullable String name,
@NotNull String identifier,
@NotNull EconomySubscriber<Account> subscription
);

/**
* Request all identifiers with associated {@link Account Accounts}.
Expand Down Expand Up @@ -203,7 +217,9 @@ default void retrieveAllAccountsPlayerIsMemberOf(
if (throwable instanceof EconomyException) {
subscription.fail((EconomyException) throwable);
} else {
subscription.fail(new EconomyException(EconomyFailureReason.OTHER_FAILURE, throwable));
subscription.fail(new EconomyException(EconomyFailureReason.OTHER_FAILURE,
throwable
));
}
return new HashSet<>();
}).thenAccept(identifiers -> {
Expand All @@ -212,24 +228,29 @@ default void retrieveAllAccountsPlayerIsMemberOf(
return;
}
Set<String> ret = new HashSet<>();
for (String identifier: identifiers) {
EconomySubscriber.<Account>asFuture(subscriber -> retrieveAccount(identifier, subscriber)).exceptionally(
throwable -> {
if (throwable instanceof EconomyException) {
subscription.fail((EconomyException) throwable);
} else {
subscription.fail(new EconomyException(EconomyFailureReason.OTHER_FAILURE, throwable));
}
return null;
}).thenCompose(account -> {
for (String identifier : identifiers) {
EconomySubscriber.<Account>asFuture(subscriber -> retrieveAccount(identifier,
subscriber
)).exceptionally(throwable -> {
if (throwable instanceof EconomyException) {
subscription.fail((EconomyException) throwable);
} else {
subscription.fail(new EconomyException(EconomyFailureReason.OTHER_FAILURE,
throwable
));
}
return null;
}).thenCompose(account -> {
if (account == null) {
return CompletableFuture.completedFuture(false);
}

if(!(account instanceof NonPlayerAccount)) {
if (!(account instanceof NonPlayerAccount)) {
return CompletableFuture.completedFuture(false);
}
return EconomySubscriber.asFuture(subscriber -> ((NonPlayerAccount)account).isMember(playerId, subscriber));
return EconomySubscriber.asFuture(subscriber -> account.isMember(playerId,
subscriber
));
}).thenAccept(val -> {
if (val) {
ret.add(identifier);
Expand Down Expand Up @@ -263,7 +284,9 @@ default void retrieveAllAccountsPlayerHasPermission(
if (throwable instanceof EconomyException) {
subscription.fail((EconomyException) throwable);
} else {
subscription.fail(new EconomyException(EconomyFailureReason.OTHER_FAILURE, throwable));
subscription.fail(new EconomyException(EconomyFailureReason.OTHER_FAILURE,
throwable
));
}
return new HashSet<>();
}).thenAccept(identifiers -> {
Expand All @@ -273,24 +296,29 @@ default void retrieveAllAccountsPlayerHasPermission(
}
Set<String> ret = new HashSet<>();
for (String identifier : identifiers) {
EconomySubscriber.<Account>asFuture(subscriber -> retrieveAccount(identifier, subscriber)).exceptionally(
throwable -> {
if (throwable instanceof EconomyException) {
subscription.fail((EconomyException) throwable);
} else {
subscription.fail(new EconomyException(EconomyFailureReason.OTHER_FAILURE, throwable));
}
return null;
}).thenCompose(account -> {
EconomySubscriber.<Account>asFuture(subscriber -> retrieveAccount(identifier,
subscriber
)).exceptionally(throwable -> {
if (throwable instanceof EconomyException) {
subscription.fail((EconomyException) throwable);
} else {
subscription.fail(new EconomyException(EconomyFailureReason.OTHER_FAILURE,
throwable
));
}
return null;
}).thenCompose(account -> {
if (account == null) {
return CompletableFuture.completedFuture(false);
}

if (!(account instanceof NonPlayerAccount)) {
return CompletableFuture.completedFuture(false);
}
return EconomySubscriber.asFuture(subscriber -> ((NonPlayerAccount)account).hasPermission(playerId, subscriber,
permissions));
return EconomySubscriber.asFuture(subscriber -> ((NonPlayerAccount) account).hasPermission(playerId,
subscriber,
permissions
));
}).thenAccept(val -> {
if (val) {
ret.add(identifier);
Expand All @@ -315,7 +343,7 @@ default void retrieveAllAccountsPlayerHasPermission(
*
* @param identifier The {@link Currency#getIdentifier()} of the {@link Currency} we are searching for.
* @return The {@link Optional} containing the search result. This will contain the
* resulting {@link Currency} if it exists, otherwise it will return {@link Optional#empty()}.
* resulting {@link Currency} if it exists, otherwise it will return {@link Optional#empty()}.
* @author creatorfromhell
* @since {@link me.lokka30.treasury.api.economy.misc.EconomyAPIVersion#v1_0 v1.0}
*/
Expand Down Expand Up @@ -346,13 +374,16 @@ default String getPrimaryCurrencyId() {
* Used to register a currency with the {@link EconomyProvider} to be utilized by
* other plugins.
*
* @param currency The currency to register with the {@link EconomyProvider}.
* @param currency The currency to register with the {@link EconomyProvider}.
* @param subscription The {@link EconomySubscriber} representing the result of the
* attempted {@link Currency} registration with an {@link Boolean}.
* This will be {@link Boolean#TRUE} if it was registered, otherwise
* it'll be {@link Boolean#FALSE}.
* @author creatorfromhell
* @since {@link me.lokka30.treasury.api.economy.misc.EconomyAPIVersion#v1_0 v1.0}
*/
void registerCurrency(@NotNull Currency currency, @NotNull EconomySubscriber<Boolean> subscription);
void registerCurrency(
@NotNull Currency currency, @NotNull EconomySubscriber<Boolean> subscription
);

}
Loading

0 comments on commit 85fe6cc

Please sign in to comment.