-
-
Notifications
You must be signed in to change notification settings - Fork 882
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring back the Sponge module, updated for 1.20.6 (#2538)
* Bring back the Sponge module * Fixes * Specify the SNAPSHOT build of SpongeAPI to use
- Loading branch information
Showing
35 changed files
with
4,235 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
plugins { | ||
id("buildlogic.libs") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
67 changes: 67 additions & 0 deletions
67
worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/CUIChannelHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/CommandAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |
Oops, something went wrong.