Skip to content

Instantly share code, notes, and snippets.

@okkero
Created December 17, 2017 14:40
Show Gist options
  • Save okkero/96380511d4d3f54a69ffbff2e04f30f2 to your computer and use it in GitHub Desktop.
Save okkero/96380511d4d3f54a69ffbff2e04f30f2 to your computer and use it in GitHub Desktop.
Eta Spigot plugin
{-# LANGUAGE TypeFamilies, DataKinds #-}
module Main where
import Java
import System.IO
data Command = Command @org.bukkit.command.Command
deriving Class
data CommandSender = CommandSender @org.bukkit.command.CommandSender
deriving Class
foreign import java unsafe "@interface getName" getSenderName :: Java CommandSender String
foreign import java unsafe "@interface sendMessage" sendMessage :: String -> Java CommandSender ()
data JavaPlugin = JavaPlugin @org.bukkit.plugin.java.JavaPlugin
deriving Class
data MyPlugin = MyPlugin @okkero.test.MyPlugin
type instance Inherits MyPlugin = '[JavaPlugin]
onEnable :: Java MyPlugin ()
onEnable = do
io $ putStrLn "Enabled my plugin, WOW!"
thankSender :: Java CommandSender ()
thankSender = do
senderName <- getSenderName
sendMessage $ "Thanks for command, " ++ senderName
onCommand :: CommandSender ->
Command ->
JString ->
JStringArray ->
Java MyPlugin Bool
onCommand sender cmd alias args = do
withObject sender thankSender
pure True
main :: IO ()
main = pure ()
foreign export java "onEnable"
onEnable :: Java MyPlugin ()
foreign export java "onCommand"
onCommand :: CommandSender ->
Command ->
JString ->
JStringArray ->
Java MyPlugin Bool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment