Skip to content

Commit

Permalink
Merge pull request #41 from RappyLabyAddons/fix/serverDetection
Browse files Browse the repository at this point in the history
Fix OPSUCHT server detection
  • Loading branch information
RappyTV authored Mar 17, 2024
2 parents 96d7389 + 5a3eac0 commit 5d29395
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 95 deletions.
11 changes: 4 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ labyMod {
author = "RappyTV"
description = "Adds some ingame utilities for OPSUCHT.net | Not affiliated with Interwebmedia GmbH"
minecraftVersion = "1.19<*"
version = System.getenv().getOrDefault("VERSION", "1.1.9")
version = System.getenv().getOrDefault("VERSION", "1.2.0")
}

minecraft {
registerVersions(
"1.8.9",
"1.12.2",
"1.16.5",
"1.17.1",
"1.18.2",
"1.19.2",
"1.19.3",
"1.19.4",
"1.20.1"
"1.20.1",
"1.20.2",
"1.20.4"
) { version, provider ->
configureRun(provider, version)
}
Expand Down
14 changes: 4 additions & 10 deletions core/src/main/java/com/rappytv/opsucht/OPSuchtAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.rappytv.opsucht.context.PayContext;
import com.rappytv.opsucht.listeners.ChatReceiveListener;
import com.rappytv.opsucht.listeners.PlayerInfo;
import com.rappytv.opsucht.listeners.ServerNavigationListener;
import com.rappytv.opsucht.managers.DiscordRPCManager;
import net.labymod.api.Laby;
import net.labymod.api.addon.LabyAddon;
Expand All @@ -17,10 +16,9 @@
@AddonMain
public class OPSuchtAddon extends LabyAddon<OPSuchtConfig> {

public static final String[] ip = {"162.19.233.3", "141.95.85.60"};
public DiscordRPCManager rpcManager;
private static OPSuchtAddon instance;
private static boolean connected = false;
private OPSuchtServer server;

@Override
protected void preConfigurationLoad() {
Expand All @@ -36,23 +34,19 @@ protected void enable() {
registerSettingCategory();
registerListener(new ChatReceiveListener(this));
registerListener(new PlayerInfo(this));
registerListener(new ServerNavigationListener(this));
labyAPI().interactionMenuRegistry().register(new ClanInviteContext(this));
labyAPI().interactionMenuRegistry().register(new FriendRequestContext(this));
labyAPI().interactionMenuRegistry().register(new PayContext(this));
labyAPI().serverController().registerServer(server = new OPSuchtServer(this));
}

public static void updateRPC() {
if(instance != null)
instance.rpcManager.updateCustomRPC(false);
}

public static void setConnected(boolean value) {
connected = value;
}

public static boolean isConnected() {
return connected;
public OPSuchtServer server() {
return server;
}

@Override
Expand Down
41 changes: 41 additions & 0 deletions core/src/main/java/com/rappytv/opsucht/OPSuchtServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.rappytv.opsucht;

import net.labymod.api.Laby;
import net.labymod.api.client.network.server.AbstractServer;
import net.labymod.api.event.Phase;

public class OPSuchtServer extends AbstractServer {

private final OPSuchtAddon addon;
private boolean connected;

public OPSuchtServer(OPSuchtAddon addon) {
super("opsucht");
this.addon = addon;
connected = false;
}

@Override
public void loginOrSwitch(LoginPhase phase) {
if(phase == LoginPhase.LOGIN) connected = true;
else if(phase == LoginPhase.SWITCH && addon.configuration().autoFly().get()) {
Laby.labyAPI().minecraft().executeNextTick(() ->
Laby.references().chatExecutor().chat("/fly", false)
);
}

Laby.labyAPI().minecraft().executeNextTick(() ->
addon.rpcManager.updateCustomRPC(phase == LoginPhase.LOGIN)
);
}

@Override
public void disconnect(Phase phase) {
if(phase == Phase.POST) connected = false;
addon.rpcManager.removeCustomRPC();
}

public boolean isConnected() {
return connected;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.rappytv.opsucht.context;

import com.rappytv.opsucht.OPSuchtAddon;
import com.rappytv.opsucht.config.OPSuchtConfig;
import net.labymod.api.Laby;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.entity.player.Player;
Expand All @@ -11,10 +10,10 @@

public class ClanInviteContext implements BulletPoint {

private final OPSuchtConfig config;
private final OPSuchtAddon addon;

public ClanInviteContext(OPSuchtAddon addon) {
this.config = addon.configuration();
this.addon = addon;
}

@Override
Expand All @@ -36,6 +35,6 @@ public void execute(Player player) {

@Override
public boolean isVisible(Player playerInfo) {
return OPSuchtAddon.isConnected() && config.contextSubconfig().clanInviteContext().get();
return addon.server().isConnected() && addon.configuration().contextSubconfig().clanInviteContext().get();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.rappytv.opsucht.context;

import com.rappytv.opsucht.OPSuchtAddon;
import com.rappytv.opsucht.config.OPSuchtConfig;
import net.labymod.api.Laby;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.entity.player.Player;
Expand All @@ -11,10 +10,10 @@

public class FriendRequestContext implements BulletPoint {

private final OPSuchtConfig config;
private final OPSuchtAddon addon;

public FriendRequestContext(OPSuchtAddon addon) {
this.config = addon.configuration();
this.addon = addon;
}

@Override
Expand All @@ -36,6 +35,6 @@ public void execute(Player player) {

@Override
public boolean isVisible(Player playerInfo) {
return OPSuchtAddon.isConnected() && config.contextSubconfig().friendRequestContext().get();
return addon.server().isConnected() && addon.configuration().contextSubconfig().friendRequestContext().get();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.rappytv.opsucht.context;

import com.rappytv.opsucht.OPSuchtAddon;
import com.rappytv.opsucht.config.OPSuchtConfig;
import net.labymod.api.Laby;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.entity.player.Player;
Expand All @@ -11,10 +10,10 @@

public class PayContext implements BulletPoint {

private final OPSuchtConfig config;
private final OPSuchtAddon addon;

public PayContext(OPSuchtAddon addon) {
this.config = addon.configuration();
this.addon = addon;
}

@Override
Expand All @@ -36,6 +35,6 @@ public void execute(Player player) {

@Override
public boolean isVisible(Player playerInfo) {
return OPSuchtAddon.isConnected() && config.contextSubconfig().payContext().get();
return addon.server().isConnected() && addon.configuration().contextSubconfig().payContext().get();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.rappytv.opsucht.listeners;

import com.rappytv.opsucht.OPSuchtAddon;
import com.rappytv.opsucht.config.OPSuchtConfig;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.TextComponent;
import net.labymod.api.client.component.TranslatableComponent;
Expand All @@ -17,27 +16,27 @@

public class ChatReceiveListener {

private final OPSuchtConfig config;
private final OPSuchtAddon addon;
private final Pattern pattern = Pattern.compile("@\\w{3,16}", Pattern.CASE_INSENSITIVE);

public ChatReceiveListener(OPSuchtAddon addon) {
this.config = addon.configuration();
this.addon = addon;
}

@Subscribe
public void onChatReceive(ChatReceiveEvent event) {
if(!OPSuchtAddon.isConnected()) return;
if(!addon.server().isConnected()) return;
Component message = event.message();
String text = event.chatMessage().getPlainText();

if(config.coloredMentions().get() && text.contains("@")) {
if(addon.configuration().coloredMentions().get() && text.contains("@")) {
for(MatchResult matcher : pattern.matcher(text).results().toList()) {
if(matcher.group().equals("@TEAM") || matcher.group().equals("@CLAN")) continue;
replaceComponent(message, matcher.group(), () -> Component.text(matcher.group(), NamedTextColor.AQUA).copy());
}
event.setMessage(message);
}
if(config.clickableNicknames().get()) {
if(addon.configuration().clickableNicknames().get()) {
if(!text.contains("|") || !text.contains("~") || text.length() < 3) return;

String nick = text.split(" ")[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public PlayerInfo(OPSuchtAddon addon) {

@Subscribe
public void onPlayerInfoAdd(PlayerInfoAddEvent event) {
if(!OPSuchtAddon.isConnected()) return;
if(!addon.server().isConnected()) return;
Debounce.of("refresh-opsucht-discord-rpc", 2000, () -> addon.rpcManager.updateCustomRPC(false));
}

@Subscribe
public void onPlayerInfoRemove(PlayerInfoRemoveEvent event) {
if(!OPSuchtAddon.isConnected()) return;
if(!addon.server().isConnected()) return;
Debounce.of("refresh-opsucht-discord-rpc", 2000, () -> addon.rpcManager.updateCustomRPC(false));
}

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rootProject.name = "OPSUCHT-Utilities"

pluginManagement {
val labyGradlePluginVersion = "0.3.38"
val labyGradlePluginVersion = "0.3.44"
plugins {
id("net.labymod.gradle") version (labyGradlePluginVersion)
}
Expand Down

0 comments on commit 5d29395

Please sign in to comment.