mirror of
https://github.com/mingjun97/gc-mojoconsole-plus.git
synced 2024-11-27 20:18:07 +00:00
Adapt upstream breaking changes
* Update Readme * Introduce pop out browser option * Relocate static files
This commit is contained in:
parent
d997c5d3d8
commit
e3e09fb0ee
13
README.md
13
README.md
@ -31,19 +31,20 @@ See realeases.
|
||||
5. Navigate to your ``Grasscutter`` server, find the ``plugins`` folder and paste the ``mojoconsole.jar`` into it.
|
||||
6. Start your server.
|
||||
|
||||
7. Put the all the frontend files into the folder `GRASSCUTTER_RESOURCE/gcstatic/mojo/console.html`.
|
||||
...Jump to next section...
|
||||
|
||||
8. Send command `/mojoconsole` or `/mojo` to server in game, and you will receive mail in your mailbox. Then follow the instructions there.
|
||||
### Usage
|
||||
|
||||
7. Put the all the frontend files into the folder `GRASSCUTTER_RESOURCE/plugins/mojoconsole/`. Note that your must have `console.html` for now. You are free to put any other dynamiclly loaded file(e.g. `.js`, `.css`) in that folder. Check the last section for current avialable frontend.
|
||||
|
||||
8. Send command `/mojoconsole` or `/mojo` to server in game, and you will receive mail in your mailbox. Then follow the instructions there. Note that you may use `o` option to use the pop out browser instead of in-game webwiew, e.g. `/mojo o`. By default, the console is in-game webview.
|
||||
|
||||
Your final plugins folder's directory structure should look similar to this
|
||||
```
|
||||
plugins
|
||||
│ mojoconsole.jar
|
||||
│ ...
|
||||
resources
|
||||
└───gcstatic
|
||||
│ ...
|
||||
└───mojo
|
||||
└───mojoconsole
|
||||
│ console.html
|
||||
| ...
|
||||
└───any other file that you want to include in your frontend
|
||||
|
@ -4,9 +4,12 @@ import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.command.CommandMap;
|
||||
import emu.grasscutter.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.mojo.consoleplus.command.PluginCommand;
|
||||
|
||||
import express.Express;
|
||||
import io.javalin.http.staticfiles.Location;
|
||||
|
||||
public class ConsolePlus extends Plugin{
|
||||
@Override
|
||||
@ -17,8 +20,14 @@ public class ConsolePlus extends Plugin{
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Express app = Grasscutter.getDispatchServer().getServer();
|
||||
String folder_name = Grasscutter.getConfig().PLUGINS_FOLDER + "/mojoconsole/";
|
||||
File folder = new File(folder_name);
|
||||
if (!folder.exists()) {
|
||||
Grasscutter.getLogger().warn("To make mojo console works, you have to put your frontend file(console.html) inside" + folder.getAbsolutePath());
|
||||
folder.mkdirs();
|
||||
}
|
||||
app.post("/mojoplus/api", new RequestHandler());
|
||||
|
||||
app.raw().config.addStaticFiles("/mojoplus", folder_name, Location.EXTERNAL);
|
||||
CommandMap.getInstance().registerCommand("mojoconsole", new PluginCommand());
|
||||
Grasscutter.getLogger().info("mojo console enabled");
|
||||
}
|
||||
|
@ -44,7 +44,8 @@ public final class RequestHandler implements HttpContextHandler {
|
||||
switch (request.request){
|
||||
case "invoke":
|
||||
try{
|
||||
CommandMap.getInstance().invoke(player, request.payload);
|
||||
// TODO: Enable execut commands to third party
|
||||
CommandMap.getInstance().invoke(player, player, request.payload);
|
||||
} catch (Exception e) {
|
||||
res.json(new ResponseJson("error", 500, e.getStackTrace().toString()));
|
||||
break;
|
||||
|
@ -8,18 +8,25 @@ import emu.grasscutter.command.CommandHandler;
|
||||
import emu.grasscutter.game.mail.Mail;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
|
||||
@Command(label = "mojoconsole", usage = "mojoconsole", description = "Generate Mojoconsole link (no arguments required)", aliases = {
|
||||
@Command(label = "mojoconsole", usage = "mojoconsole", description = "Send Mojoconsole link via mail (by default it's in-game webview, but you may use argument `o` for popping out external browser)", aliases = {
|
||||
"mojo" }, permission = "mojo.console")
|
||||
public class PluginCommand implements CommandHandler {
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
Mail mail = new Mail();
|
||||
String link = getServerURL(sender.getAccount().getSessionKey());
|
||||
String link = getServerURL(targetPlayer.getAccount().getSessionKey());
|
||||
String link_type = "webview";
|
||||
Grasscutter.getLogger().info(link);
|
||||
if (args.size() > 0 && args.get(0).equals("o")) {
|
||||
link_type = "browser";
|
||||
}
|
||||
|
||||
mail.mailContent.title = "MojoConsole";
|
||||
mail.mailContent.sender = "MojoConsolePlus";
|
||||
mail.mailContent.content = "Here is your mojo console link: " +
|
||||
"<type=\"webview\" text=\"Mojo Console\" href=\"" + link + "\"/>" +
|
||||
"<type=\""+ link_type + "\" text=\"Mojo Console\" href=\"" + link + "\"/>" +
|
||||
"Note that the link will <b>expire</b> in some time, you may retrieve a new one after that.";
|
||||
sender.sendMail(mail);
|
||||
targetPlayer.sendMail(mail);
|
||||
CommandHandler.sendMessage(sender, "[MojoConsole] Link sent, check your mailbox");
|
||||
}
|
||||
|
||||
@ -32,6 +39,6 @@ public class PluginCommand implements CommandHandler {
|
||||
":"
|
||||
+ (Grasscutter.getConfig().getDispatchOptions().PublicPort != 0
|
||||
? Grasscutter.getConfig().getDispatchOptions().PublicPort
|
||||
: Grasscutter.getConfig().getDispatchOptions().Port) + "/gcstatic/mojo/console.html?k=" + sessionKey;
|
||||
: Grasscutter.getConfig().getDispatchOptions().Port) + "/mojoplus/console.html?k=" + sessionKey;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "mojoconsole-plus",
|
||||
"description": "Grasscutter In Game Web Based Console",
|
||||
"version": "dev-1.0.0",
|
||||
"version": "dev-1.0.1",
|
||||
|
||||
"mainClass": "com.mojo.consoleplus.ConsolePlus",
|
||||
"authors": ["mingjun97"]
|
||||
|
Loading…
Reference in New Issue
Block a user