1313
1414public class UpdateCommand implements CommandExecutor
1515{
16- private static final String [] FILES =
16+ private final String [] FILES =
1717 {
1818 UpToDate .getPlugin ("Aero" ),
1919 UpToDate .getPlugin ("BukkitTelnet" ),
20- UpToDate .getPlugin ("Discord " ),
20+ UpToDate .getPlugin ("JDA " ),
2121 UpToDate .getPlugin ("EssentialsX" ),
2222 UpToDate .getPlugin ("EssentialsXSpawn" ),
2323 UpToDate .getPlugin ("LibsDisguises" ),
24+ UpToDate .getPlugin ("ProtocolLib" ),
2425 UpToDate .getPlugin ("WorldEdit" ),
2526 UpToDate .getPlugin ("WorldGuard" ),
2627 };
2728
2829 @ Override
29- public boolean onCommand (CommandSender sender , Command command , String s , String [] strings )
30- {
31- if (! TFMBridge .isAdmin ( Bukkit . getPlayer ( sender . getName ())) )
30+ public boolean onCommand (CommandSender sender , Command command , String s , String [] strings ) {
31+ boolean noTFM = false ;
32+ if (TFMBridge .getTFM () == null )
3233 {
33- sender .sendMessage (Messages .MSG_NO_PERMS );
34- return true ;
34+ noTFM = true ;
3535 }
36-
37- sender .sendMessage (ChatColor .GRAY + "Updating server plugins." );
38-
39- new BukkitRunnable ()
36+ if (noTFM || TFMBridge .isAdmin (Bukkit .getPlayer (sender .getName ())))
4037 {
41- @ Override
42- public void run ()
38+ sender .sendMessage (ChatColor .GRAY + "Updating server plugins." );
39+
40+ new BukkitRunnable ()
4341 {
44- try
42+ @ Override
43+ public void run ()
4544 {
46- for ( final String url : FILES )
45+ try
4746 {
48- NLog .info ("Downloading: " + url );
49-
50- File file = new File ("./plugins/" + url .substring (url .lastIndexOf ("/" ) + 1 ));
51- if (file .exists ())
52- {
53- file .delete ();
54- }
55- if (!file .getParentFile ().exists ())
47+ for (final String url : FILES )
5648 {
57- file .getParentFile ().mkdirs ();
58- }
49+ NLog .info ("Downloading: " + url );
5950
60- UpToDate .downloadFile (url , file , true );
51+ File file = new File ("./plugins/" + url .substring (url .lastIndexOf ("/" ) + 1 ));
52+ if (file .exists ())
53+ {
54+ file .delete ();
55+ }
56+ if (!file .getParentFile ().exists ())
57+ {
58+ file .getParentFile ().mkdirs ();
59+ }
60+
61+ UpToDate .downloadFile (url , file , true );
62+ }
63+ sender .sendMessage (ChatColor .GRAY + "Successfully updated. Restarting server." );
64+ Bukkit .broadcastMessage (ChatColor .LIGHT_PURPLE + sender .getName () + " updated the plugins, restarting the server." );
65+ Bukkit .getServer ().shutdown ();
66+ }
67+ catch (Exception ex )
68+ {
69+ NLog .severe (ex );
6170 }
62- sender .sendMessage (ChatColor .GRAY + "Successfully updated. Restarting server." );
63- Bukkit .broadcastMessage (ChatColor .LIGHT_PURPLE + sender .getName () + " updated the plugins, restarting the server." );
64- Bukkit .getServer ().shutdown ();
65- }
66- catch (Exception ex )
67- {
68- NLog .severe (ex );
6971 }
70- }
71- }.runTaskAsynchronously (UpToDate .plugin );
72+ }.runTaskAsynchronously (UpToDate .plugin );
73+ } else {
74+ sender .sendMessage (Messages .MSG_NO_PERMS );
75+ return true ;
76+ }
7277 return true ;
7378 }
7479}
0 commit comments