Skip to content

Commit ad03623

Browse files
authored
Bring back the Sponge module, updated for 1.20.6 (EngineHub#2538)
* Bring back the Sponge module * Fixes * Specify the SNAPSHOT build of SpongeAPI to use
1 parent 05db94c commit ad03623

35 files changed

+4235
-2
lines changed

build-logic/build.gradle.kts

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ repositories {
88
name = "EngineHub Repository"
99
url = uri("https://maven.enginehub.org/repo/")
1010
}
11+
maven {
12+
name = "SpongePowered"
13+
url = uri("https://repo.spongepowered.org/repository/maven-public/")
14+
}
1115
}
1216

1317
dependencies {
@@ -19,6 +23,10 @@ dependencies {
1923
implementation(libs.jfrog.buildinfo)
2024
implementation(libs.paperweight)
2125
implementation(libs.gson)
26+
27+
implementation(libs.sponge.vanillagradle)
28+
implementation(libs.neogradle.userdev)
29+
2230
constraints {
2331
val asmVersion = "[${libs.versions.minimumAsm.get()},)"
2432
implementation("org.ow2.asm:asm:$asmVersion") {

gradle/libs.versions.toml

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
codecov = "org.enginehub.codecov:0.2.0"
33
neogradle-userdev = "net.neoforged.gradle.userdev:7.0.107"
44
fabric-loom = "fabric-loom:1.6.9"
5+
sponge-spongegradle = "org.spongepowered.gradle.plugin:2.2.0"
6+
sponge-vanillagradle = "org.spongepowered.gradle.vanilla:0.2.1-20240507.024226-82"
57

68
[versions]
79
kyoriText = "3.0.4"
@@ -26,6 +28,9 @@ lang-worldeditBase = "7.3.1"
2628
lang-version = "1309"
2729

2830
[libraries]
31+
neogradle-userdev = "net.neoforged.gradle:neoform:7.0.107"
32+
sponge-vanillagradle = "org.spongepowered:vanillagradle:0.2.1-20240507.024226-82"
33+
2934
licenser = "gradle.plugin.org.cadixdev.gradle:licenser:0.6.1"
3035
grgit = "org.ajoberstar.grgit:grgit-gradle:5.2.2"
3136
japicmp = "me.champeau.gradle:japicmp-gradle-plugin:0.4.2"

settings.gradle.kts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ pluginManagement {
55
name = "EngineHub"
66
url = uri("https://maven.enginehub.org/repo/")
77
}
8+
maven {
9+
name = "SpongePowered"
10+
url = uri("https://repo.spongepowered.org/repository/maven-public/")
11+
}
812
}
913
}
1014
plugins {
@@ -35,7 +39,7 @@ listOf("1.20.2", "1.20.4", "1.20.5").forEach {
3539
include("worldedit-bukkit:adapters:adapter-$it")
3640
}
3741

38-
listOf("bukkit", "core", "fabric", "neoforge", "cli").forEach {
42+
listOf("bukkit", "core", "fabric", "neoforge", "sponge", "cli").forEach {
3943
include("worldedit-libs:$it")
4044
include("worldedit-$it")
4145
}

verification/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tasks.check {
4343
// Generic setup for all tasks
4444
// Pull the version before our current version.
4545
val baseVersion = "(,${rootProject.version.toString().substringBefore("-SNAPSHOT")}["
46-
for (projectFragment in listOf("bukkit", "cli", "core", "fabric", "neoforge")) {
46+
for (projectFragment in listOf("bukkit", "cli", "core", "fabric", "neoforge", "sponge")) {
4747
val capitalizedFragment =
4848
projectFragment.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() }
4949
val proj = project(":worldedit-$projectFragment")
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
id("buildlogic.libs")
3+
}

worldedit-sponge/build.gradle.kts

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
import org.spongepowered.gradle.plugin.config.PluginLoaders
3+
import org.spongepowered.plugin.metadata.model.PluginDependency
4+
5+
plugins {
6+
alias(libs.plugins.sponge.spongegradle)
7+
id("org.spongepowered.gradle.vanilla")
8+
`java-library`
9+
id("buildlogic.platform")
10+
}
11+
12+
platform {
13+
kind = buildlogic.WorldEditKind.Mod
14+
includeClasspath = true
15+
}
16+
17+
commonJava {
18+
banSlf4j = false
19+
}
20+
21+
repositories {
22+
mavenCentral()
23+
}
24+
25+
minecraft {
26+
version("1.20.6")
27+
}
28+
29+
val spongeApiVersion = "11.0.0-20240520.134918-37";
30+
31+
sponge {
32+
apiVersion(spongeApiVersion)
33+
license("GPL-3.0-or-later")
34+
plugin("worldedit") {
35+
loader {
36+
name(PluginLoaders.JAVA_PLAIN)
37+
version("1.0")
38+
}
39+
displayName("WorldEdit")
40+
version(project.ext["internalVersion"].toString())
41+
entrypoint("com.sk89q.worldedit.sponge.SpongeWorldEdit")
42+
description("WorldEdit is an easy-to-use in-game world editor for Minecraft, supporting both single- and multi-player.")
43+
links {
44+
homepage("https://enginehub.org/worldedit/")
45+
source("https://github.com/EngineHub/WorldEdit")
46+
issues("https://github.com/EngineHub/WorldEdit/issues")
47+
}
48+
contributor("EngineHub") {
49+
description("Various members of the EngineHub team")
50+
}
51+
dependency("spongeapi") {
52+
loadOrder(PluginDependency.LoadOrder.AFTER)
53+
optional(false)
54+
}
55+
}
56+
}
57+
58+
dependencies {
59+
"api"(project(":worldedit-core"))
60+
"api"(project(":worldedit-libs:sponge"))
61+
62+
"api"("org.apache.logging.log4j:log4j-api")
63+
"implementation"("org.bstats:bstats-sponge:3.0.0")
64+
"implementation"("it.unimi.dsi:fastutil")
65+
"testImplementation"(libs.mockito.core)
66+
67+
// Silence some warnings, since apparently this isn't on the compile classpath like it should be.
68+
"compileOnly"("com.google.errorprone:error_prone_annotations:2.11.0")
69+
}
70+
71+
configure<BasePluginExtension> {
72+
archivesName.set("${project.name}-api$spongeApiVersion")
73+
}
74+
75+
tasks.named<ShadowJar>("shadowJar") {
76+
dependencies {
77+
include(dependency("org.bstats:"))
78+
include(dependency("org.antlr:antlr4-runtime"))
79+
include(dependency("com.sk89q.lib:jlibnoise"))
80+
81+
relocate("org.antlr.v4", "com.sk89q.worldedit.antlr4")
82+
relocate("org.bstats", "com.sk89q.worldedit.sponge.bstats")
83+
relocate("net.royawesome.jlibnoise", "com.sk89q.worldedit.jlibnoise")
84+
}
85+
}
86+
tasks.named("assemble").configure {
87+
dependsOn("shadowJar")
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* WorldEdit, a Minecraft world manipulation toolkit
3+
* Copyright (C) sk89q <http://www.sk89q.com>
4+
* Copyright (C) WorldEdit team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package com.sk89q.worldedit.sponge;
21+
22+
import com.sk89q.worldedit.LocalSession;
23+
import com.sk89q.worldedit.WorldEdit;
24+
import com.sk89q.worldedit.util.lifecycle.SimpleLifecycled;
25+
import org.spongepowered.api.ResourceKey;
26+
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
27+
import org.spongepowered.api.event.Listener;
28+
import org.spongepowered.api.event.lifecycle.RegisterChannelEvent;
29+
import org.spongepowered.api.network.ServerConnectionState;
30+
import org.spongepowered.api.network.channel.ChannelBuf;
31+
import org.spongepowered.api.network.channel.raw.RawDataChannel;
32+
import org.spongepowered.api.network.channel.raw.play.RawPlayDataHandler;
33+
34+
import java.nio.charset.StandardCharsets;
35+
36+
public class CUIChannelHandler implements RawPlayDataHandler<ServerConnectionState.Game> {
37+
public static final ResourceKey CUI_PLUGIN_CHANNEL = ResourceKey.of("worldedit", "cui");
38+
private static final SimpleLifecycled<RawDataChannel> CHANNEL = SimpleLifecycled.invalid();
39+
40+
public static final class RegistrationHandler {
41+
@Listener
42+
public void onChannelRegistration(RegisterChannelEvent event) {
43+
RawDataChannel channel = event.register(CUI_PLUGIN_CHANNEL, RawDataChannel.class);
44+
channel.play().addHandler(ServerConnectionState.Game.class, new CUIChannelHandler());
45+
CHANNEL.newValue(channel);
46+
}
47+
}
48+
49+
public static RawDataChannel channel() {
50+
return CHANNEL.valueOrThrow();
51+
}
52+
53+
@Override
54+
public void handlePayload(ChannelBuf data, ServerConnectionState.Game connection) {
55+
ServerPlayer player = connection.player();
56+
57+
SpongePlayer spongePlayer = SpongeAdapter.adapt(player);
58+
LocalSession session = WorldEdit.getInstance().getSessionManager().get(
59+
spongePlayer
60+
);
61+
62+
session.handleCUIInitializationMessage(
63+
new String(data.readBytes(data.available()), StandardCharsets.UTF_8),
64+
spongePlayer
65+
);
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* WorldEdit, a Minecraft world manipulation toolkit
3+
* Copyright (C) sk89q <http://www.sk89q.com>
4+
* Copyright (C) WorldEdit team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package com.sk89q.worldedit.sponge;
21+
22+
import com.sk89q.worldedit.command.util.PermissionCondition;
23+
import com.sk89q.worldedit.sponge.internal.LocaleResolver;
24+
import net.kyori.adventure.text.Component;
25+
import org.checkerframework.checker.nullness.qual.NonNull;
26+
import org.enginehub.piston.Command;
27+
import org.spongepowered.api.command.CommandCause;
28+
29+
import java.util.Collections;
30+
import java.util.Optional;
31+
import java.util.Set;
32+
33+
public abstract class CommandAdapter implements org.spongepowered.api.command.Command.Raw {
34+
private final Command command;
35+
36+
protected CommandAdapter(Command command) {
37+
this.command = command;
38+
}
39+
40+
@Override
41+
public boolean canExecute(CommandCause cause) {
42+
Set<String> permissions = command.getCondition().as(PermissionCondition.class)
43+
.map(PermissionCondition::getPermissions)
44+
.orElseGet(Collections::emptySet);
45+
46+
// Allow commands without permission nodes to always execute.
47+
if (permissions.isEmpty()) {
48+
return true;
49+
}
50+
51+
for (String perm : permissions) {
52+
if (cause.hasPermission(perm)) {
53+
return true;
54+
}
55+
}
56+
return false;
57+
}
58+
59+
@Override
60+
public Optional<Component> shortDescription(CommandCause cause) {
61+
return Optional.of(command.getDescription())
62+
.map(desc -> SpongeTextAdapter.convert(desc, LocaleResolver.resolveLocale(cause.audience())));
63+
}
64+
65+
@Override
66+
public Optional<Component> extendedDescription(CommandCause cause) {
67+
return command.getFooter()
68+
.map(footer -> SpongeTextAdapter.convert(footer, LocaleResolver.resolveLocale(cause.audience())));
69+
}
70+
71+
@Override
72+
public Optional<Component> help(@NonNull CommandCause cause) {
73+
return Optional.of(command.getFullHelp())
74+
.map(help -> SpongeTextAdapter.convert(help, LocaleResolver.resolveLocale(cause.audience())));
75+
}
76+
77+
@Override
78+
public Component usage(CommandCause cause) {
79+
return SpongeTextAdapter.convert(command.getUsage(), LocaleResolver.resolveLocale(cause.audience()));
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* WorldEdit, a Minecraft world manipulation toolkit
3+
* Copyright (C) sk89q <http://www.sk89q.com>
4+
* Copyright (C) WorldEdit team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package com.sk89q.worldedit.sponge;
21+
22+
import org.spongepowered.api.data.persistence.DataQuery;
23+
24+
/**
25+
* Kinda mirrors Sponge Common's Constants class.
26+
*
27+
* <p>Internal. Do not use.</p>
28+
*/
29+
public class Constants {
30+
public static class Sponge {
31+
public static final DataQuery UNSAFE_NBT = DataQuery.of("UnsafeData");
32+
33+
private Sponge() {
34+
}
35+
}
36+
37+
private Constants() {
38+
}
39+
}

0 commit comments

Comments
 (0)