Skip to content

Commit

Permalink
Bring back the Sponge module, updated for 1.20.6 (#2538)
Browse files Browse the repository at this point in the history
* Bring back the Sponge module

* Fixes

* Specify the SNAPSHOT build of SpongeAPI to use
  • Loading branch information
avaruus1 authored Jun 1, 2024
1 parent 05db94c commit ad03623
Show file tree
Hide file tree
Showing 35 changed files with 4,235 additions and 2 deletions.
8 changes: 8 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ repositories {
name = "EngineHub Repository"
url = uri("https://maven.enginehub.org/repo/")
}
maven {
name = "SpongePowered"
url = uri("https://repo.spongepowered.org/repository/maven-public/")
}
}

dependencies {
Expand All @@ -19,6 +23,10 @@ dependencies {
implementation(libs.jfrog.buildinfo)
implementation(libs.paperweight)
implementation(libs.gson)

implementation(libs.sponge.vanillagradle)
implementation(libs.neogradle.userdev)

constraints {
val asmVersion = "[${libs.versions.minimumAsm.get()},)"
implementation("org.ow2.asm:asm:$asmVersion") {
Expand Down
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
codecov = "org.enginehub.codecov:0.2.0"
neogradle-userdev = "net.neoforged.gradle.userdev:7.0.107"
fabric-loom = "fabric-loom:1.6.9"
sponge-spongegradle = "org.spongepowered.gradle.plugin:2.2.0"
sponge-vanillagradle = "org.spongepowered.gradle.vanilla:0.2.1-20240507.024226-82"

[versions]
kyoriText = "3.0.4"
Expand All @@ -26,6 +28,9 @@ lang-worldeditBase = "7.3.1"
lang-version = "1309"

[libraries]
neogradle-userdev = "net.neoforged.gradle:neoform:7.0.107"
sponge-vanillagradle = "org.spongepowered:vanillagradle:0.2.1-20240507.024226-82"

licenser = "gradle.plugin.org.cadixdev.gradle:licenser:0.6.1"
grgit = "org.ajoberstar.grgit:grgit-gradle:5.2.2"
japicmp = "me.champeau.gradle:japicmp-gradle-plugin:0.4.2"
Expand Down
6 changes: 5 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ pluginManagement {
name = "EngineHub"
url = uri("https://maven.enginehub.org/repo/")
}
maven {
name = "SpongePowered"
url = uri("https://repo.spongepowered.org/repository/maven-public/")
}
}
}
plugins {
Expand Down Expand Up @@ -35,7 +39,7 @@ listOf("1.20.2", "1.20.4", "1.20.5").forEach {
include("worldedit-bukkit:adapters:adapter-$it")
}

listOf("bukkit", "core", "fabric", "neoforge", "cli").forEach {
listOf("bukkit", "core", "fabric", "neoforge", "sponge", "cli").forEach {
include("worldedit-libs:$it")
include("worldedit-$it")
}
Expand Down
2 changes: 1 addition & 1 deletion verification/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tasks.check {
// Generic setup for all tasks
// Pull the version before our current version.
val baseVersion = "(,${rootProject.version.toString().substringBefore("-SNAPSHOT")}["
for (projectFragment in listOf("bukkit", "cli", "core", "fabric", "neoforge")) {
for (projectFragment in listOf("bukkit", "cli", "core", "fabric", "neoforge", "sponge")) {
val capitalizedFragment =
projectFragment.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() }
val proj = project(":worldedit-$projectFragment")
Expand Down
3 changes: 3 additions & 0 deletions worldedit-libs/sponge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("buildlogic.libs")
}
88 changes: 88 additions & 0 deletions worldedit-sponge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.spongepowered.gradle.plugin.config.PluginLoaders
import org.spongepowered.plugin.metadata.model.PluginDependency

plugins {
alias(libs.plugins.sponge.spongegradle)
id("org.spongepowered.gradle.vanilla")
`java-library`
id("buildlogic.platform")
}

platform {
kind = buildlogic.WorldEditKind.Mod
includeClasspath = true
}

commonJava {
banSlf4j = false
}

repositories {
mavenCentral()
}

minecraft {
version("1.20.6")
}

val spongeApiVersion = "11.0.0-20240520.134918-37";

sponge {
apiVersion(spongeApiVersion)
license("GPL-3.0-or-later")
plugin("worldedit") {
loader {
name(PluginLoaders.JAVA_PLAIN)
version("1.0")
}
displayName("WorldEdit")
version(project.ext["internalVersion"].toString())
entrypoint("com.sk89q.worldedit.sponge.SpongeWorldEdit")
description("WorldEdit is an easy-to-use in-game world editor for Minecraft, supporting both single- and multi-player.")
links {
homepage("https://enginehub.org/worldedit/")
source("https://github.com/EngineHub/WorldEdit")
issues("https://github.com/EngineHub/WorldEdit/issues")
}
contributor("EngineHub") {
description("Various members of the EngineHub team")
}
dependency("spongeapi") {
loadOrder(PluginDependency.LoadOrder.AFTER)
optional(false)
}
}
}

dependencies {
"api"(project(":worldedit-core"))
"api"(project(":worldedit-libs:sponge"))

"api"("org.apache.logging.log4j:log4j-api")
"implementation"("org.bstats:bstats-sponge:3.0.0")
"implementation"("it.unimi.dsi:fastutil")
"testImplementation"(libs.mockito.core)

// Silence some warnings, since apparently this isn't on the compile classpath like it should be.
"compileOnly"("com.google.errorprone:error_prone_annotations:2.11.0")
}

configure<BasePluginExtension> {
archivesName.set("${project.name}-api$spongeApiVersion")
}

tasks.named<ShadowJar>("shadowJar") {
dependencies {
include(dependency("org.bstats:"))
include(dependency("org.antlr:antlr4-runtime"))
include(dependency("com.sk89q.lib:jlibnoise"))

relocate("org.antlr.v4", "com.sk89q.worldedit.antlr4")
relocate("org.bstats", "com.sk89q.worldedit.sponge.bstats")
relocate("net.royawesome.jlibnoise", "com.sk89q.worldedit.jlibnoise")
}
}
tasks.named("assemble").configure {
dependsOn("shadowJar")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and 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 com.sk89q.worldedit.sponge;

import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.util.lifecycle.SimpleLifecycled;
import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.lifecycle.RegisterChannelEvent;
import org.spongepowered.api.network.ServerConnectionState;
import org.spongepowered.api.network.channel.ChannelBuf;
import org.spongepowered.api.network.channel.raw.RawDataChannel;
import org.spongepowered.api.network.channel.raw.play.RawPlayDataHandler;

import java.nio.charset.StandardCharsets;

public class CUIChannelHandler implements RawPlayDataHandler<ServerConnectionState.Game> {
public static final ResourceKey CUI_PLUGIN_CHANNEL = ResourceKey.of("worldedit", "cui");
private static final SimpleLifecycled<RawDataChannel> CHANNEL = SimpleLifecycled.invalid();

public static final class RegistrationHandler {
@Listener
public void onChannelRegistration(RegisterChannelEvent event) {
RawDataChannel channel = event.register(CUI_PLUGIN_CHANNEL, RawDataChannel.class);
channel.play().addHandler(ServerConnectionState.Game.class, new CUIChannelHandler());
CHANNEL.newValue(channel);
}
}

public static RawDataChannel channel() {
return CHANNEL.valueOrThrow();
}

@Override
public void handlePayload(ChannelBuf data, ServerConnectionState.Game connection) {
ServerPlayer player = connection.player();

SpongePlayer spongePlayer = SpongeAdapter.adapt(player);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(
spongePlayer
);

session.handleCUIInitializationMessage(
new String(data.readBytes(data.available()), StandardCharsets.UTF_8),
spongePlayer
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and 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 com.sk89q.worldedit.sponge;

import com.sk89q.worldedit.command.util.PermissionCondition;
import com.sk89q.worldedit.sponge.internal.LocaleResolver;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.enginehub.piston.Command;
import org.spongepowered.api.command.CommandCause;

import java.util.Collections;
import java.util.Optional;
import java.util.Set;

public abstract class CommandAdapter implements org.spongepowered.api.command.Command.Raw {
private final Command command;

protected CommandAdapter(Command command) {
this.command = command;
}

@Override
public boolean canExecute(CommandCause cause) {
Set<String> permissions = command.getCondition().as(PermissionCondition.class)
.map(PermissionCondition::getPermissions)
.orElseGet(Collections::emptySet);

// Allow commands without permission nodes to always execute.
if (permissions.isEmpty()) {
return true;
}

for (String perm : permissions) {
if (cause.hasPermission(perm)) {
return true;
}
}
return false;
}

@Override
public Optional<Component> shortDescription(CommandCause cause) {
return Optional.of(command.getDescription())
.map(desc -> SpongeTextAdapter.convert(desc, LocaleResolver.resolveLocale(cause.audience())));
}

@Override
public Optional<Component> extendedDescription(CommandCause cause) {
return command.getFooter()
.map(footer -> SpongeTextAdapter.convert(footer, LocaleResolver.resolveLocale(cause.audience())));
}

@Override
public Optional<Component> help(@NonNull CommandCause cause) {
return Optional.of(command.getFullHelp())
.map(help -> SpongeTextAdapter.convert(help, LocaleResolver.resolveLocale(cause.audience())));
}

@Override
public Component usage(CommandCause cause) {
return SpongeTextAdapter.convert(command.getUsage(), LocaleResolver.resolveLocale(cause.audience()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and 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 com.sk89q.worldedit.sponge;

import org.spongepowered.api.data.persistence.DataQuery;

/**
* Kinda mirrors Sponge Common's Constants class.
*
* <p>Internal. Do not use.</p>
*/
public class Constants {
public static class Sponge {
public static final DataQuery UNSAFE_NBT = DataQuery.of("UnsafeData");

private Sponge() {
}
}

private Constants() {
}
}
Loading

0 comments on commit ad03623

Please sign in to comment.