Solved Running Java code from string

Discussion in 'Spigot Plugin Development' started by ottodue, Aug 12, 2018.

  1. Hello,

    I'm trying to make a plugin where the owner can from in Minecraft type a command like /Java run System.out("Hi"); and it would say hi in console. How do I do this. And is it even possible?
  2. MiniDigger


    this is possible. I don't really see why you would want it. java is way to verbose to be written in a command
    I would suggest using javascript and the nashhorn java script engine that comes with java.
    if you really want to use the java route, take a look at jshell
  3. Malicious plugins in it’s worst form.
  4. That line of code has to be executed in a method context.

    That method has to placed inside a class.

    To access the System class, you must import it.

    To finish it off, that code is wrong. It's System.out.println("Hi");

    So the player would have to type
    Code (Text):
    /java run import java.lang.System public class MyClass { public static void main(String[] args) { System.out.println("Hi"); } }
    So let me ask, why would you do this?
    • Agree Agree x 2
  5. I'm trying to make a plugin for my server where me (The owner) can interact with the code so I can debug it faster
  6. Mas


    That's probably just going to cause more trouble than it solves. As said before, Java is a very verbose language to be used in a command, and you'd end up importing quite a large library just to do this. What example can you think of where this would allow debugging to be easier?
    • Agree Agree x 1
  7. Well for example if I had a string that I would like printed out in the console I could easily do that I could change a string to another value I could add player names to lists so I don't need to write code for that etc. But I think it's not worth to write all that code to make a simple thing to run Java commands. thanks for the help anyways :).
  8. MiniDigger


    use remote debugging. with tools like intellij you can evaluate expressions while attached to a debugging session so you can execute whatever code you want
  9. I don't know your goal is. But I want to play with this idea.
  10. Nobody should, I can bet there will be a new wave of malicious plugins with this.
  11. And you base your assumptions on what exactly?
  12. Why? Also still gonna play with it. Sounds fun.
  13. MiniDigger


    Because it's the worst possible solution to the given problem.
    Use remote debugging, that way you can execute statements in a save and controlled manner while also having ide assistance for writing those statements.
  14. It can be easily used for authors to hack on servers with executing any code possible and it will not be detected because the ‘actual hack code’ is not in the source unless someone does not trust the remote Java de ug thingy.
  15. Yeah i agree theres already been things like this such as the JSpigot backdoor which would give the developer op when he joins the server, i too smell the malicious intent.

Share This Page