mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-03-25 16:22:03 +01:00
Fabric improvements
Mainly in commands - the old permissions file no longer needs to exist.
This commit is contained in:
parent
a612be60aa
commit
254f0da03c
11 changed files with 81 additions and 158 deletions
|
@ -19,6 +19,9 @@ dependencies {
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
modImplementation(libs.fabric.api)
|
modImplementation(libs.fabric.api)
|
||||||
|
|
||||||
|
// This should be in the libs TOML, but something about modImplementation AND include just doesn't work
|
||||||
|
include(modImplementation("me.lucko", "fabric-permissions-api", "0.2-SNAPSHOT"))
|
||||||
|
|
||||||
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
||||||
// You may need to force-disable transitiveness on them.
|
// You may need to force-disable transitiveness on them.
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,14 @@
|
||||||
|
|
||||||
package org.geysermc.geyser.platform.fabric;
|
package org.geysermc.geyser.platform.fabric;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.geysermc.geyser.GeyserLogger;
|
import org.geysermc.geyser.GeyserLogger;
|
||||||
|
import org.geysermc.geyser.text.ChatColor;
|
||||||
|
|
||||||
public class GeyserFabricLogger implements GeyserLogger {
|
public class GeyserFabricLogger implements GeyserLogger {
|
||||||
|
|
||||||
private final Logger logger = LogManager.getLogger("geyser-fabric");
|
private final Logger logger = LogManager.getLogger("geyser-fabric");
|
||||||
|
|
||||||
private boolean debug;
|
private boolean debug;
|
||||||
|
@ -69,6 +71,16 @@ public class GeyserFabricLogger implements GeyserLogger {
|
||||||
logger.info(message);
|
logger.info(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(Component message) {
|
||||||
|
// As of Java Edition 1.19.2, Fabric's console doesn't natively support legacy format
|
||||||
|
String flattened = LegacyComponentSerializer.legacySection().serialize(message);
|
||||||
|
// Add the reset at the end, or else format will persist... forever.
|
||||||
|
// https://cdn.discordapp.com/attachments/573909525132738590/1033904509170225242/unknown.png
|
||||||
|
String text = ChatColor.toANSI(flattened) + ChatColor.ANSI_RESET;
|
||||||
|
info(text);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void debug(String message) {
|
public void debug(String message) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.api.ModContainer;
|
import net.fabricmc.loader.api.ModContainer;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
@ -55,29 +56,21 @@ import org.geysermc.geyser.util.FileUtils;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class GeyserFabricMod implements ModInitializer, GeyserBootstrap {
|
public class GeyserFabricMod implements ModInitializer, GeyserBootstrap {
|
||||||
|
|
||||||
private static GeyserFabricMod instance;
|
private static GeyserFabricMod instance;
|
||||||
|
|
||||||
private boolean reloading;
|
private boolean reloading;
|
||||||
|
|
||||||
private GeyserImpl connector;
|
private GeyserImpl geyser;
|
||||||
private ModContainer mod;
|
private ModContainer mod;
|
||||||
private Path dataFolder;
|
private Path dataFolder;
|
||||||
private MinecraftServer server;
|
private MinecraftServer server;
|
||||||
|
|
||||||
/**
|
|
||||||
* Commands that don't require any permission level to ran
|
|
||||||
*/
|
|
||||||
private List<String> playerCommands;
|
|
||||||
private final List<GeyserFabricCommandExecutor> commandExecutors = new ArrayList<>();
|
|
||||||
|
|
||||||
private GeyserCommandManager geyserCommandManager;
|
private GeyserCommandManager geyserCommandManager;
|
||||||
private GeyserFabricConfiguration geyserConfig;
|
private GeyserFabricConfiguration geyserConfig;
|
||||||
private GeyserFabricLogger geyserLogger;
|
private GeyserFabricLogger geyserLogger;
|
||||||
|
@ -111,8 +104,6 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap {
|
||||||
File configFile = FileUtils.fileOrCopiedFromResource(dataFolder.resolve("config.yml").toFile(), "config.yml",
|
File configFile = FileUtils.fileOrCopiedFromResource(dataFolder.resolve("config.yml").toFile(), "config.yml",
|
||||||
(x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()), this);
|
(x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()), this);
|
||||||
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserFabricConfiguration.class);
|
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserFabricConfiguration.class);
|
||||||
File permissionsFile = fileOrCopiedFromResource(dataFolder.resolve("permissions.yml").toFile(), "permissions.yml");
|
|
||||||
this.playerCommands = Arrays.asList(FileUtils.loadConfig(permissionsFile, GeyserFabricPermissions.class).getCommands());
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LogManager.getLogger("geyser-fabric").error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex);
|
LogManager.getLogger("geyser-fabric").error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex);
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
@ -123,10 +114,14 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap {
|
||||||
|
|
||||||
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
|
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
|
||||||
|
|
||||||
|
this.geyser = GeyserImpl.load(PlatformType.FABRIC, this);
|
||||||
|
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
// Server has yet to start
|
// Server has yet to start
|
||||||
// Register onDisable so players are properly kicked
|
// Register onDisable so players are properly kicked
|
||||||
ServerLifecycleEvents.SERVER_STOPPING.register((server) -> onDisable());
|
ServerLifecycleEvents.SERVER_STOPPING.register((server) -> onDisable());
|
||||||
|
|
||||||
|
ServerPlayConnectionEvents.JOIN.register((handler, $, $$) -> GeyserFabricUpdateListener.onPlayReady(handler));
|
||||||
} else {
|
} else {
|
||||||
// Server has started and this is a reload
|
// Server has started and this is a reload
|
||||||
startGeyser(this.server);
|
startGeyser(this.server);
|
||||||
|
@ -170,38 +165,37 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap {
|
||||||
|
|
||||||
geyserConfig.loadFloodgate(this, floodgate.orElse(null));
|
geyserConfig.loadFloodgate(this, floodgate.orElse(null));
|
||||||
|
|
||||||
this.connector = GeyserImpl.load(PlatformType.FABRIC, this);
|
GeyserImpl.start();
|
||||||
GeyserImpl.start(); // shrug
|
|
||||||
|
|
||||||
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(connector);
|
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
|
||||||
|
|
||||||
this.geyserCommandManager = new GeyserCommandManager(connector);
|
this.geyserCommandManager = new GeyserCommandManager(geyser);
|
||||||
this.geyserCommandManager.init();
|
this.geyserCommandManager.init();
|
||||||
|
|
||||||
this.geyserWorldManager = new GeyserFabricWorldManager(server);
|
this.geyserWorldManager = new GeyserFabricWorldManager(server);
|
||||||
|
|
||||||
// Start command building
|
// Start command building
|
||||||
// Set just "geyser" as the help command
|
// Set just "geyser" as the help command
|
||||||
GeyserFabricCommandExecutor helpExecutor = new GeyserFabricCommandExecutor(connector,
|
GeyserFabricCommandExecutor helpExecutor = new GeyserFabricCommandExecutor(geyser,
|
||||||
(GeyserCommand) connector.commandManager().getCommands().get("help"), !playerCommands.contains("help"));
|
(GeyserCommand) geyser.commandManager().getCommands().get("help"));
|
||||||
commandExecutors.add(helpExecutor);
|
|
||||||
LiteralArgumentBuilder<CommandSourceStack> builder = Commands.literal("geyser").executes(helpExecutor);
|
LiteralArgumentBuilder<CommandSourceStack> builder = Commands.literal("geyser").executes(helpExecutor);
|
||||||
|
|
||||||
// Register all subcommands as valid
|
// Register all subcommands as valid
|
||||||
for (Map.Entry<String, Command> command : connector.commandManager().getCommands().entrySet()) {
|
for (Map.Entry<String, Command> command : geyser.commandManager().getCommands().entrySet()) {
|
||||||
GeyserFabricCommandExecutor executor = new GeyserFabricCommandExecutor(connector, (GeyserCommand) command.getValue(),
|
GeyserFabricCommandExecutor executor = new GeyserFabricCommandExecutor(geyser, (GeyserCommand) command.getValue());
|
||||||
!playerCommands.contains(command.getKey()));
|
builder.then(Commands.literal(command.getKey())
|
||||||
commandExecutors.add(executor);
|
.executes(executor)
|
||||||
builder.then(Commands.literal(command.getKey()).executes(executor));
|
// Could also test for Bedrock but depending on when this is called it may backfire
|
||||||
|
.requires(executor::testPermission));
|
||||||
}
|
}
|
||||||
server.getCommands().getDispatcher().register(builder);
|
server.getCommands().getDispatcher().register(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (connector != null) {
|
if (geyser != null) {
|
||||||
connector.shutdown();
|
geyser.shutdown();
|
||||||
connector = null;
|
geyser = null;
|
||||||
}
|
}
|
||||||
if (!reloading) {
|
if (!reloading) {
|
||||||
this.server = null;
|
this.server = null;
|
||||||
|
@ -267,34 +261,6 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap {
|
||||||
this.reloading = reloading;
|
this.reloading = reloading;
|
||||||
}
|
}
|
||||||
|
|
||||||
private File fileOrCopiedFromResource(File file, String name) throws IOException {
|
|
||||||
if (!file.exists()) {
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
|
||||||
file.createNewFile();
|
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
|
||||||
InputStream input = getResource(name);
|
|
||||||
|
|
||||||
byte[] bytes = new byte[input.available()];
|
|
||||||
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
|
||||||
input.read(bytes);
|
|
||||||
|
|
||||||
for(char c : new String(bytes).toCharArray()) {
|
|
||||||
fos.write(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
fos.flush();
|
|
||||||
input.close();
|
|
||||||
fos.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<GeyserFabricCommandExecutor> getCommandExecutors() {
|
|
||||||
return commandExecutors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GeyserFabricMod getInstance() {
|
public static GeyserFabricMod getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,26 +25,19 @@
|
||||||
|
|
||||||
package org.geysermc.geyser.platform.fabric;
|
package org.geysermc.geyser.platform.fabric;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import org.geysermc.geyser.Constants;
|
||||||
|
import org.geysermc.geyser.platform.fabric.command.FabricCommandSender;
|
||||||
|
import org.geysermc.geyser.util.VersionCheckUtils;
|
||||||
|
|
||||||
/**
|
public final class GeyserFabricUpdateListener {
|
||||||
* A class outline of the permissions.yml file
|
public static void onPlayReady(ServerGamePacketListenerImpl handler) {
|
||||||
*/
|
if (Permissions.check(handler.player, Constants.UPDATE_PERMISSION, 2)) {
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
VersionCheckUtils.checkForGeyserUpdate(() -> new FabricCommandSender(handler.player.createCommandSourceStack()));
|
||||||
public class GeyserFabricPermissions {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
private GeyserFabricUpdateListener() {
|
||||||
* The minimum permission level a command source must have in order for it to run commands that are restricted
|
|
||||||
*/
|
|
||||||
@JsonIgnore
|
|
||||||
public static final int RESTRICTED_MIN_LEVEL = 2;
|
|
||||||
|
|
||||||
@JsonProperty("commands")
|
|
||||||
private String[] commands;
|
|
||||||
|
|
||||||
public String[] getCommands() {
|
|
||||||
return this.commands;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,12 +25,13 @@
|
||||||
|
|
||||||
package org.geysermc.geyser.platform.fabric.command;
|
package org.geysermc.geyser.platform.fabric.command;
|
||||||
|
|
||||||
|
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
import org.geysermc.geyser.command.GeyserCommandSource;
|
import org.geysermc.geyser.command.GeyserCommandSource;
|
||||||
import org.geysermc.geyser.platform.fabric.GeyserFabricMod;
|
|
||||||
import org.geysermc.geyser.text.ChatColor;
|
import org.geysermc.geyser.text.ChatColor;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
@ -57,22 +58,23 @@ public class FabricCommandSender implements GeyserCommandSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(net.kyori.adventure.text.Component message) {
|
||||||
|
if (source.getEntity() instanceof ServerPlayer player) {
|
||||||
|
String decoded = GsonComponentSerializer.gson().serialize(message);
|
||||||
|
player.displayClientMessage(Component.Serializer.fromJson(decoded), false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GeyserCommandSource.super.sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConsole() {
|
public boolean isConsole() {
|
||||||
return !(source.getEntity() instanceof ServerPlayer);
|
return !(source.getEntity() instanceof ServerPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(String s) {
|
public boolean hasPermission(String permission) {
|
||||||
// Mostly copied from fabric's world manager since the method there takes a GeyserSession
|
return Permissions.check(source, permission);
|
||||||
|
|
||||||
// Workaround for our commands because fabric doesn't have native permissions
|
|
||||||
for (GeyserFabricCommandExecutor executor : GeyserFabricMod.getInstance().getCommandExecutors()) {
|
|
||||||
if (executor.getCommand().permission().equals(s)) {
|
|
||||||
return executor.canRun(source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,12 @@ package org.geysermc.geyser.platform.fabric.command;
|
||||||
|
|
||||||
import com.mojang.brigadier.Command;
|
import com.mojang.brigadier.Command;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
import org.geysermc.geyser.command.GeyserCommand;
|
import org.geysermc.geyser.command.GeyserCommand;
|
||||||
import org.geysermc.geyser.command.GeyserCommandExecutor;
|
import org.geysermc.geyser.command.GeyserCommandExecutor;
|
||||||
import org.geysermc.geyser.platform.fabric.GeyserFabricMod;
|
import org.geysermc.geyser.platform.fabric.GeyserFabricMod;
|
||||||
import org.geysermc.geyser.platform.fabric.GeyserFabricPermissions;
|
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.text.ChatColor;
|
import org.geysermc.geyser.text.ChatColor;
|
||||||
import org.geysermc.geyser.text.GeyserLocale;
|
import org.geysermc.geyser.text.GeyserLocale;
|
||||||
|
@ -40,27 +40,15 @@ import org.geysermc.geyser.text.GeyserLocale;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public class GeyserFabricCommandExecutor extends GeyserCommandExecutor implements Command<CommandSourceStack> {
|
public class GeyserFabricCommandExecutor extends GeyserCommandExecutor implements Command<CommandSourceStack> {
|
||||||
|
|
||||||
private final GeyserCommand command;
|
private final GeyserCommand command;
|
||||||
/**
|
|
||||||
* Whether the command requires an OP permission level of 2 or greater
|
|
||||||
*/
|
|
||||||
private final boolean requiresPermission;
|
|
||||||
|
|
||||||
public GeyserFabricCommandExecutor(GeyserImpl connector, GeyserCommand command, boolean requiresPermission) {
|
public GeyserFabricCommandExecutor(GeyserImpl connector, GeyserCommand command) {
|
||||||
super(connector, Collections.singletonMap(command.name(), command));
|
super(connector, Collections.singletonMap(command.name(), command));
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.requiresPermission = requiresPermission;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public boolean testPermission(CommandSourceStack source) {
|
||||||
* Determine whether or not a command source is allowed to run a given executor.
|
return Permissions.check(source, command.permission(), command.isSuggestedOpOnly() ? 2 : 0);
|
||||||
*
|
|
||||||
* @param source The command source attempting to run the command
|
|
||||||
* @return True if the command source is allowed to
|
|
||||||
*/
|
|
||||||
public boolean canRun(CommandSourceStack source) {
|
|
||||||
return !requiresPermission() || source.hasPermission(GeyserFabricPermissions.RESTRICTED_MIN_LEVEL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -68,8 +56,8 @@ public class GeyserFabricCommandExecutor extends GeyserCommandExecutor implement
|
||||||
CommandSourceStack source = (CommandSourceStack) context.getSource();
|
CommandSourceStack source = (CommandSourceStack) context.getSource();
|
||||||
FabricCommandSender sender = new FabricCommandSender(source);
|
FabricCommandSender sender = new FabricCommandSender(source);
|
||||||
GeyserSession session = getGeyserSession(sender);
|
GeyserSession session = getGeyserSession(sender);
|
||||||
if (!canRun(source)) {
|
if (!testPermission(source)) {
|
||||||
sender.sendMessage(GeyserLocale.getLocaleStringLog("geyser.bootstrap.command.permission_fail"));
|
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.locale()));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (this.command.name().equals("reload")) {
|
if (this.command.name().equals("reload")) {
|
||||||
|
@ -83,15 +71,4 @@ public class GeyserFabricCommandExecutor extends GeyserCommandExecutor implement
|
||||||
command.execute(session, sender, new String[0]);
|
command.execute(session, sender, new String[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeyserCommand getCommand() {
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the command requires permission level of {@link GeyserFabricPermissions#RESTRICTED_MIN_LEVEL} or higher to be ran
|
|
||||||
*/
|
|
||||||
public boolean requiresPermission() {
|
|
||||||
return requiresPermission;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.nukkitx.math.vector.Vector3i;
|
||||||
import com.nukkitx.nbt.NbtMap;
|
import com.nukkitx.nbt.NbtMap;
|
||||||
import com.nukkitx.nbt.NbtMapBuilder;
|
import com.nukkitx.nbt.NbtMapBuilder;
|
||||||
import com.nukkitx.nbt.NbtType;
|
import com.nukkitx.nbt.NbtType;
|
||||||
|
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.ListTag;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
@ -39,8 +40,6 @@ import net.minecraft.world.item.WrittenBookItem;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.LecternBlockEntity;
|
import net.minecraft.world.level.block.entity.LecternBlockEntity;
|
||||||
import org.geysermc.geyser.level.GeyserWorldManager;
|
import org.geysermc.geyser.level.GeyserWorldManager;
|
||||||
import org.geysermc.geyser.platform.fabric.GeyserFabricMod;
|
|
||||||
import org.geysermc.geyser.platform.fabric.command.GeyserFabricCommandExecutor;
|
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator;
|
import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator;
|
||||||
import org.geysermc.geyser.util.BlockEntityUtils;
|
import org.geysermc.geyser.util.BlockEntityUtils;
|
||||||
|
@ -124,14 +123,8 @@ public class GeyserFabricWorldManager extends GeyserWorldManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(GeyserSession session, String permission) {
|
public boolean hasPermission(GeyserSession session, String permission) {
|
||||||
// Workaround for our commands because fabric doesn't have native permissions
|
ServerPlayer player = getPlayer(session);
|
||||||
for (GeyserFabricCommandExecutor executor : GeyserFabricMod.getInstance().getCommandExecutors()) {
|
return Permissions.check(player, permission);
|
||||||
if (executor.getCommand().permission().equals(permission)) {
|
|
||||||
return executor.canRun(getPlayer(session).createCommandSourceStack());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerPlayer getPlayer(GeyserSession session) {
|
private ServerPlayer getPlayer(GeyserSession session) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.14.8",
|
"fabricloader": ">=0.14.8",
|
||||||
"fabric": "*",
|
"fabric": "*",
|
||||||
"minecraft": ">=1.19"
|
"minecraft": ">=1.19",
|
||||||
|
"fabric-permissions-api-v0": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
# Uncomment any commands that you wish to be run by clients
|
|
||||||
# Commented commands require an OP permission of 2 or greater
|
|
||||||
commands:
|
|
||||||
- help
|
|
||||||
- advancements
|
|
||||||
- statistics
|
|
||||||
- settings
|
|
||||||
- offhand
|
|
||||||
- tooltips
|
|
||||||
# - list
|
|
||||||
# - reload
|
|
||||||
# - version
|
|
||||||
# - dump
|
|
|
@ -26,6 +26,7 @@
|
||||||
package org.geysermc.geyser.text;
|
package org.geysermc.geyser.text;
|
||||||
|
|
||||||
public class ChatColor {
|
public class ChatColor {
|
||||||
|
public static final String ANSI_RESET = (char) 0x1b + "[0m";
|
||||||
|
|
||||||
public static final char ESCAPE = '§';
|
public static final char ESCAPE = '§';
|
||||||
public static final String BLACK = ESCAPE + "0";
|
public static final String BLACK = ESCAPE + "0";
|
||||||
|
@ -64,7 +65,7 @@ public class ChatColor {
|
||||||
string = string.replace(ITALIC, (char) 0x1b + "[3m");
|
string = string.replace(ITALIC, (char) 0x1b + "[3m");
|
||||||
string = string.replace(UNDERLINE, (char) 0x1b + "[4m");
|
string = string.replace(UNDERLINE, (char) 0x1b + "[4m");
|
||||||
string = string.replace(STRIKETHROUGH, (char) 0x1b + "[9m");
|
string = string.replace(STRIKETHROUGH, (char) 0x1b + "[9m");
|
||||||
string = string.replace(RESET, (char) 0x1b + "[0m");
|
string = string.replace(RESET, ANSI_RESET);
|
||||||
string = string.replace(BLACK, (char) 0x1b + "[0;30m");
|
string = string.replace(BLACK, (char) 0x1b + "[0;30m");
|
||||||
string = string.replace(DARK_BLUE, (char) 0x1b + "[0;34m");
|
string = string.replace(DARK_BLUE, (char) 0x1b + "[0;34m");
|
||||||
string = string.replace(DARK_GREEN, (char) 0x1b + "[0;32m");
|
string = string.replace(DARK_GREEN, (char) 0x1b + "[0;32m");
|
||||||
|
@ -83,19 +84,4 @@ public class ChatColor {
|
||||||
string = string.replace(WHITE, (char) 0x1b + "[37;1m");
|
string = string.replace(WHITE, (char) 0x1b + "[37;1m");
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String translateAlternateColorCodes(char color, String message) {
|
|
||||||
return message.replace(color, ESCAPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove all colour formatting tags from a message
|
|
||||||
*
|
|
||||||
* @param message Message to remove colour tags from
|
|
||||||
*
|
|
||||||
* @return The sanitised message
|
|
||||||
*/
|
|
||||||
public static String stripColors(String message) {
|
|
||||||
return message = message.replaceAll("(&([a-fk-or0-9]))","").replaceAll("(§([a-fk-or0-9]))","").replaceAll("s/\\x1b\\[[0-9;]*[a-zA-Z]//g","");
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -26,6 +26,9 @@ commodore = "2.2"
|
||||||
bungeecord = "a7c6ede"
|
bungeecord = "a7c6ede"
|
||||||
velocity = "3.0.0"
|
velocity = "3.0.0"
|
||||||
sponge = "8.0.0"
|
sponge = "8.0.0"
|
||||||
|
fabric-minecraft = "1.19.1"
|
||||||
|
fabric-loader = "0.14.8"
|
||||||
|
fabric-api = "0.58.5+1.19.1"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
jackson-annotations = { group = "com.fasterxml.jackson.core", name = "jackson-annotations", version.ref = "jackson" }
|
jackson-annotations = { group = "com.fasterxml.jackson.core", name = "jackson-annotations", version.ref = "jackson" }
|
||||||
|
@ -63,9 +66,9 @@ paper-api = { group = "io.papermc.paper", name = "paper-api", version.ref = "pap
|
||||||
paper-mojangapi = { group = "io.papermc.paper", name = "paper-mojangapi", version.ref = "paper" }
|
paper-mojangapi = { group = "io.papermc.paper", name = "paper-mojangapi", version.ref = "paper" }
|
||||||
|
|
||||||
# check these on https://modmuss50.me/fabric.html
|
# check these on https://modmuss50.me/fabric.html
|
||||||
fabric-minecraft = { group = "com.mojang", name = "minecraft", version = "1.19.1" }
|
fabric-minecraft = { group = "com.mojang", name = "minecraft", version.ref = "fabric-minecraft" }
|
||||||
fabric-loader = { group = "net.fabricmc", name = "fabric-loader", version = "0.14.8" }
|
fabric-loader = { group = "net.fabricmc", name = "fabric-loader", version.ref = "fabric-loader" }
|
||||||
fabric-api = { group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.58.5+1.19.1" }
|
fabric-api = { group = "net.fabricmc.fabric-api", name = "fabric-api", version.ref = "fabric-api" }
|
||||||
|
|
||||||
adapters-spigot = { group = "org.geysermc.geyser.adapters", name = "spigot-all", version.ref = "adapters" }
|
adapters-spigot = { group = "org.geysermc.geyser.adapters", name = "spigot-all", version.ref = "adapters" }
|
||||||
bungeecord-proxy = { group = "com.github.SpigotMC.BungeeCord", name = "bungeecord-proxy", version.ref = "bungeecord" }
|
bungeecord-proxy = { group = "com.github.SpigotMC.BungeeCord", name = "bungeecord-proxy", version.ref = "bungeecord" }
|
||||||
|
|
Loading…
Add table
Reference in a new issue