Skip to content

Commit

Permalink
重构一部分配方管理模块
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiyodaXiaoYi committed Nov 16, 2023
1 parent 0bc9407 commit 369e9ce
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 170 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.5.0b")
compileOnly("com.github.oraxen:oraxen:1.160.0")
compileOnly("io.lumine:Mythic-Dist:5.3.5")
implementation("com.crypticlib:CrypticLib:0.1.6")
implementation("com.crypticlib:CrypticLib:0.1.7")
}

group = "com.github.yufiriamazenta"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void disable() {

private void loadBStat() {
Metrics metrics = new Metrics(this, 17821);
metrics.addCustomChart(new Metrics.SingleLineChart("recipes", () -> RecipeManager.getRecipeFileMap().keySet().size()));
metrics.addCustomChart(new Metrics.SingleLineChart("recipes", () -> RecipeManager.getRecipeConfigWrapperMap().keySet().size()));
}

private void regListeners() {
Expand All @@ -76,6 +76,10 @@ public static Craftorithm getInstance() {
return INSTANCE;
}

public static CraftorithmAPI getAPI() {
return CraftorithmAPI.INSTANCE;
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (event.getPlayer().isOp()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private void regDefaultSubCommands() {
regSubCommand(ReloadCommand.INSTANCE);
regSubCommand(VersionCommand.INSTANCE);
regSubCommand(RemoveRecipeCommand.INSTANCE);
regSubCommand(DisableRecipeCommand.INSTANCE);
regSubCommand(ItemCommand.INSTANCE);
regSubCommand(RunArcencielCmd.INSTANCE);
regSubCommand(ShowRecipeCommand.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.yufiriamazenta.craftorithm.cmd.subcmd;

import crypticlib.command.ISubCmdExecutor;
import org.bukkit.command.CommandSender;

import java.util.List;
import java.util.Map;

public final class DisableRecipeCommand extends AbstractSubCommand {

public static final DisableRecipeCommand INSTANCE = new DisableRecipeCommand();

private DisableRecipeCommand() {
super("disable", "craftorithm.command.disable");
}

@Override
public boolean onCommand(CommandSender sender, List<String> args) {
//TODO
return super.onCommand(sender, args);
}

@Override
public List<String> onTabComplete(CommandSender sender, List<String> args) {
//TODO
return super.onTabComplete(sender, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import java.util.ArrayList;
import java.util.List;

/**
* 重构为只能删除本身插件的配方,取消其他插件配方移动到disable命令
*/
public final class RemoveRecipeCommand extends AbstractSubCommand {

public static final ISubCmdExecutor INSTANCE = new RemoveRecipeCommand();
Expand All @@ -35,7 +38,7 @@ public boolean onCommand(CommandSender sender, List<String> args) {
public List<String> onTabComplete(CommandSender sender, List<String> args) {
if (args.size() <= 1) {
List<String> tabList = new ArrayList<>();
for (NamespacedKey key : RecipeManager.getServerRecipeMap().keySet()) {
for (NamespacedKey key : RecipeManager.getServerRecipeList().keySet()) {
String str = key.toString();
if (str.startsWith(args.get(0)))
tabList.add(key.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.yufiriamazenta.craftorithm.menu.impl.recipe;

import com.github.yufiriamazenta.craftorithm.Craftorithm;
import com.github.yufiriamazenta.craftorithm.cmd.subcmd.RemoveRecipeCommand;
import com.github.yufiriamazenta.craftorithm.item.ItemManager;
import com.github.yufiriamazenta.craftorithm.menu.bukkit.BukkitMenuHandler;
import com.github.yufiriamazenta.craftorithm.menu.bukkit.ItemDisplayIcon;
Expand Down Expand Up @@ -116,7 +115,7 @@ private void setStoneCuttingMenuIcons() {
Recipe[] recipes = RecipeFactory.newMultipleRecipe(recipeConfig.config(), recipeName);
for (Recipe recipe : recipes) {
NamespacedKey key = RecipeManager.getRecipeKey(recipe);
RecipeManager.regRecipe(key, recipe, recipeConfig.config());
RecipeManager.regRecipes(key, recipe, recipeConfig.config());
}
event.getWhoClicked().closeInventory();
sendSuccessMsgAndReloadMap(event.getWhoClicked());
Expand Down Expand Up @@ -199,7 +198,7 @@ private void setSmithingMenuIcons() {
recipeConfig.saveConfig();
recipeConfig.reloadConfig();
Recipe recipe = RecipeFactory.newRecipe(recipeConfig.config(), recipeName);
RecipeManager.regRecipe(NamespacedKey.fromString(recipeName, Craftorithm.getInstance()), recipe, recipeConfig.config());
RecipeManager.regRecipes(NamespacedKey.fromString(recipeName, Craftorithm.getInstance()), recipe, recipeConfig.config());
event.getWhoClicked().closeInventory();
sendSuccessMsgAndReloadMap(event.getWhoClicked());
});
Expand Down Expand Up @@ -284,15 +283,15 @@ private void setCookingMenuIcons() {
Recipe[] multipleRecipes = RecipeFactory.newMultipleRecipe(recipeConfig.config(), recipeName);
for (Recipe recipe : multipleRecipes) {
NamespacedKey key = RecipeManager.getRecipeKey(recipe);
RecipeManager.regRecipe(key, recipe, recipeConfig.config());
RecipeManager.regRecipes(key, recipe, recipeConfig.config());
}
} else {
recipeConfig.config().set("source.block", "furnace");
recipeConfig.config().set("source.item", sourceName);
recipeConfig.saveConfig();
recipeConfig.reloadConfig();
Recipe recipe = RecipeFactory.newRecipe(recipeConfig.config(), recipeName);
RecipeManager.regRecipe(NamespacedKey.fromString(recipeName, Craftorithm.getInstance()), recipe, recipeConfig.config());
RecipeManager.regRecipes(NamespacedKey.fromString(recipeName, Craftorithm.getInstance()), recipe, recipeConfig.config());
}
event.getWhoClicked().closeInventory();
sendSuccessMsgAndReloadMap(event.getWhoClicked());
Expand Down Expand Up @@ -405,7 +404,7 @@ private void setCraftMenuIcons() {
recipeConfig.saveConfig();
recipeConfig.reloadConfig();
Recipe recipe = RecipeFactory.newRecipe(recipeConfig.config(), recipeName);
RecipeManager.regRecipe(NamespacedKey.fromString(recipeName, Craftorithm.getInstance()), recipe, recipeConfig.config());
RecipeManager.regRecipes(NamespacedKey.fromString(recipeName, Craftorithm.getInstance()), recipe, recipeConfig.config());
event.getWhoClicked().closeInventory();
sendSuccessMsgAndReloadMap(event.getWhoClicked());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public static Recipe stoneCuttingRecipe(YamlConfiguration config, String key) {
ItemStack result1 = ItemManager.matchItem(resultList.get(i));
String fullKey = key + "." + i;
NamespacedKey namespacedKey = new NamespacedKey(Craftorithm.getInstance(), fullKey);
RecipeManager.regRecipe(namespacedKey, StoneCuttingRecipeBuilder.builder().key(namespacedKey).result(result1).source(choice).build(), config);
RecipeManager.regRecipes(namespacedKey, StoneCuttingRecipeBuilder.builder().key(namespacedKey).result(result1).source(choice).build(), config);
}
} else {
result = getResultItem(config);
Expand Down
Loading

0 comments on commit 369e9ce

Please sign in to comment.