-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
1,431 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
plugins { | ||
id 'com.github.johnrengelman.shadow' version '8.1.1' | ||
id 'net.neoforged.gradle.userdev' version '7.0.97' | ||
} | ||
|
||
java.toolchain.languageVersion = JavaLanguageVersion.of(17) | ||
|
||
tasks.withType(JavaCompile) { | ||
// override, compile targeting J17 | ||
options.release = 17 | ||
} | ||
|
||
minecraft { | ||
accessTransformers { | ||
file('src/main/resources/META-INF/accesstransformer.cfg') | ||
} | ||
} | ||
|
||
configurations { | ||
shade | ||
implementation.extendsFrom shade | ||
} | ||
|
||
dependencies { | ||
implementation "net.neoforged:neoforge:20.4.223" | ||
shade project(':spark-common') | ||
} | ||
|
||
processResources { | ||
from(sourceSets.main.resources.srcDirs) { | ||
include 'META-INF/mods.toml' | ||
expand ( | ||
'pluginVersion': project.pluginVersion, | ||
'pluginDescription': project.pluginDescription | ||
) | ||
} | ||
|
||
from(sourceSets.main.resources.srcDirs) { | ||
exclude 'META-INF/mods.toml' | ||
} | ||
} | ||
|
||
shadowJar { | ||
archiveFileName = "spark-${project.pluginVersion}-neoforge.jar" | ||
configurations = [project.configurations.shade] | ||
|
||
relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' | ||
relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' | ||
relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' | ||
relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' | ||
relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' | ||
relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' | ||
relocate 'me.lucko.bytesocks.client', 'me.lucko.spark.lib.bytesocks' | ||
relocate 'org.java_websocket', 'me.lucko.spark.lib.bytesocks.ws' | ||
|
||
exclude 'module-info.class' | ||
exclude 'META-INF/maven/**' | ||
exclude 'META-INF/proguard/**' | ||
} | ||
|
||
artifacts { | ||
archives shadowJar | ||
shadow shadowJar | ||
} |
36 changes: 36 additions & 0 deletions
36
spark-neoforge/src/main/java/me/lucko/spark/neoforge/NeoForgeClassSourceLookup.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,36 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.neoforge; | ||
|
||
import cpw.mods.modlauncher.TransformingClassLoader; | ||
import me.lucko.spark.common.sampler.source.ClassSourceLookup; | ||
|
||
public class NeoForgeClassSourceLookup implements ClassSourceLookup { | ||
|
||
@Override | ||
public String identify(Class<?> clazz) { | ||
if (clazz.getClassLoader() instanceof TransformingClassLoader) { | ||
String name = clazz.getModule().getName(); | ||
return name.equals("forge") || name.equals("minecraft") ? null : name; | ||
} | ||
return null; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
spark-neoforge/src/main/java/me/lucko/spark/neoforge/NeoForgeCommandSender.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,77 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.neoforge; | ||
|
||
import me.lucko.spark.common.command.sender.AbstractCommandSender; | ||
import me.lucko.spark.neoforge.plugin.NeoForgeSparkPlugin; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; | ||
import net.minecraft.commands.CommandSource; | ||
import net.minecraft.network.chat.Component.Serializer; | ||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.rcon.RconConsoleSource; | ||
import net.minecraft.world.entity.player.Player; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
public class NeoForgeCommandSender extends AbstractCommandSender<CommandSource> { | ||
private final NeoForgeSparkPlugin plugin; | ||
|
||
public NeoForgeCommandSender(CommandSource source, NeoForgeSparkPlugin plugin) { | ||
super(source); | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
if (super.delegate instanceof Player) { | ||
return ((Player) super.delegate).getGameProfile().getName(); | ||
} else if (super.delegate instanceof MinecraftServer) { | ||
return "Console"; | ||
} else if (super.delegate instanceof RconConsoleSource) { | ||
return "RCON Console"; | ||
} else { | ||
return "unknown:" + super.delegate.getClass().getSimpleName(); | ||
} | ||
} | ||
|
||
@Override | ||
public UUID getUniqueId() { | ||
if (super.delegate instanceof Player) { | ||
return ((Player) super.delegate).getUUID(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void sendMessage(Component message) { | ||
MutableComponent component = Serializer.fromJson(GsonComponentSerializer.gson().serializeToTree(message)); | ||
Objects.requireNonNull(component, "component"); | ||
super.delegate.sendSystemMessage(component); | ||
} | ||
|
||
@Override | ||
public boolean hasPermission(String permission) { | ||
return this.plugin.hasPermission(super.delegate, permission); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
spark-neoforge/src/main/java/me/lucko/spark/neoforge/NeoForgeExtraMetadataProvider.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,73 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.neoforge; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import me.lucko.spark.common.platform.MetadataProvider; | ||
import net.minecraft.server.packs.repository.Pack; | ||
import net.minecraft.server.packs.repository.PackRepository; | ||
import net.minecraft.server.packs.repository.PackSource; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class NeoForgeExtraMetadataProvider implements MetadataProvider { | ||
|
||
private final PackRepository resourcePackManager; | ||
|
||
public NeoForgeExtraMetadataProvider(PackRepository resourcePackManager) { | ||
this.resourcePackManager = resourcePackManager; | ||
} | ||
|
||
@Override | ||
public Map<String, JsonElement> get() { | ||
Map<String, JsonElement> metadata = new LinkedHashMap<>(); | ||
metadata.put("datapacks", datapackMetadata()); | ||
return metadata; | ||
} | ||
|
||
private JsonElement datapackMetadata() { | ||
JsonObject datapacks = new JsonObject(); | ||
for (Pack profile : this.resourcePackManager.getSelectedPacks()) { | ||
JsonObject obj = new JsonObject(); | ||
obj.addProperty("name", profile.getTitle().getString()); | ||
obj.addProperty("description", profile.getDescription().getString()); | ||
obj.addProperty("source", resourcePackSource(profile.getPackSource())); | ||
datapacks.add(profile.getId(), obj); | ||
} | ||
return datapacks; | ||
} | ||
|
||
private static String resourcePackSource(PackSource source) { | ||
if (source == PackSource.DEFAULT) { | ||
return "none"; | ||
} else if (source == PackSource.BUILT_IN) { | ||
return "builtin"; | ||
} else if (source == PackSource.WORLD) { | ||
return "world"; | ||
} else if (source == PackSource.SERVER) { | ||
return "server"; | ||
} else { | ||
return "unknown"; | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
spark-neoforge/src/main/java/me/lucko/spark/neoforge/NeoForgePlatformInfo.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,53 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.neoforge; | ||
|
||
import me.lucko.spark.common.platform.PlatformInfo; | ||
import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion; | ||
import net.neoforged.neoforge.internal.versions.neoform.NeoFormVersion; | ||
|
||
public class NeoForgePlatformInfo implements PlatformInfo { | ||
private final Type type; | ||
|
||
public NeoForgePlatformInfo(Type type) { | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return this.type; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "NeoForge"; | ||
} | ||
|
||
@Override | ||
public String getVersion() { | ||
return NeoForgeVersion.getVersion(); | ||
} | ||
|
||
@Override | ||
public String getMinecraftVersion() { | ||
return NeoFormVersion.getMCVersion(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
spark-neoforge/src/main/java/me/lucko/spark/neoforge/NeoForgePlayerPingProvider.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,45 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.neoforge; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import me.lucko.spark.common.monitor.ping.PlayerPingProvider; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.level.ServerPlayer; | ||
|
||
import java.util.Map; | ||
|
||
public class NeoForgePlayerPingProvider implements PlayerPingProvider { | ||
private final MinecraftServer server; | ||
|
||
public NeoForgePlayerPingProvider(MinecraftServer server) { | ||
this.server = server; | ||
} | ||
|
||
@Override | ||
public Map<String, Integer> poll() { | ||
ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder(); | ||
for (ServerPlayer player : this.server.getPlayerList().getPlayers()) { | ||
builder.put(player.getGameProfile().getName(), player.connection.latency()); | ||
} | ||
return builder.build(); | ||
} | ||
} |
Oops, something went wrong.