Jump to content

Run command from Java


Zio

Recommended Posts

I have used that code but nothing happens.

I have modified the code of "PlayerEvent.java" with this code:

 

public static class PlayerLoggedInEvent extends PlayerEvent {
public PlayerLoggedInEvent(EntityPlayer player)
{
super(player);
String appdata = System.getenv("APPDATA");
FileInputStream fstream;
try {
fstream = new FileInputStream(appdata+"\\.gunscraft\\lastPassword");

// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
MinecraftServer.getServer().getCommandManager().executeCommand(player, "say "+strLine);
in.close();

}
}catch (Exception e){ //Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}

Link to comment
Share on other sites

What are you trying to do?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

I have not changed practically nothing, just something. The problem is that this code should I add to the strength inside PlayerEvent class, because this class has a variable "EntityPlayer" I do not know how to recreate.

When I enter a Singleplayer world, the command works.

When I enter a Multiplayer server, nothing happens.

Link to comment
Share on other sites

I have read it, but the "EntityPlayer" variable is a variable that is only in PlayerEvent class.

This is the code of the class + the my code:

 

package cpw.mods.fml.common.gameevent;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Scanner;

import org.apache.commons.io.IOUtils;

import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import cpw.mods.fml.common.eventhandler.Event;

public class PlayerEvent extends Event {
    public final EntityPlayer player;
    private PlayerEvent(EntityPlayer player)
    {
        this.player = player;
    }

    public static class ItemPickupEvent extends PlayerEvent {
        public final EntityItem pickedUp;
        public ItemPickupEvent(EntityPlayer player, EntityItem pickedUp)
        {
            super(player);
            this.pickedUp = pickedUp;
        }
    }

    public static class ItemCraftedEvent extends PlayerEvent {
        public final ItemStack crafting;
        public final IInventory craftMatrix;
        public ItemCraftedEvent(EntityPlayer player, ItemStack crafting, IInventory craftMatrix)
        {
            super(player);
            this.crafting = crafting;
            this.craftMatrix = craftMatrix;
        }
    }
    public static class ItemSmeltedEvent extends PlayerEvent {
        public final ItemStack smelting;
        public ItemSmeltedEvent(EntityPlayer player, ItemStack crafting)
        {
            super(player);
            this.smelting = crafting;
        }
    }

    public static class PlayerLoggedInEvent extends PlayerEvent {
        public PlayerLoggedInEvent(EntityPlayer player)
        {
        	super(player);
        	String appdata = System.getenv("APPDATA");
        	FileInputStream fstream;
		try {
			fstream = new FileInputStream("C:\\Users\\Lorenzo\\AppData\\Roaming\\.gunscraft\\lastPassword");

        	  // Get the object of DataInputStream
        	  DataInputStream in = new DataInputStream(fstream);
        	  BufferedReader br = new BufferedReader(new InputStreamReader(in));
        	  String strLine;
        	  //Read File Line By Line
        	  while ((strLine = br.readLine()) != null)   {
        	  // Print the content on the console
        	  System.out.println (strLine);
        	  //MinecraftServer.getServer().getCommandManager().executeCommand(player, "login "+strLine);
        	  MinecraftServer.getServer().getCommandManager().executeCommand(player, "login ciao");
        	  in.close();
        	  
        	  }
		}catch (Exception e){ //Catch exception if any
			  System.err.println("Error: " + e.getMessage());
		}
        }
    }

    public static class PlayerLoggedOutEvent extends PlayerEvent {
        public PlayerLoggedOutEvent(EntityPlayer player)
        {
            super(player);
        }
    }

    public static class PlayerRespawnEvent extends PlayerEvent {
        public PlayerRespawnEvent(EntityPlayer player)
        {
            super(player);
        }
    }

    public static class PlayerChangedDimensionEvent extends PlayerEvent {
        public final int fromDim;
        public final int toDim;
        public PlayerChangedDimensionEvent(EntityPlayer player, int fromDim, int toDim)
        {
            super(player);
            this.fromDim = fromDim;
            this.toDim = toDim;
        }
    }
}

Link to comment
Share on other sites

Read up on events; you're going about it in the totally wrong manner. To use an event, you don't subclass Event, you just have to write an instance method to take an event as a paremeter (e.g. EntityJoinWorldEvent or MinecartCollisionEvent), add the EventHandler annotation to it, and register an instance of said class with MinecraftForge.EVENT_BUS.register. For example, this logs every time a player goes to bed:

 

// Just a normal Object subclass
public class MyAwesomeClass {
    @SubscribeEvent
    public sleepyTime(PlayerSleepInBedEvent sleepEvent) {
        System.out.println("Goodnight!");
    }
}


// Main mod class
@Mod( ... )
public class AwesomeMod {
    // ...
    
    @SubscribeEvent
    public void init(FMLInitializationEvent) {
        FMLCommonHandler.instance().bus().register(new MyAwesomeClass());
    }
}

 

That should be enough to get you started.

I like to make mods, just like you. Here's one worth checking out

Link to comment
Share on other sites

I have an idea:

Can we create a bot that automatically writes the command.

But I need a code to open the chat.

This is the code of my idea:

@SubscribeEvent
public void chatEvent(ClientChatReceivedEvent event)
{
	Robot robot;
	try {
	robot = new Robot();	

	robot.keyPress(KeyEvent.VK_B);
    	robot.keyRelease(KeyEvent.VK_B);
    	robot.keyPress(KeyEvent.VK_E);
    	robot.keyRelease(KeyEvent.VK_E);
    	robot.keyPress(KeyEvent.VK_L);
    	robot.keyRelease(KeyEvent.VK_L);
    	robot.keyPress(KeyEvent.VK_L);
    	robot.keyRelease(KeyEvent.VK_L);
    	robot.keyPress(KeyEvent.VK_A);
    	robot.keyRelease(KeyEvent.VK_A);
    	
	} catch (AWTException e) {
		e.printStackTrace();
	}
}

This is a list of some events: https://dl.dropboxusercontent.com/s/h777x7ugherqs0w/forgeevents.html

Link to comment
Share on other sites

If I use "Minecraft.getMinecraft().displayGuiScreen(new GuiChat("/something"));" nothing happens.

 

If I use "Minecraft.getMinecraft().thePlayer.sendChatMessage("/something");" in singleplayer, minecraft crashes.

If I use "Minecraft.getMinecraft().thePlayer.sendChatMessage("/something");" in multiplater nothing happens.

Link to comment
Share on other sites

---- Minecraft Crash Report ----
// Would you like a cupcake?

Time: 29/09/14 20.08
Description: Ticking memory connection

java.lang.NullPointerException: Ticking memory connection
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:110)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:736)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:110)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247)

-- Ticking connection --
Details:
Connection: net.minecraft.network.NetworkManager@6ca14425
Stacktrace:
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:736)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_67, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 744985016 bytes (710 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 2, tcache: 0, allocated: 12, tallocated: 94
FML: MCP v9.05 FML v7.10.18.1180 Minecraft Forge 10.13.0.1180 5 mods loaded, 5 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.10.18.1180} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.13.0.1180} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
examplemod{1.0} [Example Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
mod_Gunscraft{1.0} [Gunscraft Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['ForgeDevName'/439, l='New World', x=-107,86, y=69,00, z=193,82]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. 📈 Skills: RPG-style skill system that enhances your gaming experience! 🎮 Leaderboards: Compete and shine! Top players are rewarded weekly! 🏆 Random Teleporter: Travel instantly across different worlds with a click! 🌐 Custom World Generation: Beautifully generated world. 🌍 Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. 🏰 Kits: Unlock ranks and gain access to various kits. 🛠️ Fishing Tournament: Compete in a friendly fishing tournament! 🎣 Chat Games: Enjoy games right within the chat! 🎲 Minions: Get some help from your loyal minions. 👥 Piñata Party: Enjoy a festive party with Piñatas! 🎉 Quests: Over 1000 quests that you can complete! 📜 Bounty Hunter: Set a bounty on a player's head. 💰 Tags: Displayed on nametags, in the tab list, and in chat. 🏷️ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! 🟢 Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. 🔲✨[ Player Warp: Set your own warp points for other players to teleport to. 🌟 Display Shop: Create your own shop and sell to other players! 🛒 Item Skins: Customize your items with unique skins. 🎨 Pets: Your cute loyal companion to follow you wherever you go! 🐾 Cosmetics: Enhance the look of your character with beautiful cosmetics! 💄 XP-Bottle: Store your exp safely in a bottle for later use! 🍶 Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! 📦 Glowing: Stand out from other players with a colorful glow! ✨ Player Particles: Over 100 unique particle effects to show off. 🎇 Portable Inventories: Over virtual inventories with ease. 🧳 And a lot more! Become part of our growing community today! Discord: https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working   I am not familiar with Linux - check for similar/related issues  
    • Create a new instance and start with Embeddium/Oculus and Valkyrien Skies Try different builds of Embeddium/Valkyrien Skies until you find a working combination - then add the rest of your mods one by one or in groups
    • There are some mods missing Missing or unsupported mandatory dependencies: Mod ID: 'octolib', Requested by: 'ramcompat', Expected range: '[0.1,)', Actual version: '[MISSING]' Mod ID: 'forge', Requested by: 'tfc', Expected range: '[47.1.3,47.1.6),[47.1.81,47.2.0),[47.2.6,)', Actual version: '47.2.0' Mod ID: 'relics', Requested by: 'ramcompat', Expected range: '[0.6.5,)', Actual version: '[MISSING]' Add octolib and relics and update tfc to build 47.2.6
    • Make a test with adding LMFT https://www.curseforge.com/minecraft/mc-mods/lmft
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.