테스트

aion-server 4.8

Gitteol
최고관리자 · 1 · 💬 0 클론/새로받기
 4.8 61f661d · 1 commits 새로받기(Pull)
game-server/data/handlers/admincommands/Announcements.java
package admincommands;

import java.util.Arrays;
import java.util.Collection;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;

import com.aionemu.gameserver.model.Announcement;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.services.AnnouncementService;
import com.aionemu.gameserver.utils.chathandlers.AdminCommand;

/**
 * @author Divinity
 */
public class Announcements extends AdminCommand {

	public Announcements() {
		super("announcements", "Manages automatic announcements.");

		// @formatter:off
		setSyntaxInfo(
			"<list> - Shows all announcements including their ID.",
			"<reload> - Reloads all announcements from DB.",
			"<add> <elyos|asmodians|all> <chatType> <delay> <message> - Adds the specified message (delay is in seconds, chatType can be system, white, orange, shout or yellow).",
			"<delete> <id> - Deletes the announcement with the specified ID."
		);
		// @formatter:on
	}

	@Override
	public void execute(Player player, String... params) {
		if (params.length == 0) {
			sendInfo(player);
			return;
		}

		if (params[0].equals("list")) {
			Collection<Announcement> announcements = AnnouncementService.getInstance().getAnnouncements();
			String msg;
			if (announcements.isEmpty()) {
				msg = "There are no active announcements.";
			} else {
				msg = "Announcements:";
				for (Announcement announce : announcements) {
					msg += "\nID: " + announce.getId() + " (chat type: " + announce.getType() + ", delay: " + announce.getDelay() + "s";
					if (announce.getFaction() != null)
						msg += ", faction: " + announce.getFaction();
					msg += ")\n\t\"" + announce.getAnnounce() + "\"";
				}
			}
			sendInfo(player, msg);
		} else if (params[0].equals("reload")) {
			AnnouncementService.getInstance().reload();
			sendInfo(player, "Reloaded " + AnnouncementService.getInstance().getAnnouncements().size() + " announcements.");
		} else if (params[0].equals("add")) {
			if (params.length < 4) {
				sendInfo(player);
				return;
			}

			String faction = params[1].toUpperCase();
			if (!Arrays.asList("ELYOS", "ASMODIANS", "ALL").contains(faction)) {
				sendInfo(player, "Please specify a valid faction parameter.");
				return;
			}

			String chatType = params[2].toUpperCase();
			if (!Arrays.asList("SYSTEM", "WHITE", "ORANGE", "SHOUT", "YELLOW").contains(chatType)) {
				sendInfo(player, "Please specify a valid chat type parameter.");
				return;
			}

			int delay;
			try {
				delay = Integer.parseInt(params[3]);
				if (delay < 300)
					throw new IllegalArgumentException("Delay must be at least 300s (5 minutes).");
			} catch (IllegalArgumentException e) {
				sendInfo(player, e instanceof NumberFormatException ? "Delay must be specified in seconds." : e.getMessage());
				return;
			}

			String message = StringEscapeUtils.unescapeJava(StringUtils.join(params, ' ', 4, params.length));
			if (message.isEmpty()) {
				sendInfo(player, "The message cannot be empty.");
				return;
			}

			if (AnnouncementService.getInstance().addAnnouncement(message, faction, chatType, delay))
				sendInfo(player, "The announcement has been created successfully");
			else
				sendInfo(player, "The announcement could not be created");
		} else if (params[0].equals("delete")) {
			if (params.length < 2) {
				sendInfo(player, "Please specify the ID of the announcement to delete.");
				return;
			}

			int id;

			try {
				id = Integer.parseInt(params[1]);
			} catch (NumberFormatException e) {
				sendInfo(player, "Illegal announcement ID.");
				return;
			}

			// Delete the announcement from the database
			if (AnnouncementService.getInstance().delAnnouncement(id))
				sendInfo(player, "The announcement has been deleted successfully.");
			else
				sendInfo(player, "The announcement could not be deleted.");
		} else {
			sendInfo(player);
		}
	}

}

📎 첨부파일

댓글 작성 권한이 없습니다.
🏆 포인트 랭킹 TOP 10
순위 닉네임 포인트
1 no_profile 타키야겐지쪽지보내기 자기소개 아이디로 검색 전체게시물 100,792
2 no_profile 동가리쪽지보내기 자기소개 아이디로 검색 전체게시물 58,079
3 no_profile 라프텔쪽지보내기 자기소개 아이디로 검색 전체게시물 51,771
4 no_profile 불멸의행복쪽지보내기 자기소개 아이디로 검색 전체게시물 36,923
5 서번트쪽지보내기 자기소개 아이디로 검색 전체게시물 35,011
6 no_profile 보거스쪽지보내기 자기소개 아이디로 검색 전체게시물 29,969
7 no_profile 닥터스쪽지보내기 자기소개 아이디로 검색 전체게시물 29,470
8 no_profile 검은고양이쪽지보내기 자기소개 아이디로 검색 전체게시물 29,077
9 no_profile Revolution쪽지보내기 자기소개 아이디로 검색 전체게시물 28,199
10 no_profile 호롤롤로쪽지보내기 자기소개 아이디로 검색 전체게시물 17,020
알림 0