Sueta
LU

LuaJ for Spigot

1.0.0

Create and Edit your LuaJ Plugins on-the-fly!

·Plugin

LuaJ for Spigot is exactly how it sounds. It's an implementation of LuaJ for Spigot Minecraft servers and works by running all of the `.lua` scripts in the `lua` directory in alphabetical order.

-- 
-- Simulate the peaceful surface mod by disallowing hostile spawns in any light level above absolute 0 
-- 
events.register("entity.CreatureSpawnEvent", function(event) 
    local mob = event:getEntity() 
    local kind = mob:getType() 

    local condition = 
      kind == EntityType.ZOMBIE or 
      kind == EntityType.SKELETON or 
      kind == EntityType.CREEPER or 
      kind == EntityType.SPIDER 

    if condition 
    then 
        -- 
        -- Remove any of the mobs defined above if the light level is NOT zero 
        -- 
        if mob:getLocation():getBlock():getLightLevel() ~= 0 
        then 
            mob:remove() 
        end 
    end 
end)

Bundled with the plugin is a handful of examples showing how powerful LuaJ can be when used to script a Spigot Minecraft server. The included examples show how to register event handlers, add custom recipes, and add desired features like controlling mob spawning conditions, adding additional mob item drops, and functional gravel sieves.

Please read through the included examples as they are thoroughly commented. This plugin is intended for those who are already familiar with the CraftBukkit API and the Lua language.

For more information on what LuaJ ( www.luaj.org ) can do, please refer to http://www.luaj.org/luaj/3.0/README.html . LuaJ is a powerful implementation of the Lua language in Java that can be used to access (and program using) most of the features Java has without compiling bytecode. You can create fully-fledged Java AWT interfaces using LuaJ alone!

The Java source of the LuaJ plugin for Spigot is not included because the JavaPlugin class is only used briefly to create the Lua bridge and run the individual scripts:

public   class  Plugin  extends  JavaPlugin 
 {  
     private   static  Plugin self  ;  
    
     public   static  Plugin getInstance  (   )  
     {  
         if   (  self  ==   null   )  
             throw   new    RuntimeException    (   "Plugin.getInstance() returned null."   )   ;  

         return  self  ;  
     }  

    @Override 
     public   void  onEnable  (   )  
     {  
        self  =   this   ;  
        Globals 
            g  =  JsePlatform.  standardGlobals   (   )   ;  
            g.  set   (   "Plugin"  , CoerceJavaToLua.  coerce   (   this   )   )   ;  
            g.  set   (   "PluginExtras"  , PluginExtras.  getTable   (   )   )   ;  
        
         if   (   !  IO.  isDirectory   (   "lua"   )   )  
         {  
              System   .  out  .  println   (   "The 'lua' directory was not found. Creating the 'lua' directory..."   )   ;  
            IO.  makePaths   (   "lua"   )   ;  
         }  
        
         for   (    String   fname  :  IO.  list   (   "lua"   )   )  
         {  
              System   .  out  .  println   (  
                  String   .  format   (  
                     "Executing lua script '%s'..."  , 
                    fname  )   )   ;  
            
            g.  set   (   "_fname"  , fname  )   ;  
            
              String   data  =  IO.  read   (  fname  )   ;  
            
            LuaValue 
                v  =  g.  load   (  data  )   ;  
                v.  call   (   )   ;  
         }  
     }  

    @Override 
     public   void  onDisable  (   )  
     {  
     }  
 }

Similar projects

Plugin →