0
0
mirror of https://github.com/Wurst-Imperium/Wurst7.git synced 2024-09-20 01:12:13 +02:00

Add warning message when VanillaTweaks Twinkling Stars is installed

This commit is contained in:
Alexander01998 2022-08-20 20:44:18 +02:00
parent 0a8555c170
commit 791be1e54c
5 changed files with 171 additions and 0 deletions

View File

@ -47,6 +47,7 @@ import net.wurstclient.nochatreports.NoChatReportsChannelHandler;
import net.wurstclient.other_feature.OtfList;
import net.wurstclient.other_feature.OtherFeature;
import net.wurstclient.settings.SettingsFile;
import net.wurstclient.update.ProblematicResourcePackDetector;
import net.wurstclient.update.WurstUpdater;
import net.wurstclient.util.json.JsonException;
@ -79,6 +80,7 @@ public enum WurstClient
private boolean enabled = true;
private static boolean guiInitialized;
private WurstUpdater updater;
private ProblematicResourcePackDetector problematicPackDetector;
private Path wurstFolder;
private KeyBinding zoomKey;
@ -139,6 +141,9 @@ public enum WurstClient
updater = new WurstUpdater();
eventManager.add(UpdateListener.class, updater);
problematicPackDetector = new ProblematicResourcePackDetector();
problematicPackDetector.start();
Path altsFile = wurstFolder.resolve("alts.encrypted_json");
Path encFolder =
Paths.get(System.getProperty("user.home"), ".Wurst encryption")
@ -316,6 +321,11 @@ public enum WurstClient
return updater;
}
public ProblematicResourcePackDetector getProblematicPackDetector()
{
return problematicPackDetector;
}
public Path getWurstFolder()
{
return wurstFolder;

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2014-2022 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.pack.PackScreen;
import net.minecraft.text.Text;
import net.wurstclient.WurstClient;
@Mixin(PackScreen.class)
public class PackScreenMixin extends Screen
{
private PackScreenMixin(WurstClient wurst, Text title)
{
super(title);
}
/**
* Scans for problematic resource packs (currently just VanillaTweaks
* Twinkling Stars) whenever the resource pack screen is closed.
*/
@Inject(at = @At("HEAD"), method = "close()V")
public void onClose(CallbackInfo ci)
{
WurstClient.INSTANCE.getProblematicPackDetector().start();
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (c) 2014-2022 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.update;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourcePackProfile;
import net.wurstclient.WurstClient;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.util.ChatUtils;
import net.wurstclient.util.StreamUtils;
public final class ProblematicResourcePackDetector implements UpdateListener
{
private static final String WARNING_MESSAGE =
"VanillaTweaks \"Twinkling Stars\" pack detected. This resource pack is known to cause problems with Wurst!";
private boolean running;
public void start()
{
if(running)
return;
WurstClient.INSTANCE.getEventManager().add(UpdateListener.class, this);
running = true;
}
@Override
public void onUpdate()
{
if(WurstClient.INSTANCE.isEnabled() && isTwinklingStarsInstalled())
ChatUtils.warning(WARNING_MESSAGE);
WurstClient.INSTANCE.getEventManager().remove(UpdateListener.class,
this);
running = false;
}
private boolean isTwinklingStarsInstalled()
{
Collection<ResourcePackProfile> enabledProfiles =
WurstClient.MC.getResourcePackManager().getEnabledProfiles();
for(ResourcePackProfile profile : enabledProfiles)
{
if(!isVanillaTweaks(profile))
continue;
ResourcePack pack = profile.createResourcePack();
if(!containsTwinklingStars(pack))
continue;
return true;
}
return false;
}
private boolean isVanillaTweaks(ResourcePackProfile profile)
{
return profile.getDescription().getString().contains("Vanilla Tweaks");
}
private boolean containsTwinklingStars(ResourcePack pack)
{
try
{
ArrayList<String> lines =
StreamUtils.readAllLines(pack.openRoot("Selected Packs.txt"));
return lines.stream()
.anyMatch(line -> line.contains("TwinklingStars"));
}catch(IOException e)
{
return false;
}
}
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2014-2022 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
public enum StreamUtils
{
;
public static ArrayList<String> readAllLines(InputStream input)
throws IOException
{
try(BufferedReader br =
new BufferedReader(new InputStreamReader(input)))
{
ArrayList<String> lines = new ArrayList<>();
String line;
while((line = br.readLine()) != null)
lines.add(line);
return lines;
}
}
}

View File

@ -46,6 +46,7 @@
"MiningToolItemMixin",
"MouseMixin",
"MultiplayerScreenMixin",
"PackScreenMixin",
"PlayerInventoryMixin",
"PlayerSkinProviderMixin",
"PowderSnowBlockMixin",