YumCore/src/main/java/pw/yumc/YumCore/config/ext/RemoteConfig.java

63 lines
1.5 KiB
Java
Raw Normal View History

package pw.yumc.YumCore.config.ext;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.config.FileConfig;
/**
*
*
* @since 2016222 8:33:51
* @author
*/
public class RemoteConfig extends FileConfig {
public RemoteConfig(String url) throws MalformedURLException, IOException {
this(new URL(url));
}
public RemoteConfig(URL url) throws IOException {
super(url.openStream());
}
/**
* (null)
*
* @param url
*
* @return {@link FileConfig}
*/
public static FileConfig getConfig(String url) {
try {
return new RemoteConfig(url);
} catch (IOException e) {
Log.debug("获取远程配置文件失败!", e);
return null;
}
}
/**
* Yaml
*
* @param url
* XML
* @param tag
*
* @param def
*
* @return
*/
public static String getYamlTag(String url, String tag, String def) {
String result = def;
try {
result = getConfig(url).getString(tag);
} catch (NullPointerException e) {
// Ignore
}
return result;
}
}