9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-30 12:29:12 +00:00

Merge pull request #41 from iqtesterrr/main

Nexo Support
This commit is contained in:
XiaoMoMi
2024-11-24 14:55:02 +08:00
committed by GitHub
7 changed files with 290 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
repositories {
mavenCentral()
maven("https://repo.nexomc.com/snapshots/")
maven("https://repo.papermc.io/repository/maven-public/")
}
dependencies {
compileOnly(project(":api"))
compileOnly(project(":common"))
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("com.nexomc:nexo:0.1.0-dev.0")
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(17)
}
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

View File

@@ -0,0 +1,135 @@
package net.momirealms.customcrops.bukkit.integration.custom.nexo_r1;
import com.nexomc.nexo.api.events.custom_block.noteblock.NexoNoteBlockBreakEvent;
import com.nexomc.nexo.api.events.custom_block.noteblock.NexoNoteBlockInteractEvent;
import com.nexomc.nexo.api.events.custom_block.noteblock.NexoNoteBlockPlaceEvent;
import com.nexomc.nexo.api.events.custom_block.stringblock.NexoStringBlockBreakEvent;
import com.nexomc.nexo.api.events.custom_block.stringblock.NexoStringBlockInteractEvent;
import com.nexomc.nexo.api.events.custom_block.stringblock.NexoStringBlockPlaceEvent;
import com.nexomc.nexo.api.events.furniture.NexoFurnitureBreakEvent;
import com.nexomc.nexo.api.events.furniture.NexoFurnitureInteractEvent;
import com.nexomc.nexo.api.events.furniture.NexoFurniturePlaceEvent;
import net.momirealms.customcrops.api.core.AbstractCustomEventListener;
import net.momirealms.customcrops.api.core.AbstractItemManager;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class NexoListener extends AbstractCustomEventListener {
private static final Set<Material> IGNORED = new HashSet<>(
List.of(
Material.NOTE_BLOCK,
Material.TRIPWIRE
)
);
@Override
protected Set<Material> ignoredMaterials() {
return IGNORED;
}
public NexoListener(AbstractItemManager itemManager) {
super(itemManager);
}
@EventHandler(ignoreCancelled = true)
public void onInteractFurniture(NexoFurnitureInteractEvent event) {
itemManager.handlePlayerInteractFurniture(
event.getPlayer(),
event.getBaseEntity().getLocation(), event.getMechanic().getItemID(),
event.getHand(), event.getItemInHand(),
event
);
}
@EventHandler(ignoreCancelled = true)
public void onInteractCustomBlock(NexoNoteBlockInteractEvent event) {
itemManager.handlePlayerInteractBlock(
event.getPlayer(),
event.getBlock(),
event.getMechanic().getItemID(), event.getBlockFace(),
event.getHand(),
event.getItemInHand(),
event
);
}
@EventHandler(ignoreCancelled = true)
public void onInteractCustomBlock(NexoStringBlockInteractEvent event) {
itemManager.handlePlayerInteractBlock(
event.getPlayer(),
event.getBlock(),
event.getMechanic().getItemID(), event.getBlockFace(),
event.getHand(),
event.getItemInHand(),
event
);
}
@EventHandler(ignoreCancelled = true)
public void onBreakFurniture(NexoFurnitureBreakEvent event) {
itemManager.handlePlayerBreak(
event.getPlayer(),
event.getBaseEntity().getLocation(), event.getPlayer().getInventory().getItemInMainHand(), event.getMechanic().getItemID(),
event
);
}
@EventHandler(ignoreCancelled = true)
public void onBreakCustomBlock(NexoNoteBlockBreakEvent event) {
itemManager.handlePlayerBreak(
event.getPlayer(),
event.getBlock().getLocation(), event.getPlayer().getInventory().getItemInMainHand(), event.getMechanic().getItemID(),
event
);
}
@EventHandler(ignoreCancelled = true)
public void onBreakCustomBlock(NexoStringBlockBreakEvent event) {
itemManager.handlePlayerBreak(
event.getPlayer(),
event.getBlock().getLocation(), event.getPlayer().getInventory().getItemInMainHand(), event.getMechanic().getItemID(),
event
);
}
@EventHandler(ignoreCancelled = true)
public void onPlaceFurniture(NexoFurniturePlaceEvent event) {
itemManager.handlePlayerPlace(
event.getPlayer(),
event.getBaseEntity().getLocation(),
event.getMechanic().getItemID(),
event.getHand(),
event.getItemInHand(),
event
);
}
@EventHandler(ignoreCancelled = true)
public void onPlaceCustomBlock(NexoNoteBlockPlaceEvent event) {
itemManager.handlePlayerPlace(
event.getPlayer(),
event.getBlock().getLocation(),
event.getMechanic().getItemID(),
event.getHand(),
event.getItemInHand(),
event
);
}
@EventHandler(ignoreCancelled = true)
public void onPlaceCustomBlock(NexoStringBlockPlaceEvent event) {
itemManager.handlePlayerPlace(
event.getPlayer(),
event.getBlock().getLocation(),
event.getMechanic().getItemID(),
event.getHand(),
event.getItemInHand(),
event
);
}
}

View File

@@ -0,0 +1,114 @@
/*
* 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.nexo_r1;
import com.nexomc.nexo.api.NexoBlocks;
import com.nexomc.nexo.api.NexoFurniture;
import com.nexomc.nexo.api.NexoItems;
import com.nexomc.nexo.items.ItemBuilder;
import com.nexomc.nexo.mechanics.Mechanic;
import com.nexomc.nexo.mechanics.furniture.FurnitureMechanic;
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
import net.momirealms.customcrops.api.core.CustomItemProvider;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Rotation;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
public class NexoProvider implements CustomItemProvider {
@Override
public boolean removeCustomBlock(Location location) {
Block block = location.getBlock();
if (NexoBlocks.isCustomBlock(block)) {
block.setType(Material.AIR, false);
return true;
}
return false;
}
@Override
public boolean placeCustomBlock(Location location, String id) {
if (NexoItems.exists(id)) {
NexoBlocks.place(id, location);
return true;
} else {
return false;
}
}
@Override
public @Nullable Entity placeFurniture(Location location, String id) {
Entity entity = NexoFurniture.place(id, location, Rotation.NONE, BlockFace.UP);
if (entity == null) {
BukkitCustomCropsPlugin.getInstance().getPluginLogger().warn("Furniture[" + id +"] doesn't exist. Please double check if that furniture exists.");
}
return entity;
}
@Override
public boolean removeFurniture(Entity entity) {
if (isFurniture(entity)) {
NexoFurniture.remove(entity, null, null);
return true;
}
return false;
}
@Override
public @Nullable String blockID(Block block) {
Mechanic mechanic = NexoBlocks.customBlockMechanic(block.getBlockData());
if (mechanic == null) {
return null;
}
return mechanic.getItemID();
}
@Override
public @Nullable String itemID(ItemStack itemStack) {
return NexoItems.idFromItem(itemStack);
}
@Override
public @Nullable ItemStack itemStack(Player player, String id) {
ItemBuilder builder = NexoItems.itemFromId(id);
if (builder == null) {
return null;
}
return builder.build();
}
@Override
public @Nullable String furnitureID(Entity entity) {
FurnitureMechanic mechanic = NexoFurniture.furnitureMechanic(entity);
if (mechanic == null) {
return null;
}
return mechanic.getItemID();
}
@Override
public boolean isFurniture(Entity entity) {
return NexoFurniture.isFurniture(entity);
}
}

View File

@@ -24,6 +24,7 @@ dependencies {
implementation(project(":compatibility"))
implementation(project(":compatibility-oraxen-r1"))
implementation(project(":compatibility-oraxen-r2"))
implementation(project(":compatibility-nexo-r1"))
implementation(project(":compatibility-itemsadder-r1"))
implementation(project(":compatibility-crucible-r1"))
implementation(project(":compatibility-asp-r1"))

View File

@@ -157,6 +157,19 @@ public class BukkitItemManager extends AbstractItemManager {
this.setCustomEventListener((AbstractCustomEventListener) oraxenListenerConstructor.newInstance(this));
plugin.getPluginLogger().info("Oraxen hooked!");
} else if (PluginUtils.isEnabled("Nexo")) {
String rVersion = "r1";
Class<?> nexoProviderClass = Class.forName("net.momirealms.customcrops.bukkit.integration.custom.nexo_" + rVersion + ".NexoProvider");
Constructor<?> nexoProviderConstructor = nexoProviderClass.getDeclaredConstructor();
nexoProviderConstructor.setAccessible(true);
this.provider = (CustomItemProvider) nexoProviderConstructor.newInstance();
Class<?> nexoListenerClass = Class.forName("net.momirealms.customcrops.bukkit.integration.custom.nexo_" + rVersion + ".NexoListener");
Constructor<?> nexoListenerConstructor = nexoListenerClass.getDeclaredConstructor(AbstractItemManager.class);
nexoListenerConstructor.setAccessible(true);
this.setCustomEventListener((AbstractCustomEventListener) nexoListenerConstructor.newInstance(this));
plugin.getPluginLogger().info("Nexo hooked!");
} else if (PluginUtils.isEnabled("ItemsAdder")) {
String rVersion = "r1";
Class<?> itemsAdderProviderClass = Class.forName("net.momirealms.customcrops.bukkit.integration.custom.itemsadder_" + rVersion + ".ItemsAdderProvider");

View File

@@ -9,6 +9,7 @@ softdepend:
- Vault
- ItemsAdder
- Oraxen
- Nexo
- MythicCrucible
- PlaceholderAPI
- BattlePass

View File

@@ -6,8 +6,6 @@ include(":compatibility")
include(":compatibility-asp-r1")
include(":compatibility-oraxen-r1")
include(":compatibility-oraxen-r2")
include(":compatibility-nexo-r1")
include(":compatibility-itemsadder-r1")
include(":compatibility-crucible-r1")