Skip to content

Commit 38a7cb4

Browse files
committed
Remove spigot proxy listener. Moving to https://github.com/Fernthedev/AskPlaceHolder
1 parent 5437f2d commit 38a7cb4

File tree

4 files changed

+45
-105
lines changed

4 files changed

+45
-105
lines changed

core/src/main/java/com/github/fernthedev/fernapi/universal/FernAPIChannels.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private FernAPIChannels() {
1313

1414
public static final String PlaceHolderValue = "PlaceHolderValue";
1515

16-
public static final Channel PlaceHolderBungeeChannel = new Channel("ferncommands", "ph", Channel.ChannelAction.BOTH);
16+
public static final Channel PlaceHolderBungeeChannel = new Channel("fernapi", "ph", Channel.ChannelAction.BOTH);
1717

1818
public static final Channel VANISH_CHANNEL = new Channel("fernapi", "vanish", Channel.ChannelAction.BOTH);
1919

core/src/main/java/com/github/fernthedev/fernapi/universal/util/ProxyAskPlaceHolder.java

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
import java.io.ByteArrayOutputStream;
1313
import java.io.DataOutputStream;
1414
import java.util.*;
15+
import java.util.concurrent.CompletableFuture;
1516

1617
public class ProxyAskPlaceHolder extends PluginMessageHandler {
1718

1819
private final ProxyPlaceholderRunnable proxyPlaceholderRunnable;
20+
private final CompletableFuture<PlaceHolderResponse> completableFuture;
1921
private IFPlayer<?> player;
2022
private String placeHolderValue;
2123

2224
public static final String PLACEHOLDER_NOT_FOUND = "NoPlaceHolderFound";
2325
public static final String PLACEHOLDER_API_NOT_ENABLE = "PlaceHolderDisabled";
2426

25-
boolean checked;
26-
boolean placeHolderReplaced;
27+
private boolean responseReceived;
28+
private boolean placeHolderReplaced;
2729
private String oldPlaceValue;
2830

2931
private static final Map<UUID, ProxyAskPlaceHolder> instances = new HashMap<>();
30-
private UUID uuid;
3132

3233
/**
3334
* Internal use
@@ -42,6 +43,7 @@ public class ProxyAskPlaceHolder extends PluginMessageHandler {
4243
private ProxyAskPlaceHolder() {
4344
Universal.getMethods().getAbstractLogger().info("Registered PlaceHolderAPI Listener");
4445
proxyPlaceholderRunnable = (player, placeHolder, isReplaced) -> {};
46+
completableFuture = null;
4547
}
4648

4749
public String getPlaceHolderResult() {
@@ -52,13 +54,14 @@ public String getPlaceHolderResult() {
5254
public ProxyAskPlaceHolder(IFPlayer<?> player, String placeHolderValue, ProxyPlaceholderRunnable proxyPlaceholderRunnable) {
5355
this.player = player;
5456
this.proxyPlaceholderRunnable = proxyPlaceholderRunnable;
57+
completableFuture = new CompletableFuture<>();
5558

5659
ByteArrayOutputStream stream = new ByteArrayOutputStream();
5760
DataOutputStream out = new DataOutputStream(stream);
5861

5962
PluginMessageData data = new PluginMessageData(stream, player.getCurrentServerName(), FernAPIChannels.getPlaceHolderResult, FernAPIChannels.PlaceHolderBungeeChannel);
6063

61-
uuid = UUID.randomUUID();
64+
UUID uuid = UUID.randomUUID();
6265
if (!instances.isEmpty()) {
6366
while (instances.containsKey(uuid)) {
6467
uuid = UUID.randomUUID();
@@ -72,7 +75,7 @@ public ProxyAskPlaceHolder(IFPlayer<?> player, String placeHolderValue, ProxyPla
7275
oldPlaceValue = placeHolderValue;
7376
data.addData(uuid.toString()); //MESSAGE 2 (UUID)
7477

75-
checked = false;
78+
responseReceived = false;
7679
Universal.getMessageHandler().sendPluginData(player, data);
7780
instances.put(uuid, this);
7881
}
@@ -81,7 +84,9 @@ public boolean isPlaceHolderReplaced() {
8184
return placeHolderReplaced;
8285
}
8386

84-
87+
public boolean isResponseReceived() {
88+
return responseReceived;
89+
}
8590

8691
/**
8792
* This is the channel name that will be registered incoming and outgoing
@@ -131,7 +136,11 @@ public void onMessageReceived(PluginMessageData data, Channel channel) {
131136
instance.placeHolderReplaced = !instance.placeHolderValue.equals(instance.oldPlaceValue);
132137
}
133138

134-
instance.checked = true;
139+
instance.responseReceived = true;
140+
141+
// Fire completable future complete.
142+
completableFuture.complete(new PlaceHolderResponse(instance.player, instance.placeHolderValue, instance.isPlaceHolderReplaced()));
143+
135144
instance.proxyPlaceholderRunnable.onFinish(instance.player, instance.placeHolderValue, instance.isPlaceHolderReplaced());
136145
instances.remove(uuide);
137146

@@ -163,4 +172,32 @@ public interface ProxyPlaceholderRunnable {
163172
void onFinish(IFPlayer<?> player, String placeHolder, boolean isReplaced);
164173

165174
}
175+
176+
public CompletableFuture<PlaceHolderResponse> getCompletableFuture() {
177+
return completableFuture;
178+
}
179+
180+
public class PlaceHolderResponse {
181+
private final IFPlayer<?> player;
182+
private final String placeholder;
183+
private final boolean isReplaced;
184+
185+
public PlaceHolderResponse(IFPlayer<?> player, String placeholder, boolean isReplaced) {
186+
this.player = player;
187+
this.placeholder = placeholder;
188+
this.isReplaced = isReplaced;
189+
}
190+
191+
public IFPlayer<?> getPlayer() {
192+
return player;
193+
}
194+
195+
public String getPlaceholder() {
196+
return placeholder;
197+
}
198+
199+
public boolean isReplaced() {
200+
return isReplaced;
201+
}
202+
}
166203
}

spigot/src/main/java/com/github/fernthedev/fernapi/server/spigot/FernSpigotAPI.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import co.aikar.commands.PaperCommandManager;
44
import com.github.fernthedev.fernapi.server.spigot.chat.SpigotChatHandler;
55
import com.github.fernthedev.fernapi.server.spigot.interfaces.SpigotPluginData;
6-
import com.github.fernthedev.fernapi.server.spigot.network.PlaceHolderAPI.PlaceHolderAPIResponder;
76
import com.github.fernthedev.fernapi.server.spigot.network.SpigotMessageHandler;
87
import com.github.fernthedev.fernapi.server.spigot.network.SpigotNetworkHandler;
98
import com.github.fernthedev.fernapi.server.spigot.pluginhandlers.VaultHandler;
@@ -45,8 +44,6 @@ public void onEnable() {
4544
);
4645
// UUIDFetcher.setFetchManager(new UUIDSpigot());
4746

48-
Universal.getMessageHandler().registerMessageHandler(new PlaceHolderAPIResponder(this));
49-
5047
// if (Bukkit.getPluginManager().isPluginEnabled(VaultHandler.VAULT_PLUGIN_NAME) && (!ListUtil.containsString(getDescription().getSoftDepend(), VaultHandler.VAULT_PLUGIN_NAME) && !ListUtil.containsString(getDescription().getDepend(), VaultHandler.VAULT_PLUGIN_NAME))) {
5148
// Universal.debug("[WARNING/CAN BE IGNORED] Vault has been enabled though not added to soft dependencies or dependencies in plugin.yml. If you want to use VaultHandler which is included in the FernSpigotAPI you must add it to your dependencies/soft dependencies. Dependencies list: " + getDescription().getDepend() + " Soft Dependencies: " + getDescription().getSoftDepend());
5249
// }

spigot/src/main/java/com/github/fernthedev/fernapi/server/spigot/network/PlaceHolderAPI/PlaceHolderAPIResponder.java

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)