we don't like integers we love strings
This commit is contained in:
@@ -12,7 +12,7 @@ import org.yaml.snakeyaml.Yaml;
|
|||||||
public class GiftMappingManager {
|
public class GiftMappingManager {
|
||||||
private final JavaPlugin plugin;
|
private final JavaPlugin plugin;
|
||||||
private final File mappingFile;
|
private final File mappingFile;
|
||||||
private Map<Integer, String> giftMap = new HashMap<>();
|
private Map<String, String> giftMap = new HashMap<>();
|
||||||
|
|
||||||
public GiftMappingManager(JavaPlugin plugin, String mappingUrl) {
|
public GiftMappingManager(JavaPlugin plugin, String mappingUrl) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@@ -69,18 +69,18 @@ public class GiftMappingManager {
|
|||||||
|
|
||||||
// downloadMapping is now handled by checkAndUpdateMapping
|
// downloadMapping is now handled by checkAndUpdateMapping
|
||||||
|
|
||||||
|
|
||||||
public void loadMapping() {
|
public void loadMapping() {
|
||||||
if (!mappingFile.exists()) return;
|
if (!mappingFile.exists()) return;
|
||||||
try (InputStream input = new FileInputStream(mappingFile)) {
|
try (InputStream input = new FileInputStream(mappingFile)) {
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
Map<String, Object> data = yaml.load(input);
|
Map<Object, Object> data = yaml.load(input);
|
||||||
giftMap.clear();
|
giftMap.clear();
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
for (Map.Entry<Object, Object> entry : data.entrySet()) {
|
||||||
try {
|
String key = entry.getKey().toString();
|
||||||
int id = Integer.parseInt(entry.getKey());
|
String value = entry.getValue() != null ? entry.getValue().toString() : "";
|
||||||
giftMap.put(id, String.valueOf(entry.getValue()));
|
giftMap.put(key, value);
|
||||||
} catch (NumberFormatException ignored) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -89,6 +89,6 @@ public class GiftMappingManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getGiftName(int id) {
|
public String getGiftName(int id) {
|
||||||
return giftMap.getOrDefault(id, "Unknown Gift");
|
return giftMap.getOrDefault(String.valueOf(id), "Unknown Gift");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user