Search in sources :

Example 26 with MessagesConfig

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

the class ExcBase 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);
    if (!config.regionsEnabled) {
        player.sendMessage(messages.regionsDisabled);
        return;
    }
    if (!config.baseEnable) {
        player.sendMessage(messages.baseTeleportationDisabled);
        return;
    }
    if (!user.hasGuild()) {
        player.sendMessage(messages.generalHasNoGuild);
        return;
    }
    Guild guild = user.getGuild();
    if (user.getTeleportation() != null) {
        player.sendMessage(messages.baseIsTeleportation);
        return;
    }
    Collection<ItemStack> requiredItems = config.baseItems;
    for (ItemStack requiredItem : requiredItems) {
        if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
            continue;
        }
        String msg = ItemUtils.translatePlaceholder(messages.baseItems, requiredItems, requiredItem);
        player.sendMessage(msg);
        return;
    }
    ItemStack[] items = ItemUtils.toArray(requiredItems);
    player.getInventory().removeItem(items);
    if (config.baseDelay < 1) {
        player.teleport(guild.getHome());
        player.sendMessage(messages.baseTeleport);
        return;
    }
    int time = config.baseDelay;
    Location before = player.getLocation();
    AtomicInteger i = new AtomicInteger(1);
    user.setTeleportation(Bukkit.getScheduler().runTaskTimer(FunnyGuilds.getInstance(), () -> {
        if (!player.isOnline()) {
            user.getTeleportation().cancel();
            user.setTeleportation(null);
            return;
        }
        if (!LocationUtils.equals(player.getLocation(), before)) {
            user.getTeleportation().cancel();
            player.sendMessage(messages.baseMove);
            user.setTeleportation(null);
            player.getInventory().addItem(items);
            return;
        }
        if (i.getAndIncrement() > time) {
            user.getTeleportation().cancel();
            player.sendMessage(messages.baseTeleport);
            player.teleport(guild.getHome());
            user.setTeleportation(null);
        }
    }, 0L, 20L));
    player.sendMessage(messages.baseDontMove.replace("{TIME}", Integer.toString(time)));
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 27 with MessagesConfig

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

the class ExcBreak 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();
    if (guild.getAllies() == null || guild.getAllies().isEmpty()) {
        player.sendMessage(messages.breakHasNotAllies);
        return;
    }
    if (args.length < 1) {
        List<String> list = messages.breakAlliesList;
        String iss = StringUtils.toString(GuildUtils.getNames(guild.getAllies()), true);
        for (String msg : list) {
            player.sendMessage(msg.replace("{GUILDS}", iss));
        }
        return;
    }
    String tag = args[0];
    Guild oppositeGuild = GuildUtils.getByTag(tag);
    if (oppositeGuild == null) {
        player.sendMessage(messages.generalGuildNotExists.replace("{TAG}", tag));
        return;
    }
    if (!guild.getAllies().contains(oppositeGuild)) {
        player.sendMessage(messages.breakAllyExists.replace("{GUILD}", oppositeGuild.getName()).replace("{TAG}", tag));
    }
    if (!SimpleEventHandler.handle(new GuildBreakAllyEvent(EventCause.USER, user, guild, oppositeGuild))) {
        return;
    }
    Player owner = oppositeGuild.getOwner().getPlayer();
    if (owner != null) {
        owner.sendMessage(messages.breakIDone.replace("{GUILD}", guild.getName()).replace("{TAG}", guild.getTag()));
    }
    guild.removeAlly(oppositeGuild);
    oppositeGuild.removeAlly(guild);
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    ConcurrencyTaskBuilder taskBuilder = ConcurrencyTask.builder();
    for (User member : guild.getMembers()) {
        // IndependentThread.action(ActionType.PREFIX_UPDATE_GUILD, member, oppositeGuild);
        taskBuilder.delegate(new PrefixUpdateGuildRequest(member, oppositeGuild));
    }
    for (User member : oppositeGuild.getMembers()) {
        // IndependentThread.action(ActionType.PREFIX_UPDATE_GUILD, member, guild);
        taskBuilder.delegate(new PrefixUpdateGuildRequest(member, guild));
    }
    ConcurrencyTask task = taskBuilder.build();
    concurrencyManager.postTask(task);
    player.sendMessage(messages.breakDone.replace("{GUILD}", oppositeGuild.getName()).replace("{TAG}", oppositeGuild.getTag()));
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) ConcurrencyTask(net.dzikoysk.funnyguilds.concurrency.ConcurrencyTask) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) GuildBreakAllyEvent(net.dzikoysk.funnyguilds.event.guild.ally.GuildBreakAllyEvent) PrefixUpdateGuildRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixUpdateGuildRequest) Guild(net.dzikoysk.funnyguilds.basic.Guild) ConcurrencyTaskBuilder(net.dzikoysk.funnyguilds.concurrency.ConcurrencyTaskBuilder)

Example 28 with MessagesConfig

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

the class ExcConfirm 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;
    }
    if (!ConfirmationList.contains(user.getUUID())) {
        player.sendMessage(messages.deleteToConfirm);
        return;
    }
    ConfirmationList.remove(user.getUUID());
    Guild guild = user.getGuild();
    if (!SimpleEventHandler.handle(new GuildDeleteEvent(EventCause.USER, user, guild))) {
        return;
    }
    GuildUtils.deleteGuild(user.getGuild());
    MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", player.getName());
    player.sendMessage(translator.translate(messages.deleteSuccessful));
    Bukkit.getServer().broadcastMessage(translator.translate(messages.broadcastDelete));
}
Also used : GuildDeleteEvent(net.dzikoysk.funnyguilds.event.guild.GuildDeleteEvent) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 29 with MessagesConfig

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

the class ExcJoin 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.joinHasGuild);
        return;
    }
    List<InvitationList.Invitation> invitations = InvitationList.getInvitationsFor(player);
    if (invitations.size() == 0) {
        player.sendMessage(messages.joinHasNotInvitation);
        return;
    }
    if (args.length < 1) {
        String guildNames = StringUtils.toString(InvitationList.getInvitationGuildNames(player), false);
        for (String msg : messages.joinInvitationList) {
            player.sendMessage(msg.replace("{GUILDS}", guildNames));
        }
        return;
    }
    String tag = args[0];
    Guild guild = GuildUtils.getByTag(tag);
    if (guild == null) {
        player.sendMessage(messages.joinTagExists);
        return;
    }
    if (!InvitationList.hasInvitationFrom(player, GuildUtils.getByTag(tag))) {
        player.sendMessage(messages.joinHasNotInvitationTo);
        return;
    }
    List<ItemStack> requiredItems = Settings.getConfig().joinItems;
    for (ItemStack requiredItem : requiredItems) {
        if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
            continue;
        }
        String msg = ItemUtils.translatePlaceholder(messages.joinItems, requiredItems, requiredItem);
        player.sendMessage(msg);
        return;
    }
    if (!SimpleEventHandler.handle(new GuildMemberAcceptInviteEvent(EventCause.USER, user, guild, user))) {
        return;
    }
    InvitationList.expireInvitation(guild, player);
    if (!SimpleEventHandler.handle(new GuildMemberJoinEvent(EventCause.USER, user, guild, user))) {
        return;
    }
    guild.addMember(user);
    user.setGuild(guild);
    player.getInventory().removeItem(ItemUtils.toArray(requiredItems));
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_ADD_PLAYER, user.getName());
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalAddPlayerRequest(user.getName()));
    MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", player.getName());
    player.sendMessage(translator.translate(messages.joinToMember));
    Bukkit.broadcastMessage(translator.translate(messages.broadcastJoin));
    Player owner = guild.getOwner().getPlayer();
    if (owner != null) {
        owner.sendMessage(translator.translate(messages.joinToOwner));
    }
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) GuildMemberJoinEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent) Guild(net.dzikoysk.funnyguilds.basic.Guild) PrefixGlobalAddPlayerRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest) GuildMemberAcceptInviteEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberAcceptInviteEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) ItemStack(org.bukkit.inventory.ItemStack) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 30 with MessagesConfig

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

the class ExcKick 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;
    }
    User formerUser = User.get(args[0]);
    if (!formerUser.hasGuild()) {
        player.sendMessage(messages.generalPlayerHasNoGuild);
        return;
    }
    if (!user.getGuild().equals(formerUser.getGuild())) {
        player.sendMessage(messages.kickOtherGuild);
        return;
    }
    if (formerUser.isOwner()) {
        player.sendMessage(messages.kickOwner);
        return;
    }
    Guild guild = user.getGuild();
    if (!SimpleEventHandler.handle(new GuildMemberKickEvent(EventCause.USER, user, guild, formerUser))) {
        return;
    }
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_PLAYER, formerUser.getName());
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalRemovePlayerRequest(formerUser.getName()));
    guild.removeMember(formerUser);
    formerUser.removeGuild();
    if (formerUser.isOnline()) {
        // IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE_PLAYER, player);
        concurrencyManager.postRequests(new PrefixGlobalUpdatePlayer(player));
    }
    MessageTranslator translator = new MessageTranslator().register("{PLAYER}", formerUser.getName()).register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag());
    player.sendMessage(translator.translate(messages.kickToOwner));
    Bukkit.broadcastMessage(translator.translate(messages.broadcastKick));
    Player formerPlayer = formerUser.getPlayer();
    if (formerPlayer != null) {
        formerPlayer.sendMessage(translator.translate(messages.kickToPlayer));
    }
}
Also used : PrefixGlobalUpdatePlayer(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer) Player(org.bukkit.entity.Player) PrefixGlobalUpdatePlayer(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) PrefixGlobalRemovePlayerRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest) GuildMemberKickEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberKickEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

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