mirror of
https://github.com/kaboomserver/extras.git
synced 2025-01-08 23:48:14 +00:00
Fixed tab completion for /deop and /op (#299)
This commit is contained in:
parent
e22044a158
commit
4e5e257534
3 changed files with 81 additions and 0 deletions
|
@ -36,6 +36,7 @@ import pw.kaboom.extras.modules.player.PlayerInteract;
|
||||||
import pw.kaboom.extras.modules.player.PlayerRecipe;
|
import pw.kaboom.extras.modules.player.PlayerRecipe;
|
||||||
import pw.kaboom.extras.modules.player.PlayerTeleport;
|
import pw.kaboom.extras.modules.player.PlayerTeleport;
|
||||||
import pw.kaboom.extras.modules.server.ServerCommand;
|
import pw.kaboom.extras.modules.server.ServerCommand;
|
||||||
|
import pw.kaboom.extras.modules.server.ServerTabComplete;
|
||||||
import pw.kaboom.extras.modules.server.ServerTick;
|
import pw.kaboom.extras.modules.server.ServerTick;
|
||||||
|
|
||||||
public final class Main extends JavaPlugin {
|
public final class Main extends JavaPlugin {
|
||||||
|
@ -97,6 +98,7 @@ public final class Main extends JavaPlugin {
|
||||||
|
|
||||||
/* Server-related modules */
|
/* Server-related modules */
|
||||||
this.getServer().getPluginManager().registerEvents(new ServerCommand(), this);
|
this.getServer().getPluginManager().registerEvents(new ServerCommand(), this);
|
||||||
|
this.getServer().getPluginManager().registerEvents(new ServerTabComplete(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new ServerTick(), this);
|
this.getServer().getPluginManager().registerEvents(new ServerTick(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.destroystokyo.paper.profile.ProfileProperty;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
|
||||||
import pw.kaboom.extras.Main;
|
import pw.kaboom.extras.Main;
|
||||||
|
import pw.kaboom.extras.modules.server.ServerTabComplete;
|
||||||
|
|
||||||
public final class PlayerConnection implements Listener {
|
public final class PlayerConnection implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -61,6 +62,8 @@ public final class PlayerConnection implements Listener {
|
||||||
fadeOut
|
fadeOut
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerTabComplete.getLoginNameList().put(player.getUniqueId(), player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -105,6 +108,7 @@ public final class PlayerConnection implements Listener {
|
||||||
void onPlayerQuit(final PlayerQuitEvent event) {
|
void onPlayerQuit(final PlayerQuitEvent event) {
|
||||||
PlayerCommand.getCommandMillisList().remove(event.getPlayer().getUniqueId());
|
PlayerCommand.getCommandMillisList().remove(event.getPlayer().getUniqueId());
|
||||||
//PlayerInteract.interactMillisList.remove(event.getPlayer().getUniqueId());
|
//PlayerInteract.interactMillisList.remove(event.getPlayer().getUniqueId());
|
||||||
|
ServerTabComplete.getLoginNameList().remove(event.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package pw.kaboom.extras.modules.server;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
||||||
|
|
||||||
|
public final class ServerTabComplete implements Listener {
|
||||||
|
private static HashMap<UUID, String> loginNameList = new HashMap<UUID, String>();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
void onAsyncTabComplete(final AsyncTabCompleteEvent event) {
|
||||||
|
final String[] arr = event.getBuffer().split(" ", 2);
|
||||||
|
|
||||||
|
// Vanilla clients will not send tab complete requests on the first word, but modified or bot clients may
|
||||||
|
if (arr.length < 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String command = arr[0];
|
||||||
|
String argsFragment = arr[1];
|
||||||
|
if (command.startsWith("/")) {
|
||||||
|
command = command.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.equalsIgnoreCase("op")) {
|
||||||
|
event.setCompletions(getOpCompletions(argsFragment));
|
||||||
|
} else if (command.equalsIgnoreCase("deop")) {
|
||||||
|
event.setCompletions(getDeopCompletions(argsFragment));
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getCompletions().size() == 0) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<String> getOpCompletions(final String argsFragment) {
|
||||||
|
ArrayList<String> deops = new ArrayList<String>();
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (!player.isOp()) {
|
||||||
|
String loginName = loginNameList.get(player.getUniqueId());
|
||||||
|
if (loginName != null && loginName.startsWith(argsFragment)) {
|
||||||
|
deops.add(loginName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deops;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<String> getDeopCompletions(final String argsFragment) {
|
||||||
|
ArrayList<String> ops = new ArrayList<String>();
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (player.isOp()) {
|
||||||
|
String loginName = loginNameList.get(player.getUniqueId());
|
||||||
|
if (loginName != null && loginName.startsWith(argsFragment)) {
|
||||||
|
ops.add(loginName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ops;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<UUID, String> getLoginNameList() {
|
||||||
|
return loginNameList;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue