mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-19 15:09:25 +00:00
improved compatibility with itemsadder 4.0.8+
This commit is contained in:
25
compatibility-itemsadder-r2/build.gradle.kts
Normal file
25
compatibility-itemsadder-r2/build.gradle.kts
Normal file
@@ -0,0 +1,25 @@
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://maven.devs.beer/")
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":api"))
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
|
||||
compileOnly("dev.lone:api-itemsadder:4.0.9")
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
options.release.set(21)
|
||||
dependsOn(tasks.clean)
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (C) <2024> <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.bukkit.integration.custom.itemsadder_r1;
|
||||
|
||||
import dev.lone.itemsadder.api.Events.*;
|
||||
import net.momirealms.customcrops.api.core.AbstractCustomEventListener;
|
||||
import net.momirealms.customcrops.api.core.AbstractItemManager;
|
||||
import net.momirealms.customcrops.api.util.DummyCancellable;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemsAdderListener extends AbstractCustomEventListener {
|
||||
|
||||
private static final Set<Material> IGNORED = new HashSet<>(
|
||||
List.of(
|
||||
Material.NOTE_BLOCK,
|
||||
Material.MUSHROOM_STEM, Material.BROWN_MUSHROOM_BLOCK, Material.RED_MUSHROOM_BLOCK,
|
||||
Material.TRIPWIRE,
|
||||
Material.CHORUS_PLANT
|
||||
)
|
||||
);
|
||||
|
||||
@Override
|
||||
protected Set<Material> ignoredMaterials() {
|
||||
return IGNORED;
|
||||
}
|
||||
|
||||
public ItemsAdderListener(AbstractItemManager itemManager) {
|
||||
super(itemManager);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInteractFurniture(FurnitureInteractEvent event) {
|
||||
itemManager.handlePlayerInteractFurniture(
|
||||
event.getPlayer(),
|
||||
event.getBukkitEntity().getLocation(), event.getNamespacedID(),
|
||||
EquipmentSlot.HAND, event.getPlayer().getInventory().getItemInMainHand(),
|
||||
event
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInteractCustomBlock(CustomBlockInteractEvent event) {
|
||||
itemManager.handlePlayerInteractBlock(
|
||||
event.getPlayer(),
|
||||
event.getBlockClicked(),
|
||||
event.getNamespacedID(),
|
||||
event.getBlockFace(),
|
||||
event.getHand(),
|
||||
event.getItem(),
|
||||
event
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBreakFurniture(FurnitureBreakEvent event) {
|
||||
itemManager.handlePlayerBreak(
|
||||
event.getPlayer(),
|
||||
event.getBukkitEntity().getLocation(), event.getPlayer().getInventory().getItemInMainHand(), event.getNamespacedID(),
|
||||
event
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBreakCustomBlock(CustomBlockBreakEvent event) {
|
||||
itemManager.handlePlayerBreak(
|
||||
event.getPlayer(),
|
||||
event.getBlock().getLocation(), event.getPlayer().getInventory().getItemInMainHand(), event.getNamespacedID(),
|
||||
event
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlaceCustomBlock(CustomBlockPlaceEvent event) {
|
||||
itemManager.handlePlayerPlace(
|
||||
event.getPlayer(),
|
||||
event.getBlock().getLocation(),
|
||||
event.getNamespacedID(),
|
||||
EquipmentSlot.HAND,
|
||||
event.getItemInHand(),
|
||||
event
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlaceFurniture(FurniturePlacedEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
// ItemsAdder would trigger FurniturePlaceSuccessEvent if the furniture is placed by API
|
||||
if (player == null) return;
|
||||
itemManager.handlePlayerPlace(
|
||||
player,
|
||||
event.getBukkitEntity().getLocation(),
|
||||
event.getNamespacedID(),
|
||||
EquipmentSlot.HAND,
|
||||
event.getPlayer().getInventory().getItemInMainHand(),
|
||||
event
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) <2024> <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.bukkit.integration.custom.itemsadder_r1;
|
||||
|
||||
import dev.lone.itemsadder.api.CustomBlock;
|
||||
import dev.lone.itemsadder.api.CustomFurniture;
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.core.CustomItemProvider;
|
||||
import net.momirealms.customcrops.api.util.LocationUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemsAdderProvider implements CustomItemProvider {
|
||||
|
||||
@Override
|
||||
public boolean removeCustomBlock(Location location) {
|
||||
return CustomBlock.remove(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeCustomBlock(Location location, String id) {
|
||||
CustomBlock block = CustomBlock.place(id, location);
|
||||
if (block == null) {
|
||||
CustomStack furniture = CustomFurniture.getInstance(id);
|
||||
if (furniture == null) {
|
||||
BukkitCustomCropsPlugin.getInstance().getPluginLogger().warn("Detected that custom block[" + id + "] doesn't exist in ItemsAdder configs. Please double check if that block exists.");
|
||||
} else {
|
||||
BukkitCustomCropsPlugin.getInstance().getPluginLogger().warn("Detected that you mistakenly configured the custom block[" + id + "] as furniture.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity placeFurniture(Location location, String id) {
|
||||
try {
|
||||
CustomFurniture furniture = CustomFurniture.spawnPreciseNonSolid(id, LocationUtils.toSurfaceCenterLocation(location));
|
||||
if (furniture == null) return null;
|
||||
return furniture.getEntity();
|
||||
} catch (RuntimeException e) {
|
||||
BukkitCustomCropsPlugin.getInstance().getPluginLogger().warn("Failed to place furniture[" + id + "]. If this is not a problem caused by furniture not existing, consider increasing max-furniture-vehicles-per-chunk in ItemsAdder config.yml.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFurniture(Entity entity) {
|
||||
if (isFurniture(entity)) {
|
||||
CustomFurniture.remove(entity, false);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String blockID(Block block) {
|
||||
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
||||
if (customBlock == null) {
|
||||
return null;
|
||||
}
|
||||
return customBlock.getNamespacedID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String itemID(ItemStack itemStack) {
|
||||
CustomStack customStack = CustomStack.byItemStack(itemStack);
|
||||
if (customStack == null) {
|
||||
return null;
|
||||
}
|
||||
return customStack.getNamespacedID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack itemStack(Player player, String id) {
|
||||
if (id == null) return new ItemStack(Material.AIR);
|
||||
CustomStack customStack = CustomStack.getInstance(id);
|
||||
if (customStack == null) {
|
||||
return null;
|
||||
}
|
||||
return customStack.getItemStack().clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String furnitureID(Entity entity) {
|
||||
CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(entity);
|
||||
if (customFurniture == null) {
|
||||
return null;
|
||||
}
|
||||
return customFurniture.getNamespacedID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFurniture(Entity entity) {
|
||||
try {
|
||||
return CustomFurniture.byAlreadySpawned(entity) != null;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ tasks {
|
||||
from(project(":compatibility-oraxen-r1").tasks.jar.get().archiveFile)
|
||||
from(project(":compatibility-oraxen-r2").tasks.jar.get().archiveFile)
|
||||
from(project(":compatibility-itemsadder-r1").tasks.jar.get().archiveFile)
|
||||
from(project(":compatibility-itemsadder-r2").tasks.jar.get().archiveFile)
|
||||
from(project(":compatibility-crucible-r1").tasks.jar.get().archiveFile)
|
||||
from(project(":compatibility-craftengine-r1").tasks.jar.get().archiveFile)
|
||||
archiveFileName = "CustomCrops-${rootProject.properties["project_version"]}.jar"
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -184,7 +185,26 @@ public class BukkitItemManager extends AbstractItemManager {
|
||||
|
||||
plugin.getPluginLogger().info("Nexo hooked!");
|
||||
} else if (PluginUtils.isEnabled("ItemsAdder")) {
|
||||
String rVersion = "r1";
|
||||
Plugin iaPlugin = Bukkit.getPluginManager().getPlugin("ItemsAdder");
|
||||
String version = iaPlugin.getDescription().getVersion();
|
||||
String[] split = version.split("\\.");
|
||||
boolean above408 = false;
|
||||
if (Integer.parseInt(split[0]) >= 4) {
|
||||
if (Integer.parseInt(split[1]) > 0) {
|
||||
above408 = true;
|
||||
} else {
|
||||
if (Integer.parseInt(String.valueOf(split[2].charAt(0))) >= 8) {
|
||||
above408 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String rVersion;
|
||||
if (!above408) {
|
||||
rVersion = "r1";
|
||||
} else {
|
||||
rVersion = "r2";
|
||||
}
|
||||
Class<?> itemsAdderProviderClass = Class.forName("net.momirealms.customcrops.bukkit.integration.custom.itemsadder_" + rVersion + ".ItemsAdderProvider");
|
||||
Constructor<?> itemsAdderProviderConstructor = itemsAdderProviderClass.getDeclaredConstructor();
|
||||
itemsAdderProviderConstructor.setAccessible(true);
|
||||
|
||||
@@ -7,5 +7,6 @@ include(":compatibility-oraxen-r1")
|
||||
include(":compatibility-oraxen-r2")
|
||||
include(":compatibility-nexo-r1")
|
||||
include(":compatibility-itemsadder-r1")
|
||||
include(":compatibility-itemsadder-r2")
|
||||
include(":compatibility-crucible-r1")
|
||||
include(":compatibility-craftengine-r1")
|
||||
|
||||
Reference in New Issue
Block a user