Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
echo "STATUS=release" >> $GITHUB_ENV
fi
- name: Publish Snapshot
if: "${{ env.STATUS != 'release' && github.event_name == 'push' && github.ref == 'refs/heads/1.8.0-dev' }}"
if: "${{ env.STATUS != 'release' && github.event_name == 'push' && github.ref == 'refs/heads/1.9.0-dev' }}"
run: ./gradlew publish
env:
ORG_GRADLE_PROJECT_sonatypeUsername: "${{ secrets.SONATYPE_USERNAME }}"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Snapshot builds of Cloud are available through the [Sonatype OSS Snapshot reposi
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-PLATFORM</artifactId>
<version>1.8.0</version>
<version>1.9.0-SNAPSHOT</version>
</dependency>
<!--
~ Optional: Allows you to use annotated methods
Expand All @@ -124,7 +124,7 @@ Snapshot builds of Cloud are available through the [Sonatype OSS Snapshot reposi
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-annotations</artifactId>
<version>1.8.0</version>
<version>1.9.0-SNAPSHOT</version>
</dependency>
```

Expand Down Expand Up @@ -185,7 +185,7 @@ repositories {

```kotlin
dependencies {
implementation("cloud.commandframework", "cloud-PLATFORM", "1.8.0")
implementation("cloud.commandframework", "cloud-PLATFORM", "1.9.0-SNAPSHOT")
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -878,7 +877,7 @@ public void verifyAndRegister() {

CommandPermission permission;
if (existingPermission != null) {
permission = OrPermission.of(Arrays.asList(commandPermission, existingPermission));
permission = commandPermission.or(existingPermission);
} else {
permission = commandPermission;
}
Expand All @@ -893,7 +892,7 @@ public void verifyAndRegister() {
.getSetting(CommandManager.ManagerSettings.ENFORCE_INTERMEDIARY_PERMISSIONS)) {
permission = command.getCommandPermission();
} else {
permission = OrPermission.of(Arrays.asList(permission, command.getCommandPermission()));
permission = permission.or(command.getCommandPermission());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public synchronized <T> void registerInjector(
/**
* Register an injector for a particular type predicate.
*
* <p>The predicate should only
* return true if the injected type is assignable to the tested type. This predicate overload
* is provided in addition to {@link #registerInjector(Class, ParameterInjector)} to allow
* for exact, non-exact, or custom predicates, however is still bound by the aforementioned constraint.
* Failure to adhere to this will result in runtime exceptions.</p>
*
* @param predicate A predicate that matches if the injector should be used for a type
* @param injector The injector that should inject the value into the command method
* @param <T> Injected type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.apiguardian.api.API;
import org.checkerframework.checker.nullness.qual.NonNull;

import static java.util.Objects.requireNonNull;

/**
* Accepts if every single permission is accepted.
*/
Expand Down Expand Up @@ -67,6 +69,34 @@ public final class AndPermission implements CommandPermission {
return this.permissions;
}

@Override
public @NonNull CommandPermission and(final @NonNull CommandPermission other) {
requireNonNull(other, "other");

if (this.permissions.contains(other)) {
return this;
} else {
final Set<CommandPermission> objects = new HashSet<>(this.permissions);
addToSet(objects, other);
return new AndPermission(objects);
}
}

@Override
public @NonNull CommandPermission and(final @NonNull CommandPermission @NonNull... other) {
if (other.length == 0) {
return this;
} else if (other.length == 1) {
return this.and(other[0]);
} else {
final Set<CommandPermission> objects = new HashSet<>(this.permissions);
for (final CommandPermission permission : other) {
addToSet(objects, permission);
}
return new AndPermission(objects);
}
}

@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder();
Expand Down Expand Up @@ -97,4 +127,15 @@ public boolean equals(final Object o) {
public int hashCode() {
return Objects.hash(this.getPermissions());
}

private static void addToSet(
@NonNull final Set<CommandPermission> objects,
@NonNull final CommandPermission permission
) {
if (permission instanceof AndPermission) {
objects.addAll(permission.getPermissions());
} else {
objects.add(permission);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ public interface CommandPermission {
@API(status = API.Status.STABLE, since = "1.4.0")
default @NonNull CommandPermission or(final @NonNull CommandPermission other) {
requireNonNull(other, "other");
final Set<CommandPermission> permission = new HashSet<>(2);
permission.add(this);
permission.add(other);
return OrPermission.of(permission);

// Performance optimization
if (other instanceof OrPermission) {
return other.or(this);
}

return OrPermission.of(Arrays.asList(this, other));
}

/**
Expand Down Expand Up @@ -95,10 +98,13 @@ public interface CommandPermission {
@API(status = API.Status.STABLE, since = "1.4.0")
default @NonNull CommandPermission and(final @NonNull CommandPermission other) {
requireNonNull(other, "other");
final Set<CommandPermission> permission = new HashSet<>(2);
permission.add(this);
permission.add(other);
return AndPermission.of(permission);

// Performance optimization
if (other instanceof AndPermission) {
return other.and(this);
}

return AndPermission.of(Arrays.asList(this, other));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.apiguardian.api.API;
import org.checkerframework.checker.nullness.qual.NonNull;

import static java.util.Objects.requireNonNull;

/**
* Accepts as long as at least one of the permissions is accepted
*/
Expand All @@ -53,11 +55,7 @@ public final class OrPermission implements CommandPermission {
public static @NonNull CommandPermission of(final @NonNull Collection<CommandPermission> permissions) {
final Set<CommandPermission> objects = new HashSet<>();
for (final CommandPermission permission : permissions) {
if (permission instanceof OrPermission) {
objects.addAll(permission.getPermissions());
} else {
objects.add(permission);
}
addToSet(objects, permission);
}
return new OrPermission(objects);
}
Expand All @@ -67,6 +65,34 @@ public final class OrPermission implements CommandPermission {
return this.permissions;
}

@Override
public @NonNull CommandPermission or(final @NonNull CommandPermission other) {
requireNonNull(other, "other");

if (this.permissions.contains(other)) {
return this;
} else {
final Set<CommandPermission> objects = new HashSet<>(this.permissions);
addToSet(objects, other);
return new OrPermission(objects);
}
}

@Override
public @NonNull CommandPermission or(final @NonNull CommandPermission @NonNull... other) {
if (other.length == 0) {
return this;
} else if (other.length == 1) {
return this.or(other[0]);
} else {
final Set<CommandPermission> objects = new HashSet<>(this.permissions);
for (final CommandPermission permission : other) {
addToSet(objects, permission);
}
return new OrPermission(objects);
}
}

@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder();
Expand Down Expand Up @@ -97,4 +123,15 @@ public boolean equals(final Object o) {
public int hashCode() {
return Objects.hash(this.getPermissions());
}

private static void addToSet(
@NonNull final Set<CommandPermission> objects,
@NonNull final CommandPermission permission
) {
if (permission instanceof OrPermission) {
objects.addAll(permission.getPermissions());
} else {
objects.add(permission);
}
}
}
22 changes: 11 additions & 11 deletions cloud-minecraft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ mappings will be available.
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-bukkit</artifactId>
<version>1.8.0</version>
<version>1.9.0-SNAPSHOT</version>
</dependency>
```

**gradle**:
```groovy
dependencies {
implementation 'cloud.commandframework:cloud-bukkit:1.8.0'
implementation 'cloud.commandframework:cloud-bukkit:1.9.0-SNAPSHOT'
}
```

Expand Down Expand Up @@ -93,14 +93,14 @@ mappings are available even without commodore present.
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-paper</artifactId>
<version>1.8.0</version>
<version>1.9.0-SNAPSHOT</version>
</dependency>
```

**gradle**:
```groovy
dependencies {
implementation 'cloud.commandframework:cloud-paper:1.8.0'
implementation 'cloud.commandframework:cloud-paper:1.9.0-SNAPSHOT'
}
```

Expand All @@ -118,14 +118,14 @@ BungeeCord mappings for cloud.
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-bungee</artifactId>
<version>1.8.0</version>
<version>1.9.0-SNAPSHOT</version>
</dependency>
```

**gradle**:
```groovy
dependencies {
implementation 'cloud.commandframework:cloud-bungee:1.8.0'
implementation 'cloud.commandframework:cloud-bungee:1.9.0-SNAPSHOT'
}
```

Expand All @@ -150,14 +150,14 @@ cloud mappings for Velocity 1.1.0.
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-velocity</artifactId>
<version>1.8.0</version>
<version>1.9.0-SNAPSHOT</version>
</dependency>
```

**gradle**:
```groovy
dependencies {
implementation 'cloud.commandframework:cloud-velocity:1.8.0'
implementation 'cloud.commandframework:cloud-velocity:1.9.0-SNAPSHOT'
}
```

Expand All @@ -181,14 +181,14 @@ cloud mappings for CloudBurst 1.0.0-SNAPSHOT.
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-cloudburst</artifactId>
<version>1.8.0</version>
<version>1.9.0-SNAPSHOT</version>
</dependency>
```

**gradle**:
```groovy
dependencies {
implementation 'cloud.commandframework:cloud-velocity:1.8.0'
implementation 'cloud.commandframework:cloud-velocity:1.9.0-SNAPSHOT'
}
```

Expand Down Expand Up @@ -217,7 +217,7 @@ the latest release of cloud.
**gradle**:
```groovy
dependencies {
modImplementation 'cloud.commandframework:cloud-fabric:1.8.0'
modImplementation 'cloud.commandframework:cloud-fabric:1.9.0-SNAPSHOT'
}
```

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=cloud.commandframework
version=1.8.0
version=1.9.0-SNAPSHOT
description=Command framework and dispatcher for the JVM

org.gradle.caching=true
Expand Down