[FEAT] Paper Support
This commit is contained in:
@@ -2,9 +2,9 @@ def projectName = "CraterLib";
|
||||
def projectIcon = "https://cdn.modrinth.com/data/Nn8Wasaq/a172c634683a11a2e9ae593e56eba7885743bb44.png";
|
||||
def JDK = "21";
|
||||
def majorMc = "1.21.2";
|
||||
def modLoaders = "neoforge|fabric|quilt";
|
||||
def supportedMc = "1.21.2";
|
||||
def reltype = "release";
|
||||
def modLoaders = "neoforge|fabric|quilt|paper";
|
||||
def supportedMc = "1.21.3";
|
||||
def reltype = "snapshot";
|
||||
|
||||
pipeline {
|
||||
agent {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
// @excludeplugin
|
||||
package com.hypherionmc.craterlib.compat;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
@@ -13,4 +14,4 @@ public class FTBEssentials {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -12,7 +12,9 @@ import net.kyori.adventure.text.serializer.json.JSONOptions;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.Util;
|
||||
// @noplugin
|
||||
import net.minecraft.client.Minecraft;
|
||||
// #noplugin
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -37,8 +39,10 @@ public class ChatUtils {
|
||||
}
|
||||
|
||||
private static HolderLookup.Provider getRegistryLookup() {
|
||||
// @noplugin
|
||||
if (ModloaderEnvironment.INSTANCE.getEnvironment().isClient() && Minecraft.getInstance().level != null)
|
||||
return Minecraft.getInstance().level.registryAccess();
|
||||
// #noplugin
|
||||
|
||||
if (ModloaderEnvironment.INSTANCE.getEnvironment().isServer() && CommonPlatform.INSTANCE.getMCServer() != null)
|
||||
return CommonPlatform.INSTANCE.getMCServer().toMojang().registryAccess();
|
||||
@@ -113,7 +117,15 @@ public class ChatUtils {
|
||||
|
||||
public static net.kyori.adventure.text.Component format(String value) {
|
||||
value = convertFormattingCodes(value);
|
||||
return miniMessage.deserializeOr(value, net.kyori.adventure.text.Component.translatable(value));
|
||||
|
||||
try {
|
||||
return miniMessage.deserializeOr(value, net.kyori.adventure.text.Component.translatable(value));
|
||||
} catch (Exception ignored) {
|
||||
// Mini message fails to format text that contain legacy formatting. Since we support both, that's bad.
|
||||
// We just ignore the exception here so that the whole format doesn't fail
|
||||
}
|
||||
|
||||
return net.kyori.adventure.text.Component.translatable(value);
|
||||
}
|
||||
|
||||
private static String convertFormattingCodes(String input) {
|
||||
|
@@ -10,6 +10,8 @@ import java.util.ServiceLoader;
|
||||
*/
|
||||
public class InternalServiceUtil {
|
||||
|
||||
public static ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
/**
|
||||
* Try to load a service
|
||||
*
|
||||
@@ -17,7 +19,7 @@ public class InternalServiceUtil {
|
||||
* @return The loaded class
|
||||
*/
|
||||
public static <T> T load(Class<T> clazz) {
|
||||
final T loadedService = ServiceLoader.load(clazz)
|
||||
final T loadedService = ServiceLoader.load(clazz, loader)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
||||
CraterConstants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
||||
|
@@ -113,10 +113,10 @@ publisher {
|
||||
setModrinthID(modrinth_id)
|
||||
setNightbloomID("craterlib")
|
||||
setVersionType("release")
|
||||
setChangelog("https://raw.githubusercontent.com/hypherionmc/changelogs/main/craterlib/changelog-fabric.md")
|
||||
setChangelog(rootProject.file("changelog.md"))
|
||||
setProjectVersion("${minecraft_version}-${project.version}")
|
||||
setDisplayName("[FABRIC/QUILT 1.21.2] CraterLib - ${project.version}")
|
||||
setGameVersions("1.21.2")
|
||||
setDisplayName("[FABRIC/QUILT 1.21.3] CraterLib - ${project.version}")
|
||||
setGameVersions("1.21.3")
|
||||
setLoaders("fabric", "quilt")
|
||||
setArtifact(remapJar)
|
||||
setCurseEnvironment("both")
|
||||
|
@@ -13,7 +13,7 @@ public class FabricCompatHelper implements CompatUtils {
|
||||
if (!ModloaderEnvironment.INSTANCE.isModLoaded("melius-vanish"))
|
||||
return true;
|
||||
|
||||
return Vanish.isPlayerVanished(player.toMojangServerPlayer());
|
||||
return !Vanish.isPlayerVanished(player.toMojangServerPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,116 +0,0 @@
|
||||
// Adjust the output jar name here
|
||||
archivesBaseName = "${mod_name.replace(" ", "")}-Forge-${minecraft_version}"
|
||||
|
||||
dependencies {
|
||||
// Compat
|
||||
// NOT AVAILABLE ON FORGE modImplementation("maven.modrinth:vanishmod:${vanishmod}")
|
||||
|
||||
// Do not edit or remove
|
||||
implementation project(":Common")
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
from sourceSets.main.output
|
||||
configurations = [project.configurations.shade]
|
||||
|
||||
dependencies {
|
||||
exclude(dependency('com.google.code.gson:.*'))
|
||||
|
||||
relocate 'me.hypherionmc.moonconfig', 'shadow.hypherionmc.moonconfig'
|
||||
relocate 'me.hypherionmc.mcdiscordformatter', 'shadow.hypherionmc.mcdiscordformatter'
|
||||
relocate 'net.kyori', 'shadow.kyori'
|
||||
}
|
||||
|
||||
setArchiveClassifier('dev-shadow')
|
||||
mergeServiceFiles()
|
||||
}
|
||||
|
||||
/**
|
||||
* ===============================================================================
|
||||
* = DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING =
|
||||
* ===============================================================================
|
||||
*/
|
||||
|
||||
unimined.minecraft {
|
||||
minecraftForge {
|
||||
loader forge_version
|
||||
mixinConfig("${mod_id}.mixins.json", "${mod_id}.forge.mixins.json")
|
||||
}
|
||||
}
|
||||
|
||||
remapJar {
|
||||
inputFile.set shadowJar.archiveFile
|
||||
dependsOn shadowJar
|
||||
archiveClassifier.set null
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveClassifier.set "dev"
|
||||
}
|
||||
|
||||
processResources {
|
||||
from project(":Common").sourceSets.main.resources
|
||||
def buildProps = project.properties.clone()
|
||||
|
||||
filesMatching("META-INF/mods.toml") {
|
||||
expand buildProps
|
||||
}
|
||||
}
|
||||
|
||||
compileTestJava.enabled = false
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
source(project(":Common").sourceSets.main.allSource)
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishing Config
|
||||
*/
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
artifactId project.archivesBaseName
|
||||
from components.java
|
||||
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
|
||||
pom.withXml {
|
||||
Node pomNode = asNode()
|
||||
pomNode.dependencies.'*'.findAll() {
|
||||
it.artifactId.text() == 'regutils-joined-fabric' ||
|
||||
it.artifactId.text() == 'core' ||
|
||||
it.artifactId.text() == 'toml'
|
||||
}.each() {
|
||||
it.parent().remove(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven rootProject.orion.getPublishingMaven()
|
||||
}
|
||||
}
|
||||
|
||||
publisher {
|
||||
apiKeys {
|
||||
modrinth(System.getenv("MODRINTH_TOKEN"))
|
||||
curseforge(System.getenv("CURSE_TOKEN"))
|
||||
nightbloom(System.getenv("PLATFORM_KEY"))
|
||||
}
|
||||
|
||||
setCurseID(curse_id)
|
||||
setModrinthID(modrinth_id)
|
||||
setNightbloomID("craterlib")
|
||||
setVersionType("release")
|
||||
setChangelog("https://raw.githubusercontent.com/hypherionmc/changelogs/main/craterlib/changelog-forge.md")
|
||||
setProjectVersion("${minecraft_version}-${project.version}")
|
||||
setDisplayName("[Forge 1.20.6] CraterLib - ${project.version}")
|
||||
setGameVersions("1.20.6")
|
||||
setLoaders("forge")
|
||||
setArtifact(remapJar)
|
||||
setCurseEnvironment("both")
|
||||
setIsManualRelease(true)
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
package com.hypherionmc.craterlib;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.common.ForgeServerEvents;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
import com.hypherionmc.craterlib.network.CraterForgeNetworkHandler;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedOptions;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
|
||||
@Mod(CraterConstants.MOD_ID)
|
||||
public class CraterLib {
|
||||
|
||||
public CraterLib() {
|
||||
MinecraftForge.EVENT_BUS.register(new ForgeServerEvents());
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
|
||||
}
|
||||
|
||||
public void commonSetup(FMLCommonSetupEvent evt) {
|
||||
new CraterPacketNetwork(new CraterForgeNetworkHandler(FMLLoader.getDist().isClient() ? PacketSide.CLIENT : PacketSide.SERVER));
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
LateInitEvent event = new LateInitEvent(new BridgedMinecraft(), BridgedOptions.of(Minecraft.getInstance().options));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
package com.hypherionmc.craterlib.client;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import com.hypherionmc.craterlib.api.events.client.CraterClientTickEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = CraterConstants.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
|
||||
public class ForgeClientEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void clientTick(TickEvent.LevelTickEvent event) {
|
||||
if (Minecraft.getInstance().level == null)
|
||||
return;
|
||||
|
||||
CraterClientTickEvent craterClientTickEvent = new CraterClientTickEvent(BridgedClientLevel.of(Minecraft.getInstance().level));
|
||||
CraterEventBus.INSTANCE.postEvent(craterClientTickEvent);
|
||||
}
|
||||
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
package com.hypherionmc.craterlib.client;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.ClientPlatform;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.Connection;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 16/06/2022
|
||||
*/
|
||||
public class ForgeClientHelper implements ClientPlatform {
|
||||
|
||||
public ForgeClientHelper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BridgedMinecraft getClientInstance() {
|
||||
return new BridgedMinecraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BridgedPlayer getClientPlayer() {
|
||||
return BridgedPlayer.of(Minecraft.getInstance().player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BridgedClientLevel getClientLevel() {
|
||||
return BridgedClientLevel.of(Minecraft.getInstance().level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getClientConnection() {
|
||||
Objects.requireNonNull(Minecraft.getInstance().getConnection(), "Cannot send packets when not in game!");
|
||||
return Minecraft.getInstance().getConnection().getConnection();
|
||||
}
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public class ForgeCommonHelper implements CommonPlatform {
|
||||
|
||||
public static Map<ResourceLocation, CreativeModeTab> TABS = new HashMap<>();
|
||||
|
||||
public ForgeCommonHelper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BridgedMinecraftServer getMCServer() {
|
||||
return BridgedMinecraftServer.of(ServerLifecycleHooks.getCurrentServer());
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.CompatUtils;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
|
||||
public class ForgeCompatHelper implements CompatUtils {
|
||||
|
||||
@Override
|
||||
public boolean isPlayerActive(BridgedPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSkinUUID(BridgedPlayer player) {
|
||||
return player.getStringUUID();
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterRegisterCommandEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterServerLifecycleEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.commands.CommandsRegistry;
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
||||
import net.minecraftforge.event.server.ServerStoppedEvent;
|
||||
import net.minecraftforge.event.server.ServerStoppingEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
public class ForgeServerEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStarting(ServerStartingEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Starting(BridgedMinecraftServer.of(event.getServer())));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStarted(ServerStartedEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Started(BridgedMinecraftServer.of(event.getServer())));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStopping(ServerStoppingEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopping(BridgedMinecraftServer.of(event.getServer())));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStopped(ServerStoppedEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopped(BridgedMinecraftServer.of(event.getServer())));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onCommandRegister(RegisterCommandsEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent());
|
||||
CommandsRegistry.INSTANCE.registerCommands(event.getDispatcher());
|
||||
}
|
||||
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
package com.hypherionmc.craterlib.mixin;
|
||||
|
||||
import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
||||
import com.hypherionmc.craterlib.core.config.ConfigController;
|
||||
import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
||||
import com.hypherionmc.craterlib.core.config.annotations.NoConfigScreen;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraftforge.client.ConfigScreenHandler;
|
||||
import net.minecraftforge.forgespi.language.IModInfo;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
@Mixin(ConfigScreenHandler.class)
|
||||
public class ConfigScreenHandlerMixin {
|
||||
|
||||
/**
|
||||
* Inject Auto Generated config Screens into forge
|
||||
*
|
||||
*/
|
||||
@Inject(at = @At("RETURN"), method = "getScreenFactoryFor", cancellable = true, remap = false)
|
||||
private static void injectConfigScreen(IModInfo selectedMod, CallbackInfoReturnable<Optional<BiFunction<Minecraft, Screen, Screen>>> cir) {
|
||||
ConfigController.getMonitoredConfigs().forEach((conf, watcher) -> {
|
||||
if (!conf.getClass().isAnnotationPresent(NoConfigScreen.class)) {
|
||||
ModuleConfig config = (ModuleConfig) conf;
|
||||
if (config.getModId().equals(selectedMod.getModId())) {
|
||||
cir.setReturnValue(
|
||||
Optional.of((minecraft, screen) -> new CraterConfigScreen(config, screen))
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package com.hypherionmc.craterlib.mixin;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterServerChatEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.FilteredText;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(value = ServerGamePacketListenerImpl.class, priority = Integer.MIN_VALUE)
|
||||
public class ServerGamePacketListenerImplMixin {
|
||||
|
||||
@Shadow
|
||||
public ServerPlayer player;
|
||||
|
||||
@Inject(
|
||||
method = "lambda$handleChat$5",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
private void injectChatEvent(Component component, PlayerChatMessage arg, FilteredText p_296589_, CallbackInfo ci) {
|
||||
Component finalcomp = component == null ? arg.decoratedContent() : component;
|
||||
CraterServerChatEvent event = new CraterServerChatEvent(BridgedPlayer.of(this.player), finalcomp.getString(), ChatUtils.mojangToAdventure(finalcomp));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.wasCancelled())
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
package com.hypherionmc.craterlib.mixin;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.server.ServerStatusEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import net.minecraft.network.protocol.status.ServerboundStatusRequestPacket;
|
||||
import net.minecraft.server.network.ServerStatusPacketListenerImpl;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerStatusPacketListenerImpl.class)
|
||||
public class ServerStatusPacketListenerMixin {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private ServerStatus status;
|
||||
|
||||
@Shadow @Final private Connection connection;
|
||||
|
||||
@Inject(method = "handleStatusRequest",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/network/Connection;send(Lnet/minecraft/network/protocol/Packet;)V",
|
||||
shift = At.Shift.BEFORE),
|
||||
cancellable = true
|
||||
)
|
||||
private void injectHandleStatusRequest(ServerboundStatusRequestPacket arg, CallbackInfo ci) {
|
||||
ServerStatusEvent.StatusRequestEvent event = new ServerStatusEvent.StatusRequestEvent(ChatUtils.mojangToAdventure(status.description()));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
|
||||
if (event.getNewStatus() != null) {
|
||||
ci.cancel();
|
||||
this.connection.send(new ClientboundStatusResponsePacket(
|
||||
new ServerStatus(ChatUtils.adventureToMojang(
|
||||
event.getNewStatus()),
|
||||
status.players(),
|
||||
status.version(),
|
||||
status.favicon(),
|
||||
status.enforcesSecureChat(),
|
||||
status.isModded()
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,98 +0,0 @@
|
||||
package com.hypherionmc.craterlib.network;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import com.hypherionmc.craterlib.core.networking.PacketRegistry;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraftforge.event.network.CustomPayloadEvent;
|
||||
import net.minecraftforge.network.ChannelBuilder;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.network.SimpleChannel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public class CraterForgeNetworkHandler extends PacketRegistry {
|
||||
private final Map<Class<?>, SimpleChannel> CHANNELS = new HashMap<>();
|
||||
|
||||
public CraterForgeNetworkHandler(PacketSide side) {
|
||||
super(side);
|
||||
}
|
||||
|
||||
protected <T> void registerPacket(PacketHolder<T> holder) {
|
||||
if (CHANNELS.get(holder.messageType()) == null) {
|
||||
SimpleChannel channel = ChannelBuilder
|
||||
.named(holder.type().id())
|
||||
.clientAcceptedVersions((a, b) -> true)
|
||||
.serverAcceptedVersions((a, b) -> true)
|
||||
.networkProtocolVersion(1)
|
||||
.simpleChannel();
|
||||
|
||||
channel.messageBuilder(holder.messageType())
|
||||
.decoder(mojangDecoder(holder.decoder()))
|
||||
.encoder(mojangEncoder(holder.encoder()))
|
||||
.consumerNetworkThread(buildHandler(holder.handler()))
|
||||
.add();
|
||||
|
||||
CHANNELS.put(holder.messageType(), channel);
|
||||
} else {
|
||||
CraterConstants.LOG.error("Trying to register duplicate packet for type {}", holder.messageType());
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void sendToServer(T packet) {
|
||||
this.sendToServer(packet, false);
|
||||
}
|
||||
|
||||
public <T> void sendToServer(T packet, boolean ignoreCheck) {
|
||||
SimpleChannel channel = CHANNELS.get(packet.getClass());
|
||||
Connection connection = Minecraft.getInstance().getConnection().getConnection();
|
||||
if (channel.isRemotePresent(connection) || ignoreCheck) {
|
||||
channel.send(packet, PacketDistributor.SERVER.noArg());
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void sendToClient(T packet, BridgedPlayer player) {
|
||||
SimpleChannel channel = CHANNELS.get(packet.getClass());
|
||||
ServerGamePacketListenerImpl connection = player.getConnection();
|
||||
if (connection == null)
|
||||
return;
|
||||
|
||||
if (channel.isRemotePresent(connection.getConnection())) {
|
||||
channel.send(packet, PacketDistributor.PLAYER.with(player.toMojangServerPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
private <T> Function<FriendlyByteBuf, T> mojangDecoder(Function<BridgedFriendlyByteBuf, T> handler) {
|
||||
return byteBuf -> handler.apply(BridgedFriendlyByteBuf.of(byteBuf));
|
||||
}
|
||||
|
||||
private <T> BiConsumer<T, FriendlyByteBuf> mojangEncoder(BiConsumer<T, BridgedFriendlyByteBuf> handler) {
|
||||
return ((t, byteBuf) -> handler.accept(t, BridgedFriendlyByteBuf.of(byteBuf)));
|
||||
}
|
||||
|
||||
private <T> BiConsumer<T, CustomPayloadEvent.Context> buildHandler(Consumer<PacketContext<T>> handler) {
|
||||
return (message, ctx) -> {
|
||||
ctx.enqueueWork(() -> {
|
||||
PacketSide side = ctx.getDirection().getReceptionSide().isServer() ? PacketSide.SERVER : PacketSide.CLIENT;
|
||||
ServerPlayer player = ctx.getSender();
|
||||
handler.accept(new PacketContext<>(BridgedPlayer.of(player), message, side));
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
};
|
||||
}
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[50,)"
|
||||
license = "MIT"
|
||||
issueTrackerURL = "https://github.com/firstdarkdev/craterLib/issues"
|
||||
|
||||
[[mods]]
|
||||
modId = "${mod_id}"
|
||||
version = "${version}"
|
||||
displayName = "${mod_name}"
|
||||
displayURL = "https://modrinth.com/mod/craterlib"
|
||||
logoFile = "craterlib_logo.png"
|
||||
#credits="Thanks for this example mod goes to Java"
|
||||
authors = "${mod_author}, Zenith"
|
||||
description = '''
|
||||
A library mod used by First Dark Development and HypherionSA Mods
|
||||
'''
|
||||
displayTest = "NONE"
|
||||
|
||||
[[dependencies.${ mod_id }]]
|
||||
modId = "forge"
|
||||
mandatory = true
|
||||
versionRange = "[50,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.${ mod_id }]]
|
||||
modId = "minecraft"
|
||||
mandatory = true
|
||||
versionRange = "[1.20.6,1.21)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
@@ -1 +0,0 @@
|
||||
com.hypherionmc.craterlib.client.ForgeClientHelper
|
@@ -1 +0,0 @@
|
||||
com.hypherionmc.craterlib.common.ForgeCommonHelper
|
@@ -1 +0,0 @@
|
||||
com.hypherionmc.craterlib.common.ForgeCompatHelper
|
@@ -1 +0,0 @@
|
||||
com.hypherionmc.craterlib.common.ForgeLoaderHelper
|
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.hypherionmc.craterlib.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"ConfigScreenHandlerMixin"
|
||||
],
|
||||
"server": [
|
||||
"ServerGamePacketListenerImplMixin",
|
||||
"ServerStatusPacketListenerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 48 KiB |
@@ -106,10 +106,10 @@ publisher {
|
||||
setModrinthID(modrinth_id)
|
||||
setNightbloomID("craterlib")
|
||||
setVersionType("release")
|
||||
setChangelog("https://raw.githubusercontent.com/hypherionmc/changelogs/main/craterlib/changelog-forge.md")
|
||||
setChangelog(rootProject.file("changelog.md"))
|
||||
setProjectVersion("${minecraft_version}-${project.version}")
|
||||
setDisplayName("[NeoForge 1.21.2] CraterLib - ${project.version}")
|
||||
setGameVersions("1.21.2")
|
||||
setDisplayName("[NeoForge 1.21.3] CraterLib - ${project.version}")
|
||||
setGameVersions("1.21.3")
|
||||
setLoaders("neoforge")
|
||||
setArtifact(remapJar)
|
||||
setCurseEnvironment("both")
|
||||
|
@@ -12,7 +12,7 @@ public class NeoForgeCompatHelper implements CompatUtils {
|
||||
if (!ModloaderEnvironment.INSTANCE.isModLoaded("vmod"))
|
||||
return true;
|
||||
|
||||
return VanishUtil.isVanished(player.toMojangServerPlayer());
|
||||
return !VanishUtil.isVanished(player.toMojangServerPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
80
1.21.2/Paper/build.gradle
Normal file
80
1.21.2/Paper/build.gradle
Normal file
@@ -0,0 +1,80 @@
|
||||
plugins {
|
||||
id "io.papermc.paperweight.userdev" version "1.7.3"
|
||||
id "xyz.jpenilla.run-paper" version "2.3.0"
|
||||
}
|
||||
|
||||
archivesBaseName = "${mod_name.replace(" ", "")}-Paper-${minecraft_version}"
|
||||
|
||||
origami {
|
||||
excludedPackages = ["com.hypherionmc.craterlib.client", "com.hypherionmc.craterlib.mixin", "com.hypherionmc.craterlib.nojang.client", "com.hypherionmc.craterlib.core.rpcsdk", "com.hypherionmc.craterlib.nojang.realmsclient"]
|
||||
excludedResources = ["pack.mcmeta", "craterlib.mixins.json"]
|
||||
}
|
||||
|
||||
dependencies {
|
||||
paperweight.paperDevBundle("${minecraft_version}-R0.1-SNAPSHOT")
|
||||
|
||||
// Do not edit or remove
|
||||
implementation project(":Common")
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
from sourceSets.main.output
|
||||
configurations = [project.configurations.shade]
|
||||
|
||||
dependencies {
|
||||
exclude(dependency('com.google.code.gson:.*'))
|
||||
exclude(dependency('net.kyori:.*'))
|
||||
|
||||
relocate 'me.hypherionmc.moonconfig', 'shadow.hypherionmc.moonconfig'
|
||||
relocate 'me.hypherionmc.mcdiscordformatter', 'shadow.hypherionmc.mcdiscordformatter'
|
||||
|
||||
exclude("linux-x86-64/**", "win32-x86/**", "win32-x86-64/**", "darwin/**")
|
||||
}
|
||||
|
||||
setArchiveClassifier(null)
|
||||
mergeServiceFiles()
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveClassifier.set "slim"
|
||||
}
|
||||
|
||||
tasks {
|
||||
runServer {
|
||||
minecraftVersion(project.minecraft_version)
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
def buildProps = project.properties.clone()
|
||||
|
||||
filesMatching(['paper-plugin.yml']) {
|
||||
expand buildProps
|
||||
}
|
||||
}
|
||||
|
||||
compileTestJava.enabled = false
|
||||
|
||||
tasks.assemble {
|
||||
dependsOn(tasks.reobfJar)
|
||||
}
|
||||
|
||||
publisher {
|
||||
apiKeys {
|
||||
modrinth(System.getenv("MODRINTH_TOKEN"))
|
||||
nightbloom(System.getenv("PLATFORM_KEY"))
|
||||
}
|
||||
|
||||
setModrinthID(modrinth_id)
|
||||
setNightbloomID("craterlib")
|
||||
setVersionType("alpha")
|
||||
setChangelog(rootProject.file("changelog.md"))
|
||||
setProjectVersion("${minecraft_version}-${project.version}")
|
||||
setDisplayName("[Paper 1.21.3] CraterLib - ${project.version}")
|
||||
setGameVersions("1.21.3")
|
||||
setLoaders("paper")
|
||||
setArtifact(reobfJar.outputJar)
|
||||
}
|
||||
|
||||
publishModrinth.dependsOn(reobfJar)
|
||||
publishNightbloom.dependsOn(reobfJar)
|
@@ -0,0 +1,19 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public class PaperCommonHelper implements CommonPlatform {
|
||||
|
||||
public PaperCommonHelper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BridgedMinecraftServer getMCServer() {
|
||||
return BridgedMinecraftServer.of(MinecraftServer.getServer());
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.CompatUtils;
|
||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class PaperCompatHelper implements CompatUtils {
|
||||
|
||||
@Override
|
||||
public boolean isPlayerActive(BridgedPlayer player) {
|
||||
// Essentials Vanish
|
||||
if (ModloaderEnvironment.INSTANCE.isModLoaded("Essentials")) {
|
||||
return !isEssentialsVanished(player);
|
||||
}
|
||||
|
||||
// PhantomAdmin Vanish
|
||||
if (ModloaderEnvironment.INSTANCE.isModLoaded("PhantomAdmin"))
|
||||
return !isPhantomVanished(player);
|
||||
|
||||
// Other vanish mods
|
||||
try {
|
||||
Player p = (Player) player.toMojangServerPlayer();
|
||||
for (MetadataValue meta : p.getMetadata("vanished")) {
|
||||
if (meta.asBoolean()) return true;
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSkinUUID(BridgedPlayer player) {
|
||||
return player.getStringUUID();
|
||||
}
|
||||
|
||||
private boolean isEssentialsVanished(BridgedPlayer player) {
|
||||
try {
|
||||
Plugin p = Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
if (p == null)
|
||||
return false;
|
||||
|
||||
Method getUser = p.getClass().getMethod("getUser", String.class);
|
||||
Object essentialsPlayer = getUser.invoke(p, ChatUtils.resolve(player.getName(), false));
|
||||
|
||||
if (essentialsPlayer != null) {
|
||||
Method isVanished = essentialsPlayer.getClass().getMethod("isVanished");
|
||||
return (boolean) isVanished.invoke(essentialsPlayer);
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isPhantomVanished(BridgedPlayer player) {
|
||||
try {
|
||||
Plugin p = Bukkit.getPluginManager().getPlugin("PhantomAdmin");
|
||||
if (p == null)
|
||||
return false;
|
||||
|
||||
Method isInvisible = p.getClass().getDeclaredMethod("isInvisible", Player.class);
|
||||
isInvisible.setAccessible(true);
|
||||
|
||||
return (boolean) isInvisible.invoke(p, (Player) player.toMojangServerPlayer());
|
||||
} catch (Exception ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -4,19 +4,18 @@ import com.hypherionmc.craterlib.core.platform.Environment;
|
||||
import com.hypherionmc.craterlib.core.platform.LoaderType;
|
||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public class ForgeLoaderHelper implements ModloaderEnvironment {
|
||||
public class PaperLoaderHelper implements ModloaderEnvironment {
|
||||
|
||||
public ForgeLoaderHelper() {
|
||||
public PaperLoaderHelper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,54 +25,46 @@ public class ForgeLoaderHelper implements ModloaderEnvironment {
|
||||
|
||||
@Override
|
||||
public LoaderType getLoaderType() {
|
||||
return LoaderType.FORGE;
|
||||
return LoaderType.PAPER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGameVersion() {
|
||||
return SharedConstants.VERSION_STRING;
|
||||
return SharedConstants.getCurrentVersion().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getGameFolder() {
|
||||
return Minecraft.getInstance().gameDirectory;
|
||||
return new File(".");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getConfigFolder() {
|
||||
return FMLPaths.CONFIGDIR.get().toFile();
|
||||
return new File("config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getModsFolder() {
|
||||
return FMLPaths.MODSDIR.get().toFile();
|
||||
return Bukkit.getPluginsFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Environment getEnvironment() {
|
||||
switch (FMLLoader.getDist()) {
|
||||
case CLIENT -> {
|
||||
return Environment.CLIENT;
|
||||
}
|
||||
case DEDICATED_SERVER -> {
|
||||
return Environment.SERVER;
|
||||
}
|
||||
}
|
||||
return Environment.UNKNOWN;
|
||||
return Environment.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModLoaded(String modid) {
|
||||
return ModList.get().isLoaded(modid);
|
||||
return Bukkit.getPluginManager().isPluginEnabled(modid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDevEnv() {
|
||||
return !FMLLoader.isProduction();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModCount() {
|
||||
return ModList.get().size();
|
||||
return (int) Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(Plugin::isEnabled).count();
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.hypherionmc.craterlib.paper;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
|
||||
|
||||
public class CraterLibBootstrap implements PluginBootstrap {
|
||||
|
||||
@Override
|
||||
public void bootstrap(BootstrapContext bootstrapContext) {
|
||||
CraterConstants.LOG.info("Hello from CraterLib");
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.hypherionmc.craterlib.paper;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterRegisterCommandEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class CraterLibPlugin extends JavaPlugin {
|
||||
|
||||
private final PaperEventListener listener = new PaperEventListener();
|
||||
|
||||
public CraterLibPlugin() {
|
||||
super();
|
||||
InternalServiceUtil.loader = getClassLoader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
listener.onServerStarting(MinecraftServer.getServer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent(MinecraftServer.getServer().createCommandSourceStack().dispatcher()));
|
||||
getServer().getPluginManager().registerEvents(listener, this);
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(this, listener::onServerStarted);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,113 @@
|
||||
package com.hypherionmc.craterlib.paper;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.common.CraterPlayerDeathEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.PlayerPreLoginEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.*;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.advancements.BridgedAdvancement;
|
||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.craftbukkit.advancement.CraftAdvancement;
|
||||
import org.bukkit.craftbukkit.damage.CraftDamageSource;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.server.ServerCommandEvent;
|
||||
|
||||
public class PaperEventListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(
|
||||
new CraterPlayerDeathEvent(BridgedPlayer.of(((CraftPlayer) event.getPlayer()).getHandle()), ((CraftDamageSource) event.getDamageSource()).getHandle())
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onAdvancement(PlayerAdvancementDoneEvent event) {
|
||||
if (((CraftAdvancement) event.getAdvancement()).getHandle().value().display().isEmpty() || !((CraftAdvancement) event.getAdvancement()).getHandle().value().display().get().shouldAnnounceChat())
|
||||
return;
|
||||
|
||||
CraterEventBus.INSTANCE.postEvent(
|
||||
new CraterAdvancementEvent(BridgedPlayer.of(((CraftPlayer) event.getPlayer()).getHandle()), BridgedAdvancement.of(((CraftAdvancement) event.getAdvancement()).getHandle().value()))
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(((CraftPlayer) event.getPlayer()).getHandle())));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(((CraftPlayer) event.getPlayer()).getHandle())));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onServerChat(AsyncChatEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(
|
||||
new CraterServerChatEvent(BridgedPlayer.of(((CraftPlayer) event.getPlayer()).getHandle()), PlainTextComponentSerializer.plainText().serialize(event.message()), event.message())
|
||||
);
|
||||
}
|
||||
|
||||
public void onServerStarting(MinecraftServer server) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Starting(BridgedMinecraftServer.of(server)));
|
||||
}
|
||||
|
||||
public void onServerStarted() {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Started(BridgedMinecraftServer.of(MinecraftServer.getServer())));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onCommandEvent(PlayerCommandPreprocessEvent event) {
|
||||
CommandSourceStack stack = null;
|
||||
|
||||
if (event.getPlayer() instanceof CraftPlayer craftPlayer) {
|
||||
stack = craftPlayer.getHandle().createCommandSourceStack();
|
||||
} else if (event.getPlayer() instanceof ConsoleCommandSender) {
|
||||
stack = MinecraftServer.getServer().createCommandSourceStack();
|
||||
}
|
||||
|
||||
if (stack == null)
|
||||
return;
|
||||
|
||||
String cmd = event.getMessage().substring(1);
|
||||
|
||||
CommandDispatcher<CommandSourceStack> dispatcher = MinecraftServer.getServer().getCommands().getDispatcher();
|
||||
ParseResults<CommandSourceStack> parseResults = dispatcher.parse(cmd, stack);
|
||||
CraterEventBus.INSTANCE.postEvent(CraterCommandEvent.of(parseResults, cmd));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onServerCommandEvent(ServerCommandEvent event) {
|
||||
CommandSourceStack stack = MinecraftServer.getServer().createCommandSourceStack();
|
||||
|
||||
String cmd = event.getCommand();
|
||||
|
||||
CommandDispatcher<CommandSourceStack> dispatcher = MinecraftServer.getServer().getCommands().getDispatcher();
|
||||
ParseResults<CommandSourceStack> parseResults = dispatcher.parse(cmd, stack);
|
||||
CraterEventBus.INSTANCE.postEvent(CraterCommandEvent.of(parseResults, cmd));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
|
||||
PlayerPreLoginEvent playerPreLoginEvent = new PlayerPreLoginEvent(null, BridgedGameProfile.of(new GameProfile(event.getUniqueId(), event.getName())));
|
||||
CraterEventBus.INSTANCE.postEvent(playerPreLoginEvent);
|
||||
|
||||
if (playerPreLoginEvent.wasCancelled() || playerPreLoginEvent.getMessage() != null) {
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, playerPreLoginEvent.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
com.hypherionmc.craterlib.common.PaperCommonHelper
|
@@ -0,0 +1 @@
|
||||
com.hypherionmc.craterlib.common.PaperCompatHelper
|
@@ -0,0 +1 @@
|
||||
com.hypherionmc.craterlib.common.PaperLoaderHelper
|
8
1.21.2/Paper/src/main/resources/paper-plugin.yml
Normal file
8
1.21.2/Paper/src/main/resources/paper-plugin.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
name: CraterLib
|
||||
version: ${version}
|
||||
description: "A Modding API used to create 'universal' mods"
|
||||
main: com.hypherionmc.craterlib.paper.CraterLibPlugin
|
||||
author: HypherionSA
|
||||
api-version: '1.21.3'
|
||||
bootstrapper: com.hypherionmc.craterlib.paper.CraterLibBootstrap
|
||||
load: STARTUP
|
@@ -3,7 +3,8 @@ plugins {
|
||||
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
|
||||
id "xyz.wagyourtail.unimined" version "1.3.9" apply false
|
||||
id "com.hypherionmc.modutils.modpublisher" version "2.1.6"
|
||||
id "com.hypherionmc.modutils.orion" version "1.0.+"
|
||||
id "com.hypherionmc.modutils.orion" version "1.0.24"
|
||||
id "com.hypherionmc.modutils.orion.origami" version "1.0.24" apply false
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
@@ -30,6 +31,10 @@ subprojects {
|
||||
apply plugin: 'com.github.johnrengelman.shadow'
|
||||
apply plugin: 'com.hypherionmc.modutils.modpublisher'
|
||||
|
||||
if (project.name === "Paper") {
|
||||
apply plugin: 'com.hypherionmc.modutils.orion.origami'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
|
||||
@@ -95,17 +100,19 @@ subprojects {
|
||||
* = DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING =
|
||||
* ===============================================================================
|
||||
*/
|
||||
unimined.minecraft(sourceSets.main, true) {
|
||||
version minecraft_version
|
||||
if (project.name !== "Paper") {
|
||||
unimined.minecraft(sourceSets.main, true) {
|
||||
version minecraft_version
|
||||
|
||||
mappings {
|
||||
mojmap()
|
||||
devNamespace "mojmap"
|
||||
}
|
||||
mappings {
|
||||
mojmap()
|
||||
devNamespace "mojmap"
|
||||
}
|
||||
|
||||
mods {
|
||||
remap(configurations.stupidRemapArch) {
|
||||
catchAWNamespaceAssertion()
|
||||
mods {
|
||||
remap(configurations.stupidRemapArch) {
|
||||
catchAWNamespaceAssertion()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
1.21.2/changelog.md
Normal file
11
1.21.2/changelog.md
Normal file
@@ -0,0 +1,11 @@
|
||||
**New Features**:
|
||||
|
||||
- Paper Support. Currently only available on Modrinth and NightBloom
|
||||
|
||||
**Bug Fixes**:
|
||||
|
||||
- Fixed Vanish compact API being swapped
|
||||
|
||||
**Changes**:
|
||||
|
||||
- Config library now logs which line of the config the error is on
|
@@ -1,7 +1,7 @@
|
||||
#Project
|
||||
version_major=2
|
||||
version_minor=1
|
||||
version_patch=1
|
||||
version_patch=2
|
||||
version_build=0
|
||||
|
||||
#Mod
|
||||
@@ -10,18 +10,18 @@ mod_id=craterlib
|
||||
mod_name=CraterLib
|
||||
|
||||
# Shared
|
||||
minecraft_version=1.21.2
|
||||
minecraft_version=1.21.3
|
||||
project_group=com.hypherionmc.craterlib
|
||||
|
||||
# Fabric
|
||||
fabric_loader=0.16.7
|
||||
fabric_api=0.106.1+1.21.2
|
||||
fabric_api=0.107.3+1.21.3
|
||||
|
||||
# Forge
|
||||
forge_version=50.0.6
|
||||
|
||||
# NeoForged
|
||||
neoforge_version=0-beta
|
||||
neoforge_version=16-beta
|
||||
|
||||
# Dependencies
|
||||
moon_config=1.0.10
|
||||
|
@@ -14,4 +14,6 @@ pluginManagement {
|
||||
}
|
||||
|
||||
rootProject.name = 'CraterLib'
|
||||
include("Common", "Fabric", "NeoForge")
|
||||
include("Common", "Fabric", "NeoForge")
|
||||
include 'Paper'
|
||||
|
||||
|
Reference in New Issue
Block a user