Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Alex
2019-07-03 03:28:36 -04:00
9 changed files with 76 additions and 38 deletions
+1 -1
View File
@@ -185,7 +185,7 @@
"Localized Strings","LeaderboardInfo","Shows you the 10 users with the most beans on the server" "Localized Strings","LeaderboardInfo","Shows you the 10 users with the most beans on the server"
"Localized Strings","LeaderboardTitle","Server Leaderboard" "Localized Strings","LeaderboardTitle","Server Leaderboard"
"Localized Strings","MapHeight","" "Localized Strings","MapHeight",""
"Localized Strings","MapInfo","Generates a map! You can pass additional information if you want with the flags `-s<seed>`. If one of the fields isn't provided, its default will be used. Note that adjusting the width and height impacts the map outcomes.nn**Defaults**nDefault Seed: Random,nDefault Width: 35(max %s),nDefault Height: 25(max %s)nn**Key**nLand: ~nMountain: nBeach: " "Localized Strings","MapInfo","Generates a map! You can pass additional information if you want with the flags `-s<seed>`. If one of the fields isn't provided, its default will be used. Note that adjusting the width and height impacts the map outcomes.\n\n**Defaults**\nDefault Seed: Random,\nDefault Width: 35(max %s),\nDefault Height: 25(max %s)\n\n**Key**\nLand: ~\nMountain: \u25B2\nBeach: =\nTrees: \u00A5\nVolcano: #"
"Localized Strings","MapInvalid","Invalid arguments provided!" "Localized Strings","MapInvalid","Invalid arguments provided!"
"Localized Strings","MapSeed","Seed" "Localized Strings","MapSeed","Seed"
"Localized Strings","MapVersion","Using mapgen v0.1" "Localized Strings","MapVersion","Using mapgen v0.1"
1 Type Key Value
185 Localized Strings LeaderboardInfo Shows you the 10 users with the most beans on the server
186 Localized Strings LeaderboardTitle Server Leaderboard
187 Localized Strings MapHeight
188 Localized Strings MapInfo Generates a map! You can pass additional information if you want with the flags `-s<seed>`. If one of the fields isn't provided, its default will be used. Note that adjusting the width and height impacts the map outcomes.nn**Defaults**nDefault Seed: Random,nDefault Width: 35(max %s),nDefault Height: 25(max %s)nn**Key**nLand: ~nMountain: ▲nBeach: Generates a map! You can pass additional information if you want with the flags `-s<seed>`. If one of the fields isn't provided, its default will be used. Note that adjusting the width and height impacts the map outcomes.\n\n**Defaults**\nDefault Seed: Random,\nDefault Width: 35(max %s),\nDefault Height: 25(max %s)\n\n**Key**\nLand: ~\nMountain: \u25B2\nBeach: =\nTrees: \u00A5\nVolcano: #
189 Localized Strings MapInvalid Invalid arguments provided!
190 Localized Strings MapSeed Seed
191 Localized Strings MapVersion Using mapgen v0.1
+1
View File
@@ -8,6 +8,7 @@ function plugin(message, user)
hours = ((timedif / (60*60)) % 24); hours = ((timedif / (60*60)) % 24);
mins = ((timedif / (60)) % 60); mins = ((timedif / (60)) % 60);
secs = timedif % 60; secs = timedif % 60;
return "*GASP!!!* \n" .. user.name .. " said **THE** word! It's been " .. round(days) .. " days, " .. round(hours) .. " hours, " .. round(mins) .. " minutes, and " .. round(secs) .. " seconds since the last time!"; return "*GASP!!!* \n" .. user.name .. " said **THE** word! It's been " .. round(days) .. " days, " .. round(hours) .. " hours, " .. round(mins) .. " minutes, and " .. round(secs) .. " seconds since the last time!";
end end
+5 -3
View File
@@ -14,8 +14,10 @@ import java.util.Vector;
import com.opencsv.CSVReader; import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder; import com.opencsv.CSVReaderBuilder;
import com.opencsv.CSVWriter; import com.opencsv.CSVWriter;
import com.opencsv.RFC4180ParserBuilder;
import utils.GlobalLog; import utils.GlobalLog;
import utils.StringUtils;
public class ConfigCSV public class ConfigCSV
{ {
@@ -41,7 +43,7 @@ public class ConfigCSV
return new CSVWriter(writer, return new CSVWriter(writer,
CSVWriter.DEFAULT_SEPARATOR, CSVWriter.DEFAULT_SEPARATOR,
CSVWriter.DEFAULT_QUOTE_CHARACTER, CSVWriter.DEFAULT_QUOTE_CHARACTER,
'\\', CSVWriter.DEFAULT_ESCAPE_CHARACTER,
CSVWriter.DEFAULT_LINE_END); CSVWriter.DEFAULT_LINE_END);
} }
@@ -60,7 +62,7 @@ public class ConfigCSV
} }
Reader reader = Files.newBufferedReader(Paths.get(filepath)); 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(); fileContents.clear();
// Read contents. As for the line number, we not only start counting at 1, we also skip the header. // 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; 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); fileContents.add(parsedLine);
++line; ++line;
} }
+3 -1
View File
@@ -1,5 +1,7 @@
package core; package core;
import utils.StringUtils;
// Everything in here must be a string type. This class does not // Everything in here must be a string type. This class does not
// perform any parsing past naming columns, and just holds the raw data. // perform any parsing past naming columns, and just holds the raw data.
public class ConfigItem public class ConfigItem
@@ -30,7 +32,7 @@ public class ConfigItem
public String[] getAll() public String[] getAll()
{ {
return new String[] {type, key, value}; return new String[] {StringUtils.reEscape(type), StringUtils.reEscape(key), StringUtils.reEscape(value) };
} }
public String toString() public String toString()
+5 -3
View File
@@ -26,12 +26,14 @@ public class Plugin
public Plugin(Path filepath) public Plugin(Path filepath)
{ {
this.filepath = filepath; this.filepath = filepath;
reRead();
}
public void reRead()
StringBuilder contentBuilder = new StringBuilder(); {
try try
{ {
StringBuilder contentBuilder = new StringBuilder();
Stream<String> stream = Files.lines(filepath, StandardCharsets.UTF_8); Stream<String> stream = Files.lines(filepath, StandardCharsets.UTF_8);
stream.forEach(str -> contentBuilder.append(str).append("\n")); stream.forEach(str -> contentBuilder.append(str).append("\n"));
stream.close(); stream.close();
+46 -9
View File
@@ -1,33 +1,31 @@
package core.lua; package core.lua;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import dataStructures.KittyUser; 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. // Reads in, handles, and manipulates plugins. Plugins are loaded in the order they appear in the folder.
public class PluginManager public class PluginManager
{ {
// Variables // Variables
public final String pluginFolder;
public ArrayList<Plugin> plugins; public ArrayList<Plugin> plugins;
public DirectoryMonitor directoryMonitor;
// Constructor // Constructor
public PluginManager(String folder) public PluginManager(String folder)
{ {
this.pluginFolder = folder; this.directoryMonitor = new DirectoryMonitor(folder);
plugins = new ArrayList<Plugin>(); plugins = new ArrayList<Plugin>();
try try
{ {
try (Stream<Path> paths = Files.walk(Paths.get(this.pluginFolder))) directoryMonitor.getCurrentFiles().forEach((file) -> addPlugin(file.path));
{
paths.filter(Files::isRegularFile).forEach((path)->{ addPlugin(path); });
}
} }
catch(Exception e) 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) public void addPlugin(Path path)
{ {
plugins.add(new Plugin(path)); plugins.add(new Plugin(path));
@@ -66,6 +101,8 @@ public class PluginManager
public void printAll() public void printAll()
{ {
for(int i = 0; i < plugins.size(); ++i) for(int i = 0; i < plugins.size(); ++i)
{
PluginLog.log(plugins.get(i).contents.toString()); PluginLog.log(plugins.get(i).contents.toString());
} }
} }
}
+4 -2
View File
@@ -86,7 +86,8 @@ public class Main extends ListenerAdapter
RPManager.instance.addLine(channel, user, input); RPManager.instance.addLine(channel, user, input);
// Run any pre-emptive upkeep we need to // Run any pre-emptive upkeep we need to
Superintendent.perCommandUpkeepPre(); if(!Superintendent.perCommandUpkeepPre(pluginManager))
return;
// Attempt to spin up a command. If the command doesn't exist. // Attempt to spin up a command. If the command doesn't exist.
// Run plugins right before invoking the commands but after all other setup. // Run plugins right before invoking the commands but after all other setup.
@@ -111,6 +112,7 @@ public class Main extends ListenerAdapter
} }
// Run any upkeep in post we need to // Run any upkeep in post we need to
Superintendent.perCommandUpkeepPost(kittyCore, databaseManager); if(!Superintendent.perCommandUpkeepPost(kittyCore, databaseManager))
return;
} }
} }
+4 -1
View File
@@ -6,6 +6,7 @@ import core.Config;
import core.DatabaseManager; import core.DatabaseManager;
import core.RPManager; import core.RPManager;
import core.Stats; import core.Stats;
import core.lua.PluginManager;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyCore; import dataStructures.KittyCore;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
@@ -71,11 +72,13 @@ public class Superintendent
// Only called once per command. Good for lazily updating. // Only called once per command. Good for lazily updating.
// Happens just before the command / plugin runs. // Happens just before the command / plugin runs.
public static boolean perCommandUpkeepPre() public static boolean perCommandUpkeepPre(PluginManager pluginManager)
{ {
// Upkeep the config file monitoring // Upkeep the config file monitoring
Config.instance.upkeep(); Config.instance.upkeep();
pluginManager.update();
// Return if we succeeded or not. At this time, we always succeed.
return true; return true;
} }
+5 -16
View File
@@ -1,29 +1,18 @@
package utils; package utils;
import org.apache.commons.lang3.StringEscapeUtils;
@SuppressWarnings("deprecation")
public class StringUtils public class StringUtils
{ {
public static String unEscape(String str) public static String unEscape(String str)
{ {
str = str.replaceAll("\\\\b", "\b"); return StringEscapeUtils.unescapeJava(str);
str = str.replaceAll("\\\\n", "\n");
str = str.replaceAll("\\\\t", "\t");
str = str.replaceAll("\\\\r", "\r");
str = str.replaceAll("\\\\f", "\f");
str = str.replaceAll("\\\\\"", "\"");
str = str.replaceAll("\\\\\\\\\\\\", "\\\\");
return str;
} }
public static String reEscape(String str) public static String reEscape(String str)
{ {
str = str.replaceAll("\\\b", "\\\\\\b"); return StringEscapeUtils.escapeJava(str);
str = str.replaceAll("\\\n", "\\\\\\n");
str = str.replaceAll("\\\t", "\\\\\\t");
str = str.replaceAll("\\\r", "\\\\\\r");
str = str.replaceAll("\\\f", "\\\\\\f");
return str;
} }
// Finds first whitespace in the string // Finds first whitespace in the string