Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial 1.16.5/Sponge API 8 Functionality (Currently Forge Only) #2

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 82 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,40 +1,86 @@
import org.spongepowered.gradle.plugin.config.PluginLoaders
import org.spongepowered.plugin.metadata.model.PluginDependency

buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
url = "https://files.minecraftforge.net/maven"
}
}

dependencies {
classpath "net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT"
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
}
}

plugins {
id "java"
id 'java'
id 'java-library'
id "maven-publish"
id "net.minecrell.licenser" version "0.4.1"
id "com.github.johnrengelman.shadow" version "5.2.0"
id "net.minecrell.vanillagradle.server" version "2.2-6"
id "org.spongepowered.plugin" version "0.9.0"
id 'org.cadixdev.licenser' version '0.6.1'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id "org.spongepowered.gradle.plugin" version "2.0.1"
}

apply plugin: 'net.minecraftforge.gradle'

minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'official', version: '1.16.5'
}

group = "com.ichorpowered"
version = "0.1.0-SNAPSHOT"
description = "A minimal packet manipulation library for Sponge."

sponge.plugin.id = project.name

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

sponge {
apiVersion("8.0.0")
license("MIT")
loader {
name(PluginLoaders.JAVA_PLAIN)
version("1.0")
}
plugin("protocolcontrol") {
displayName("Protocol Control")
entrypoint("com.ichorpowered.protocolcontrol.ProtocolPlugin")
description("${project.description}")
links {
source("https://github.com/vectrix-space/protocolcontrol")
issues("https://github.com/vectrix-space/protocolcontrol/issues")
}
contributor("Vectrix") {
description("Project Owner/Developer")
}
dependency("spongeapi") {
loadOrder(PluginDependency.LoadOrder.AFTER)
optional(false)
}
}
}

repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
// maven {
// url "https://repo.ichorpowered.com/repository/maven-public"
// }
maven {
name 'Sponge Releases'
url 'https://repo.spongepowered.org/repository/maven-releases'
}
maven {
url "https://repo.ichorpowered.com/repository/maven-public"
name 'Sponge Snapshots'
url 'https://repo.spongepowered.org/repository/maven-snapshots'
}
}

Expand All @@ -51,13 +97,15 @@ license {
}

dependencies {
compile "com.ichorpowered:indigo:1.0.0-SNAPSHOT"
compile "net.kyori:mu:1.0.0-SNAPSHOT"
compile "net.kyori:violet:1.2.0-SNAPSHOT"
compile "net.kyori:event-method-asm:4.0.0-SNAPSHOT"
compileOnly "org.spongepowered:spongeapi:7.3.0"
compileOnly "org.spongepowered:spongecommon:1.12.2-7.3.0:dev"
annotationProcessor "org.spongepowered:spongeapi:7.3.0"
minecraft 'net.minecraftforge:forge:1.16.5-36.2.20'

implementation "net.kyori:indigo:1.0.0-SNAPSHOT"
implementation "net.kyori:mu:1.0.0-SNAPSHOT"
implementation "net.kyori:violet:1.2.0-SNAPSHOT"
implementation "net.kyori:event-method-asm:4.0.0-SNAPSHOT"
implementation 'com.google.inject:guice:4.1.0'
compileOnly group: 'org.spongepowered', name: 'math', version: '2.0.1'
//compileOnly "org.spongepowered:sponge:1.16.5-8.0.0-SNAPSHOT:dev"
}

tasks.withType(JavaCompile) {
Expand All @@ -66,12 +114,6 @@ tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

minecraft {
version = "1.12.2"
mappings = "snapshot_20180808"
makeObfSourceJar = false
}

jar {
manifest.attributes(
"Specification-Title": "ProtocolControl",
Expand Down Expand Up @@ -110,28 +152,35 @@ task javadocsJar(type: Jar) {

shadowJar {
classifier = "shaded"
dependsOn reobfJar

dependencies {
include(dependency("com.ichorpowered:indigo"))
include(dependency("net.kyori:indigo"))

include(dependency("net.kyori:mu"))
include(dependency("net.kyori:violet"))
include(dependency("net.kyori:event-api"))
include(dependency("net.kyori:event-method"))
include(dependency("net.kyori:event-method-asm"))
include(dependency("net.kyori:examination-api"))
//include(dependency("net.kyori:examination-api"))

include(dependency("com.google.inject:guice"))
include(dependency("com.google.inject.extensions:guice-assistedinject"))
include(dependency("com.google.inject.extensions:guice-multibindings"))
}

relocate("com.ichorpowered.indigo", "com.ichorpowered.indigo.lib.indigo")
relocate("net.kyori", "com.ichorpowered.protocolcontrol.lib.kyori")

relocate('com.google.guice', 'com.ichorpowered.protocolcontrol.lib.guice')
relocate("net.kyori.mu", "com.ichorpowered.protocolcontrol.lib.kyori.mu")
relocate("net.kyori.violet", "com.ichorpowered.protocolcontrol.lib.kyori.violet")
relocate("net.kyori.event-api", "com.ichorpowered.protocolcontrol.lib.kyori.event-api")
relocate("net.kyori.event-method", "com.ichorpowered.protocolcontrol.lib.kyori.event-method")
relocate("net.kyori.event-method-asm", "com.ichorpowered.protocolcontrol.lib.kyori.event-method-asm")
exclude "dummyThing"
}

reobf {
shadowJar {}
}

def ichorpoweredUsername = System.getenv("ICHORPOWERED_USERNAME")
def ichorpoweredPassword = System.getenv("ICHORPOWERED_PASSWORD")

Expand Down Expand Up @@ -191,3 +240,6 @@ publishing {
}
}
}

checkLicenseMain.dependsOn(updateLicenses)
build.dependsOn reobfShadowJar
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public final class ProtocolChannel {
private final ConcurrentMap<UUID, ChannelProfile> channels = Maps.newConcurrentMap();
private boolean enabled = false;

protected void enable() {
void enable() {
if(this.enabled) return;
this.enabled = true;
}

protected void disable() {
void disable() {
if(!this.enabled) return;
this.enabled = false;
this.channels.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
import net.kyori.event.SimpleEventBus;
import net.kyori.event.method.MethodSubscriptionAdapter;
import net.kyori.event.method.asm.ASMEventExecutorFactory;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;

import static java.util.Objects.requireNonNull;

Expand All @@ -66,7 +66,7 @@ public ProtocolEvent(final Logger logger) {
this.logger = logger;
}

protected void enable() {
void enable() {
if(this.enabled) return;
this.bus = new SimpleEventBus<Object>(Object.class) {
@Override
Expand All @@ -92,7 +92,7 @@ protected boolean shouldPost(final @NonNull Object event, final @NonNull EventSu
this.enabled = true;
}

protected void disable() {
void disable() {
if(!this.enabled) return;
this.bus.unregisterAll();
this.service.shutdownNow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.List;
import net.minecraft.network.NetworkSystem;
import net.minecraft.server.MinecraftServer;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.spongepowered.api.Game;

@Singleton
Expand All @@ -58,14 +58,16 @@ public ProtocolInjector(final Game game,
}

@SuppressWarnings({"unchecked", "JavaReflectionMemberAccess"})
protected void setup() {
void setup() {
if(this.setup) return;

Exceptions.catchingReport(
() -> {
final Field networkField = MinecraftServer.class.getDeclaredField("field_147144_o");
final NetworkSystem networkSystem = (NetworkSystem) networkField.get(this.game.getServer());
networkField.setAccessible(true);
final NetworkSystem networkSystem = (NetworkSystem) networkField.get(this.game.server());
final Field endpointsField = networkSystem.getClass().getDeclaredField("field_151274_e");
endpointsField.setAccessible(true);
this.endpoints = (List<ChannelFuture>) endpointsField.get(networkSystem);
this.setup = true;
},
Expand All @@ -76,7 +78,7 @@ protected void setup() {
);
}

protected void enable() {
void enable() {
if(this.enabled || !this.setup) return;
Exceptions.catchingReport(
() -> {
Expand All @@ -92,7 +94,7 @@ protected void enable() {
);
}

protected void disable() {
void disable() {
if(!this.enabled) return;
Exceptions.catchingReport(
() -> {
Expand Down
43 changes: 19 additions & 24 deletions src/main/java/com/ichorpowered/protocolcontrol/ProtocolPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,18 @@
import com.google.inject.Injector;
import com.ichorpowered.protocolcontrol.packet.PacketTranslations;
import com.ichorpowered.protocolcontrol.service.ProtocolService;
import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import com.ichorpowered.protocolcontrol.service.ServiceProvider;
import org.apache.logging.log4j.Logger;
import org.spongepowered.api.Server;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GamePostInitializationEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.event.lifecycle.ConstructPluginEvent;
import org.spongepowered.api.event.lifecycle.StartingEngineEvent;
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent;
import org.spongepowered.plugin.PluginContainer;
import org.spongepowered.plugin.builtin.jvm.Plugin;

@Plugin(
id = "protocolcontrol",
name = "ProtocolControl",
description = "A minimal protocol manipulation library for Sponge.",
authors = {
"Vectrix"
}
)
@Plugin("protocolcontrol")
public final class ProtocolPlugin {
private final Injector injector;
private final PluginContainer plugin;
Expand All @@ -65,31 +59,32 @@ public ProtocolPlugin(final Injector injector,
}

@Listener(order = Order.FIRST)
public void onGameInitialization(final GameInitializationEvent event) {
public void onGameInitialization(final ConstructPluginEvent event) {
final Injector childInjector = this.injector.createChildInjector(new ProtocolModule());
this.packetTranslations = childInjector.getInstance(PacketTranslations.class);
this.protocolInjector = childInjector.getInstance(ProtocolInjector.class);
this.protocolChannel = childInjector.getInstance(ProtocolChannel.class);
this.protocolEvent = childInjector.getInstance(ProtocolEvent.class);
final ProtocolService protocolService = childInjector.getInstance(ProtocolService.class);
ServiceProvider.register(protocolService);
}

@Listener(order = Order.FIRST)
public void onGameStarting(final StartingEngineEvent<Server> event) {
this.packetTranslations.register();
this.protocolInjector.setup();
this.protocolChannel.enable();
this.protocolEvent.enable();
final ProtocolService protocolService = childInjector.getInstance(ProtocolService.class);
Sponge.getServiceManager().setProvider(this, ProtocolService.class, protocolService);
}

@Listener(order = Order.FIRST)
public void onGameStarting(final GamePostInitializationEvent event) {
this.protocolInjector.enable();
this.logger.info("Successfully injected " + this.plugin.getName() + " version " + this.plugin.getVersion().orElse("UNKNOWN"));
this.logger.info("Successfully injected " + this.plugin.metadata().name().orElse("Unknown") + " version " + this.plugin.metadata().version());
}

@Listener(order = Order.LAST)
public void onGameStopped(final GameStoppingServerEvent event) {
public void onGameStopped(final StoppingEngineEvent<Server> event) {
if(this.protocolInjector != null && this.protocolInjector.enabled()) this.protocolInjector.disable();
if(this.protocolEvent != null && this.protocolEvent.enabled()) this.protocolEvent.disable();
if(this.protocolChannel != null && this.protocolChannel.enabled()) this.protocolChannel.disable();
this.logger.info("Stopped " + this.plugin.getName());
this.logger.info("Stopped " + this.plugin.metadata().name().orElse("Unknown"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;

@Singleton
public final class ChannelInitializer extends ChannelInboundHandlerAdapter {
Expand Down
Loading