Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<!-- More visible way how to change dependency versions -->
<bentobox.version>3.10.0</bentobox.version>
<items-adder.version>4.0.10</items-adder.version>
<nexo.version>1.8.0</nexo.version>
<level.version>2.6.2</level.version>
<bank.version>1.3.0</bank.version>
<!-- Revision variable removes warning about dynamic version -->
Expand Down Expand Up @@ -151,6 +152,13 @@
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<!-- Nexo API -->
<repository>
<id>nexomc</id>
<url>https://repo.nexomc.com/releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<!-- General Maven public mirror -->
<repository>
<id>codemc-repo</id>
Expand Down Expand Up @@ -251,6 +259,18 @@
<version>${items-adder.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.nexomc</groupId>
<artifactId>nexo</artifactId>
<version>${nexo.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/world/bentobox/aoneblock/AOneBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import world.bentobox.aoneblock.listeners.InfoListener;
import world.bentobox.aoneblock.listeners.ItemsAdderListener;
import world.bentobox.aoneblock.listeners.JoinLeaveListener;
import world.bentobox.aoneblock.listeners.NexoListener;
import world.bentobox.aoneblock.listeners.NoBlockHandler;
import world.bentobox.aoneblock.listeners.StartSafetyListener;
import world.bentobox.aoneblock.oneblocks.OneBlockCustomBlockCreator;
import world.bentobox.aoneblock.oneblocks.OneBlocksManager;
import world.bentobox.aoneblock.oneblocks.customblock.ItemsAdderCustomBlock;
import world.bentobox.aoneblock.oneblocks.customblock.NexoCustomBlock;
import world.bentobox.aoneblock.requests.IslandStatsHandler;
import world.bentobox.aoneblock.requests.LocationStatsHandler;
import world.bentobox.bentobox.api.addons.GameModeAddon;
Expand All @@ -53,6 +55,8 @@ public class AOneBlock extends GameModeAddon {
private static final String THE_END = "_the_end";
/** Whether ItemsAdder is present on the server */
private boolean hasItemsAdder = false;
/** Whether Nexo is present on the server */
private boolean hasNexo = false;

/** The addon settings */
private Settings settings;
Expand Down Expand Up @@ -116,6 +120,13 @@ public void onLoad() {
OneBlockCustomBlockCreator.register("itemsadder", ItemsAdderCustomBlock::fromMap);
hasItemsAdder = true;
}
// Check if Nexo exists, if yes register listener
if (Bukkit.getPluginManager().getPlugin("Nexo") != null) {
registerListener(new NexoListener(this));
OneBlockCustomBlockCreator.register(NexoCustomBlock::fromId);
OneBlockCustomBlockCreator.register("nexo", NexoCustomBlock::fromMap);
hasNexo = true;
}
// Save the default config from config.yml
saveDefaultConfig();
// Load settings from config.yml. This will check if there are any issues with
Expand Down Expand Up @@ -398,6 +409,13 @@ public boolean hasItemsAdder() {
return hasItemsAdder;
}

/**
* @return true if Nexo is on the server
*/
public boolean hasNexo() {
return hasNexo;
}

/**
* Set the addon's world. Used only for testing.
* @param world world
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/world/bentobox/aoneblock/listeners/NexoListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package world.bentobox.aoneblock.listeners;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import com.nexomc.nexo.api.events.NexoItemsLoadedEvent;
import world.bentobox.aoneblock.AOneBlock;

/**
* Handles NexoItemsLoadedEvent which is fired when Nexo loads or reloads its data
*/
public class NexoListener implements Listener {

private final AOneBlock addon;

public NexoListener(AOneBlock addon) {
this.addon = addon;
}

/**
* Handle NexoItemsLoadedEvent then reload the addon if it gets triggered
* @param e - NexoItemsLoadedEvent
*/
@EventHandler
public void onLoad(NexoItemsLoadedEvent e) {
addon.loadData();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package world.bentobox.aoneblock.oneblocks.customblock;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.bukkit.Material;
import org.bukkit.block.Block;

import com.nexomc.nexo.api.NexoBlocks;
import world.bentobox.aoneblock.AOneBlock;
import world.bentobox.aoneblock.oneblocks.OneBlockCustomBlock;
import world.bentobox.bentobox.BentoBox;

public class NexoCustomBlock implements OneBlockCustomBlock {
private final String itemId;

public NexoCustomBlock(String itemId) {
this.itemId = itemId;
}

public static Optional<NexoCustomBlock> fromId(String id) {
if (NexoBlocks.isCustomBlock(id)) {
return Optional.of(new NexoCustomBlock(id));
}
return Optional.empty();
}

public static Optional<NexoCustomBlock> fromMap(Map<?, ?> map) {
return Optional
.ofNullable(Objects.toString(map.get("id"), null))
.flatMap(NexoCustomBlock::fromId);
}

@Override
public void execute(AOneBlock addon, Block block) {
try {
block.setType(Material.AIR);
NexoBlocks.place(itemId, block.getLocation());
} catch (Exception e) {
BentoBox.getInstance().logError("Could not place Nexo block " + itemId + ": " + e.getMessage());
block.setType(Material.STONE);
}
}
}
Loading