Skip to content

Commit

Permalink
removed port config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ixf1nity committed Nov 12, 2023
1 parent 2f0982c commit 8244c13
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/main/java/me/infinity/ngrokcom/NgrokCommunication.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import discord4j.core.spec.MessageCreateSpec;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Arrays;
import java.util.Objects;

public final class NgrokCommunication extends JavaPlugin {
Expand All @@ -25,8 +24,6 @@ public final class NgrokCommunication extends JavaPlugin {

@Override
public void onEnable() {
this.getConfig().addDefault("PORT", this.getServer().getPort());
this.getConfig().setComments("PORT", Arrays.asList("Ngrok hosting port, Do not touch if you dont know how it works!"));
this.saveDefaultConfig();
this.client = DiscordClientBuilder.create(Objects.requireNonNull(this.getConfig().getString("BOT_TOKEN")))
.build()
Expand All @@ -42,18 +39,20 @@ public void onEnable() {
.build();
final CreateTunnel createTunnel = new CreateTunnel.Builder()
.withProto(Proto.TCP)
.withAddr(this.getConfig().getInt("PORT"))
.withAddr(this.getServer().getPort())
.build();
final Tunnel tunnel = ngrokClient.connect(createTunnel);
this.publicIp = tunnel.getPublicUrl();
this.publicIp = tunnel.getPublicUrl().replace("tcp://", "");

client.getChannelById(Snowflake.of(Objects.requireNonNull(this.getConfig().getString("IP_UPDATE_CHANNEL_ID"))))
.ofType(GuildMessageChannel.class)
.flatMap(guildMessageChannel -> guildMessageChannel.createMessage(MessageCreateSpec.builder()
.content(Objects.requireNonNull(this.getConfig().getString("IP_UPDATE_MESSAGE"))
.replace("%server_ip%", publicIp.replace("tcp://", "")))
.replace("%server_ip%", publicIp))
.build()
)).subscribe();

this.getLogger().info("Listening server on port " + this.getServer().getPort() + ", IP: " + publicIp);
}

@Override
Expand Down

0 comments on commit 8244c13

Please sign in to comment.