21
21
import com .azortis .azortislib .command .Command ;
22
22
import com .azortis .azortislib .command .CommandInjector ;
23
23
import com .azortis .azortislib .command .builders .CommandBuilder ;
24
- import com .azortis .azortislib .command .builders .SubCommandBuilder ;
25
24
import com .azortis .azortislib .command .executors .ICommandExecutor ;
26
- import com .azortis .azortislib .command .executors .ITabCompleter ;
27
- import com .azortis .protocolvanish .bukkit .PermissionManager ;
28
25
import com .azortis .protocolvanish .bukkit .ProtocolVanish ;
29
- import com .azortis .protocolvanish .bukkit .command .subcommands .*;
30
- import com .azortis .protocolvanish .bukkit .settings .old .wrappers .CommandSettingsWrapper ;
31
- import org .bukkit .Location ;
26
+ import com .azortis .protocolvanish .common .VanishPlayer ;
32
27
import org .bukkit .command .CommandSender ;
33
28
import org .bukkit .command .ConsoleCommandSender ;
34
29
import org .bukkit .entity .Player ;
35
- import org .bukkit .util .StringUtil ;
36
30
37
- import java .util .ArrayList ;
38
- import java .util .Collection ;
39
- import java .util .List ;
40
-
41
- public class VanishCommand implements ICommandExecutor , ITabCompleter {
31
+ public class VanishCommand implements ICommandExecutor {
42
32
43
33
private final ProtocolVanish plugin ;
44
- private Collection <String > enabledSubCommands = new ArrayList <>();
45
34
46
- public VanishCommand (ProtocolVanish plugin ) {
35
+ public VanishCommand (ProtocolVanish plugin ){
47
36
this .plugin = plugin ;
48
- plugin .getLogger ().info ("Loading command..." );
49
- CommandSettingsWrapper commandSettings = plugin .getSettingsManager ().getCommandSettings ();
37
+ CommandSettings commandSettings = plugin .getSettingsManager ().getSettings ().getCommandSettings ();
50
38
Command command = new CommandBuilder ()
51
39
.setName (commandSettings .getName ())
52
40
.setDescription (commandSettings .getDescription ())
53
41
.setUsage (commandSettings .getUsage ())
54
42
.addAliases (commandSettings .getAliases ())
43
+ .setPermission ("protocolvanish.use" )
55
44
.setPlugin (plugin )
56
- .setExecutor (this )
57
- .setTabCompleter (this )
58
- .addSubCommands (
59
- new SubCommandBuilder ()
60
- .setName (commandSettings .getSubCommandName ("toggleNightVision" ))
61
- .setExecutor (new ToggleNightVisionSub (plugin ))
62
- .addAliases (commandSettings .getSubCommandAliases ("toggleNightVision" )),
63
- new SubCommandBuilder ()
64
- .setName (commandSettings .getSubCommandName ("toggleDamage" ))
65
- .setExecutor (new ToggleDamageSub (plugin ))
66
- .addAliases (commandSettings .getSubCommandAliases ("toggleDamage" )),
67
- new SubCommandBuilder ()
68
- .setName (commandSettings .getSubCommandName ("toggleHunger" ))
69
- .setExecutor (new ToggleHungerSub (plugin ))
70
- .addAliases (commandSettings .getSubCommandAliases ("toggleHunger" )),
71
- new SubCommandBuilder ()
72
- .setName (commandSettings .getSubCommandName ("toggleCreatureTarget" ))
73
- .setExecutor (new ToggleCreatureTargetSub (plugin ))
74
- .addAliases (commandSettings .getSubCommandAliases ("toggleCreatureTarget" )),
75
- new SubCommandBuilder ()
76
- .setName (commandSettings .getSubCommandName ("toggleItemPickup" ))
77
- .setExecutor (new ToggleItemPickupSub (plugin ))
78
- .addAliases (commandSettings .getSubCommandAliases ("toggleItemPickup" ))
79
- ).build ();
80
- CommandInjector .injectCommand ("protocolvanish" , command , false );
81
- String [] subCommands = new String []{"toggleNightVision" , "toggleDamage" , "toggleHunger" , "toggleCreatureTarget" , "toggleItemPickup" };
82
- for (String subCommand : subCommands ) {
83
- if (commandSettings .isSubCommandEnabled (subCommand )) this .enabledSubCommands .add (subCommand );
84
- }
45
+ .setExecutor (this ).build ();
46
+ CommandInjector .injectCommand ("protocolvanish" , command , true );
85
47
}
86
48
87
49
@ Override
@@ -93,66 +55,24 @@ public boolean onCommand(CommandSender commandSender, Command command, String la
93
55
Player player = (Player ) commandSender ;
94
56
if (plugin .getPermissionManager ().hasPermissionToVanish (player )) {
95
57
VanishPlayer vanishPlayer = plugin .getVanishPlayer (player .getUniqueId ());
96
- if (vanishPlayer == null ) vanishPlayer = plugin . createVanishPlayer ( player ) ;
97
- if (args .length > 0 ){
98
- plugin .sendPlayerMessage (player , player ,"invalidUsage" );
58
+ if (vanishPlayer == null ) return false ;
59
+ if (args .length > 0 ) {
60
+ plugin .sendPlayerMessage (player , player , "invalidUsage" , null );
99
61
return false ;
100
62
}
101
63
if (vanishPlayer .isVanished ()) {
102
64
plugin .getVisibilityManager ().setVanished (player .getUniqueId (), false );
103
- plugin .sendPlayerMessage (player , player ,"onReappear" );
65
+ plugin .sendPlayerMessage (player , player , "onReappear" , null );
104
66
} else {
105
67
plugin .getVisibilityManager ().setVanished (player .getUniqueId (), true );
106
- plugin .sendPlayerMessage (player , player ,"onVanish" );
68
+ plugin .sendPlayerMessage (player , player , "onVanish" , null );
107
69
}
108
70
return true ;
109
71
} else {
110
- plugin .sendPlayerMessage (player , player , "noPermission" );
72
+ plugin .sendPlayerMessage (player , player , "noPermission" , null );
111
73
return false ;
112
74
}
113
75
}
114
76
return false ;
115
77
}
116
-
117
- @ Override
118
- public List <String > onTabComplete (CommandSender commandSender , Command command , String label , String [] args , Location location ) {
119
- if (!(commandSender instanceof Player ))return null ;
120
- Player player = (Player )commandSender ;
121
- if (args .length < 2 && plugin .getPermissionManager ().hasPermissionToVanish (player )){
122
- List <String > suggestions = new ArrayList <>();
123
- for (String subCommand : this .enabledSubCommands ){
124
- switch (subCommand ){
125
- case "toggleNightVision" :
126
- addSuggestions (subCommand , PermissionManager .Permission .CHANGE_NIGHT_VISION , player , suggestions );
127
- break ;
128
- case "toggleDamage" :
129
- addSuggestions (subCommand , PermissionManager .Permission .CHANGE_DAMAGE , player , suggestions );
130
- break ;
131
- case "toggleHunger" :
132
- addSuggestions (subCommand , PermissionManager .Permission .CHANGE_HUNGER , player , suggestions );
133
- break ;
134
- case "toggleCreatureTarget" :
135
- addSuggestions (subCommand , PermissionManager .Permission .CHANGE_CREATURE_TARGET , player , suggestions );
136
- break ;
137
- case "toggleItemPickup" :
138
- addSuggestions (subCommand , PermissionManager .Permission .CHANGE_ITEM_PICKUP , player , suggestions );
139
- break ;
140
- }
141
- }
142
- return StringUtil .copyPartialMatches (args [0 ], suggestions , new ArrayList <>());
143
- }
144
- return null ;
145
- }
146
-
147
- private void addSuggestions (String subCommand , PermissionManager .Permission permission , Player player , List <String > suggestionList ){
148
- if (plugin .getPermissionManager ().hasPermission (player , permission )){
149
- suggestionList .add (plugin .getSettingsManager ().getCommandSettings ().getSubCommandName (subCommand ));
150
- }
151
- }
152
-
153
- public void setEnabled (String subCommand , boolean enabled ) {
154
- if (enabled && !enabledSubCommands .contains (subCommand )) enabledSubCommands .add (subCommand );
155
- else if (!enabled ) enabledSubCommands .remove (subCommand );
156
- }
157
-
158
78
}
0 commit comments