Search in sources :

Example 21 with MessagesConfig

use of net.dzikoysk.funnyguilds.data.configs.MessagesConfig in project FunnyGuilds by FunnyGuilds.

the class ExcDelete method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    Player player = (Player) sender;
    User user = User.get(player);
    if (!user.hasGuild()) {
        player.sendMessage(messages.generalHasNoGuild);
        return;
    }
    if (!user.isOwner()) {
        player.sendMessage(messages.generalIsNotOwner);
        return;
    }
    if (Settings.getConfig().regionDeleteIfNear && user.getGuild().isSomeoneInRegion()) {
        player.sendMessage(messages.deleteSomeoneIsNear);
        return;
    }
    ConfirmationList.add(user.getUUID());
    player.sendMessage(messages.deleteConfirm);
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig)

Example 22 with MessagesConfig

use of net.dzikoysk.funnyguilds.data.configs.MessagesConfig in project FunnyGuilds by FunnyGuilds.

the class ExcDeputy method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    Player player = (Player) sender;
    User owner = User.get(player);
    if (!owner.hasGuild()) {
        player.sendMessage(messages.generalHasNoGuild);
        return;
    }
    if (!owner.isOwner()) {
        player.sendMessage(messages.generalIsNotOwner);
        return;
    }
    if (args.length < 1) {
        player.sendMessage(messages.generalNoNickGiven);
        return;
    }
    String name = args[0];
    if (!UserUtils.playedBefore(name)) {
        player.sendMessage(messages.generalNotPlayedBefore);
        return;
    }
    User deputyUser = User.get(name);
    if (owner.equals(deputyUser)) {
        player.sendMessage(messages.deputyMustBeDifferent);
        return;
    }
    Guild guild = owner.getGuild();
    Player deputyPlayer = deputyUser.getPlayer();
    if (!guild.getMembers().contains(deputyUser)) {
        player.sendMessage(messages.generalIsNotMember);
        return;
    }
    if (!SimpleEventHandler.handle(new GuildMemberDeputyEvent(EventCause.USER, owner, guild, deputyUser))) {
        return;
    }
    if (deputyUser.isDeputy()) {
        guild.removeDeputy(deputyUser);
        ;
        player.sendMessage(messages.deputyRemove);
        if (deputyPlayer != null) {
            deputyPlayer.sendMessage(messages.deputyMember);
        }
        return;
    }
    guild.addDeputy(deputyUser);
    player.sendMessage(messages.deputySet);
    if (deputyPlayer != null) {
        deputyPlayer.sendMessage(messages.deputyOwner);
    }
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildMemberDeputyEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberDeputyEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Example 23 with MessagesConfig

use of net.dzikoysk.funnyguilds.data.configs.MessagesConfig in project FunnyGuilds by FunnyGuilds.

the class ExcInfo method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    String tag = null;
    if (args.length > 0) {
        tag = args[0];
    } else if (sender instanceof Player) {
        User user = User.get((Player) sender);
        if (user.hasGuild()) {
            tag = user.getGuild().getTag();
        }
    }
    if (tag == null || tag.isEmpty()) {
        sender.sendMessage(messages.infoTag);
        return;
    }
    if (!GuildUtils.tagExists(tag)) {
        sender.sendMessage(messages.infoExists);
        return;
    }
    Guild guild = GuildUtils.getByTag(tag);
    if (guild == null) {
        sender.sendMessage(messages.infoExists);
        return;
    }
    String validity = config.dateFormat.format(new Date(guild.getValidity()));
    long now = System.currentTimeMillis();
    long protectionEndTime = guild.getProtectionEndTime();
    for (String messageLine : messages.infoList) {
        messageLine = StringUtils.replace(messageLine, "{GUILD}", guild.getName());
        messageLine = StringUtils.replace(messageLine, "{TAG}", guild.getTag());
        messageLine = StringUtils.replace(messageLine, "{OWNER}", guild.getOwner().getName());
        messageLine = StringUtils.replace(messageLine, "{MEMBERS-ONLINE}", String.valueOf(guild.getOnlineMembers().size()));
        messageLine = StringUtils.replace(messageLine, "{MEMBERS-ALL}", String.valueOf(guild.getMembers().size()));
        messageLine = StringUtils.replace(messageLine, "{MEMBERS}", StringUtils.toString(UserUtils.getOnlineNames(guild.getMembers()), true));
        messageLine = StringUtils.replace(messageLine, "{DEPUTIES}", StringUtils.toString(UserUtils.getNames(guild.getDeputies()), true));
        messageLine = StringUtils.replace(messageLine, "{REGION-SIZE}", String.valueOf(guild.getRegionData().getSize()));
        messageLine = StringUtils.replace(messageLine, "{GUILD-PROTECTION}", protectionEndTime < now ? "Brak" : TimeUtils.getDurationBreakdown(protectionEndTime - now));
        Rank rank = guild.getRank();
        messageLine = StringUtils.replace(messageLine, "{POINTS-FORMAT}", IntegerRange.inRange(rank.getPoints(), config.pointsFormat));
        messageLine = StringUtils.replace(messageLine, "{POINTS}", Integer.toString(rank.getPoints()));
        messageLine = StringUtils.replace(messageLine, "{KILLS}", Integer.toString(rank.getKills()));
        messageLine = StringUtils.replace(messageLine, "{DEATHS}", Integer.toString(rank.getDeaths()));
        messageLine = StringUtils.replace(messageLine, "{KDR}", String.format(Locale.US, "%.2f", rank.getKDR()));
        messageLine = StringUtils.replace(messageLine, "{VALIDITY}", validity);
        messageLine = StringUtils.replace(messageLine, "{LIVES}", Integer.toString(guild.getLives()));
        if (guild.getMembers().size() >= config.minMembersToInclude) {
            messageLine = StringUtils.replace(messageLine, "{RANK}", String.valueOf(rank.getPosition()));
        } else {
            messageLine = StringUtils.replace(messageLine, "{RANK}", messages.minMembersToIncludeNoValue);
        }
        if (!guild.getAllies().isEmpty()) {
            messageLine = StringUtils.replace(messageLine, "{ALLIES}", StringUtils.toString(GuildUtils.getNames(guild.getAllies()), true));
        } else {
            messageLine = StringUtils.replace(messageLine, "{ALLIES}", messages.alliesNoValue);
        }
        if (messageLine.contains("<online>")) {
            String color = ChatColor.getLastColors(messageLine.split("<online>")[0]);
            messageLine = StringUtils.replace(messageLine, "<online>", ChatColor.GREEN + "");
            messageLine = StringUtils.replace(messageLine, "</online>", color);
        }
        sender.sendMessage(messageLine);
    }
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Rank(net.dzikoysk.funnyguilds.basic.Rank) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) Date(java.util.Date)

Example 24 with MessagesConfig

use of net.dzikoysk.funnyguilds.data.configs.MessagesConfig in project FunnyGuilds by FunnyGuilds.

the class ExcInvite method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    Player player = (Player) sender;
    User user = User.get(player);
    if (!user.hasGuild()) {
        player.sendMessage(messages.generalHasNoGuild);
        return;
    }
    if (!user.isOwner() && !user.isDeputy()) {
        player.sendMessage(messages.generalIsNotOwner);
        return;
    }
    if (args.length < 1) {
        player.sendMessage(messages.generalNoNickGiven);
        return;
    }
    Guild guild = user.getGuild();
    if (guild.getMembers().size() >= Settings.getConfig().inviteMembers) {
        player.sendMessage(messages.inviteAmount.replace("{AMOUNT}", Integer.toString(Settings.getConfig().inviteMembers)));
        return;
    }
    if (!UserUtils.playedBefore(args[0])) {
        player.sendMessage(messages.generalNotPlayedBefore);
        return;
    }
    User invitedUser = User.get(args[0]);
    Player invitedPlayer = invitedUser.getPlayer();
    if (InvitationList.hasInvitationFrom(invitedUser, guild)) {
        if (!SimpleEventHandler.handle(new GuildMemberRevokeInviteEvent(EventCause.USER, user, guild, invitedUser))) {
            return;
        }
        InvitationList.expireInvitation(guild, invitedUser);
        player.sendMessage(messages.inviteCancelled);
        if (invitedPlayer != null) {
            invitedPlayer.sendMessage(messages.inviteCancelledToInvited.replace("{OWNER}", player.getName()).replace("{GUILD}", guild.getName()).replace("{TAG}", guild.getTag()));
        }
        return;
    }
    if (invitedPlayer == null) {
        player.sendMessage(messages.invitePlayerExists);
        return;
    }
    if (invitedUser.hasGuild()) {
        player.sendMessage(messages.generalUserHasGuild);
        return;
    }
    if (!SimpleEventHandler.handle(new GuildMemberInviteEvent(EventCause.USER, user, guild, invitedUser))) {
        return;
    }
    InvitationList.createInvitation(guild, invitedPlayer);
    player.sendMessage(messages.inviteToOwner.replace("{PLAYER}", invitedPlayer.getName()));
    invitedPlayer.sendMessage(messages.inviteToInvited.replace("{OWNER}", player.getName()).replace("{GUILD}", guild.getName()).replace("{TAG}", guild.getTag()));
}
Also used : GuildMemberRevokeInviteEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberRevokeInviteEvent) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildMemberInviteEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberInviteEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Example 25 with MessagesConfig

use of net.dzikoysk.funnyguilds.data.configs.MessagesConfig in project FunnyGuilds by FunnyGuilds.

the class ExcAlly method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    Player player = (Player) sender;
    User user = User.get(player);
    if (!user.hasGuild()) {
        player.sendMessage(messages.generalHasNoGuild);
        return;
    }
    if (!user.isOwner()) {
        player.sendMessage(messages.generalIsNotOwner);
        return;
    }
    Guild guild = user.getGuild();
    List<InvitationList.Invitation> invitations = InvitationList.getInvitationsFor(guild);
    if (args.length < 1) {
        if (invitations.size() == 0) {
            player.sendMessage(messages.allyHasNotInvitation);
            return;
        }
        List<String> list = messages.allyInvitationList;
        String guildNames = StringUtils.toString(InvitationList.getInvitationGuildNames(guild), false);
        for (String msg : list) {
            player.sendMessage(msg.replace("{GUILDS}", guildNames));
        }
        return;
    }
    String tag = args[0];
    if (!GuildUtils.tagExists(tag)) {
        player.sendMessage(StringUtils.replace(messages.generalGuildNotExists, "{TAG}", tag));
        return;
    }
    Guild invitedGuild = GuildUtils.getByTag(tag);
    if (guild.equals(invitedGuild)) {
        player.sendMessage(messages.allySame);
        return;
    }
    if (guild.getAllies().contains(invitedGuild)) {
        player.sendMessage(messages.allyAlly);
        return;
    }
    if (InvitationList.hasInvitationFrom(guild, invitedGuild)) {
        if (!SimpleEventHandler.handle(new GuildAcceptAllyInvitationEvent(EventCause.USER, user, guild, invitedGuild))) {
            return;
        }
        InvitationList.expireInvitation(invitedGuild, guild);
        guild.addAlly(invitedGuild);
        invitedGuild.addAlly(guild);
        String allyDoneMessage = messages.allyDone;
        allyDoneMessage = StringUtils.replace(allyDoneMessage, "{GUILD}", invitedGuild.getName());
        allyDoneMessage = StringUtils.replace(allyDoneMessage, "{TAG}", invitedGuild.getTag());
        player.sendMessage(allyDoneMessage);
        Player owner = invitedGuild.getOwner().getPlayer();
        if (owner != null) {
            String allyIDoneMessage = messages.allyIDone;
            allyIDoneMessage = StringUtils.replace(allyIDoneMessage, "{GUILD}", guild.getName());
            allyIDoneMessage = StringUtils.replace(allyIDoneMessage, "{TAG}", guild.getTag());
            owner.sendMessage(allyIDoneMessage);
        }
        ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
        ConcurrencyTaskBuilder taskBuilder = ConcurrencyTask.builder();
        for (User member : guild.getMembers()) {
            // IndependentThread.action(ActionType.PREFIX_UPDATE_GUILD, member, invitedGuild);
            taskBuilder.delegate(new PrefixUpdateGuildRequest(member, invitedGuild));
        }
        for (User member : invitedGuild.getMembers()) {
            // IndependentThread.action(ActionType.PREFIX_UPDATE_GUILD, member, guild);
            taskBuilder.delegate(new PrefixUpdateGuildRequest(member, guild));
        }
        ConcurrencyTask task = taskBuilder.build();
        concurrencyManager.postTask(task);
        return;
    }
    if (InvitationList.hasInvitationFrom(invitedGuild, guild)) {
        if (!SimpleEventHandler.handle(new GuildRevokeAllyInvitationEvent(EventCause.USER, user, guild, invitedGuild))) {
            return;
        }
        InvitationList.expireInvitation(guild, invitedGuild);
        String allyReturnMessage = messages.allyReturn;
        allyReturnMessage = StringUtils.replace(allyReturnMessage, "{GUILD}", invitedGuild.getName());
        allyReturnMessage = StringUtils.replace(allyReturnMessage, "{TAG}", invitedGuild.getTag());
        player.sendMessage(allyReturnMessage);
        Player owner = invitedGuild.getOwner().getPlayer();
        if (owner != null) {
            String allyIReturnMessage = messages.allyIReturn;
            allyIReturnMessage = StringUtils.replace(allyIReturnMessage, "{GUILD}", guild.getName());
            allyIReturnMessage = StringUtils.replace(allyIReturnMessage, "{TAG}", guild.getTag());
            owner.sendMessage(allyIReturnMessage);
        }
        return;
    }
    if (!SimpleEventHandler.handle(new GuildSendAllyInvitationEvent(EventCause.USER, user, guild, invitedGuild))) {
        return;
    }
    InvitationList.createInvitation(guild, invitedGuild);
    String allyInviteDoneMessage = messages.allyInviteDone;
    allyInviteDoneMessage = StringUtils.replace(allyInviteDoneMessage, "{GUILD}", invitedGuild.getName());
    allyInviteDoneMessage = StringUtils.replace(allyInviteDoneMessage, "{TAG}", invitedGuild.getTag());
    player.sendMessage(allyInviteDoneMessage);
    Player owner = invitedGuild.getOwner().getPlayer();
    if (owner != null) {
        String allyToInvitedMessage = messages.allyToInvited;
        allyToInvitedMessage = StringUtils.replace(allyToInvitedMessage, "{GUILD}", guild.getName());
        allyToInvitedMessage = StringUtils.replace(allyToInvitedMessage, "{TAG}", guild.getTag());
        owner.sendMessage(allyToInvitedMessage);
    }
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) GuildRevokeAllyInvitationEvent(net.dzikoysk.funnyguilds.event.guild.ally.GuildRevokeAllyInvitationEvent) PrefixUpdateGuildRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixUpdateGuildRequest) Guild(net.dzikoysk.funnyguilds.basic.Guild) ConcurrencyTask(net.dzikoysk.funnyguilds.concurrency.ConcurrencyTask) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) GuildSendAllyInvitationEvent(net.dzikoysk.funnyguilds.event.guild.ally.GuildSendAllyInvitationEvent) GuildAcceptAllyInvitationEvent(net.dzikoysk.funnyguilds.event.guild.ally.GuildAcceptAllyInvitationEvent) ConcurrencyTaskBuilder(net.dzikoysk.funnyguilds.concurrency.ConcurrencyTaskBuilder)

Aggregations

MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)42 User (net.dzikoysk.funnyguilds.basic.User)39 Player (org.bukkit.entity.Player)38 Guild (net.dzikoysk.funnyguilds.basic.Guild)31 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)17 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)12 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)9 Region (net.dzikoysk.funnyguilds.basic.Region)8 Location (org.bukkit.Location)6 ItemStack (org.bukkit.inventory.ItemStack)6 Rank (net.dzikoysk.funnyguilds.basic.Rank)5 Date (java.util.Date)3 ConcurrencyTask (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTask)3 ConcurrencyTaskBuilder (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTaskBuilder)3 PrefixGlobalAddPlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest)3 PrefixGlobalRemovePlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest)3 PrefixGlobalUpdatePlayer (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer)3 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 PrefixUpdateGuildRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixUpdateGuildRequest)2