mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
HEntityType enum, HPacket change
This commit is contained in:
parent
50a76155f8
commit
62dce6fa99
@ -8,11 +8,11 @@ public class HEntity {
|
||||
private HPoint tile;
|
||||
private String name;
|
||||
private String motto;
|
||||
private HGender gender;
|
||||
private int entityType;
|
||||
private HGender gender = null;
|
||||
private HEntityType entityType;
|
||||
private String figureId;
|
||||
private String favoriteGroup;
|
||||
private HEntityUpdate lastUpdate;
|
||||
private String favoriteGroup = null;
|
||||
private HEntityUpdate lastUpdate = null;
|
||||
|
||||
public HEntity(HPacket packet) {
|
||||
id = packet.readInteger();
|
||||
@ -24,9 +24,10 @@ public class HEntity {
|
||||
Double.parseDouble(packet.readString()));
|
||||
|
||||
packet.readInteger();
|
||||
entityType = packet.readInteger();
|
||||
int entityTypeId = packet.readInteger();
|
||||
entityType = HEntityType.valueOf(entityTypeId);
|
||||
|
||||
switch (entityType) {
|
||||
switch (entityTypeId) {
|
||||
case 1:
|
||||
gender = HGender.valueOf(packet.readString());
|
||||
packet.readInteger();
|
||||
@ -104,7 +105,7 @@ public class HEntity {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public int getEntityType() {
|
||||
public HEntityType getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
package gearth.extensions.parsers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Jeunez on 8/01/2019.
|
||||
*/
|
||||
public enum HEntityType {
|
||||
HABBO(1),
|
||||
PET(2),
|
||||
OLD_BOT(3),
|
||||
BOT(4);
|
||||
|
||||
private int id;
|
||||
|
||||
HEntityType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
private static Map<Integer, HEntityType> map = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (HEntityType type : HEntityType.values()) {
|
||||
map.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static HEntityType valueOf (int id) {
|
||||
return map.get(id);
|
||||
}
|
||||
}
|
@ -684,14 +684,21 @@ public class HPacket implements StringifyAble {
|
||||
}
|
||||
|
||||
|
||||
private String toExpressionFromGivenStructure(String struct) {
|
||||
int oldReadIndex = readIndex;
|
||||
resetReadIndex();
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("{l}{u:").append(headerId()).append("}");
|
||||
|
||||
buildExpressionFromGivenStructure(struct, 0, builder);
|
||||
readIndex = oldReadIndex;
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private void buildExpressionFromGivenStructure(String struct, int indexInGivenStruct, StringBuilder builder) {
|
||||
int prevInt = 0;
|
||||
|
||||
if (indexInGivenStruct == -1) {
|
||||
builder.append("{l}{u:").append(headerId()).append("}");
|
||||
indexInGivenStruct = 0;
|
||||
}
|
||||
|
||||
while (indexInGivenStruct < struct.length()) {
|
||||
char c = struct.charAt(indexInGivenStruct++);
|
||||
if (c == '(') {
|
||||
@ -710,7 +717,6 @@ public class HPacket implements StringifyAble {
|
||||
else if (c == 'B') builder.append("{b:").append(readBoolean()).append('}');
|
||||
else return; // ')'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String toExpression(HMessage.Side side) {
|
||||
@ -720,12 +726,7 @@ public class HPacket implements StringifyAble {
|
||||
if (HarbleAPIFetcher.HARBLEAPI != null &&
|
||||
((msg = HarbleAPIFetcher.HARBLEAPI.getHarbleMessageFromHeaderId(side, headerId())) != null)) {
|
||||
if (msg.getStructure() != null) {
|
||||
int oldReadIndex = readIndex;
|
||||
resetReadIndex();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
buildExpressionFromGivenStructure(msg.getStructure(), -1, builder);
|
||||
readIndex = oldReadIndex;
|
||||
return builder.toString();
|
||||
return toExpressionFromGivenStructure(msg.getStructure());
|
||||
}
|
||||
}
|
||||
return toExpression();
|
||||
@ -1026,9 +1027,7 @@ public class HPacket implements StringifyAble {
|
||||
public static void main(String[] args) {
|
||||
HPacket packet = new HPacket("{l}{u:4564}{i:3}{i:0}{s:hi}{i:0}{i:1}{s:how}{i:3}{b:1}{b:2}{b:3}{i:2}{s:r u}{i:1}{b:120}{i:2}{b:true}");
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
packet.buildExpressionFromGivenStructure("i(isi(b))iB", -1, builder);
|
||||
String str = builder.toString();
|
||||
String str = packet.toExpressionFromGivenStructure("i(isi(b))iB");
|
||||
|
||||
HPacket packetverify = new HPacket(str);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user