Код:
/**
*
* @author Visor123
* L2Emu Enterprise Server
*/
public class L2ManagementEventGroupEngine extends L2EventGroupEngine
{
public L2ManagementEventGroupEngine(String name, String command)
{
super(name, command);
}
@Override
public boolean useAdminCommand(L2PcInstance player, String command)
{
if (Config.ENT_TESTEVENTS)
_log.info("L2ManagementEventGroupEngine "+getName()+" useAdminCommand player="+player.getName()+" command="+command);
if (command.equalsIgnoreCase(getCommand()))
{
showMainPage(player);
}
else if (command.startsWith(getCommand()+"_show")
|| command.startsWith(getCommand()+"_status")
|| command.startsWith(getCommand()+"_edit")
|| command.startsWith(getCommand()+"_save")
|| command.startsWith(getCommand()+"_load")
|| command.startsWith(getCommand()+"_schedule")
|| command.startsWith(getCommand()+"_totaliser")
|| command.startsWith(getCommand()+"_join")
|| command.startsWith(getCommand()+"_start")
|| command.startsWith(getCommand()+"_teleport")
|| command.startsWith(getCommand()+"_abort")
|| command.startsWith(getCommand()+"_finish")
|| command.startsWith(getCommand()+"_auto")
|| command.startsWith(getCommand()+"_sit")
|| command.startsWith(getCommand()+"_stand")
|| command.startsWith(getCommand()+"_kick")
)
{
String eventName = command.substring(getCommand().length()+6);
if (command.startsWith(getCommand()+"_schedule")
|| command.startsWith(getCommand()+"_teleport"))
eventName = command.substring(getCommand().length()+10);
else if (command.startsWith(getCommand()+"_finish") || command.startsWith(getCommand()+"_status"))
eventName = command.substring(getCommand().length()+8);
else if (command.startsWith(getCommand()+"_start")
|| command.startsWith(getCommand()+"_abort")
|| command.startsWith(getCommand()+"_stand"))
eventName = command.substring(getCommand().length()+7);
else if (command.startsWith(getCommand()+"_sit"))
eventName = command.substring(getCommand().length()+5);
else if (command.startsWith(getCommand()+"_totaliser"))
eventName = command.substring(getCommand().length()+11);
try
{
String[] params = eventName.split(" ");
if (Config.ENT_TESTEVENTS)
_log.info("L2ManagementEventEngine "+getName()+" show/edit... eventName="+params[0]+" params.length="+params.length);
if (_eventInstances.containsKey(params[0]))
_eventInstances.get(params[0]).useAdminCommand(player, command, params);
else
{
player.sendMessage("Event instance with name="+params[0]+" not found");
showMainPage(player);
}
return true;
}
catch (Exception e) {
_log.warn(e.getMessage());
}
}
else if (command.startsWith(getCommand()+"_del"))
{
try
{
String eventName = command.substring(getCommand().length()+5);
String[] params = eventName.split(" ");
if (Config.ENT_TESTEVENTS)
_log.info(getName()+" eventName="+params[0]+" params.length="+params.length);
if (_eventInstances.containsKey(params[0]) && params.length > 1 && params[1].equalsIgnoreCase("y"))
{
L2EventGroupEngineInstance event = _eventInstances.remove(params[0]);
event.deleteData();
saveData();
player.sendMessage(getName()+" data saved to DB");
}
else if (params.length <= 1 || !params[1].equalsIgnoreCase("y"))
player.sendMessage("For delete event instance need enter character `y`");
showMainPage(player);
return true;
}
catch (Exception e) {
_log.warn(e.getMessage());
}
}
else if (command.startsWith(getCommand()+"_create"))
{
try
{
String eventName = command.substring(getCommand().length() + 8);
if (Config.ENT_TESTEVENTS)
_log.info(getName()+"eventName="+eventName);
if (!eventName.isEmpty() && eventName.length() > 0 && !eventName.contains(" ") && eventName.length() <= 16)
createEventInstance(eventName);
else if (!eventName.isEmpty() && eventName.contains(" "))
player.sendMessage("Name event need without spaces");
else if (!eventName.isEmpty() && eventName.length() > 16)
player.sendMessage("Name event need have 1-16 characters");
showMainPage(player);
}
catch (Exception e) {
_log.warn(e.getMessage());
}
}
return super.useAdminCommand(player, command);
}
protected void showMainPage(L2PcInstance player)
{
NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
TextBuilder replyMSG = new TextBuilder("<html><title>"+getName()+"</title><body>");
replyMSG.append("<table width=\"292\" bgcolor=\"666666\"><tr><td><font color=\"LEVEL\">[ "+getName()+" ]</font></td>"
+"<td><button value=\"Back\" action=\"bypass -h " + "admin_events"+"\" width=75 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>"
+"</tr></table>");
replyMSG.append("<br><center>Engine instances</center>");
replyMSG.append("<table width=\"292\">");
for (L2EventGroupEngineInstance event : _eventInstances.values())
{
replyMSG.append("<tr><td><font color=\"LEVEL\">"+event.getName()+"</font></td>"
+"<td><button value=\"Show\" action=\"bypass -h " + getCommand()+"_show "+event.getName() + "\" width=60 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>"
+"<td><button value=\"Edit\" action=\"bypass -h " + getCommand()+"_edit "+event.getName() + "\" width=60 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>"
+"<td><button value=\"Delete\" action=\"bypass -h " + getCommand()+"_del "+event.getName()+" $name" + "\" width=60 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>"
);
}
replyMSG.append("</table>");
replyMSG.append("<table width=\"292\"><tr><td><edit var=\"name\" width=\"125\"></td>");
replyMSG.append("<td><button value=\""+"Create New Event"+"\" action=\"bypass -h " + getCommand()+"_create $name" + "\" width=125 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
replyMSG.append("</table>");
replyMSG.append("</body></html>");
adminReply.setHtml(replyMSG.toString());
player.sendPacket(adminReply);
// Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
player.sendPacket(ActionFailed.STATIC_PACKET);
}
}
Но с точки зрения написания - ***ец
Чет герычем попахивает, мдам.......
command.substring(getCommand().length()+5); еще меня особенно умиляет)
Берем строку, режем ее, вычленяем остаток - вуаля, команда!
Последнее редактирование модератором: