mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-10-02 17:47:53 +02:00
Refactor to allow items to be added after first load
This commit is contained in:
parent
303aa77901
commit
05fcb7b1aa
@ -98,8 +98,13 @@ public class FlatItemDbProvider extends ItemDbProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void resetDb() {
|
||||
primaryNames.clear();
|
||||
names.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebuild(List<String> lines) {
|
||||
public void addFrom(List<String> lines) {
|
||||
String json = lines.stream()
|
||||
.filter(line -> !line.startsWith("#"))
|
||||
.collect(Collectors.joining("\n"));
|
||||
@ -124,6 +129,12 @@ public class FlatItemDbProvider extends ItemDbProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebuild(List<String> lines) {
|
||||
resetDb();
|
||||
addFrom(lines);
|
||||
}
|
||||
|
||||
private void addAlias(String primaryName, String alias) {
|
||||
List<String> aliasList;
|
||||
|
||||
|
@ -174,13 +174,15 @@ public class LegacyItemDbProvider extends ItemDbProvider {
|
||||
return nameList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebuild(List<String> lines) {
|
||||
private void resetDb() {
|
||||
durabilities.clear();
|
||||
items.clear();
|
||||
names.clear();
|
||||
primaryNames.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFrom(List<String> lines) {
|
||||
lines.stream()
|
||||
.filter(line -> line.length() > 0 && !(line.charAt(0) == '#'))
|
||||
.map(this::parseLine)
|
||||
@ -192,6 +194,12 @@ public class LegacyItemDbProvider extends ItemDbProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebuild(List<String> lines) {
|
||||
resetDb();
|
||||
addFrom(lines);
|
||||
}
|
||||
|
||||
private ItemData parseLine(String line) {
|
||||
String itemName = null;
|
||||
int numeric = -1;
|
||||
|
@ -20,9 +20,16 @@ public abstract class ItemDbProvider implements Provider {
|
||||
private PotionMetaProvider potionMetaProvider;
|
||||
|
||||
/**
|
||||
* Rebuild the item database, using the given lines of a file.
|
||||
* Populate the item database using the given lines of data.
|
||||
*
|
||||
* @param lines The lines of the file from which the database should be built.
|
||||
* @param lines The lines of data from which the database should be populated
|
||||
*/
|
||||
public abstract void addFrom(List<String> lines);
|
||||
|
||||
/**
|
||||
* Reset the database and rebuild it from the given lines of data.
|
||||
*
|
||||
* @param lines The lines of the file from which the database should be built
|
||||
*/
|
||||
public abstract void rebuild(List<String> lines);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user