View difference between Paste ID: wxtg9iqn and 2K8JwZLF
SHOW: | | - or go back to the newest paste.
1
diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java b/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java
2
index 5992525c..07153c7a 100755
3
--- a/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java
4
+++ b/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java
5
@@ -88,6 +88,7 @@ import net.sf.l2j.gameserver.taskmanager.AiTaskManager;
6
 import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager;
7
 import net.sf.l2j.gameserver.taskmanager.BoatTaskManager;
8
 import net.sf.l2j.gameserver.taskmanager.DecayTaskManager;
9
+import net.sf.l2j.gameserver.taskmanager.DoubleTitleTaskManager;
10
 import net.sf.l2j.gameserver.taskmanager.GameTimeTaskManager;
11
 import net.sf.l2j.gameserver.taskmanager.InventoryUpdateTaskManager;
12
 import net.sf.l2j.gameserver.taskmanager.ItemInstanceTaskManager;
13
@@ -208,6 +209,7 @@ public class GameServer
14
 		WaterTaskManager.getInstance();
15
 		InventoryUpdateTaskManager.getInstance();
16
 		ItemInstanceTaskManager.getInstance();
17
+		DoubleTitleTaskManager.getInstance();
18
 		
19
 		StringUtil.printSection("Seven Signs");
20
 		SevenSignsManager.getInstance();
21
diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java b/aCis_gameserver/java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
22
index 929a2e9a..4373afdd 100644
23
--- a/aCis_gameserver/java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
24
+++ b/aCis_gameserver/java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
25
@@ -3,6 +3,8 @@ package net.sf.l2j.gameserver.handler;
26
 import java.util.HashMap;
27
 import java.util.Map;
28
 
29
+import net.sf.l2j.gameserver.handler.voicedcommandhandlers.SecondTitle;
30
+
31
 public class VoicedCommandHandler
32
 {
33
 	private final Map<Integer, IVoicedCommandHandler> _datatable = new HashMap<>();
34
@@ -14,7 +16,7 @@ public class VoicedCommandHandler
35
 	
36
 	protected VoicedCommandHandler()
37
 	{
38
-//		registerHandler(new HandlerName());
39
+		registerHandler(new SecondTitle());
40
 	}
41
 	
42
 	public void registerHandler(IVoicedCommandHandler handler)
43
diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/SecondTitle.java b/aCis_gameserver/java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/SecondTitle.java
44
new file mode 100644
45
index 00000000..eeebf687
46
--- /dev/null
47
+++ b/aCis_gameserver/java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/SecondTitle.java
48
@@ -0,0 +1,39 @@
49
+package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
50
+
51
+import net.sf.l2j.commons.lang.StringUtil;
52
+
53
+import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
54
+import net.sf.l2j.gameserver.model.actor.Player;
55
+import net.sf.l2j.gameserver.network.SystemMessageId;
56
+
57
+public class SecondTitle implements IVoicedCommandHandler
58
+{
59
+	private static final String[] VOICED_COMMANDS =
60
+	{
61
+		"nick2"
62
+	};
63
+	
64
+	@Override
65
+	public boolean useVoicedCommand(String command, Player activeChar, String params)
66
+	{
67
+		if (activeChar.getTitle().isEmpty())
68
+			return false;
69
+		
70
+		final String nick = params.substring(VOICED_COMMANDS[0].length() + 2);
71
+		if (!StringUtil.isValidString(nick, "^[a-zA-Z0-9 !@#$&()\\-`.+,/\"]*{0,16}$"))
72
+		{
73
+			activeChar.sendPacket(SystemMessageId.NOT_WORKING_PLEASE_TRY_AGAIN_LATER);
74
+			return false;
75
+		}
76
+		
77
+		activeChar.sendMessage("Nick secundário ativado. Ele começará a ser exibido em breve.");
78
+		activeChar.setSecondTitle(nick);
79
+		return true;
80
+	}
81
+
82
+	@Override
83
+	public String[] getVoicedCommandList()
84
+	{
85
+		return VOICED_COMMANDS;
86
+	}
87
+}
88
diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Creature.java b/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Creature.java
89
index 4a0fd47c..84941362 100755
90
--- a/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Creature.java
91
+++ b/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Creature.java
92
@@ -935,7 +935,13 @@ public abstract class Creature extends WorldObject
93
 	 */
94
 	public void setTitle(String value)
95
 	{
96
-		_title = StringUtil.trim(value, 16, "");
97
+		final String newTitle = StringUtil.trim(value, 16, "");
98
+		
99
+		// Desativar o double title
100
+		if (getActingPlayer() != null && _title != null && newTitle.isEmpty())
101
+			getActingPlayer().setSecondTitle(newTitle);
102
+		
103
+		_title = newTitle;
104
 	}
105
 	
106
 	/**
107
diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java b/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java
108
index 64610148..136e53d2 100755
109
--- a/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java
110
+++ b/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java
111
@@ -214,6 +214,7 @@ import net.sf.l2j.gameserver.skills.funcs.FuncHenna;
112
 import net.sf.l2j.gameserver.skills.funcs.FuncMaxCpMul;
113
 import net.sf.l2j.gameserver.skills.funcs.FuncRegenCpMul;
114
 import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager;
115
+import net.sf.l2j.gameserver.taskmanager.DoubleTitleTaskManager;
116
 import net.sf.l2j.gameserver.taskmanager.GameTimeTaskManager;
117
 import net.sf.l2j.gameserver.taskmanager.PvpFlagTaskManager;
118
 import net.sf.l2j.gameserver.taskmanager.ShadowItemTaskManager;
119
@@ -460,6 +461,8 @@ public final class Player extends Playable
120
 	private final Set<Integer> _selectedBlocksList = ConcurrentHashMap.newKeySet();
121
 	private final Set<Integer> _selectedFriendList = ConcurrentHashMap.newKeySet();
122
 	
123
+	private String _doubleTitle;
124
+	
125
 	/**
126
 	 * Constructor of Player (use Creature constructor).
127
 	 * <ul>
128
@@ -5962,6 +5965,9 @@ public final class Player extends Playable
129
 			}
130
 		}
131
 		
132
+		if (getSecondTitle() != null)
133
+			DoubleTitleTaskManager.getInstance().add(this);
134
+		
135
 		// Jail task
136
 		_punishment.handle();
137
 		
138
@@ -6291,6 +6297,7 @@ public final class Player extends Playable
139
 			PvpFlagTaskManager.getInstance().remove(this, false);
140
 			GameTimeTaskManager.getInstance().remove(this);
141
 			ShadowItemTaskManager.getInstance().remove(this);
142
+			DoubleTitleTaskManager.getInstance().remove(this);
143
 			
144
 			// Stop all QuestTimer affected to this Player.
145
 			for (Quest quest : ScriptData.getInstance().getQuests())
146
@@ -7154,4 +7161,44 @@ public final class Player extends Playable
147
 	{
148
 		return _selectedBlocksList;
149
 	}
150
+	
151
+	public void setSecondTitle(String nick)
152
+	{
153
+		if (getSecondTitle() != null && !nick.isEmpty() && (getSecondTitle().equals(nick) || getTitle().equals(nick)))
154
+			return;
155
+		
156
+		if (nick.isEmpty() || nick.isBlank())
157
+		{
158
+			// Nick secundário estava ativo no momento em que foi removido
159
+			if (getSecondTitle().equals(getTitleToBroadcast()))
160
+			{
161
+				setTitleToBroadcast(getTitle());
162
+				broadcastTitleInfo();
163
+			}
164
+				
165
+			DoubleTitleTaskManager.getInstance().remove(this);
166
+			getMemos().unset("SECOND_TITLE");
167
+			setTitleToBroadcast(null);
168
+		}
169
+		else
170
+		{
171
+			getMemos().set("SECOND_TITLE", nick);
172
+			DoubleTitleTaskManager.getInstance().add(this);
173
+		}
174
+	}
175
+	
176
+	public String getSecondTitle()
177
+	{
178
+		return getMemos().get("SECOND_TITLE");
179
+	}
180
+	
181
+	public void setTitleToBroadcast(String title)
182
+	{
183
+		_doubleTitle = title;
184
+	}
185
+	
186
+	public String getTitleToBroadcast()
187
+	{
188
+		return getSecondTitle() == null || _doubleTitle == null ? _title : _doubleTitle;
189
+	}
190
 }
191
\ No newline at end of file
192
diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/TitleUpdate.java b/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/TitleUpdate.java
193
index 186d2e59..b11ba630 100755
194
--- a/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/TitleUpdate.java
195
+++ b/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/TitleUpdate.java
196
@@ -10,7 +10,7 @@ public class TitleUpdate extends L2GameServerPacket
197
 	public TitleUpdate(Creature cha)
198
 	{
199
 		_objectId = cha.getObjectId();
200
-		_title = cha.getTitle();
201
+		_title = cha.getActingPlayer() != null ? cha.getActingPlayer().getTitleToBroadcast() : cha.getTitle();
202
 	}
203
 	
204
 	@Override
205
diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/UserInfo.java b/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/UserInfo.java
206
index a18e2685..6547ad4a 100755
207
--- a/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/UserInfo.java
208
+++ b/aCis_gameserver/java/net/sf/l2j/gameserver/network/serverpackets/UserInfo.java
209
@@ -169,7 +169,7 @@ public class UserInfo extends L2GameServerPacket
210
 		writeD(_player.getAppearance().getFace());
211
 		writeD((_player.isGM()) ? 1 : 0);
212
 		
213
-		writeS((_player.getPolymorphTemplate() != null) ? "Morphed" : _player.getTitle());
214
+		writeS((_player.getPolymorphTemplate() != null) ? "Morphed" : _player.getTitleToBroadcast());
215
 		
216
 		writeD(_player.getClanId());
217
 		writeD(_player.getClanCrestId());
218
diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/taskmanager/DoubleTitleTaskManager.java b/aCis_gameserver/java/net/sf/l2j/gameserver/taskmanager/DoubleTitleTaskManager.java
219
new file mode 100644
220
index 00000000..cfb5b333
221
--- /dev/null
222
+++ b/aCis_gameserver/java/net/sf/l2j/gameserver/taskmanager/DoubleTitleTaskManager.java
223
@@ -0,0 +1,57 @@
224
+package net.sf.l2j.gameserver.taskmanager;
225
+
226
+import java.util.Set;
227
+import java.util.concurrent.ConcurrentHashMap;
228
+
229
+import net.sf.l2j.commons.pool.ThreadPool;
230
+
231
+import net.sf.l2j.gameserver.model.actor.Player;
232
+import net.sf.l2j.gameserver.network.serverpackets.TitleUpdate;
233
+
234
+public class DoubleTitleTaskManager implements Runnable
235
+{
236
+	private final Set<Player> _players = ConcurrentHashMap.newKeySet();
237
+	
238
+	private boolean _sendFirstTitle;
239
+	
240
+	protected DoubleTitleTaskManager()
241
+	{
242
+		// Execute a cada 5s
243
+		ThreadPool.scheduleAtFixedRate(this, 5000, 5000);
244
+	}
245
+	
246
+	public void add(Player player)
247
+	{
248
+		_players.add(player);
249
+	}
250
+	
251
+	public void remove(Player player)
252
+	{
253
+		_players.remove(player);
254
+	}
255
+	
256
+	@Override
257
+	public void run()
258
+	{
259
+		for (Player player : _players)
260
+		{
261
+			player.setTitleToBroadcast(_sendFirstTitle ? player.getTitle() : player.getSecondTitle());
262
+
263
+			// O UserInfo é realmente necessário?
264
+			// player.broadcastTitleInfo();
265
+			player.broadcastPacket(new TitleUpdate(player));
266
+		}
267
+		
268
+		_sendFirstTitle = !_sendFirstTitle;
269
+	}
270
+	
271
+	public static final DoubleTitleTaskManager getInstance()
272
+	{
273
+		return SingletonHolder.INSTANCE;
274
+	}
275
+	
276
+	private static class SingletonHolder
277
+	{
278
+		protected static final DoubleTitleTaskManager INSTANCE = new DoubleTitleTaskManager();
279
+	}
280
+}
281
\ No newline at end of file
282