Skip to content

Commit

Permalink
chore: Added some API annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed May 18, 2023
1 parent 2e09079 commit c14d691
Show file tree
Hide file tree
Showing 34 changed files with 114 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github._4drian3d.chatregulator.api;

import org.jetbrains.annotations.NotNull;

public interface ChatRegulatorAPI {
PlayerManager getPlayerManager();
@NotNull PlayerManager getPlayerManager();

Statistics getStatistics();
@NotNull Statistics getStatistics();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github._4drian3d.chatregulator.api;

import io.github._4drian3d.chatregulator.api.enums.InfractionType;
import org.checkerframework.checker.index.qual.NonNegative;
import org.jetbrains.annotations.NotNull;

import java.util.EnumMap;
Expand All @@ -13,7 +14,7 @@ public final class InfractionCount {
* Adds an infraction to the count of any type of player infraction.
* @param type the infraction type
*/
public void addViolation(@NotNull InfractionType type) {
public void addViolation(final @NotNull InfractionType type) {
if (type == InfractionType.GLOBAL) {
throw new IllegalArgumentException("Invalid InfractionType provided");
}
Expand Down Expand Up @@ -51,7 +52,7 @@ public void resetViolations(final @NotNull InfractionType @NotNull... types) {
* @param type the violation type
* @return the count
*/
public int getCount(final @NotNull InfractionType type) {
public @NonNegative int getCount(final @NotNull InfractionType type) {
if (type == InfractionType.GLOBAL) {
int count = 0;
for (final int infraction : infractionMap.values()) {
Expand All @@ -63,7 +64,7 @@ public int getCount(final @NotNull InfractionType type) {
}

@Override
public boolean equals(Object o){
public boolean equals(final Object o){
if (this==o) return true;
if (!(o instanceof final InfractionCount that)) return false;
return Objects.equals(this.infractionMap, that.infractionMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface InfractionPlayer extends ForwardingAudience.Single {
*/
boolean isOnline();

StringChain getChain(SourceType sourceType);
@NotNull StringChain getChain(final @NotNull SourceType sourceType);

/**
* Get the infractions count of the player
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.github._4drian3d.chatregulator.api;

import io.github._4drian3d.chatregulator.api.result.CheckResult;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.CompletableFuture;

public interface LazyDetection {
CompletableFuture<CheckResult> detect(InfractionPlayer player, String string);
@NotNull CompletableFuture<CheckResult> detect(final @NotNull InfractionPlayer player, final @NotNull String string);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github._4drian3d.chatregulator.api;

import org.jetbrains.annotations.NotNull;

import java.util.UUID;

public interface PlayerManager {
InfractionPlayer getPlayer(UUID uuid);
InfractionPlayer getPlayer(final @NotNull UUID uuid);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github._4drian3d.chatregulator.api;

import io.github._4drian3d.chatregulator.api.enums.InfractionType;
import org.checkerframework.checker.index.qual.NonNegative;
import org.jetbrains.annotations.NotNull;

public interface Statistics {
Expand All @@ -9,5 +10,5 @@ public interface Statistics {
* @param type the infraction type
* @return count of the respective infraction type
*/
int getInfractionCount(@NotNull InfractionType type);
@NonNegative int getInfractionCount(final @NotNull InfractionType type);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package io.github._4drian3d.chatregulator.api;

import org.checkerframework.checker.index.qual.NonNegative;
import org.jetbrains.annotations.NotNull;

import java.time.Instant;

public interface StringChain extends Iterable<String> {
String index(int index);
public interface StringChain extends Iterable<@NotNull String> {
@NotNull String index(final @NonNegative int index);

String first();
@NotNull String first();

String last();
@NotNull String last();

Instant lastExecuted();
@NotNull Instant lastExecuted();

int size();
@NonNegative int size();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github._4drian3d.chatregulator.api.enums.InfractionType;
import io.github._4drian3d.chatregulator.api.result.CheckResult;
import net.kyori.adventure.builder.AbstractBuilder;
import org.checkerframework.checker.index.qual.NonNegative;
import org.jetbrains.annotations.NotNull;

import java.util.Locale;
Expand Down Expand Up @@ -78,7 +79,7 @@ public static class Builder implements AbstractBuilder<CapsCheck> {
* @param limit the new limit
* @return this
*/
public Builder limit(int limit) {
public Builder limit(@NonNegative int limit) {
this.limit = limit;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public sealed interface Check permits CapsCheck, CommandCheck, CooldownCheck, FloodCheck, RegexCheck, SpamCheck, SyntaxCheck, UnicodeCheck {
/**
* Check if the delivered string contains any infraction
* ans returns a CompletableFuture with the corresponding CheckResult
* and returns a CompletableFuture with the corresponding CheckResult
* To see what check has returned, perform a check by instanceof
* @param string the string to check
* @see CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private Builder(){}
* @param blockedCommands the blocked commands
* @return this
*/
public Builder blockedCommands(Collection<String> blockedCommands){
public Builder blockedCommands(final @NotNull Collection<@NotNull String> blockedCommands){
this.blockedCommands = blockedCommands;
return this;
}
Expand All @@ -66,7 +66,7 @@ public Builder blockedCommands(Collection<String> blockedCommands){
* @param blockedCommands the blocked commands
* @return this
*/
public Builder blockedCommands(String... blockedCommands){
public Builder blockedCommands(final @NotNull String @NotNull ... blockedCommands){
if (this.blockedCommands == null) {
this.blockedCommands = new HashSet<>(Arrays.asList(blockedCommands));
} else {
Expand All @@ -81,7 +81,7 @@ public Builder blockedCommands(String... blockedCommands){
* @param command the command to add
* @return this
*/
public Builder blockedCommand(String command){
public Builder blockedCommand(@NotNull String command){
if (this.blockedCommands == null) this.blockedCommands = new HashSet<>();

this.blockedCommands.add(command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github._4drian3d.chatregulator.api.enums.SourceType;
import io.github._4drian3d.chatregulator.api.result.CheckResult;
import net.kyori.adventure.builder.AbstractBuilder;
import org.checkerframework.checker.index.qual.NonNegative;
import org.jetbrains.annotations.NotNull;

import java.time.Duration;
Expand Down Expand Up @@ -47,18 +48,18 @@ public static class Builder implements AbstractBuilder<CooldownCheck> {
private SourceType source;

@Required
public Builder timeUnit(TimeUnit unit) {
public Builder timeUnit(final @NotNull TimeUnit unit) {
this.unit = unit;
return this;
}

public Builder limit(long limit) {
public Builder limit(final @NonNegative long limit) {
this.limit = limit;
return this;
}

@Required
public Builder source(SourceType source) {
public Builder source(final @NotNull SourceType source) {
this.source = source;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static class Builder implements AbstractBuilder<RegexCheck> {
private Builder() {
}

public Builder blockedPatterns(Collection<Pattern> patterns) {
public Builder blockedPatterns(final @NotNull Collection<@NotNull Pattern> patterns) {
requireNonNull(patterns);
if (this.blockedWords == null) {
this.blockedWords = new ArrayList<>(patterns);
Expand All @@ -82,7 +82,7 @@ public Builder blockedPatterns(Collection<Pattern> patterns) {
return this;
}

public Builder blockedPatterns(Pattern... patterns) {
public Builder blockedPatterns(final @NotNull Pattern @NotNull ... patterns) {
if (this.blockedWords == null) {
this.blockedWords = new ArrayList<>(List.of(patterns));
} else {
Expand All @@ -92,7 +92,7 @@ public Builder blockedPatterns(Pattern... patterns) {
}

@Required
public Builder controlType(ControlType controlType) {
public Builder controlType(final @NotNull ControlType controlType) {
this.controlType = requireNonNull(controlType);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static class Builder implements AbstractBuilder<SyntaxCheck> {

Builder() {}

public Builder allowedCommands(Collection<String> commands){
public Builder allowedCommands(final @NotNull Collection<@NotNull String> commands){
this.allowedCommands.addAll(commands);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private Builder() {
* @param chars the characters
* @return this
*/
public Builder characters(char... chars) {
public Builder characters(final char @NotNull ... chars) {
this.chars = chars;
return this;
}
Expand All @@ -111,13 +111,13 @@ public Builder characters(char... chars) {
* @return this
*/
@Required
public Builder controlType(ControlType control) {
public Builder controlType(final @NotNull ControlType control) {
this.control = control;
return this;
}

@Required
public Builder detectionMode(DetectionMode mode) {
public Builder detectionMode(final @NotNull DetectionMode mode) {
this.mode = mode;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public enum ControlType {
/**
* Replace the infraction
*/
REPLACE;
REPLACE
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public enum Permission implements Predicate<CommandSource> {
/**General Command */
COMMAND("chatregulator.command"),

/**Help Subcommand */
COMMAND_HELP("chatregulator.command.help"),
/**Stats Subcommand */
COMMAND_STATS("chatregulator.command.stats"),
/**Player Subcommand */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public enum SourceType {
* Represents a detection made when the player
* has written a comment in the chat.
*/
CHAT;
CHAT
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ public enum WarningType {
/**
* Simple message format
*/
MESSAGE;

MESSAGE
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public ChatInfractionEvent(
final @NotNull CheckResult detectionResult,
final @NotNull String message
) {

super(infractionPlayer, type, detectionResult);
this.message = message;
super(infractionPlayer, type, detectionResult);
this.message = message;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github._4drian3d.chatregulator.api.event;

import java.util.Objects;

import io.github._4drian3d.chatregulator.api.result.CheckResult;
import org.jetbrains.annotations.NotNull;

import io.github._4drian3d.chatregulator.api.InfractionPlayer;
import io.github._4drian3d.chatregulator.api.enums.InfractionType;

import static java.util.Objects.requireNonNull;

/**
* Event fired when recognizing an infraction in a command executed by a player.
*/
Expand All @@ -27,9 +27,8 @@ public CommandInfractionEvent(
@NotNull CheckResult result,
@NotNull String command
) {

super(Objects.requireNonNull(infractionPlayer), type, Objects.requireNonNull(result));
this.command = command;
super(requireNonNull(infractionPlayer), type, requireNonNull(result));
this.command = command;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package io.github._4drian3d.chatregulator.api.event;

import io.github._4drian3d.chatregulator.api.result.CheckResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.ApiStatus.Internal;

import io.github._4drian3d.chatregulator.api.InfractionPlayer;
import io.github._4drian3d.chatregulator.api.enums.InfractionType;
import io.github._4drian3d.chatregulator.api.result.CheckResult;
import org.jetbrains.annotations.NotNull;

/**
* Basis for infringement events
Expand All @@ -27,11 +25,10 @@ public sealed abstract class InfractionEvent permits ChatInfractionEvent, Comman
* @param type the infraction type
* @param detectionResult the result of the detection
*/
@Internal
protected InfractionEvent(
@NotNull InfractionPlayer infractionPlayer,
@NotNull InfractionType type,
@NotNull CheckResult detectionResult
final @NotNull InfractionPlayer infractionPlayer,
final @NotNull InfractionType type,
final @NotNull CheckResult detectionResult
) {
this.infractionPlayer = infractionPlayer;
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
import io.github._4drian3d.chatregulator.api.enums.InfractionType;
import org.jetbrains.annotations.NotNull;

import static java.util.Objects.requireNonNull;

public sealed interface CheckResult {
static CheckResult denied(final @NotNull InfractionType type) {
static @NotNull CheckResult denied(final @NotNull InfractionType type) {
return new DeniedCheckresult(type);
}

static CheckResult allowed() {
static @NotNull CheckResult allowed() {
return AllowedCheckResult.INSTANCE;
}

static CheckResult modified(final String modifier) {
static @NotNull CheckResult modified(final @NotNull String modifier) {
return new ReplaceCheckResult(modifier);
}

Expand Down Expand Up @@ -71,7 +73,7 @@ public InfractionType infractionType() {
final class ReplaceCheckResult implements CheckResult {
private final String modified;
private ReplaceCheckResult(final String modified) {
this.modified = modified;
this.modified = requireNonNull(modified);
}

@Override
Expand Down
Loading

0 comments on commit c14d691

Please sign in to comment.