mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-18 14:57:35 +01:00
Smaller fixes for the pinger, slightly changed position behaviour. Added
getHeight() to Hologram.
This commit is contained in:
parent
db03559136
commit
c4ef162caf
@ -89,6 +89,14 @@ public interface Hologram {
|
||||
public int size();
|
||||
|
||||
|
||||
/**
|
||||
* The physical height of the hologram, counting all the lines. Since: v2.1.4
|
||||
*
|
||||
* @return the height of the hologram, counting all the lines and the gaps between them
|
||||
*/
|
||||
public double getHeight();
|
||||
|
||||
|
||||
/**
|
||||
* Teleports a hologram to the given location.
|
||||
*
|
||||
|
@ -3,6 +3,7 @@ package com.gmail.filoghost.holographicdisplays.bridge.bungeecord.serverpinger;
|
||||
import java.lang.String;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
|
||||
|
||||
@ -20,7 +21,23 @@ public class PingResponse
|
||||
this.maxPlayers = maxPlayers;
|
||||
}
|
||||
|
||||
public PingResponse(JSONObject json) {
|
||||
public PingResponse(String jsonString, ServerAddress address) {
|
||||
|
||||
if (jsonString == null || jsonString.isEmpty()) {
|
||||
motd = "Invalid ping response";
|
||||
DebugHandler.logToConsole("Received empty Json response from IP \"" + address.toString() + "\"!");
|
||||
return;
|
||||
}
|
||||
|
||||
Object jsonObject = JSONValue.parse(jsonString);
|
||||
|
||||
if (!(jsonObject instanceof JSONObject)) {
|
||||
motd = "Invalid ping response";
|
||||
DebugHandler.logToConsole("Received invalid Json response from IP \"" + address.toString() + "\": " + jsonString);
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject json = (JSONObject) jsonObject;
|
||||
isOnline = true;
|
||||
|
||||
Object descriptionObject = json.get("description");
|
||||
@ -29,7 +46,7 @@ public class PingResponse
|
||||
motd = descriptionObject.toString();
|
||||
} else {
|
||||
motd = "Invalid ping response";
|
||||
DebugHandler.logToConsole("Received invalid ping response: " + json.toString());
|
||||
DebugHandler.logToConsole("Received invalid Json response from IP \"" + address.toString() + "\": " + jsonString);
|
||||
}
|
||||
|
||||
Object playersObject = json.get("players");
|
||||
|
@ -8,9 +8,6 @@ import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
final class ServerPingerPostNetty extends ServerPinger {
|
||||
|
||||
@Override
|
||||
@ -43,7 +40,7 @@ final class ServerPingerPostNetty extends ServerPinger {
|
||||
final byte[] responseData = new byte[PacketUtils.readVarInt(dataIn)];
|
||||
dataIn.readFully(responseData);
|
||||
final String jsonString = new String(responseData, PacketUtils.UTF8);
|
||||
return new PingResponse((JSONObject) JSONValue.parse(jsonString));
|
||||
return new PingResponse(jsonString, serverAddress);
|
||||
}
|
||||
finally {
|
||||
PacketUtils.closeQuietly(dataOut);
|
||||
|
@ -8,8 +8,11 @@ import java.lang.Integer;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.Arrays;
|
||||
import java.lang.String;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
|
||||
|
||||
final class ServerPingerPreNetty extends ServerPinger {
|
||||
|
||||
@Override
|
||||
@ -33,6 +36,12 @@ final class ServerPingerPreNetty extends ServerPinger {
|
||||
dataIn.readFully(bytes);
|
||||
socket.close();
|
||||
final String[] info = new String(bytes, PacketUtils.UTF16BE).split(String.valueOf('\0'));
|
||||
|
||||
if (info.length < 6) {
|
||||
DebugHandler.logToConsole("Received invalid ping response: " + Arrays.toString(info));
|
||||
return new PingResponse(true, "Invalid ping response", 0, 0);
|
||||
}
|
||||
|
||||
final PingResponse response = new PingResponse(true, info[3], Integer.parseInt(info[4]), Integer.parseInt(info[5]));
|
||||
// String versionName = info[2];
|
||||
// String protocol = info[1];
|
||||
|
@ -183,6 +183,21 @@ public class CraftHologram implements Hologram, com.gmail.filoghost.holograms.ap
|
||||
return lines.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
if (lines.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double height = 0.0;
|
||||
|
||||
for (CraftHologramLine line : lines) {
|
||||
height += line.getHeight();
|
||||
}
|
||||
|
||||
height += Configuration.spaceBetweenLines * (lines.size() - 1);
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftVisibilityManager getVisibilityManager() {
|
||||
@ -241,10 +256,11 @@ public class CraftHologram implements Hologram, com.gmail.filoghost.holograms.ap
|
||||
|
||||
for (CraftHologramLine line : lines) {
|
||||
|
||||
currentY -= line.getHeight();
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
currentY -= line.getHeight();
|
||||
currentY -= Configuration.spaceBetweenLines;
|
||||
}
|
||||
|
||||
@ -273,10 +289,11 @@ public class CraftHologram implements Hologram, com.gmail.filoghost.holograms.ap
|
||||
|
||||
for (CraftHologramLine line : lines) {
|
||||
|
||||
currentY -= line.getHeight();
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
currentY -= line.getHeight();
|
||||
currentY -= Configuration.spaceBetweenLines;
|
||||
}
|
||||
|
||||
@ -325,10 +342,11 @@ public class CraftHologram implements Hologram, com.gmail.filoghost.holograms.ap
|
||||
continue;
|
||||
}
|
||||
|
||||
currentY -= line.getHeight();
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
currentY -= line.getHeight();
|
||||
currentY -= Configuration.spaceBetweenLines;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user