use of org.cubeengine.butler.parametric.Command in project modules-extra by CubeEngine.
the class KitCommand method create.
@Command(alias = "open", desc = "Opens the configured kit if the kit does not exists a new is created")
@Restricted(value = Player.class, msg = "Just log in or use the config!")
public void create(Player context, String kitname) {
if (!FileUtil.isValidFileName(kitname)) {
i18n.send(context, NEGATIVE, "{name#kit} is is not a valid name! Do not use characters like *, | or ?", kitname);
return;
}
Inventory inventory = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST).property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(i18n.getTranslation(context, "Kit Contents: "), kitname))).build(module.getPlugin());
List<ItemStack> itemList = new ArrayList<>();
Kit kit = manager.getKit(kitname);
if (kit == null) {
kit = new Kit(module, kitname, false, 0, -1, true, "", new ArrayList<>(), itemList);
} else {
itemList = kit.getItems();
}
showKit(context, inventory, itemList, kit);
}
use of org.cubeengine.butler.parametric.Command in project modules-extra by CubeEngine.
the class KitCommand method giveall.
@Command(desc = "Gives a kit to every online player")
public void giveall(CommandSource context, Kit kit, @ParameterPermission @Flag boolean force) {
boolean gaveKit = false;
int kitNotReceived = 0;
for (Player receiver : Sponge.getServer().getOnlinePlayers()) {
try {
if (kit.give(context, receiver, force)) {
if (receiver.equals(context)) {
i18n.send(context, POSITIVE, "Received the {name#kit} kit!", kit.getKitName());
} else {
i18n.send(context, POSITIVE, "You gave {user} the {name#kit} kit!", receiver, kit.getKitName());
i18n.send(receiver, POSITIVE, "Received the {name#kit} kit. Enjoy.", kit.getKitName());
}
gaveKit = true;
}
} catch (Exception ex) {
kitNotReceived++;
}
}
if (!gaveKit) {
i18n.send(context, NEGATIVE, "No one received the kit!");
} else if (kitNotReceived > 0) {
i18n.sendN(context, NEGATIVE, kitNotReceived, "{amount} players did not receive a kit!", "One player did not receive a kit!", kitNotReceived);
}
}
use of org.cubeengine.butler.parametric.Command in project modules-extra by CubeEngine.
the class LookupCommands method lookup.
@Command(desc = "Queries a lookup in the database\n Show availiable parameters with /lookup params")
public // TODO param for filter / chat / command / signtexts
void lookup(CommandContext context, @Label("params") @Optional String action, @Named({ "action", "a" }) @Complete(ActionTypeCompleter.class) String actions, @Named({ "radius", "r" }) String radius, @Named({ "player", "p" }) @Complete(PlayerListCompleter.class) String players, @Named({ "block", "b" }) @Complete(MaterialListCompleter.class) String blocks, @Named({ "entity", "e" }) String entities, @Named({ "since", "time", "t" }) String since, @Named({ "before" }) String before, @Named({ "world", "w", "in" }) @Complete(WorldCompleter.class) String world, @Named({ "limit", "pagelimit" }) Integer limit, @Named({ "page" }) Integer page, @Named("params") @Complete(ActionTypeCompleter.class) String params, @Flag(longName = "coordinates", name = "coords") boolean showCoord, @Flag(longName = "detailed", name = "det") boolean detailed, @Flag(longName = "nodate", name = "nd") boolean nodate, @Flag(longName = "descending", name = "desc") boolean descending) {
if ("params".equalsIgnoreCase(action) || params != null) {
this.params(context.getSource(), params);
return;
}
if (context.getSource() instanceof User) {
if (!context.hasNamed()) {
try {
context.sendTranslated(NEGATIVE, "You have to provide parameters");
// ((Dispatcher)context.getCommand()).getCommand("?").execute(context.getInvocation());
// TODO show all selected params of last lookup
} catch (Exception e) {
throw new IllegalStateException(e);
}
return;
}
User user = (User) context.getSource();
LogAttachment attachment = user.attachOrGet(LogAttachment.class, this.module);
// gets last OR new Showparameter
ShowParameter show = attachment.getLastShowParameter();
Lookup lookup = attachment.getLastLookup();
if (// /lookup show / page <page>
!this.fillShowOptions(attachment, lookup, show, context.getSource(), showCoord, nodate, detailed, descending, limit, page, action)) {
return;
}
lookup = attachment.createNewCommandLookup();
QueryParameter parameters = lookup.getQueryParameter();
if (!(readActions(parameters, actions, user) && readRadius(parameters, radius, user) && readUser(parameters, players, user) && readBlocks(parameters, blocks, user) && readEntities(parameters, entities, user) && readWorld(parameters, world, radius != null, user) && readTimeSince(parameters, since, user) && readTimeBefore(parameters, before, user))) {
return;
}
attachment.queueShowParameter(show);
this.module.getLogManager().fillLookupAndShow(lookup, user);
} else {
// TODO implement me
System.out.println("Not implemented yet");
}
}
use of org.cubeengine.butler.parametric.Command in project modules-extra by CubeEngine.
the class MuteCommands method mute.
@Command(desc = "Mutes a player")
public void mute(CommandSource context, Player player, @Optional String duration) {
Date muted = getMuted(player);
if (muted != null && muted.getTime() > System.currentTimeMillis()) {
i18n.send(context, NEUTRAL, "{user} was already muted!", player);
}
try {
Integer.parseInt(duration);
duration += "m";
} catch (NumberFormatException ignored) {
}
Duration dura = module.getConfig().defaultMuteTime;
if (duration != null) {
try {
dura = converter.fromNode(StringNode.of(duration), null, null);
} catch (ConversionException e) {
i18n.send(context, NEGATIVE, "Invalid duration format!");
return;
}
}
setMuted(player, new Date(System.currentTimeMillis() + (dura.toMillis() == 0 ? DAYS.toMillis(9001) : dura.toMillis())));
Text timeString = dura.toMillis() == 0 ? i18n.translate(player, NONE, "ever") : Text.of(TimeUtil.format(player.getLocale(), dura.toMillis()));
i18n.send(player, NEGATIVE, "You are now muted for {txt#amount}!", timeString);
i18n.send(context, NEUTRAL, "You muted {user} globally for {txt#amount}!", player, timeString);
}
use of org.cubeengine.butler.parametric.Command in project modules-extra by CubeEngine.
the class RulebookCommands method getRuleBook.
@Alias(value = { "getrules", "rules" })
@Command(desc = "gets the player the rulebook in the inventory")
public void getRuleBook(CommandSource context, @Optional String language, @Default @Named({ "player", "p" }) Player player) {
// console msg /wo player: i18n.sendTranslated(context, NEGATIVE, "The post office will give you your book!");
Locale locale;
if (!context.equals(player)) {
if (!context.hasPermission(getOtherPerm.getId())) {
i18n.send(context, NEGATIVE, "You do not have the permissions to add the rulebook to the inventory of an other player");
return;
}
}
if (this.rulebookManager.getLocales().isEmpty()) {
i18n.send(context, NEUTRAL, "It does not exist a rulebook yet");
return;
}
if (language != null) {
Language l = this.rulebookManager.getLanguage(language);
if (l == null) {
i18n.send(context, NEGATIVE, "Can't match the language");
return;
}
locale = l.getLocale();
if (!this.rulebookManager.contains(locale)) {
i18n.send(context, NEUTRAL, "The language {name} is not supported yet.", locale.getDisplayLanguage(context.getLocale()));
return;
}
} else {
locale = player.getLocale();
if (!this.rulebookManager.contains(locale)) {
locale = i18n.getDefaultLanguage().getLocale();
if (!this.rulebookManager.contains(locale)) {
locale = this.rulebookManager.getLocales().iterator().next();
}
}
}
Set<Inventory> books = this.inventoryRulebookSearching(player.getInventory(), locale);
for (Inventory book : books) {
book.clear();
}
player.getInventory().offer(this.rulebookManager.getBook(locale));
i18n.send(player, POSITIVE, "Lots of fun with your rulebook.");
if (!books.isEmpty()) {
i18n.send(player, POSITIVE, "Your old rulebook was removed");
}
}
Aggregations