• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SimplyVanilla / SimplyPerms / #12

11 Mar 2024 09:32AM UTC coverage: 28.261% (-0.5%) from 28.729%
#12

push

github

web-flow
Fix velocity crash #2 (#7)

* Fixed [Velocity crash](https://gist.github.com/Netherwhal/5e37bd8a1656dbb9ac8cc88530144a65) happening when users in list are null

* Added forced stack trace to individuate error on Velocity restart

0 of 4 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

52 of 184 relevant lines covered (28.26%)

0.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/net/simplyvanilla/simplyperms/listeners/CommandListener.java
1
package net.simplyvanilla.simplyperms.listeners;
2

3
import com.velocitypowered.api.command.CommandSource;
4
import com.velocitypowered.api.event.Subscribe;
5
import com.velocitypowered.api.event.command.CommandExecuteEvent;
6
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent;
7
import com.velocitypowered.api.event.player.TabCompleteEvent;
8
import com.velocitypowered.api.proxy.Player;
9
import net.simplyvanilla.simplyperms.SimplyPerms;
10
import net.kyori.adventure.text.Component;
11
import net.kyori.adventure.text.format.NamedTextColor;
12

13
public class CommandListener {
14
    private final SimplyPerms plugin;
15

16
    public CommandListener(SimplyPerms plugin) {
×
17
        this.plugin = plugin;
×
18
    }
×
19

20
    @Subscribe
21
    public void on(CommandExecuteEvent event) {
22
        String command = getCommand(event.getCommand());
×
23
        if (cannotExecute(event.getCommandSource(), command)) {
×
24
            event.setResult(CommandExecuteEvent.CommandResult.denied());
×
25
            event.getCommandSource().sendMessage(Component
×
26
                    .translatable("velocity.command.command-does-not-exist")
×
27
                    .color(NamedTextColor.RED));
×
28
        }
29
    }
×
30

31
    @Subscribe
32
    @SuppressWarnings("UnstableApiUsage")
33
    public void on(PlayerAvailableCommandsEvent event) {
34
        try {
NEW
35
            event.getRootNode().getChildren().removeIf((commandNode) ->
×
36
                cannotExecute(event.getPlayer(), commandNode.getName()));
×
NEW
37
        } catch (Exception e) {
×
NEW
38
            e.printStackTrace();
×
NEW
39
        }
×
UNCOV
40
    }
×
41

42
    @Subscribe
43
    public void on(TabCompleteEvent event) {
44
        if (cannotExecute(event.getPlayer(), event.getPartialMessage()))
×
45
            event.getSuggestions().clear();
×
46
    }
×
47

48
    private boolean cannotExecute(CommandSource source, String command) {
49
        String cmd = getCommand(command);
×
50
        if (!(source instanceof Player)) return false;
×
51
        if (this.plugin.getProxyServer().getCommandManager().getCommandMeta(cmd) == null) return false;
×
52
        return this.plugin.getAllowedCommands().stream().noneMatch(c -> c.equalsIgnoreCase(getCommand(cmd)));
×
53
    }
54

55
    private String getCommand(String raw) {
56
        if (raw == null) return "";
×
57
        while (raw.startsWith("/")) raw = raw.substring(1);
×
58
        return raw.split(" ")[0];
×
59
    }
60
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc