Skip to content

Commit

Permalink
Fixed critical bug with global handlers.
Browse files Browse the repository at this point in the history
They were losing all their settings between restarts.
  • Loading branch information
gravityfox committed Jan 29, 2016
1 parent 732b497 commit 380a178
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion FoxCore
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,18 @@ public synchronized void loadHandlers() {
metaSet.getString("TYPE").equalsIgnoreCase(handlerDataSet.getString("TYPE")) &&
metaSet.getInt("PRIORITY") == handlerDataSet.getInt("PRIORITY") &&
metaSet.getBoolean("ENABLED") == handlerDataSet.getBoolean("ENABLED")) {
FGManager.getInstance().addHandler(
FGFactoryManager.getInstance().createHandler(
source, handlerDataSet.getString("NAME"), handlerDataSet.getString("TYPE"),
handlerDataSet.getInt("PRIORITY"), handlerDataSet.getBoolean("ENABLED")));
IHandler handler = FGFactoryManager.getInstance().createHandler(
source,
handlerDataSet.getString("NAME"),
handlerDataSet.getString("TYPE"),
handlerDataSet.getInt("PRIORITY"),
handlerDataSet.getBoolean("ENABLED")
);
if (handler != null) {
FoxGuardMain.instance().logger().info("Loaded handler \"" + handler.getName() +
"\" of type \"" + handler.getLongTypeName() +"\"");
}
FGManager.getInstance().addHandler(handler);
} else if (FGConfigManager.getInstance().forceLoad()) {
FoxGuardMain.instance().logger().info("Mismatched database found. Attempting force load...");
if (metaSet.getString("CATEGORY").equalsIgnoreCase("region")) {
Expand Down Expand Up @@ -210,13 +218,16 @@ public synchronized void loadWorldRegions(World world) {
metaSet.getString("TYPE").equalsIgnoreCase(regionDataSet.getString("TYPE")) &&
metaSet.getString("WORLD").equals(world.getName()) &&
metaSet.getBoolean("ENABLED") == regionDataSet.getBoolean("ENABLED")) {
FGManager.getInstance().addRegion(world,
FGFactoryManager.getInstance().createRegion(
source,
regionDataSet.getString("NAME"), regionDataSet.getString("TYPE"),
regionDataSet.getBoolean("ENABLED")
)
IRegion region = FGFactoryManager.getInstance().createRegion(
source,
regionDataSet.getString("NAME"), regionDataSet.getString("TYPE"),
regionDataSet.getBoolean("ENABLED")
);
if (region != null) {
FoxGuardMain.instance().logger().info("Loaded region \"" + region.getName() +
"\" of type \"" + region.getLongTypeName() + "\"");
}
FGManager.getInstance().addRegion(world, region);
} else if (FGConfigManager.getInstance().forceLoad()) {
FoxGuardMain.instance().logger().info("Mismatched database found. Attempting force load...");
if (metaSet.getString("CATEGORY").equalsIgnoreCase("region")) {
Expand Down Expand Up @@ -642,6 +653,7 @@ public synchronized void resolveDeferredObjects() {
public synchronized void loadGlobalHandler() {
Server server = Sponge.getGame().getServer();
try {
FoxGuardMain.instance().logger().info("Loading global handler");
FGManager.getInstance().getGlobalHandler().loadFromDatabase(FoxGuardMain.instance().getDataSource(
"jdbc:h2:" + Sponge.getGame().getSavesDirectory().resolve(server.getDefaultWorldName()) + "/foxguard/handlers/" + GlobalHandler.NAME
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ public void loadFromDatabase(DataSource dataSource) throws SQLException {
try (Connection conn = dataSource.getConnection()) {
CallbackHashMap<Flag, Tristate> flagMap = new CallbackHashMap<>((key, map) -> Tristate.UNDEFINED);
try (Statement statement = conn.createStatement()) {
statement.execute("CREATE TABLE IF NOT EXISTS FLAGMAP(KEY VARCHAR (256), VALUE VARCHAR (256));" +
"DELETE FROM FLAGMAP;");
statement.execute("CREATE TABLE IF NOT EXISTS FLAGMAP(KEY VARCHAR (256), VALUE VARCHAR (256));");
try (ResultSet mapEntrySet = statement.executeQuery("SELECT * FROM FLAGMAP")) {
while (mapEntrySet.next()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ProcessResult modify(CommandSource source, String arguments) throws Comma
} else if (parse.args[0].equalsIgnoreCase("remove")) {
return remove(source, newArgs);
}
return ProcessResult.of(false, Text.of("Not a valid"));
return ProcessResult.of(false, Text.of("Not a valid handler state command!"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public ProcessResult modify(CommandSource source, String arguments) throws Comma
} else if (parse.args[0].equalsIgnoreCase("remove")) {
return remove(source, newArgs);
}
return ProcessResult.of(false, Text.of("Not a valid"));
return ProcessResult.of(false, Text.of("Not a valid region state command!"));
}

@Override
Expand Down

0 comments on commit 380a178

Please sign in to comment.