Updated cape system for new website

This commit is contained in:
noil 2023-05-06 01:04:28 -04:00
parent 31647d09a3
commit 8580124c73
2 changed files with 101 additions and 51 deletions

View File

@ -14,10 +14,7 @@ import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @author Seth
@ -27,48 +24,102 @@ public final class CapeManager {
private List<CapeUser> capeUserList = new ArrayList<>();
private HashMap<String, ResourceLocation> capesMap = new HashMap();
private HashMap<String, ResourceLocation> capesMap = new HashMap<>();
public CapeManager() {
this.downloadCapeUsers();
this.downloadCapes();
//this.downloadCapeUsers();
//this.downloadCapes();
Seppuku.INSTANCE.getEventManager().addEventListener(this);
}
@Listener
public void displayCape(EventCapeLocation event) {
if (Minecraft.getMinecraft().player != null && event.getPlayer() != Minecraft.getMinecraft().player) {
final ResourceLocation cape = this.getCape(event.getPlayer());
if (cape != null) {
event.setLocation(cape);
event.setCanceled(true);
String uuid = event.getPlayer().getUniqueID().toString().replace("-", "");
if (this.hasCape(uuid)) {
final ResourceLocation cape = this.getCape(event.getPlayer());
if (cape != null) {
event.setLocation(cape);
event.setCanceled(true);
}
}
}
}
public boolean hasCapeForUuid(String uuid) {
for (CapeUser capeUser : this.capeUserList) {
if (capeUser.getUuid().equals(uuid)) {
return true;
}
}
return false;
}
public boolean findCape(String uuid) {
if (hasCapeForUuid(uuid))
return true;
try {
URL url = new URL("https://seppuku.pw/cape/" + uuid);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76");
final BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
if (!line.toLowerCase().startsWith("no") && line.toLowerCase().endsWith("png")) {
this.capeUserList.add(new CapeUser(uuid, line));
} else {
return false;
}
}
reader.close();
return true;
} catch (Exception e) {
//e.printStackTrace();
}
return false;
}
/**
* Download and cache each cape for each user
* TODO thread this
*/
protected void downloadCapes() {
public void downloadCape(String uuid) {
CapeUser existingUser = null;
for (CapeUser capeUser : this.capeUserList) {
if (capeUser.getUuid().equals(uuid)) {
existingUser = capeUser;
break;
}
}
if (existingUser != null) {
if (this.capesMap.containsKey(existingUser.getCape())) {
return;
}
}
try {
Minecraft.getMinecraft().getTextureManager();
for (CapeUser user : this.capeUserList) {
if (user != null) {
final ResourceLocation cape = this.findResource(user.getCape());
if (Objects.equals(user.getUuid(), uuid)) {
final ResourceLocation cape = this.findResource(user.getCape());
if (cape == null) {
URL url = new URL(user.getCape());
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76");
final DynamicTexture texture = new DynamicTexture(ImageIO.read(httpURLConnection.getInputStream()));
final ResourceLocation location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("seppuku/capes", texture);
this.capesMap.put(user.getCape(), location);
if (cape == null) {
URL url = new URL(user.getCape());
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76");
final DynamicTexture texture = new DynamicTexture(ImageIO.read(httpURLConnection.getInputStream()));
final ResourceLocation location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("seppuku/capes", texture);
this.capesMap.put(user.getCape(), location);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
//e.printStackTrace();
}
}
@ -87,35 +138,33 @@ public final class CapeManager {
return null;
}
/**
* Read a list of UUIDS and their cape names
*/
protected void downloadCapeUsers() {
try {
URL url = new URL("https://seppuku.pw/files/capes_new.txt");
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76");
final BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
//this.capeUserList.add(new CapeUser(split[0], split[1]));
// /**
// * Read a list of UUIDS and their cape names
// */
// protected void downloadCapeUsers() {
// try {
// URL url = new URL("https://seppuku.pw/files/capes_new.txt");
// HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
// httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76");
// final BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
//
// String line;
// while ((line = reader.readLine()) != null) {
// final String[] split = line.split(";");
// this.capeUserList.add(new CapeUser(split[0], split[1]));
// }
//
// reader.close();
// } catch (Exception e) {
// e.printStackTrace();
// }
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(";");
this.capeUserList.add(new CapeUser(split[0], split[1]));
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
public boolean hasCape(String uuid) {
if (this.findCape(uuid)) {
this.downloadCape(uuid);
return true;
}
}
public boolean hasCape() {
for (CapeUser capeUser : this.capeUserList) {
if (capeUser.getUuid().equals(Minecraft.getMinecraft().session.getProfile().getId().toString().replace("-", ""))) {
return true;
}
}
return false;
}
@ -128,8 +177,7 @@ public final class CapeManager {
public ResourceLocation getCape(AbstractClientPlayer player) {
final CapeUser user = this.find(player);
if (user != null) {
final ResourceLocation res = this.findResource(user.getCape());
return res;
return this.findResource(user.getCape());
}
return null;
}

View File

@ -14,6 +14,7 @@ import me.rigamortis.seppuku.impl.module.player.*;
import me.rigamortis.seppuku.impl.module.render.*;
import me.rigamortis.seppuku.impl.module.ui.HudEditorModule;
import me.rigamortis.seppuku.impl.module.world.*;
import net.minecraft.client.Minecraft;
import java.io.File;
import java.lang.reflect.Field;
@ -177,7 +178,8 @@ public final class ModuleManager {
add(new ChestFarmerModule());
add(new FastProjectile());
// p2w experience
if (Seppuku.INSTANCE.getCapeManager().hasCape())
if (Seppuku.INSTANCE.getCapeManager().hasCape(Minecraft.getMinecraft().session.getProfile().getId().toString().replace("-", "")))
add(new CapeModule());
this.loadExternalModules();