package ru vlad0sminer bansystem import org bukkit Bukkit import org b

  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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
package ru.vlad0sminer.bansystem;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.plugin.java.JavaPlugin;
import ru.tehkode.permissions.PermissionGroup;
import ru.tehkode.permissions.PermissionManager;
import ru.tehkode.permissions.bukkit.PermissionsEx;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import static org.bukkit.event.EventPriority.HIGHEST;
public class main extends JavaPlugin implements Listener {
private static main instance;
private File messagesConfigFile;
private FileConfiguration messagesConfig;
private File prioritiesConfigFile;
private FileConfiguration prioritiesConfig;
private File player_prioritiesConfigFile;
private FileConfiguration player_prioritiesConfig;
private File banlist_ConfigFile;
private FileConfiguration banlist_Config;
private File mutelist_ConfigFile;
private FileConfiguration mutelist_Config;
public static int max_targetgroup_priority;
public static int max_playergroup_priority;
public static int player_priority_file;
public static int target_priority_file;
public Date data = new Date();
public static long time_now;
public long time_to_unmute;
public long time_muted;
public long mute_long_time;
public long time_to_unban;
public long time_banned;
public long ban_long_time;
public SimpleDateFormat formatForDateNow = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
//Начало переменных с сообщениями
public static String kick;
public static String ban;
public static String reason_kick;
public static String reason_ban;
public static String player_kick_player;
public static String player_ban_player;
public static String kicked_or_banned_or_muted;
public static String mute_or_kick_or_ban_unknown_reason;
public static String player_notfound;
public static String prefix;
public static String permanent_ban_or_mute;
public static String player_mute_player;
public static String your_muted;
public static String expires_never;
public static String mute_expires;
public static String reason_mute;
public static String minutes_msg;
public static String ban_expires;
public static String ban_expires_howmuch;
public static String ban_permission;
public static String adminban_permission;
public static String kick_permission;
public static String adminkick_permission;
public static String mute_permission;
public static String adminmute_permission;
public static String tempban_permission;
public static String admintempban_permission;
public static String tempmute_permission;
public static String admintempmute_permission;
public static String unban_permission;
public static String adminunban_permission;
public static String unmute_permission;
public static String adminunmute_permission;
//Конец
public void loadMessages(){
prefix = color(getMessagesConfig().getString("prefix"));
kick = color(getMessagesConfig().getString("kick"));
ban = color(getMessagesConfig().getString("ban"));
reason_kick = color(getMessagesConfig().getString("reason_kick"));
reason_ban = color(getMessagesConfig().getString("reason_ban"));
player_kick_player = color(getMessagesConfig().getString("player_kick_player"));
player_ban_player = color(getMessagesConfig().getString("player_ban_player"));
kicked_or_banned_or_muted = color(getMessagesConfig().getString("kicked_or_banned_or_muted"));
mute_or_kick_or_ban_unknown_reason = color(getMessagesConfig().getString("mute_or_kick_or_ban_unknown_reason"));
player_notfound = color(getMessagesConfig().getString("player_notfound"));
permanent_ban_or_mute = color(getMessagesConfig().getString("permanent_ban_or_mute"));
player_mute_player = color(getMessagesConfig().getString("player_mute_player"));
your_muted = color(getMessagesConfig().getString("your_muted"));
expires_never = color(getMessagesConfig().getString("expires_never"));
mute_expires = color(getMessagesConfig().getString("mute_expires"));
reason_mute = color(getMessagesConfig().getString("reason_mute"));
minutes_msg = color(getMessagesConfig().getString("minutes_msg"));
ban_expires = color(getMessagesConfig().getString("ban_expires"));
ban_expires_howmuch = color(getMessagesConfig().getString("ban_expires_howmuch"));
ban_permission = color(getMessagesConfig().getString("ban_permission"));
adminban_permission = color(getMessagesConfig().getString("adminban_permission"));
adminkick_permission = color(getMessagesConfig().getString("adminkick_permission"));
kick_permission = color(getMessagesConfig().getString("kick_permission"));
mute_permission = color(getMessagesConfig().getString("mute_permission"));
adminmute_permission = color(getMessagesConfig().getString("adminmute_permission"));
tempban_permission = color(getMessagesConfig().getString("tempban_permission"));
admintempban_permission = color(getMessagesConfig().getString("admintempban_permission"));
tempmute_permission = color(getMessagesConfig().getString("tempmute_permission"));
admintempmute_permission = color(getMessagesConfig().getString("admintempmute_permission"));
unban_permission = color(getMessagesConfig().getString("unban_permission"));
adminunban_permission = color(getMessagesConfig().getString("adminunban_permission"));
unmute_permission = color(getMessagesConfig().getString("unmute_permission"));
adminunmute_permission = color(getMessagesConfig().getString("adminunmute_permission"));
}
//=============================Загрузка конфига сообщений=============================
public FileConfiguration getMessagesConfig() {
return this.messagesConfig;
}
private void createMessagesConfig() {
messagesConfigFile = new File(getDataFolder(), "messages.yml");
if (!messagesConfigFile.exists()) {
messagesConfigFile.getParentFile().mkdirs();
saveResource("messages.yml", false);
}
messagesConfig = new YamlConfiguration();
try {
messagesConfig.load(messagesConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
public static String color(String format){
return ChatColor.translateAlternateColorCodes('&', format);
}
public void reloadMessages(){
messagesConfig = YamlConfiguration.loadConfiguration(messagesConfigFile);
loadMessages();
}
//=============================Конец загрузки конфига сообщений=============================
//=============================Загрузка приоритетов групп=============================
public FileConfiguration getPriorities() {
return this.prioritiesConfig;
}
private void createPrioritiesConfig() throws IOException, InvalidConfigurationException {
prioritiesConfigFile = new File(getDataFolder(), "groups.yml");
if (!prioritiesConfigFile.exists()) {
prioritiesConfigFile.getParentFile().mkdirs();
saveResource("groups.yml", false);
prioritiesConfig = new YamlConfiguration();
prioritiesConfig.load(prioritiesConfigFile);
setPermGroupsPriorities();
}
prioritiesConfig = new YamlConfiguration();
try {
prioritiesConfig.load(prioritiesConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
public void reloadPriorities(){
prioritiesConfig = YamlConfiguration.loadConfiguration(prioritiesConfigFile);
}
public void setPermGroupsPriorities(){
PermissionManager mgr = PermissionsEx.getPermissionManager();
List<PermissionGroup> groups = mgr.getGroupList();
int prior = 0;
int time_limit_group = 0;
for(int i = 0; i < groups.size(); i++){
if(groups.get(i).getWeight() != 0) {
prior++;
time_limit_group = time_limit_group + 50;
getPriorities()
.set("groups." + groups.get(i).getName() + ".priority", prior);
getPriorities()
.set("groups." + groups.get(i).getName() + ".limit", time_limit_group);
savePrioritiesBase();
}
}
}
public void savePrioritiesBase() {
try {
this.getPriorities().save(prioritiesConfigFile);
} catch (IOException var2) {
System.out.println("Ошибка! Проверьте плагин!");
}
}
//=============================Конец загрузки конфига приоритетов групп=============================
//=============================Загрузка приоритетов игроков=============================
public FileConfiguration getPlayerPriorities() {
return this.player_prioritiesConfig;
}
private void createPlayerPrioritiesConfig() {
player_prioritiesConfigFile = new File(getDataFolder(), "player_priorities.yml");
if (!player_prioritiesConfigFile.exists()) {
player_prioritiesConfigFile.getParentFile().mkdirs();
saveResource("player_priorities.yml", false);
}
player_prioritiesConfig = new YamlConfiguration();
try {
player_prioritiesConfig.load(player_prioritiesConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
public void reloadPlayerPriorities(){
player_prioritiesConfig = YamlConfiguration.loadConfiguration(player_prioritiesConfigFile);
}
public void savePlayerPrioritiesBase() {
try {
this.getPlayerPriorities().save(player_prioritiesConfigFile);
} catch (IOException var2) {
System.out.println("Ошибка! Проверьте плагин!");
}
}
//=============================Конец загрузки конфига приоритетов игроков=============================
//=============================Загрузка банлиста=============================
public FileConfiguration getBanList() {
return this.banlist_Config;
}
private void createBanList() {
banlist_ConfigFile = new File(getDataFolder(), "base_bans.yml");
if (!banlist_ConfigFile.exists()) {
banlist_ConfigFile.getParentFile().mkdirs();
saveResource("base_bans.yml", false);
}
banlist_Config = new YamlConfiguration();
try {
banlist_Config.load(banlist_ConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
public void reloadBanList(){
banlist_Config = YamlConfiguration.loadConfiguration(banlist_ConfigFile);
}
public void saveBanList() {
try {
this.getBanList().save(banlist_ConfigFile);
} catch (IOException var2) {
System.out.println("Ошибка! Проверьте плагин!");
}
}
//=============================Конец загрузки банлиста=============================
//=============================Загрузка мутлиста=============================
public FileConfiguration getMuteList() {
return this.mutelist_Config;
}
private void createMuteList() {
mutelist_ConfigFile = new File(getDataFolder(), "base_mute.yml");
if (!mutelist_ConfigFile.exists()) {
mutelist_ConfigFile.getParentFile().mkdirs();
saveResource("base_mute.yml", false);
}
mutelist_Config = new YamlConfiguration();
try {
mutelist_Config.load(mutelist_ConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
public void reloadMuteList(){
mutelist_Config = YamlConfiguration.loadConfiguration(mutelist_ConfigFile);
}
public void saveMuteList() {
try {
this.getMuteList().save(mutelist_ConfigFile);
} catch (IOException var2) {
System.out.println("Ошибка! Проверьте плагин!");
}
}
//=============================Конец загрузки мутлиста=============================
public static main getInstance() {
return main.instance;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if((sender instanceof ConsoleCommandSender) && (cmd.getName().equalsIgnoreCase("rlbans"))){
reloadConfig();
reloadMessages();
reloadPriorities();
reloadPlayerPriorities();
reloadBanList();
reloadMuteList();
sender.sendMessage("Config reloaded.");
}
return true;
}
@EventHandler(priority = HIGHEST, ignoreCancelled = false)
public void onPlayerJoin(PlayerLoginEvent event){
Player player = event.getPlayer();
if((getBanList().getString("bans." + player.getName() + "." + "ban_date_on_milliseconds")) != null) {
this.time_banned = Long.parseLong((getBanList().getString("bans." + player.getName() + "." + "ban_date_on_milliseconds")));
this.ban_long_time = 1000 * (Long.parseLong((getBanList().getString("bans." + player.getName() + "." + "ban_time"))));
this.time_to_unban = ((time_banned + ban_long_time) - (updateTimeNow())) / 1000;
if(time_to_unban <= 0){
getBanList().set("bans." + player.getName(), null);
saveBanList();
}
}
if(player.getName().equalsIgnoreCase(getBanList().getString("bans." + player.getName() + ".nickname"))) {
if(!getBanList().getString("bans." + player.getName() + ".permanent").equals("true")) {
String how_to_unban = String.format("%.1f", (double) time_to_unban / 60);
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, prefix + "\n" + ban
+ getBanList().getString(
"bans." + player.getName() + "." + "banned_by") + "\n" + reason_ban
+ getBanList().getString(
"bans." + player.getName() + "." + "reason") + "\n" + ban_expires
+ how_to_unban + " минут");
} else if(!getBanList().getString("bans." + player.getName() + ".permanent").equals("false")) {
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, prefix + "\n" + ban
+ getBanList().getString(
"bans." + player.getName() + "." + "banned_by") + "\n" + reason_ban
+ getBanList().getString(
"bans." + player.getName() + "." + "reason") + "\n" + ban_expires
+ permanent_ban_or_mute);
}
}
}
@EventHandler(priority = HIGHEST, ignoreCancelled = false)
public void onChatSend(AsyncPlayerChatEvent event){
Player player = event.getPlayer();
if((getMuteList().getString("mute." + player.getName() + "." + "muted_date_on_milliseconds")) != null) {
this.time_muted = Long.parseLong((getMuteList().getString("mute." + player.getName() + "." + "muted_date_on_milliseconds")));
this.mute_long_time = 1000 * (Long.parseLong((getMuteList().getString("mute." + player.getName() + "." + "mute_time"))));
this.time_to_unmute = ((time_muted + mute_long_time) - (updateTimeNow())) / 1000;
if(time_to_unmute <= 0){
getMuteList().set("mute." + player.getName(), null);
saveMuteList();
}
}
if((getMuteList().getString("mute." + player.getName() + "." + "nickname") != null)
&& (getMuteList().getString("mute." + player.getName() + "." + "mute_time") != null)
&& (getMuteList().getString("mute." + player.getName() + "." + "muted_time") != null)
&& (getMuteList().getString("mute." + player.getName() + "." + "permanent").equals("false")))
{
event.setCancelled(true);
player.sendMessage(prefix + your_muted + "\n" + mute_expires + time_to_unmute + minutes_msg);
}
if((getMuteList().getString("mute." + player.getName() + "." + "nickname") != null)
&& (getMuteList().getString("mute." + player.getName() + "." + "permanent").equals("true")))
{
event.setCancelled(true);
player.sendMessage(prefix + your_muted + "\n" + expires_never);
}
}
@EventHandler(priority = HIGHEST, ignoreCancelled = false)
public void onPrivateMessage(PlayerCommandPreprocessEvent event){
Player player = event.getPlayer();
final String[] cmd = event.getMessage().split(" ");
try {
try {
if ((getMuteList().getString("mute." + player.getName() + "." + "nickname").equalsIgnoreCase(event.getPlayer().getName()))
&& (cmd.length >= 1 && cmd[0].equalsIgnoreCase("/m"))
|| (cmd[0].equalsIgnoreCase("/me"))
|| (cmd[0].equalsIgnoreCase("/eme"))
|| (cmd[0].equalsIgnoreCase("/bc"))
|| (cmd[0].equalsIgnoreCase("/ebc"))
|| (cmd[0].equalsIgnoreCase("/broadcast"))
|| (cmd[0].equalsIgnoreCase("/ebroadcast"))
|| (cmd[0].equalsIgnoreCase("/ebcast"))
|| (cmd[0].equalsIgnoreCase("/w"))
|| (cmd[0].equalsIgnoreCase("/m"))
|| (cmd[0].equalsIgnoreCase("/t"))
|| (cmd[0].equalsIgnoreCase("/pm"))
|| (cmd[0].equalsIgnoreCase("/emsg"))
|| (cmd[0].equalsIgnoreCase("/epm"))
|| (cmd[0].equalsIgnoreCase("/er"))
|| (cmd[0].equalsIgnoreCase("/r"))
|| (cmd[0].equalsIgnoreCase("/tell"))
|| (cmd[0].equalsIgnoreCase("/etell"))
|| (cmd[0].equalsIgnoreCase("/whisper"))
|| (cmd[0].equalsIgnoreCase("/ewhisper"))) {
event.setCancelled(true);
event.getPlayer().sendMessage(prefix + your_muted + "\n" + mute_expires + expires_never);
}
} catch (NullPointerException ignore){}
} catch (ArrayIndexOutOfBoundsException e){
event.getPlayer().sendMessage(prefix + your_muted + "\n" + expires_never);
}
}
public long updateTimeNow(){
time_now = new Date().getTime();
return time_now;
}
@Override
public void onEnable(){
if(!getDataFolder().exists()){
getDataFolder().mkdirs();
}
createMessagesConfig();
createBanList();
createPlayerPrioritiesConfig();
createMuteList();
loadMessages();
try {
createPrioritiesConfig();
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
File config = new File(getDataFolder() + File.separator + "config.yml");
if (!config.exists()) {
getLogger().info("Конфиг не найден, создаю новый файл!");
getConfig().options().copyDefaults(true);
saveDefaultConfig();
}
Bukkit.getLogger().info("Плагин запущен");
Bukkit.getPluginManager().registerEvents(this, this);
getCommand("kick").setExecutor(new kick(this));
getCommand("ban").setExecutor(new ban(this));
getCommand("mute").setExecutor(new mute(this));
getCommand("tempmute").setExecutor(new tempmute(this));
getCommand("tempban").setExecutor(new tempban(this));
getCommand("unban").setExecutor(new unban(this));
getCommand("unmute").setExecutor(new unmute(this));
}
public void onDisable(){
Bukkit.getLogger().info("Плагин выключен");
}
}