Search in sources :

Example 1 with GuildExtendValidityEvent

use of net.dzikoysk.funnyguilds.event.guild.GuildExtendValidityEvent in project FunnyGuilds by FunnyGuilds.

the class ExcValidity method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    PluginConfig config = Settings.getConfig();
    MessagesConfig messages = Messages.getInstance();
    Player player = (Player) sender;
    User user = User.get(player);
    Guild guild = user.getGuild();
    if (!user.hasGuild()) {
        player.sendMessage(messages.generalHasNoGuild);
        return;
    }
    if (!user.isOwner() && !user.isDeputy()) {
        player.sendMessage(messages.generalIsNotOwner);
        return;
    }
    if (config.validityWhen != 0) {
        long c = guild.getValidity();
        long d = c - System.currentTimeMillis();
        if (d > config.validityWhen) {
            long when = d - config.validityWhen;
            player.sendMessage(messages.validityWhen.replace("{TIME}", TimeUtils.getDurationBreakdown(when)));
            return;
        }
    }
    List<ItemStack> requiredItems = config.validityItems;
    for (ItemStack requiredItem : requiredItems) {
        if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
            continue;
        }
        String msg = ItemUtils.translatePlaceholder(messages.validityItems, requiredItems, requiredItem);
        player.sendMessage(msg);
        return;
    }
    if (!SimpleEventHandler.handle(new GuildExtendValidityEvent(EventCause.USER, user, guild, config.validityTime))) {
        return;
    }
    player.getInventory().removeItem(ItemUtils.toArray(requiredItems));
    long c = guild.getValidity();
    if (c == 0) {
        c = System.currentTimeMillis();
    }
    c += config.validityTime;
    guild.setValidity(c);
    player.sendMessage(messages.validityDone.replace("{DATE}", config.dateFormat.format(new Date(c))));
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) ItemStack(org.bukkit.inventory.ItemStack) GuildExtendValidityEvent(net.dzikoysk.funnyguilds.event.guild.GuildExtendValidityEvent) Date(java.util.Date)

Example 2 with GuildExtendValidityEvent

use of net.dzikoysk.funnyguilds.event.guild.GuildExtendValidityEvent in project FunnyGuilds by FunnyGuilds.

the class AxcValidity method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    } else if (args.length < 2) {
        sender.sendMessage(messages.adminNoValidityTimeGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    if (guild.isBanned()) {
        sender.sendMessage(messages.adminGuildBanned);
        return;
    }
    long time = Parser.parseTime(args[1]);
    if (time < 1) {
        sender.sendMessage(messages.adminTimeError);
        return;
    }
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildExtendValidityEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, time))) {
        return;
    }
    long validity = guild.getValidity();
    if (validity == 0) {
        validity = System.currentTimeMillis();
    }
    validity += time;
    guild.setValidity(validity);
    String date = config.dateFormat.format(new Date(validity));
    sender.sendMessage(messages.adminNewValidity.replace("{GUILD}", guild.getName()).replace("{VALIDITY}", date));
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) GuildExtendValidityEvent(net.dzikoysk.funnyguilds.event.guild.GuildExtendValidityEvent) Date(java.util.Date)

Aggregations

Date (java.util.Date)2 Guild (net.dzikoysk.funnyguilds.basic.Guild)2 User (net.dzikoysk.funnyguilds.basic.User)2 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)2 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)2 GuildExtendValidityEvent (net.dzikoysk.funnyguilds.event.guild.GuildExtendValidityEvent)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)1