Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

CoalOres

Members
  • Joined

  • Last visited

Everything posted by CoalOres

  1. Whole class: package com.simpleafk; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.nio.charset.Charset; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import java.util.Timer; import java.util.TimerTask; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; public class wparty extends CommandBase { @Override public String getCommandName() { // TODO Auto-generated method stub return "wparty"; } @Override public String getCommandUsage(ICommandSender sender) { // TODO Auto-generated method stub return "wparty"; } @Override public boolean canCommandSenderUseCommand(ICommandSender icommandsender) { return true; } @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { String path = "config/whitelist.txt"; String line = null; try { FileReader file = new FileReader(path); BufferedReader buffered = new BufferedReader(file); sender.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_AQUA + "People on your invite list: ")); while((line = buffered.readLine()) != null) { Minecraft.getMinecraft().thePlayer.sendChatMessage("/party invite " + line ); Thread.sleep(100); } buffered.close(); } catch (IOException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } The file in question is totally fine, just need a better thing for the delay.
  2. This is for another part of it. And how do I count ticks?
  3. I've been using this code to execute a bulk operation: while((line = buffered.readLine()) != null) { Minecraft.getMinecraft().thePlayer.sendChatMessage("/party invite " + line ); Thread.sleep(100); It reads 100 lines, which works. However it freezes my Minecraft and because of this the time is not consistent, and so sometimes I get the message "Sending Commands too fast!", making it inconsistent.
  4. It crashes now when trying to run it: My code: Main: package com.simpleafk; import java.io.File; import java.io.IOException; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @Mod(modid="simpleafk", name= "Simple AFK", version="1.0", clientSideOnly = true) public class AFKMain { public static String path; //Creating instances. @Instance("simpleafk") public static AFKMain instance; @EventHandler public void preInit(FMLPreInitializationEvent event) { path = event.getSourceFile().getAbsolutePath().substring(0, path.lastIndexOf(File.separator)); MinecraftForge.EVENT_BUS.register(new ChatListener()); } @EventHandler public void init(FMLInitializationEvent event) { ClientCommandHandler.instance.registerCommand(new SampleCommand()); ClientCommandHandler.instance.registerCommand(new WhitelistAdd()); } } WhitelistAdd: package com.simpleafk; import java.io.BufferedOutputStream; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; import java.nio.charset.Charset; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatComponentText; public class WhitelistAdd extends CommandBase { private static final String FILE_PATH = ""; @Override public String getCommandName() { // TODO Auto-generated method stub return "wparty"; } @Override public String getCommandUsage(ICommandSender sender) { // TODO Auto-generated method stub return "wparty <add|remove|clear|list> <username>"; } @Override public boolean canCommandSenderUseCommand(ICommandSender icommandsender) { return true; } @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { // TODO Auto-generated method stub if (args.length == 0){ sender.addChatMessage(new ChatComponentText("You must specify a valid username!")); } else { if (args[0] == "add") { // The name of the file to open. String fileName = "whitelist.txt"; try { String user = args[1]; File file = new File(AFKMain.path + "\\whitelist.txt"); if (!file.exists()){ file.createNewFile(); } String absolutePath = file.getAbsolutePath(); // Assume default encoding. FileWriter fileWriter = new FileWriter(file.getAbsolutePath()); // Always wrap FileWriter in BufferedWriter. BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); // Note that write() does not automatically // append a newline character. bufferedWriter.write(user); bufferedWriter.newLine(); // Always close files. bufferedWriter.close(); Minecraft.getMinecraft().thePlayer.sendChatMessage("Done Writing! File is at:" ); } catch(IOException ex) { System.out.println( "Error writing to file '" + fileName + "'"); // Or we could just do this: // ex.printStackTrace(); } } else if (args[0] == "clear"){ } else if (args[0] == "remove"){ } } } }
  5. You have been the most unhelpful person, you aren't even trying to give me a simple explanation. What the heck do you mean by I need the variable in the main class to the substring?
  6. I'm really confused now, can you just do it with my code and paste it? I'm really not getting what I'm supposed to be doing.
  7. So I've added this to the processCommand: File file = new File(AFKMain.absolutePath + "\whitelist.txt"); String absolutePath = file.getAbsolutePath(); String filePath = absolutePath.substring(0,absolutePath.lastIndexOf(File.separator)); What else do I need to do, I wouldn't have thought it would be this hard
  8. @EventHandler public void preInit(FMLPreInitializationEvent event) { absolutePath = event.getSourceFile().getAbsolutePath(); MinecraftForge.EVENT_BUS.register(new ChatListener()); }
  9. Sorry I must have misread the title of this forum thread, I was fairly sure it said "Modder Support". Though if you don't know Java we won't teach it, there are plenty of tutorials out there for that. Now the last step is to modify the snippet of code I gave to suit your own needs if you run into any trouble after that come back. I can't create the substring for some reason but this is my code: package com.simpleafk; import java.io.BufferedOutputStream; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; import java.nio.charset.Charset; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatComponentText; public class WhitelistAdd extends CommandBase { private static final String FILE_PATH = ""; @Override public String getCommandName() { // TODO Auto-generated method stub return "wparty"; } @Override public String getCommandUsage(ICommandSender sender) { // TODO Auto-generated method stub return "wparty <username>"; } @Override public boolean canCommandSenderUseCommand(ICommandSender icommandsender) { return true; } @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { // TODO Auto-generated method stub if (args.length == 0){ sender.addChatMessage(new ChatComponentText("You must specify a valid username!")); } else { String user = args[1]; if (args[0] == "add") if (user.length() == 0){ } else { // The name of the file to open. String fileName = "whitelist.txt"; String filePath = AFKMain.absolutePath + "\\whitelist.txt"; try { // Assume default encoding. FileWriter fileWriter = new FileWriter(filePath); // Always wrap FileWriter in BufferedWriter. BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); // Note that write() does not automatically // append a newline character. bufferedWriter.write(user); bufferedWriter.newLine(); // Always close files. bufferedWriter.close(); } catch(IOException ex) { System.out.println( "Error writing to file '" + fileName + "'"); // Or we could just do this: // ex.printStackTrace(); } } else if (args[0] == "clear"){ } else if (args[0] == "remove"){ } } } } The rest is from the tutorial you linked me to. It still does not create a file anywhere.
  10. Sorry I must have misread the title of this forum thread, I was fairly sure it said "Modder Support".
  11. That is still completely unhelpful.
  12. "preevent cannot be resolved" This error without any code is meaningless. package com.simpleafk; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @Mod(modid="simpleafk", name= "Simple AFK", version="1.0", clientSideOnly = true) public class AFKMain { public static String absolutePath = preevent.getSourceFile().getAbsolutePath(); //Creating instances. @Instance("simpleafk") public static AFKMain instance; @EventHandler public void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new ChatListener()); } @EventHandler public void init(FMLInitializationEvent event) { ClientCommandHandler.instance.registerCommand(new SampleCommand()); ClientCommandHandler.instance.registerCommand(new WhitelistAdd()); } }
  13. File(String) method is undefined for my WhitelistAdd command. How do I implement this?
  14. How? And there is nothing in my C drive...
  15. How do I create the file in the same directory? It just creates a file somewhere and I have no idea where it is.
  16. I've tried quite a few things but none of it seems to work. I don't know where to specify the path for the file, I want to create it in the same directory as the mods. Could you give me a quick tutorial?
  17. I've had a request for a mod in which a user can execute a command "/wparty add user" and it will add that user to a text file (created in the same directory as the mod, in the mods folder), every time the command is executed the name needs to be written a line down. There also needs to be a "/wparty clear" and "/wparty remove user". Then, when the user executed "/wparty party", it takes those names and executes a command in bulk with a small delay between them "/party user". Note the /party is a command on the server I am using it on, and so all I need to do is send a message through the player (easy). This is the beginnings of my attempt: WhitelistAdd Command: package com.simpleafk; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; import java.nio.charset.Charset; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatComponentText; public class WhitelistAdd extends CommandBase { private static final String FILE_PATH = ""; @Override public String getCommandName() { // TODO Auto-generated method stub return "wparty"; } @Override public String getCommandUsage(ICommandSender sender) { // TODO Auto-generated method stub return "wparty <username>"; } @Override public boolean canCommandSenderUseCommand(ICommandSender icommandsender) { return true; } @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { // TODO Auto-generated method stub if (args.length == 0){ sender.addChatMessage(new ChatComponentText("You must specify a valid username!")); } else { String user = args[1]; if (args[0] == "add") { if (user.length() == 0){ } else { try { FileWriter fw = new FileWriter("wpartylist.txt"); fw.write(user); fw.close(); } catch (IOException x){ } } } else if (args[0] == "clear"){ } else if (args[0] == "remove"){ } } } } This is a CLIENT side mod. Any help would be appreciated, thanks in advance!
  18. Nevermind, I had to delete the GRADLE_OPTS variable and it worked now. Thanks tho.
  19. I understand that now, but that properties file didn't work for me, so I had to add some "-Diag" or something extension and it worked. The issue is the error I'm getting trying to turn my mod into a jar file.
  20. After much frustration copying my Mod's source files to a 1.8.9 forge version, making an environment variable called "GRADLE_OPTS" which didn't help because I needed to allocate 3 gigs of RAM to the gradle setup process, I came up with an issue. Upon completion I copied the src folder to the new forgesource workspace, resolved the errors, and tried to run "gradlew build". When I did it returned this error: Error: Could not find or load main class GRADLE_OPTS=-Xmx3072m I feel this is related to the tinkering I did before, as 3 gigs of ram was the amount I attempted to allocate. Yet I have deleted the environment variable and the gradle properties file I created and yet I still get this issue. Anybody know how to fix this? Thanks in advance.
  21. Nope... Didn't work. Because it was correct. Read Guava docs. I already gave you solution in my 1st post. DO YOUR STATEMENTS LIKE I SHOWED AND DON'T USE "return"... (Joiner is never reached) Thank you, solved the problem. Everything works now.
  22. Could you explain a little more? This is my command's execute method: public void execute(ICommandSender icommandsender, String[] args) throws CommandException { // TODO Auto-generated method stub if (ChatListener.isAFK == false) { ChatListener.isAFK = true; icommandsender.addChatMessage(new ChatComponentText("You are now AFK!")); return; } if (ChatListener.isAFK == true) { ChatListener.isAFK = false; icommandsender.addChatMessage(new ChatComponentText("You are no longer AFK!")); return; } ChatListener.reason = Joiner.on(" ").join(args); This is my chatlistener class: public void onChat(ClientChatReceivedEvent event) { String message = event.message.getUnformattedText(); if (message.contains("From") && isAFK) { Minecraft.getMinecraft().thePlayer.sendChatMessage("/r I am currently AFK. Reason: " + ChatListener.reason); } Upon doing /afk this is a test, it replies "I am currently AFK. Reason: " If I change Reason manually in the code it sets it to that.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.