use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class KitEditCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
final Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
if (KIT_HANDLER.isOpen(kitInfo.getName())) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.edit.current", kitInfo.getName()));
}
Inventory inventory = Util.getKitInventoryBuilder().property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.edit.title", kitInfo.getName()))).build(plugin);
kitInfo.getStacks().stream().filter(x -> !x.getType().equals(ItemTypes.NONE)).forEach(x -> inventory.offer(x.createStack()));
Optional<Container> openedInventory = src.openInventory(inventory);
if (openedInventory.isPresent()) {
KIT_HANDLER.addKitInventoryToListener(Tuple.of(kitInfo, inventory), openedInventory.get());
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.kit.edit.cantopen", kitInfo.getName());
}
use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class InvSeeCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
User target = args.<User>getOne(player).get();
if (!target.isOnline() && !permissions.testSuffix(src, "offline")) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.invsee.nooffline"));
}
if (!this.self && target.getUniqueId().equals(src.getUniqueId())) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.invsee.self"));
}
if (permissions.testSuffix(target, "exempt.target", src, false)) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.invsee.targetexempt", target.getName()));
}
// Just in case, get the subject inventory if they are online.
try {
Inventory targetInv = target.isOnline() ? target.getPlayer().get().getInventory() : target.getInventory();
Optional<Container> oc = src.openInventory(targetInv);
if (oc.isPresent()) {
if (!permissions.testSuffix(src, "modify") || permissions.testSuffix(target, "exempt.interact")) {
InvSeeListener.addEntry(src.getUniqueId(), oc.get());
}
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.invsee.failed");
} catch (UnsupportedOperationException e) {
throw ReturnMessageException.fromKey("command.invsee.offlinenotsupported");
}
}
use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class SpawnMobCommand method executeWithPlayer.
@Override
public CommandResult executeWithPlayer(CommandSource src, Player pl, CommandContext args, boolean isSelf) throws Exception {
// Get the amount
int amount = args.<Integer>getOne(amountKey).get();
EntityType et = args.<EntityType>getOne(mobTypeKey).get();
if (!Living.class.isAssignableFrom(et.getEntityClass())) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.livingonly", et.getTranslation().get()));
}
String id = et.getId().toLowerCase();
if (this.mobConfig.isPerMobPermission() && !permissions.testSuffix(src, "mob." + id.replace(":", "."))) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.mobnoperm", et.getTranslation().get()));
}
Optional<BlockSpawnsConfig> config = this.mobConfig.getBlockSpawnsConfigForWorld(pl.getWorld());
if (config.isPresent() && (config.get().isBlockVanillaMobs() && id.startsWith("minecraft:") || config.get().getIdsToBlock().contains(id))) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.blockedinconfig", et.getTranslation().get()));
}
Location<World> loc = pl.getLocation();
World w = loc.getExtent();
MessageProvider mp = plugin.getMessageProvider();
// Count the number of entities spawned.
int i = 0;
Entity entityone = null;
do {
Entity e = w.createEntity(et, loc.getPosition());
if (!w.spawnEntity(e)) {
throw ReturnMessageException.fromKeyText("command.spawnmob.fail", Text.of(e));
}
if (entityone == null) {
entityone = e;
}
i++;
} while (i < Math.min(amount, this.mobConfig.getMaxMobsToSpawn()));
if (amount > this.mobConfig.getMaxMobsToSpawn()) {
src.sendMessage(mp.getTextMessageWithFormat("command.spawnmob.limit", String.valueOf(this.mobConfig.getMaxMobsToSpawn())));
}
if (i == 0) {
throw ReturnMessageException.fromKey("command.spawnmob.fail", et.getTranslation().get());
}
if (i == 1) {
src.sendMessage(mp.getTextMessageWithTextFormat("command.spawnmob.success.singular", Text.of(i), Text.of(entityone)));
} else {
src.sendMessage(mp.getTextMessageWithTextFormat("command.spawnmob.success.plural", Text.of(i), Text.of(entityone)));
}
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class SellCommand method executeCommand.
@Override
public CommandResult executeCommand(final Player src, CommandContext args) throws Exception {
// Get the item in the hand.
ItemStack is = src.getItemInHand(HandTypes.MAIN_HAND).orElseThrow(() -> new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.generalerror.handempty")));
String id;
Optional<BlockState> blockState = is.get(Keys.ITEM_BLOCKSTATE);
id = blockState.map(blockState1 -> blockState1.getId().toLowerCase()).orElseGet(() -> is.getType().getId());
ItemDataNode node = itemDataService.getDataForItem(id);
final double sellPrice = node.getServerSellPrice();
if (sellPrice < 0) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.itemsell.notforselling"));
return CommandResult.empty();
}
// Get the cost.
final int amt = is.getQuantity();
final double overallCost = sellPrice * amt;
if (econHelper.depositInPlayer(src, overallCost, false)) {
src.setItemInHand(HandTypes.MAIN_HAND, null);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsell.summary", Text.of(amt), Text.of(is), Text.of(econHelper.getCurrencySymbol(overallCost))));
return CommandResult.success();
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsell.error", Text.of(is)));
return CommandResult.empty();
}
use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class TeleportAskCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
Player target = args.<Player>getOne(PLAYER_KEY).get();
if (src.equals(target)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.teleport.self"));
return CommandResult.empty();
}
// Before we do all this, check the event.
RequestEvent.CauseToPlayer event = new RequestEvent.CauseToPlayer(CauseStackHelper.createCause(src), target);
if (Sponge.getEventManager().post(event)) {
throw new ReturnMessageException(event.getCancelMessage().orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("command.tpa.eventfailed")));
}
TeleportHandler.TeleportBuilder tb = tpHandler.getBuilder().setFrom(src).setTo(target).setSafe(!args.<Boolean>getOne("f").orElse(false));
int warmup = getWarmup(src);
if (warmup > 0) {
tb.setWarmupTime(warmup);
}
double cost = getCost(src, args);
if (cost > 0.) {
tb.setCharge(src).setCost(cost);
}
tpHandler.addAskQuestion(target.getUniqueId(), new TeleportHandler.TeleportPrep(Instant.now().plus(30, ChronoUnit.SECONDS), src, cost, tb));
target.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tpa.question", src.getName()));
target.sendMessage(tpHandler.getAcceptDenyMessage());
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tpask.sent", target.getName()));
return CommandResult.success();
}
Aggregations