Search in sources :

Example 1 with Alias

use of org.cubeengine.butler.alias.Alias 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");
    }
}
Also used : Locale(java.util.Locale) Language(de.cubeisland.engine.i18n.language.Language) Inventory(org.spongepowered.api.item.inventory.Inventory) ContainerCommand(org.cubeengine.libcube.service.command.ContainerCommand) Command(org.cubeengine.butler.parametric.Command) Alias(org.cubeengine.butler.alias.Alias)

Example 2 with Alias

use of org.cubeengine.butler.alias.Alias in project modules-extra by CubeEngine.

the class RulebookCommands method modify.

@Alias(value = "modifyrules")
@Command(desc = "modified the rulebook of the declared language with the book in hand")
public void modify(Player context, String language) {
    ItemStack item = context.getItemInHand(MAIN_HAND).orElse(null);
    if (item != null && !(item.getItem() == WRITABLE_BOOK || item.getItem() == WRITTEN_BOOK)) {
        i18n.send(context, NEGATIVE, "I would try it with a book as item in hand");
        return;
    }
    Language lang = this.rulebookManager.getLanguage(language);
    if (lang == null) {
        i18n.send(context, NEGATIVE, "More than one or no language is matched with {input}", language);
        return;
    }
    Locale locale = lang.getLocale();
    if (!this.rulebookManager.contains(locale)) {
        i18n.send(context, NEGATIVE, "You can't modify a non-existent book.");
        return;
    }
    try {
        this.rulebookManager.removeBook(locale);
        this.rulebookManager.addBook(item, locale);
        i18n.send(context, POSITIVE, "The rulebook {name} was succesful modified.", locale.getDisplayLanguage(context.getLocale()));
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : Locale(java.util.Locale) Language(de.cubeisland.engine.i18n.language.Language) IOException(java.io.IOException) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ContainerCommand(org.cubeengine.libcube.service.command.ContainerCommand) Command(org.cubeengine.butler.parametric.Command) Alias(org.cubeengine.butler.alias.Alias)

Example 3 with Alias

use of org.cubeengine.butler.alias.Alias in project modules-extra by CubeEngine.

the class RulebookCommands method add.

@Alias(value = "addrules")
@Command(desc = "adds the book in hand as rulebook of the declared language")
public void add(Player context, String language) {
    ItemStack item = context.getItemInHand(MAIN_HAND).orElse(null);
    if (item != null && !(item.getItem() == WRITABLE_BOOK || item.getItem() == WRITTEN_BOOK)) {
        i18n.send(context, NEGATIVE, "I would try it with a book as item in hand");
        return;
    }
    Language lang = this.rulebookManager.getLanguage(language);
    if (lang == null) {
        i18n.send(context, NEGATIVE, "More than one or no language is matched with {input}", language);
        return;
    }
    Locale locale = lang.getLocale();
    if (this.rulebookManager.contains(locale)) {
        i18n.send(context, NEUTRAL, "There is already a book in that language.");
        return;
    }
    this.rulebookManager.addBook(item, locale);
    i18n.send(context, POSITIVE, "Rulebook for the language {input} was added succesfully", lang.getLocale().getDisplayLanguage(context.getLocale()));
}
Also used : Locale(java.util.Locale) Language(de.cubeisland.engine.i18n.language.Language) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ContainerCommand(org.cubeengine.libcube.service.command.ContainerCommand) Command(org.cubeengine.butler.parametric.Command) Alias(org.cubeengine.butler.alias.Alias)

Example 4 with Alias

use of org.cubeengine.butler.alias.Alias in project modules-extra by CubeEngine.

the class RulebookCommands method remove.

@Alias(value = "removerules")
@Command(desc = "removes the declared language and languagefiles!")
public void remove(CommandSource context, String language) {
    Language lang = this.rulebookManager.getLanguage(language);
    if (lang == null) {
        i18n.send(context, NEGATIVE, "More than one or no language is matched with {input}", language);
        return;
    }
    if (!this.rulebookManager.contains(lang.getLocale())) {
        i18n.send(context, POSITIVE, "The languagefile of {input} doesn't exist at the moment", lang.getLocale().getDisplayLanguage(context.getLocale()));
        return;
    }
    try {
        this.rulebookManager.removeBook(lang.getLocale());
        i18n.send(context, POSITIVE, "The languagefiles of {input} was deleted", lang.getLocale().getDisplayLanguage(context.getLocale()));
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : Language(de.cubeisland.engine.i18n.language.Language) IOException(java.io.IOException) ContainerCommand(org.cubeengine.libcube.service.command.ContainerCommand) Command(org.cubeengine.butler.parametric.Command) Alias(org.cubeengine.butler.alias.Alias)

Example 5 with Alias

use of org.cubeengine.butler.alias.Alias in project modules-extra by CubeEngine.

the class ShoutCommand method list.

@Alias(value = { "announcements" })
@Command(alias = "announcements", desc = "List all announcements")
public void list(CommandSource context) {
    Collection<Announcement> list = this.module.getManager().getAllAnnouncements();
    if (list.isEmpty()) {
        i18n.send(context, NEGATIVE, "There are no announcements loaded!");
        return;
    }
    i18n.send(context, POSITIVE, "Here is the list of announcements:");
    for (Announcement announcement : list) {
        context.sendMessage(Text.of(" - ", announcement.getName()));
    }
}
Also used : Announcement(org.cubeengine.module.shout.announce.Announcement) ContainerCommand(org.cubeengine.libcube.service.command.ContainerCommand) Command(org.cubeengine.butler.parametric.Command) Alias(org.cubeengine.butler.alias.Alias)

Aggregations

Alias (org.cubeengine.butler.alias.Alias)10 Command (org.cubeengine.butler.parametric.Command)10 ContainerCommand (org.cubeengine.libcube.service.command.ContainerCommand)10 Language (de.cubeisland.engine.i18n.language.Language)4 Restricted (org.cubeengine.butler.filter.Restricted)4 Locale (java.util.Locale)3 Inventory (org.spongepowered.api.item.inventory.Inventory)3 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 IOException (java.io.IOException)2 Material (org.bukkit.Material)2 IPowertoolData (org.cubeengine.module.powertools.data.IPowertoolData)1 PowertoolData (org.cubeengine.module.powertools.data.PowertoolData)1 Announcement (org.cubeengine.module.shout.announce.Announcement)1 Lookup (org.cubeengine.module.vigil.Lookup)1 LookupData (org.cubeengine.module.vigil.data.LookupData)1