Skip to content

Commit

Permalink
Merge branch 'feature/#29-display-entities' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	pathfinder-editmode/src/main/java/de/cubbossa/pathfinder/editmode/menu/EditModeMenu.java
  • Loading branch information
CubBossa committed Oct 28, 2023
2 parents 2e3fc0d + c554337 commit 309f373
Show file tree
Hide file tree
Showing 30 changed files with 767 additions and 673 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
minecraft_version=1.20
minecraft_version=1.20.2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import de.cubbossa.pathapi.misc.PathPlayer;
import de.cubbossa.pathapi.node.Node;

import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;

Expand All @@ -15,7 +14,7 @@
public interface GraphRenderer<Player> extends AutoCloseable {

@Override
default void close() throws IOException {
default void close() throws Exception {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import de.cubbossa.pathapi.node.Edge;
import de.cubbossa.pathapi.node.NodeType;
import de.cubbossa.pathapi.visualizer.VisualizerType;
import org.jetbrains.annotations.Nullable;

import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.logging.Logger;

/**
Expand All @@ -19,6 +22,10 @@
*/
public interface StorageImplementation {

default @Nullable ExecutorService service(ThreadFactory factory) {
return null;
}

/**
* Initializes this storage implementation. Will be called by {@link Storage#init()} and will create
* necessary files or objects. It assures that the instance can be used without issues afterward.
Expand Down
12 changes: 10 additions & 2 deletions pathfinder-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repositories {
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://nexus.leonardbausenwein.de/repository/maven-public/")
maven("https://libraries.minecraft.net/")
maven("https://repo.codemc.org/repository/maven-public/")
maven("https://repo.codemc.org/repository/maven-snapshots/")
maven("https://repo.papermc.io/repository/maven-public/")
}

Expand Down Expand Up @@ -87,7 +87,15 @@ bukkit {

apiVersion = "1.18"

softDepend = listOf("PlaceholderAPI")
softDepend = listOf(
"PlaceholderAPI",
"ProtocolLib",
"ProtocolSupport",
"ViaVersion",
"ViaBackwards",
"ViaRewind",
"Geyser-Spigot"
)
libraries = listOf(
"org.openjdk.nashorn:nashorn-core:15.4",
"org.snakeyaml:snakeyaml-engine:2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,20 @@ public void onEvent(Event e) {
@SneakyThrows
@Override
public void drop(Listener<?> listener) {
HandlerList handlerList = (HandlerList) listener.eventType().getMethod("getHandlerList")
.invoke(classMapping.get(listener.eventType()));
handlerList.unregister(listenerMap.remove(listener));
// Remove listener if exists.
org.bukkit.event.Listener bukkitListener = listenerMap.remove(listener);
if (bukkitListener == null) {
return;
}

Class<? extends Event> bukkitEventClass = classMapping.get(listener.eventType());
Method handlerListMethod;
try {
handlerListMethod = bukkitEventClass.getMethod("getHandlerList");
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Bukkit Event class '" + bukkitEventClass.getName() + "' does not implement mandatory method getHandlerList.");
}
HandlerList handlerList = (HandlerList) handlerListMethod.invoke(bukkitEventClass);
handlerList.unregister(bukkitListener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@

public class BukkitMainThreadExecutor implements Executor {

private Queue<Runnable> tasks = new ConcurrentLinkedQueue<>();
private final double MAX_MILLIS_PER_TICK;
private final int MAX_NANOS_PER_TICK;

private final Queue<Runnable> tasks = new ConcurrentLinkedQueue<>();

public BukkitMainThreadExecutor(JavaPlugin plugin) {
this(plugin, 50);
}

public BukkitMainThreadExecutor(JavaPlugin plugin, double maxMillis) {
this.MAX_MILLIS_PER_TICK = maxMillis;
this.MAX_NANOS_PER_TICK = (int) (MAX_MILLIS_PER_TICK * 1E6);
plugin.getServer().getScheduler().runTaskTimer(plugin, this::runTasks, 1, 1);
}

Expand All @@ -21,8 +30,9 @@ public void execute(@NotNull Runnable command) {
}

public void runTasks() {
long stopTime = System.nanoTime() + MAX_NANOS_PER_TICK;
Runnable task;
while ((task = tasks.poll()) != null) {
while (System.nanoTime() < stopTime && (task = tasks.poll()) != null) {
task.run();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import de.cubbossa.pathfinder.storage.StorageImpl;
import de.cubbossa.pathfinder.storage.StorageUtil;
import de.cubbossa.pathfinder.storage.cache.CacheLayerImpl;
import de.cubbossa.pathfinder.storage.implementation.DebugStorage;
import de.cubbossa.pathfinder.storage.implementation.RemoteSqlStorage;
import de.cubbossa.pathfinder.storage.implementation.SqliteStorage;
import de.cubbossa.pathfinder.storage.implementation.WaypointStorage;
Expand Down Expand Up @@ -193,7 +194,7 @@ public void onEnable() {
impl.setWorldLoader(this::getWorld);
impl.setLogger(getLogger());

storage.setImplementation(impl);
storage.setImplementation(new DebugStorage(impl, getLogger()));
storage.setEventDispatcher(eventDispatcher);
storage.setLogger(getLogger());
storage.init();
Expand Down Expand Up @@ -268,11 +269,10 @@ public void shutdown() {
}
state = ApplicationState.DISABLED;

NodeHandler.getInstance().cancelAllEditModes();
NodeHandler.getInstance().close();
extensionRegistry.disableExtensions(this);
storage.shutdown();

NodeHandler.getInstance().close();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public static class EditModeConf implements EditModeConfig {
1s = 20t""")
public int edgeParticleTickDelay = 6;
@Comment("The edge color that indicates an outgoing or undirected edge.")
public Color edgeParticleColorFrom = new Color(0xff0000);
public Color edgeParticleColorFrom = new Color(0xff5500);
@Comment("The edge color that indicates an incoming edge.")
public Color edgeParticleColorTo = new Color(0x0088ff);
@Comment("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public static MessageFormatter formatter() {
.withPlaceholders("page", "next-page", "prev-page", "pages")
.build();
public static final Message CMD_DISCOVERIES_FOOTER = new MessageBuilder("commands.discoveries.list.footer")
.withDefault("<gradient:black:dark_gray:black>------------<t> <click:run_command:/discoveries <prev-page>>←</click> <page>/<pages> <click:run_command:/discoveries <next-page>>→</click> </t>-------------</gradient>")
.withDefault("<gradient:black:dark_gray:black>-------------<t> <click:run_command:/discoveries <prev-page>>←</click> <page>/<pages> <click:run_command:/discoveries <next-page>>→</click> </t>--------------</gradient>")
.withPlaceholders("page", "next-page", "prev-page", "pages")
.build();
public static final Message CMD_FIND_EMPTY = new MessageBuilder("commands.find.no_nodes_found")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public void cancelAllEditModes() {

@Override
public void close() throws Exception {
editors.forEach((key, nodeGroupEditor) -> nodeGroupEditor.cancelEditModes());
editors.forEach((key, nodeGroupEditor) -> {
nodeGroupEditor.cancelEditModes();
nodeGroupEditor.dispose();
});
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.cubbossa.pathfinder.storage;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import de.cubbossa.pathapi.PathFinderProvider;
import de.cubbossa.pathapi.event.EventDispatcher;
import de.cubbossa.pathapi.group.Modifier;
Expand Down Expand Up @@ -28,10 +29,7 @@
import javax.annotation.Nullable;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.logging.Level;
Expand Down Expand Up @@ -61,7 +59,11 @@ private Optional<EventDispatcher<?>> eventDispatcher() {

@Override
public void init() throws Exception {
ioExecutor = Executors.newCachedThreadPool();
ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("pathfinder-io-%d").build();
ioExecutor = implementation.service(factory);
if (ioExecutor == null) {
ioExecutor = Executors.newCachedThreadPool(factory);
}
implementation.init();
}

Expand Down Expand Up @@ -117,9 +119,11 @@ private CompletableFuture<Void> asyncFuture(Runnable runnable) {

private <T> CompletableFuture<T> asyncFuture(Supplier<T> supplier) {

return CompletableFuture.supplyAsync(supplier, ioExecutor).exceptionally(throwable -> {
throwable.printStackTrace();
return null;
return CompletableFuture.supplyAsync(() -> {
return CompletableFuture.supplyAsync(supplier, ioExecutor).exceptionally(throwable -> {
throwable.printStackTrace();
return null;
}).join();
});
}

Expand Down Expand Up @@ -184,9 +188,9 @@ public <N extends Node> CompletableFuture<N> insertGlobalGroupAndSave(N node) {
}

private CompletableFuture<Collection<Node>> insertEdges(Collection<Node> nodes) {
return CompletableFuture.supplyAsync(() -> {
return asyncFuture(() -> {
return implementation.loadEdgesFrom(nodes.stream().map(Node::getNodeId).toList());
}, ioExecutor).thenApply(edges -> {
}).thenApply(edges -> {
for (Node node : nodes) {
if (!edges.containsKey(node.getNodeId())) {
continue;
Expand Down
Loading

0 comments on commit 309f373

Please sign in to comment.