package de.craften.plugins.rpgplus.scripting.api;

import org.bukkit.Effect;
import org.bukkit.Location;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.VarArgFunction;

import de.craften.plugins.rpgplus.RpgPlus;
import de.craften.plugins.rpgplus.scripting.ScriptingModule;
import de.craften.plugins.rpgplus.scripting.util.ScriptUtil;

public class ParticleModule extends LuaTable implements ScriptingModule{

	public ParticleModule(final RpgPlus plugin) {
		set("spawn", new VarArgFunction() {
			
			@Override
            public Varargs invoke(Varargs varargs) {
                
				Location loc = ScriptUtil.getLocation(varargs.arg(1));
				
				Effect effect = Effect.valueOf(varargs.arg(2).tojstring().toUpperCase());
				
				int id = varargs.toint(3);
				
				int data = varargs.toint(4);
				
				float offsetX = (float) varargs.optdouble(5, 0);
				float offsetY = (float) varargs.optdouble(6, 0);
				float offsetZ = (float) varargs.optdouble(7, 0);
				
				float speed = (float) varargs.optdouble(8, 0);
				
				int particleCount = varargs.optint(9, 1);
				
				int radius = varargs.optint(10, 100);
				
				loc.getWorld().spigot().playEffect(loc, effect, id, data, offsetX, offsetY, offsetZ, speed, particleCount, radius);
				
                return LuaValue.NIL;
            }
			
		});
	}
	
	@Override
	public LuaValue getModule() {
		return this;
	}

	@Override
	public void reset() {
		//nothing to do here
	}


}

@@ -197,49 +197,8 @@
 gs;%0D
-%0Aimport org.luaj.vm2.lib.VarArgFunction;%0D
 %0A%0D%0Ai
@@ -363,16 +363,151 @@
 ptUtil;%0D
+%0Aimport de.craften.plugins.rpgplus.scripting.util.luaify.LuaFunction;%0D%0Aimport de.craften.plugins.rpgplus.scripting.util.luaify.Luaify;%0D
 %0A%0D%0Apubli
@@ -572,16 +572,17 @@
 ngModule
+ 
 %7B%0D%0A%0D%0A%09pu
@@ -632,97 +632,86 @@
 %0D%0A%09%09
-set(%22spawn%22, new VarArgFunction() %7B%0D%0A%09%09%09%0D%0A%09%09%09@Override%0D%0A            public Varargs invoke
+Luaify.convertInPlace(this);%0D%0A%09%7D%0D%0A%0D%0A%09@LuaFunction(%22spawn%22)%0D%0A%09public void spawn
 (Var
@@ -731,28 +731,10 @@
  %7B%0D%0A
-                %0D%0A%09%09
+%0D%0A
 %09%09Lo
@@ -787,24 +787,18 @@
 g(1));%0D%0A
-%09%09%09%09%0D%0A%09%09
+%0D%0A
 %09%09Effect
@@ -813,16 +813,22 @@
 = Effect
+%0D%0A%09%09%09%09
 .valueOf
@@ -868,32 +868,26 @@
 erCase());%0D%0A
-%09%09%09%09%0D%0A%09%09
+%0D%0A
 %09%09int id = v
@@ -900,32 +900,26 @@
 .toint(3);%0D%0A
-%09%09%09%09%0D%0A%09%09
+%0D%0A
 %09%09int data =
@@ -934,32 +934,26 @@
 .toint(4);%0D%0A
-%09%09%09%09%0D%0A%09%09
+%0D%0A
 %09%09float offs
@@ -988,26 +988,24 @@
 ble(5, 0);%0D%0A
-%09%09
 %09%09float offs
@@ -1042,26 +1042,24 @@
 e(6, 0);%0D%0A%09%09
-%09
-%09
 float offset
@@ -1096,24 +1096,18 @@
 7, 0);%0D%0A
-%09%09%09%09%0D%0A%09%09
+%0D%0A
 %09%09float 
@@ -1144,32 +1144,26 @@
 ble(8, 0);%0D%0A
-%09%09%09%09%0D%0A%09%09
+%0D%0A
 %09%09int partic
@@ -1195,24 +1195,18 @@
 9, 1);%0D%0A
-%09%09%09%09%0D%0A%09%09
+%0D%0A
 %09%09int ra
@@ -1242,16 +1242,10 @@
 );%0D%0A
-%09%09%09%09%0D%0A%09%09
+%0D%0A
 %09%09lo
@@ -1256,16 +1256,22 @@
 tWorld()
+%0D%0A%09%09%09%09
 .spigot(
@@ -1271,16 +1271,22 @@
 spigot()
+%0D%0A%09%09%09%09
 .playEff
@@ -1338,17 +1338,24 @@
 offsetZ,
- 
+%0D%0A%09%09%09%09%09%09
 speed, p
@@ -1382,84 +1382,14 @@
 );%0D%0A
-%09%09%09%09%0D%0A                return LuaValue.NIL;%0D%0A            %7D%0D%0A%09%09%09%0D%0A%09%09%7D);
 %0D%0A%09%7D%0D%0A
-%09
 %0D%0A%09@
@@ -1492,16 +1492,17 @@
  %7B%0D%0A%09%09//
+ 
 nothing 
@@ -1519,13 +1519,11 @@
 %0D%0A%09%7D%0D%0A%0D%0A
-%0D%0A
 %7D%0D%0A

Use the lua annotations to register the functions.