diff --git a/pom.xml b/pom.xml
index 579ec79..60d9bc5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,8 +8,9 @@
unified-parent
0.1-SNAPSHOT
+ unified-core
unified-energy
- unified
+ unified-plugin
pom
@@ -108,5 +109,5 @@
-
+
diff --git a/unified-core/pom.xml b/unified-core/pom.xml
new file mode 100644
index 0000000..1a273a1
--- /dev/null
+++ b/unified-core/pom.xml
@@ -0,0 +1,14 @@
+
+
+
+ unified-parent
+ io.github.unifiedtechpower.unified
+ 0.1-SNAPSHOT
+
+ 4.0.0
+
+ unified-core
+
+
\ No newline at end of file
diff --git a/unified-core/src/main/java/io/github/unifiedtechpower/unified/core/UnifiedBlockListener.java b/unified-core/src/main/java/io/github/unifiedtechpower/unified/core/UnifiedBlockListener.java
new file mode 100644
index 0000000..c7a472a
--- /dev/null
+++ b/unified-core/src/main/java/io/github/unifiedtechpower/unified/core/UnifiedBlockListener.java
@@ -0,0 +1,21 @@
+package io.github.unifiedtechpower.unified.core;
+
+import org.bukkit.Chunk;
+import org.bukkit.Location;
+import org.jetbrains.annotations.NotNull;
+
+public interface UnifiedBlockListener {
+
+ /**
+ * Called when a custom block of a plugin with "unified" integration was placed.
+ * @param location The {@link Location} of the block
+ */
+ void handleBlockPlaced(@NotNull Location location);
+
+ /**
+ * Called when a custom block of a plugin with "unified" integration was destroyed.
+ * @param location The {@link Location} of the block
+ */
+ void handleBlockDestroyed(@NotNull Location location);
+
+}
diff --git a/unified-core/src/main/java/io/github/unifiedtechpower/unified/core/UnifiedBlockManager.java b/unified-core/src/main/java/io/github/unifiedtechpower/unified/core/UnifiedBlockManager.java
new file mode 100644
index 0000000..e9d2944
--- /dev/null
+++ b/unified-core/src/main/java/io/github/unifiedtechpower/unified/core/UnifiedBlockManager.java
@@ -0,0 +1,63 @@
+package io.github.unifiedtechpower.unified.core;
+
+import org.bukkit.Location;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class UnifiedBlockManager {
+
+ private static final UnifiedBlockManager INSTANCE = new UnifiedBlockManager();
+
+ private final List listeners = new ArrayList<>();
+
+ private UnifiedBlockManager() {
+ }
+
+ /**
+ * Retrieves the {@link UnifiedBlockManager} instance.
+ * @return The {@link UnifiedBlockManager} instance.
+ */
+ public static UnifiedBlockManager getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Registers a new {@link UnifiedBlockListener}
+ * @param listener The {@link UnifiedBlockListener} to register
+ */
+ public void registerBlockListener(UnifiedBlockListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * Invokes {@link UnifiedBlockListener#handleBlockPlaced(Location)} for all registered {@link UnifiedBlockListener listeners}.
+ * @param location The {@link Location} of the placed block
+ * @param ignored A {@link UnifiedBlockListener} that should not be called. Can be null.
+ */
+ public void callBlockPlaced(@NotNull Location location, @Nullable UnifiedBlockListener ignored) {
+ for (var listener : listeners) {
+ if (listener == ignored)
+ continue;
+
+ listener.handleBlockPlaced(location);
+ }
+ }
+
+ /**
+ * Invokes {@link UnifiedBlockListener#handleBlockDestroyed(Location)} for all registered {@link UnifiedBlockListener listeners}.
+ * @param location The {@link Location} of the destroyed block
+ * @param ignored A {@link UnifiedBlockListener} that should not be called. Can be null.
+ */
+ public void callBlockDestroyed(@NotNull Location location, @Nullable UnifiedBlockListener ignored) {
+ for (var listener : listeners) {
+ if (listener == ignored)
+ continue;
+
+ listener.handleBlockDestroyed(location);
+ }
+ }
+
+}
diff --git a/unified-energy/src/main/java/io/github/unifiedtechpower/unified/energy/manager/EnergyNetworkManager.java b/unified-energy/src/main/java/io/github/unifiedtechpower/unified/energy/manager/EnergyNetworkManager.java
index cca6a5a..427e41b 100644
--- a/unified-energy/src/main/java/io/github/unifiedtechpower/unified/energy/manager/EnergyNetworkManager.java
+++ b/unified-energy/src/main/java/io/github/unifiedtechpower/unified/energy/manager/EnergyNetworkManager.java
@@ -7,6 +7,7 @@
import org.jetbrains.annotations.Nullable;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.CompletableFuture;
/**
@@ -30,6 +31,6 @@ public interface EnergyNetworkManager {
* @return a {@link CompletableFuture} that completes with the {@link EnergyStorage}s in the given chunk
*/
@NotNull
- CompletableFuture<@NotNull List<@NotNull EnergyStorage>> getEnergyStoragesIn(@NotNull Chunk chunk);
+ CompletableFuture<@NotNull Map<@NotNull Location, @NotNull EnergyStorage>> getEnergyStoragesIn(@NotNull Chunk chunk);
}
diff --git a/unified-energy/src/main/java/io/github/unifiedtechpower/unified/energy/manager/UnifiedEnergy.java b/unified-energy/src/main/java/io/github/unifiedtechpower/unified/energy/manager/UnifiedEnergy.java
index e982cd4..b5c4b6c 100644
--- a/unified-energy/src/main/java/io/github/unifiedtechpower/unified/energy/manager/UnifiedEnergy.java
+++ b/unified-energy/src/main/java/io/github/unifiedtechpower/unified/energy/manager/UnifiedEnergy.java
@@ -6,10 +6,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
+import java.util.*;
import java.util.concurrent.CompletableFuture;
/**
@@ -58,7 +55,7 @@ public boolean removeManager(@NotNull EnergyNetworkManager manager) {
for (var manager : managers)
futures.add(manager.getEnergyStorageAt(location));
- for (var future : futures) {
+ for (var future : new HashSet<>(futures)) {
future.thenAccept(storage -> {
if (mainFuture.isDone())
return;
@@ -83,18 +80,18 @@ public boolean removeManager(@NotNull EnergyNetworkManager manager) {
* @return a {@link CompletableFuture} that completes with a list of {@link EnergyStorage}s in the given chunk
*/
@NotNull
- public CompletableFuture<@NotNull List<@NotNull EnergyStorage>> getEnergyStoragesIn(@NotNull Chunk chunk) {
- var futures = Collections.synchronizedSet(new HashSet>>());
- var energyStorages = Collections.synchronizedList(new ArrayList<@NotNull EnergyStorage>());
- var mainFuture = new CompletableFuture<@NotNull List<@NotNull EnergyStorage>>();
+ public CompletableFuture<@NotNull Map<@NotNull Location, @NotNull EnergyStorage>> getEnergyStoragesIn(@NotNull Chunk chunk) {
+ var futures = Collections.synchronizedSet(new HashSet>>());
+ var energyStorages = Collections.synchronizedMap(new HashMap<@NotNull Location, @NotNull EnergyStorage>());
+ var mainFuture = new CompletableFuture<@NotNull Map<@NotNull Location, @NotNull EnergyStorage>>();
for (var manager : managers)
futures.add(manager.getEnergyStoragesIn(chunk));
- for (var future : futures) {
+ for (var future : new HashSet<>(futures)) {
future.thenAccept(storages -> {
if (!storages.isEmpty())
- energyStorages.addAll(storages);
+ energyStorages.putAll(storages);
futures.remove(future);
if (futures.isEmpty())
diff --git a/unified/pom.xml b/unified-plugin/pom.xml
similarity index 90%
rename from unified/pom.xml
rename to unified-plugin/pom.xml
index bf5ed60..a9c56d5 100644
--- a/unified/pom.xml
+++ b/unified-plugin/pom.xml
@@ -9,16 +9,18 @@
4.0.0
- unified
+ unified-plugin
- 11
- 11
- UTF-8
${project.build.directory}/out
+
+ io.github.unifiedtechpower.unified
+ unified-core
+ ${project.version}
+
io.github.unifiedtechpower.unified
unified-energy
@@ -53,7 +55,7 @@
- io.github.unifiedtechpower.unified:unified-energy
+ io.github.unifiedtechpower.unified:*
diff --git a/unified/src/main/java/io/github/unifiedtechpower/unified/Unified.java b/unified-plugin/src/main/java/io/github/unifiedtechpower/unified/Unified.java
similarity index 100%
rename from unified/src/main/java/io/github/unifiedtechpower/unified/Unified.java
rename to unified-plugin/src/main/java/io/github/unifiedtechpower/unified/Unified.java
diff --git a/unified/src/main/resources/plugin.yml b/unified-plugin/src/main/resources/plugin.yml
similarity index 100%
rename from unified/src/main/resources/plugin.yml
rename to unified-plugin/src/main/resources/plugin.yml