|
1 | | -package com.miraclem4n.mchat; |
2 | | - |
3 | | -import com.miraclem4n.mchat.api.API; |
4 | | -import com.miraclem4n.mchat.api.Parser; |
5 | | -import com.miraclem4n.mchat.api.Writer; |
6 | | -import com.miraclem4n.mchat.commands.InfoAlterCommand; |
7 | | -import com.miraclem4n.mchat.commands.MChatCommand; |
8 | | -import com.miraclem4n.mchat.commands.MeCommand; |
9 | | -import com.miraclem4n.mchat.configs.YmlManager; |
10 | | -import com.miraclem4n.mchat.configs.YmlType; |
11 | | -import com.miraclem4n.mchat.configs.config.ConfigType; |
12 | | -import com.miraclem4n.mchat.events.ChatListener; |
13 | | -import com.miraclem4n.mchat.events.CommandListener; |
14 | | -import com.miraclem4n.mchat.events.PlayerListener; |
15 | | -import com.miraclem4n.mchat.types.InfoType; |
16 | | -import com.miraclem4n.mchat.updater.Updater; |
17 | | -import com.miraclem4n.mchat.util.MessageUtil; |
18 | | -import com.miraclem4n.mchat.util.Timer; |
19 | | -import org.bukkit.Bukkit; |
20 | | -import org.bukkit.command.CommandExecutor; |
21 | | -import org.bukkit.entity.Player; |
22 | | -import org.bukkit.plugin.Plugin; |
23 | | -import org.bukkit.plugin.PluginDescriptionFile; |
24 | | -import org.bukkit.plugin.PluginManager; |
25 | | -import org.bukkit.plugin.java.JavaPlugin; |
26 | | -import org.bukkit.scheduler.BukkitRunnable; |
27 | | - |
28 | | -public class MChat extends JavaPlugin { |
29 | | - // Default Plugin Data |
30 | | - public PluginManager pm; |
31 | | - public PluginDescriptionFile pdfFile; |
32 | | - |
33 | | - public Boolean update = false; |
34 | | - |
35 | | - public void onEnable() { |
36 | | - // Initialize and Start the Timer |
37 | | - Timer timer = new Timer(); |
38 | | - |
39 | | - // Initialize Plugin Data |
40 | | - pm = getServer().getPluginManager(); |
41 | | - pdfFile = getDescription(); |
42 | | - |
43 | | - // First we kill EssentialsChat |
44 | | - killEss(); |
45 | | - |
46 | | - // Initialize Metrics |
47 | | - /*getServer().getScheduler().runTaskLater(this, new BukkitRunnable(){ |
48 | | - @Override |
49 | | - public void run() { |
50 | | - try { |
51 | | - Metrics metrics = new Metrics(Bukkit.getPluginManager().getPlugin("MChat")); |
52 | | - metrics.findCustomData(); |
53 | | - metrics.start(); |
54 | | - } catch (IOException ignored) {} |
55 | | - } |
56 | | - |
57 | | - }, 200);*/ |
58 | | - |
59 | | - // Load Yml |
60 | | - YmlManager.initialize(); |
61 | | - |
62 | | - // Initialize Classes |
63 | | - initializeClasses(); |
64 | | - |
65 | | - // Register Events |
66 | | - registerEvents(); |
67 | | - |
68 | | - // Setup Commands |
69 | | - setupCommands(); |
70 | | - |
71 | | - // Add All Players To Info.yml |
72 | | - if (ConfigType.INFO_ADD_NEW_PLAYERS.getBoolean()) { |
73 | | - for (Player players : getServer().getOnlinePlayers()) { |
74 | | - if (YmlManager.getYml(YmlType.INFO_YML).getConfig().get("users." + players.getName()) == null) { |
75 | | - Writer.addBase(players.getName(), ConfigType.INFO_DEFAULT_GROUP.getString(), false); |
76 | | - } |
77 | | - } |
78 | | - } |
79 | | - |
80 | | - // Updater |
81 | | - if (ConfigType.MCHAT_UPDATE_CHECK.getBoolean()) { |
82 | | - getServer().getScheduler().runTaskLater(this, new BukkitRunnable(){ |
83 | | - @Override |
84 | | - public void run() { |
85 | | - MChat mchat = (MChat) Bukkit.getPluginManager().getPlugin("MChat"); |
86 | | - Updater updater = new Updater(mchat, "mchat", mchat.getFile(), Updater.UpdateType.NO_DOWNLOAD, false); |
87 | | - mchat.update = updater.getResult() == Updater.UpdateResult.UPDATE_AVAILABLE; |
88 | | - } |
89 | | - |
90 | | - }, 50); |
91 | | - } else { |
92 | | - MessageUtil.logFormatted("Update Check has been Disabled."); |
93 | | - MessageUtil.logFormatted("To Enable please change ''mchat.updateCheck''"); |
94 | | - MessageUtil.logFormatted("in config.yml to true!!"); |
95 | | - } |
96 | | - |
97 | | - // Stop the Timer |
98 | | - timer.stop(); |
99 | | - |
100 | | - // Calculate Startup Timer |
101 | | - long diff = timer.difference(); |
102 | | - |
103 | | - MessageUtil.log("[" + pdfFile.getName() + "] " + pdfFile.getName() + " v" + pdfFile.getVersion() + " is enabled! [" + diff + "ms]"); |
104 | | - } |
105 | | - |
106 | | - public void onDisable() { |
107 | | - // Initialize and Start the Timer |
108 | | - Timer timer = new Timer(); |
109 | | - |
110 | | - getServer().getScheduler().cancelTasks(this); |
111 | | - |
112 | | - // Unload Yml |
113 | | - YmlManager.unload(); |
114 | | - |
115 | | - // Stop the Timer |
116 | | - timer.stop(); |
117 | | - |
118 | | - // Calculate Shutdown Timer |
119 | | - long diff = timer.difference(); |
120 | | - |
121 | | - MessageUtil.log("[" + pdfFile.getName() + "] " + pdfFile.getName() + " v" + pdfFile.getVersion() + " is disabled! [" + diff + "ms]"); |
122 | | - } |
123 | | - |
124 | | - private void registerEvents() { |
125 | | - if (!ConfigType.MCHAT_API_ONLY.getBoolean()) { |
126 | | - pm.registerEvents(new PlayerListener(this), this); |
127 | | - |
128 | | - pm.registerEvents(new ChatListener(this), this); |
129 | | - |
130 | | - pm.registerEvents(new CommandListener(), this); |
131 | | - } |
132 | | - } |
133 | | - |
134 | | - private void killEss() { |
135 | | - Plugin plugin = pm.getPlugin("EssentialsChat"); |
136 | | - |
137 | | - if (plugin != null) { |
138 | | - pm.disablePlugin(plugin); |
139 | | - } |
140 | | - } |
141 | | - |
142 | | - private void setupCommands() { |
143 | | - regCommands("mchat", new MChatCommand(this)); |
144 | | - |
145 | | - regCommands("mchatuser", new InfoAlterCommand("mchatuser", InfoType.USER)); |
146 | | - regCommands("mchatgroup", new InfoAlterCommand("mchatgroup", InfoType.GROUP)); |
147 | | - |
148 | | - regCommands("mchatme", new MeCommand(this)); |
149 | | - } |
150 | | - |
151 | | - private void regCommands(String command, CommandExecutor executor) { |
152 | | - if (getCommand(command) != null) { |
153 | | - getCommand(command).setExecutor(executor); |
154 | | - } |
155 | | - } |
156 | | - |
157 | | - private void initializeClasses() { |
158 | | - API.initialize(); |
159 | | - Parser.initialize(); |
160 | | - } |
161 | | -} |
| 1 | +package ca.q0r.mchat; |
| 2 | + |
| 3 | +import ca.q0r.mchat.api.API; |
| 4 | +import ca.q0r.mchat.api.Writer; |
| 5 | +import ca.q0r.mchat.commands.InfoAlterCommand; |
| 6 | +import ca.q0r.mchat.commands.MChatCommand; |
| 7 | +import ca.q0r.mchat.commands.MeCommand; |
| 8 | +import ca.q0r.mchat.configs.YmlManager; |
| 9 | +import ca.q0r.mchat.configs.YmlType; |
| 10 | +import ca.q0r.mchat.configs.config.ConfigType; |
| 11 | +import ca.q0r.mchat.events.ChatListener; |
| 12 | +import ca.q0r.mchat.events.CommandListener; |
| 13 | +import ca.q0r.mchat.events.PlayerListener; |
| 14 | +import ca.q0r.mchat.types.InfoType; |
| 15 | +import ca.q0r.mchat.updater.Updater; |
| 16 | +import ca.q0r.mchat.util.MessageUtil; |
| 17 | +import ca.q0r.mchat.util.Timer; |
| 18 | +import ca.q0r.mchat.variables.VariableManager; |
| 19 | +import org.bukkit.Bukkit; |
| 20 | +import org.bukkit.command.CommandExecutor; |
| 21 | +import org.bukkit.entity.Player; |
| 22 | +import org.bukkit.plugin.Plugin; |
| 23 | +import org.bukkit.plugin.PluginDescriptionFile; |
| 24 | +import org.bukkit.plugin.PluginManager; |
| 25 | +import org.bukkit.plugin.java.JavaPlugin; |
| 26 | +import org.bukkit.scheduler.BukkitRunnable; |
| 27 | + |
| 28 | +public class MChat extends JavaPlugin { |
| 29 | + // Default Plugin Data |
| 30 | + public PluginManager pm; |
| 31 | + public PluginDescriptionFile pdfFile; |
| 32 | + |
| 33 | + public Boolean update = false; |
| 34 | + |
| 35 | + public void onEnable() { |
| 36 | + // Initialize and Start the Timer |
| 37 | + Timer timer = new Timer(); |
| 38 | + |
| 39 | + // Initialize Plugin Data |
| 40 | + pm = getServer().getPluginManager(); |
| 41 | + pdfFile = getDescription(); |
| 42 | + |
| 43 | + // First we kill EssentialsChat |
| 44 | + killEss(); |
| 45 | + |
| 46 | + // Initialize Metrics |
| 47 | + /*getServer().getScheduler().runTaskLater(this, new BukkitRunnable(){ |
| 48 | + @Override |
| 49 | + public void run() { |
| 50 | + try { |
| 51 | + Metrics metrics = new Metrics(Bukkit.getPluginManager().getPlugin("MChat")); |
| 52 | + metrics.findCustomData(); |
| 53 | + metrics.start(); |
| 54 | + } catch (IOException ignored) {} |
| 55 | + } |
| 56 | + }, 200);*/ |
| 57 | + |
| 58 | + // Load Yml |
| 59 | + YmlManager.initialize(); |
| 60 | + |
| 61 | + // Initialize Classes |
| 62 | + initializeClasses(); |
| 63 | + |
| 64 | + // Register Events |
| 65 | + registerEvents(); |
| 66 | + |
| 67 | + // Setup Commands |
| 68 | + setupCommands(); |
| 69 | + |
| 70 | + // Add All Players To Info.yml |
| 71 | + if (ConfigType.INFO_ADD_NEW_PLAYERS.getBoolean()) { |
| 72 | + for (Player players : getServer().getOnlinePlayers()) { |
| 73 | + if (YmlManager.getYml(YmlType.INFO_YML).getConfig().get("users." + players.getName()) == null) { |
| 74 | + Writer.addBase(players.getName(), ConfigType.INFO_DEFAULT_GROUP.getString(), false); |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + // Updater |
| 80 | + if (ConfigType.MCHAT_UPDATE_CHECK.getBoolean()) { |
| 81 | + getServer().getScheduler().runTaskLater(this, new BukkitRunnable(){ |
| 82 | + @Override |
| 83 | + public void run() { |
| 84 | + MChat mchat = (MChat) Bukkit.getPluginManager().getPlugin("MChat"); |
| 85 | + Updater updater = new Updater(mchat, "mchat", mchat.getFile(), Updater.UpdateType.NO_DOWNLOAD, false); |
| 86 | + mchat.update = updater.getResult() == Updater.UpdateResult.UPDATE_AVAILABLE; |
| 87 | + } |
| 88 | + |
| 89 | + }, 50); |
| 90 | + } else { |
| 91 | + MessageUtil.logFormatted("Update Check has been Disabled."); |
| 92 | + MessageUtil.logFormatted("To Enable please change ''mchat.updateCheck''"); |
| 93 | + MessageUtil.logFormatted("in config.yml to true!!"); |
| 94 | + } |
| 95 | + |
| 96 | + // Stop the Timer |
| 97 | + timer.stop(); |
| 98 | + |
| 99 | + // Calculate Startup Timer |
| 100 | + long diff = timer.difference(); |
| 101 | + |
| 102 | + MessageUtil.log("[" + pdfFile.getName() + "] " + pdfFile.getName() + " v" + pdfFile.getVersion() + " is enabled! [" + diff + "ms]"); |
| 103 | + } |
| 104 | + |
| 105 | + public void onDisable() { |
| 106 | + // Initialize and Start the Timer |
| 107 | + Timer timer = new Timer(); |
| 108 | + |
| 109 | + getServer().getScheduler().cancelTasks(this); |
| 110 | + |
| 111 | + // Unload Yml |
| 112 | + YmlManager.unload(); |
| 113 | + |
| 114 | + // Stop the Timer |
| 115 | + timer.stop(); |
| 116 | + |
| 117 | + // Calculate Shutdown Timer |
| 118 | + long diff = timer.difference(); |
| 119 | + |
| 120 | + MessageUtil.log("[" + pdfFile.getName() + "] " + pdfFile.getName() + " v" + pdfFile.getVersion() + " is disabled! [" + diff + "ms]"); |
| 121 | + } |
| 122 | + |
| 123 | + private void registerEvents() { |
| 124 | + if (!ConfigType.MCHAT_API_ONLY.getBoolean()) { |
| 125 | + pm.registerEvents(new PlayerListener(this), this); |
| 126 | + |
| 127 | + pm.registerEvents(new ChatListener(this), this); |
| 128 | + |
| 129 | + pm.registerEvents(new CommandListener(), this); |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + private void killEss() { |
| 134 | + Plugin plugin = pm.getPlugin("EssentialsChat"); |
| 135 | + |
| 136 | + if (plugin != null) { |
| 137 | + pm.disablePlugin(plugin); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + private void setupCommands() { |
| 142 | + regCommands("mchat", new MChatCommand(this)); |
| 143 | + |
| 144 | + regCommands("mchatuser", new InfoAlterCommand("mchatuser", InfoType.USER)); |
| 145 | + regCommands("mchatgroup", new InfoAlterCommand("mchatgroup", InfoType.GROUP)); |
| 146 | + |
| 147 | + regCommands("mchatme", new MeCommand(this)); |
| 148 | + } |
| 149 | + |
| 150 | + private void regCommands(String command, CommandExecutor executor) { |
| 151 | + if (getCommand(command) != null) { |
| 152 | + getCommand(command).setExecutor(executor); |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + private void initializeClasses() { |
| 157 | + API.initialize(); |
| 158 | + VariableManager.initialize(); |
| 159 | + } |
| 160 | +} |
0 commit comments