File Manager [Plugin - 5.8]

Started by Goldorion on

Topic category: Plugins and third-party tools

File Manager [Plugin - 5.8]
Thu, 02/08/2024 - 02:49 (edited)

Plugin's page: https://mcreator.net/plugin/64638/file-creator

File Manager is a plugin adding new procedure blocks allowing you to create and read your files! 

File Types

  • JSON
  • TXT (simple file reader/writer)
  • ZIP (5.7+)

Important Information

  • This version supports Forge 1.19.4 and 1.20.1 and Fabric .20.1

https://storage.ko-fi.com/cdn/brandasset/kofi_button_blue.png

The 2 following examples require File Manager 5.0 or after.

Create a JSON file

Create a json file

Read a JSON file

Read a JSON file

I made a tutorial covering this here.

Credits/License

Tutorial by NorthWestTrees

Tutorial on sub-JSON objects by NorthWestTrees

Tutorial by Cursed Warrior

Icon by Tobi-Wan#0482

Licensed under the GNU Lesser General Public License, version 2.1  

  • Appropriate credit must be provided to the creators and maintainers of this plugin.
  • Forked versions of this plugin must be distributed under the same license as this with attribution if distributed.
  • Changes must be stated if any modified works are to be distributed.
  • Under no circumstances you can state that the original creator endorses modified works.

Changelog

To see a complete changelog of the plugin, check this file.

5.8

* Removed support for Forge 1.18.2, 1.19.2
* Removed support for Fabric 1.19.2
* Re-organized File Manager's categories to use the new parent/children category system
* [#51] Add a Remove JSON property
* [#54] Add Get client's directory
* [#58] Add Get JSON property name at index
* [Bugfix #50] Is JSON object empty caused a build error
* [Bugfix #52] Copy url to file didn't work correctly
Edited by Goldorion on Thu, 02/08/2024 - 02:49
Last seen on 01:35, 18. Apr 2024
Joined Jan 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This does lead me to think…
Thu, 09/16/2021 - 10:45

This does lead me to think that maybe the Does "file" exist block might be broken too

Last seen on 17:34, 28. Dec 2023
Joined Aug 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
When I try tocreate a JSON…
Wed, 09/22/2021 - 00:42

When I try tocreate a JSON file (for a config), the compilation fails!

 

My console output is (NOTE: Some sensitive informationhas been removed):

Executing Gradle task: build
Build info: MCreator 2021.2.36710, forge-1.16.5, 64-bit, 16320 MB, Windows 10, JVM 11.0.11, JAVA_HOME: C:\Program Files\Pylo\MCreator\jdk
> Task :compileJava
LoadConfigProcedure.java:56: error: ';' expected FileWriter MoarModVariables.configFilefw = new FileWriter(MoarModVariables.configFile);
^
LoadConfigProcedure.java:64: error: ';' expected BufferedReader MoarModVariables.configFileReader = new BufferedReader(new FileReader(MoarModVariables.configFile));
^
2 errors
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec…
BUILD FAILED in 7s
1 actionable task: 1 executed
BUILD FAILED
Task completed in 57 seconds
 

My code is below:

package mrbradlerz.moar.procedures;

import net.minecraftforge.fml.loading.FMLPaths;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import net.minecraft.world.IWorld;

import mrbradlerz.moar.MoarModVariables;
import mrbradlerz.moar.MoarMod;

import java.util.Map;
import java.util.Collections;

import java.io.IOException;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.File;
import java.io.BufferedReader;

import com.google.gson.JsonObject;
import com.google.gson.GsonBuilder;
import com.google.gson.Gson;

public class LoadConfigProcedure {
    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
    private static class GlobalTrigger {
        @SubscribeEvent
        public static void init(FMLCommonSetupEvent event) {
            executeProcedure(Collections.emptyMap());
        }
    }
    public static void executeProcedure(Map<String, Object> dependencies){
            if(dependencies.get("world") == null) {
                if(!dependencies.containsKey("world"))
                    MoarMod.LOGGER.warn("Failed to load dependency world for procedure LoadConfig!");
                return;
            }
                IWorld world = (IWorld) dependencies.get("world");
        if ((!MoarModVariables.configFile.exists())) {MoarModVariables.configFile = new File(((FMLPaths.GAMEDIR.get().toString())+""+("config")), File.separator + "moar.json");
    if (!MoarModVariables.configFile.exists()) {
        try {
            MoarModVariables.configFile.createNewFile();
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    }
{
    Gson mainGSONBuilderVariable = new GsonBuilder().setPrettyPrinting().create();
    JsonObject config = new JsonObject();
    JsonObject general = new JsonObject();
general.addProperty("giveBurnedPaper", (true));
config.add("general", general);
    try {
          FileWriter MoarModVariables.configFilefw = new FileWriter(MoarModVariables.configFile);
          MoarModVariables.configFilefw.write(mainGSONBuilderVariable.toJson(config));
          MoarModVariables.configFilefw.close();
    } catch (IOException exception) {
          exception.printStackTrace();
      }    
}{
    try {
        BufferedReader MoarModVariables.configFileReader = new BufferedReader(new FileReader(MoarModVariables.configFile));
        StringBuilder jsonstringbuilder = new StringBuilder();
        String line;
        while((line = MoarModVariables.configFileReader.readLine()) != null) {
            jsonstringbuilder.append(line);
        }
        MoarModVariables.configFileReader.close();
        JsonObject config = new Gson().fromJson(jsonstringbuilder.toString(), JsonObject.class);
        MoarModVariables.MapVariables.get(world).giveBurnedPaper = (boolean)        config.general
.get("giveBurnedPaper").getAsBoolean();
MoarModVariables.MapVariables.get(world).syncData(world);
  
    } catch (IOException e) {
        e.printStackTrace();
    }
}}
    }
}

Last seen on 11:46, 11. Dec 2021
Joined Feb 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It would be really great if…
Thu, 11/04/2021 - 20:19

It would be really great if we had a "does JSON property exist" block
Cause if we try to read a JSON property value that doesn't exist and try to use it for a variable, Java will throw a NullPointerException at game start, which could happen for example if you update a mod and the existing config file doesn't cover all options 
So checking whether a JSON property exists in the file would be really helpful 

File Manager 5.0 is now…
Wed, 12/15/2021 - 21:45

File Manager 5.0 is now released to support MCreator 2021.3, Forge 1.17.1 and make easier the creation of JSON files! https://mcreator.net/plugin/64638/file-creator

 

Changelog:

Note: This version breaks workspaces using a previous update.
* Updated to MCreator 2021.3.51219
* Removed support for Forge 1.15.2
* Added support for Forge 1.17.1
* Added a new JsonObject variable type
* Removed the "Create sub JSON object" block
* Added "Add JSON object to Json Object" and "Get Json Object property" blocks
* Changed the old Json Object fields to the new JsonObject variable list
* Procedure blocks requiring a file variable now use a normal variable list
* Created file block has been changed for a block giving values to the setter block variable
* Added a new create file procedure block
* Changed the new line checkbox to an input boolean value in the "Write TXT line" block

 

Last seen on 18:34, 4. Feb 2024
Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Whenever I load my mod, the…
Fri, 02/04/2022 - 16:33

Whenever I load my mod, the config file gets reset to default. anyone know how to fix this?

Last seen on 18:34, 4. Feb 2024
Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Whenever I load my mod, the…
Fri, 02/04/2022 - 16:53

Whenever I load my mod, the config file gets reset to default. anyone know how to fix this?

nevermind

Last seen on 09:58, 14. Aug 2023
Joined Dec 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
is there a way you can copy…
Sat, 12/10/2022 - 09:45

is there a way you can copy a file from a local directory?

Such as .minecraft/saves/world/randomfile

Last seen on 14:47, 17. Apr 2024
Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Is it possible with File…
Wed, 12/28/2022 - 10:21

Is it possible with File Manager to make 'data-driven' Mods?

 

I want to add into a Mod a Plague System where you can create Plagues, Cures etc. but you have also the Ability to create your own Viruses via json File.

Last seen on 22:32, 17. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Just a question about plugin…
Mon, 06/12/2023 - 01:54

Just a question about plugin security, this plugin *can't* overwrite system files, right?

It's technically possible to…
Mon, 06/12/2023 - 02:22

It's technically possible to alter the system's files if you have proper permissions (or even simply without doing anything). My real option to limit the reach of this plugin would be to limit writing files to the current game's directory and the temp directory. However, this can still be bypassed by using the custom code snippet blocks. :/ This is the problem with files in Java and we have the same with Java plugins for MCreator. This is the reason users need to manually enable Java plugins from Preferences inside MCreator.

 

This is also to avoid as much as possible problems on other players' computers that I still don't (and won't) have a procedure block to delete files. I don't want a user to accidentally (or not) delete files from the computers of other players.

Last seen on 22:32, 17. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Is it also possible to have…
Tue, 06/13/2023 - 01:15

Is it also possible to have non-existent JSON properties return their default values? It would make procedure-making a lot easier instead of having it break the procedure.