Search in sources :

Example 1 with GeyserSession

use of org.geysermc.geyser.session.GeyserSession in project Geyser by GeyserMC.

the class GeyserSpigotCommandExecutor method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    SpigotCommandSender commandSender = new SpigotCommandSender(sender);
    GeyserSession session = getGeyserSession(commandSender);
    if (args.length > 0) {
        GeyserCommand geyserCommand = getCommand(args[0]);
        if (geyserCommand != null) {
            if (!sender.hasPermission(geyserCommand.getPermission())) {
                String message = GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());
                commandSender.sendMessage(ChatColor.RED + message);
                return true;
            }
            if (geyserCommand.isBedrockOnly() && session == null) {
                sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.getLocale()));
                return true;
            }
            geyserCommand.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
            return true;
        }
    } else {
        getCommand("help").execute(session, commandSender, new String[0]);
        return true;
    }
    return true;
}
Also used : GeyserCommand(org.geysermc.geyser.command.GeyserCommand) GeyserSession(org.geysermc.geyser.session.GeyserSession)

Example 2 with GeyserSession

use of org.geysermc.geyser.session.GeyserSession in project Geyser by GeyserMC.

the class GeyserVelocityCommandExecutor method execute.

@Override
public void execute(Invocation invocation) {
    CommandSender sender = new VelocityCommandSender(invocation.source());
    GeyserSession session = getGeyserSession(sender);
    if (invocation.arguments().length > 0) {
        GeyserCommand command = getCommand(invocation.arguments()[0]);
        if (command != null) {
            if (!invocation.source().hasPermission(getCommand(invocation.arguments()[0]).getPermission())) {
                sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.getLocale()));
                return;
            }
            if (command.isBedrockOnly() && session == null) {
                sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", sender.getLocale()));
                return;
            }
            command.execute(session, sender, invocation.arguments().length > 1 ? Arrays.copyOfRange(invocation.arguments(), 1, invocation.arguments().length) : new String[0]);
        }
    } else {
        getCommand("help").execute(session, sender, new String[0]);
    }
}
Also used : GeyserCommand(org.geysermc.geyser.command.GeyserCommand) GeyserSession(org.geysermc.geyser.session.GeyserSession) CommandSender(org.geysermc.geyser.command.CommandSender)

Example 3 with GeyserSession

use of org.geysermc.geyser.session.GeyserSession in project Geyser by GeyserMC.

the class GeyserStandaloneGUI method startUpdateThread.

/**
 * Start the thread to update the form information every 1s
 */
public void startUpdateThread() {
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    Runnable periodicTask = () -> {
        if (GeyserImpl.getInstance() != null) {
            // Update player table
            playerTableModel.getDataVector().removeAllElements();
            for (GeyserSession player : GeyserImpl.getInstance().getSessionManager().getSessions().values()) {
                Vector<String> row = new Vector<>();
                row.add(player.getSocketAddress().getHostName());
                row.add(player.getPlayerEntity().getUsername());
                playerTableModel.addRow(row);
            }
            playerTableModel.fireTableDataChanged();
        }
        // Update ram graph
        final long freeMemory = Runtime.getRuntime().freeMemory();
        final long totalMemory = Runtime.getRuntime().totalMemory();
        final int freePercent = (int) (freeMemory * 100.0 / totalMemory + 0.5);
        ramValues.add(100 - freePercent);
        ramGraph.setXLabel(GeyserLocale.getLocaleStringLog("geyser.gui.graph.usage", String.format("%,d", (totalMemory - freeMemory) / MEGABYTE), freePercent));
        // Trim the list
        int k = ramValues.size();
        if (k > 10)
            ramValues.subList(0, k - 10).clear();
        // Update the graph
        ramGraph.setValues(ramValues);
    };
    // SwingUtilities.invokeLater is called so we don't run into threading issues with the GUI
    executor.scheduleAtFixedRate(() -> SwingUtilities.invokeLater(periodicTask), 0, 1, TimeUnit.SECONDS);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) GeyserSession(org.geysermc.geyser.session.GeyserSession) Vector(java.util.Vector)

Example 4 with GeyserSession

use of org.geysermc.geyser.session.GeyserSession in project Geyser by GeyserMC.

the class BedrockEmoteTranslator method translate.

@Override
public void translate(GeyserSession session, EmotePacket packet) {
    if (session.getGeyser().getConfig().getEmoteOffhandWorkaround() != EmoteOffhandWorkaroundOption.DISABLED) {
        // Activate the workaround - we should trigger the offhand now
        ServerboundPlayerActionPacket swapHandsPacket = new ServerboundPlayerActionPacket(PlayerAction.SWAP_HANDS, BlockUtils.POSITION_ZERO, Direction.DOWN);
        session.sendDownstreamPacket(swapHandsPacket);
        if (session.getGeyser().getConfig().getEmoteOffhandWorkaround() == EmoteOffhandWorkaroundOption.NO_EMOTES) {
            return;
        }
    }
    int javaId = session.getPlayerEntity().getEntityId();
    for (GeyserSession otherSession : session.getGeyser().getSessionManager().getSessions().values()) {
        if (otherSession != session) {
            if (otherSession.isClosed())
                continue;
            if (otherSession.getEventLoop().inEventLoop()) {
                playEmote(otherSession, javaId, packet.getEmoteId());
            } else {
                session.executeInEventLoop(() -> playEmote(otherSession, javaId, packet.getEmoteId()));
            }
        }
    }
}
Also used : GeyserSession(org.geysermc.geyser.session.GeyserSession) ServerboundPlayerActionPacket(com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket)

Example 5 with GeyserSession

use of org.geysermc.geyser.session.GeyserSession in project Geyser-Fabric by GeyserMC.

the class GeyserFabricCommandExecutor method run.

@Override
public int run(CommandContext context) {
    ServerCommandSource source = (ServerCommandSource) context.getSource();
    FabricCommandSender sender = new FabricCommandSender(source);
    GeyserSession session = getGeyserSession(sender);
    if (!canRun(source)) {
        sender.sendMessage(GeyserLocale.getLocaleStringLog("geyser.bootstrap.command.permission_fail"));
        return 0;
    }
    if (this.command.getName().equals("reload")) {
        GeyserFabricMod.getInstance().setReloading(true);
    }
    if (command.isBedrockOnly() && session == null) {
        sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", sender.getLocale()));
        return 0;
    }
    command.execute(session, sender, new String[0]);
    return 0;
}
Also used : GeyserSession(org.geysermc.geyser.session.GeyserSession) ServerCommandSource(net.minecraft.server.command.ServerCommandSource)

Aggregations

GeyserSession (org.geysermc.geyser.session.GeyserSession)12 GeyserCommand (org.geysermc.geyser.command.GeyserCommand)4 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 GeyserConfiguration (org.geysermc.geyser.configuration.GeyserConfiguration)2 GeyserLocale (org.geysermc.geyser.text.GeyserLocale)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonNodeType (com.fasterxml.jackson.databind.node.JsonNodeType)1 MsaAuthenticationService (com.github.steveice10.mc.auth.service.MsaAuthenticationService)1 PistonValueType (com.github.steveice10.mc.protocol.data.game.level.block.value.PistonValueType)1 ServerboundPlayerActionPacket (com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket)1 TcpSession (com.github.steveice10.packetlib.tcp.TcpSession)1 JWSObject (com.nimbusds.jose.JWSObject)1 JSONObject (com.nimbusds.jose.shaded.json.JSONObject)1 JSONValue (com.nimbusds.jose.shaded.json.JSONValue)1 Vector3i (com.nukkitx.math.vector.Vector3i)1