mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-22 01:55:47 +01:00
Add ability to detection level in /viaversion displayleaks (#3934)
This commit is contained in:
parent
1039b8556b
commit
72cc9e9968
@ -20,11 +20,14 @@ package com.viaversion.viaversion.commands.defaultsubs;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.api.command.ViaSubCommand;
|
||||
import io.netty.util.ResourceLeakDetector;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DisplayLeaksSubCmd implements ViaSubCommand {
|
||||
@Override
|
||||
public String name() {
|
||||
return "displayleaks";
|
||||
return "displayleaks <level>";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,12 +37,28 @@ public class DisplayLeaksSubCmd implements ViaSubCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(ViaCommandSender sender, String[] args) {
|
||||
if (ResourceLeakDetector.getLevel() != ResourceLeakDetector.Level.PARANOID)
|
||||
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
|
||||
else
|
||||
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
|
||||
|
||||
sendMessage(sender, "&6Leak detector is now %s", (ResourceLeakDetector.getLevel() == ResourceLeakDetector.Level.PARANOID ? "&aenabled" : "&cdisabled"));
|
||||
if (args.length == 1) {
|
||||
try {
|
||||
ResourceLeakDetector.Level level = ResourceLeakDetector.Level.valueOf(args[0]);
|
||||
ResourceLeakDetector.setLevel(level);
|
||||
sendMessage(sender, "&6Set leak detector level to &2" + level);
|
||||
} catch (IllegalArgumentException e) {
|
||||
sendMessage(sender, "&cInvalid level (" + Arrays.toString(ResourceLeakDetector.Level.values()) + ")");
|
||||
}
|
||||
} else {
|
||||
sendMessage(sender, "&6Current leak detection level is &2" + ResourceLeakDetector.getLevel());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(ViaCommandSender sender, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return Arrays.stream(ResourceLeakDetector.Level.values())
|
||||
.map(Enum::name)
|
||||
.filter(it -> it.startsWith(args[0]))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return ViaSubCommand.super.onTabComplete(sender, args);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user