Search in sources :

Example 1 with DataManager

use of com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager in project Fragile-Glass by fredtargaryen.

the class ExportAllCommand method execute.

private static int execute(CommandSource source, String manager) {
    DataManager dm = CommandsBase.getDataManager(manager);
    if (dm == null) {
        return 1;
    }
    StringBuilder sb = new StringBuilder();
    if (manager.equals("blocks")) {
        dm.getKeys().forEach(state -> {
            try {
                List<FragilityData> fdList = (List<FragilityData>) dm.getData(state);
                fdList.forEach(fragilityData -> {
                    sb.append(dm.stringifyBehaviours(state, null, false));
                    sb.append("\n");
                });
            } catch (NullPointerException npe) {
                source.sendFeedback(new StringTextComponent("No existing block state data for " + KeyParser.cleanBlockStateString(state.toString())), false);
            }
        });
    } else if (manager.equals("entities")) {
        dm.getKeys().forEach(type -> {
            try {
                sb.append(dm.stringifyBehaviours(type, null, false));
                sb.append("\n");
            } catch (NullPointerException npe) {
                source.sendFeedback(new StringTextComponent("No existing entity data for " + ((EntityType) type).getRegistryName()), false);
            }
        });
    } else {
        // "tileentities"
        dm.getKeys().forEach(type -> {
            try {
                List<FragilityData> fdList = (List<FragilityData>) dm.getData(type);
                fdList.forEach(fragilityData -> {
                    sb.append(dm.stringifyBehaviours(type, null, false));
                    sb.append("\n");
                });
            } catch (NullPointerException npe) {
                source.sendFeedback(new StringTextComponent("No existing tile entity data for " + ((TileEntityType) type).getRegistryName()), false);
            }
        });
    }
    try {
        dm.export(sb.toString());
        source.sendFeedback(new StringTextComponent("File exported successfully!"), true);
        return 0;
    } catch (IOException ioe) {
        source.sendFeedback(new StringTextComponent("File failed to export."), true);
        return 1;
    }
}
Also used : CommandSource(net.minecraft.command.CommandSource) EntityType(net.minecraft.entity.EntityType) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) List(java.util.List) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) DataManager(com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager) TileEntityType(net.minecraft.tileentity.TileEntityType) StringTextComponent(net.minecraft.util.text.StringTextComponent) IOException(java.io.IOException) KeyParser(com.fredtargaryen.fragileglass.config.behaviour.configloader.KeyParser) FragilityData(com.fredtargaryen.fragileglass.config.behaviour.data.FragilityData) DataManager(com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager) List(java.util.List) StringTextComponent(net.minecraft.util.text.StringTextComponent) IOException(java.io.IOException) FragilityData(com.fredtargaryen.fragileglass.config.behaviour.data.FragilityData)

Example 2 with DataManager

use of com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager in project Fragile-Glass by fredtargaryen.

the class ExportCommand method execute.

private static int execute(CommandSource source, String manager, DataManagerEntry entry) {
    DataManager dm = CommandsBase.getDataManager(manager);
    if (dm == null) {
        return 1;
    }
    StringBuilder sb = new StringBuilder();
    if (manager.equals("blocks")) {
        entry.getBlockStateSet().forEach(state -> {
            try {
                sb.append(dm.stringifyBehaviours(state, null, false));
                sb.append("\n");
            } catch (NullPointerException npe) {
                source.sendFeedback(new StringTextComponent("No existing block state data for " + KeyParser.cleanBlockStateString(state.toString())), false);
            }
        });
    } else if (manager.equals("entities")) {
        entry.getEntityTypeSet().forEach(type -> {
            try {
                sb.append(dm.stringifyBehaviours(type, null, false));
                sb.append("\n");
            } catch (NullPointerException npe) {
                source.sendFeedback(new StringTextComponent("No existing entity data for " + type.getRegistryName()), false);
            }
        });
    } else {
        // "tileentities"
        try {
            sb.append(dm.stringifyBehaviours(entry.getTileEntityType(), null, false));
            sb.append("\n");
        } catch (NullPointerException npe) {
            source.sendFeedback(new StringTextComponent("No existing tile entity data for " + entry.getTileEntityType().getRegistryName()), false);
        }
    }
    try {
        dm.export(sb.toString());
        source.sendFeedback(new StringTextComponent("File exported successfully!"), true);
    } catch (IOException ioe) {
        source.sendFeedback(new StringTextComponent("File failed to export."), true);
        return 1;
    }
    return 0;
}
Also used : CommandSource(net.minecraft.command.CommandSource) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) DataManager(com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager) StringTextComponent(net.minecraft.util.text.StringTextComponent) IOException(java.io.IOException) KeyParser(com.fredtargaryen.fragileglass.config.behaviour.configloader.KeyParser) Commands(net.minecraft.command.Commands) DataManager(com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager) StringTextComponent(net.minecraft.util.text.StringTextComponent) IOException(java.io.IOException)

Example 3 with DataManager

use of com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager in project Fragile-Glass by fredtargaryen.

the class ReloadCommand method execute.

private static int execute(CommandSource source, String manager) {
    DataManager dm = CommandsBase.getDataManager(manager);
    if (dm == null) {
        return 1;
    }
    dm.clearData();
    source.sendFeedback(FragileGlassBase.setReloadStatus(dm.loadData()), true);
    return 0;
}
Also used : DataManager(com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager)

Example 4 with DataManager

use of com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager in project Fragile-Glass by fredtargaryen.

the class RemoveAllCommand method execute.

private static int execute(CommandSource source, String manager) {
    DataManager dm = CommandsBase.getDataManager(manager);
    if (dm == null) {
        return 1;
    }
    dm.clearData();
    return 0;
}
Also used : DataManager(com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager)

Aggregations

DataManager (com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager)4 KeyParser (com.fredtargaryen.fragileglass.config.behaviour.configloader.KeyParser)2 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)2 StringArgumentType (com.mojang.brigadier.arguments.StringArgumentType)2 IOException (java.io.IOException)2 CommandSource (net.minecraft.command.CommandSource)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 FragilityData (com.fredtargaryen.fragileglass.config.behaviour.data.FragilityData)1 List (java.util.List)1 Commands (net.minecraft.command.Commands)1 EntityType (net.minecraft.entity.EntityType)1 TileEntityType (net.minecraft.tileentity.TileEntityType)1