테스트

aion-server 4.8

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

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.aionemu.gameserver.dataholders.DataManager;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.model.templates.item.ItemTemplate;
import com.aionemu.gameserver.model.templates.item.actions.AbstractItemAction;
import com.aionemu.gameserver.model.templates.item.actions.MegaphoneAction;
import com.aionemu.gameserver.network.aion.serverpackets.SM_MEGAPHONE;
import com.aionemu.gameserver.utils.ChatUtil;
import com.aionemu.gameserver.utils.PacketSendUtility;
import com.aionemu.gameserver.utils.chathandlers.AdminCommand;

/**
 * @author ginho1, Neon
 */
public class Megaphone extends AdminCommand {

	private final List<MegaphoneChatColor> colors;

	public Megaphone() {
		super("megaphone", "Sends a message to the global faction chat (client must be started with -megaphone to show the megaphone chat window).");

		colors = collectColors();

		// @formatter:off
		setSyntaxInfo(
			"<none|elyos|asmo> <name> <message> - Sends the message with given sender name and faction prefix.",
			"<color ID> <none|elyos|asmo> <name> <message> - Sends the message in the color of given color ID.",
			"Color IDs: " + colorIds()
		);
		// @formatter:on
	}

	@Override
	public void execute(Player admin, String... params) {
		if (params.length < 3) {
			sendInfo(admin);
			return;
		}

		int i = 0;
		int colorIndex = params[i].matches("\\d+") ? Integer.parseInt(params[i++]) - 1 : 0;
		if (colorIndex >= colors.size()) {
			sendInfo(admin, "Invalid color ID.");
			return;
		}
		int megaphoneItemId = colors.get(colorIndex).megaphoneItemId;
		String label = params[i++].toLowerCase();
		SM_MEGAPHONE.FactionLabel factionLabel;
		if ("none".startsWith(label))
			factionLabel = SM_MEGAPHONE.FactionLabel.NONE;
		else if ("elyos".startsWith(label))
			factionLabel = SM_MEGAPHONE.FactionLabel.ELYOS;
		else if ("asmodians".startsWith(label))
			factionLabel = SM_MEGAPHONE.FactionLabel.ASMODIANS;
		else {
			sendInfo(admin);
			return;
		}
		String sender = params[i++];
		String message = StringUtils.join(params, ' ', i, params.length);

		PacketSendUtility.broadcastToWorld(new SM_MEGAPHONE(factionLabel, sender, message, megaphoneItemId));
	}

	private List<MegaphoneChatColor> collectColors() {
		List<MegaphoneChatColor> colors = new ArrayList<>();
		for (ItemTemplate itemTemplate : DataManager.ITEM_DATA.getItemTemplates()) {
			if (itemTemplate.getActions() != null) {
				for (AbstractItemAction itemAction : itemTemplate.getActions().getItemActions()) {
					if (itemAction instanceof MegaphoneAction && colors.stream().noneMatch(c -> c.color == ((MegaphoneAction) itemAction).getColor()))
						colors.add(new MegaphoneChatColor(itemTemplate.getTemplateId(), ((MegaphoneAction) itemAction).getColor()));
				}
			}
		}
		colors.sort(Comparator.comparingInt((MegaphoneChatColor m) -> m.color).reversed());
		return colors;
	}

	private String colorIds() {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < colors.size(); i++) {
			if (sb.length() > 0)
				sb.append(", ");
			sb.append(ChatUtil.color(i + 1 + " █", colors.get(i).color));
		}
		return sb.toString();
	}

	private class MegaphoneChatColor {

		private final int megaphoneItemId;
		private final int color;

		private MegaphoneChatColor(int megaphoneItemId, int color) {
			this.megaphoneItemId = megaphoneItemId;
			this.color = color;
		}
	}
}

📎 첨부파일

댓글 작성 권한이 없습니다.
🏆 포인트 랭킹 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