· 6 years ago · Nov 17, 2019, 01:28 AM
1package com.vife.core;
2
3import com.comphenix.protocol.ProtocolLibrary;
4import com.comphenix.protocol.ProtocolManager;
5import com.vife.core.anvil.AnvilCheckListener;
6import com.vife.core.commands.admin.*;
7import com.vife.core.commands.admin.bans.BanCommand;
8import com.vife.core.commands.admin.bans.UnBanCommand;
9import com.vife.core.commands.helper.VanishCommand;
10import com.vife.core.commands.player.*;
11import com.vife.core.commands.guilds.*;
12import com.vife.core.commands.helper.ChatCommand;
13import com.vife.core.commands.helper.FlyCommand;
14import com.vife.core.commands.helper.ListCommand;
15import com.vife.core.commands.premium.EnderChestCommand;
16import com.vife.core.commands.premium.RepairCommand;
17import com.vife.core.engine.BanEngine;
18import com.vife.core.enums.GroupType;
19import com.vife.core.inventories.CraftingInv;
20import com.vife.core.listeners.*;
21import com.vife.core.listeners.action.*;
22import com.vife.core.mysql.MySQL;
23import com.vife.core.threads.*;
24
25import com.vife.core.config.Config;
26import com.vife.core.engine.DataEngine;
27import com.vife.core.engine.GuildEngine;
28import com.vife.core.utils.LocationUtil;
29import net.vife.inc.commands.IncognitoCommand;
30import org.bukkit.Bukkit;
31import org.bukkit.event.Listener;
32import org.bukkit.plugin.Plugin;
33import org.bukkit.plugin.java.JavaPlugin;
34
35public class Main extends JavaPlugin {
36
37 private static Main instance;
38
39 @Override
40 public void onEnable() {
41 instance = this;
42 initSettings();
43 //initRecipes();
44 CraftingInv.registerRecipe();
45 initSQL();
46 initThreads();
47 initListeners();
48 initCache();
49 initRegions();
50 initCommands();
51 }
52
53 @Override
54 public void onDisable() {
55 Bukkit.getScheduler().cancelTasks(this);
56 }
57
58 private void initSQL() {
59 MySQL.getInstance();
60 //store.update(true, "CREATE TABLE IF NOT EXISTS `{P}bans` (" + (store.getStoreMode() == StoreMode.MYSQL ? "`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT," : "`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,") + "`name` varchar(32) NOT NULL,`time` bigint(22) NOT NULL, `reason` text NOT NULL, `admin` varchar(32) NOT NULL, `start` BIGINT(22) NOT NULL);");
61
62 MySQL.getInstance().executeUpdate("CREATE TABLE IF NOT EXISTS " + Config.DATABASE_TABLEPREFIX + "data(id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, uuid text not null, name text not null, rank text not null, protection long not null, onlinetime long not null, connections int not null, points int not null, kills int not null, deaths int not null, assists int not null, logouts int not null, eatenkox int not null, eatenrefil int not null, throwedpearl int not null, namemc text not null, kit_start bigint not null, kit_vip bigint not null, kit_svip bigint not null, kit_tw bigint not null, kit_yt bigint not null, home text not null);");
63 MySQL.getInstance().executeUpdate("CREATE TABLE IF NOT EXISTS " + Config.DATABASE_TABLEPREFIX + "guilds(id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, gtag text not null, gname text not null, points int not null, cuboid text not null, gsize int not null, ghome text not null, gleader text not null, gcreatedate bigint not null, glives bigint not null, gvalidity bigint not null);");
64 MySQL.getInstance().executeUpdate("CREATE TABLE IF NOT EXISTS " + Config.DATABASE_TABLEPREFIX + "members(id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, uuid text not null, guild text not null);");
65 MySQL.getInstance().executeUpdate("CREATE TABLE IF NOT EXISTS " + Config.DATABASE_TABLEPREFIX + "guilds_ally(id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, g1 text not null, g2 text not null);");
66 MySQL.getInstance().executeUpdate("CREATE TABLE IF NOT EXISTS " + Config.DATABASE_TABLEPREFIX + "bans(id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, name text not null, time long not null, reason text not null, admin text not null, start long not null);");
67
68 }
69
70 private void initThreads() {
71 // Bukkit.getScheduler().runTaskTimer(this, new ProtectionThread(), 240L, 20L);
72 Bukkit.getScheduler().runTaskTimer(this, new CombatThread(), 240L, 20L);
73 Bukkit.getScheduler().runTaskTimer(this, new DropThread(), 20*60*30L, 20*60*30L);
74
75 Bukkit.getScheduler().runTaskTimerAsynchronously((Plugin)this, (Runnable)new RefreshThread(), 180L, 240L);
76 Bukkit.getScheduler().runTaskTimerAsynchronously(this, new AutoMessageThread(), 240L, 20 * 45L);
77
78 }
79
80 private void initListeners() {
81 registerListener(this, new PlayerDeathListener(),
82 new EntityDamageByEntityListener(),
83 new PlayerInteractListener(),
84 new AsyncPlayerChatListener(),
85 new PlayerQuitJoinListener(),
86 new BlockPlaceListener(),
87 new EfektListener(),
88 new BlockBreakListener(),
89 new BlockedCommandListener(),
90 new BlockedListener(),
91 new BlockedListener(),
92 new BlockFromToListener(),
93 new PlayerRankingEntityListener(),
94 new PlayerNormalEmpyListener(),
95 new EnchantListener(),
96 new AnvilCheckListener(),
97 new BlockSpreadListener(),
98 new PlayerInventoryClick(),
99 new TntListener(),
100 new EntityExplodeBlock(),
101 new CraftItemListener(),
102 new TntLevelListener(),
103 new PlayerMoveListener());
104
105 }
106
107 private void initCache() {
108 DataEngine.loadData();
109 BanEngine.loadBans();
110 GuildEngine.loadGuilds();
111 GuildEngine.loadMembers();
112 GuildEngine.loadAlly();
113
114 }
115
116 private void initRegions() {
117 LocationUtil.init();
118 }
119
120 private void initSettings() {
121 Config.reloadConfig();
122 }
123
124 private void initCommands() {
125 // PLAYER COMMAND //
126 new SpawnCommand("spawn", new String[]{"spawn"}, GroupType.PLAYER);
127 new SetHomeCommand("sethome", new String[]{"setdom"}, GroupType.PLAYER);
128 new HomeCommand("home", new String[]{"dom"}, GroupType.PLAYER);
129 new ProtectionCommand("ochrona", new String[]{"protection"}, GroupType.PLAYER);
130 new StatsCommand("statystyki", new String[]{"staty"}, GroupType.PLAYER);
131
132 //new NameMcCommand("namemc", new String[]{"namemc"}, GroupType.PLAYER);
133 new CraftingCommand("craft", new String[]{"crafting"}, GroupType.PLAYER);
134 new RankingCommand("ranking", new String[]{"rank"}, GroupType.PLAYER);
135 new EfektCommand("efekt", new String[]{"efekty"}, GroupType.PLAYER);
136 new VipCommand("vip", new String[]{"vipinfo"}, GroupType.PLAYER);
137 new VifeCommand("vife", new String[]{"vifeinfo"}, GroupType.PLAYER);
138 new HelpCommand("pomoc", new String[]{"help"}, GroupType.PLAYER);
139 new GuildCommand("g", new String[]{"gildie"}, GroupType.PLAYER);
140 new GuildItemCommand("itemy", new String[]{"g itemy"}, GroupType.PLAYER);
141 new KitCommand("kit", new String[]{"zestaw"}, GroupType.PLAYER);
142 new TpaCommand("tpa", new String[]{"teleport"}, GroupType.PLAYER);
143 new TpacceptCommand("tpaacept", new String[]{"tptak"}, GroupType.PLAYER);
144
145
146 // ADMIN COMMAND //
147 new GroupCommand("group", new String[]{"grupa"}, GroupType.HEADADMIN);
148 new BanCommand("ban", new String[]{"blok"}, GroupType.HELPER);
149 new UnBanCommand("unban", new String[]{"odbanuj"}, GroupType.HELPER);
150
151
152 new SlotCommand("slot", new String[]{"slots"}, GroupType.HEADADMIN);
153 new SetSpawnCommand("setspawn", new String[]{"spawnpoint"}, GroupType.ADMIN);
154 new IsCommand("is", new String[]{"is"}, GroupType.HEADADMIN);
155 new GamemodeCommand("gamemode", new String[]{"gm"}, GroupType.ADMIN);
156 new FlyCommand("fly", new String[]{"latanie"}, GroupType.HELPER);
157 new PerformanceCommand("perf", new String[]{"performance"}, GroupType.HEADADMIN);
158 new ListCommand("list", new String[]{"online"}, GroupType.HEADADMIN);
159 new ChatCommand("chat", new String[]{"czat"}, GroupType.HELPER);
160 new SwitchCommand("switch", new String[]{"start"}, GroupType.HEADADMIN);
161 new VanishCommand("vanish", new String[]{"v"}, GroupType.HELPER);
162 new EnderChestCommand("ec", new String[]{"enderchest"}, GroupType.VIP);
163 new RepairCommand("repair", new String[]{"napraw"}, GroupType.VIP);
164 // GUILD COMMAND //
165 new CreateCommand("zaloz", new String[]{"create"}, GroupType.PLAYER);
166 new DeleteCommand("usun", new String[]{"delete"}, GroupType.PLAYER);
167 new InviteCommand("zapros", new String[]{"invite"}, GroupType.PLAYER);
168 new EnemyCommand("zerwij", new String[]{"enemy"}, GroupType.PLAYER);
169 new AllyCommand("sojusz", new String[]{"ally"}, GroupType.PLAYER);
170 new SetBaseCommand("ustawbaze", new String[]{"ustawbaza"}, GroupType.PLAYER);
171 new BaseCommand("baza", new String[]{"dom"}, GroupType.PLAYER);
172 new IncognitoCommand("incognito", new String[]{"inc"}, GroupType.PLAYER);
173
174 new JoinCommand("dolacz", new String[]{"join"}, GroupType.PLAYER);
175 new KickCommand("wyrzuc", new String[]{"kick"}, GroupType.PLAYER);
176
177
178 }
179
180 public static Main getInstance() {
181 return instance;
182 }
183
184 private void registerListener(Plugin plugin, Listener... listeners) {
185 for (Listener listener : listeners) {
186 Bukkit.getPluginManager().registerEvents(listener, plugin);
187 }
188 }
189}