Updated cape system for new website
This commit is contained in:
parent
31647d09a3
commit
8580124c73
|
@ -14,10 +14,7 @@ import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Seth
|
* @author Seth
|
||||||
|
@ -27,48 +24,102 @@ public final class CapeManager {
|
||||||
|
|
||||||
private List<CapeUser> capeUserList = new ArrayList<>();
|
private List<CapeUser> capeUserList = new ArrayList<>();
|
||||||
|
|
||||||
private HashMap<String, ResourceLocation> capesMap = new HashMap();
|
private HashMap<String, ResourceLocation> capesMap = new HashMap<>();
|
||||||
|
|
||||||
public CapeManager() {
|
public CapeManager() {
|
||||||
this.downloadCapeUsers();
|
//this.downloadCapeUsers();
|
||||||
this.downloadCapes();
|
//this.downloadCapes();
|
||||||
Seppuku.INSTANCE.getEventManager().addEventListener(this);
|
Seppuku.INSTANCE.getEventManager().addEventListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
public void displayCape(EventCapeLocation event) {
|
public void displayCape(EventCapeLocation event) {
|
||||||
if (Minecraft.getMinecraft().player != null && event.getPlayer() != Minecraft.getMinecraft().player) {
|
if (Minecraft.getMinecraft().player != null && event.getPlayer() != Minecraft.getMinecraft().player) {
|
||||||
final ResourceLocation cape = this.getCape(event.getPlayer());
|
String uuid = event.getPlayer().getUniqueID().toString().replace("-", "");
|
||||||
if (cape != null) {
|
if (this.hasCape(uuid)) {
|
||||||
event.setLocation(cape);
|
final ResourceLocation cape = this.getCape(event.getPlayer());
|
||||||
event.setCanceled(true);
|
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
|
* Download and cache each cape for each user
|
||||||
* TODO thread this
|
* 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 {
|
try {
|
||||||
Minecraft.getMinecraft().getTextureManager();
|
Minecraft.getMinecraft().getTextureManager();
|
||||||
for (CapeUser user : this.capeUserList) {
|
for (CapeUser user : this.capeUserList) {
|
||||||
if (user != null) {
|
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) {
|
if (cape == null) {
|
||||||
URL url = new URL(user.getCape());
|
URL url = new URL(user.getCape());
|
||||||
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 DynamicTexture texture = new DynamicTexture(ImageIO.read(httpURLConnection.getInputStream()));
|
final DynamicTexture texture = new DynamicTexture(ImageIO.read(httpURLConnection.getInputStream()));
|
||||||
final ResourceLocation location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("seppuku/capes", texture);
|
final ResourceLocation location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("seppuku/capes", texture);
|
||||||
this.capesMap.put(user.getCape(), location);
|
this.capesMap.put(user.getCape(), location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
//e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,35 +138,33 @@ public final class CapeManager {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//this.capeUserList.add(new CapeUser(split[0], split[1]));
|
||||||
* Read a list of UUIDS and their cape names
|
// /**
|
||||||
*/
|
// * Read a list of UUIDS and their cape names
|
||||||
protected void downloadCapeUsers() {
|
// */
|
||||||
try {
|
// protected void downloadCapeUsers() {
|
||||||
URL url = new URL("https://seppuku.pw/files/capes_new.txt");
|
// try {
|
||||||
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
// URL url = new URL("https://seppuku.pw/files/capes_new.txt");
|
||||||
httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76");
|
// HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
|
// 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;
|
public boolean hasCape(String uuid) {
|
||||||
while ((line = reader.readLine()) != null) {
|
if (this.findCape(uuid)) {
|
||||||
final String[] split = line.split(";");
|
this.downloadCape(uuid);
|
||||||
this.capeUserList.add(new CapeUser(split[0], split[1]));
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
reader.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasCape() {
|
|
||||||
for (CapeUser capeUser : this.capeUserList) {
|
|
||||||
if (capeUser.getUuid().equals(Minecraft.getMinecraft().session.getProfile().getId().toString().replace("-", ""))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,8 +177,7 @@ public final class CapeManager {
|
||||||
public ResourceLocation getCape(AbstractClientPlayer player) {
|
public ResourceLocation getCape(AbstractClientPlayer player) {
|
||||||
final CapeUser user = this.find(player);
|
final CapeUser user = this.find(player);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
final ResourceLocation res = this.findResource(user.getCape());
|
return this.findResource(user.getCape());
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import me.rigamortis.seppuku.impl.module.player.*;
|
||||||
import me.rigamortis.seppuku.impl.module.render.*;
|
import me.rigamortis.seppuku.impl.module.render.*;
|
||||||
import me.rigamortis.seppuku.impl.module.ui.HudEditorModule;
|
import me.rigamortis.seppuku.impl.module.ui.HudEditorModule;
|
||||||
import me.rigamortis.seppuku.impl.module.world.*;
|
import me.rigamortis.seppuku.impl.module.world.*;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
@ -177,7 +178,8 @@ public final class ModuleManager {
|
||||||
add(new ChestFarmerModule());
|
add(new ChestFarmerModule());
|
||||||
add(new FastProjectile());
|
add(new FastProjectile());
|
||||||
// p2w experience
|
// p2w experience
|
||||||
if (Seppuku.INSTANCE.getCapeManager().hasCape())
|
|
||||||
|
if (Seppuku.INSTANCE.getCapeManager().hasCape(Minecraft.getMinecraft().session.getProfile().getId().toString().replace("-", "")))
|
||||||
add(new CapeModule());
|
add(new CapeModule());
|
||||||
|
|
||||||
this.loadExternalModules();
|
this.loadExternalModules();
|
||||||
|
|
Loading…
Reference in New Issue