Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -14,8 +14,10 @@ import java.util.Vector;
|
||||
import com.opencsv.CSVReader;
|
||||
import com.opencsv.CSVReaderBuilder;
|
||||
import com.opencsv.CSVWriter;
|
||||
import com.opencsv.RFC4180ParserBuilder;
|
||||
|
||||
import utils.GlobalLog;
|
||||
import utils.StringUtils;
|
||||
|
||||
public class ConfigCSV
|
||||
{
|
||||
@@ -41,7 +43,7 @@ public class ConfigCSV
|
||||
return new CSVWriter(writer,
|
||||
CSVWriter.DEFAULT_SEPARATOR,
|
||||
CSVWriter.DEFAULT_QUOTE_CHARACTER,
|
||||
'\\',
|
||||
CSVWriter.DEFAULT_ESCAPE_CHARACTER,
|
||||
CSVWriter.DEFAULT_LINE_END);
|
||||
}
|
||||
|
||||
@@ -60,7 +62,7 @@ public class ConfigCSV
|
||||
}
|
||||
|
||||
Reader reader = Files.newBufferedReader(Paths.get(filepath));
|
||||
CSVReader csvReader = new CSVReaderBuilder(reader).withSkipLines(1).build();
|
||||
CSVReader csvReader = new CSVReaderBuilder(reader).withSkipLines(1).withCSVParser(new RFC4180ParserBuilder().build()).build();
|
||||
fileContents.clear();
|
||||
|
||||
// Read contents. As for the line number, we not only start counting at 1, we also skip the header.
|
||||
@@ -74,7 +76,7 @@ public class ConfigCSV
|
||||
continue;
|
||||
}
|
||||
|
||||
ConfigItem parsedLine = new ConfigItem(record[0], record[1], record[2]);
|
||||
ConfigItem parsedLine = new ConfigItem(StringUtils.unEscape(record[0]), StringUtils.unEscape(record[1]), StringUtils.unEscape(record[2]));
|
||||
fileContents.add(parsedLine);
|
||||
++line;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package core;
|
||||
|
||||
import utils.StringUtils;
|
||||
|
||||
// Everything in here must be a string type. This class does not
|
||||
// perform any parsing past naming columns, and just holds the raw data.
|
||||
public class ConfigItem
|
||||
@@ -30,7 +32,7 @@ public class ConfigItem
|
||||
|
||||
public String[] getAll()
|
||||
{
|
||||
return new String[] {type, key, value};
|
||||
return new String[] {StringUtils.reEscape(type), StringUtils.reEscape(key), StringUtils.reEscape(value) };
|
||||
}
|
||||
|
||||
public String toString()
|
||||
|
||||
@@ -26,12 +26,14 @@ public class Plugin
|
||||
public Plugin(Path filepath)
|
||||
{
|
||||
this.filepath = filepath;
|
||||
|
||||
|
||||
StringBuilder contentBuilder = new StringBuilder();
|
||||
|
||||
reRead();
|
||||
}
|
||||
|
||||
public void reRead()
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder contentBuilder = new StringBuilder();
|
||||
Stream<String> stream = Files.lines(filepath, StandardCharsets.UTF_8);
|
||||
stream.forEach(str -> contentBuilder.append(str).append("\n"));
|
||||
stream.close();
|
||||
|
||||
@@ -1,33 +1,31 @@
|
||||
package core.lua;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
import dataStructures.KittyUser;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
import utils.io.DirectoryMonitor;
|
||||
|
||||
// Reads in, handles, and manipulates plugins. Plugins are loaded in the order they appear in the folder.
|
||||
public class PluginManager
|
||||
{
|
||||
// Variables
|
||||
public final String pluginFolder;
|
||||
public ArrayList<Plugin> plugins;
|
||||
public DirectoryMonitor directoryMonitor;
|
||||
|
||||
// Constructor
|
||||
public PluginManager(String folder)
|
||||
{
|
||||
this.pluginFolder = folder;
|
||||
this.directoryMonitor = new DirectoryMonitor(folder);
|
||||
plugins = new ArrayList<Plugin>();
|
||||
|
||||
try
|
||||
{
|
||||
try (Stream<Path> paths = Files.walk(Paths.get(this.pluginFolder)))
|
||||
{
|
||||
paths.filter(Files::isRegularFile).forEach((path)->{ addPlugin(path); });
|
||||
}
|
||||
directoryMonitor.getCurrentFiles().forEach((file) -> addPlugin(file.path));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@@ -35,6 +33,43 @@ public class PluginManager
|
||||
}
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
directoryMonitor.update(
|
||||
(addedFile) ->
|
||||
{
|
||||
addPlugin(addedFile.path);
|
||||
|
||||
GlobalLog.log(LogFilter.Plugin, "Found new plugin at " + addedFile.path);
|
||||
},
|
||||
(updatedFile) ->
|
||||
{
|
||||
for(Plugin plugin : plugins)
|
||||
{
|
||||
if(plugin.filepath.toString().equalsIgnoreCase(updatedFile.path.toString()))
|
||||
{
|
||||
plugin.reRead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GlobalLog.log(LogFilter.Plugin, "A plugin was updated " + updatedFile.path);
|
||||
},
|
||||
(deletedFile) ->
|
||||
{
|
||||
for(int i = plugins.size() - 1; i >= 0; i--)
|
||||
{
|
||||
Plugin plugin = plugins.get(i);
|
||||
|
||||
if(plugin.filepath.toString().equalsIgnoreCase(deletedFile.path.toString()))
|
||||
plugins.remove(i);
|
||||
}
|
||||
|
||||
GlobalLog.log(LogFilter.Plugin, "Plugin deleted at " + deletedFile.path);
|
||||
});
|
||||
}
|
||||
|
||||
// Registers a plugin based on the path
|
||||
public void addPlugin(Path path)
|
||||
{
|
||||
plugins.add(new Plugin(path));
|
||||
@@ -66,6 +101,8 @@ public class PluginManager
|
||||
public void printAll()
|
||||
{
|
||||
for(int i = 0; i < plugins.size(); ++i)
|
||||
{
|
||||
PluginLog.log(plugins.get(i).contents.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user