-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from gnmyt/features/plugins-description
🔌 Added the plugin feature & added a description
- Loading branch information
Showing
4 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/de/gnmyt/mcdash/panel/routes/plugin/PluginListRoute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package de.gnmyt.mcdash.panel.routes.plugin; | ||
|
||
import de.gnmyt.mcdash.api.handler.DefaultHandler; | ||
import de.gnmyt.mcdash.api.http.ContentType; | ||
import de.gnmyt.mcdash.api.http.Request; | ||
import de.gnmyt.mcdash.api.http.ResponseController; | ||
import de.gnmyt.mcdash.api.json.ArrayBuilder; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
public class PluginListRoute extends DefaultHandler { | ||
|
||
@Override | ||
public String path() { | ||
return "list"; | ||
} | ||
|
||
/** | ||
* Gets all plugins of the server | ||
* @param request The request object from the HttpExchange | ||
* @param response The response controller from the HttpExchange | ||
*/ | ||
@Override | ||
public void get(Request request, ResponseController response) throws Exception { | ||
|
||
ArrayBuilder builder = new ArrayBuilder(); | ||
|
||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { | ||
builder.addNode() | ||
.add("name", plugin.getName()) | ||
.add("author", plugin.getDescription().getAuthors().size() == 0 ? null : plugin.getDescription().getAuthors().get(0)) | ||
.add("description", plugin.getDescription().getDescription()) | ||
.add("path", plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getFile()) | ||
.add("enabled", plugin.isEnabled()) | ||
.register(); | ||
} | ||
|
||
response.type(ContentType.JSON).text(builder.toJSON()); | ||
} | ||
|
||
} |
92 changes: 92 additions & 0 deletions
92
src/main/java/de/gnmyt/mcdash/panel/routes/plugin/PluginRoute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package de.gnmyt.mcdash.panel.routes.plugin; | ||
|
||
import de.gnmyt.mcdash.api.handler.DefaultHandler; | ||
import de.gnmyt.mcdash.api.http.Request; | ||
import de.gnmyt.mcdash.api.http.ResponseController; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
public class PluginRoute extends DefaultHandler { | ||
|
||
/** | ||
* Gets a plugin by name | ||
* @param request The request object from the HttpExchange | ||
* @param response The response controller from the HttpExchange | ||
*/ | ||
@Override | ||
public void get(Request request, ResponseController response) throws Exception { | ||
if (!isStringInQuery("name")) return; | ||
|
||
String pluginName = getStringFromQuery("name"); | ||
|
||
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); | ||
|
||
if (plugin == null) { | ||
response.code(404).message("Plugin not found"); | ||
return; | ||
} | ||
|
||
String filePath = plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getFile(); | ||
String author = plugin.getDescription().getAuthors().size() == 0 ? null : plugin.getDescription().getAuthors().get(0); | ||
|
||
response.json("name=\""+plugin.getName()+"\"", "author=\""+author+"\"", | ||
"description=\""+plugin.getDescription().getDescription()+"\"", "path=\""+filePath+"\"", "enabled="+plugin.isEnabled()); | ||
} | ||
|
||
/** | ||
* Enables a plugin | ||
* @param request The request object from the HttpExchange | ||
* @param response The response controller from the HttpExchange | ||
*/ | ||
@Override | ||
public void post(Request request, ResponseController response) throws Exception { | ||
if (!isStringInBody("name")) return; | ||
|
||
String pluginName = getStringFromBody("name"); | ||
|
||
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); | ||
|
||
if (plugin == null) { | ||
response.code(404).message("Plugin not found"); | ||
return; | ||
} | ||
|
||
runSync(() -> { | ||
try { | ||
Bukkit.getPluginManager().enablePlugin(plugin); | ||
response.message("Plugin successfully enabled"); | ||
} catch (Exception e) { | ||
response.code(500).message("Could not enable the plugin"); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Disables a plugin | ||
* @param request The request object from the HttpExchange | ||
* @param response The response controller from the HttpExchange | ||
*/ | ||
@Override | ||
public void delete(Request request, ResponseController response) throws Exception { | ||
if (!isStringInBody("name")) return; | ||
|
||
String pluginName = getStringFromBody("name"); | ||
|
||
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); | ||
|
||
if (plugin == null) { | ||
response.code(404).message("Plugin not found"); | ||
return; | ||
} | ||
|
||
runSync(() -> { | ||
try { | ||
Bukkit.getPluginManager().disablePlugin(plugin); | ||
response.message("Plugin successfully disabled"); | ||
} catch (Exception e) { | ||
response.code(500).message("Could not disable the plugin"); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
name: MinecraftDashboard | ||
main: de.gnmyt.mcdash.MinecraftDashboard | ||
version: 1.0-SNAPSHOT | ||
description: This is the official plugin (wrapper) for MCDash, a free and open-source minecraft dashboard. | ||
author: GNMYT |