Skip to content

Instantly share code, notes, and snippets.

@Exerosis
Created February 20, 2018 14:39
Show Gist options
  • Save Exerosis/b39f2a9c63f6b0a39be48ea1e6d6fff1 to your computer and use it in GitHub Desktop.
Save Exerosis/b39f2a9c63f6b0a39be48ea1e6d6fff1 to your computer and use it in GitHub Desktop.
try {
debugServer = new DebugServer(25566, 512);
} catch (IOException e) {
e.printStackTrace();
}
//--Toggle Plugins--
debugServer.respond(OP_TOGGLE, request -> {
byte count = request.get();
byte[] errors = new byte[count];
fill(errors, NONE.code);
for (int i = 0; i < count; i++) {
String name = getString(request);
long delay = request.getLong();
boolean unload = request.get() == 0;
try {
Plugin plugin = getPluginManager().getPlugin(name);
if (plugin == null)
errors[i] = NOT_FOUND.handle(name);
if (unload)
getPluginManager().enablePlugin(plugin);
else
getPluginManager().disablePlugin(plugin);
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
errors[i] = INTERRUPTED.handle(name);
}
} catch (Exception e) {
errors[i] = OTHER.handle(name);
}
}
return response -> response.put(errors);
});
//--List Plugins--
debugServer.respond(OP_LIST, request -> {
String filter = getString(request);
return response -> stream(Bukkit.getPluginManager().getPlugins())
.filter(plugin -> plugin.getName().contains(filter))
.forEach(plugin -> {
putString(response, plugin.getName());
response.put((byte) (plugin.isEnabled() ? 1 : 0));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment