|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright (C) 2004-2014 L2J DataPack
|
|
|
+ * Copyright (C) 2004-2013 L2J DataPack
|
|
|
*
|
|
|
* This file is part of L2J DataPack.
|
|
|
*
|
|
@@ -18,308 +18,504 @@
|
|
|
*/
|
|
|
package handlers.admincommandhandlers;
|
|
|
|
|
|
-import java.util.List;
|
|
|
import java.util.StringTokenizer;
|
|
|
|
|
|
-import javolution.text.TextBuilder;
|
|
|
-
|
|
|
import com.l2jserver.Config;
|
|
|
-import com.l2jserver.gameserver.Announcements;
|
|
|
import com.l2jserver.gameserver.cache.HtmCache;
|
|
|
+import com.l2jserver.gameserver.datatables.AnnouncementsTable;
|
|
|
import com.l2jserver.gameserver.handler.IAdminCommandHandler;
|
|
|
-import com.l2jserver.gameserver.model.L2World;
|
|
|
+import com.l2jserver.gameserver.model.PageResult;
|
|
|
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
|
|
-import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
|
|
|
-import com.l2jserver.gameserver.taskmanager.AutoAnnounceTaskManager;
|
|
|
-import com.l2jserver.gameserver.taskmanager.AutoAnnounceTaskManager.AutoAnnouncement;
|
|
|
+import com.l2jserver.gameserver.model.announce.Announcement;
|
|
|
+import com.l2jserver.gameserver.model.announce.AnnouncementType;
|
|
|
+import com.l2jserver.gameserver.model.announce.AutoAnnouncement;
|
|
|
+import com.l2jserver.gameserver.model.announce.IAnnouncement;
|
|
|
+import com.l2jserver.gameserver.util.Broadcast;
|
|
|
+import com.l2jserver.gameserver.util.HtmlUtil;
|
|
|
import com.l2jserver.gameserver.util.Util;
|
|
|
-import com.l2jserver.util.StringUtil;
|
|
|
|
|
|
/**
|
|
|
- * This class handles following admin commands: - announce text = announces text to all players - list_announcements = show menu - reload_announcements = reloads announcements from txt file - announce_announcements = announce all stored announcements to all players - add_announcement text = adds
|
|
|
- * text to startup announcements - del_announcement id = deletes announcement with respective id
|
|
|
- * @version $Revision: 1.4.4.5 $ $Date: 2005/04/11 10:06:06 $
|
|
|
+ * @author UnAfraid
|
|
|
*/
|
|
|
public class AdminAnnouncements implements IAdminCommandHandler
|
|
|
{
|
|
|
-
|
|
|
private static final String[] ADMIN_COMMANDS =
|
|
|
{
|
|
|
- "admin_list_announcements",
|
|
|
- "admin_list_critannouncements",
|
|
|
- "admin_reload_announcements",
|
|
|
- "admin_announce_announcements",
|
|
|
- "admin_add_announcement",
|
|
|
- "admin_del_announcement",
|
|
|
- "admin_add_critannouncement",
|
|
|
- "admin_del_critannouncement",
|
|
|
"admin_announce",
|
|
|
- "admin_critannounce",
|
|
|
- "admin_announce_menu",
|
|
|
- "admin_critannounce_menu",
|
|
|
- "admin_list_autoann",
|
|
|
- "admin_reload_autoann",
|
|
|
- "admin_add_autoann",
|
|
|
- "admin_del_autoann"
|
|
|
+ "admin_announce_crit",
|
|
|
+ "admin_announce_screen",
|
|
|
+ "admin_announces",
|
|
|
};
|
|
|
|
|
|
@Override
|
|
|
public boolean useAdminCommand(String command, L2PcInstance activeChar)
|
|
|
{
|
|
|
- if (command.equals("admin_list_announcements"))
|
|
|
- {
|
|
|
- Announcements.getInstance().listAnnouncements(activeChar);
|
|
|
- }
|
|
|
- else if (command.equals("admin_list_critannouncements"))
|
|
|
- {
|
|
|
- Announcements.getInstance().listCritAnnouncements(activeChar);
|
|
|
- }
|
|
|
- else if (command.equals("admin_reload_announcements"))
|
|
|
+ final StringTokenizer st = new StringTokenizer(command);
|
|
|
+ final String cmd = st.hasMoreTokens() ? st.nextToken() : "";
|
|
|
+ switch (cmd)
|
|
|
{
|
|
|
- Announcements.getInstance().loadAnnouncements();
|
|
|
- Announcements.getInstance().listAnnouncements(activeChar);
|
|
|
- }
|
|
|
- else if (command.startsWith("admin_announce_menu"))
|
|
|
- {
|
|
|
- if (Config.GM_ANNOUNCER_NAME && (command.length() > 20))
|
|
|
+ case "admin_announce":
|
|
|
+ case "admin_announce_crit":
|
|
|
+ case "admin_announce_screen":
|
|
|
{
|
|
|
- command += " (" + activeChar.getName() + ")";
|
|
|
- }
|
|
|
- Announcements.getInstance().handleAnnounce(command, 20, false);
|
|
|
- AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
|
|
|
- }
|
|
|
- else if (command.startsWith("admin_critannounce_menu"))
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- command = command.substring(24);
|
|
|
-
|
|
|
- if (Config.GM_CRITANNOUNCER_NAME && (command.length() > 0))
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
{
|
|
|
- command = activeChar.getName() + ": " + command;
|
|
|
+ activeChar.sendMessage("Syntax: //announce <text to announce here>");
|
|
|
+ return false;
|
|
|
}
|
|
|
- Announcements.getInstance().handleAnnounce(command, 0, true);
|
|
|
- }
|
|
|
- catch (StringIndexOutOfBoundsException e)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
|
|
|
- }
|
|
|
- else if (command.equals("admin_announce_announcements"))
|
|
|
- {
|
|
|
- for (L2PcInstance player : L2World.getInstance().getPlayers())
|
|
|
- {
|
|
|
- Announcements.getInstance().showAnnouncements(player);
|
|
|
- }
|
|
|
- Announcements.getInstance().listAnnouncements(activeChar);
|
|
|
- }
|
|
|
- else if (command.startsWith("admin_add_announcement"))
|
|
|
- {
|
|
|
- // FIXME the player can send only 16 chars (if you try to send more
|
|
|
- // it sends null), remove this function or not?
|
|
|
- if (!command.equals("admin_add_announcement"))
|
|
|
- {
|
|
|
- try
|
|
|
+ String announce = st.nextToken();
|
|
|
+ while (st.hasMoreTokens())
|
|
|
{
|
|
|
- String val = command.substring(23);
|
|
|
- Announcements.getInstance().addAnnouncement(val);
|
|
|
- Announcements.getInstance().listAnnouncements(activeChar);
|
|
|
+ announce += " " + st.nextToken();
|
|
|
}
|
|
|
- catch (StringIndexOutOfBoundsException e)
|
|
|
- {
|
|
|
- }// ignore errors
|
|
|
- }
|
|
|
- }
|
|
|
- else if (command.startsWith("admin_add_critannouncement"))
|
|
|
- {
|
|
|
- // FIXME the player can send only 16 chars (if you try to send more
|
|
|
- // it sends null), remove this function or not?
|
|
|
- if (!command.equals("admin_add_critannouncement"))
|
|
|
- {
|
|
|
- try
|
|
|
+ if (cmd.equals("admin_announce_screen"))
|
|
|
{
|
|
|
- String val = command.substring(27);
|
|
|
- Announcements.getInstance().addCritAnnouncement(val);
|
|
|
- Announcements.getInstance().listCritAnnouncements(activeChar);
|
|
|
+ Broadcast.toAllOnlinePlayersOnScreen(announce);
|
|
|
}
|
|
|
- catch (StringIndexOutOfBoundsException e)
|
|
|
+ else
|
|
|
{
|
|
|
- }// ignore errors
|
|
|
- }
|
|
|
- }
|
|
|
- else if (command.startsWith("admin_del_announcement"))
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- int val = Integer.parseInt(command.substring(23));
|
|
|
- Announcements.getInstance().delAnnouncement(val);
|
|
|
- Announcements.getInstance().listAnnouncements(activeChar);
|
|
|
- }
|
|
|
- catch (StringIndexOutOfBoundsException e)
|
|
|
- {
|
|
|
- }
|
|
|
- }
|
|
|
- else if (command.startsWith("admin_del_critannouncement"))
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- int val = Integer.parseInt(command.substring(27));
|
|
|
- Announcements.getInstance().delCritAnnouncement(val);
|
|
|
- Announcements.getInstance().listCritAnnouncements(activeChar);
|
|
|
- }
|
|
|
- catch (StringIndexOutOfBoundsException e)
|
|
|
- {
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Command is admin announce
|
|
|
- else if (command.startsWith("admin_announce"))
|
|
|
- {
|
|
|
- if (Config.GM_ANNOUNCER_NAME && (command.length() > 15))
|
|
|
- {
|
|
|
- command += " (" + activeChar.getName() + ")";
|
|
|
+ if (Config.GM_ANNOUNCER_NAME)
|
|
|
+ {
|
|
|
+ announce = announce + " [" + activeChar.getName() + "]";
|
|
|
+ }
|
|
|
+ Broadcast.toAllOnlinePlayers(announce, cmd.equals("admin_announce_crit"));
|
|
|
+ }
|
|
|
+ AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
|
|
|
+ break;
|
|
|
}
|
|
|
- // Call method from another class
|
|
|
- Announcements.getInstance().handleAnnounce(command, 15, false);
|
|
|
- }
|
|
|
- else if (command.startsWith("admin_critannounce"))
|
|
|
- {
|
|
|
- try
|
|
|
+ case "admin_announces":
|
|
|
{
|
|
|
- command = command.substring(19);
|
|
|
-
|
|
|
- if (Config.GM_CRITANNOUNCER_NAME && (command.length() > 0))
|
|
|
+ final String subCmd = st.hasMoreTokens() ? st.nextToken() : "";
|
|
|
+ switch (subCmd)
|
|
|
{
|
|
|
- command = activeChar.getName() + ": " + command;
|
|
|
+ case "add":
|
|
|
+ {
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ String content = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/announces-add.htm");
|
|
|
+ Util.sendCBHtml(activeChar, content);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ final String annType = st.nextToken();
|
|
|
+ final AnnouncementType type = AnnouncementType.findByName(annType);
|
|
|
+ // ************************************
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String annInitDelay = st.nextToken();
|
|
|
+ if (!isDigit(annInitDelay))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ int initDelay = Integer.parseInt(annInitDelay) * 1000;
|
|
|
+ // ************************************
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String annDelay = st.nextToken();
|
|
|
+ if (!isDigit(annDelay))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ int delay = Integer.parseInt(annDelay) * 1000;
|
|
|
+ if ((delay < (10 * 1000)) && ((type == AnnouncementType.AUTO_NORMAL) || (type == AnnouncementType.AUTO_CRITICAL)))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Delay cannot be less then 10 seconds!");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // ************************************
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String annRepeat = st.nextToken();
|
|
|
+ if (!isDigit(annRepeat))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ int repeat = Integer.parseInt(annRepeat);
|
|
|
+ if (repeat == 0)
|
|
|
+ {
|
|
|
+ repeat = -1;
|
|
|
+ }
|
|
|
+ // ************************************
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String content = st.nextToken();
|
|
|
+ while (st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ content += " " + st.nextToken();
|
|
|
+ }
|
|
|
+ // ************************************
|
|
|
+ final IAnnouncement announce;
|
|
|
+ if ((type == AnnouncementType.AUTO_CRITICAL) || (type == AnnouncementType.AUTO_NORMAL))
|
|
|
+ {
|
|
|
+ announce = new AutoAnnouncement(type, content, activeChar.getName(), initDelay, delay, repeat);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ announce = new Announcement(type, content, activeChar.getName());
|
|
|
+ }
|
|
|
+ AnnouncementsTable.getInstance().addAnnouncement(announce);
|
|
|
+ activeChar.sendMessage("Announcement has been successfully added!");
|
|
|
+ return useAdminCommand("admin_announces list", activeChar);
|
|
|
+ }
|
|
|
+ case "edit":
|
|
|
+ {
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces edit <id>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String annId = st.nextToken();
|
|
|
+ if (!isDigit(annId))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces edit <id>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ int id = Integer.parseInt(annId);
|
|
|
+ final IAnnouncement announce = AnnouncementsTable.getInstance().getAnnounce(id);
|
|
|
+ if (announce == null)
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Announcement doesnt exists!");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ String content = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/announces-edit.htm");
|
|
|
+ String announcementId = "" + announce.getId();
|
|
|
+ String announcementType = announce.getType().name();
|
|
|
+ String announcementInital = "0";
|
|
|
+ String announcementDelay = "0";
|
|
|
+ String announcementRepeat = "0";
|
|
|
+ String announcementAuthor = announce.getAuthor();
|
|
|
+ String announcementContent = announce.getContent();
|
|
|
+ if (announce instanceof AutoAnnouncement)
|
|
|
+ {
|
|
|
+ final AutoAnnouncement autoAnnounce = (AutoAnnouncement) announce;
|
|
|
+ announcementInital = "" + (autoAnnounce.getInitial() / 1000);
|
|
|
+ announcementDelay = "" + (autoAnnounce.getDelay() / 1000);
|
|
|
+ announcementRepeat = "" + autoAnnounce.getRepeat();
|
|
|
+ }
|
|
|
+ content = content.replaceAll("%id%", announcementId);
|
|
|
+ content = content.replaceAll("%type%", announcementType);
|
|
|
+ content = content.replaceAll("%initial%", announcementInital);
|
|
|
+ content = content.replaceAll("%delay%", announcementDelay);
|
|
|
+ content = content.replaceAll("%repeat%", announcementRepeat);
|
|
|
+ content = content.replaceAll("%author%", announcementAuthor);
|
|
|
+ content = content.replaceAll("%content%", announcementContent);
|
|
|
+ Util.sendCBHtml(activeChar, content);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ final String annType = st.nextToken();
|
|
|
+ final AnnouncementType type = AnnouncementType.findByName(annType);
|
|
|
+ switch (announce.getType())
|
|
|
+ {
|
|
|
+ case AUTO_CRITICAL:
|
|
|
+ case AUTO_NORMAL:
|
|
|
+ {
|
|
|
+ switch (type)
|
|
|
+ {
|
|
|
+ case AUTO_CRITICAL:
|
|
|
+ case AUTO_NORMAL:
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Announce type can be changed only to AUTO_NORMAL or AUTO_CRITICAL!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case NORMAL:
|
|
|
+ case CRITICAL:
|
|
|
+ {
|
|
|
+ switch (type)
|
|
|
+ {
|
|
|
+ case NORMAL:
|
|
|
+ case CRITICAL:
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Announce type can be changed only to NORMAL or CRITICAL!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // ************************************
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String annInitDelay = st.nextToken();
|
|
|
+ if (!isDigit(annInitDelay))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ int initDelay = Integer.parseInt(annInitDelay);
|
|
|
+ // ************************************
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String annDelay = st.nextToken();
|
|
|
+ if (!isDigit(annDelay))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ int delay = Integer.parseInt(annDelay);
|
|
|
+ if ((delay < 10) && ((type == AnnouncementType.AUTO_NORMAL) || (type == AnnouncementType.AUTO_CRITICAL)))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Delay cannot be less then 10 seconds!");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // ************************************
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String annRepeat = st.nextToken();
|
|
|
+ if (!isDigit(annRepeat))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces add <type> <delay> <repeat> <text>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ int repeat = Integer.parseInt(annRepeat);
|
|
|
+ if (repeat == 0)
|
|
|
+ {
|
|
|
+ repeat = -1;
|
|
|
+ }
|
|
|
+ // ************************************
|
|
|
+ String content = "";
|
|
|
+ if (st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ content = st.nextToken();
|
|
|
+ while (st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ content += " " + st.nextToken();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (content.isEmpty())
|
|
|
+ {
|
|
|
+ content = announce.getContent();
|
|
|
+ }
|
|
|
+ // ************************************
|
|
|
+ announce.setType(type);
|
|
|
+ announce.setContent(content);
|
|
|
+ announce.setAuthor(activeChar.getName());
|
|
|
+ if (announce instanceof AutoAnnouncement)
|
|
|
+ {
|
|
|
+ AutoAnnouncement autoAnnounce = (AutoAnnouncement) announce;
|
|
|
+ autoAnnounce.setInitial(initDelay * 1000);
|
|
|
+ autoAnnounce.setDelay(delay * 1000);
|
|
|
+ autoAnnounce.setRepeat(repeat);
|
|
|
+ }
|
|
|
+ announce.updateMe();
|
|
|
+ activeChar.sendMessage("Announcement has been successfully edited!");
|
|
|
+ return useAdminCommand("admin_announces list", activeChar);
|
|
|
+ }
|
|
|
+ case "remove":
|
|
|
+ {
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces remove <announcement id>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String token = st.nextToken();
|
|
|
+ if (!isDigit(token))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces remove <announcement id>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ int id = Integer.parseInt(token);
|
|
|
+ if (AnnouncementsTable.getInstance().deleteAnnouncement(id))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Announcement has been successfully removed!");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Announcement doesnt exists!");
|
|
|
+ }
|
|
|
+ return useAdminCommand("admin_announces list", activeChar);
|
|
|
+ }
|
|
|
+ case "restart":
|
|
|
+ {
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ for (IAnnouncement announce : AnnouncementsTable.getInstance().getAllAnnouncements())
|
|
|
+ {
|
|
|
+ if (announce instanceof AutoAnnouncement)
|
|
|
+ {
|
|
|
+ final AutoAnnouncement autoAnnounce = (AutoAnnouncement) announce;
|
|
|
+ autoAnnounce.restartMe();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ activeChar.sendMessage("Auto announcements has been successfully restarted");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String token = st.nextToken();
|
|
|
+ if (!isDigit(token))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces show <announcement id>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ int id = Integer.parseInt(token);
|
|
|
+ final IAnnouncement announce = AnnouncementsTable.getInstance().getAnnounce(id);
|
|
|
+ if (announce != null)
|
|
|
+ {
|
|
|
+ if (announce instanceof AutoAnnouncement)
|
|
|
+ {
|
|
|
+ final AutoAnnouncement autoAnnounce = (AutoAnnouncement) announce;
|
|
|
+ autoAnnounce.restartMe();
|
|
|
+ activeChar.sendMessage("Auto announcement has been successfully restarted");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("This option has effect only on auto announcements!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Announcement doesnt exists!");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "show":
|
|
|
+ {
|
|
|
+ if (!st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces show <announcement id>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String token = st.nextToken();
|
|
|
+ if (!isDigit(token))
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("Syntax: //announces show <announcement id>");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ int id = Integer.parseInt(token);
|
|
|
+ final IAnnouncement announce = AnnouncementsTable.getInstance().getAnnounce(id);
|
|
|
+ if (announce != null)
|
|
|
+ {
|
|
|
+ String content = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/announces-show.htm");
|
|
|
+ String announcementId = "" + announce.getId();
|
|
|
+ String announcementType = announce.getType().name();
|
|
|
+ String announcementInital = "0";
|
|
|
+ String announcementDelay = "0";
|
|
|
+ String announcementRepeat = "0";
|
|
|
+ String announcementAuthor = announce.getAuthor();
|
|
|
+ String announcementContent = announce.getContent();
|
|
|
+ if (announce instanceof AutoAnnouncement)
|
|
|
+ {
|
|
|
+ final AutoAnnouncement autoAnnounce = (AutoAnnouncement) announce;
|
|
|
+ announcementInital = "" + (autoAnnounce.getInitial() / 1000);
|
|
|
+ announcementDelay = "" + (autoAnnounce.getDelay() / 1000);
|
|
|
+ announcementRepeat = "" + autoAnnounce.getRepeat();
|
|
|
+ }
|
|
|
+ content = content.replaceAll("%id%", announcementId);
|
|
|
+ content = content.replaceAll("%type%", announcementType);
|
|
|
+ content = content.replaceAll("%initial%", announcementInital);
|
|
|
+ content = content.replaceAll("%delay%", announcementDelay);
|
|
|
+ content = content.replaceAll("%repeat%", announcementRepeat);
|
|
|
+ content = content.replaceAll("%author%", announcementAuthor);
|
|
|
+ content = content.replaceAll("%content%", announcementContent);
|
|
|
+ Util.sendCBHtml(activeChar, content);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ activeChar.sendMessage("Announcement doesnt exists!");
|
|
|
+ return useAdminCommand("admin_announces list", activeChar);
|
|
|
+ }
|
|
|
+ case "list":
|
|
|
+ {
|
|
|
+ int page = 0;
|
|
|
+ if (st.hasMoreTokens())
|
|
|
+ {
|
|
|
+ final String token = st.nextToken();
|
|
|
+ if (Util.isDigit(token))
|
|
|
+ {
|
|
|
+ page = Integer.valueOf(token);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String content = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/announces-list.htm");
|
|
|
+ final PageResult result = HtmlUtil.createPage(AnnouncementsTable.getInstance().getAllAnnouncements(), page, 8, currentPage ->
|
|
|
+ {
|
|
|
+ return "<td align=center><button action=\"bypass admin_announces list " + currentPage + "\" value=\"" + (currentPage + 1) + "\" width=35 height=20 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>";
|
|
|
+ }, announcement ->
|
|
|
+ {
|
|
|
+ final StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append("<tr>");
|
|
|
+ sb.append("<td width=5></td>");
|
|
|
+ sb.append("<td width=80>" + announcement.getId() + "</td>");
|
|
|
+ sb.append("<td width=100>" + announcement.getType() + "</td>");
|
|
|
+ sb.append("<td width=100>" + announcement.getAuthor() + "</td>");
|
|
|
+ if ((announcement.getType() == AnnouncementType.AUTO_NORMAL) || (announcement.getType() == AnnouncementType.AUTO_CRITICAL))
|
|
|
+ {
|
|
|
+ sb.append("<td width=60><button action=\"bypass -h admin_announces restart " + announcement.getId() + "\" value=\"Restart\" width=\"60\" height=\"21\" back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sb.append("<td width=60><button action=\"\" value=\"\" width=\"60\" height=\"21\" back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
|
|
|
+ }
|
|
|
+ if (announcement.getType() == AnnouncementType.EVENT)
|
|
|
+ {
|
|
|
+ sb.append("<td width=60><button action=\"bypass -h admin_announces show " + announcement.getId() + "\" value=\"Show\" width=\"60\" height=\"21\" back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
|
|
|
+ sb.append("<td width=60></td>");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sb.append("<td width=60><button action=\"bypass -h admin_announces show " + announcement.getId() + "\" value=\"Show\" width=\"60\" height=\"21\" back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
|
|
|
+ sb.append("<td width=60><button action=\"bypass -h admin_announces edit " + announcement.getId() + "\" value=\"Edit\" width=\"60\" height=\"21\" back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
|
|
|
+ }
|
|
|
+ sb.append("<td width=60><button action=\"bypass -h admin_announces remove " + announcement.getId() + "\" value=\"Remove\" width=\"60\" height=\"21\" back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
|
|
|
+ sb.append("<td width=5></td>");
|
|
|
+ sb.append("</tr>");
|
|
|
+ return sb.toString();
|
|
|
+ });
|
|
|
+ content = content.replaceAll("%pages%", result.getPagerTemplate().toString());
|
|
|
+ content = content.replaceAll("%announcements%", result.getBodyTemplate().toString());
|
|
|
+ Util.sendCBHtml(activeChar, content);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- Announcements.getInstance().handleAnnounce(command, 0, true);
|
|
|
}
|
|
|
- catch (StringIndexOutOfBoundsException e)
|
|
|
- {
|
|
|
- }
|
|
|
- }
|
|
|
- else if (command.startsWith("admin_list_autoann"))
|
|
|
- {
|
|
|
- listAutoAnnouncements(activeChar);
|
|
|
- }
|
|
|
- else if (command.startsWith("admin_reload_autoann"))
|
|
|
- {
|
|
|
- AutoAnnounceTaskManager.getInstance().restore();
|
|
|
- activeChar.sendMessage("AutoAnnouncement Reloaded.");
|
|
|
- listAutoAnnouncements(activeChar);
|
|
|
}
|
|
|
- else if (command.startsWith("admin_add_autoann"))
|
|
|
- {
|
|
|
- StringTokenizer st = new StringTokenizer(command);
|
|
|
- st.nextToken();
|
|
|
-
|
|
|
- if (!st.hasMoreTokens())
|
|
|
- {
|
|
|
- activeChar.sendMessage("Not enough parameters for adding autoannounce!");
|
|
|
- return false;
|
|
|
- }
|
|
|
- String token = st.nextToken();
|
|
|
- if (!Util.isDigit(token))
|
|
|
- {
|
|
|
- activeChar.sendMessage("Not a valid initial value!");
|
|
|
- return false;
|
|
|
- }
|
|
|
- long initial = Long.parseLong(token);
|
|
|
- if (!st.hasMoreTokens())
|
|
|
- {
|
|
|
- activeChar.sendMessage("Not enough parameters for adding autoannounce!");
|
|
|
- return false;
|
|
|
- }
|
|
|
- token = st.nextToken();
|
|
|
- if (!Util.isDigit(token))
|
|
|
- {
|
|
|
- activeChar.sendMessage("Not a valid delay value!");
|
|
|
- return false;
|
|
|
- }
|
|
|
- long delay = Long.parseLong(token);
|
|
|
- if (!st.hasMoreTokens())
|
|
|
- {
|
|
|
- activeChar.sendMessage("Not enough parameters for adding autoannounce!");
|
|
|
- return false;
|
|
|
- }
|
|
|
- token = st.nextToken();
|
|
|
- if (!token.equals("-1") && !Util.isDigit(token))
|
|
|
- {
|
|
|
- activeChar.sendMessage("Not a valid repeat value!");
|
|
|
- return false;
|
|
|
- }
|
|
|
- int repeat = Integer.parseInt(token);
|
|
|
- if (!st.hasMoreTokens())
|
|
|
- {
|
|
|
- activeChar.sendMessage("Not enough parameters for adding autoannounce!");
|
|
|
- return false;
|
|
|
- }
|
|
|
- boolean isCritical = Boolean.valueOf(st.nextToken());
|
|
|
- if (!st.hasMoreTokens())
|
|
|
- {
|
|
|
- activeChar.sendMessage("Not enough parameters for adding autoannounce!");
|
|
|
- return false;
|
|
|
- }
|
|
|
- TextBuilder memo = new TextBuilder();
|
|
|
- while (st.hasMoreTokens())
|
|
|
- {
|
|
|
- memo.append(st.nextToken());
|
|
|
- memo.append(" ");
|
|
|
- }
|
|
|
-
|
|
|
- AutoAnnounceTaskManager.getInstance().addAutoAnnounce(initial * 1000, delay * 1000, repeat, memo.toString().trim(), isCritical);
|
|
|
- listAutoAnnouncements(activeChar);
|
|
|
- }
|
|
|
-
|
|
|
- else if (command.startsWith("admin_del_autoann"))
|
|
|
- {
|
|
|
- StringTokenizer st = new StringTokenizer(command);
|
|
|
- st.nextToken();
|
|
|
-
|
|
|
- if (!st.hasMoreTokens())
|
|
|
- {
|
|
|
- activeChar.sendMessage("Not enough parameters for deleting autoannounce!");
|
|
|
- return false;
|
|
|
- }
|
|
|
- String token = st.nextToken();
|
|
|
- if (!Util.isDigit(token))
|
|
|
- {
|
|
|
- activeChar.sendMessage("Not a valid auto announce Id value!");
|
|
|
- return false;
|
|
|
- }
|
|
|
- AutoAnnounceTaskManager.getInstance().deleteAutoAnnounce(Integer.parseInt(token));
|
|
|
- listAutoAnnouncements(activeChar);
|
|
|
- }
|
|
|
- return true;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- private void listAutoAnnouncements(L2PcInstance activeChar)
|
|
|
+ public boolean isDigit(String value)
|
|
|
{
|
|
|
- String content = HtmCache.getInstance().getHtmForce(activeChar.getHtmlPrefix(), "data/html/admin/autoannounce.htm");
|
|
|
- final NpcHtmlMessage adminReply = new NpcHtmlMessage();
|
|
|
- adminReply.setHtml(content);
|
|
|
-
|
|
|
- final StringBuilder replyMSG = StringUtil.startAppend(500, "<br>");
|
|
|
- List<AutoAnnouncement> autoannouncements = AutoAnnounceTaskManager.getInstance().getAutoAnnouncements();
|
|
|
- for (int i = 0; i < autoannouncements.size(); i++)
|
|
|
+ try
|
|
|
{
|
|
|
- AutoAnnouncement autoann = autoannouncements.get(i);
|
|
|
- TextBuilder memo2 = new TextBuilder();
|
|
|
- for (String memo0 : autoann.getMemo())
|
|
|
- {
|
|
|
- memo2.append(memo0);
|
|
|
- memo2.append("/n");
|
|
|
- }
|
|
|
- replyMSG.append("<table width=260><tr><td width=220><font color=\"" + (autoann.isCritical() ? "00FCFC" : "7FFCFC") + "\">");
|
|
|
- replyMSG.append(memo2.toString().trim());
|
|
|
- replyMSG.append("</font></td><td width=40><button value=\"Delete\" action=\"bypass -h admin_del_autoann ");
|
|
|
- replyMSG.append(i);
|
|
|
- replyMSG.append("\" width=60 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr></table>");
|
|
|
+ Integer.parseInt(value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
}
|
|
|
- adminReply.replace("%announces%", replyMSG.toString());
|
|
|
-
|
|
|
- activeChar.sendPacket(adminReply);
|
|
|
}
|
|
|
|
|
|
@Override
|