mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-03 14:38:56 +00:00
UUID used over integer, no generation
This commit is contained in:
1 parent
271648712d
commit
d1a46ba2e0
1 file changed
+19
-7
@@ -21,11 +21,13 @@ import java.nio.file.StandardCopyOption;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class WarData
|
public class WarData
|
||||||
@@ -80,7 +82,7 @@ public class WarData
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for(File file : warsFiles) {
|
for(File file : warsFiles) {
|
||||||
this.warsData.add(i, new Pair(YamlConfiguration.loadConfiguration(file), file));
|
this.warsData.add(i, new Pair(YamlConfiguration.loadConfiguration(file), file));
|
||||||
//template
|
//template, may not be needed but eh ill let this work for now
|
||||||
final InputStream defaultStream = this.plugin.getResource("warstemplate.yml");
|
final InputStream defaultStream = this.plugin.getResource("warstemplate.yml");
|
||||||
if (defaultStream != null) {
|
if (defaultStream != null) {
|
||||||
final YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration((Reader)new InputStreamReader(defaultStream));
|
final YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration((Reader)new InputStreamReader(defaultStream));
|
||||||
@@ -91,21 +93,22 @@ public class WarData
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public FileConfiguration getConfig(int id) {
|
public FileConfiguration getConfig(@Nonnull UUID id) {
|
||||||
if (this.warsData.isEmpty() || this.warsData == null) {
|
if (this.warsData.isEmpty() || this.warsData == null) {
|
||||||
this.reloadConfig();
|
this.reloadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (Pair<FileConfiguration,File> file : this.warsData) {
|
for (Pair<FileConfiguration,File> file : this.warsData) {
|
||||||
if(file.fst.getInt("id") == id) {
|
UUID fileUUID = UUID.fromString(file.fst.getString("id"));
|
||||||
|
if(fileUUID.compareTo(id) == 0) {
|
||||||
return file.fst;
|
return file.fst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveConfig(int id) {
|
public void saveConfig(@Nonnull UUID id) {
|
||||||
if (this.warsData.isEmpty() || this.warsData == null) {
|
if (this.warsData.isEmpty() || this.warsData == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -113,7 +116,8 @@ public class WarData
|
|||||||
FileConfiguration toSave = null;
|
FileConfiguration toSave = null;
|
||||||
|
|
||||||
for (int i = 0; i < warsData.size(); i++) {
|
for (int i = 0; i < warsData.size(); i++) {
|
||||||
if (warsData.get(i).fst.getInt("id") == id) {
|
UUID fileUUID = UUID.fromString(warsData.get(i).fst.getString("id"));
|
||||||
|
if (fileUUID.compareTo(id) == 0) {
|
||||||
try {
|
try {
|
||||||
warsData.get(i).fst.save(warsData.get(i).snd);
|
warsData.get(i).fst.save(warsData.get(i).snd);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -129,13 +133,14 @@ public class WarData
|
|||||||
* Also removes the war from the data list
|
* Also removes the war from the data list
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
public void archiveWar(int id) {
|
public void archiveWar(@Nonnull UUID id) {
|
||||||
if (this.warsData.isEmpty() || this.warsData == null) {
|
if (this.warsData.isEmpty() || this.warsData == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < warsData.size(); i++) {
|
for (int i = 0; i < warsData.size(); i++) {
|
||||||
if (warsData.get(i).fst.getInt("id") == id) {
|
UUID fileUUID = UUID.fromString(warsData.get(i).fst.getString("id"));
|
||||||
|
if (fileUUID.compareTo(id) == 0) {
|
||||||
try {
|
try {
|
||||||
Path archive = Paths.get(this.plugin.getDataFolder().toString() + "/wars/archive/" + warsData.get(i).snd.getName() + ".old");
|
Path archive = Paths.get(this.plugin.getDataFolder().toString() + "/wars/archive/" + warsData.get(i).snd.getName() + ".old");
|
||||||
Files.copy(warsData.get(i).snd.toPath(), archive, StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(warsData.get(i).snd.toPath(), archive, StandardCopyOption.REPLACE_EXISTING);
|
||||||
@@ -149,6 +154,10 @@ public class WarData
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grab actual config for war file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public FileConfiguration getConfigConfig() {
|
public FileConfiguration getConfigConfig() {
|
||||||
if (this.warsData.isEmpty() || this.warsData == null) {
|
if (this.warsData.isEmpty() || this.warsData == null) {
|
||||||
this.reloadConfig();
|
this.reloadConfig();
|
||||||
@@ -157,6 +166,9 @@ public class WarData
|
|||||||
return this.configConfig;
|
return this.configConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save actual config for war file
|
||||||
|
*/
|
||||||
public void saveConfigConfig() {
|
public void saveConfigConfig() {
|
||||||
if (this.configConfig == null || this.configFile == null) {
|
if (this.configConfig == null || this.configFile == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user