Remove old loading code, use inherited registerCommand()

This commit is contained in:
Norbi Peti 2020-02-16 20:28:19 +01:00
parent f19aa41205
commit 6af2ad79a7
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 7 additions and 34 deletions

View file

@ -69,13 +69,13 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
Component.registerComponent(this, new FunComponent()); Component.registerComponent(this, new FunComponent());
Component.registerComponent(this, new AppendTextComponent()); Component.registerComponent(this, new AppendTextComponent());
Component.registerComponent(this, new FormatterComponent()); Component.registerComponent(this, new FormatterComponent());
getCommand2MC().registerCommand(new DebugCommand()); registerCommand(new DebugCommand());
getCommand2MC().registerCommand(new HelpCommand()); registerCommand(new HelpCommand());
getCommand2MC().registerCommand(new HistoryCommand()); registerCommand(new HistoryCommand());
getCommand2MC().registerCommand(new InfoCommand()); registerCommand(new InfoCommand());
getCommand2MC().registerCommand(new MWikiCommand()); registerCommand(new MWikiCommand());
getCommand2MC().registerCommand(new ReloadCommand()); registerCommand(new ReloadCommand());
getCommand2MC().registerCommand(new SnapCommand()); registerCommand(new SnapCommand());
} }
public static Essentials essentials = null; public static Essentials essentials = null;

View file

@ -19,14 +19,12 @@ import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.dynmap.towny.DTBridge; import org.dynmap.towny.DTBridge;
import java.io.File;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@ -81,14 +79,10 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
var cs = getConfig().getConfig().getConfigurationSection("towncolors"); var cs = getConfig().getConfig().getConfigurationSection("towncolors");
if (cs != null) if (cs != null)
loadTC.accept(cs); loadTC.accept(cs);
else
load_old(loadTC, null); //Load old data
if (usenc) { if (usenc) {
var ncs = getConfig().getConfig().getConfigurationSection("nationcolors"); var ncs = getConfig().getConfig().getConfigurationSection("nationcolors");
if (ncs != null) if (ncs != null)
loadNC.accept(ncs); loadNC.accept(ncs);
else
load_old(null, loadNC); //Why not choose by making different args null
} }
TownColors.keySet().removeIf(t -> !TownyComponent.TU.getTownsMap().containsKey(t)); // Removes town colors for deleted/renamed towns TownColors.keySet().removeIf(t -> !TownyComponent.TU.getTownsMap().containsKey(t)); // Removes town colors for deleted/renamed towns
@ -227,25 +221,4 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
public void onPlayerJoin(TBMCPlayerJoinEvent event) { public void onPlayerJoin(TBMCPlayerJoinEvent event) {
updatePlayerColors(event.getPlayer(), event.GetPlayer().asPluginPlayer(ChatPlayer.class)); updatePlayerColors(event.getPlayer(), event.GetPlayer().asPluginPlayer(ChatPlayer.class));
} }
private static void load_old(Consumer<ConfigurationSection> loadTC,
Consumer<ConfigurationSection> loadNC) {
PluginMain.Instance.getLogger().info("Loading files...");
try {
File file = new File("TBMC/chatsettings.yml");
if (file.exists()) {
YamlConfiguration yc = new YamlConfiguration();
yc.load(file);
ConfigurationSection cs;
if (loadTC != null && (cs = yc.getConfigurationSection("towncolors")) != null)
loadTC.accept(cs);
if (loadNC != null && (cs = yc.getConfigurationSection("nationcolors")) != null)
loadNC.accept(cs);
PluginMain.Instance.getLogger().info("Loaded files!");
} else
PluginMain.Instance.getLogger().info("No files to load, first run probably.");
} catch (Exception e) {
TBMCCoreAPI.SendException("Error while loading chat files!", e);
}
}
} }