Skip to content

Commit

Permalink
Make a config reload on init try twice if there is an IOError + fix f…
Browse files Browse the repository at this point in the history
…or bukkit: don't propagate exceptions, they cause the plugin to be "unloaded", meaning everyone can log in.

Signed-off-by: Dries007 <admin@dries007.net>
  • Loading branch information
dries007 committed Feb 20, 2019
1 parent f54cb36 commit 81a3726
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
34 changes: 17 additions & 17 deletions Bukkit/src/main/java/net/dries007/mclink/MCLink.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/*
* Copyright (c) 2017 - 2018 Dries007. All rights reserved
* Copyright (c) 2017 - 2019 Dries007. All rights reserved
*/

package net.dries007.mclink;

import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableCollection;
import net.dries007.mclink.api.Authentication;
import net.dries007.mclink.binding.FormatCode;
Expand Down Expand Up @@ -83,28 +82,29 @@ private Player getPlayerFromEntity(org.bukkit.entity.Player player)
@Override
public void onEnable()
{
getLogger().setLevel(Level.FINEST);

common.setModVersion(getDescription().getVersion());
common.setMcVersion(Bukkit.getVersion());
common.setBranding(Bukkit.getName() + "v" + Bukkit.getBukkitVersion());
common.setLogger(new JavaLogger(getLogger()));
common.setConfig(new BukkitConfig(this));
common.setSide(MCLinkCommon.Side.SERVER);

try
{
getLogger().setLevel(Level.FINEST);

common.setModVersion(getDescription().getVersion());
common.setMcVersion(Bukkit.getVersion());
common.setBranding(Bukkit.getName() + "v" + Bukkit.getBukkitVersion());
common.setLogger(new JavaLogger(getLogger()));
common.setConfig(new BukkitConfig(this));
common.setSide(MCLinkCommon.Side.SERVER);

common.init();

Bukkit.getServer().getPluginManager().registerEvents(this, this);
common.registerCommands(e -> getCommand(e.getName()).setExecutor(new CommandWrapper(this, common, e)));

common.getLogger().info("Enabled");
}
catch (Exception e)
{
Throwables.propagate(e);
common.getLogger().error("WARNING! Something went wrong initializing... People won't be able to join.");
common.getLogger().catching(e);
}

Bukkit.getServer().getPluginManager().registerEvents(this, this);
common.registerCommands(e -> getCommand(e.getName()).setExecutor(new CommandWrapper(this, common, e)));

common.getLogger().info("Enabled");
}

@Override
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/net/dries007/mclink/common/MCLinkCommon.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 - 2018 Dries007. All rights reserved
* Copyright (c) 2017 - 2019 Dries007. All rights reserved
*/

package net.dries007.mclink.common;
Expand Down Expand Up @@ -62,7 +62,15 @@ public void init() throws IConfig.ConfigException, IOException, APIException
logger.warn("");
}

String warnings = config.reload();
String warnings;
try
{
warnings = config.reload();
}
catch (IOException e)
{
warnings = config.reload();
}
if (!Strings.isNullOrEmpty(warnings)) logger.warn(warnings);
}

Expand Down

0 comments on commit 81a3726

Please sign in to comment.