Send commands to the server in Minecraft Fabric mod - java

I am using Fabric for 1.19.3.
How do I send messages from the client to the server, imitating running commands from the chat.
I have tried using:
ClientPlayNetworkHandler.sendCommand("my command");
But it always gives an error saying net.fabricmc.fabric.impl.command.client.ClientCommandInternals.activeDispatcher is null
ClientPlayNetworkHandler.sendChatCommand("my command") does the same
By the way I'm running this in the ClientPlayConnectionEvents.Join event.
I have also tried:
MinecraftClient.getInstance().getServer().getCommandManager().executeWithPrefix(player, "my command");
But this also doesn't work because MinecraftClient.getInstance().getServer() is null.
I have searched a lot on the internet on how to do this but almost everything leads to creating custom commands in Fabric.

Related

Trying out Expo for React Native, just did an "init", getting socketException error?

Last week I started learning about React Native and using Expo. I created some small apps using "expo init (name)" etc, followed some tutorials, tried some stuff you know the drill.
Today I wanted to start working on a small app idea I have and wanted to do it using Expo CLI instead of React Native CLI first, since building, testing etc is supposed to be easier using Expo.
I just made a new project using "expo init (name)", selecting blank template (so nothing fancy) and running "npm start", then scanning the code with my smartphone app and the app crashes instantly. The error is as follows:
"Uncaught Error: java.net.SocketException: Connection reset"
What does this mean? How can I fix it? I really want to start today using Expo...
This happens when you mobile and system using different internet connection or port.
so try following
Make sure you have stable internet connection and your device and system connected with same internet connection
remove node_modules folder
run npm install
npm start --reset-cache
scan bar code to run it on your device

Java windows Service starts a new process but I'm unable to see it (although it's present on Task Manager)

I have a java app (which I made windows service using nnsm) that sets up sockets on localhost. When a message is received by that app it opens internet explorer.
When I run the app using cmd (e.g java -jar myServer.jar) it works as expected. An internet explorer instance starts.
When the app is being set up as a windows service and receives a message, it opens internet explorer but I'm unable to see it (although it is visible in Task Manager).
I want the process to start on the local system and be able to see it and interact with it
Any help or idea would be much appreciated.
Thanks

How to implemented push notification to java client

I'm building a java stand alone application. This application is installed on one pc. There is another java stand alone program that it is installed in another pc to another net.
Now I want to send a notification with these program. For example the program 1, send message "start update", and the program 2 read this message and can execute an activity.
Now how can I implemented this push notification.
I have also a php server, I don't know if this server is necessary.
It is a little strange question... you can use lot of technologies e.g. Rest, JMS, but also ugh you can send UDP packets or use a pipe on file system. It depends to what you have to send, for which purpose, with which security level.

How to simulate different server responses, including offline?

An app I am working on relies on connecting to a private, remote server to login via an API.
The other day, I got an ANR message and I think it was due to the server being offline (its a Windows Server that was being updated).
In my app, I am using the following code:
new ReadJSONFeedTask().execute(url).get();
Which turns an AsyncTask into a synchronous task (I believe!)
And because the server was offline, I think the app got hung up, causing the ANR (it's my only lead at the moment, and all seems to make sense, despite the code above is inside a Service class, which shouldn't cause an ANR, should it?)
So, I want to try an simulate the server being offline. I tried replacing the URL with one that simply doesn't work, by removing some letters from the hostname, but that only triggered an "UnknownHostException".
Is there any way to achieve this kind of simulation? I know there are tools for browsers to simulate low bandwidth etc, but have no idea what could be done when my app is running on Android and is trying to connect to a remote server that I can't really reboot at will.

RMI connection in javafx standalone application

I have the following problem with my javafx application:
I'm using RMI to connect client app to server, and everything goes fine, until I run application in web browser or standalone mode. In this case, RMI doesn't work properly, but don't throw any exceptions. I cant send any message to server. Problem disappears when I run program in IDE or by clicking on jar file.
I think, that it can be connected with some browser privileges, and application launched in that context probably doesn't have access to network adapter.
Any ideas how to fix that?
EDIT: There was an exception that was invisible for me: java.net.SocketPermission. So as I thought, access to socked is denied. What is the solution to this problem?
An unsigned applet can only connect to the host it was loaded from. So, either change your topology or sign the applet.

Categories