Skip to content

Commit

Permalink
Update spark-forge to 1.14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Aug 25, 2019
1 parent c8d631f commit f8398d6
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 145 deletions.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion 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-4.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 19 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -109,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
Expand Down
18 changes: 17 additions & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
2 changes: 1 addition & 1 deletion spark-bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencies {
exclude(module: 'text-api')
exclude(module: 'text-serializer-gson')
}
compileOnly 'org.spigotmc:spigot-api:1.14-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT'

// placeholders
compileOnly 'me.clip:placeholderapi:2.10.3'
Expand Down
29 changes: 18 additions & 11 deletions spark-forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@ buildscript {
maven { url = "http://files.minecraftforge.net/maven" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
}

plugins {
id 'com.github.johnrengelman.shadow' version '4.0.1'
}

apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'net.minecraftforge.gradle'

minecraft {
version = '1.12.2-14.23.4.2705'
runDir = 'run'
mappings = 'snapshot_20171003'

replaceIn 'me/lucko/spark/forge/ForgeSparkMod.java'
replace '@version@', project.pluginVersion
mappings channel: 'snapshot', version: '20190801-1.14.3'
}

processResources {
Expand All @@ -28,16 +23,27 @@ processResources {
'pluginVersion': project.pluginVersion,
'pluginDescription': project.pluginDescription
)
include 'mcmod.info'
include 'META-INF/mods.toml'
}

from(sourceSets.main.resources.srcDirs) {
exclude 'META-INF/mods.toml'
}
}

configurations {
shade
compile.extendsFrom shade
}

dependencies {
compile project(':spark-common')
minecraft 'net.minecraftforge:forge:1.14.4-28.0.45'
shade project(':spark-common')
}

shadowJar {
archiveName = 'spark-forge.jar'
configurations = [project.configurations.shade]

relocate 'okio', 'me.lucko.spark.lib.okio'
relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3'
Expand All @@ -53,6 +59,7 @@ artifacts {

reobf {
shadowJar {
mappingType = 'SEARGE'
dependsOn createMcpToSrg
mappings = createMcpToSrg.outputs.files.singleFile
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,95 @@

package me.lucko.spark.forge;

import com.mojang.brigadier.CommandDispatcher;
import me.lucko.spark.common.sampler.TickCounter;
import net.minecraft.client.Minecraft;
import net.minecraft.command.ICommandSender;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.network.play.ClientPlayNetHandler;
import net.minecraft.command.ICommandSource;
import net.minecraft.command.ISuggestionProvider;
import net.minecraftforge.client.event.ClientChatEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;

import java.util.Collections;
import java.util.List;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

public class ForgeClientSparkPlugin extends ForgeSparkPlugin {

public static void register(ForgeSparkMod mod) {
ClientCommandHandler.instance.registerCommand(new ForgeClientSparkPlugin(mod));
private static final Field COMMAND_DISPATCHER_FIELD;
static {
COMMAND_DISPATCHER_FIELD = Arrays.stream(ClientPlayNetHandler.class.getDeclaredFields())
.filter(f -> f.getType() == CommandDispatcher.class)
.findFirst().orElseThrow(() -> new RuntimeException("No field with CommandDispatcher type"));
COMMAND_DISPATCHER_FIELD.setAccessible(true);
}

public ForgeClientSparkPlugin(ForgeSparkMod mod) {
public static void register(ForgeSparkMod mod, FMLClientSetupEvent event) {
Minecraft minecraft = event.getMinecraftSupplier().get();

ForgeClientSparkPlugin plugin = new ForgeClientSparkPlugin(mod, minecraft);
MinecraftForge.EVENT_BUS.register(plugin);

plugin.scheduler.scheduleWithFixedDelay(plugin::checkCommandRegistered, 10, 10, TimeUnit.SECONDS);
}

private final Minecraft minecraft;
private CommandDispatcher<ISuggestionProvider> dispatcher;

public ForgeClientSparkPlugin(ForgeSparkMod mod, Minecraft minecraft) {
super(mod);
this.minecraft = minecraft;
}

private void checkCommandRegistered() {
ClientPlayerEntity player = this.minecraft.player;
if (player == null) {
return;
}

ClientPlayNetHandler connection = player.connection;
if (connection == null) {
return;
}

try {
CommandDispatcher<ISuggestionProvider> dispatcher = (CommandDispatcher) COMMAND_DISPATCHER_FIELD.get(connection);
if (dispatcher != this.dispatcher) {
this.dispatcher = dispatcher;
registerCommands(this.dispatcher, context -> 1, "sparkc", "sparkclient");
}
} catch (Exception e) {
e.printStackTrace();
}
}

@SubscribeEvent
public void onClientChat(ClientChatEvent event) {
String chat = event.getMessage();
String[] split = chat.split(" ");
if (split.length == 0 || (!split[0].equals("/sparkc") && !split[0].equals("/sparkclient"))) {
return;
}

String[] args = Arrays.copyOfRange(split, 1, split.length);
this.platform.executeCommand(new ForgeCommandSender(this.minecraft.player, this), args);
this.minecraft.ingameGUI.getChatGUI().addToSentMessages(chat);
event.setCanceled(true);
}

@Override
boolean hasPermission(ICommandSender sender, String permission) {
boolean hasPermission(ICommandSource sender, String permission) {
return true;
}

@Override
public Stream<ForgeCommandSender> getSendersWithPermission(String permission) {
return Stream.of(new ForgeCommandSender(Minecraft.getMinecraft().player, this));
return Stream.of(new ForgeCommandSender(this.minecraft.player, this));
}

@Override
Expand All @@ -60,13 +121,4 @@ public String getCommandName() {
return "sparkc";
}

@Override
public String getName() {
return "sparkc";
}

@Override
public List<String> getAliases() {
return Collections.singletonList("sparkclient");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,44 @@
import me.lucko.spark.common.CommandSender;
import net.kyori.text.Component;
import net.kyori.text.serializer.gson.GsonComponentSerializer;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.command.ICommandSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.rcon.IServer;
import net.minecraft.util.text.ITextComponent;

import java.util.UUID;

public class ForgeCommandSender implements CommandSender {
private final ICommandSender sender;
private final ICommandSource sender;
private final ForgeSparkPlugin plugin;

public ForgeCommandSender(ICommandSender sender, ForgeSparkPlugin plugin) {
public ForgeCommandSender(ICommandSource sender, ForgeSparkPlugin plugin) {
this.sender = sender;
this.plugin = plugin;
}

@Override
public String getName() {
return this.sender.getName();
if (this.sender instanceof PlayerEntity) {
return ((PlayerEntity) this.sender).getGameProfile().getName();
} else if (this.sender instanceof IServer) {
return "Console";
} else {
return "unknown:" + this.sender.getClass().getSimpleName();
}
}

@Override
public UUID getUniqueId() {
if (this.sender instanceof EntityPlayer) {
return ((EntityPlayer) this.sender).getUniqueID();
if (this.sender instanceof PlayerEntity) {
return ((PlayerEntity) this.sender).getUniqueID();
}
return null;
}

@Override
public void sendMessage(Component message) {
ITextComponent component = ITextComponent.Serializer.jsonToComponent(GsonComponentSerializer.INSTANCE.serialize(message));
ITextComponent component = ITextComponent.Serializer.fromJson(GsonComponentSerializer.INSTANCE.serialize(message));
this.sender.sendMessage(component);
}

Expand Down
Loading

0 comments on commit f8398d6

Please sign in to comment.