From 1c2f7729ef336a8fc9df31fb437015a76d97e2e2 Mon Sep 17 00:00:00 2001 From: XiaoMoMi <972454774@qq.com> Date: Sat, 16 Mar 2024 22:08:45 +0800 Subject: [PATCH] crucible --- plugin/build.gradle.kts | 1 + .../mechanic/item/ItemManagerImpl.java | 5 + .../custom/crucible/CrucibleListener.java | 56 ++++++++ .../custom/crucible/CrucibleProvider.java | 128 ++++++++++++++++++ .../item/custom/oraxen/OraxenProvider.java | 6 +- 5 files changed, 193 insertions(+), 3 deletions(-) create mode 100644 plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/crucible/CrucibleListener.java create mode 100644 plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/crucible/CrucibleProvider.java diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 872644f..e4ed660 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -35,6 +35,7 @@ dependencies { compileOnly("net.Indyuce:MMOItems-API:6.9.2-SNAPSHOT") compileOnly("io.lumine:MythicLib-dist:1.6-SNAPSHOT") compileOnly("io.lumine:Mythic-Dist:5.3.5") + compileOnly("io.lumine:MythicCrucible-Dist:2.1.0-SNAPSHOT") // Quests compileOnly("org.betonquest:betonquest:2.0.0") diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java index 320ea05..e3daee0 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java @@ -40,6 +40,8 @@ import net.momirealms.customcrops.api.mechanic.world.SimpleLocation; import net.momirealms.customcrops.api.mechanic.world.level.*; import net.momirealms.customcrops.api.util.LogUtils; import net.momirealms.customcrops.mechanic.item.custom.AbstractCustomListener; +import net.momirealms.customcrops.mechanic.item.custom.crucible.CrucibleListener; +import net.momirealms.customcrops.mechanic.item.custom.crucible.CrucibleProvider; import net.momirealms.customcrops.mechanic.item.custom.itemsadder.ItemsAdderListener; import net.momirealms.customcrops.mechanic.item.custom.itemsadder.ItemsAdderProvider; import net.momirealms.customcrops.mechanic.item.custom.oraxen.OraxenListener; @@ -128,6 +130,9 @@ public class ItemManagerImpl implements ItemManager { } else if (Bukkit.getPluginManager().isPluginEnabled("ItemsAdder")) { listener = new ItemsAdderListener(this); customProvider = new ItemsAdderProvider(); + } else if (Bukkit.getPluginManager().isPluginEnabled("MythicCrucible")) { + listener = new CrucibleListener(this); + customProvider = new CrucibleProvider(); } else { LogUtils.severe("======================================================"); LogUtils.severe(" Please install ItemsAdder or Oraxen as dependency."); diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/crucible/CrucibleListener.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/crucible/CrucibleListener.java new file mode 100644 index 0000000..1d896d6 --- /dev/null +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/crucible/CrucibleListener.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.mechanic.item.custom.crucible; + +import io.lumine.mythiccrucible.events.MythicFurniturePlaceEvent; +import net.momirealms.customcrops.mechanic.item.ItemManagerImpl; +import net.momirealms.customcrops.mechanic.item.custom.AbstractCustomListener; +import org.bukkit.event.EventHandler; + +public class CrucibleListener extends AbstractCustomListener { + + public CrucibleListener(ItemManagerImpl itemManager) { + super(itemManager); + } + + @EventHandler (ignoreCancelled = true) + public void onBreakCustomBlock() { + } + + @EventHandler (ignoreCancelled = true) + public void onPlaceCustomBlock() { + } + + @EventHandler (ignoreCancelled = true) + public void onPlaceFurniture(MythicFurniturePlaceEvent event) { + super.onPlaceFurniture( + event.getPlayer(), + event.getBlock().getLocation(), + event.getFurnitureItemContext().getItem().getInternalName(), + event + ); + } + + @EventHandler (ignoreCancelled = true) + public void onBreakFurniture() { + } + + @EventHandler (ignoreCancelled = true) + public void onInteractFurniture() { + } +} diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/crucible/CrucibleProvider.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/crucible/CrucibleProvider.java new file mode 100644 index 0000000..705e499 --- /dev/null +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/crucible/CrucibleProvider.java @@ -0,0 +1,128 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.mechanic.item.custom.crucible; + +import io.lumine.mythic.bukkit.BukkitAdapter; +import io.lumine.mythic.bukkit.adapters.BukkitEntity; +import io.lumine.mythiccrucible.MythicCrucible; +import io.lumine.mythiccrucible.items.CrucibleItem; +import io.lumine.mythiccrucible.items.ItemManager; +import io.lumine.mythiccrucible.items.blocks.CustomBlockItemContext; +import io.lumine.mythiccrucible.items.blocks.CustomBlockManager; +import io.lumine.mythiccrucible.items.furniture.Furniture; +import io.lumine.mythiccrucible.items.furniture.FurnitureManager; +import net.momirealms.customcrops.api.util.LogUtils; +import net.momirealms.customcrops.mechanic.item.CustomProvider; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.ItemStack; + +import java.util.Optional; + +public class CrucibleProvider implements CustomProvider { + + private final ItemManager itemManager; + private final CustomBlockManager blockManager; + private final FurnitureManager furnitureManager; + + public CrucibleProvider() { + this.itemManager = MythicCrucible.inst().getItemManager(); + this.blockManager = itemManager.getCustomBlockManager(); + this.furnitureManager = itemManager.getFurnitureManager(); + } + + @Override + public boolean removeBlock(Location location) { + Block block = location.getBlock(); + if (block.getType() == Material.AIR) { + return false; + } + Optional optional = blockManager.getBlockFromBlock(block); + if (optional.isPresent()) { + optional.get().remove(block, null, false); + } else { + block.setType(Material.AIR); + } + return true; + } + + @Override + public void placeCustomBlock(Location location, String id) { + Optional optionalCI = itemManager.getItem(id); + if (optionalCI.isPresent()) { + location.getBlock().setBlockData(optionalCI.get().getBlockData().getBlockData()); + } else { + LogUtils.warn("Custom block(" + id +") doesn't exist in Crucible configs. Please double check if that block exists."); + } + } + + @Override + public Entity placeFurniture(Location location, String id) { + Location center = location.toCenterLocation(); + center.setY(center.getBlockY()); + Optional optionalCI = itemManager.getItem(id); + if (optionalCI.isPresent()) { + return optionalCI.get().getFurnitureData().placeFrame(location.getBlock(), BlockFace.UP, 0f, null); + } else { + LogUtils.warn("Furniture(" + id +") doesn't exist in Crucible configs. Please double check if that furniture exists."); + return null; + } + } + + @Override + public void removeFurniture(Entity entity) { + Optional optional = furnitureManager.getFurniture(entity.getUniqueId()); + optional.ifPresent(furniture -> furniture.getFurnitureData().remove(furniture, null, false, false)); + } + + @Override + public String getBlockID(Block block) { + Optional optionalCB = blockManager.getBlockFromBlock(block); + return optionalCB.map(customBlockItemContext -> customBlockItemContext.getCrucibleItem().getInternalName()).orElse(block.getType().name()); + } + + @Override + public String getItemID(ItemStack itemStack) { + Optional optionalCI = itemManager.getItem(itemStack); + if (optionalCI.isEmpty()) return itemStack.getType().name(); + else return optionalCI.get().getInternalName(); + } + + @Override + public ItemStack getItemStack(String id) { + Optional optionalCI = itemManager.getItem(id); + return optionalCI.map(crucibleItem -> BukkitAdapter.adapt(crucibleItem.getMythicItem().generateItemStack(1))).orElse(null); + } + + @Override + public String getEntityID(Entity entity) { + Optional optionalCI = furnitureManager.getItemFromEntity(entity); + if (optionalCI.isPresent()) { + return optionalCI.get().getInternalName(); + } + return entity.getType().name(); + } + + @Override + public boolean isFurniture(Entity entity) { + return furnitureManager.isFurniture(new BukkitEntity(entity)); + } +} diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/oraxen/OraxenProvider.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/oraxen/OraxenProvider.java index 11f0fa4..1b2d5bd 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/oraxen/OraxenProvider.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/oraxen/OraxenProvider.java @@ -78,10 +78,10 @@ public class OraxenProvider implements CustomProvider { } @Override - public String getItemID(ItemStack itemInHand) { - String id = OraxenItems.getIdByItem(itemInHand); + public String getItemID(ItemStack itemStack) { + String id = OraxenItems.getIdByItem(itemStack); if (id == null) { - return itemInHand.getType().name(); + return itemStack.getType().name(); } return id; }