diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java index 7624ef32a..db58fa6f7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java @@ -195,29 +195,20 @@ public class Research implements Keyed { PlayerProfile.get(p, profile -> { if (!profile.hasUnlocked(this)) { - Runnable runnable = () -> { - profile.setResearched(this, true); - SlimefunPlugin.getLocal().sendMessage(p, "messages.unlocked", true, msg -> msg.replace(PLACEHOLDER_RESEARCH, getName(p))); - - if (SlimefunPlugin.getRegistry().isResearchFireworkEnabled() && SlimefunGuideSettings.hasFireworksEnabled(p)) { - FireworkUtils.launchRandom(p, 1); - } - }; - Slimefun.runSync(() -> { ResearchUnlockEvent event = new ResearchUnlockEvent(p, this); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { if (instant) { - runnable.run(); + finishResearch(p, profile); } else if (SlimefunPlugin.getRegistry().getCurrentlyResearchingPlayers().add(p.getUniqueId())) { SlimefunPlugin.getLocal().sendMessage(p, "messages.research.start", true, msg -> msg.replace(PLACEHOLDER_RESEARCH, getName(p))); playResearchAnimation(p); Slimefun.runSync(() -> { - runnable.run(); + finishResearch(p, profile); SlimefunPlugin.getRegistry().getCurrentlyResearchingPlayers().remove(p.getUniqueId()); }, (RESEARCH_PROGRESS.length + 1) * 20L); } @@ -227,6 +218,15 @@ public class Research implements Keyed { }); } + private void finishResearch(Player p, PlayerProfile profile) { + profile.setResearched(this, true); + SlimefunPlugin.getLocal().sendMessage(p, "messages.unlocked", true, msg -> msg.replace(PLACEHOLDER_RESEARCH, getName(p))); + + if (SlimefunPlugin.getRegistry().isResearchFireworkEnabled() && SlimefunGuideSettings.hasFireworksEnabled(p)) { + FireworkUtils.launchRandom(p, 1); + } + } + private void playResearchAnimation(Player p) { for (int i = 1; i < RESEARCH_PROGRESS.length + 1; i++) { int j = i; @@ -245,7 +245,6 @@ public class Research implements Keyed { SlimefunPlugin.getResearchCfg().setDefaultValue("enable-researching", true); String path = key.getNamespace() + '.' + key.getKey(); - migrate(id, path); if (SlimefunPlugin.getResearchCfg().contains(path + ".enabled") && !SlimefunPlugin.getResearchCfg().getBoolean(path + ".enabled")) { for (SlimefunItem item : new ArrayList<>(items)) { @@ -267,19 +266,6 @@ public class Research implements Keyed { SlimefunPlugin.getRegistry().getResearches().add(this); } - // Temporary migration method from ids to Namespaced Keys. - private void migrate(int id, String path) { - if (SlimefunPlugin.getResearchCfg().contains(id + ".enabled")) { - SlimefunPlugin.getResearchCfg().setValue(path + ".enabled", SlimefunPlugin.getResearchCfg().getBoolean(id + ".enabled")); - } - - if (SlimefunPlugin.getResearchCfg().contains(id + ".cost")) { - SlimefunPlugin.getResearchCfg().setValue(path + ".cost", SlimefunPlugin.getResearchCfg().getInt(id + ".cost")); - } - - SlimefunPlugin.getResearchCfg().setValue(String.valueOf(id), null); - } - /** * Attempts to get a {@link Research} with the given ID. *