Skip to content

Commit

Permalink
feat: add Sponge 11 platform support
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Jun 30, 2024
1 parent 8c00cde commit 3e2a0a3
Show file tree
Hide file tree
Showing 7 changed files with 364 additions and 16 deletions.
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

Versions are available on maven in the format `net.william278.uniform:ARTIFACT:VERSION`. See below for a table of supported platforms.

Note that Uniform versions omit the `v` prefix. Fabric versions are suffixed with the target Minecraft version (e.g. `1.1.9+1.21`) and also require Fabric API installed on the server.
Note that Uniform versions omit the `v` prefix. Fabric versions are suffixed with the target Minecraft version (e.g. `1.1.10+1.21`) and also require Fabric API installed on the server. Sponge versions are suffixed with the target Sponge API version (e.g. `1.1.10+11`).

<table align="center">
<thead>
Expand All @@ -29,7 +29,7 @@ Note that Uniform versions omit the `v` prefix. Fabric versions are suffixed wit
<tr>
<th>Platform</th>
<th>Artifact</th>
<th>Platform ver.</th>
<th>Minecraft ver.</th>
<th>Java ver.</th>
<th>Uniform ver.</th>
</tr>
Expand All @@ -46,45 +46,50 @@ Note that Uniform versions omit the `v` prefix. Fabric versions are suffixed wit
<th colspan="5">Supported Platforms</th>
</tr>
<tr>
<td>Bukkit/Spigot</td>
<td>Bukkit / Spigot</td>
<td><code>uniform-bukkit</code></td>
<td>≥<code>mc 1.17.1</code></td>
<td rowspan="2">≥<code>1.17.1</code></td>
<td rowspan="3" align="center">≥<code>17</code></td>
<td rowspan="5" align="center"><img src="https://img.shields.io/github/v/tag/WiIIiam278/Uniform?color=000000&label=%20&style=flat"/></td>
<td rowspan="6" align="center"><img src="https://img.shields.io/github/v/tag/WiIIiam278/Uniform?color=000000&label=%20&style=flat"/></td>
</tr>
<tr>
<td>Paper</td>
<td><code>uniform-paper</code></td>
<td>≥<code>mc 1.17.1</code></td>
</tr>
<tr>
<td>Velocity</td>
<td>Velocity <small>(3.3.0)</small></td>
<td><code>uniform-velocity</code></td>
<td>≥<code>3.3.0</code></td>
<td>≥<code>1.8.9</code></td>
</tr>
<tr>
<td rowspan="2">Fabric</td>
<td>Sponge <small>(api 11)</small></td>
<td><code>uniform-sponge</code></td>
<td>=<code>1.20.6</code></td>
<td rowspan="3" align="center">≥<code>21</code></td>
</tr>
<tr>
<td>Fabric <small>(1.20.1)</small></td>
<td rowspan="2"><code>uniform-fabric</code></td>
<td>=<code>mc 1.20.1</code></td>
<td rowspan="2" align="center">≥<code>21</code></td>
<td>=<code>1.20.1</code></td>
</tr>
<tr>
<td>=<code>mc 1.21</code></td>
<td>Fabric <small>(1.21)</small></td>
<td>=<code>1.21</code></td>
</tr>
<tr>
<th colspan="5">Formerly Supported Platforms</th>
</tr>
<tr>
<td>Fabric</td>
<td>Fabric <small>(1.20.6)</small></td>
<td><code>uniform-fabric</code></td>
<td>=<code>mc 1.20.6</code></td>
<td>=<code>1.20.6</code></td>
<td align="center">≥<code>21</code></td>
<td align="center"><code>v1.1.8</code></td>
</tr>
</tbody>
</table>

Example: To target Uniform on Bukkit, the artifact is `net.william278.uniform:uniform-bukkit:1.1.9` (check that this version is up-to-date &ndash; make sure you target the latest available!).
Example: To target Uniform on Bukkit, the artifact is `net.william278.uniform:uniform-bukkit:1.1.10` (check that this version is up-to-date &ndash; make sure you target the latest available!).

## Setup
Uniform is available [on Maven](https://repo.william278.net/#/releases/net/william278/uniform/). You can browse the Javadocs [here](https://repo.william278.net/javadoc/releases/net/william278/uniform/latest).
Expand All @@ -99,7 +104,7 @@ repositories {
}
```

Then, add the dependency itself. Replace `VERSION` with the latest release version. (e.g., `1.0`) and `PLATFORM` with the platform you are targeting (e.g., `paper`). If you want to target pre-release "snapshot" versions (not recommended), you should use the `/snapshots` repository instead.
Then, add the dependency itself. Replace `VERSION` with the latest release version. (e.g., `1.1.10`) and `PLATFORM` with the platform you are targeting (e.g., `paper`). If you want to target pre-release "snapshot" versions (not recommended), you should use the `/snapshots` repository instead.

```groovy
dependencies {
Expand Down
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ subprojects {
}
}

if (['sponge-11'].contains(project.name)) {
publications {
mavenSponge11(MavenPublication) {
groupId = 'net.william278.uniform'
artifactId = 'uniform-sponge'
version = "${rootProject.version}+11"
artifact shadowJar
artifact sourcesJar
artifact javadocJar
}
}
}

}

jar.dependsOn shadowJar
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include(
// Server Plugins
'paper',
'bukkit',
'sponge-11',

// Proxy Plugins
'velocity',
Expand Down
13 changes: 13 additions & 0 deletions sponge-11/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
id 'java-library'
id 'maven-publish'
}

dependencies {
implementation project(path: ':common')

compileOnly 'org.spongepowered:spongeapi:11.0.0'
compileOnly 'org.projectlombok:lombok:1.18.32'

annotationProcessor 'org.projectlombok:lombok:1.18.32'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* This file is part of Uniform, licensed under the GNU General Public License v3.0.
*
* Copyright (c) Tofaa2
* Copyright (c) William278 <[email protected]>
* Copyright (c) contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.william278.uniform.sponge;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.william278.uniform.BaseCommand;
import net.william278.uniform.Command;
import net.william278.uniform.Permission;
import net.william278.uniform.Uniform;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.api.Game;
import org.spongepowered.api.command.Command.Raw;
import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.command.CommandCompletion;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.exception.CommandException;
import org.spongepowered.api.command.parameter.ArgumentReader;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class SpongeCommand extends BaseCommand<CommandCause> {

private @Nullable Permission permission;

public SpongeCommand(@NotNull Command command) {
super(command);
this.permission = command.getPermission().orElse(null);
}

public SpongeCommand(@NotNull String name, @NotNull String description, @NotNull List<String> aliases) {
super(name, description, aliases);
}

public SpongeCommand(@NotNull String name, @NotNull List<String> aliases) {
super(name, aliases);
}

@NotNull
Impl getImpl() {
return new Impl(this);
}

static final class Impl implements Raw {

private static final int COMMAND_SUCCESS = com.mojang.brigadier.Command.SINGLE_SUCCESS;
private final CommandDispatcher<CommandCause> dispatcher = new CommandDispatcher<>();
private final SpongeCommand command;
private final @Nullable Permission permission;

public Impl(@NotNull SpongeCommand command) {
this.dispatcher.register(command.createBuilder());
this.command = command;
this.permission = command.permission;
}

@Override
public CommandResult process(CommandCause cause, ArgumentReader.Mutable arguments) throws CommandException {
try {
return dispatcher.execute(arguments.immutable().remaining(), cause) == COMMAND_SUCCESS
? CommandResult.success()
: CommandResult.error(Component.translatable("command.failed", NamedTextColor.RED));
} catch (CommandSyntaxException e) {
throw new CommandException(Component
.translatable("command.context.parse_error", NamedTextColor.RED).arguments(
Component.text(e.getRawMessage().getString()),
Component.text(e.getCursor()),
Component.text(e.getContext())
), e, true);
}
}

@Override
public List<CommandCompletion> complete(CommandCause cause, ArgumentReader.Mutable arguments) throws CommandException {
return dispatcher.getCompletionSuggestions(
dispatcher.parse(arguments.remaining(), cause),
arguments.cursor()
)
.thenApply(suggestions -> suggestions.getList().stream().map(s -> CommandCompletion.of(
s.getText(), Component.text(s.getTooltip().getString())
)).toList())
.join();
}

@Override
public boolean canExecute(CommandCause cause) {
if (permission == null) {
return true;
}
return new SpongeCommandUser(cause).checkPermission(permission);
}

@Override
public Optional<Component> shortDescription(CommandCause cause) {
return Optional.of(Component.text(command.getDescription()));
}

@Override
public Optional<Component> extendedDescription(CommandCause cause) {
return Optional.of(Component.text(command.getDescription()));
}

@Override
public Component usage(CommandCause cause) {
return Component.text(dispatcher.getSmartUsage(dispatcher.getRoot(), cause)
.values().stream().map("/%s"::formatted).collect(Collectors.joining("\n")));
}

}

@Override
public void addSubCommand(@NotNull Command command) {
addSubCommand(new SpongeCommand(command));
}

@Override
public Uniform getUniform() {
return SpongeUniform.INSTANCE;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This file is part of Uniform, licensed under the GNU General Public License v3.0.
*
* Copyright (c) Tofaa2
* Copyright (c) William278 <[email protected]>
* Copyright (c) contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.william278.uniform.sponge;

import net.kyori.adventure.audience.Audience;
import net.william278.uniform.CommandUser;
import net.william278.uniform.Permission;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.util.Tristate;

import java.util.UUID;

public record SpongeCommandUser(@NotNull CommandCause executor) implements CommandUser {

@Override
@NotNull
public Audience getAudience() {
return executor.audience();
}

@Override
@Nullable
public String getName() {
return executor instanceof Player player ? player.name() : null;
}

@Override
@Nullable
public UUID getUuid() {
return executor instanceof Player player ? player.uniqueId() : null;
}

@Override
public boolean checkPermission(@NotNull Permission permission) {
final Tristate state = executor.permissionValue(permission.toString());
if (state == Tristate.UNDEFINED && permission.defaultValue() == Permission.Default.IF_OP) {
return executor.hasPermission(permission.toString());
}
return state == Tristate.TRUE;
}

}
Loading

0 comments on commit 3e2a0a3

Please sign in to comment.