Fix #40; remove per-client tick check of capes, when donation list wasn't even used

This commit is contained in:
Dave Smith committed 2019-03-12 12:20:32 -06:00
1 parent dcd440705d
commit 75c51487ee
4 files changed
-180

No files matched your search

@@ -1,82 +0,0 @@
package mekanism.client;
import java.io.File;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class CapeBufferDownload extends Thread {
public String username;
public String staticCapeUrl;
public ResourceLocation resourceLocation;
public ThreadDownloadImageData capeImage;
boolean downloaded = false;
public CapeBufferDownload(String name, String url) {
username = name;
staticCapeUrl = url;
setDaemon(true);
setName("Cape Download Thread");
}
@Override
public void run() {
try {
download();
} catch (Exception e) {
e.printStackTrace();
}
}
private void download() {
try {
resourceLocation = new ResourceLocation("mekanism/" + StringUtils.stripControlCodes(username));
capeImage = downloadCape();
} catch (Exception e) {
e.printStackTrace();
}
downloaded = true;
}
public ThreadDownloadImageData getImage() {
return capeImage;
}
public ResourceLocation getResourceLocation() {
return resourceLocation;
}
public ThreadDownloadImageData downloadCape() {
try {
File capeFile = new File(resourceLocation.getPath() + ".png");
if (capeFile.exists()) {
capeFile.delete();
}
TextureManager manager = Minecraft.getMinecraft().getTextureManager();
ThreadDownloadImageData data = new ThreadDownloadImageData(capeFile, staticCapeUrl, null, null);
manager.loadTexture(resourceLocation, data);
return data;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
@@ -1,6 +1,5 @@
package mekanism.client;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -30,18 +29,13 @@ import mekanism.common.network.PacketItemStack.ItemStackMessage;
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage;
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterPacketType;
import mekanism.common.util.ListUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@@ -58,8 +52,6 @@ import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ClientTickHandler {
public static final String DONATE_CAPE = "http://aidancbrady.com/data/capes/donate.png";
public static final String AIDAN_CAPE = "http://aidancbrady.com/data/capes/aidan.png";
public static Minecraft mc = FMLClientHandler.instance().getClient();
public static Random rand = new Random();
public static Set<IClientTicker> tickingSet = new HashSet<>();
@@ -67,16 +59,6 @@ public class ClientTickHandler {
public static int wheelStatus = 0;
public boolean initHoliday = false;
public boolean shouldReset = false;
private Map<String, CapeBufferDownload> donateDownload = new HashMap<>();
private Map<String, CapeBufferDownload> aidanDownload = new HashMap<>();
public static void setCape(AbstractClientPlayer player, ResourceLocation cape) {
NetworkPlayerInfo info = player.getPlayerInfo();
if (info != null) {
info.playerTextures.put(MinecraftProfileTexture.Type.CAPE, cape);
}
}
public static void killDeadNetworks() {
tickingSet.removeIf(iClientTicker -> !iClientTicker.needsTicks());
@@ -222,44 +204,6 @@ public class ClientTickHandler {
initHoliday = true;
}
for (EntityPlayer entityPlayer : mc.world.playerEntities) {
if (entityPlayer instanceof AbstractClientPlayer) {
AbstractClientPlayer player = (AbstractClientPlayer) entityPlayer;
if (StringUtils.stripControlCodes(player.getName()).equals("aidancbrady")) {
CapeBufferDownload download = aidanDownload.get(player.getName());
if (download == null) {
download = new CapeBufferDownload(player.getName(), AIDAN_CAPE);
aidanDownload.put(player.getName(), download);
download.start();
} else {
if (!download.downloaded) {
continue;
}
setCape(player, download.getResourceLocation());
}
} else if (Mekanism.donators.contains(StringUtils.stripControlCodes(player.getName()))) {
CapeBufferDownload download = donateDownload.get(player.getName());
if (download == null) {
download = new CapeBufferDownload(player.getName(), DONATE_CAPE);
donateDownload.put(player.getName(), download);
download.start();
} else {
if (!download.downloaded) {
continue;
}
setCape(player, download.getResourceLocation());
}
}
}
}
if (Mekanism.freeRunnerOn.contains(mc.player.getName()) != isFreeRunnerOn(mc.player)) {
if (isFreeRunnerOn(mc.player) && mc.currentScreen == null) {
Mekanism.freeRunnerOn.add(mc.player.getName());
@@ -225,10 +225,6 @@ public class Mekanism {
* List of Mekanism modules loaded
*/
public static List<IModule> modulesLoaded = new ArrayList<>();
/**
* A list of the usernames of players who have donated to Mekanism.
*/
public static List<String> donators = new ArrayList<>();
/**
* The server's world tick handler.
*/
@@ -127,44 +127,6 @@ public final class MekanismUtils {
}
}
/**
* Updates the donator list by retrieving the most recent information from a foreign document.
*/
public static void updateDonators() {
Mekanism.donators.clear();
Mekanism.donators.addAll(getHTML("http://aidancbrady.com/data/capes/Mekanism.txt"));
}
/**
* Returns one line of HTML from the url.
*
* @param urlToRead - URL to read from.
* @return HTML text from the url.
*/
public static List<String> getHTML(String urlToRead) {
String line;
List<String> result = new ArrayList<>();
try {
URL url = new URL(urlToRead);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("User-Agent", "Mekanism/" + Mekanism.versionNumber.toString());
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
result.add(line.trim());
}
rd.close();
} catch (Exception e) {
result.clear();
result.add("null");
Mekanism.logger.error("An error occurred while connecting to URL '" + urlToRead + "'", e);
}
return result;
}
public static String merge(List<String> text) {
StringBuilder builder = new StringBuilder();