Skip to content

Commit

Permalink
引入AzureFlow支持
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Jan 20, 2025
1 parent 140cad7 commit b194a9c
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 25 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.text.SimpleDateFormat
version = "1.10.17-beta2"
version = "1.10.17-beta3"

plugins {
`java-library`
Expand Down Expand Up @@ -53,6 +53,7 @@ dependencies {
compileOnly("com.willfp:libreforge:4.71.6:all@jar")
compileOnly("com.ssomar:SCore:5.24.10.5")
compileOnly("com.nexomc:nexo:0.7.0")
compileOnly(fileTree("libs"))
implementation("com.crypticlib:bukkit:${rootProject.findProperty("crypticlibVer")}")
implementation("com.crypticlib:bukkit-ui:${rootProject.findProperty("crypticlibVer")}")
implementation("com.crypticlib:bukkit-conversation:${rootProject.findProperty("crypticlibVer")}")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
crypticlibVer=1.8.2
crypticlibVer=1.10.5
Binary file added libs/AzureFlow-1.0.2.4-rc1-build-41216-all.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void enable() {
BukkitMsgSender.INSTANCE.info("&c[Craftorithm] Unsupported Version");
throw new UnsupportedVersionException();
}
CrypticLib.DEBUG = PluginConfigs.DEBUG.value();
CrypticLib.setDebug(PluginConfigs.DEBUG.value());
loadBStat();

UpdateChecker.pullUpdateCheckRequest(Bukkit.getConsoleSender());
Expand Down Expand Up @@ -80,13 +80,13 @@ public static CraftorithmAPI api() {
@Override
public void run(Plugin plugin, LifeCycle lifeCycle) {
if (lifeCycle == LifeCycle.ACTIVE) {
CrypticLibBukkit.scheduler().runTask(this, () -> {
CrypticLibBukkit.scheduler().sync(() -> {
RecipeManager.INSTANCE.reloadRecipeManager();
OtherPluginsListenerManager.INSTANCE.convertOtherPluginsListeners();
LangUtils.info(Languages.LOAD_FINISH);
});
} else {
CrypticLib.DEBUG = PluginConfigs.DEBUG.value();
CrypticLib.setDebug(PluginConfigs.DEBUG.value());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Metrics(JavaPlugin plugin, int serviceId) {
enabled,
this::appendPlatformData,
this::appendServiceData,
submitDataTask -> CrypticLibBukkit.scheduler().runTask(plugin, submitDataTask),
submitDataTask -> CrypticLibBukkit.scheduler().sync(submitDataTask),
plugin::isEnabled,
(message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
(message) -> this.plugin.getLogger().log(Level.INFO, message),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void execute(CommandSender sender, List<String> args) {
player.getWorld().dropItem(player.getLocation(), stack);
}
};
CrypticLibBukkit.scheduler().runTaskOnEntity(Craftorithm.instance(), player, dropTask, dropTask);
CrypticLibBukkit.scheduler().runOnEntity(player, dropTask, dropTask);
}
}
LangUtils.sendLang(sender, Languages.COMMAND_ITEM_GIVE_SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.yufiriamazenta.craftorithm.hook.impl;

import com.github.yufiriamazenta.craftorithm.hook.ItemPluginHooker;
import com.github.yufiriamazenta.craftorithm.item.ItemProvider;
import com.github.yufiriamazenta.craftorithm.item.impl.AzureFlowItemProvider;
import crypticlib.lifecycle.AutoTask;
import crypticlib.lifecycle.LifeCycle;
import crypticlib.lifecycle.TaskRule;

@AutoTask(rules = @TaskRule(lifeCycle = LifeCycle.ACTIVE))
public enum AzureFlowHooker implements ItemPluginHooker {

INSTANCE;

@Override
public ItemProvider itemProvider() {
return AzureFlowItemProvider.INSTANCE;
}

@Override
public String pluginName() {
return "AzureFlow";
}

@Override
public boolean hook() {
return hookByEnabled();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.github.yufiriamazenta.craftorithm.item.impl;

import com.github.yufiriamazenta.craftorithm.item.ItemProvider;
import io.rokuko.azureflow.api.AzureFlowAPI;
import io.rokuko.azureflow.features.item.AzureFlowItem;
import io.rokuko.azureflow.features.item.factory.AzureFlowItemFactory;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public enum AzureFlowItemProvider implements ItemProvider {

INSTANCE;

@Override
public @NotNull String namespace() {
return "azureflow";
}

@Override
public @Nullable String getItemName(ItemStack itemStack, boolean ignoreAmount) {
AzureFlowItem azureFlowItem = AzureFlowAPI.toItem(itemStack);
if (azureFlowItem == null) {
return null;
}
String itemId = azureFlowItem.getUuid();
if (ignoreAmount) {
return itemId;
} else {
return itemId + itemStack.getAmount() / Objects.requireNonNull(getItem(itemId)).getAmount();
}
}

@Override
public @Nullable ItemStack getItem(String itemName) {
AzureFlowItemFactory factory = AzureFlowAPI.getFactory(itemName);
if (factory == null) {
return null;
}
AzureFlowItem azureFlowItem = factory.build();
return azureFlowItem.staticItemStack();
}

@Override
public @Nullable ItemStack getItem(String itemName, @Nullable OfflinePlayer player) {
AzureFlowItemFactory factory = AzureFlowAPI.getFactory(itemName);
if (factory == null) {
return null;
}
AzureFlowItem azureFlowItem = factory.build();
if (player == null) {
return azureFlowItem.staticItemStack();
}
return azureFlowItem.virtualItemStack(player.getPlayer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import crypticlib.lifecycle.BukkitLifeCycleTask;
import crypticlib.lifecycle.LifeCycle;
import crypticlib.lifecycle.TaskRule;
import crypticlib.util.FileHelper;
import crypticlib.util.IOHelper;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
Expand Down Expand Up @@ -84,7 +84,7 @@ private void loadItemFiles() {
if (!mkdirResult)
throw new RuntimeException("Create item folder failed");
}
List<File> allFiles = FileHelper.allYamlFiles(ITEM_FILE_FOLDER);
List<File> allFiles = IOHelper.allYamlFiles(ITEM_FILE_FOLDER);
if (allFiles.isEmpty()) {
Craftorithm.instance().saveResource("items/example_item.yml", false);
allFiles.add(new File(ITEM_FILE_FOLDER, "example_item.yml"));
Expand Down Expand Up @@ -124,7 +124,7 @@ public String regCraftorithmItem(String namespace, String itemName, ItemStack it
if (!itemConfigFileMap.containsKey(namespace)) {
File itemFile = new File(ITEM_FILE_FOLDER, namespace + ".yml");
if (!itemFile.exists()) {
FileHelper.createNewFile(itemFile);
IOHelper.createNewFile(itemFile);
}
itemConfigFile = new BukkitConfigWrapper(itemFile);
itemConfigFileMap.put(namespace, itemConfigFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void runConditions(PrepareAnvilEvent event) {
YamlConfiguration config = RecipeManager.INSTANCE.getRecipeConfig(anvilRecipe.key());
if (config != null) {
Object inventoryView = InventoryViewHelper.getInventoryView(event);
Player player = (Player) InventoryViewHelper.getPlayer(inventoryView);
Player player = (Player) InventoryViewHelper.getViewingPlayer(inventoryView);
String condition = config.getString("condition", "true");
condition = "if " + condition;
boolean conditionResult = (boolean) ArcencielDispatcher.INSTANCE.dispatchArcencielBlock(player, condition).obj();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void runConditions(PrepareItemCraftEvent event) {
return;

Object inventoryView = InventoryViewHelper.getInventoryView(event);
Player player = (Player) InventoryViewHelper.getPlayer(inventoryView);
Player player = (Player) InventoryViewHelper.getViewingPlayer(inventoryView);
String condition = config.getString("condition", "true");
condition = "if " + condition;
boolean result = (boolean) ArcencielDispatcher.INSTANCE.dispatchArcencielBlock(player, condition).obj();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void putRecipeCache(Block block, CookingRecipe<?> recipe) {
blockSmeltRecipeMap.put(block, recipe);
int cookingTime = recipe.getCookingTime();
//防止玩家对大量烧炼方块进行烧炼打断操作导致出现大量无用缓存,在烧炼配方预计完成时间的一秒后清除缓存
CrypticLibBukkit.scheduler().runTaskLaterAsync(Craftorithm.instance(), () -> {
CrypticLibBukkit.scheduler().asyncLater(() -> {
blockSmeltRecipeMap.remove(block);
}, cookingTime + 20);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void runConditions(PrepareSmithingEvent event) {
return;

Object inventoryView = InventoryViewHelper.getInventoryView(event);
Player player = (Player) InventoryViewHelper.getPlayer(inventoryView);
Player player = (Player) InventoryViewHelper.getViewingPlayer(inventoryView);
String condition = config.getString("condition", "true");
condition = "if " + condition;
boolean result = (boolean) ArcencielDispatcher.INSTANCE.dispatchArcencielBlock(player, condition).obj();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import crypticlib.ui.display.Icon;
import crypticlib.ui.display.IconDisplay;
import crypticlib.ui.menu.StoredMenu;
import crypticlib.util.FileHelper;
import crypticlib.util.IOHelper;
import crypticlib.util.ItemHelper;
import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand Down Expand Up @@ -72,7 +72,7 @@ protected void sendSuccessMsg(HumanEntity receiver, String recipeName) {
protected BukkitConfigWrapper createRecipeConfig(String recipeName) {
File recipeFile = new File(RecipeManager.INSTANCE.RECIPE_FILE_FOLDER, recipeName + ".yml");
if (!recipeFile.exists()) {
FileHelper.createNewFile(recipeFile);
IOHelper.createNewFile(recipeFile);
}
BukkitConfigWrapper configWrapper = new BukkitConfigWrapper(recipeFile);
configWrapper.reloadConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ private void setAnvilRecipeMenu() {
@Override
public void onClose(InventoryCloseEvent event) {
if (parentMenu != null) {
CrypticLibBukkit.scheduler().runTask(
Craftorithm.instance(),
CrypticLibBukkit.scheduler().sync(
() -> {
InventoryType type = event.getPlayer().getOpenInventory().getType();
List<InventoryType> typeWhenNotOpenInv = Arrays.asList(InventoryType.CRAFTING, InventoryType.CREATIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ private void resetIcons() {
@Override
public void onClose(InventoryCloseEvent event) {
if (parentMenu != null) {
CrypticLibBukkit.scheduler().runTask(
Craftorithm.instance(),
CrypticLibBukkit.scheduler().sync(
() -> {
InventoryType type = event.getPlayer().getOpenInventory().getType();
List<InventoryType> typeWhenNotOpenInv = Arrays.asList(InventoryType.CRAFTING, InventoryType.CREATIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import crypticlib.lifecycle.BukkitLifeCycleTask;
import crypticlib.lifecycle.LifeCycle;
import crypticlib.lifecycle.TaskRule;
import crypticlib.platform.Platform;
import crypticlib.util.FileHelper;
import crypticlib.util.IOHelper;
import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
Expand Down Expand Up @@ -131,7 +130,7 @@ private void loadRecipeGroups() {
if (!mkdirResult)
return;
}
List<File> allFiles = FileHelper.allYamlFiles(RECIPE_FILE_FOLDER);
List<File> allFiles = IOHelper.allYamlFiles(RECIPE_FILE_FOLDER);
if (allFiles.isEmpty()) {
saveDefConfigFile(allFiles);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
public static void pullUpdateCheckRequest(CommandSender sender) {
if (!PluginConfigs.CHECK_UPDATE.value())
return;
CrypticLibBukkit.scheduler().runTaskAsync(Craftorithm.instance(), () -> {
CrypticLibBukkit.scheduler().async(() -> {
try {
URL url = new URL("https://api.spigotmc.org/legacy/update.php?resource=108429/");
URLConnection conn = url.openConnection();
Expand All @@ -40,7 +40,7 @@ public static void pullUpdateCheckRequest(CommandSender sender) {
String pluginVersion = Craftorithm.instance().getDescription().getVersion();
pluginVersion = pluginVersion.substring(0, pluginVersion.indexOf("-"));
if (checkVersion(latestVersion, pluginVersion)) {
CrypticLibBukkit.scheduler().runTask(Craftorithm.instance(), () -> {
CrypticLibBukkit.scheduler().sync(() -> {
LangUtils.sendLang(sender, Languages.NEW_VERSION, CollectionsUtils.newStringHashMap("<new_version>", latestVersion));
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ softdepend:
- EcoItems
- ExecutableItems
- SCore
- Nexo
- AzureFlow
authors: [ YufiriaMazenta ]
folia-supported: true
website: https://github.com/YufiriaMazenta/Craftorithm
Expand Down

0 comments on commit b194a9c

Please sign in to comment.