Skip to content

Commit

Permalink
[1.4.5]修复高于1.14版本依然无法通过GUI创建锻造台和切石机配方的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiyodaXiaoYi committed Nov 13, 2023
1 parent e60d612 commit 0bff137
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 38 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ 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.0.6")
implementation("com.crypticlib:CrypticLib:0.0.7")
}

group = "com.github.yufiriamazenta"
version = "1.4.4"
version = "1.4.5"
var pluginVersion: String = version.toString() + "-" + SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis())
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.github.yufiriamazenta.craftorithm.arcenciel.ArcencielDispatcher;
import com.github.yufiriamazenta.craftorithm.bstat.Metrics;
import com.github.yufiriamazenta.craftorithm.cmd.PluginCommand;
import com.github.yufiriamazenta.craftorithm.config.ConfigUpdater;
import com.github.yufiriamazenta.craftorithm.item.ItemManager;
import com.github.yufiriamazenta.craftorithm.listener.*;
Expand All @@ -12,6 +11,7 @@
import com.github.yufiriamazenta.craftorithm.util.PluginHookUtil;
import com.github.yufiriamazenta.craftorithm.util.UpdateUtil;
import crypticlib.BukkitPlugin;
import crypticlib.CrypticLib;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.event.EventHandler;
Expand All @@ -28,7 +28,6 @@
public final class Craftorithm extends BukkitPlugin implements Listener {

private static Craftorithm INSTANCE;
private int vanillaVersion;
private boolean hasLoadPluginRecipeMap = false;

public Craftorithm() {
Expand All @@ -37,7 +36,6 @@ public Craftorithm() {

@Override
public void enable() {
loadVanillaVersion();
saveDefaultConfig();
ConfigUpdater.INSTANCE.updateConfig();

Expand All @@ -57,18 +55,6 @@ public void disable() {
RecipeManager.resetRecipes();
}

private void loadVanillaVersion() {
String versionStr = Bukkit.getBukkitVersion();
int index1 = versionStr.indexOf(".");
int index2 = versionStr.indexOf(".", index1 + 1);
versionStr = versionStr.substring(index1 + 1, index2);
try {
vanillaVersion = Integer.parseInt(versionStr);
} catch (NumberFormatException e) {
vanillaVersion = Integer.parseInt(versionStr.substring(0, versionStr.indexOf("-")));
}
}

private void loadBStat() {
Metrics metrics = new Metrics(this, 17821);
metrics.addCustomChart(new Metrics.SingleLineChart("recipes", () -> RecipeManager.getRecipeFileMap().keySet().size()));
Expand All @@ -80,9 +66,9 @@ private void regListeners() {
Bukkit.getPluginManager().registerEvents(RecipeUnlockHandler.INSTANCE, this);
Bukkit.getPluginManager().registerEvents(AnvilRecipeHandler.INSTANCE, this);
Bukkit.getPluginManager().registerEvents(BukkitMenuDispatcher.INSTANCE, this);
if (getVanillaVersion() >= 14)
if (CrypticLib.minecraftVersion() >= 11400)
Bukkit.getPluginManager().registerEvents(SmithingHandler.INSTANCE, this);
if (getVanillaVersion() >= 17)
if (CrypticLib.minecraftVersion() >= 11700)
Bukkit.getPluginManager().registerEvents(FurnaceSmeltHandler.INSTANCE, this);
}

Expand All @@ -94,10 +80,6 @@ public static Craftorithm getInstance() {
return INSTANCE;
}

public int getVanillaVersion() {
return vanillaVersion;
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (event.getPlayer().isOp()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.yufiriamazenta.craftorithm.menu.impl.recipe.RecipeCreatorMenuHolder;
import com.github.yufiriamazenta.craftorithm.recipe.RecipeType;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
import crypticlib.CrypticLib;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand All @@ -26,7 +27,7 @@ protected CreateRecipeCommand() {
unsupportedRecipeTypeList.add("random_cooking");
unsupportedRecipeTypeList.add("anvil");
unsupportedRecipeTypeList.add("unknown");
if (Craftorithm.getInstance().getVanillaVersion() < 14) {
if (CrypticLib.minecraftVersion() < 11400) {
unsupportedRecipeTypeList.add("stone_cutting");
unsupportedRecipeTypeList.add("smithing");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.yufiriamazenta.craftorithm.Craftorithm;
import com.github.yufiriamazenta.craftorithm.recipe.RecipeManager;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
import crypticlib.CrypticLib;
import crypticlib.command.ISubCmdExecutor;
import crypticlib.config.impl.YamlConfigWrapper;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -79,9 +80,9 @@ public void removeRecipes(List<String> keyStrList, boolean save2File) {
if (key != null)
keyList.add(key);
}
if (keyList.size() < 1)
if (keyList.isEmpty())
return;
if (Craftorithm.getInstance().getVanillaVersion() >= 15) {
if (CrypticLib.minecraftVersion() >= 11500) {
for (NamespacedKey key : keyList) {
Bukkit.removeRecipe(key);
if (save2File) {
Expand All @@ -101,7 +102,7 @@ public void removeRecipes(List<String> keyStrList, boolean save2File) {
addKey2RemovedConfig(key1.toString());
}
keyList.remove(key1);
if (keyList.size() <= 0)
if (keyList.isEmpty())
break;
}
}
Expand All @@ -114,7 +115,7 @@ public boolean removeRecipe(String keyStr, boolean save2File) {
Iterator<Recipe> recipeIterator = Bukkit.recipeIterator();
if (key == null)
return false;
if (Craftorithm.getInstance().getVanillaVersion() >= 15) {
if (CrypticLib.minecraftVersion() >= 11500) {
if (Bukkit.removeRecipe(key) && save2File)
addKey2RemovedConfig(key.toString());
reloadRecipeMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.github.yufiriamazenta.craftorithm.util.ContainerUtil;
import com.github.yufiriamazenta.craftorithm.util.FileUtil;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
import crypticlib.CrypticLib;
import crypticlib.config.impl.YamlConfigWrapper;
import crypticlib.util.ItemUtil;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -143,7 +144,7 @@ private void setSmithingMenuIcons() {
getMenuIconMap().put(slot, resultFrameIcon);
}
int[] smithingFrameSlots;
if (Craftorithm.getInstance().getVanillaVersion() < 20) {
if (CrypticLib.minecraftVersion() < 12000) {
smithingFrameSlots = new int[]{
10, 11, 12,
20,
Expand All @@ -169,7 +170,7 @@ private void setSmithingMenuIcons() {
String resultName = getItemName(result, false);
ItemStack base, addition, template;
String baseName, additionName, templateName = null;
if (Craftorithm.getInstance().getVanillaVersion() < 20) {
if (CrypticLib.minecraftVersion() < 12000) {
base = event.getClickedInventory().getItem(19);
addition = event.getClickedInventory().getItem(21);
} else {
Expand All @@ -189,7 +190,7 @@ private void setSmithingMenuIcons() {
recipeConfig.config().set("source.base", baseName);
recipeConfig.config().set("source.addition", additionName);
recipeConfig.config().set("type", "smithing");
if (Craftorithm.getInstance().getVanillaVersion() >= 20) {
if (CrypticLib.minecraftVersion() >= 12000) {
recipeConfig.config().set("source.type", "transform");
recipeConfig.config().set("source.template", templateName);
}
Expand Down Expand Up @@ -233,7 +234,7 @@ private void setCookingMenuIcons() {
for (int slot : cookingFrameSlots) {
getMenuIconMap().put(slot, cookingFrameIcon);
}
if (Craftorithm.getInstance().getVanillaVersion() >= 14) {
if (CrypticLib.minecraftVersion() >= 11400) {
ItemDisplayIcon furnaceIcon = ItemDisplayIcon.icon(Material.FURNACE, LangUtil.lang("menu.recipe_creator.icon.furnace_toggle"), event -> {
setIconGlowing(38, event);
});
Expand Down Expand Up @@ -268,7 +269,7 @@ private void setCookingMenuIcons() {
YamlConfigWrapper recipeConfig = new YamlConfigWrapper(recipeFile);
recipeConfig.config().set("type", "cooking");
recipeConfig.config().set("result", resultName);
if (Craftorithm.getInstance().getVanillaVersion() >= 14) {
if (CrypticLib.minecraftVersion() >= 11400) {
recipeConfig.config().set("multiple", true);
List<Map<String, String>> sourceList = new ArrayList<>();
int []toggleSlots = { 38, 39, 41, 42 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.github.yufiriamazenta.craftorithm.recipe.RecipeType;
import com.github.yufiriamazenta.craftorithm.recipe.custom.AnvilRecipe;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
import crypticlib.CrypticLib;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryType;
Expand Down Expand Up @@ -144,7 +145,7 @@ private void setCookingRecipeMenu() {

private void setSmithingRecipeMenu() {
SmithingRecipe smithingRecipe = (SmithingRecipe) recipe;
if (Craftorithm.getInstance().getVanillaVersion() >= 20) {
if (CrypticLib.minecraftVersion() >= 12000) {
getMenuIconMap().put(1, ItemDisplayIcon.icon(smithingRecipe.getBase().getItemStack()));
getMenuIconMap().put(2, ItemDisplayIcon.icon(smithingRecipe.getAddition().getItemStack()));
getMenuIconMap().put(3, ItemDisplayIcon.icon(smithingRecipe.getResult()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.yufiriamazenta.craftorithm.menu.bukkit.ItemDisplayIcon;
import com.github.yufiriamazenta.craftorithm.recipe.RecipeManager;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
import crypticlib.CrypticLib;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
Expand Down Expand Up @@ -32,7 +33,7 @@ public RecipeListMenuHolder() {
maxPage = recipeNum / 45;
else
maxPage = recipeNum / 45 + 1;
if (Craftorithm.getInstance().getVanillaVersion() >= 20) {
if (CrypticLib.minecraftVersion() >= 12000) {
recipeList.removeIf(recipe -> recipe instanceof SmithingTrimRecipe);
}
recipeList.sort((o1, o2) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.github.yufiriamazenta.craftorithm.recipe.builder.vanilla.*;
import com.github.yufiriamazenta.craftorithm.recipe.custom.AnvilRecipe;
import com.github.yufiriamazenta.craftorithm.recipe.custom.AnvilRecipeItem;
import crypticlib.CrypticLib;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Tag;
Expand Down Expand Up @@ -157,7 +158,7 @@ public static Recipe smithingRecipe(YamlConfiguration config, String key) {
ItemStack result = getResultItem(config);
RecipeChoice base = getRecipeChoice(config.getString("source.base", ""));
RecipeChoice addition = getRecipeChoice(config.getString("source.addition", ""));
if (Craftorithm.getInstance().getVanillaVersion() >= 20) {
if (CrypticLib.minecraftVersion() >= 12000) {
RecipeChoice template = getRecipeChoice(config.getString("source.template", ""));
XSmithingRecipeBuilder.SmithingType type = XSmithingRecipeBuilder.SmithingType.valueOf(config.getString("source.type", "default").toUpperCase());
return XSmithingRecipeBuilder.builder(type).key(namespacedKey).result(result).base(base).addition(addition).template(template).build();
Expand All @@ -180,7 +181,7 @@ public static Recipe[] multipleSmithingRecipe(YamlConfiguration config, String k
if (typeStr == null) {
typeStr = "DEFAULT";
}
if (Craftorithm.getInstance().getVanillaVersion() >= 20) {
if (CrypticLib.minecraftVersion() >= 12000) {
RecipeChoice template = getRecipeChoice((String) map.get("template"));
XSmithingRecipeBuilder.SmithingType type = XSmithingRecipeBuilder.SmithingType.valueOf(typeStr.toUpperCase());
smithingRecipes[i] = XSmithingRecipeBuilder.builder(type).key(namespacedKey).result(result).base(base).addition(addition).template(template).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.yufiriamazenta.craftorithm.util;

import com.github.yufiriamazenta.craftorithm.Craftorithm;
import crypticlib.CrypticLib;
import crypticlib.config.impl.YamlConfigWrapper;
import me.clip.placeholderapi.PlaceholderAPI;
import net.md_5.bungee.api.ChatColor;
Expand Down Expand Up @@ -46,7 +47,7 @@ public static void sendMsg(CommandSender sender, String msgKey, Map<String, Stri
}

public static String color(String text) {
if (Craftorithm.getInstance().getVanillaVersion() >= 16) {
if (CrypticLib.minecraftVersion() >= 11600) {
StringBuilder strBuilder = new StringBuilder(text);
Matcher matcher = colorPattern.matcher(strBuilder);
while (matcher.find()) {
Expand Down

0 comments on commit 0bff137

Please sign in to comment.