|
| 1 | +package org.mineacademy.boss; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.bukkit.entity.Player; |
| 7 | +import org.mineacademy.boss.api.BossSkillRegistry; |
| 8 | +import org.mineacademy.boss.hook.BossHeroesHook; |
| 9 | +import org.mineacademy.boss.hook.GriefPreventionHook; |
| 10 | +import org.mineacademy.boss.hook.SilkSpawnersHook; |
| 11 | +import org.mineacademy.boss.hook.StackMobListener; |
| 12 | +import org.mineacademy.boss.listener.BossSpawnerListener; |
| 13 | +import org.mineacademy.boss.listener.EntityListener; |
| 14 | +import org.mineacademy.boss.listener.FreezeListener; |
| 15 | +import org.mineacademy.boss.listener.PlayerListener; |
| 16 | +import org.mineacademy.boss.listener.SpawningListener; |
| 17 | +import org.mineacademy.boss.menu.MenuToolsBoss; |
| 18 | +import org.mineacademy.boss.model.BossCommandGroup; |
| 19 | +import org.mineacademy.boss.model.BossManager; |
| 20 | +import org.mineacademy.boss.model.BossPlayer; |
| 21 | +import org.mineacademy.boss.model.task.BossKeepTask; |
| 22 | +import org.mineacademy.boss.model.task.BossRetargetTask; |
| 23 | +import org.mineacademy.boss.model.task.BossSkillTask; |
| 24 | +import org.mineacademy.boss.model.task.BossTimedSpawnTask; |
| 25 | +import org.mineacademy.boss.settings.Localization; |
| 26 | +import org.mineacademy.boss.settings.Settings; |
| 27 | +import org.mineacademy.boss.storage.SimplePlayerData; |
| 28 | +import org.mineacademy.boss.storage.SimpleSpawnerData; |
| 29 | +import org.mineacademy.boss.storage.SimpleTagData; |
| 30 | +import org.mineacademy.fo.Common; |
| 31 | +import org.mineacademy.fo.MinecraftVersion.V; |
| 32 | +import org.mineacademy.fo.Valid; |
| 33 | +import org.mineacademy.fo.collection.StrictMap; |
| 34 | +import org.mineacademy.fo.command.SimpleCommandGroup; |
| 35 | +import org.mineacademy.fo.model.SpigotUpdater; |
| 36 | +import org.mineacademy.fo.plugin.SimplePlugin; |
| 37 | +import org.mineacademy.fo.remain.Remain; |
| 38 | +import org.mineacademy.fo.settings.YamlStaticConfig; |
| 39 | + |
| 40 | +/** |
| 41 | + * The main class for the Boss plugin. |
| 42 | + */ |
| 43 | +public final class BossPlugin extends SimplePlugin { |
| 44 | + |
| 45 | + /** |
| 46 | + * Store temporary players' data until BOSS restarts. |
| 47 | + */ |
| 48 | + private static final StrictMap<String, BossPlayer> playerCache = new StrictMap<>(); |
| 49 | + |
| 50 | + /** |
| 51 | + * Class responsible for loading, saving, and creating Bosses. |
| 52 | + */ |
| 53 | + private final BossManager bossManager = new BossManager(); |
| 54 | + |
| 55 | + /** |
| 56 | + * The main /boss command, capable of handling subcommands such as /boss region. |
| 57 | + */ |
| 58 | + private final BossCommandGroup bossCommand = new BossCommandGroup(); |
| 59 | + |
| 60 | + @Override |
| 61 | + protected String[] getStartupLogo() { |
| 62 | + return new String[] { |
| 63 | + "&e______ ", |
| 64 | + "&e(____ \\ ", |
| 65 | + "&e ____) ) ___ ___ ___ ", |
| 66 | + "&e| __ ( / _ \\ /___)/___)", |
| 67 | + "&e| |__) ) |_| |___ |___ |", |
| 68 | + "&6|______/ \\___/(___/(___/ ", |
| 69 | + " " |
| 70 | + }; |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + protected void onPluginStart() { |
| 75 | + MenuToolsBoss.getInstance(); |
| 76 | + |
| 77 | + if (!Remain.hasScoreboardTags()) |
| 78 | + SimpleTagData.$(); |
| 79 | + |
| 80 | + SimplePlayerData.$(); |
| 81 | + |
| 82 | + registerEvents(new PlayerListener()); |
| 83 | + registerEvents(new EntityListener()); |
| 84 | + registerEvents(new SpawningListener()); |
| 85 | + registerEvents(new BossSpawnerListener()); |
| 86 | + registerEvents(new FreezeListener()); |
| 87 | + |
| 88 | + if (Common.doesPluginExist("Heroes")) |
| 89 | + BossHeroesHook.setEnabled(true); |
| 90 | + |
| 91 | + if (Common.doesPluginExist("GriefPrevention")) |
| 92 | + GriefPreventionHook.setEnabled(true); |
| 93 | + |
| 94 | + Common.ADD_TELL_PREFIX = true; |
| 95 | + |
| 96 | + // Delay after start because we check the world, so Multiverse must load it |
| 97 | + // first |
| 98 | + Common.runLater(SimpleSpawnerData::$); |
| 99 | + |
| 100 | + Common.runLater(10, () -> SimpleTagData.$().clear()); |
| 101 | + |
| 102 | + Common.log( |
| 103 | + " ", |
| 104 | + "Tutorial:", |
| 105 | + "&6https://github.com/kangarko/Boss/wiki", |
| 106 | + " ", |
| 107 | + "Get help:", |
| 108 | + "&6https://github.com/kangarko/Boss/issues", |
| 109 | + "&8" + Common.consoleLineSmooth()); |
| 110 | + |
| 111 | + if (Settings.TimedSpawning.ENABLED && (Common.doesPluginExistSilently("Top") || Common.doesPluginExistSilently("TopLite") || Common.doesPluginExistSilently("MassiveLag"))) |
| 112 | + Common.runLaterAsync(10, () -> Common.logFramed(false, |
| 113 | + "[Boss] Notice for Anti-Lag Plugins", |
| 114 | + " ", |
| 115 | + "Boss is a greatly optimized plugin, however timed", |
| 116 | + "spawning must use the main thread for safety.", |
| 117 | + "Depending on your settings, this may be shown", |
| 118 | + "in your Top / MassiveLag. You can ignore this.")); |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + protected void onPluginReload() { |
| 123 | + SimpleSpawnerData.$().save(); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Start the parts of the plugin that support /boss reload or /reload function. |
| 128 | + */ |
| 129 | + @Override |
| 130 | + protected void onReloadablesStart() { |
| 131 | + BossSkillRegistry.registerDefaults(); |
| 132 | + |
| 133 | + Common.runLater(() -> bossManager.loadBosses()); |
| 134 | + |
| 135 | + Common.runTimer(10, 20, new BossSkillTask()); |
| 136 | + Common.runTimer(10, Settings.Fight.Target.DELAY.getTimeTicks(), new BossRetargetTask()); |
| 137 | + |
| 138 | + if (Settings.TimedSpawning.ENABLED) |
| 139 | + Common.runTimer(Settings.TimedSpawning.DELAY.getTimeTicks(), new BossTimedSpawnTask()); |
| 140 | + |
| 141 | + if (Settings.RegionKeep.ENABLED) |
| 142 | + Common.runTimer(Settings.RegionKeep.PERIOD.getTimeTicks(), new BossKeepTask()); |
| 143 | + |
| 144 | + if (Common.doesPluginExistSilently("SilkSpawners")) |
| 145 | + registerEvents(new SilkSpawnersHook()); |
| 146 | + |
| 147 | + registerEventsIf(new StackMobListener(), Common.doesPluginExistSilently("StackMob")); |
| 148 | + } |
| 149 | + |
| 150 | + public static BossPlayer getDataFor(final Player player) { |
| 151 | + Valid.checkNotNull(player, "Player = null"); |
| 152 | + |
| 153 | + BossPlayer cache = playerCache.get(player.getName()); |
| 154 | + |
| 155 | + if (cache == null) { |
| 156 | + cache = new BossPlayer(); |
| 157 | + |
| 158 | + playerCache.put(player.getName(), cache); |
| 159 | + |
| 160 | + } |
| 161 | + |
| 162 | + return cache; |
| 163 | + } |
| 164 | + |
| 165 | + public static BossManager getBossManager() { |
| 166 | + return ((BossPlugin) SimplePlugin.getInstance()).bossManager; |
| 167 | + } |
| 168 | + |
| 169 | + @Override |
| 170 | + public List<Class<? extends YamlStaticConfig>> getSettings() { |
| 171 | + return Arrays.asList(Settings.class, Localization.class); |
| 172 | + } |
| 173 | + |
| 174 | + @Override |
| 175 | + public int getFoundedYear() { |
| 176 | + return 2017; // 17.07 |
| 177 | + } |
| 178 | + |
| 179 | + @Override |
| 180 | + public SimpleCommandGroup getMainCommand() { |
| 181 | + return bossCommand; |
| 182 | + } |
| 183 | + |
| 184 | + @Override |
| 185 | + public SpigotUpdater getUpdateCheck() { |
| 186 | + return new SpigotUpdater(46497); |
| 187 | + } |
| 188 | + |
| 189 | + @Override |
| 190 | + public V getMinimumVersion() { |
| 191 | + return V.v1_8; |
| 192 | + } |
| 193 | +} |
0 commit comments