初中生
- UID
- 59076
- 威望
- 0
- 金钱
- 347
- 积分
- 461
- 精华
- 帖子
- 114
- 阅读权限
- 30
- 在线时间
- 31 小时
- 注册时间
- 2018-7-2
- 最后登录
- 2020-5-19
|
/*
* DISCORD: https://discord.gg/YYjjPMM
*
* Copyright (C) 2018 bdoEmu
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.bdoemu.gameserver.scripts.commands;
import com.bdoemu.commons.model.enums.EAccessLevel;
import com.bdoemu.gameserver.model.chat.CommandHandler;
import com.bdoemu.gameserver.model.chat.CommandHandlerMethod;
import com.bdoemu.gameserver.model.creature.player.Player;
import com.bdoemu.gameserver.model.creature.player.itemPack.events.AddItemEvent;
import com.bdoemu.gameserver.worldInstance.World;
import org.apache.commons.lang3.text.StrBuilder;
@CommandHandler(prefix = "bag", accessLevel = EAccessLevel.MODERATOR)
public class BagCommandHandler extends AbstractCommandHandler {
private static StrBuilder helpBuilder;
static {
(BagCommandHandler.helpBuilder = new StrBuilder()).appendln("Available commands:");
BagCommandHandler.helpBuilder.appendln("add [itemId] [count] (Optional: [enchantLevel])");
BagCommandHandler.helpBuilder.appendln("addtoplayer [playerName] [itemId] [count] (Optional: [enchantLevel])");
}
@CommandHandlerMethod
public static Object[] index(final Player player, final String... params) {
return AbstractCommandHandler.getAcceptResult(BagCommandHandler.helpBuilder.toString());
}
@CommandHandlerMethod
public static Object[] add(final Player player, final String[] params) {
int enchantLevel = 0;
if (params.length < 2) {
return index(player, params);
}
Integer itemId;
Long count;
try {
itemId = Integer.parseInt(params[0]);
count = Long.parseLong(params[1]);
if (params.length >= 3) {
enchantLevel = Integer.parseInt(params[2]);
}
} catch (NumberFormatException ex) {
return AbstractCommandHandler.getRejectResult("Incorrect number format.");
} catch (ArrayIndexOutOfBoundsException ex2) {
return AbstractCommandHandler.getRejectResult("Incorrect parameters count.");
}
if (!player.getPlayerBag().onEvent(new AddItemEvent(player, itemId, enchantLevel, count))) {
return AbstractCommandHandler.getRejectResult("Fail while executing add ItemEvent.");
}
return AbstractCommandHandler.getAcceptResult("Item successfully added.");
}
@CommandHandlerMethod(accessLevel = EAccessLevel.ADMIN)
public static Object[] addtoplayer(final Player player, final String[] params) {
int enchantLevel = 0;
if (params.length < 3) {
return index(player, params);
}
Player target;
Integer itemId;
Long count;
try {
target = World.getInstance().getPlayer(params[0]);
if (target == null) {
return AbstractCommandHandler.getRejectResult("Player " + params[3] + " doesn't exist in world!");
}
itemId = Integer.parseInt(params[1]);
count = Long.parseLong(params[2]);
if (params.length >= 4) {
enchantLevel = Integer.parseInt(params[3]);
}
} catch (NumberFormatException ex) {
return AbstractCommandHandler.getRejectResult("Incorrect number format.");
} catch (ArrayIndexOutOfBoundsException ex2) {
return AbstractCommandHandler.getRejectResult("Incorrect parameters count.");
}
if (!target.getPlayerBag().onEvent(new AddItemEvent(target, itemId, enchantLevel, count))) {
return AbstractCommandHandler.getRejectResult("Fail while executing add ItemEvent.");
}
return AbstractCommandHandler.getAcceptResult("Item successfully added.");
}
}
|
|