-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc: Use StandaloneYamlConfigManager to manage recipe config
- Loading branch information
1 parent
7469a9e
commit 84bf814
Showing
5 changed files
with
186 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/xiamomc/morph/misc/recipe/RecipeYamlConfigManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package xiamomc.morph.misc.recipe; | ||
|
||
import com.google.common.base.Charsets; | ||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import org.jetbrains.annotations.Nullable; | ||
import xiamomc.morph.utilities.PluginAssetUtils; | ||
import xiamomc.pluginbase.Configuration.ConfigOption; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.util.List; | ||
|
||
public class RecipeYamlConfigManager extends StandaloneYamlConfigManager | ||
{ | ||
public RecipeYamlConfigManager(File file, @Nullable String internalResourceName) | ||
{ | ||
super(file, internalResourceName); | ||
} | ||
|
||
/** | ||
* Copy internal resource to the location | ||
* | ||
* @return Whether this operation was successful | ||
*/ | ||
@Override | ||
protected boolean copyInternalResource() | ||
{ | ||
try | ||
{ | ||
if (!configFile.createNewFile()) | ||
return false; | ||
|
||
try (var writer = new OutputStreamWriter(new FileOutputStream(configFile), Charsets.UTF_8)) | ||
{ | ||
writer.write(PluginAssetUtils.getFileStrings("recipes.yml")); | ||
} | ||
catch (Throwable t) | ||
{ | ||
logger.error("Can't write content: " + t.getMessage()); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
catch (Throwable t) | ||
{ | ||
logger.error("Can't create config file: " + t.getMessage()); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
protected int getExpectedConfigVersion() | ||
{ | ||
return 1; | ||
} | ||
|
||
private final List<ConfigOption<?>> options = new ObjectArrayList<>(List.of( | ||
RecipeOptions.DISGUISE_TOOL_CRAFTING_SHAPE, | ||
RecipeOptions.DISGUISE_TOOL_RESULT_LORE, | ||
RecipeOptions.DISGUISE_TOOL_RESULT_NAME, | ||
RecipeOptions.ALLOW_DISGUISE_TOOL_CRAFTING, | ||
RecipeOptions.DISGUISE_TOOL_CRAFTING_MATERIALS, | ||
RecipeOptions.DISGUISE_TOOL_CRAFTING_UNSHAPED, | ||
RecipeOptions.DISGUISE_TOOL_RESULT_MATERIAL | ||
)); | ||
|
||
@Override | ||
protected List<ConfigOption<?>> getAllOptions() | ||
{ | ||
return options; | ||
} | ||
} |
Oops, something went wrong.