CapeManager bug fixes
This commit is contained in:
parent
4cb74a14ae
commit
d60a58daea
|
@ -55,16 +55,21 @@ public final class CapeManager {
|
||||||
// });
|
// });
|
||||||
// t.start();
|
// t.start();
|
||||||
try {
|
try {
|
||||||
URL url = new URL("https://seppuku.pw/capes");
|
URL url = new URL("https://seppuku.pw/capes/");
|
||||||
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||||
httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76");
|
httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76");
|
||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
|
final BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
|
||||||
reader.lines().forEachOrdered(line -> {
|
String line;
|
||||||
final String[] split = line.split(";");
|
while ((line = reader.readLine()) != null) {
|
||||||
if (split[1].toLowerCase().endsWith("png")) {
|
if (!line.startsWith("<pre>") && !line.startsWith("</pre>") && line.length() > 1) {
|
||||||
this.getCapeUserList().add(new CapeUser(split[0], split[1]));
|
final String[] split = line.split(";");
|
||||||
|
if (split[0] != null && split[1] != null) {
|
||||||
|
if (split[1].toLowerCase().endsWith("png")) {
|
||||||
|
this.capeUserList.add(new CapeUser(split[0], split[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//e.printStackTrace();
|
//e.printStackTrace();
|
||||||
|
@ -76,23 +81,25 @@ public final class CapeManager {
|
||||||
* TODO thread this
|
* TODO thread this
|
||||||
*/
|
*/
|
||||||
public void downloadCapes() {
|
public void downloadCapes() {
|
||||||
this.capeUserList.parallelStream().filter(capeUser -> this.findResource(capeUser.getCape()) == null).forEach(capeUser -> {
|
for (CapeUser capeUser : this.capeUserList) {
|
||||||
try {
|
if (this.findResource(capeUser.getCape()) == null) {
|
||||||
URL url = new URL(capeUser.getCape());
|
try {
|
||||||
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
URL url = new URL(capeUser.getCape());
|
||||||
httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76");
|
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||||
final BufferedImage imageIO = ImageIO.read(httpURLConnection.getInputStream());
|
httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76");
|
||||||
if (imageIO != null) {
|
final BufferedImage imageIO = ImageIO.read(httpURLConnection.getInputStream());
|
||||||
if (imageIO.getWidth() <= 2048 && imageIO.getHeight() <= 1024) {
|
if (imageIO != null) {
|
||||||
final DynamicTexture texture = new DynamicTexture(imageIO);
|
if (imageIO.getWidth() <= 2048 && imageIO.getHeight() <= 1024) {
|
||||||
final ResourceLocation location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("seppuku/capes", texture);
|
final DynamicTexture texture = new DynamicTexture(imageIO);
|
||||||
this.capesMap.put(capeUser.getCape(), location);
|
final ResourceLocation location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("seppuku/capes", texture);
|
||||||
|
this.capesMap.put(capeUser.getCape(), location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
//e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
//e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,13 +119,14 @@ public final class CapeManager {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ResourceLocation getCape(AbstractClientPlayer player) {
|
public ResourceLocation getCape(AbstractClientPlayer player) {
|
||||||
|
ResourceLocation result = null;
|
||||||
final CapeUser user = this.find(player);
|
final CapeUser user = this.find(player);
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
return this.findResource(user.getCape());
|
result = this.findResource(user.getCape());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,16 +136,17 @@ public final class CapeManager {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public CapeUser find(AbstractClientPlayer player) {
|
public CapeUser find(AbstractClientPlayer player) {
|
||||||
if (this.capeUserList.isEmpty())
|
CapeUser result = null;
|
||||||
return null;
|
if (!this.capeUserList.isEmpty()) {
|
||||||
|
for (CapeUser user : this.capeUserList) {
|
||||||
for (CapeUser user : this.capeUserList) {
|
if (user.getUuid().equals(player.getUniqueID().toString().replace("-", ""))) {
|
||||||
if (user.getUuid().equals(player.getUniqueID().toString().replace("-", ""))) {
|
result = user;
|
||||||
return user;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCape() {
|
public boolean hasCape() {
|
||||||
|
|
Loading…
Reference in New Issue