Merge branch 'development'

This commit is contained in:
sirjonasxx 2021-09-06 17:29:21 +02:00
commit acf90073e5
4 changed files with 108 additions and 17 deletions

View File

@ -18,6 +18,8 @@ public class HEntity {
private HEntityUpdate lastUpdate = null; private HEntityUpdate lastUpdate = null;
private Object[] stuff = new Object[0]; private Object[] stuff = new Object[0];
private int unknown1;
public HEntity(HPacket packet) { public HEntity(HPacket packet) {
id = packet.readInteger(); id = packet.readInteger();
name = packet.readString(); name = packet.readString();
@ -27,7 +29,7 @@ public class HEntity {
tile = new HPoint(packet.readInteger(), packet.readInteger(), tile = new HPoint(packet.readInteger(), packet.readInteger(),
Double.parseDouble(packet.readString())); Double.parseDouble(packet.readString()));
packet.readInteger(); unknown1 = packet.readInteger();
int entityTypeId = packet.readInteger(); int entityTypeId = packet.readInteger();
entityType = HEntityType.valueOf(entityTypeId); entityType = HEntityType.valueOf(entityTypeId);
@ -43,7 +45,7 @@ public class HEntity {
stuff[4] = packet.readBoolean(); stuff[4] = packet.readBoolean();
break; break;
case 2: case 2:
stuff = new Object[20]; stuff = new Object[12];
stuff[0] = packet.readInteger(); stuff[0] = packet.readInteger();
stuff[1] = packet.readInteger(); stuff[1] = packet.readInteger();
stuff[2] = packet.readString(); stuff[2] = packet.readString();
@ -72,6 +74,48 @@ public class HEntity {
} }
} }
public void appendToPacket(HPacket packet) {
packet.appendInt(id);
packet.appendString(name);
packet.appendString(motto);
packet.appendString(figureId);
packet.appendInt(index);
packet.appendInt(tile.getX());
packet.appendInt(tile.getY());
packet.appendString(tile.getZ() + "");
packet.appendInt(unknown1);
packet.appendInt(entityType.getId());
//
switch (entityType.getId()) {
case 1:
packet.appendObjects(gender.toString(), stuff[0], stuff[1],
favoriteGroup, stuff[2], stuff[3], stuff[4]);
break;
case 2:
packet.appendObjects(stuff);
break;
case 4:
packet.appendObjects(stuff[0], stuff[1], stuff[2]);
List<Short> list = (List<Short>) stuff[3];
packet.appendInt(list.size());
for(short s : list) {
packet.appendShort(s);
}
break;
}
}
public static HPacket constructPacket(HEntity[] entities, int headerId) {
HPacket packet = new HPacket(headerId);
packet.appendInt(entities.length);
for (HEntity entity : entities) {
entity.appendToPacket(packet);
}
return packet;
}
public static HEntity[] parse(HPacket packet) { public static HEntity[] parse(HPacket packet) {
HEntity[] entities = new HEntity[packet.readInteger()]; HEntity[] entities = new HEntity[packet.readInteger()];
@ -132,4 +176,44 @@ public class HEntity {
public Object[] getStuff() { public Object[] getStuff() {
return stuff; return stuff;
} }
public void setId(int id) {
this.id = id;
}
public void setIndex(int index) {
this.index = index;
}
public void setTile(HPoint tile) {
this.tile = tile;
}
public void setName(String name) {
this.name = name;
}
public void setMotto(String motto) {
this.motto = motto;
}
public void setGender(HGender gender) {
this.gender = gender;
}
public void setFigureId(String figureId) {
this.figureId = figureId;
}
public void setFavoriteGroup(String favoriteGroup) {
this.favoriteGroup = favoriteGroup;
}
public void setLastUpdate(HEntityUpdate lastUpdate) {
this.lastUpdate = lastUpdate;
}
public void setStuff(Object[] stuff) {
this.stuff = stuff;
}
} }

View File

@ -17,8 +17,9 @@ import java.util.List;
public class Cacher { public class Cacher {
private static final String DEFAULT_CACHE_FILENAME = "cache.json"; private static final String DEFAULT_CACHE_FILENAME = "cache.json";
private static String cacheDir;
public static String getCacheDir() { static {
File GEarthDir = null; File GEarthDir = null;
try { try {
GEarthDir = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile(); GEarthDir = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile();
@ -26,15 +27,21 @@ public class Cacher {
GEarthDir = GEarthDir.getParentFile(); GEarthDir = GEarthDir.getParentFile();
} }
} catch (URISyntaxException e) { } catch (URISyntaxException e) { }
// e.printStackTrace();
}
return GEarthDir cacheDir = GEarthDir
+ File.separator + File.separator
+ "Cache"; + "Cache";
} }
public static void setCacheDir(String s) {
cacheDir = s;
}
public static String getCacheDir() {
return cacheDir;
}
public static boolean cacheFileExists(String cache_filename) { public static boolean cacheFileExists(String cache_filename) {

View File

@ -120,7 +120,7 @@ public class StoreExtensionDetailsOverview extends HOverview {
@Override @Override
public void buttonClick(GExtensionStore gExtensionStore) { public void buttonClick(GExtensionStore gExtensionStore) {
int mode = mode(); int mode = mode();
if (mode == 2) return; if (mode == 1) return;
String modeString = mode() == 0 ? "Install" : "Update"; String modeString = mode() == 0 ? "Install" : "Update";
HOverview selff = this; HOverview selff = this;
@ -149,7 +149,7 @@ public class StoreExtensionDetailsOverview extends HOverview {
if (mode() == 0) { if (mode() == 0) {
StoreExtensionTools.installExtension(extension.getTitle(), storeRepository, listener); StoreExtensionTools.installExtension(extension.getTitle(), storeRepository, listener);
} }
else if (mode() == 1) { else if (mode() == 2) {
StoreExtensionTools.updateExtension(extension.getTitle(), storeRepository, listener); StoreExtensionTools.updateExtension(extension.getTitle(), storeRepository, listener);
} }
} }

View File

@ -142,10 +142,14 @@ public class StoreExtensionTools {
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
listener.fail("Invalid extension URL"); listener.fail("Invalid extension URL");
removeExtension(path); // cleanup try {
removeExtension(path); // cleanup
} catch (IOException ignore) { }
} catch (IOException e) { } catch (IOException e) {
listener.fail("Extension not available in repository"); listener.fail("Extension not available in repository");
removeExtension(path); // cleanup try {
removeExtension(path); // cleanup
} catch (IOException ignore) { }
} }
} }
else { else {
@ -161,12 +165,8 @@ public class StoreExtensionTools {
} }
public static void removeExtension(String extensionPath) { public static void removeExtension(String extensionPath) throws IOException {
try { FileUtils.deleteDirectory(new File(extensionPath));
FileUtils.deleteDirectory(new File(extensionPath));
} catch (IOException e) {
e.printStackTrace();
}
} }
public static List<InstalledExtension> getInstalledExtension() { public static List<InstalledExtension> getInstalledExtension() {