mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-08 19:35:36 -04:00
Fixed ClassCastException
This commit is contained in:
parent
4a2ac63d25
commit
16152de39d
@ -96,7 +96,8 @@ public abstract class IAuthenticator {
|
||||
public void onLoadSettings(Map m) {
|
||||
if (m == null)
|
||||
return;
|
||||
username = (String) m.get("IAuthenticator_UserName");
|
||||
Object o = m.get("IAuthenticator_UserName");
|
||||
username = o instanceof String ? (String) o : "";
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
|
@ -64,7 +64,7 @@ public class MojangDownloadProvider extends IDownloadProvider {
|
||||
|
||||
@Override
|
||||
public String getAssetsDownloadURL() {
|
||||
return "http://resources.download.minecraft.net/";
|
||||
return "https://resources.download.minecraft.net/";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,10 +52,10 @@ import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
|
||||
import org.jackhuang.hellominecraft.lookandfeel.Theme;
|
||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.Utils;
|
||||
import org.jackhuang.hellominecraft.util.ui.DropShadowBorder;
|
||||
import org.jackhuang.hellominecraft.util.ui.TintablePanel;
|
||||
import org.jackhuang.hellominecraft.util.ui.BasicColors;
|
||||
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -168,7 +168,7 @@ public final class MainFrame extends DraggableFrame {
|
||||
|
||||
ImageIcon headerIcon = Main.getIcon("icon.png");
|
||||
this.setIconImage(headerIcon.getImage());
|
||||
headerIcon = Utils.scaleImage(headerIcon, 16, 16);
|
||||
headerIcon = SwingUtils.scaleImage(headerIcon, 16, 16);
|
||||
JLabel headerLabel = new JLabel(headerIcon);
|
||||
headerLabel.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
|
||||
header.add(headerLabel);
|
||||
@ -318,7 +318,7 @@ public final class MainFrame extends DraggableFrame {
|
||||
ImageIcon background;
|
||||
|
||||
public void loadBackground() {
|
||||
background = Utils.searchBackgroundImage(Main.getIcon(Settings.getInstance().getTheme().settings.get("Customized.MainFrame.background_image")), Settings.getInstance().getBgpath(), 800, 480);
|
||||
background = SwingUtils.searchBackgroundImage(Main.getIcon(Settings.getInstance().getTheme().settings.get("Customized.MainFrame.background_image")), Settings.getInstance().getBgpath(), 800, 480);
|
||||
if (background != null)
|
||||
if (backgroundLabel == null) {
|
||||
backgroundLabel = new JLabel(background);
|
||||
|
@ -19,19 +19,13 @@ package org.jackhuang.hellominecraft.util;
|
||||
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
import com.sun.management.OperatingSystemMXBean;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Random;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
/**
|
||||
* @author huangyuhui
|
||||
@ -52,18 +46,6 @@ public final class Utils {
|
||||
return ((URLClassLoader) Utils.class.getClassLoader()).getURLs();
|
||||
}
|
||||
|
||||
public static String[] getURLString() {
|
||||
URL[] urls = ((URLClassLoader) Utils.class.getClassLoader()).getURLs();
|
||||
String[] urlStrings = new String[urls.length];
|
||||
for (int i = 0; i < urlStrings.length; i++)
|
||||
try {
|
||||
urlStrings[i] = URLDecoder.decode(urls[i].getPath(), "UTF-8");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
HMCLog.warn("Unsupported UTF-8 encoding", ex);
|
||||
}
|
||||
return urlStrings;
|
||||
}
|
||||
|
||||
public static int getSuggestedMemorySize() {
|
||||
try {
|
||||
OperatingSystemMXBean osmb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
|
||||
@ -80,65 +62,6 @@ public final class Utils {
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), null);
|
||||
}
|
||||
|
||||
public static ImageIcon scaleImage(ImageIcon i, int x, int y) {
|
||||
return new ImageIcon(i.getImage().getScaledInstance(x, y, Image.SCALE_SMOOTH));
|
||||
}
|
||||
|
||||
public static ImageIcon searchBackgroundImage(ImageIcon init, String bgpath, int width, int height) {
|
||||
Random r = new Random();
|
||||
boolean loaded = false;
|
||||
ImageIcon background = init;
|
||||
|
||||
// bgpath
|
||||
if (StrUtils.isNotBlank(bgpath) && !loaded) {
|
||||
String[] backgroundPath = bgpath.split(";");
|
||||
if (backgroundPath.length > 0) {
|
||||
int index = r.nextInt(backgroundPath.length);
|
||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundPath[index]).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||
HMCLog.log("Prepared background image in bgpath.");
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// bgskin
|
||||
if (!loaded) {
|
||||
File backgroundImageFile = new File("bg");
|
||||
if (backgroundImageFile.exists() && backgroundImageFile.isDirectory()) {
|
||||
String[] backgroundPath = backgroundImageFile.list();
|
||||
if (backgroundPath.length > 0) {
|
||||
int index = r.nextInt(backgroundPath.length);
|
||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage("bg" + File.separator + backgroundPath[index]).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||
HMCLog.log("Prepared background image in bgskin folder.");
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// background.png
|
||||
if (!loaded) {
|
||||
File backgroundImageFile = new File("background.png");
|
||||
if (backgroundImageFile.exists()) {
|
||||
loaded = true;
|
||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundImageFile.getAbsolutePath()).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||
HMCLog.log("Prepared background image in background.png.");
|
||||
}
|
||||
}
|
||||
|
||||
// background.jpg
|
||||
if (!loaded) {
|
||||
File backgroundImageFile = new File("background.jpg");
|
||||
if (backgroundImageFile.exists()) {
|
||||
//loaded = true;
|
||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundImageFile.getAbsolutePath()).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||
HMCLog.log("Prepared background image in background.jpg.");
|
||||
}
|
||||
}
|
||||
|
||||
if (background == null)
|
||||
return init;
|
||||
return background;
|
||||
}
|
||||
|
||||
/**
|
||||
* In order to fight against the permission manager by Minecraft Forge.
|
||||
*
|
||||
|
@ -20,7 +20,8 @@ package org.jackhuang.hellominecraft.util.ui;
|
||||
import java.awt.Component;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -28,7 +29,9 @@ import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
@ -302,4 +305,63 @@ public class SwingUtils {
|
||||
else
|
||||
thisFrame.dispose();
|
||||
}
|
||||
|
||||
public static ImageIcon scaleImage(ImageIcon i, int x, int y) {
|
||||
return new ImageIcon(i.getImage().getScaledInstance(x, y, Image.SCALE_SMOOTH));
|
||||
}
|
||||
|
||||
public static ImageIcon searchBackgroundImage(ImageIcon init, String bgpath, int width, int height) {
|
||||
Random r = new Random();
|
||||
boolean loaded = false;
|
||||
ImageIcon background = init;
|
||||
|
||||
// bgpath
|
||||
if (StrUtils.isNotBlank(bgpath) && !loaded) {
|
||||
String[] backgroundPath = bgpath.split(";");
|
||||
if (backgroundPath.length > 0) {
|
||||
int index = r.nextInt(backgroundPath.length);
|
||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundPath[index]).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||
HMCLog.log("Prepared background image in bgpath.");
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// bgskin
|
||||
if (!loaded) {
|
||||
File backgroundImageFile = new File("bg");
|
||||
if (backgroundImageFile.exists() && backgroundImageFile.isDirectory()) {
|
||||
String[] backgroundPath = backgroundImageFile.list();
|
||||
if (backgroundPath.length > 0) {
|
||||
int index = r.nextInt(backgroundPath.length);
|
||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage("bg" + File.separator + backgroundPath[index]).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||
HMCLog.log("Prepared background image in bgskin folder.");
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// background.png
|
||||
if (!loaded) {
|
||||
File backgroundImageFile = new File("background.png");
|
||||
if (backgroundImageFile.exists()) {
|
||||
loaded = true;
|
||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundImageFile.getAbsolutePath()).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||
HMCLog.log("Prepared background image in background.png.");
|
||||
}
|
||||
}
|
||||
|
||||
// background.jpg
|
||||
if (!loaded) {
|
||||
File backgroundImageFile = new File("background.jpg");
|
||||
if (backgroundImageFile.exists()) {
|
||||
//loaded = true;
|
||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundImageFile.getAbsolutePath()).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||
HMCLog.log("Prepared background image in background.jpg.");
|
||||
}
|
||||
}
|
||||
|
||||
if (background == null)
|
||||
return init;
|
||||
return background;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user