Search in sources :

Example 1 with ScriptEditor

use of io.github.wysohn.triggerreactor.tools.ScriptEditor in project TriggerReactor by wysohn.

the class ScriptEditManager method startEdit.

@Override
public void startEdit(ICommandSender sender, String title, String script, SaveHandler saveHandler) {
    ConversationFactory factory = new ConversationFactory(plugin.getMain());
    EditingPrompt prompt = new EditingPrompt(plugin.getMain(), sender.get(), new ScriptEditor(title, script, saveHandler));
    Conversation conv = factory.thatExcludesNonPlayersWithMessage("Sorry, this is in-game only feature!").withFirstPrompt(new UsagePrompt(prompt)).addConversationAbandonedListener(this).buildConversation(sender.get());
    conv.getContext().setSessionData("edit", prompt);
    conv.begin();
}
Also used : EditingPrompt(io.github.wysohn.triggerreactor.bukkit.tools.prompts.EditingPrompt) UsagePrompt(io.github.wysohn.triggerreactor.bukkit.tools.prompts.UsagePrompt) ConversationFactory(org.bukkit.conversations.ConversationFactory) Conversation(org.bukkit.conversations.Conversation) ScriptEditor(io.github.wysohn.triggerreactor.tools.ScriptEditor)

Example 2 with ScriptEditor

use of io.github.wysohn.triggerreactor.tools.ScriptEditor in project TriggerReactor by wysohn.

the class ScriptEditManager method onChat.

@Listener
public void onChat(MessageChannelEvent.Chat e, @First MessageReceiver receiver) {
    if (!editings.containsKey(receiver))
        return;
    e.setCancelled(true);
    ScriptEditor editor = editings.get(receiver);
    Text message = e.getRawMessage();
    String arg1 = message.toPlainSingle();
    if (arg1.equals("save")) {
        try {
            editor.save();
        } catch (IOException | ScriptException ex) {
            plugin.handleException(e, ex);
        }
        editings.remove(receiver);
    } else if (arg1.equals("exit")) {
        editings.remove(receiver);
    } else if (arg1.equals("il")) {
        editor.insertNewLine();
    } else if (arg1.equals("dl")) {
        editor.deleteLine();
    } else if (arg1.length() > 0 && arg1.charAt(0) == 'u') {
        String[] split = arg1.split(" ");
        int lines = 1;
        try {
            lines = split.length > 1 ? Integer.parseInt(split[1]) : 1;
        } catch (NumberFormatException ex) {
            plugin.handleException(e, ex);
        }
        editor.up(lines);
    } else if (arg1.length() > 0 && arg1.charAt(0) == 'd') {
        String[] split = arg1.split(" ");
        int lines = 1;
        try {
            lines = split.length > 1 ? Integer.parseInt(split[1]) : 1;
        } catch (NumberFormatException ex) {
            plugin.handleException(e, ex);
        }
        editor.down(lines);
    } else {
        editor.intput(arg1.replaceAll("\\$", " "));
    }
}
Also used : ScriptException(javax.script.ScriptException) Text(org.spongepowered.api.text.Text) IOException(java.io.IOException) ScriptEditor(io.github.wysohn.triggerreactor.tools.ScriptEditor) Listener(org.spongepowered.api.event.Listener)

Example 3 with ScriptEditor

use of io.github.wysohn.triggerreactor.tools.ScriptEditor in project TriggerReactor by wysohn.

the class ScriptEditManager method startEdit.

@Override
public void startEdit(ICommandSender sender, String title, String script, SaveHandler saveHandler) {
    if (editings.containsKey(sender))
        return;
    ScriptEditor editor = new ScriptEditor(title, script, saveHandler);
    editings.put(sender, editor);
}
Also used : ScriptEditor(io.github.wysohn.triggerreactor.tools.ScriptEditor)

Aggregations

ScriptEditor (io.github.wysohn.triggerreactor.tools.ScriptEditor)3 EditingPrompt (io.github.wysohn.triggerreactor.bukkit.tools.prompts.EditingPrompt)1 UsagePrompt (io.github.wysohn.triggerreactor.bukkit.tools.prompts.UsagePrompt)1 IOException (java.io.IOException)1 ScriptException (javax.script.ScriptException)1 Conversation (org.bukkit.conversations.Conversation)1 ConversationFactory (org.bukkit.conversations.ConversationFactory)1 Listener (org.spongepowered.api.event.Listener)1 Text (org.spongepowered.api.text.Text)1