Getting Started

To run a simple, single line of Java code, you can use


/x <java code>


For example, you could do things like:


/x 2 + 2
/x 17 ^ 2
/x Bukkit.getPlayer("jojodmo").kickPlayer("I love MCJava")
/x Bukkit.getPlayer("jojodmo").getInventory().setItemInHand(makeItem(Material.DIAMOND, 32))


But, keep in mind that doing this has no "memory", and everything you type is instant. If you want to get more control, you should open up a console using /x open (or /mcjava console). Inside of this console, you can save things to variables, or even load a class that MCJava doesn't have enabled by default.

For example, after opening a console with /x open, you could type:


bukkit.broadcastMessage("A random player is being chosen to get some diamonds. And the winner is...")

loadClass("math", "java.lang.Math")
onlinePlayers = Bukkit.getOnlinePlayers()
randomPlayer = onlinePlayers.get(math.random() * (onlinePlayers.length - 1))

loadClass("integerAlias", "java.lang.Integer")
amount = integerAlias.valueOf("3f", 16)

item = makeItem(Material.DIAMOND, amount)
meta = item.getItemMeta()
meta.setDisplayName("Randomly Won Diamonds, Wow!")
item.setItemMeta(meta)

randomPlayer.getInventory().setItemInMainHand(item)

bukkit.broadcastMessage(randomPlayer.getName())


This will pick a random player that's online, and change the item in their main hand to 63 diamonds named "Randomly Won Diamonds, Wow!". It'll also broadcast the message to the server

Obviously, you don't always have to write this much if you don't want to — this is just an example. If you just want to pick a random player and set the item in their main hand to 63 diamonds, you could also just do


loadClass("math", "java.lang.Math")
randomPlayer = Bukkit.getOnlinePlayers().get(math.random() * (Bukkit.getOnlinePlayers().length - 1))
item = makeItem(Material.DIAMOND, 63)
randomPlayer.getInventory().setItemInMainHand(item)