11package com .jaimemartz .playerbalancer .commands ;
22
3- import com .jaimemartz . playerbalancer . PlayerBalancer ;
3+ import com .google . common . collect . Iterables ;
44import com .jaimemartz .playerbalancer .connection .ConnectionIntent ;
55import com .jaimemartz .playerbalancer .section .ServerSection ;
6- import com .jaimemartz .playerbalancer .settings .ConfigEntries ;
6+ import com .jaimemartz .playerbalancer .settings .Settings ;
7+ import com .jaimemartz .playerbalancer .settings .beans .MapBean ;
8+ import com .jaimemartz .playerbalancer .settings .types .CommandProperties ;
9+ import com .jaimemartz .playerbalancer .settings .types .GeneralProperties ;
10+ import com .jaimemartz .playerbalancer .settings .types .MessageProperties ;
11+ import com .jaimemartz .playerbalancer .settings .types .SectionsHolder ;
712import com .jaimemartz .playerbalancer .utils .MessageUtils ;
813import net .md_5 .bungee .api .ChatColor ;
914import net .md_5 .bungee .api .CommandSender ;
1015import net .md_5 .bungee .api .chat .ComponentBuilder ;
1116import net .md_5 .bungee .api .config .ServerInfo ;
1217import net .md_5 .bungee .api .connection .ProxiedPlayer ;
1318import net .md_5 .bungee .api .plugin .Command ;
14- import net .md_5 .bungee .config .Configuration ;
1519
20+ import javax .inject .Inject ;
1621import java .util .concurrent .Callable ;
1722
1823public class FallbackCommand extends Command {
19- private final PlayerBalancer plugin ;
24+ @ Inject
25+ private Settings settings ;
2026
21- public FallbackCommand (PlayerBalancer plugin ) {
22- super (ConfigEntries .FALLBACK_COMMAND_NAME .get (), ConfigEntries .FALLBACK_COMMAND_PERMISSION .get (), (ConfigEntries .FALLBACK_COMMAND_ALIASES .get ().stream ()).toArray (String []::new ));
23- this .plugin = plugin ;
27+ @ Inject
28+ private SectionsHolder sections ;
29+
30+ @ Inject
31+ public FallbackCommand (Settings settings ) {
32+ super (
33+ settings .getProperty (CommandProperties .COMMAND ).getName (),
34+ settings .getProperty (CommandProperties .COMMAND ).getPermission (),
35+ Iterables .toArray (settings .getProperty (CommandProperties .COMMAND ).getAliases (), String .class )
36+ );
2437 }
2538
2639 @ Override
@@ -29,38 +42,38 @@ public void execute(CommandSender sender, String[] args) {
2942 ProxiedPlayer player = (ProxiedPlayer ) sender ;
3043
3144 Callable <ServerSection > callable = () -> {
32- ServerSection current = plugin . getSectionManager () .getByPlayer (player );
45+ ServerSection current = sections .getByPlayer (player );
3346
3447 if (current != null ) {
35- if (( ConfigEntries . FALLBACK_COMMAND_IGNORED_SECTIONS . get () ).contains (current .getName ())) {
36- MessageUtils .send (player , ConfigEntries . UNAVAILABLE_MESSAGE . get ( ));
48+ if (settings . getProperty ( CommandProperties . IGNORED_SECTIONS ).contains (current .getName ())) {
49+ MessageUtils .send (player , settings . getProperty ( MessageProperties . UNAVAILABLE_SERVER ));
3750 return null ;
3851 }
3952
40- Configuration rules = plugin . getConfigHandle (). getSection ( "settings.fallback-command.rules" );
41- String bind = rules .getString (current .getName ());
42- ServerSection target = plugin . getSectionManager () .getByName (bind );
53+ MapBean rules = settings . getProperty ( CommandProperties . RULES );
54+ String bind = rules .getMap (). get (current .getName ());
55+ ServerSection target = sections .getByName (bind );
4356
4457 if (target == null ) {
4558 if (current .getParent () != null ) {
4659 target = current .getParent ();
4760 } else {
48- MessageUtils .send (player , ConfigEntries . UNAVAILABLE_MESSAGE . get ( ));
61+ MessageUtils .send (player , settings . getProperty ( MessageProperties . UNAVAILABLE_SERVER ));
4962 return null ;
5063 }
5164 }
5265
53- if (ConfigEntries . FALLBACK_COMMAND_RESTRICTED . get ( )) {
66+ if (settings . getProperty ( CommandProperties . RESTRICTED )) {
5467 if (current .getPosition () >= 0 && target .getPosition () < 0 ) {
55- MessageUtils .send (player , ConfigEntries . UNAVAILABLE_MESSAGE . get ( ));
68+ MessageUtils .send (player , settings . getProperty ( MessageProperties . UNAVAILABLE_SERVER ));
5669 return null ;
5770 }
5871 }
5972
6073 return target ;
6174 } else {
62- if (ConfigEntries . FALLBACK_PRINCIPAL_ENABLED . get ( )) {
63- return plugin . getSectionManager () .getPrincipal ();
75+ if (settings . getProperty ( GeneralProperties . FALLBACK_PRINCIPAL )) {
76+ return sections .getPrincipal ();
6477 }
6578 }
6679
0 commit comments