Fix for issue saving default config.

This commit is contained in:
Brianna 2019-05-23 23:28:25 -04:00
parent 7dc3b26776
commit 02e0920feb
2 changed files with 23 additions and 21 deletions

View File

@ -4,7 +4,7 @@ stages:
variables:
name: "EpicHeads"
path: "/builds/$CI_PROJECT_PATH"
version: "3.0.13"
version: "3.0.14"
build:
stage: build

View File

@ -33,6 +33,25 @@ public class SettingsManager implements Listener {
Bukkit.getPluginManager().registerEvents(this, plugin);
}
public static <K, V> void add(LinkedHashMap<K, V> map, int index, K key, V value) {
assert (map != null);
assert !map.containsKey(key);
assert (index >= 0) && (index < map.size());
int i = 0;
List<Map.Entry<K, V>> rest = new ArrayList<>();
for (Map.Entry<K, V> entry : map.entrySet()) {
if (i++ >= index) {
rest.add(entry);
}
}
map.put(key, value);
for (Map.Entry<K, V> entry : rest) {
map.remove(entry.getKey());
map.put(entry.getKey(), entry.getValue());
}
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
ItemStack clickedItem = event.getCurrentItem();
@ -294,8 +313,10 @@ public class SettingsManager implements Listener {
}
try {
if (!plugin.getDataFolder().exists())
plugin.getDataFolder().mkdir();
BufferedWriter writer =
new BufferedWriter(new FileWriter(new File(plugin.getDataFolder() + "\\config.yml")));
new BufferedWriter(new FileWriter(new File(plugin.getDataFolder() + File.separator + "config.yml")));
writer.write(config.toString());
writer.flush();
writer.close();
@ -304,23 +325,4 @@ public class SettingsManager implements Listener {
e.printStackTrace();
}
}
public static <K, V> void add(LinkedHashMap<K, V> map, int index, K key, V value) {
assert (map != null);
assert !map.containsKey(key);
assert (index >= 0) && (index < map.size());
int i = 0;
List<Map.Entry<K, V>> rest = new ArrayList<>();
for (Map.Entry<K, V> entry : map.entrySet()) {
if (i++ >= index) {
rest.add(entry);
}
}
map.put(key, value);
for (Map.Entry<K, V> entry : rest) {
map.remove(entry.getKey());
map.put(entry.getKey(), entry.getValue());
}
}
}