Jump to content

[Share] Script Handlers


Recommended Posts

This isnt an event, nor a fantastic npc or voiced command

Its an abstract engine which will allow you to add customize code to many parts of the game where only core mod was the way.

With this, you can modify the most used core parts without touch it (which reduce sync problems)

PD: The code there in the script is just a sample so you can follow it to do whatever you want

PD2: Ofc, the engine can be extended to be called in more placed according to your needs

 

Core patch

Index: java/com/l2jserver/gameserver/handler/IScriptHandler.java
===================================================================
--- java/com/l2jserver/gameserver/handler/IScriptHandler.java	(revision 0)
+++ java/com/l2jserver/gameserver/handler/IScriptHandler.java	(revision 0)
@@ -0,0 +1,29 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.gameserver.handler;
+
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public interface IScriptHandler
+{
+	public CallSite getCallSite();
+	public void execute(L2PcInstance activeChar, L2Character enemy);
+}
Index: java/com/l2jserver/gameserver/handler/ScriptHandler.java
===================================================================
--- java/com/l2jserver/gameserver/handler/ScriptHandler.java	(revision 0)
+++ java/com/l2jserver/gameserver/handler/ScriptHandler.java	(revision 0)
@@ -0,0 +1,77 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.gameserver.handler;
+
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+import javolution.util.FastMap;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class ScriptHandler
+{	
+	public enum CallSite
+	{
+		// Entering to server
+		ON_ENTER,
+		// Killing any L2Character instance
+		ON_KILL,
+		// Dyeing
+		ON_DEATH,
+		// When revive
+		ON_RESS,
+		// Exiting from server
+		ON_EXIT,
+	}
+	
+	private static FastMap<CallSite, IScriptHandler> _handler;
+	
+	private ScriptHandler()
+	{
+		if(_handler == null)
+			_handler = new FastMap<CallSite, IScriptHandler>();
+	}
+	
+	public static ScriptHandler getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
+	public void registerHandler(IScriptHandler handler)
+	{
+		CallSite site = handler.getCallSite();
+		_handler.put(site, handler);
+	}
+	
+	public void execute(CallSite site, L2PcInstance activeChar, L2Character enemy)
+	{
+		IScriptHandler handler = _handler.get(site);
+		if(handler != null)
+			handler.execute(activeChar, enemy);
+	}
+	
+	public int size()
+	{
+		return _handler.size();
+	}
+	
+	private static final class SingletonHolder
+	{
+		private static final ScriptHandler _instance = new ScriptHandler();
+	}
+}
Index: java/com/l2jserver/gameserver/model/actor/L2Character.java
===================================================================
--- java/com/l2jserver/gameserver/model/actor/L2Character.java	(revision 4330)
+++ java/com/l2jserver/gameserver/model/actor/L2Character.java	(working copy)
@@ -44,7 +44,9 @@
import com.l2jserver.gameserver.datatables.SkillTable;
import com.l2jserver.gameserver.datatables.MapRegionTable.TeleportWhereType;
import com.l2jserver.gameserver.handler.ISkillHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler;
import com.l2jserver.gameserver.handler.SkillHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
import com.l2jserver.gameserver.instancemanager.DimensionalRiftManager;
import com.l2jserver.gameserver.instancemanager.InstanceManager;
import com.l2jserver.gameserver.instancemanager.TerritoryWarManager;
@@ -2160,6 +2162,8 @@
		{
			_log.log(Level.SEVERE, "deleteMe()", e);
		}
+		if(killer instanceof L2PcInstance)
+			ScriptHandler.getInstance().execute(CallSite.ON_KILL, (L2PcInstance)killer, this);
		return true;
	}

Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
--- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java	(revision 4330)
+++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java	(working copy)
@@ -76,6 +76,8 @@
import com.l2jserver.gameserver.datatables.SkillTreeTable;
import com.l2jserver.gameserver.handler.IItemHandler;
import com.l2jserver.gameserver.handler.ItemHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
import com.l2jserver.gameserver.instancemanager.AntiFeedManager;
import com.l2jserver.gameserver.instancemanager.CastleManager;
import com.l2jserver.gameserver.instancemanager.CoupleManager;
@@ -5455,7 +5457,7 @@
			L2PcInstance pk = killer.getActingPlayer();

			TvTEvent.onKill(killer, this);
-			
+			ScriptHandler.getInstance().execute(CallSite.ON_DEATH, this, pk);
			if (atEvent && pk != null)
			{
				pk.kills.add(getName());
@@ -11037,6 +11039,7 @@
			if (!DimensionalRiftManager.getInstance().checkIfInPeaceZone(getX(), getY(), getZ()))
				getParty().getDimensionalRift().memberRessurected(this);
		}
+		ScriptHandler.getInstance().execute(CallSite.ON_RESS, this, null);
	}

	@Override
@@ -11629,6 +11632,15 @@

		try
		{
+			ScriptHandler.getInstance().execute(CallSite.ON_EXIT, this, null);
+		}
+		catch(Exception e)
+		{
+			_log.log(Level.SEVERE, "deleteMe()", e);
+		}
+		
+		try
+		{
			if (isFlying())
			{
				removeSkill(SkillTable.getInstance().getInfo(4289, 1));
Index: java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java
===================================================================
--- java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java	(revision 4330)
+++ java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java	(working copy)
@@ -30,6 +30,8 @@
import com.l2jserver.gameserver.datatables.GMSkillTable;
import com.l2jserver.gameserver.datatables.MapRegionTable;
import com.l2jserver.gameserver.datatables.SkillTable;
+import com.l2jserver.gameserver.handler.ScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
import com.l2jserver.gameserver.instancemanager.CastleManager;
import com.l2jserver.gameserver.instancemanager.ClanHallManager;
import com.l2jserver.gameserver.instancemanager.CoupleManager;
@@ -493,6 +495,8 @@
			sm.addString(Integer.toString(birthday));
			activeChar.sendPacket(sm);
		}
+		
+		ScriptHandler.getInstance().execute(CallSite.ON_ENTER, activeChar, null);
	}

	/**

 

DP Patch

Index: data/scripts/handlers/MasterHandler.java
===================================================================
--- data/scripts/handlers/MasterHandler.java	(revision 7571)
+++ data/scripts/handlers/MasterHandler.java	(working copy)
@@ -19,6 +19,7 @@
import handlers.bypasshandlers.*;
import handlers.chathandlers.*;
import handlers.itemhandlers.*;
+import handlers.scripthandlers.*;
import handlers.skillhandlers.*;
import handlers.usercommandhandlers.*;
import handlers.voicedcommandhandlers.*;
@@ -31,6 +32,7 @@
import com.l2jserver.gameserver.handler.BypassHandler;
import com.l2jserver.gameserver.handler.ChatHandler;
import com.l2jserver.gameserver.handler.ItemHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler;
import com.l2jserver.gameserver.handler.SkillHandler;
import com.l2jserver.gameserver.handler.UserCommandHandler;
import com.l2jserver.gameserver.handler.VoicedCommandHandler;
@@ -314,6 +316,16 @@
		_log.config("Loaded " + VoicedCommandHandler.getInstance().size() + " VoicedHandlers");
	}

+	private static void loadScriptHandlers()
+	{
+		ScriptHandler.getInstance().registerHandler(new EnterWorld());
+		ScriptHandler.getInstance().registerHandler(new OnDeath());
+		ScriptHandler.getInstance().registerHandler(new OnExit());
+		ScriptHandler.getInstance().registerHandler(new OnKill());
+		ScriptHandler.getInstance().registerHandler(new OnRess());
+		_log.config("Loaded " + ScriptHandler.getInstance().size() + " ScriptHandlers");
+	}
+	
	/**
	 * @param args
	 */
@@ -329,6 +341,7 @@
		loadSkillHandlers();
		loadUserHandlers();
		loadVoicedHandlers();
+		loadScriptHandlers();
		_log.config("Handlers Loaded...");
	}
}
\ No newline at end of file
Index: data/scripts/handlers/scripthandlers/EnterWorld.java
===================================================================
--- data/scripts/handlers/scripthandlers/EnterWorld.java	(revision 0)
+++ data/scripts/handlers/scripthandlers/EnterWorld.java	(revision 0)
@@ -0,0 +1,41 @@
+/**
+ * 
+ */
+package handlers.scripthandlers;
+
+import com.l2jserver.gameserver.Announcements;
+import com.l2jserver.gameserver.handler.IScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class EnterWorld implements IScriptHandler
+{
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#execute()
+	 */
+	@Override
+	public void execute(L2PcInstance activeChar, L2Character enemy)
+	{
+		activeChar.sendMessage("This is a test and damn it works!");
+		activeChar.setHero(true);
+		
+		if(activeChar.isGM())
+			Announcements.getInstance().announceToAll("GM "+activeChar.getName()+" has logged in!");
+	}
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()
+	 */
+	@Override
+	public CallSite getCallSite()
+	{
+		return CallSite.ON_ENTER;
+	}
+	
+}
Index: data/scripts/handlers/scripthandlers/OnDeath.java
===================================================================
--- data/scripts/handlers/scripthandlers/OnDeath.java	(revision 0)
+++ data/scripts/handlers/scripthandlers/OnDeath.java	(revision 0)
@@ -0,0 +1,47 @@
+/**
+ * 
+ */
+package handlers.scripthandlers;
+
+import com.l2jserver.gameserver.Announcements;
+import com.l2jserver.gameserver.handler.IScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class OnDeath implements IScriptHandler
+{
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#execute(com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
+	 */
+	@Override
+	public void execute(L2PcInstance activeChar, L2Character enemy)
+	{
+		activeChar.sendMessage("This is a test and damn, it works!");
+		if(enemy instanceof L2PcInstance)
+		{
+			L2PcInstance enem = (L2PcInstance)enemy;
+			enem.sendMessage("ffs");
+			if(enem.getKarma() > 0)
+				Announcements.getInstance().announceToAll(enem.getName()+" is PK!, Go get his stuff!");
+		}
+		else
+			enemy.doDie(activeChar);
+		activeChar.doRevive();
+	}
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()
+	 */
+	@Override
+	public CallSite getCallSite()
+	{
+		return CallSite.ON_DEATH;
+	}
+	
+}
Index: data/scripts/handlers/scripthandlers/OnExit.java
===================================================================
--- data/scripts/handlers/scripthandlers/OnExit.java	(revision 0)
+++ data/scripts/handlers/scripthandlers/OnExit.java	(revision 0)
@@ -0,0 +1,37 @@
+/**
+ * 
+ */
+package handlers.scripthandlers;
+
+import com.l2jserver.gameserver.handler.IScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class OnExit implements IScriptHandler
+{
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#execute(com.l2jserver.gameserver.model.actor.instance.L2PcInstance, com.l2jserver.gameserver.model.actor.L2Character)
+	 */
+	@Override
+	public void execute(L2PcInstance activeChar, L2Character enemy)
+	{
+		// TODO Auto-generated method stub
+		activeChar.sendMessage("Thanks for playing our server! You are welcome anytime.");
+	}
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()
+	 */
+	@Override
+	public CallSite getCallSite()
+	{
+		// TODO Auto-generated method stub
+		return CallSite.ON_EXIT;
+	}
+}
Index: data/scripts/handlers/scripthandlers/OnKill.java
===================================================================
--- data/scripts/handlers/scripthandlers/OnKill.java	(revision 0)
+++ data/scripts/handlers/scripthandlers/OnKill.java	(revision 0)
@@ -0,0 +1,38 @@
+/**
+ * 
+ */
+package handlers.scripthandlers;
+
+import com.l2jserver.gameserver.handler.IScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class OnKill implements IScriptHandler
+{
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#execute(com.l2jserver.gameserver.model.actor.instance.L2PcInstance, com.l2jserver.gameserver.model.actor.L2Character)
+	 */
+	@Override
+	public void execute(L2PcInstance activeChar, L2Character enemy)
+	{
+		// TODO Auto-generated method stub
+		activeChar.sendMessage(activeChar.getName()+ " what did you just do !? You are an assasin!");
+	}
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()
+	 */
+	@Override
+	public CallSite getCallSite()
+	{
+		// TODO Auto-generated method stub
+		return CallSite.ON_KILL;
+	}
+	
+}
Index: data/scripts/handlers/scripthandlers/OnRess.java
===================================================================
--- data/scripts/handlers/scripthandlers/OnRess.java	(revision 0)
+++ data/scripts/handlers/scripthandlers/OnRess.java	(revision 0)
@@ -0,0 +1,39 @@
+/**
+ * 
+ */
+package handlers.scripthandlers;
+
+import com.l2jserver.gameserver.handler.IScriptHandler;
+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author BiggBoss
+ *
+ */
+public class OnRess implements IScriptHandler
+{
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#execute(com.l2jserver.gameserver.model.actor.instance.L2PcInstance, com.l2jserver.gameserver.model.actor.L2Character)
+	 */
+	@Override
+	public void execute(L2PcInstance activeChar, L2Character enemy)
+	{
+		activeChar.setCurrentHp(activeChar.getMaxHp());
+		activeChar.setCurrentMp(activeChar.getMaxMp());
+		activeChar.setCurrentCp(activeChar.getMaxCp());
+	}
+
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()
+	 */
+	@Override
+	public CallSite getCallSite()
+	{
+		// TODO Auto-generated method stub
+		return CallSite.ON_RESS;
+	}
+	
+}

 

Link to comment
Share on other sites

AWSOME MANY I LOVE YOU :D

 

now i can unhardcode every costum check i had also every events check can be done in a dp handler pure awsomeness :D

 

PS.: is it tested or still w8 for testing?

Link to comment
Share on other sites

@Gabor:

 

Index: data/scripts/handlers/scripthandlers/OnDeath.java

===================================================================

--- data/scripts/handlers/scripthandlers/OnDeath.java (revision 0)

+++ data/scripts/handlers/scripthandlers/OnDeath.java (revision 0)

@@ -0,0 +1,47 @@

+/**

+ *

+ */

+package handlers.scripthandlers;

+

+import com.l2jserver.gameserver.Announcements;

+import com.l2jserver.gameserver.handler.IScriptHandler;

+import com.l2jserver.gameserver.handler.ScriptHandler.CallSite;

+import com.l2jserver.gameserver.model.actor.L2Character;

+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;

+

+/**

+ * @author BiggBoss

+ *

+ */

+public class OnDeath implements IScriptHandler

+{

+

+ /* (non-Javadoc)

+ * @see com.l2jserver.gameserver.handler.IScriptHandler#execute(com.l2jserver.gameserver.model.actor.instance.L2PcInstance)

+ */

+ @Override

+ public void execute(L2PcInstance activeChar, L2Character enemy)

+ {

+ activeChar.sendMessage("This is a test and damn, it works!");

+ if(enemy instanceof L2PcInstance)

+ {

+ L2PcInstance enem = (L2PcInstance)enemy;

+ enem.sendMessage("ffs");

+ if(enem.getKarma() > 0)

+ Announcements.getInstance().announceToAll(enem.getName()+" is PK!, Go get his stuff!");

+ }

+ else

+ enemy.doDie(activeChar);

+ activeChar.doRevive();

+ }

+

+ /* (non-Javadoc)

+ * @see com.l2jserver.gameserver.handler.IScriptHandler#getCallSite()

+ */

+ @Override

+ public CallSite getCallSite()

+ {

+ return CallSite.ON_DEATH;

+ }

+

+}

Link to comment
Share on other sites

Well Thank you, but i don`t rly got what this code is for could you explain better?

makes server core a little bit more abstract

btw, thx all  :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...