[FEAT] More Nojang abstractions and compat layers (SDLink)
This commit is contained in:
@@ -9,8 +9,11 @@ shadowJar {
|
||||
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")
|
||||
}
|
||||
@@ -43,9 +46,7 @@ processResources {
|
||||
publishing {
|
||||
publications {
|
||||
mavenCommon(MavenPublication) {
|
||||
groupId project.group
|
||||
artifactId project.archivesBaseName
|
||||
version project.version
|
||||
from components.java
|
||||
|
||||
pom.withXml {
|
||||
|
@@ -6,8 +6,8 @@ import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||
import org.apache.commons.lang3.function.TriConsumer;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.util.TriConsumer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
@@ -0,0 +1,13 @@
|
||||
package com.hypherionmc.craterlib.core.platform;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
||||
|
||||
public interface CompatUtils {
|
||||
|
||||
public static final CompatUtils INSTANCE = InternalServiceUtil.load(CompatUtils.class);
|
||||
|
||||
boolean isPlayerActive(BridgedPlayer player);
|
||||
String getSkinUUID(BridgedPlayer player);
|
||||
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package com.hypherionmc.craterlib.nojang.commands;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import net.minecraft.commands.CommandSource;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class BridgedFakePlayer {
|
||||
|
||||
final MojangBridge internal;
|
||||
|
||||
public BridgedFakePlayer(BridgedMinecraftServer server, int perm, String name) {
|
||||
internal = new MojangBridge(server.toMojang(), perm, name, this::onSuccess, this::onError);
|
||||
}
|
||||
|
||||
public abstract void onSuccess(Supplier<net.kyori.adventure.text.Component> supplier, Boolean aBoolean);
|
||||
|
||||
public void onError(net.kyori.adventure.text.Component component) {
|
||||
this.onSuccess(() -> component, false);
|
||||
}
|
||||
|
||||
public CommandSourceStack toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
static class MojangBridge extends CommandSourceStack {
|
||||
|
||||
private final BiConsumer<Supplier<net.kyori.adventure.text.Component>, Boolean> successCallback;
|
||||
public final Consumer<net.kyori.adventure.text.Component> errorCallback;
|
||||
|
||||
MojangBridge(MinecraftServer server, int perm, String name, BiConsumer<Supplier<net.kyori.adventure.text.Component>, Boolean> successCallback, Consumer<net.kyori.adventure.text.Component> errorCallback) {
|
||||
super(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, server.overworld(), perm, name, Component.literal(name), server, null);
|
||||
this.successCallback = successCallback;
|
||||
this.errorCallback = errorCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSuccess(Supplier<Component> supplier, boolean bl) {
|
||||
successCallback.accept(() -> ChatUtils.mojangToAdventure(supplier.get()), bl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendFailure(Component arg) {
|
||||
errorCallback.accept(ChatUtils.mojangToAdventure(arg));
|
||||
}
|
||||
}
|
||||
}
|
@@ -47,6 +47,8 @@ public class CommandsRegistry {
|
||||
cmd.getExecutor().accept(BridgedCommandSourceStack.of(context.getSource()));
|
||||
return 1;
|
||||
});
|
||||
|
||||
dispatcher.register(command);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -74,6 +76,8 @@ public class CommandsRegistry {
|
||||
|
||||
return 1;
|
||||
})));
|
||||
|
||||
dispatcher.register(command);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.hypherionmc.craterlib.nojang.server;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
import com.hypherionmc.craterlib.nojang.commands.BridgedFakePlayer;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -79,6 +80,10 @@ public class BridgedMinecraftServer {
|
||||
internal.getPlayerList().getBans().add(new UserBanListEntry(profile.toMojang()));
|
||||
}
|
||||
|
||||
public void executeCommand(BridgedMinecraftServer server, BridgedFakePlayer player, String command) {
|
||||
internal.getCommands().performPrefixedCommand(player.toMojang(), command);
|
||||
}
|
||||
|
||||
public MinecraftServer toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
Reference in New Issue
Block a user