mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Update pom
Former-commit-id: c05d19803b26c9f6c5770a46854c2bfe3ccbbc85 [formerly 7480e68ce2a21c285b115a65ae107a97d69b7ae1] Former-commit-id: 1c92d7f8924b1dae4d9935aafe90b7ee2be8abec
This commit is contained in:
1 parent
0ea4173c6e
commit
d86eeefc86
4 files changed
+41
-107
No files matched your search
@@ -5,7 +5,6 @@ import java.io.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
import org.maxgamer.quickshop.Util.YamlIsSucked;
|
||||
|
||||
public class Language {
|
||||
private QuickShop plugin;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.maxgamer.quickshop.Util;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
@@ -49,21 +51,21 @@ public class MsgUtil {
|
||||
messagei18n = YamlConfiguration.loadConfiguration(messageFile);
|
||||
messagei18n.options().copyDefaults(true);
|
||||
|
||||
//YamlConfiguration messagei18nYAML = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getLanguage()
|
||||
// .getFile("en", "messages")));
|
||||
//messagei18n.setDefaults(messagei18nYAML);
|
||||
|
||||
//Convert %YAML 1.2 to %YAML 1.0
|
||||
|
||||
String messagei18nYaml2 = new String(Util
|
||||
.inputStream2ByteArray(plugin.getLanguage().getFile(plugin.getConfig().getString("language"), "messages")));
|
||||
YamlIsSucked yamlIsSucked = new YamlIsSucked();
|
||||
String messagei18nJson = yamlIsSucked.readYaml2ToJson(messagei18nYaml2);
|
||||
String messagei18nYaml1 = yamlIsSucked.writeJson2Yaml1(messagei18nJson);
|
||||
InputStream inputStream = new ByteArrayInputStream(messagei18nYaml1.getBytes());
|
||||
YamlConfiguration messagei18nYAML = YamlConfiguration.loadConfiguration(new InputStreamReader(inputStream));
|
||||
YamlConfiguration messagei18nYAML = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getLanguage()
|
||||
.getFile(plugin.getConfig().getString("language"), "messages")));
|
||||
messagei18n.setDefaults(messagei18nYAML);
|
||||
|
||||
// //Convert %YAML 1.2 to %YAML 1.0
|
||||
//
|
||||
// String messagei18nYaml2 = new String(Util
|
||||
// .inputStream2ByteArray(plugin.getLanguage().getFile(plugin.getConfig().getString("language"), "messages")));
|
||||
// YamlIsSucked yamlIsSucked = new YamlIsSucked();
|
||||
// String messagei18nJson = yamlIsSucked.readYaml2ToJson(messagei18nYaml2);
|
||||
// String messagei18nYaml1 = yamlIsSucked.writeJson2Yaml1(messagei18nJson);
|
||||
// InputStream inputStream = new ByteArrayInputStream(messagei18nYaml1.getBytes());
|
||||
// YamlConfiguration messagei18nYAML = YamlConfiguration.loadConfiguration(new InputStreamReader(inputStream));
|
||||
// messagei18n.setDefaults(messagei18nYAML);
|
||||
|
||||
if (messagei18n.getInt("language-version") == 0) {
|
||||
messagei18n.set("language-version", 1);
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
package org.maxgamer.quickshop.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import com.google.gson.Gson;
|
||||
import org.snakeyaml.engine.v1.api.Load;
|
||||
import org.snakeyaml.engine.v1.api.LoadSettings;
|
||||
import org.snakeyaml.engine.v1.api.LoadSettingsBuilder;
|
||||
|
||||
/**
|
||||
* A Util class to convert YAML1.2 to YAML1.0
|
||||
*/
|
||||
public class YamlIsSucked {
|
||||
/**
|
||||
* Convert YAML1.2 config to Json
|
||||
*
|
||||
* @param yaml2 Target yaml config
|
||||
* @return Json string
|
||||
*/
|
||||
public String readYaml2ToJson(String yaml2) {
|
||||
// try{
|
||||
// JsonNode jsonNodeTree = new ObjectMapper(new YAMLFactory()).readTree(yaml2);
|
||||
// return jsonNodeTree.asText();
|
||||
// }catch (IOException e){
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
try {
|
||||
LoadSettings settings = new LoadSettingsBuilder().build();
|
||||
Load load = new Load(settings);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) load.loadFromString("a: 1\nb: 2\nc:\n - aaa\n - bbb");
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(map);
|
||||
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//
|
||||
// // Load load = new Load(settings);
|
||||
// // @SuppressWarnings("unchecked")
|
||||
// // Map<String, Object> map = (Map<String, Object>) load.loadFromString(yaml2);
|
||||
// Gson gson = new Gson();
|
||||
// return gson.toJson(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Json to YAML1.0 config
|
||||
*
|
||||
* @param json Target Json string
|
||||
* @return YAML 1.0 config
|
||||
*/
|
||||
public String writeJson2Yaml1(String json) {
|
||||
try {
|
||||
JsonNode jsonNodeTree = new ObjectMapper().readTree(json);
|
||||
return new YAMLMapper().writeValueAsString(jsonNodeTree);
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user