|
| 1 | +package com.andrei1058.bedwars.proxy; |
| 2 | + |
| 3 | +import com.andrei1058.bedwars.proxy.arenamanager.ArenaSelectorListener; |
| 4 | +import com.andrei1058.bedwars.proxy.arenamanager.RefreshGUI; |
| 5 | +import com.andrei1058.bedwars.proxy.configuration.BedWarsConfig; |
| 6 | +import com.andrei1058.bedwars.proxy.configuration.SoundsConfig; |
| 7 | +import com.andrei1058.bedwars.proxy.database.Database; |
| 8 | +import com.andrei1058.bedwars.proxy.database.MySQL; |
| 9 | +import com.andrei1058.bedwars.proxy.database.NoDatabase; |
| 10 | +import com.andrei1058.bedwars.proxy.database.StatsCache; |
| 11 | +import com.andrei1058.bedwars.proxy.language.English; |
| 12 | +import com.andrei1058.bedwars.proxy.language.LangListeners; |
| 13 | +import com.andrei1058.bedwars.proxy.language.Language; |
| 14 | +import com.andrei1058.bedwars.proxy.socketmanager.ServerSocketTask; |
| 15 | +import com.andrei1058.spigot.versionsupport.BlockSupport; |
| 16 | +import com.andrei1058.spigot.versionsupport.ItemStackSupport; |
| 17 | +import com.andrei1058.spigot.versionsupport.MaterialSupport; |
| 18 | +import com.andrei1058.spigot.versionsupport.SoundSupport; |
| 19 | +import org.bukkit.Bukkit; |
| 20 | +import org.bukkit.event.Listener; |
| 21 | +import org.bukkit.plugin.Plugin; |
| 22 | +import org.bukkit.plugin.java.JavaPlugin; |
| 23 | + |
| 24 | +public class BedWarsProxy extends JavaPlugin { |
| 25 | + |
| 26 | + private static String defaultLanguage = "ro"; |
| 27 | + private static Plugin plugin; |
| 28 | + public static BedWarsConfig config; |
| 29 | + private static Database remoteDatabase = null; |
| 30 | + private static StatsCache statsCache; |
| 31 | + |
| 32 | + private static SoundSupport soundAdapter; |
| 33 | + private static MaterialSupport materialAdapter; |
| 34 | + private static BlockSupport blockAdapter; |
| 35 | + private static ItemStackSupport itemAdapter; |
| 36 | + |
| 37 | + @Override |
| 38 | + public void onLoad() { |
| 39 | + plugin = this; |
| 40 | + // Setup languages |
| 41 | + new English(); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public void onEnable() { |
| 46 | + soundAdapter = SoundSupport.SupportBuilder.load(); |
| 47 | + materialAdapter = MaterialSupport.SupportBuilder.load(); |
| 48 | + blockAdapter = BlockSupport.SupportBuilder.load(); |
| 49 | + itemAdapter = ItemStackSupport.SupportBuilder.load(); |
| 50 | + |
| 51 | + config = new BedWarsConfig(); |
| 52 | + if (config.getBoolean("database.enable")){ |
| 53 | + Bukkit.getScheduler().runTaskAsynchronously(this, () -> remoteDatabase = new MySQL()); |
| 54 | + } else { |
| 55 | + remoteDatabase = new NoDatabase(); |
| 56 | + } |
| 57 | + statsCache = new StatsCache(); |
| 58 | + |
| 59 | + //todo make port configurable |
| 60 | + if (!ServerSocketTask.init(25569)){ |
| 61 | + //todo could not register socket on given port |
| 62 | + } |
| 63 | + |
| 64 | + //Leave this code at the end of the enable method |
| 65 | + for (Language l : Language.getLanguages()) { |
| 66 | + Language.addDefaultMessagesCommandItems(l); |
| 67 | + } |
| 68 | + |
| 69 | + registerListeners(new LangListeners(), new RefreshGUI(), new ArenaSelectorListener()); |
| 70 | + new SoundsConfig(); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public void onDisable() { |
| 75 | + ServerSocketTask.stopTasks(); |
| 76 | + } |
| 77 | + |
| 78 | + public static String getDefaultLanguage() { |
| 79 | + return defaultLanguage; |
| 80 | + } |
| 81 | + |
| 82 | + public static Plugin getPlugin() { |
| 83 | + return plugin; |
| 84 | + } |
| 85 | + |
| 86 | + public static Database getRemoteDatabase() { |
| 87 | + return remoteDatabase; |
| 88 | + } |
| 89 | + |
| 90 | + public static StatsCache getStatsCache() { |
| 91 | + return statsCache; |
| 92 | + } |
| 93 | + |
| 94 | + public static MaterialSupport getMaterialAdapter() { |
| 95 | + return materialAdapter; |
| 96 | + } |
| 97 | + |
| 98 | + public static BlockSupport getBlockAdapter() { |
| 99 | + return blockAdapter; |
| 100 | + } |
| 101 | + |
| 102 | + public static ItemStackSupport getItemAdapter() { |
| 103 | + return itemAdapter; |
| 104 | + } |
| 105 | + |
| 106 | + public static SoundSupport getSoundAdapter() { |
| 107 | + return soundAdapter; |
| 108 | + } |
| 109 | + |
| 110 | + private static void registerListeners(Listener... listeners){ |
| 111 | + for (Listener listener : listeners){ |
| 112 | + Bukkit.getPluginManager().registerEvents(listener, getPlugin()); |
| 113 | + } |
| 114 | + } |
| 115 | +} |
0 commit comments