Skip to content

Commit b39ec6d

Browse files
committed
Fix issues with /whereami by replacing with /locraw. Also update Hypixel IP support
1 parent 9fe37c6 commit b39ec6d

File tree

5 files changed

+48
-35
lines changed

5 files changed

+48
-35
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jar {
2828

2929
targetCompatibility = sourceCompatibility = 1.8
3030

31-
version = "2.0.5"
31+
version = "2.0.6"
3232
group= "co.bugg.quickplay" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
3333
archivesBaseName = "Quickplay-1.8.9"
3434

src/main/java/co/bugg/quickplay/Reference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Reference {
1515
/**
1616
* Version of this forge mod
1717
*/
18-
public static final String VERSION = "2.0.5";
18+
public static final String VERSION = "2.0.6";
1919
/**
2020
* Google Analytics tracking ID
2121
*/

src/main/java/co/bugg/quickplay/util/InstanceWatcher.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* When online Hypixel, enabled instances of
1414
* this class will watch for what instance the
1515
* client is on by occasionally executing
16-
* /whereami
16+
* /locraw
1717
*/
1818
public class InstanceWatcher {
1919
/**
@@ -27,29 +27,29 @@ public class InstanceWatcher {
2727
*/
2828
public boolean started = false;
2929
/**
30-
* How often in seconds /whereami should be executed
30+
* How often in seconds /locraw should be executed
3131
*/
32-
public int whereamiFrequency;
32+
public int locrawFrequency;
3333

3434
public InstanceWatcher(int frequency) {
35-
whereamiFrequency = frequency;
35+
locrawFrequency = frequency;
3636
}
3737

3838
public int tick;
3939

4040
@SubscribeEvent
4141
public void onTick(TickEvent.ClientTickEvent event) {
42-
if(event.phase == TickEvent.Phase.START && tick++ > whereamiFrequency * 20) {
42+
if(event.phase == TickEvent.Phase.START && tick++ > locrawFrequency * 20) {
4343
tick = 0;
44-
runWhereami();
44+
runLocraw();
4545
}
4646
}
4747

4848
@SubscribeEvent
4949
public void onWorldChange(WorldEvent.Load event) {
5050
// Run twice, just in case first one doesn't trigger
51-
new TickDelay(this::runWhereami, 15);
52-
new TickDelay(this::runWhereami, 60);
51+
new TickDelay(this::runLocraw, 15);
52+
new TickDelay(this::runLocraw, 60);
5353
}
5454

5555
/**
@@ -59,7 +59,7 @@ public void onWorldChange(WorldEvent.Load event) {
5959
public InstanceWatcher start() {
6060
Quickplay.INSTANCE.registerEventHandler(this);
6161
started = true;
62-
runWhereami();
62+
runLocraw();
6363
return this;
6464
}
6565

@@ -74,12 +74,12 @@ public InstanceWatcher stop() {
7474
}
7575

7676
/**
77-
* Send the /whereami message if possible
77+
* Send the /locraw message if possible
7878
* @return this
7979
*/
80-
public InstanceWatcher runWhereami() {
80+
public InstanceWatcher runLocraw() {
8181
if(Quickplay.INSTANCE.onHypixel && Quickplay.INSTANCE.enabled) {
82-
new WhereamiWrapper((server) -> {
82+
new LocrawWrapper((server) -> {
8383

8484
// Automatic lobby 1 swapper
8585
if (Quickplay.INSTANCE.settings.lobbyOneSwap) {

src/main/java/co/bugg/quickplay/util/WhereamiWrapper.java renamed to src/main/java/co/bugg/quickplay/util/LocrawWrapper.java

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,49 @@
11
package co.bugg.quickplay.util;
22

33
import co.bugg.quickplay.Quickplay;
4+
import com.google.gson.Gson;
5+
import com.google.gson.JsonObject;
6+
import com.google.gson.JsonSyntaxException;
47
import net.minecraftforge.client.event.ClientChatReceivedEvent;
58
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
69

710
import java.util.regex.Matcher;
811
import java.util.regex.Pattern;
912

1013
/**
11-
* Wrapper for the <code>/whereami</code> command on Hypixel and determining the client's location
14+
* Wrapper for the <code>/locraw</code> command on Hypixel and determining the client's location
1215
*/
13-
public class WhereamiWrapper {
16+
public class LocrawWrapper {
1417
/**
1518
* Whether this wrapper should listen for & action on chat messages
1619
*/
1720
boolean listening;
1821
/**
19-
* Whether this wrapper should cancel whereami messages it finds
22+
* Whether this wrapper should cancel locraw messages it finds
2023
*/
2124
boolean cancel;
2225
/**
23-
* Callback when this wrapper finds a /whereami message
26+
* Callback when this wrapper finds a /locraw message
2427
*/
25-
final WhereamiListenerCallback callback;
28+
final LocrawListenerCallback callback;
2629

2730
/**
2831
* Constructor
2932
*
30-
* @param callback Callback when this wrapper finds a /whereami message
33+
* @param callback Callback when this wrapper finds a /locraw message
3134
*/
32-
public WhereamiWrapper(WhereamiListenerCallback callback) {
35+
public LocrawWrapper(LocrawListenerCallback callback) {
3336

3437
Quickplay.INSTANCE.registerEventHandler(this);
3538
this.callback = callback;
3639
this.listening = true;
3740
this.cancel = true;
3841

39-
// Send the /whereami command
40-
Quickplay.INSTANCE.chatBuffer.push("/whereami");
41-
// If a /whereami isn't received within 120 ticks (6 seconds), don't cancel the message
42+
// Send the /locraw command
43+
Quickplay.INSTANCE.chatBuffer.push("/locraw");
44+
// If a /locraw isn't received within 120 ticks (6 seconds), don't cancel the message
4245
new TickDelay(this::stopCancelling, 120);
43-
// If a /whereami isn't received within 1200 ticks (60 seconds), stop listening
46+
// If a /locraw isn't received within 1200 ticks (60 seconds), stop listening
4447
new TickDelay(() -> stopListening(null), 1200);
4548
}
4649

@@ -69,10 +72,8 @@ public void stopListening(String instance) {
6972
@SubscribeEvent
7073
public void onChat(ClientChatReceivedEvent event) {
7174
final String message = event.message.getUnformattedText();
72-
// Regex for the /whereami response
73-
// §bYou are currently connected to server §r§6lobby5§r
74-
final Pattern pattern = Pattern.compile("^(?:\u00a7b)?You are currently (?:in limbo|" +
75-
"connected to server (?:\u00a76)?([a-zA-Z]+\\d+[A-Z]?))$");
75+
// Regex for the /locraw response
76+
final Pattern pattern = Pattern.compile("^\\{\"server\":");
7677
final Matcher matcher = pattern.matcher(message);
7778

7879
if(
@@ -87,20 +88,32 @@ public void onChat(ClientChatReceivedEvent event) {
8788
event.setCanceled(true);
8889
}
8990

90-
// Get the regex group containing the current instance
91-
final String instance = matcher.group(1);
92-
stopListening(instance);
91+
try {
92+
String instance = null;
93+
final JsonObject locrawResponse = new Gson().fromJson(message, JsonObject.class);
94+
// Try lobby name first -- If null, use server name.
95+
if (locrawResponse.get("lobbyname") != null) {
96+
instance = locrawResponse.get("lobbyname").getAsString();
97+
}
98+
if (instance == null && locrawResponse.get("server") != null) {
99+
instance = locrawResponse.get("server").getAsString();
100+
}
101+
stopListening(instance);
102+
} catch (JsonSyntaxException e) {
103+
e.printStackTrace();
104+
stopListening(null);
105+
}
93106
}
94107

95108
}
96109

97110
/**
98111
* Interface for inline callbacks
99-
* Called when a response to /whereami is received,
112+
* Called when a response to /locraw is received,
100113
* or after 60 seconds of no response with "null" passed
101114
*/
102115
@FunctionalInterface
103-
public interface WhereamiListenerCallback {
116+
public interface LocrawListenerCallback {
104117

105118
void call(String instance);
106119
}

src/main/java/co/bugg/quickplay/util/ServerChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public ServerChecker(ServerCheckerCallback callback) {
4242

4343
final String ip = getCurrentIP();
4444
if(!ip.equals("singleplayer")) {
45-
Pattern hypixelPattern = Pattern.compile("^(?:(?:(?:.*\\.)?hypixel\\.net)|(?:209\\.222\\.115\\.\\d{1,3}))(?::\\d{1,5})?$", Pattern.CASE_INSENSITIVE);
45+
Pattern hypixelPattern = Pattern.compile("^(?:.*\\.)?hypixel\\.(?:net|io)(?::\\d{1,5})?$", Pattern.CASE_INSENSITIVE);
4646
Matcher matcher = hypixelPattern.matcher(ip);
4747

4848
// If the current IP matches the regex above

0 commit comments

Comments
 (0)