mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-15 05:44:36 +01:00
Initial Commit
This commit is contained in:
45
src/main/java/emu/nebula/command/commands/GiveCommand.java
Normal file
45
src/main/java/emu/nebula/command/commands/GiveCommand.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package emu.nebula.command.commands;
|
||||
|
||||
import emu.nebula.util.Utils;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.game.mail.GameMail;
|
||||
import emu.nebula.command.Command;
|
||||
import emu.nebula.command.CommandArgs;
|
||||
import emu.nebula.command.CommandHandler;
|
||||
|
||||
@Command(
|
||||
label = "give",
|
||||
aliases = {"g", "item"},
|
||||
permission = "player.give",
|
||||
requireTarget = true,
|
||||
desc = "/give [item id] x(amount). Gives the targeted player an item."
|
||||
)
|
||||
public class GiveCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(CommandArgs args) {
|
||||
// Setup mail
|
||||
var mail = new GameMail("System", "Give Command Result", "");
|
||||
|
||||
// Get amount to give
|
||||
int amount = Math.max(args.getAmount(), 1);
|
||||
|
||||
// Parse items
|
||||
for (String arg : args.getList()) {
|
||||
// Parse item id
|
||||
int itemId = Utils.parseSafeInt(arg);
|
||||
|
||||
var itemData = GameData.getItemDataTable().get(itemId);
|
||||
if (itemData == null) {
|
||||
args.sendMessage("Item \"" + arg + "\" does not exist!");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add
|
||||
mail.addAttachment(itemId, amount);
|
||||
}
|
||||
|
||||
// Add mail
|
||||
args.getTarget().getMailbox().sendMail(mail);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user