mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-25 09:59:20 +00:00
crucible
This commit is contained in:
@@ -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.");
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<CustomBlockItemContext> 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<CrucibleItem> 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<CrucibleItem> 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<Furniture> optional = furnitureManager.getFurniture(entity.getUniqueId());
|
||||
optional.ifPresent(furniture -> furniture.getFurnitureData().remove(furniture, null, false, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBlockID(Block block) {
|
||||
Optional<CustomBlockItemContext> optionalCB = blockManager.getBlockFromBlock(block);
|
||||
return optionalCB.map(customBlockItemContext -> customBlockItemContext.getCrucibleItem().getInternalName()).orElse(block.getType().name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemID(ItemStack itemStack) {
|
||||
Optional<CrucibleItem> optionalCI = itemManager.getItem(itemStack);
|
||||
if (optionalCI.isEmpty()) return itemStack.getType().name();
|
||||
else return optionalCI.get().getInternalName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(String id) {
|
||||
Optional<CrucibleItem> optionalCI = itemManager.getItem(id);
|
||||
return optionalCI.map(crucibleItem -> BukkitAdapter.adapt(crucibleItem.getMythicItem().generateItemStack(1))).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEntityID(Entity entity) {
|
||||
Optional<CrucibleItem> 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));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user