ソースを参照

Add custom announce pk/pvp as custom handler

Zealar 9 年 前
コミット
c03fb21464

+ 27 - 22
dist/game/data/scripts/handlers/MasterHandler.java

@@ -18,6 +18,28 @@
  */
 package handlers;
 
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import com.l2jserver.Config;
+import com.l2jserver.gameserver.handler.ActionHandler;
+import com.l2jserver.gameserver.handler.ActionShiftHandler;
+import com.l2jserver.gameserver.handler.AdminCommandHandler;
+import com.l2jserver.gameserver.handler.BypassHandler;
+import com.l2jserver.gameserver.handler.ChatHandler;
+import com.l2jserver.gameserver.handler.CommunityBoardHandler;
+import com.l2jserver.gameserver.handler.IHandler;
+import com.l2jserver.gameserver.handler.ItemHandler;
+import com.l2jserver.gameserver.handler.PunishmentHandler;
+import com.l2jserver.gameserver.handler.TargetHandler;
+import com.l2jserver.gameserver.handler.TelnetHandler;
+import com.l2jserver.gameserver.handler.UserCommandHandler;
+import com.l2jserver.gameserver.handler.VoicedCommandHandler;
+
 import handlers.actionhandlers.L2ArtefactInstanceAction;
 import handlers.actionhandlers.L2DecoyAction;
 import handlers.actionhandlers.L2DoorInstanceAction;
@@ -158,6 +180,7 @@ import handlers.communityboard.HomepageBoard;
 import handlers.communityboard.MailBoard;
 import handlers.communityboard.MemoBoard;
 import handlers.communityboard.RegionBoard;
+import handlers.custom.CustomAnnouncePkPvP;
 import handlers.itemhandlers.BeastSoulShot;
 import handlers.itemhandlers.BeastSpiritShot;
 import handlers.itemhandlers.BlessedSpiritShot;
@@ -256,28 +279,6 @@ import handlers.voicedcommandhandlers.Lang;
 import handlers.voicedcommandhandlers.StatsVCmd;
 import handlers.voicedcommandhandlers.Wedding;
 
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import com.l2jserver.Config;
-import com.l2jserver.gameserver.handler.ActionHandler;
-import com.l2jserver.gameserver.handler.ActionShiftHandler;
-import com.l2jserver.gameserver.handler.AdminCommandHandler;
-import com.l2jserver.gameserver.handler.BypassHandler;
-import com.l2jserver.gameserver.handler.ChatHandler;
-import com.l2jserver.gameserver.handler.CommunityBoardHandler;
-import com.l2jserver.gameserver.handler.IHandler;
-import com.l2jserver.gameserver.handler.ItemHandler;
-import com.l2jserver.gameserver.handler.PunishmentHandler;
-import com.l2jserver.gameserver.handler.TargetHandler;
-import com.l2jserver.gameserver.handler.TelnetHandler;
-import com.l2jserver.gameserver.handler.UserCommandHandler;
-import com.l2jserver.gameserver.handler.VoicedCommandHandler;
-
 /**
  * Master handler.
  * @author UnAfraid
@@ -580,6 +581,10 @@ public class MasterHandler
 			StatusHandler.class,
 			ThreadHandler.class,
 		},
+		{
+			// Custom Handlers
+			CustomAnnouncePkPvP.class
+		}
 	};
 	
 	public static void main(String[] args)

+ 76 - 0
dist/game/data/scripts/handlers/custom/CustomAnnouncePkPvP.java

@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2004-2015 L2J DataPack
+ * 
+ * This file is part of L2J DataPack.
+ * 
+ * L2J DataPack 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.
+ * 
+ * L2J DataPack 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 handlers.custom;
+
+import com.l2jserver.Config;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.gameserver.model.events.Containers;
+import com.l2jserver.gameserver.model.events.EventType;
+import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerPvPKill;
+import com.l2jserver.gameserver.model.events.listeners.ConsumerEventListener;
+import com.l2jserver.gameserver.network.SystemMessageId;
+import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
+import com.l2jserver.gameserver.util.Broadcast;
+
+/**
+ * @author Zealar
+ */
+public class CustomAnnouncePkPvP
+{
+	
+	public CustomAnnouncePkPvP()
+	{
+		if (Config.ANNOUNCE_PK_PVP)
+		{
+			Containers.Players().addListener(new ConsumerEventListener(Containers.Players(), EventType.ON_PLAYER_PVP_KILL, (OnPlayerPvPKill event) -> OnPlayerPvPKill(event), this));
+		}
+	}
+	
+	/**
+	 * @param event
+	 * @return
+	 */
+	private Object OnPlayerPvPKill(OnPlayerPvPKill event)
+	{
+		L2PcInstance pk = event.getActiveChar();
+		if (pk.isGM())
+		{
+			return null;
+		}
+		L2PcInstance player = event.getTarget();
+		
+		String msg = Config.ANNOUNCE_PVP_MSG;
+		if (player.getPvpFlag() == 0)
+		{
+			msg = Config.ANNOUNCE_PK_MSG;
+		}
+		msg = msg.replace("$killer", pk.getName()).replace("$target", player.getName());
+		if (Config.ANNOUNCE_PK_PVP_NORMAL_MESSAGE)
+		{
+			SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1);
+			sm.addString(msg);
+			Broadcast.toAllOnlinePlayers(sm);
+		}
+		else
+		{
+			Broadcast.toAllOnlinePlayers(msg, false);
+		}
+		return null;
+	}
+}