Skip to content

Commit

Permalink
1. Fix static class
Browse files Browse the repository at this point in the history
  • Loading branch information
megoRU committed Dec 29, 2022
1 parent 662ac9c commit 128bb89
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.boticordjava.api</groupId>
<artifactId>boticordjava</artifactId>
<version>4.0</version>
<version>4.1</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down Expand Up @@ -40,7 +40,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<version>4.5.14</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.json/json -->
Expand All @@ -53,7 +53,7 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<version>23.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
public abstract class ListenerAdapter {

public void onTestEvent(@NotNull TestMessage event) {}

public void onCommentEvent(@NotNull CommentAction event) {}

public void onBotBumpEvent(@NotNull BotBump event) {}

public void onServerBumpEvent(@NotNull ServerBump event) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@
import org.boticordjava.api.entity.webhooks.comment.CommentAction;
import org.boticordjava.api.entity.webhooks.comment.Type;
import org.boticordjava.api.entity.webhooks.test.TestMessage;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.*;

public class Initiator {
public class Observer {

private final List<ListenerAdapter> listeners = new ArrayList<>();

public void addListener(ListenerAdapter listenerAdapter) {
listeners.add(listenerAdapter);
}

public void addListener(ListenerAdapter... listenerAdapter) {
listeners.addAll(List.of(listenerAdapter));
public void addListener(@NotNull ListenerAdapter... listenerAdapter) {
Collections.addAll(this.listeners, listenerAdapter);
}

public void handle(WebhookListener commentAction) {
Expand All @@ -46,4 +42,4 @@ public void handle(WebhookListener commentAction) {
}
}
}
}
}
12 changes: 4 additions & 8 deletions src/main/java/org/boticordjava/api/impl/WebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.boticordjava.api.entity.webhooks.bump.server.ServerBump;
import org.boticordjava.api.entity.webhooks.comment.CommentAction;
import org.boticordjava.api.entity.webhooks.comment.Type;
import org.boticordjava.api.entity.webhooks.observer.Initiator;
import org.boticordjava.api.entity.webhooks.observer.Observer;
import org.boticordjava.api.entity.webhooks.observer.ListenerAdapter;
import org.boticordjava.api.entity.webhooks.test.TestMessage;
import org.boticordjava.api.io.DefaultResponseTransformer;
Expand All @@ -35,7 +35,7 @@ public class WebSocket {
private final String XHookKey;
private final String path;
private final int port;
private final static Initiator INITIATOR = new Initiator();
private final Observer Observer = new Observer();

/**
* @param xHookKey String X-Hook-Key for filter request
Expand Down Expand Up @@ -137,18 +137,14 @@ public void handle(HttpExchange t) {
private <E> void webhooks(ResponseTransformer<E> responseTransformer, String response) {
if (responseTransformer != null) {
WebhookListener transform = (WebhookListener) responseTransformer.transform(response);
INITIATOR.handle(transform);
Observer.handle(transform);
}
}

public void addListener(ListenerAdapter listenerAdapter) {
INITIATOR.addListener(listenerAdapter);
}
public void addListener(ListenerAdapter... listenerAdapter) {
INITIATOR.addListener(listenerAdapter);
Observer.addListener(listenerAdapter);
}


public String getXHookKey() {
return XHookKey;
}
Expand Down

0 comments on commit 128bb89

Please sign in to comment.