-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
87 lines (69 loc) · 3.25 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* AdvancedNMotd - Bukkit / Bungeecord plugin that provides advanced ways to manage minecraft server motd
* Copyright (C) 2023 NamerPRO
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package ru.namerpro.AdvancedNMotd.Bukkit;
import java.util.Objects;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.utility.MinecraftVersion;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import ru.namerpro.AdvancedNMotd.Configuration.Adapters.BukkitConfigurationAdapter;
import ru.namerpro.AdvancedNMotd.Configuration.IConfigurationFactory;
import ru.namerpro.AdvancedNMotd.Universal.Information;
import ru.namerpro.AdvancedNMotd.Templates.PluginStartUpTemplate;
import ru.namerpro.AdvancedNMotd.Universal.UniversalActions;
import ru.namerpro.AdvancedNMotd.Updater.UpdateChecker;
public class Main extends JavaPlugin {
private static final int pluginId = 19452;
private static BukkitTask updateCheckingTask;
private final PluginStartUpTemplate template = new PluginStartUpTemplate(this) {
@Override
protected IConfigurationFactory getConfigurationFactory() {
return new BukkitConfigurationAdapter.BukkitConfigurationAdapterFactory();
}
@Override
protected void setUpdater() {
updateCheckingTask = Bukkit.getScheduler().runTaskTimerAsynchronously((Main) mainClassInstance, UpdateChecker::check, 1L, 1728000L);
}
@Override
protected void registrar() {
Objects.requireNonNull(getCommand("advancedNMotd")).setExecutor(new BukkitCommandExecutor());
ProtocolLibrary.getProtocolManager().addPacketListener(new ProtocolLibMotd((Main) mainClassInstance, ListenerPriority.NORMAL, PacketType.Status.Server.SERVER_INFO));
ProtocolLibrary.getProtocolManager().addPacketListener(new BukkitClientVersionDetector((Main) mainClassInstance, ListenerPriority.NORMAL, PacketType.Handshake.Client.SET_PROTOCOL));
}
@Override
protected void cancelTask(Object updateCheckingTask) {
((BukkitTask) updateCheckingTask).cancel();
}
};
@Override
public void onEnable() {
Metrics metrics = new Metrics(this, pluginId);
UniversalActions.universalInstance = new BukkitUniversalActions();
Information.serverType = Information.ServerType.BUKKIT;
Information.areColorsSupportedByServer = ProtocolLibrary.getProtocolManager().getMinecraftVersion().compareTo(MinecraftVersion.NETHER_UPDATE) >= 0;
template.onAdvancedNMotdEnable();
}
@Override
public void onDisable() {
template.onAdvancedNMotdDisable(updateCheckingTask);
}
}