customrealms / core

Core library for the CustomRealms runtime
https://customrealms.io/core
MIT License
36 stars 14 forks source link

feat: Basic File implementation #44

Closed NexelOfficial closed 4 months ago

NexelOfficial commented 4 months ago

Added some basic File classes to support file reading and writing. Added the following classes:

This should provide the basic File reader and writing needs that are crucial for plugin development.

Example file reading implementation:

import { ServerCommands } from "@customrealms/core";

ServerCommands.register("/log-properties", () => {
  const serverPropsFile = new java.io.File("server.properties");
  const propsScanner = new java.util.Scanner(serverPropsFile);

  while (propsScanner.hasNextLine()) {
    const nextLine = propsScanner.nextLine();
    console.log(nextLine);
  }
});

Example file writing implementation:

import { ServerCommands } from "@customrealms/core";

ServerCommands.register("/write-file", () => {
  const file = new java.io.File("test-document.txt");
  const writer = new java.io.FileWriter(file);
  writer.write("This is some example text!");
  writer.close();
});
connerdouglass commented 4 months ago

You're free to merge this whenever you're ready 🚀

NexelOfficial commented 4 months ago

You're free to merge this whenever you're ready 🚀

I don't have write access to the repository :o

connerdouglass commented 4 months ago

Oh, I thought you would be able to merge an approved PR. I'll look into that later, but merge this one myself 👍