Skip to content

Commit

Permalink
misc: Depend on the Adventure API instead of the Velocity API in the …
Browse files Browse the repository at this point in the history
…API module
  • Loading branch information
4drian3d committed Sep 15, 2023
1 parent a07844a commit 5e4c41c
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 26 deletions.
9 changes: 4 additions & 5 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ java {
}

dependencies {
compileOnlyApi(libs.velocity)
compileOnlyApi(libs.adventure)
compileOnly(libs.caffeine)
}

tasks {
Expand All @@ -25,10 +26,8 @@ tasks {
javadoc {
options.encoding = Charsets.UTF_8.name()
(options as StandardJavadocDocletOptions).links(
"https://jd.advntr.dev/api/4.13.1/",
"https://jd.advntr.dev/text-minimessage/4.13.1/",
"https://jd.papermc.io/velocity/3.0.0/",
"https://checkerframework.org/api/",
"https://jd.advntr.dev/api/${libs.versions.adventure.get()}/",
"https://jd.advntr.dev/text-minimessage/${libs.versions.adventure.get()}/",
"https://javadoc.io/doc/org.jetbrains/annotations/24.0.1/index.html",
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class FloodCheck implements Check {
.maximumSize(3)
.initialCapacity(1)
.build(length -> Pattern.compile(
"(\\w)\\1{"+length+",}", //(\w{28,})|([^\wñ]{20,})|(^.{220,}$)
"(\\w)\\1{"+length+",}",
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)
);
private final Pattern pattern;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github._4drian3d.chatregulator.api.enums;

/**
* UnicodeChek's Detection Mode
* UnicodeCheck's Detection Mode
*/
public enum DetectionMode {
WHITELIST,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.github._4drian3d.chatregulator.api.enums;

import com.velocitypowered.api.command.CommandSource;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.permission.PermissionChecker;

import java.util.function.Predicate;

/**
* ChatRegulator Permissions
*/
public enum Permission implements Predicate<CommandSource> {
public enum Permission implements Predicate<Audience> {
/**General Command */
COMMAND("chatregulator.command"),

Expand Down Expand Up @@ -83,7 +84,9 @@ public String toString() {
}

@Override
public boolean test(final CommandSource source) {
return source.hasPermission(permission);
public boolean test(final Audience source) {
return source.get(PermissionChecker.POINTER)
.filter(checker -> checker.test(this.permission))
.isPresent();
}
}
1 change: 0 additions & 1 deletion api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
requires static org.checkerframework.checker.qual;
requires net.kyori.adventure;
requires net.kyori.examination.api;
requires com.velocitypowered.api;
requires com.github.benmanes.caffeine;

exports io.github._4drian3d.chatregulator.api;
Expand Down
5 changes: 0 additions & 5 deletions build.gradle.kts

This file was deleted.

4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ metadata.format.version = "1.1"

[versions]

adventure = "4.14.0"
velocity = "3.2.0-SNAPSHOT"
futures = "0.3.5"

Expand All @@ -10,6 +11,7 @@ assertj = "3.24.2"
miniplaceholders = "2.2.1"
hexlogger = "1.0.2"
bstats = "3.0.2"
caffeine = "3.1.8"

blossom = "2.0.1"
shadow = "8.1.1"
Expand All @@ -21,6 +23,7 @@ mockito = "5.5.0"

[libraries]

adventure = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" }
velocity = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" }
bstats = { module = "org.bstats:bstats-velocity", version.ref = "bstats" }
configurate = { module = "org.spongepowered:configurate-hocon", version.ref = "configurate" }
Expand All @@ -31,6 +34,7 @@ junit-bom = { group = "org.junit", name = "junit-bom", version.ref = "junit" }
mockito = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" }
hexlogger = { group = "io.github.4drian3d", name = "velocityhexlogger", version.ref = "hexlogger" }
futures = { group = "com.spotify", name = "completable-futures", version.ref = "futures" }
caffeine = { group = "com.github.ben-manes.caffeine", name = "caffeine", version.ref = "caffeine" }

[plugins]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ClearArgument implements Argument {
@Override
public CommandNode<CommandSource> node() {
return literal("clear")
.requires(Permission.COMMAND_CLEAR)
.requires(Permission.COMMAND_CLEAR::test)
.executes(cmd -> {
proxyServer.sendMessage(Components.SPACES_COMPONENT);
cmd.getSource().sendMessage(
Expand All @@ -39,7 +39,7 @@ public CommandNode<CommandSource> node() {
return Command.SINGLE_SUCCESS;
})
.then(literal("server")
.requires(Permission.COMMAND_CLEAR_SERVER)
.requires(Permission.COMMAND_CLEAR_SERVER::test)
.executes(cmd -> {
if (cmd.getSource() instanceof final Player player) {
player.getCurrentServer().ifPresent(playerServer -> {
Expand Down Expand Up @@ -90,7 +90,7 @@ public CommandNode<CommandSource> node() {
)
)
.then(literal("player")
.requires(Permission.COMMAND_CLEAR_PLAYER)
.requires(Permission.COMMAND_CLEAR_PLAYER::test)
.executes(cmd -> {
cmd.getSource().sendMessage(
formatter.parse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class PlayerArgument implements Argument {
@Override
public CommandNode<CommandSource> node() {
return literal("player")
.requires(Permission.COMMAND_PLAYER)
.requires(Permission.COMMAND_PLAYER::test)
.executes(ctx -> {
ctx.getSource().sendMessage(
formatter.parse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class RegulatorCommand {
public void register() {
final LiteralCommandNode<CommandSource> node = LiteralArgumentBuilder
.<CommandSource>literal("chatregulator")
.requires(Permission.COMMAND)
.requires(Permission.COMMAND::test)
.executes(cmd -> {
cmd.getSource().sendMessage(
formatter.parse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ReloadArgument implements Argument {
public CommandNode<CommandSource> node() {
return LiteralArgumentBuilder
.<CommandSource>literal("reload")
.requires(Permission.COMMAND_RELOAD)
.requires(Permission.COMMAND_RELOAD::test)
.executes(cmd -> {
CompletableFutures.combine(
messagesContainer.reload(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ResetArgument implements Argument {
@Override
public CommandNode<CommandSource> node() {
return literal("reset")
.requires(Permission.COMMAND_RESET)
.requires(Permission.COMMAND_RESET::test)
.executes(cmd -> {
cmd.getSource().sendMessage(
formatter.parse(
Expand Down Expand Up @@ -77,7 +77,7 @@ public CommandNode<CommandSource> node() {

private LiteralCommandNode<CommandSource> subReset(String subcommand, InfractionType type, Permission resetPermission) {
return literal(subcommand)
.requires(resetPermission)
.requires(resetPermission::test)
.executes(cmd -> {
String arg = cmd.getArgument("player", String.class);
Player player = proxyServer.getPlayer(arg).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class StatsArgument implements Argument {
@Override
public CommandNode<CommandSource> node() {
return literal("stats")
.requires(Permission.COMMAND_STATS)
.requires(Permission.COMMAND_STATS::test)
.executes(cmd -> {
final TagResolver resolver;
if (cmd.getSource() instanceof Player player) {
Expand Down
7 changes: 7 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
@file:Suppress("UnstableApiUsage")
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
rootProject.name = "ChatRegulator"

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven("https://papermc.io/repo/repository/maven-public/")
}
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
Expand Down

0 comments on commit 5e4c41c

Please sign in to comment.