Skip to content

Commit 9a6d471

Browse files
committed
Command autocomplete
Also fixes the clickable for /awf world in the help menu. Previously was running /awf remove world.
1 parent 12a8cbc commit 9a6d471

4 files changed

Lines changed: 58 additions & 9 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.hm.antiworldfly</groupId>
55
<artifactId>AntiWorldFly</artifactId>
6-
<version>2.5.2</version>
6+
<version>2.5.3</version>
77
<url>https://github.com/PyvesB/AntiWorldFly</url>
88
<name>AntiWorldFly</name>
99
<description>A Minecraft plugin to disable flying and chosen commands when joining or playing in specific worlds.</description>

src/main/java/com/hm/antiworldfly/AntiWorldFly.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.logging.Level;
66
import java.util.logging.Logger;
77

8+
import com.hm.antiworldfly.command.CommandsTab;
89
import com.hm.antiworldfly.listener.*;
910
import com.hm.antiworldfly.worldguard.FlagRegistry;
1011
import com.hm.antiworldfly.worldguard.listener.PlayerMove;
@@ -40,9 +41,8 @@
4041
* Spigot project page: spigotmc.org/resources/anti-world-fly.5357
4142
*
4243
* @since March 2015.
43-
* @version 2.5.0
44-
* @author DarkPyves
45-
* @maintainer Sidpatchy
44+
* @version 2.5.3
45+
* @author DarkPyves, Sidpatchy
4646
*/
4747

4848
public class AntiWorldFly extends JavaPlugin {
@@ -143,10 +143,6 @@ public void onEnable() {
143143

144144
PluginManager pm = getServer().getPluginManager();
145145

146-
System.out.println(awfToggleGlide);
147-
System.out.println(awfPlayerMove);
148-
System.out.println(awfRegionToggleGlide);
149-
150146
pm.registerEvents(awfPreProcess, this);
151147
pm.registerEvents(awfWorldJoin, this);
152148
pm.registerEvents(awfPlayerJoin, this);
@@ -172,6 +168,7 @@ public void onEnable() {
172168

173169
helpCommand = new HelpCommand(this);
174170
infoCommand = new InfoCommand(this);
171+
this.getCommand("antiworldfly").setTabCompleter(new CommandsTab(this));
175172

176173
if (bStatsEnabled) {
177174
bStats();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.hm.antiworldfly.command;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.World;
5+
import org.bukkit.command.Command;
6+
import org.bukkit.command.CommandSender;
7+
import org.bukkit.command.TabCompleter;
8+
import org.bukkit.configuration.file.FileConfiguration;
9+
import com.hm.antiworldfly.AntiWorldFly;
10+
import java.util.Arrays;
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
public class CommandsTab implements TabCompleter {
15+
private final AntiWorldFly plugin;
16+
17+
public CommandsTab(AntiWorldFly plugin) {
18+
this.plugin = plugin;
19+
}
20+
21+
@Override
22+
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
23+
List<String> cmdlist = new ArrayList<String>();
24+
FileConfiguration config = plugin.getConfig();
25+
26+
if (args.length == 1) {
27+
cmdlist.add("help");
28+
cmdlist.add("info");
29+
if (sender.hasPermission("antiworldfly.use")) {
30+
cmdlist.addAll(Arrays.asList("reload", "disable", "enable", "add", "remove", "world"));
31+
}
32+
} else if (args.length == 2 && sender.hasPermission("antiworldfly.use")) {
33+
String input = args[1].toLowerCase();
34+
35+
if (args[0].equalsIgnoreCase("add")) {
36+
for (World world : Bukkit.getWorlds()) {
37+
String worldName = world.getName();
38+
if (worldName.toLowerCase().startsWith(input)) {
39+
cmdlist.add(worldName);
40+
}
41+
}
42+
} else if (args[0].equalsIgnoreCase("remove")) {
43+
for (String worldName : config.getStringList("antiFlyWorlds")) {
44+
if (worldName.toLowerCase().startsWith(input)) {
45+
cmdlist.add(worldName);
46+
}
47+
}
48+
}
49+
}
50+
return cmdlist.isEmpty() ? null : cmdlist;
51+
}
52+
}

src/main/java/com/hm/antiworldfly/command/HelpCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void getHelp(CommandSender sender) {
9090
+ ChatColor.WHITE + " > "
9191
+ plugin.getPluginLang().getString("awf-command-world", "Display the world you are standing in.")
9292
.replace("WORLD", "world"),
93-
"/awf remove world",
93+
"/awf world",
9494
plugin.getPluginLang().getString("awf-command-remove-hover", "World must be listed in /awf list."));
9595
}
9696

0 commit comments

Comments
 (0)