Java Formatter问题

时间:2018-07-30 09:05:50

标签: java social-gaming

java.util.MissingFormatArgumentException: Format specifier 's'
    at java.util.Formatter.format(Formatter.java:2487) ~[na:1.7.0_80]
    at java.util.Formatter.format(Formatter.java:2423) ~[na:1.7.0_80]
    at java.lang.String.format(String.java:2enter code here792) ~[na:1.7.0_80]
    at com.aionemu.gameserver.utils.audit.GMService.onPlayerUnavailable(Unknown Source) ~[AL-Game.jar:na]
    at admincommands.GMMode.execute(GMMode.java]:73) ~[na:na]

在游戏内发送命令时,出现此错误。

该问题与我的配置文件有关,还是与Java有关?

整个代码是:

package admincommands;

 import com.aionemu.gameserver.model.gameobjects.player.Player;
 import com.aionemu.gameserver.network.aion.serverpackets.SM_MOTION;
 import com.aionemu.gameserver.network.aion.serverpackets.SM_PLAYER_INFO;
 import com.aionemu.gameserver.utils.PacketSendUtility;
 import com.aionemu.gameserver.utils.audit.GMService;
 import com.aionemu.gameserver.utils.chathandlers.AdminCommand;

  */
 public class GMMode extends AdminCommand {

    public GMMode() {
        super("gm");
    }

    @Override
    public void execute(Player admin, String... params) {
        if (admin.getAccessLevel() < 1) {
            PacketSendUtility.sendMessage(admin, "You cannot use this command.");
            return;
        }

        if (params.length != 1) {
            onFail(admin, null);
            return;
        }

        if (params[0].toLowerCase().equals("on")) {
            if (!admin.isGmMode()) {
                admin.setGmMode(true);
                admin.setWispable();

                GMService.getInstance().onPlayerLogin(admin); // put gm into
                // gmlist
                GMService.getInstance().onPlayerAvailable(admin); // send
                // available
                // message
                admin.clearKnownlist();
                PacketSendUtility.sendPacket(admin, new SM_PLAYER_INFO(admin, false));
                PacketSendUtility.sendPacket(admin, new SM_MOTION(admin.getObjectId(), admin.getMotions().getActiveMotions()));
                admin.updateKnownlist();
                PacketSendUtility.sendMessage(admin, "you are now Available and Wispable by players");

            }
        }
        if (params[0].equals("off")) {
            if (admin.isGmMode()) {
                admin.setGmMode(false);
                admin.setUnWispable();

                GMService.getInstance().onPlayerLogedOut(admin); // remove gm
                // into
                // gmlist
                GMService.getInstance().onPlayerUnavailable(admin); // send
                // unavailable
                // message
                admin.clearKnownlist();
                PacketSendUtility.sendPacket(admin, new SM_PLAYER_INFO(admin, false));
                PacketSendUtility.sendPacket(admin, new SM_MOTION(admin.getObjectId(), admin.getMotions().getActiveMotions()));
                admin.updateKnownlist();
                PacketSendUtility.sendMessage(admin, "you are now Unavailable and Unwispable by players");
            }
        }
    }

    @Override
    public void onFail(Player admin, String message) {
        String syntax = "syntax //gm <on|off>";
        PacketSendUtility.sendMessage(admin, syntax);
    }
}

1 个答案:

答案 0 :(得分:0)

该异常告诉您,发生String.format时,格式说明符多于格式化值。所以某处会有一个呼叫

ret = String.format("name %s, surname %s", "Firstname");

根据堆栈跟踪,这发生在类中 com.aionemu.gameserver.utils.audit.GMService在方法onPlayerUnavailable中某个地方的位置,您的问题中缺少该位置。

简短的Google搜索显示了a Git-project,您可以在其中看到罪魁祸首的源头,在这里可以看到String.format的呼叫:

Iterator<Player> iter = World.getInstance().getPlayersIterator();
while (iter.hasNext()) {
    PacketSendUtility.sendBrightYellowMessageOnCenter(iter.next(), "Information : " + String.format(adminTag, player.getName()) + LanguageHandler.translate(CustomMessageId.ANNOUNCE_GM_DECONNECTION));
}

变量adminTag是根据您要传递的Player实例中的设置而构建的,因此,更进一步地说,我们需要有关该实例状态的信息-查看源代码通常,仅显示以下几行是您遇到异常的可能原因:

if (MembershipConfig.PREMIUM_TAG_DISPLAY) {
    switch (player.getClientConnection().getAccount().getMembership()) {
        case 1:
        adminTag = sb.insert(0, MembershipConfig.TAG_PREMIUM.substring(0, 2)).toString();
        break;
    case 2:
        adminTag = sb.insert(0, MembershipConfig.TAG_VIP.substring(0, 2)).toString();
        break;
    }
}
// * = Wedding
if (player.isMarried()) {
    adminTag = sb.insert(0, WeddingsConfig.TAG_WEDDING.substring(0, 2)).toString();
}

查看保存例如值的相应类。 TAG_WEDDING我猜您的配置中至少包含一个以%s开头的常量的自定义值,因此adminTag最终以%s%s结尾。

所以回答你的问题

  

该问题与我的配置文件有关,还是与Java有关?

我想这是您的配置文件中的错误(某些字符串以%s开头)或您正在使用的库中的错误,但这绝对不是Java中的错误。