Skip to content

Commit

Permalink
Bypass some issues that need to be fixed in WolfyUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyScript committed Mar 19, 2022
1 parent 7ec57c8 commit ee6359e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,47 +149,52 @@ public void onInit() {
}

private void registerSaveButtons() {
getButtonBuilder().action(SAVE.getKey()).state(state -> state.icon(Material.WRITABLE_BOOK).action((cache, guiHandler, player, guiInventory, i, inventoryInteractEvent) -> {
registerButton(new ActionButton<>(SAVE.getKey(), Material.WRITABLE_BOOK, (cache, guiHandler, player, guiInventory, i, inventoryInteractEvent) -> {
if (guiHandler.getWindow() instanceof RecipeCreator && !cache.getRecipeCreatorCache().getRecipeCache().save(customCrafting, player, guiHandler)) {
getChat().sendMessage(player, translatedMsgKey("save.empty"));
guiHandler.getApi().getChat().sendKey(player, KEY, "save.empty");
}
return true;
}).render((values, cache, guiHandler, player, guiInventory, itemStack, i, b) -> {
}, (values, cache, guiHandler, player, guiInventory, itemStack, i, b) -> {
NamespacedKey namespacedKey = cache.getRecipeCreatorCache().getRecipeCache().getKey();
if (namespacedKey != null) {
values.put("<recipe_folder>", namespacedKey.getKeyComponent().getFolder());
values.put("<recipe_key>", namespacedKey.getKeyComponent().getObject());
}
return itemStack;
})).register();
getButtonBuilder().chatInput(SAVE_AS.getKey()).state(state -> state.icon(Material.WRITABLE_BOOK)).message(translatedMsgKey("save.input")).tabComplete((guiHandler, player, args) -> {
List<String> results = new ArrayList<>();
if (args.length > 0) {
var registryRecipes = customCrafting.getRegistries().getRecipes();
if (args.length == 1) {
results.add("<folder>");
StringUtil.copyPartialMatches(args[0], registryRecipes.folders(NamespacedKeyUtils.NAMESPACE), results);
} else if (args.length == 2) {
results.add("<recipe_name>");
StringUtil.copyPartialMatches(args[1], registryRecipes.get(NamespacedKeyUtils.NAMESPACE, args[0]).stream().filter(recipe -> guiHandler.getCustomCache().getRecipeCreatorCache().getRecipeType().isInstance(recipe)).map(recipe -> NamespacedKeyUtils.getRelativeKeyObjPath(recipe.getNamespacedKey())).toList(), results);
}
}
Collections.sort(results);
return results;
}).inputAction((guiHandler, player, s, args) -> {
CCCache cache = guiHandler.getCustomCache();
var namespacedKey = ChatUtils.getNamespacedKey(player, s, args);
if (namespacedKey != null && !namespacedKey.getNamespace().equalsIgnoreCase("minecraft")) {
cache.getRecipeCreatorCache().getRecipeCache().setKey(namespacedKey);
if (!cache.getRecipeCreatorCache().getRecipeCache().save(customCrafting, player, guiHandler)) {
getChat().sendMessage(player, translatedMsgKey("save.empty"));
return false;
}
} else {
getChat().sendMessage(player, translatedMsgKey("save.key.invalid"));
return false;
}));
registerButton(new ActionButton<>(SAVE_AS.getKey(), Material.WRITABLE_BOOK, (cache, guiHandler, player, guiInventory, i, inventoryInteractEvent) -> {
if (guiHandler.getWindow() instanceof RecipeCreator recipeCreator) {
guiHandler.setChatTabComplete((guiHandler1, player1, args) -> {
List<String> results = new ArrayList<>();
if (args.length > 0) {
var registryRecipes = customCrafting.getRegistries().getRecipes();
if (args.length == 1) {
results.add("<folder>");
StringUtil.copyPartialMatches(args[0], registryRecipes.folders(NamespacedKeyUtils.NAMESPACE), results);
} else if (args.length == 2) {
results.add("<recipe_name>");
StringUtil.copyPartialMatches(args[1], registryRecipes.get(NamespacedKeyUtils.NAMESPACE, args[0]).stream().filter(recipe -> cache.getRecipeCreatorCache().getRecipeType().isInstance(recipe)).map(recipe -> NamespacedKeyUtils.getRelativeKeyObjPath(recipe.getNamespacedKey())).toList(), results);
}
}
Collections.sort(results);
return results;
});
recipeCreator.openChat(guiHandler.getInvAPI().getGuiCluster(KEY), "save.input", guiHandler, (guiHandler1, player1, s, args) -> {
var namespacedKey = ChatUtils.getNamespacedKey(player1, s, args);
if (namespacedKey != null && !namespacedKey.getNamespace().equalsIgnoreCase("minecraft")) {
cache.getRecipeCreatorCache().getRecipeCache().setKey(namespacedKey);
if (!cache.getRecipeCreatorCache().getRecipeCache().save(customCrafting, player, guiHandler)) {
guiHandler.getApi().getChat().sendKey(player, KEY, "save.empty");
return false;
}
} else {
guiHandler.getApi().getChat().sendKey(player, KEY, "save.key.invalid");
return false;
}
return true;
});
}
return true;
}).register();
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import me.wolfyscript.utilities.api.language.Language;
import me.wolfyscript.utilities.api.language.LanguageAPI;
import me.wolfyscript.utilities.util.json.jackson.JacksonUtil;
import me.wolfyscript.utilities.util.version.ServerVersion;
import me.wolfyscript.utilities.util.version.WUVersion;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -107,13 +109,23 @@ public void loadLang() {
customCrafting.saveResource("lang/en_US.json", true);
customCrafting.saveResource("lang/de_DE.json", true);
customCrafting.saveResource("lang/zh_CN.json", true);
//The default language to use and to which it falls back if a key is not found in the active language
var fallBackLanguage = new Language(customCrafting, "en_US");
//The default language to use and to which it falls back to if a key is not found in the active language
Language fallBackLanguage;
if (ServerVersion.getWUVersion().isAfterOrEq(WUVersion.of(4, 16, 0, 0))) {
fallBackLanguage = languageAPI.loadLangFile("en_US");
} else {
fallBackLanguage = new Language(customCrafting, "en_US");
}
languageAPI.registerLanguage(fallBackLanguage);
customCrafting.getLogger().info(() -> "Loaded fallback language \"en_US\" v" + fallBackLanguage.getVersion() + " translated by " + String.join(", ", fallBackLanguage.getAuthors()));
//Load the chosen language
if (Files.exists(Path.of(customCrafting.getDataFolder().getPath(), "lang", chosenLang + ".json"))) {
var language = new Language(customCrafting, chosenLang);
Language language;
if (ServerVersion.getWUVersion().isAfterOrEq(WUVersion.of(4, 16, 0, 0))) {
language = languageAPI.loadLangFile(chosenLang);
} else {
language = new Language(customCrafting, chosenLang);
}
languageAPI.registerLanguage(language);
languageAPI.setActiveLanguage(language);
customCrafting.getLogger().info(() -> "Loaded active language \"" + chosenLang + "\" v" + language.getVersion() + " translated by " + String.join(", ", language.getAuthors()));
Expand Down

0 comments on commit ee6359e

Please sign in to comment.