Skip to content

Commit

Permalink
Fix sponge building
Browse files Browse the repository at this point in the history
  • Loading branch information
Elikill58 committed Nov 6, 2024
1 parent 622e10b commit e0807fd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id 'io.github.goooler.shadow' version '8.1.7'
id 'fabric-loom' version '1.7-SNAPSHOT' apply false
id 'org.spongepowered.gradle.plugin' version '2.2.0' apply false
id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' apply false
id 'org.spongepowered.gradle.vanilla' version '0.2' apply false
}

shadowJar {
Expand Down
14 changes: 0 additions & 14 deletions sponge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import org.spongepowered.gradle.plugin.config.PluginLoaders
import org.spongepowered.gradle.vanilla.repository.MinecraftPlatform
import org.spongepowered.plugin.metadata.model.PluginDependency
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id 'io.github.goooler.shadow'
id 'org.spongepowered.gradle.plugin'
id 'org.spongepowered.gradle.vanilla'
}

evaluationDependsOn(':common')
Expand All @@ -22,12 +20,6 @@ dependencies {
api project(':common')
}

minecraft {
version '1.16.5'
platform MinecraftPlatform.SERVER
injectRepositories false
}

sponge {
apiVersion("8.0.0")
license("NO_LICENCE_YET")
Expand Down Expand Up @@ -101,9 +93,3 @@ task prepareServer(type: Copy) {
}
}

runServer {
def runDir = System.getProperty("sponge.run.dir")
if (runDir != null) {
workingDir(runDir)
}
}
5 changes: 2 additions & 3 deletions sponge/src/com/elikill58/negativity/sponge/SpongeAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.minecraft.SharedConstants;

public class SpongeAdapter extends Adapter {

Expand All @@ -66,13 +65,13 @@ public class SpongeAdapter extends Adapter {
private final SpongeItemRegistrar itemRegistrar = new SpongeItemRegistrar();
private final Scheduler scheduler;

public SpongeAdapter(SpongeNegativity plugin) {
public SpongeAdapter(SpongeNegativity plugin, int version) {
this.plugin = plugin;
this.logger = new Log4jAdapter(plugin.getLogger());
this.config = UniversalUtils.loadConfig(plugin.getConfigDir().resolve("config.yml").toFile(), "config.yml");

this.translationProviderFactory = new NegativityTranslationProviderFactory(plugin.getConfigDir().resolve("lang"), "Negativity", "CheatHover");
this.serverVersion = Version.getVersionByProtocolID(SharedConstants.getProtocolVersion());
this.serverVersion = Version.getVersionByProtocolID(version);
this.scheduler = new SpongeScheduler(plugin.getContainer());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.elikill58.negativity.sponge.utils.Utils;
import com.elikill58.negativity.universal.Adapter;
import com.elikill58.negativity.universal.Negativity;
import com.elikill58.negativity.universal.Version;
import com.elikill58.negativity.universal.pluginMessages.NegativityMessagesManager;
import com.elikill58.negativity.universal.storage.account.NegativityAccountStorage;
import com.elikill58.negativity.universal.utils.UniversalUtils;
Expand Down Expand Up @@ -73,7 +74,7 @@ public SpongeNegativity(Logger logger, PluginContainer container, @ConfigDir(sha

@Listener
public void onConstructPlugin(ConstructPluginEvent event) {
Adapter.setAdapter(new SpongeAdapter(this));
Adapter.setAdapter(new SpongeAdapter(this, event.game().platform().minecraftVersion().dataVersion().orElse(Version.HIGHER.getFirstProtocolNumber())));
ChannelManager chan = Sponge.channelManager();
chan.ofType(ResourceKey.resolve("fml:hs"), RawDataChannel.class).play().addHandler(new FmlRawDataListener());
this.channel = chan.ofType(ResourceKey.resolve(NegativityMessagesManager.CHANNEL_ID), RawDataChannel.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.elikill58.negativity.sponge.nms;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.spongepowered.api.entity.living.player.server.ServerPlayer;

import com.elikill58.negativity.api.packets.nms.VersionAdapter;
Expand All @@ -9,17 +12,27 @@
import com.elikill58.negativity.universal.utils.ReflectionUtils;

import io.netty.channel.Channel;
import net.minecraft.network.Connection;

public class SpongeVersionAdapter extends VersionAdapter<ServerPlayer> {

private Field connectionField;
private Method getConnectionMethod;

public SpongeVersionAdapter() {
super(Adapter.getAdapter().getServerVersion());
try {
connectionField = Class.forName("net.minecraft.server.level.ServerPlayer").getDeclaredField("connection");
getConnectionMethod = Class.forName("net.minecraft.server.network.ServerGamePacketListenerImpl").getDeclaredMethod("getConnection");
} catch (Exception e) {
e.printStackTrace();
}
}

public Channel getChannel(ServerPlayer p) {
try {
Connection co = ((net.minecraft.server.level.ServerPlayer) p).connection.getConnection();
//Connection co = ((net.minecraft.server.level.ServerPlayer) p).connection.getConnection();
Object playerConnection = connectionField.get(p);
Object co = getConnectionMethod.invoke(playerConnection);
Channel channel = ReflectionUtils.getFirstWith(co, co.getClass(), Channel.class);
return channel;
} catch (Exception e) {
Expand Down

0 comments on commit e0807fd

Please sign in to comment.