9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-28 19:39:20 +00:00

[Compatibility] Oraxen 2.0 support

This commit is contained in:
XiaoMoMi
2024-04-29 14:35:29 +08:00
parent e750d40cf6
commit 9f379ec601
23 changed files with 378 additions and 37 deletions

View File

@@ -38,7 +38,7 @@ import net.momirealms.customcrops.mechanic.misc.migrator.Migration;
import net.momirealms.customcrops.mechanic.requirement.RequirementManagerImpl;
import net.momirealms.customcrops.mechanic.world.WorldManagerImpl;
import net.momirealms.customcrops.scheduler.SchedulerImpl;
import net.momirealms.customcrops.util.EventUtils;
import net.momirealms.customcrops.api.util.EventUtils;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;

View File

@@ -58,7 +58,7 @@ import net.momirealms.customcrops.mechanic.misc.TempFakeItem;
import net.momirealms.customcrops.mechanic.world.block.MemoryCrop;
import net.momirealms.customcrops.util.ClassUtils;
import net.momirealms.customcrops.util.ConfigUtils;
import net.momirealms.customcrops.util.EventUtils;
import net.momirealms.customcrops.api.util.EventUtils;
import net.momirealms.customcrops.util.ItemUtils;
import org.bukkit.*;
import org.bukkit.block.BlockFace;

View File

@@ -1,135 +0,0 @@
/*
* 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;
import net.momirealms.customcrops.api.manager.VersionManager;
import net.momirealms.customcrops.api.mechanic.misc.CRotation;
import net.momirealms.customcrops.api.util.LocationUtils;
import net.momirealms.customcrops.util.ConfigUtils;
import net.momirealms.customcrops.util.DisplayEntityUtils;
import net.momirealms.customcrops.util.RotationUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
import java.util.Collection;
public interface CustomProvider {
boolean removeBlock(Location location);
void placeCustomBlock(Location location, String id);
default void placeBlock(Location location, String id) {
if (ConfigUtils.isVanillaItem(id)) {
location.getBlock().setType(Material.valueOf(id));
} else {
placeCustomBlock(location, id);
}
}
Entity placeFurniture(Location location, String id);
void removeFurniture(Entity entity);
String getBlockID(Block block);
String getItemID(ItemStack itemInHand);
ItemStack getItemStack(String id);
String getEntityID(Entity entity);
boolean isFurniture(Entity entity);
default boolean isAir(Location location) {
Block block = location.getBlock();
if (block.getType() != Material.AIR)
return false;
Location center = LocationUtils.toCenterLocation(location);
Collection<Entity> entities = center.getWorld().getNearbyEntities(center, 0.5,0.51,0.5);
entities.removeIf(entity -> (entity instanceof Player || entity instanceof Item));
return entities.size() == 0;
}
default CRotation removeAnythingAt(Location location) {
if (!removeBlock(location)) {
Collection<Entity> entities = location.getWorld().getNearbyEntities(LocationUtils.toCenterLocation(location), 0.5,0.51,0.5);
entities.removeIf(entity -> {
EntityType type = entity.getType();
return type != EntityType.ITEM_FRAME
&& (!VersionManager.isHigherThan1_19_R3() || type != EntityType.ITEM_DISPLAY);
});
if (entities.size() == 0) return CRotation.NONE;
CRotation previousCRotation;
Entity first = entities.stream().findFirst().get();
if (first instanceof ItemFrame itemFrame) {
previousCRotation = CRotation.getByRotation(itemFrame.getRotation());
} else if (VersionManager.isHigherThan1_19_R3()) {
previousCRotation = DisplayEntityUtils.getRotation(first);
} else {
previousCRotation = CRotation.NONE;
}
for (Entity entity : entities) {
removeFurniture(entity);
}
return previousCRotation;
}
return CRotation.NONE;
}
default String getSomethingAt(Location location) {
Block block = location.getBlock();
if (block.getType() != Material.AIR) {
return getBlockID(block);
} else {
Collection<Entity> entities = location.getWorld().getNearbyEntities(location.toCenterLocation(), 0.5,0.51,0.5);
for (Entity entity : entities) {
if (isFurniture(entity)) {
return getEntityID(entity);
}
}
}
return "AIR";
}
default CRotation getRotation(Location location) {
if (location.getBlock().getType() == Material.AIR) {
Collection<Entity> entities = location.getWorld().getNearbyEntities(LocationUtils.toCenterLocation(location), 0.5,0.51,0.5);
entities.removeIf(entity -> {
EntityType type = entity.getType();
return type != EntityType.ITEM_FRAME
&& (!VersionManager.isHigherThan1_19_R3() || type != EntityType.ITEM_DISPLAY);
});
if (entities.size() == 0) return CRotation.NONE;
CRotation rotation;
Entity first = entities.stream().findFirst().get();
if (first instanceof ItemFrame itemFrame) {
rotation = CRotation.getByRotation(itemFrame.getRotation());
} else if (VersionManager.isHigherThan1_19_R3()) {
rotation = DisplayEntityUtils.getRotation(first);
} else {
rotation = CRotation.NONE;
}
return rotation;
}
return CRotation.NONE;
}
}

View File

@@ -40,13 +40,15 @@ import net.momirealms.customcrops.api.mechanic.world.SimpleLocation;
import net.momirealms.customcrops.api.mechanic.world.level.*;
import net.momirealms.customcrops.api.util.LocationUtils;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.mechanic.item.custom.AbstractCustomListener;
import net.momirealms.customcrops.api.mechanic.item.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;
import net.momirealms.customcrops.mechanic.item.custom.oraxen.OraxenProvider;
import net.momirealms.customcrops.mechanic.item.custom.oraxenlegacy.LegacyOraxenListener;
import net.momirealms.customcrops.mechanic.item.custom.oraxenlegacy.LegacyOraxenProvider;
import net.momirealms.customcrops.mechanic.item.function.CFunction;
import net.momirealms.customcrops.mechanic.item.function.FunctionResult;
import net.momirealms.customcrops.mechanic.item.function.FunctionTrigger;
@@ -58,7 +60,7 @@ import net.momirealms.customcrops.mechanic.item.impl.WateringCanConfig;
import net.momirealms.customcrops.mechanic.item.impl.fertilizer.*;
import net.momirealms.customcrops.mechanic.world.block.*;
import net.momirealms.customcrops.util.ConfigUtils;
import net.momirealms.customcrops.util.EventUtils;
import net.momirealms.customcrops.api.util.EventUtils;
import net.momirealms.customcrops.util.ItemUtils;
import net.momirealms.customcrops.util.RotationUtils;
import org.bukkit.*;
@@ -126,8 +128,13 @@ public class ItemManagerImpl implements ItemManager {
this.stage2CropStageMap = new HashMap<>();
this.deadCrops = new HashSet<>();
if (Bukkit.getPluginManager().getPlugin("Oraxen") != null) {
listener = new OraxenListener(this);
customProvider = new OraxenProvider();
if (Bukkit.getPluginManager().getPlugin("Oraxen").getDescription().getVersion().startsWith("2")) {
listener = new OraxenListener(this);
customProvider = new OraxenProvider();
} else {
listener = new LegacyOraxenListener(this);
customProvider = new LegacyOraxenProvider();
}
} else if (Bukkit.getPluginManager().getPlugin("ItemsAdder") != null) {
listener = new ItemsAdderListener(this);
customProvider = new ItemsAdderProvider();
@@ -2328,6 +2335,7 @@ public class ItemManagerImpl implements ItemManager {
}
}
@Override
@SuppressWarnings("DuplicatedCode")
public void handlePlayerInteractBlock(
Player player,
@@ -2358,6 +2366,7 @@ public class ItemManagerImpl implements ItemManager {
.ifPresent(itemFunctions -> handleFunctions(itemFunctions, condition, event));
}
@Override
public void handlePlayerInteractAir(
Player player,
Cancellable event
@@ -2377,6 +2386,7 @@ public class ItemManagerImpl implements ItemManager {
.ifPresent(cFunctions -> handleFunctions(cFunctions, condition, event));
}
@Override
public void handlePlayerBreakBlock(
Player player,
Block brokenBlock,
@@ -2395,6 +2405,7 @@ public class ItemManagerImpl implements ItemManager {
.ifPresent(cFunctions -> handleFunctions(cFunctions, new BreakBlockWrapper(player, brokenBlock), event));
}
@Override
@SuppressWarnings("DuplicatedCode")
public void handlePlayerInteractFurniture(
Player player,
@@ -2423,6 +2434,7 @@ public class ItemManagerImpl implements ItemManager {
.ifPresent(cFunctions -> handleFunctions(cFunctions, condition, event));
}
@Override
public void handlePlayerPlaceFurniture(
Player player,
Location location,
@@ -2442,6 +2454,7 @@ public class ItemManagerImpl implements ItemManager {
.ifPresent(cFunctions -> handleFunctions(cFunctions, new PlaceFurnitureWrapper(player, location, id), event));
}
@Override
public void handlePlayerBreakFurniture(
Player player,
Location location,
@@ -2461,6 +2474,7 @@ public class ItemManagerImpl implements ItemManager {
.ifPresent(cFunctions -> handleFunctions(cFunctions, new BreakFurnitureWrapper(player, location, id), event));
}
@Override
public void handlePlayerPlaceBlock(Player player, Block block, String blockID, Cancellable event) {
if (!plugin.getWorldManager().isMechanicEnabled(player.getWorld()))
return;
@@ -2475,6 +2489,7 @@ public class ItemManagerImpl implements ItemManager {
.ifPresent(cFunctions -> handleFunctions(cFunctions, new PlaceBlockWrapper(player, block, blockID), event));
}
@Override
public void handleEntityTramplingBlock(Entity entity, Block block, Cancellable event) {
if (entity instanceof Player player) {
handlePlayerBreakBlock(player, block, "FARMLAND", event);
@@ -2542,6 +2557,7 @@ public class ItemManagerImpl implements ItemManager {
}
}
@Override
public void handleExplosion(Entity entity, List<Block> blocks, Cancellable event) {
List<Location> locationsToRemove = new ArrayList<>();
List<Location> locationsToRemoveBlock = new ArrayList<>();

View File

@@ -1,328 +0,0 @@
/*
* 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;
import net.momirealms.customcrops.api.CustomCropsPlugin;
import net.momirealms.customcrops.api.event.BoneMealDispenseEvent;
import net.momirealms.customcrops.api.manager.ConfigManager;
import net.momirealms.customcrops.api.manager.VersionManager;
import net.momirealms.customcrops.api.manager.WorldManager;
import net.momirealms.customcrops.api.mechanic.item.*;
import net.momirealms.customcrops.api.mechanic.requirement.State;
import net.momirealms.customcrops.api.mechanic.world.SimpleLocation;
import net.momirealms.customcrops.api.mechanic.world.level.WorldCrop;
import net.momirealms.customcrops.mechanic.item.ItemManagerImpl;
import net.momirealms.customcrops.util.EventUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
public abstract class AbstractCustomListener implements Listener {
protected ItemManagerImpl itemManager;
private final HashSet<Material> CUSTOM_MATERIAL = new HashSet<>();
public AbstractCustomListener(ItemManagerImpl itemManager) {
this.itemManager = itemManager;
this.CUSTOM_MATERIAL.addAll(
List.of(
Material.NOTE_BLOCK,
Material.MUSHROOM_STEM,
Material.BROWN_MUSHROOM_BLOCK,
Material.RED_MUSHROOM_BLOCK,
Material.TRIPWIRE,
Material.CHORUS_PLANT,
Material.CHORUS_FLOWER,
Material.ACACIA_LEAVES,
Material.BIRCH_LEAVES,
Material.JUNGLE_LEAVES,
Material.DARK_OAK_LEAVES,
Material.AZALEA_LEAVES,
Material.FLOWERING_AZALEA_LEAVES,
Material.OAK_LEAVES,
Material.SPRUCE_LEAVES,
Material.CAVE_VINES,
Material.TWISTING_VINES,
Material.WEEPING_VINES,
Material.KELP,
Material.CACTUS
)
);
if (VersionManager.isHigherThan1_19()) {
this.CUSTOM_MATERIAL.add(
Material.MANGROVE_LEAVES
);
}
if (VersionManager.isHigherThan1_20()) {
this.CUSTOM_MATERIAL.add(
Material.CHERRY_LEAVES
);
}
}
@EventHandler (ignoreCancelled = true)
public void onInteractBlock(PlayerInteractEvent event) {
if (event.getHand() != EquipmentSlot.HAND)
return;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
Player player = event.getPlayer();
this.itemManager.handlePlayerInteractBlock(
player,
event.getClickedBlock(),
event.getBlockFace(),
event
);
}
@EventHandler (ignoreCancelled = false)
public void onInteractAir(PlayerInteractEvent event) {
if (event.getHand() != EquipmentSlot.HAND)
return;
if (event.getAction() != Action.RIGHT_CLICK_AIR)
return;
Player player = event.getPlayer();
this.itemManager.handlePlayerInteractAir(
player,
event
);
}
@EventHandler (ignoreCancelled = true, priority = EventPriority.LOW)
public void onBreakBlock(BlockBreakEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
Material type = block.getType();
// custom block should be handled by other plugins' events
if (CUSTOM_MATERIAL.contains(type))
return;
this.itemManager.handlePlayerBreakBlock(
player,
block,
type.name(),
event
);
}
@EventHandler (ignoreCancelled = true)
public void onPlaceBlock(BlockPlaceEvent event) {
final Block block = event.getBlock();
// prevent players from placing blocks on entities (crops/sprinklers)
if (CustomCropsPlugin.get().getWorldManager().getBlockAt(SimpleLocation.of(block.getLocation())).isPresent()) {
event.setCancelled(true);
return;
}
this.onPlaceBlock(
event.getPlayer(),
block,
event.getBlockPlaced().getType().name(),
event
);
}
@EventHandler (ignoreCancelled = true)
public void onItemSpawn(ItemSpawnEvent event) {
Item item = event.getEntity();
ItemStack itemStack = item.getItemStack();
String itemID = this.itemManager.getItemID(itemStack);
Crop.Stage stage = this.itemManager.getCropStageByStageID(itemID);
if (stage != null) {
event.setCancelled(true);
return;
}
Sprinkler sprinkler = this.itemManager.getSprinklerBy3DItemID(itemID);
if (sprinkler != null) {
ItemStack newItem = this.itemManager.getItemStack(null, sprinkler.get2DItemID());
if (newItem != null) {
newItem.setAmount(itemStack.getAmount());
item.setItemStack(newItem);
}
return;
}
Pot pot = this.itemManager.getPotByBlockID(itemID);
if (pot != null) {
ItemStack newItem = this.itemManager.getItemStack(null, pot.getDryItem());
if (newItem != null) {
newItem.setAmount(itemStack.getAmount());
item.setItemStack(newItem);
}
return;
}
}
@EventHandler (ignoreCancelled = true)
public void onBlockChange(BlockFadeEvent event) {
Block block = event.getBlock();
if (block.getType() == Material.FARMLAND) {
SimpleLocation above = SimpleLocation.of(block.getLocation()).add(0,1,0);
if (CustomCropsPlugin.get().getWorldManager().getBlockAt(above).isPresent()) {
event.setCancelled(true);
}
}
}
@EventHandler (ignoreCancelled = true)
public void onTrampling(EntityChangeBlockEvent event) {
Block block = event.getBlock();
if (block.getType() == Material.FARMLAND && event.getTo() == Material.DIRT) {
if (ConfigManager.preventTrampling()) {
event.setCancelled(true);
return;
}
itemManager.handleEntityTramplingBlock(event.getEntity(), block, event);
}
}
@EventHandler (ignoreCancelled = true)
public void onMoistureChange(MoistureChangeEvent event) {
if (ConfigManager.disableMoisture())
event.setCancelled(true);
}
@EventHandler (ignoreCancelled = true)
public void onPistonExtend(BlockPistonExtendEvent event) {
WorldManager manager = CustomCropsPlugin.get().getWorldManager();
for (Block block : event.getBlocks()) {
if (manager.getBlockAt(SimpleLocation.of(block.getLocation())).isPresent()) {
event.setCancelled(true);
return;
}
}
}
@EventHandler (ignoreCancelled = true)
public void onPistonRetract(BlockPistonRetractEvent event) {
WorldManager manager = CustomCropsPlugin.get().getWorldManager();
for (Block block : event.getBlocks()) {
if (manager.getBlockAt(SimpleLocation.of(block.getLocation())).isPresent()) {
event.setCancelled(true);
return;
}
}
}
@EventHandler (ignoreCancelled = true)
public void onItemDamage(PlayerItemDamageEvent event) {
ItemStack itemStack = event.getItem();
WateringCan wateringCan = this.itemManager.getWateringCanByItemStack(itemStack);
if (wateringCan != null) {
event.setCancelled(true);
}
}
@EventHandler (ignoreCancelled = true)
public void onExplosion(EntityExplodeEvent event) {
this.itemManager.handleExplosion(event.getEntity(), event.blockList(), event);
}
@EventHandler (ignoreCancelled = true)
public void onExplosion(BlockExplodeEvent event) {
this.itemManager.handleExplosion(null, event.blockList(), event);
}
@EventHandler (ignoreCancelled = true)
public void onDispenser(BlockDispenseEvent event) {
Block block = event.getBlock();
if (block.getBlockData() instanceof org.bukkit.block.data.type.Dispenser directional) {
Block relative = block.getRelative(directional.getFacing());
Location location = relative.getLocation();
SimpleLocation simpleLocation = SimpleLocation.of(location);
Optional<WorldCrop> worldCropOptional = CustomCropsPlugin.get().getWorldManager().getCropAt(simpleLocation);
if (worldCropOptional.isPresent()) {
WorldCrop crop = worldCropOptional.get();
Crop config = crop.getConfig();
ItemStack itemStack = event.getItem();
String itemID = itemManager.getItemID(itemStack);
if (crop.getPoint() < config.getMaxPoints()) {
for (BoneMeal boneMeal : config.getBoneMeals()) {
if (boneMeal.getItem().equals(itemID)) {
if (!boneMeal.isDispenserAllowed()) {
return;
}
// fire the event
if (EventUtils.fireAndCheckCancel(new BoneMealDispenseEvent(block, itemStack, location, boneMeal, crop))) {
event.setCancelled(true);
return;
}
if (block.getState() instanceof Dispenser dispenser) {
event.setCancelled(true);
Inventory inventory = dispenser.getInventory();
for (ItemStack storage : inventory.getStorageContents()) {
if (storage == null) continue;
String id = itemManager.getItemID(storage);
if (id.equals(itemID)) {
storage.setAmount(storage.getAmount() - 1);
boneMeal.trigger(new State(null, itemStack, location));
CustomCropsPlugin.get().getWorldManager().addPointToCrop(config, boneMeal.getPoint(), simpleLocation);
}
}
}
return;
}
}
}
}
}
}
public void onPlaceBlock(Player player, Block block, String blockID, Cancellable event) {
if (player == null) return;
this.itemManager.handlePlayerPlaceBlock(player, block, blockID, event);
}
public void onBreakFurniture(Player player, Location location, String id, Cancellable event) {
if (player == null) return;
this.itemManager.handlePlayerBreakFurniture(player, location, id, event);
}
public void onPlaceFurniture(Player player, Location location, String id, Cancellable event) {
if (player == null) return;
this.itemManager.handlePlayerPlaceFurniture(player, location, id, event);
}
public void onInteractFurniture(Player player, Location location, String id, @Nullable Entity baseEntity, Cancellable event) {
if (player == null) return;
this.itemManager.handlePlayerInteractFurniture(player, location, id, baseEntity, event);
}
}

View File

@@ -19,7 +19,7 @@ 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 net.momirealms.customcrops.api.mechanic.item.AbstractCustomListener;
import org.bukkit.event.EventHandler;
public class CrucibleListener extends AbstractCustomListener {

View File

@@ -27,7 +27,7 @@ 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 net.momirealms.customcrops.api.mechanic.item.CustomProvider;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;

View File

@@ -20,7 +20,7 @@ package net.momirealms.customcrops.mechanic.item.custom.itemsadder;
import dev.lone.itemsadder.api.CustomFurniture;
import dev.lone.itemsadder.api.Events.*;
import net.momirealms.customcrops.mechanic.item.ItemManagerImpl;
import net.momirealms.customcrops.mechanic.item.custom.AbstractCustomListener;
import net.momirealms.customcrops.api.mechanic.item.AbstractCustomListener;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;

View File

@@ -21,7 +21,7 @@ import dev.lone.itemsadder.api.CustomBlock;
import dev.lone.itemsadder.api.CustomFurniture;
import dev.lone.itemsadder.api.CustomStack;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.mechanic.item.CustomProvider;
import net.momirealms.customcrops.api.mechanic.item.CustomProvider;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;

View File

@@ -17,16 +17,16 @@
package net.momirealms.customcrops.mechanic.item.custom.oraxen;
import io.th0rgal.oraxen.api.events.custom_block.noteblock.OraxenNoteBlockBreakEvent;
import io.th0rgal.oraxen.api.events.custom_block.noteblock.OraxenNoteBlockPlaceEvent;
import io.th0rgal.oraxen.api.events.custom_block.stringblock.OraxenStringBlockBreakEvent;
import io.th0rgal.oraxen.api.events.custom_block.stringblock.OraxenStringBlockPlaceEvent;
import io.th0rgal.oraxen.api.events.furniture.OraxenFurnitureBreakEvent;
import io.th0rgal.oraxen.api.events.furniture.OraxenFurnitureInteractEvent;
import io.th0rgal.oraxen.api.events.furniture.OraxenFurniturePlaceEvent;
import io.th0rgal.oraxen.api.events.noteblock.OraxenNoteBlockBreakEvent;
import io.th0rgal.oraxen.api.events.noteblock.OraxenNoteBlockPlaceEvent;
import io.th0rgal.oraxen.api.events.stringblock.OraxenStringBlockBreakEvent;
import io.th0rgal.oraxen.api.events.stringblock.OraxenStringBlockPlaceEvent;
import net.momirealms.customcrops.api.util.LocationUtils;
import net.momirealms.customcrops.mechanic.item.ItemManagerImpl;
import net.momirealms.customcrops.mechanic.item.custom.AbstractCustomListener;
import net.momirealms.customcrops.api.mechanic.item.AbstractCustomListener;
import org.bukkit.event.EventHandler;
public class OraxenListener extends AbstractCustomListener {
@@ -98,10 +98,10 @@ public class OraxenListener extends AbstractCustomListener {
@EventHandler (ignoreCancelled = true)
public void onInteractFurniture(OraxenFurnitureInteractEvent event) {
super.onInteractFurniture(
event.getPlayer(),
LocationUtils.toBlockLocation(event.getBaseEntity().getLocation()),
event.getMechanic().getItemID(),
event.getBaseEntity(),
event.player(),
LocationUtils.toBlockLocation(event.baseEntity().getLocation()),
event.mechanic().getItemID(),
event.baseEntity(),
event
);
}

View File

@@ -24,7 +24,7 @@ import io.th0rgal.oraxen.items.ItemBuilder;
import io.th0rgal.oraxen.mechanics.Mechanic;
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.mechanic.item.CustomProvider;
import net.momirealms.customcrops.api.mechanic.item.CustomProvider;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Rotation;
@@ -66,7 +66,7 @@ public class OraxenProvider implements CustomProvider {
@Override
public String getBlockID(Block block) {
Mechanic mechanic = OraxenBlocks.getOraxenBlock(block.getLocation());
Mechanic mechanic = OraxenBlocks.getCustomBlockMechanic(block.getLocation());
if (mechanic == null) {
return block.getType().name();
}

View File

@@ -36,7 +36,7 @@ import net.momirealms.customcrops.api.mechanic.world.season.Season;
import net.momirealms.customcrops.api.scheduler.CancellableTask;
import net.momirealms.customcrops.api.scheduler.Scheduler;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.util.EventUtils;
import net.momirealms.customcrops.api.util.EventUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;

View File

@@ -1,15 +0,0 @@
package net.momirealms.customcrops.util;
import net.momirealms.customcrops.api.mechanic.misc.CRotation;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemDisplay;
public class DisplayEntityUtils {
public static CRotation getRotation(Entity entity) {
if (entity instanceof ItemDisplay itemDisplay) {
return CRotation.getByYaw(itemDisplay.getLocation().getYaw());
}
return CRotation.NONE;
}
}

View File

@@ -1,36 +0,0 @@
/*
* 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.util;
import org.bukkit.Bukkit;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
public class EventUtils {
public static void fireAndForget(Event event) {
Bukkit.getPluginManager().callEvent(event);
}
public static boolean fireAndCheckCancel(Event event) {
if (!(event instanceof Cancellable cancellable))
throw new IllegalArgumentException("Only cancellable events are allowed here");
Bukkit.getPluginManager().callEvent(event);
return cancellable.isCancelled();
}
}