Search in sources :

Example 1 with ItemBuilder

use of com.ebicep.warlords.util.bukkit.ItemBuilder in project Warlords by ebicep.

the class BotListener method onMessageReceived.

@Override
public void onMessageReceived(MessageReceivedEvent event) {
    Member member = event.getMember();
    Message message = event.getMessage();
    if (event.isFromType(ChannelType.PRIVATE)) {
        if (event.getAuthor().isBot()) {
            return;
        }
        try {
            Long key = Long.parseLong(message.getContentRaw());
            if (DiscordCommand.playerLinkKeys.containsValue(key)) {
                UUID uuid = DiscordCommand.playerLinkKeys.getKey(key);
                if (DatabaseManager.playerService == null)
                    return;
                Warlords.newChain().asyncFirst(() -> DatabaseManager.playerService.findByUUID(uuid)).syncLast(databasePlayer -> {
                    Long id = event.getAuthor().getIdLong();
                    databasePlayer.setDiscordID(id);
                    DatabaseManager.updatePlayerAsync(databasePlayer);
                    event.getPrivateChannel().sendMessage("You linked **" + Bukkit.getOfflinePlayer(uuid).getName() + "** to your discord account (" + id + ").").queue();
                    if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
                        Bukkit.getOfflinePlayer(uuid).getPlayer().sendMessage(ChatColor.GREEN + "Your account was linked to the discord account " + event.getAuthor().getAsTag() + " (" + id + ").");
                    }
                    BotManager.sendDebugMessage(new EmbedBuilder().setColor(3066993).setTitle("Player Linked - " + id).setDescription("UUID: " + uuid + "\n" + "IGN: " + databasePlayer.getName() + "\n" + "KEY: " + key).build());
                }).execute();
            }
        } catch (Exception e) {
            System.out.println(message);
            System.out.println("Could not parseLong from direct message");
            e.printStackTrace();
        }
    } else if (event.isFromType(ChannelType.TEXT)) {
        TextChannel textChannel = event.getTextChannel();
        switch(textChannel.getName().toLowerCase()) {
            case "gs-teams":
            case "bot-teams":
                {
                    if (message.getContentRaw().contains(", Balance Cancelled")) {
                        cancelOnGoingBalance();
                    } else if (!message.getEmbeds().isEmpty() && message.getEmbeds().get(0).getFields().size() == 2) {
                        cancelOnGoingBalance();
                        MessageEmbed embed = message.getEmbeds().get(0);
                        List<String> playerNames = new ArrayList<>();
                        for (MessageEmbed.Field field : embed.getFields()) {
                            String fieldName = field.getName();
                            String fieldValue = field.getValue();
                            if (fieldName != null && fieldValue != null) {
                                String[] players = fieldValue.replace("```", "").replace(" ", "").split("\n");
                                if (fieldName.contains("Blue Team") || fieldName.contains("Red Team")) {
                                    for (String player : players) {
                                        playerNames.add(player.substring(0, player.indexOf('-')));
                                    }
                                }
                            }
                        }
                        onGoingBalance = new BukkitRunnable() {

                            int counter = 0;

                            @Override
                            public void run() {
                                playerNames.forEach(name -> {
                                    Player player = Bukkit.getPlayer(name);
                                    if (player != null) {
                                        Random random = new Random();
                                        PacketUtils.sendTitle(player, ChatColor.GREEN + Utils.specsOrdered[random.nextInt(Utils.specsOrdered.length)], random.nextInt(2) == 0 ? ChatColor.BLUE.toString() + ChatColor.BOLD + "BLUE" : ChatColor.RED.toString() + ChatColor.BOLD + "RED", 0, 5, 0);
                                    }
                                });
                                // auto cancel after 15 seconds
                                if (counter++ > 20 * 15) {
                                    this.cancel();
                                }
                            }
                        }.runTaskTimer(Warlords.getInstance(), 10, 0);
                    }
                    break;
                }
            case "teams":
                {
                    if (!message.getEmbeds().isEmpty() && message.getEmbeds().get(0).getFields().size() == 2) {
                        cancelOnGoingBalance();
                        MessageEmbed embed = message.getEmbeds().get(0);
                        boolean isExperimental = embed.getTitle().contains("*");
                        List<String> blueTeam = new ArrayList<>();
                        List<String> redTeam = new ArrayList<>();
                        for (MessageEmbed.Field field : embed.getFields()) {
                            String fieldName = field.getName();
                            String fieldValue = field.getValue();
                            String[] players;
                            if (fieldName != null && fieldValue != null) {
                                players = fieldValue.replace("```", "").split("\n");
                                if (fieldName.contains("Blue Team")) {
                                    blueTeam.add(ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Blue Team" + ChatColor.DARK_GRAY + " - ");
                                    for (String player : players) {
                                        String name = player.substring(0, player.indexOf('-'));
                                        String spec = player.substring(player.indexOf('-') + 1);
                                        blueTeam.add(ChatColor.BLUE + name + ChatColor.GRAY + " - " + ChatColor.YELLOW + spec);
                                    }
                                } else if (fieldName.contains("Red Team")) {
                                    redTeam.add(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "Red Team" + ChatColor.DARK_GRAY + " - ");
                                    for (String player : players) {
                                        String name = player.substring(0, player.indexOf('-'));
                                        String spec = player.substring(player.indexOf('-') + 1);
                                        redTeam.add(ChatColor.RED + name + ChatColor.GRAY + " - " + ChatColor.YELLOW + spec);
                                    }
                                }
                            }
                        }
                        AtomicBoolean resetMenu = new AtomicBoolean(true);
                        for (MessageEmbed.Field field : embed.getFields()) {
                            String fieldName = field.getName();
                            String fieldValue = field.getValue();
                            String[] players;
                            if (fieldName != null && fieldValue != null) {
                                boolean isBlueTeam = fieldName.contains("Blue Team");
                                boolean isRedTeam = fieldName.contains("Red Team");
                                players = fieldValue.replace("```", "").replace(" ", "").split("\n");
                                try {
                                    Bukkit.getScheduler().callSyncMethod(Warlords.getInstance(), () -> {
                                        for (String player : players) {
                                            String name = player.substring(0, player.indexOf('-'));
                                            String spec = player.substring(player.indexOf('-') + 1);
                                            OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
                                            if (offlinePlayer == null)
                                                continue;
                                            UUID uuid = offlinePlayer.getUniqueId();
                                            if (resetMenu.get()) {
                                                Warlords.partyManager.getPartyFromAny(uuid).ifPresent(party -> party.getRegularGamesMenu().reset());
                                                resetMenu.set(false);
                                            }
                                            // includes offline players
                                            if (isBlueTeam) {
                                                Warlords.getPlayerSettings(uuid).setWantedTeam(Team.BLUE);
                                            } else if (isRedTeam) {
                                                Warlords.getPlayerSettings(uuid).setWantedTeam(Team.RED);
                                            }
                                            if (!spec.isEmpty()) {
                                                Warlords.getPlayerSettings(uuid).setSelectedClass(Classes.getClass(spec));
                                                DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(uuid);
                                                databasePlayer.setLastSpec(Classes.getClass(spec));
                                                DatabaseManager.updatePlayerAsync(databasePlayer);
                                            // TODO: fix
                                            /*if (!isExperimental) {
                                                    Warlords.partyManager.getPartyFromAny(uuid).ifPresent(party -> {
                                                        party.getRegularGamesMenu().getRegularGamePlayers().add(
                                                                new RegularGamesMenu.RegularGamePlayer(uuid, isBlueTeam ? Team.BLUE : Team.RED, Classes.getClass(spec))
                                                        );
                                                    });
                                                }*/
                                            } else {
                                            // TODO: fix
                                            /*if (!isExperimental) {
                                                    Warlords.partyManager.getPartyFromAny(uuid).ifPresent(party -> {
                                                        party.getRegularGamesMenu().getRegularGamePlayers().add(
                                                                new RegularGamesMenu.RegularGamePlayer(uuid, isBlueTeam ? Team.BLUE : Team.RED, Classes.PYROMANCER)
                                                        );
                                                    });
                                                }*/
                                            }
                                            if (!isExperimental) {
                                                Warlords.partyManager.getPartyFromAny(uuid).ifPresent(party -> {
                                                    if (offlinePlayer.isOnline()) {
                                                        offlinePlayer.getPlayer().getInventory().setItem(7, new ItemBuilder((isBlueTeam ? Team.BLUE : Team.RED).getItem()).name("§aTeam Builder").get());
                                                    }
                                                });
                                            }
                                            // only send messages to online
                                            if (offlinePlayer.isOnline()) {
                                                Player targetPlayer = offlinePlayer.getPlayer();
                                                targetPlayer.sendMessage(ChatColor.DARK_BLUE + "---------------------------------------");
                                                if (isBlueTeam) {
                                                    targetPlayer.sendMessage(ChatColor.GREEN + "You were automatically put into the " + ChatColor.BLUE + "BLUE" + ChatColor.GREEN + " team!");
                                                } else if (isRedTeam) {
                                                    targetPlayer.sendMessage(ChatColor.GREEN + "You were automatically put into the " + ChatColor.RED + "RED" + ChatColor.GREEN + " team!");
                                                }
                                                if (!spec.isEmpty()) {
                                                    PacketUtils.sendTitle(targetPlayer, ChatColor.GREEN + spec, isBlueTeam ? ChatColor.BLUE.toString() + ChatColor.BOLD + "BLUE" : isRedTeam ? ChatColor.RED.toString() + ChatColor.BOLD + "RED" : "", 0, 100, 40);
                                                    targetPlayer.sendMessage(ChatColor.GREEN + "Your spec was automatically changed to " + ChatColor.YELLOW + spec + ChatColor.GREEN + "!");
                                                }
                                                targetPlayer.sendMessage("");
                                                blueTeam.forEach(s -> {
                                                    if (s.contains(name)) {
                                                        targetPlayer.sendMessage(ChatColor.GREEN + s.substring(2, s.indexOf('-') - 2) + s.substring(s.indexOf('-') - 2));
                                                    } else {
                                                        targetPlayer.sendMessage(s);
                                                    }
                                                });
                                                redTeam.forEach(s -> {
                                                    if (s.contains(name)) {
                                                        targetPlayer.sendMessage(ChatColor.GREEN + s.substring(2, s.indexOf('-') - 2) + s.substring(s.indexOf('-') - 2));
                                                    } else {
                                                        targetPlayer.sendMessage(s);
                                                    }
                                                });
                                                targetPlayer.sendMessage(ChatColor.DARK_BLUE + "---------------------------------------");
                                            }
                                        }
                                        return null;
                                    }).get();
                                } catch (InterruptedException | ExecutionException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                    break;
                }
            case "waiting":
                {
                    if (member != null && member.getUser().isBot()) {
                        return;
                    }
                    // disable queue on test servers
                    if (!Warlords.serverIP.equals("51.81.49.127")) {
                        return;
                    }
                    String queueCommand = message.getContentRaw();
                    String[] args = queueCommand.substring(1).split(" ");
                    // System.out.println(Arrays.toString(args));
                    if (member != null) {
                        String playerName = member.getEffectiveName();
                        if (queueCommand.equalsIgnoreCase("-queue")) {
                            QueueManager.sendNewQueue();
                        } else if (queueCommand.startsWith("-queue") && args.length > 0) {
                            switch(args[1]) {
                                case "join":
                                    {
                                        if (QueueManager.queue.stream().anyMatch(uuid -> uuid.equals(Bukkit.getOfflinePlayer(playerName).getUniqueId())) || QueueManager.futureQueue.stream().anyMatch(futureQueuePlayer -> futureQueuePlayer.getUuid().equals(Bukkit.getOfflinePlayer(playerName).getUniqueId()))) {
                                            message.reply("You are already in the queue!").queue();
                                            break;
                                        }
                                        if (args.length == 3) {
                                            // adding to queue for future time
                                            try {
                                                String futureTime = args[2];
                                                SimpleDateFormat hourFormat = new SimpleDateFormat("hh");
                                                SimpleDateFormat minuteFormat = new SimpleDateFormat("mm");
                                                hourFormat.setTimeZone(TimeZone.getTimeZone("EST"));
                                                minuteFormat.setTimeZone(TimeZone.getTimeZone("EST"));
                                                Date date = new Date();
                                                int currentHour = Integer.parseInt(hourFormat.format(date));
                                                int currentMinute = Integer.parseInt(minuteFormat.format(date));
                                                int hourDiff = Integer.parseInt(futureTime.substring(0, futureTime.indexOf(':'))) - currentHour;
                                                int minuteDiff = Integer.parseInt(futureTime.substring(futureTime.indexOf(':') + 1)) - currentMinute;
                                                if (hourDiff > 5) {
                                                    textChannel.sendMessage("You cannot join the queue 3+ hours ahead").queue();
                                                } else if (hourDiff == 0 && minuteDiff < 20) {
                                                    textChannel.sendMessage("You cannot join the queue within 20 minutes. Join the server and type **/queue join** to join the queue now").queue();
                                                } else if (hourDiff >= 0) {
                                                    long futureTimeMillis = System.currentTimeMillis();
                                                    futureTimeMillis += hourDiff * 3600000L;
                                                    futureTimeMillis += minuteDiff * 60000L;
                                                    long diff = futureTimeMillis - System.currentTimeMillis();
                                                    message.reply("You will join the queue in **" + TimeUnit.MILLISECONDS.toMinutes(diff) + "** minutes. Make sure you are online at that time or you will be automatically removed if there is an open party spot!").queue();
                                                    QueueManager.addPlayerToFutureQueue(playerName, futureTime, new BukkitRunnable() {

                                                        @Override
                                                        public void run() {
                                                            QueueManager.addPlayerToQueue(playerName, false);
                                                            QueueManager.futureQueue.removeIf(futureQueuePlayer -> futureQueuePlayer.getUuid().equals(Bukkit.getOfflinePlayer(member.getEffectiveName()).getUniqueId()));
                                                            textChannel.sendMessage("<@" + member.getId() + "> You are now in the queue, make sure you are on the server once the party is open").queue();
                                                            QueueManager.sendNewQueue();
                                                        }
                                                    }.runTaskLater(Warlords.getInstance(), TimeUnit.MILLISECONDS.toSeconds(diff) * 20));
                                                } else {
                                                    message.reply("Invalid Time - HOUR:MINUTE").queue();
                                                }
                                            } catch (Exception e) {
                                                message.reply("Invalid Time - HOUR:MINUTE").queue();
                                            }
                                        } else {
                                            // adding to queue normally
                                            QueueManager.addPlayerToQueue(member.getEffectiveName(), false);
                                        }
                                        break;
                                    }
                                case "leave":
                                    {
                                        if (QueueManager.queue.stream().anyMatch(uuid -> uuid.equals(Bukkit.getOfflinePlayer(playerName).getUniqueId()))) {
                                            QueueManager.removePlayerFromQueue(playerName);
                                            message.reply("You left the queue!").queue();
                                            break;
                                        } else if (QueueManager.futureQueue.stream().anyMatch(futureQueuePlayer -> futureQueuePlayer.getUuid().equals(Bukkit.getOfflinePlayer(playerName).getUniqueId()))) {
                                            QueueManager.removePlayerFromFutureQueue(playerName);
                                            message.reply("You left the future queue!").queue();
                                            break;
                                        }
                                        break;
                                    }
                            }
                            QueueManager.sendNewQueue();
                            break;
                        }
                    }
                }
        }
    }
}
Also used : Utils(com.ebicep.warlords.util.warlords.Utils) net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) java.util(java.util) PacketUtils(com.ebicep.warlords.util.bukkit.PacketUtils) SimpleDateFormat(java.text.SimpleDateFormat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DiscordCommand(com.ebicep.warlords.commands.miscellaneouscommands.DiscordCommand) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) EventHandler(org.bukkit.event.EventHandler) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Classes(com.ebicep.warlords.player.Classes) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Team(com.ebicep.warlords.game.Team) QueueManager(com.ebicep.warlords.queuesystem.QueueManager) ListenerAdapter(net.dv8tion.jda.api.hooks.ListenerAdapter) Warlords(com.ebicep.warlords.Warlords) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) OfflinePlayer(org.bukkit.OfflinePlayer) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) BukkitTask(org.bukkit.scheduler.BukkitTask) ChatColor(org.bukkit.ChatColor) MessageReceivedEvent(net.dv8tion.jda.api.events.message.MessageReceivedEvent) OfflinePlayer(org.bukkit.OfflinePlayer) ExecutionException(java.util.concurrent.ExecutionException) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) OfflinePlayer(org.bukkit.OfflinePlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ExecutionException(java.util.concurrent.ExecutionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with ItemBuilder

use of com.ebicep.warlords.util.bukkit.ItemBuilder in project Warlords by ebicep.

the class AchievementsMenu method openChallengeAchievementHistoryMenu.

public static void openChallengeAchievementHistoryMenu(Player player, GameMode gameMode, ChallengeAchievements achievement) {
    if (DatabaseManager.playerService == null)
        return;
    DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
    List<ChallengeAchievements.ChallengeAchievementRecord> achievementRecords = databasePlayer.getAchievements().stream().filter(ChallengeAchievements.ChallengeAchievementRecord.class::isInstance).map(ChallengeAchievements.ChallengeAchievementRecord.class::cast).filter(t -> t.getAchievement() == achievement).collect(Collectors.toList());
    Menu menu = new Menu("Achievement History", 9 * 6);
    int x = 0;
    int y = 0;
    for (ChallengeAchievements.ChallengeAchievementRecord achievementRecord : achievementRecords) {
        menu.setItem(x, y, new ItemBuilder(Material.BOOK).name(ChatColor.GREEN + achievement.name).lore(ChatColor.GRAY + DATE_FORMAT.format(achievementRecord.getDate())).get(), (m, e) -> {
        });
        x++;
        if (x == 9) {
            x = 0;
            y++;
        }
    }
    menu.setItem(3, 5, MENU_BACK, (m, e) -> openChallengeAchievementsMenu(player, gameMode));
    menu.setItem(4, 5, MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.openForPlayer(player);
}
Also used : ItemFlag(org.bukkit.inventory.ItemFlag) TieredAchievements(com.ebicep.warlords.achievements.types.TieredAchievements) Menu(com.ebicep.warlords.menu.Menu) Arrays(java.util.Arrays) Enchantment(org.bukkit.enchantments.Enchantment) SimpleDateFormat(java.text.SimpleDateFormat) Warlords(com.ebicep.warlords.Warlords) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) WordWrap(com.ebicep.warlords.util.bukkit.WordWrap) Player(org.bukkit.entity.Player) UUID(java.util.UUID) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) Collectors(java.util.stream.Collectors) ChallengeAchievements(com.ebicep.warlords.achievements.types.ChallengeAchievements) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) List(java.util.List) ChatColor(org.bukkit.ChatColor) GameMode(com.ebicep.warlords.game.GameMode) Material(org.bukkit.Material) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) ChallengeAchievements(com.ebicep.warlords.achievements.types.ChallengeAchievements) Menu(com.ebicep.warlords.menu.Menu) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)

Example 3 with ItemBuilder

use of com.ebicep.warlords.util.bukkit.ItemBuilder in project Warlords by ebicep.

the class SpectateCommand method openSpectateMenu.

public static void openSpectateMenu(Player player) {
    Menu menu = new Menu("Current Games", 9 * 3);
    int column = 0;
    int row = 0;
    for (GameHolder holder : Warlords.getGameManager().getGames()) {
        Game game = holder.getGame();
        if (game != null && game.acceptsSpectators()) {
            menu.setItem(column, row, new ItemBuilder(Material.BOOK).name(ChatColor.GREEN + "Game " + game.getGameId()).lore(ChatColor.DARK_GRAY + "Map - " + ChatColor.RED + game.getMap().getMapName(), ChatColor.DARK_GRAY + "GameMode - " + ChatColor.RED + game.getGameMode(), ChatColor.DARK_GRAY + "Addons - " + ChatColor.RED + game.getAddons(), ChatColor.DARK_GRAY + "Players - " + ChatColor.RED + game.playersCount()).get(), (m, e) -> {
                if (game.isClosed()) {
                    player.sendMessage(ChatColor.RED + "This game is no longer running");
                    openSpectateMenu(player);
                    return;
                }
                if (!game.acceptsSpectators()) {
                    player.sendMessage(ChatColor.RED + "This game does not accepts spectators");
                    openSpectateMenu(player);
                    return;
                }
                Optional<Game> currentGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
                if (currentGame.isPresent() && currentGame.get().getPlayerTeam(player.getUniqueId()) != null) {
                    player.sendMessage(ChatColor.RED + "You cannot use this command inside a game!");
                } else if (currentGame.isPresent() && currentGame.get().equals(game)) {
                    player.sendMessage(ChatColor.RED + "You are already spectating this game");
                } else {
                    if (currentGame.isPresent()) {
                        currentGame.get().removePlayer(player.getUniqueId());
                    }
                    game.addPlayer(player, true);
                }
            });
            column++;
            if (column > 8) {
                column = 0;
                row++;
            }
        }
    }
    Optional<Game> currentGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
    if (currentGame.isPresent()) {
        menu.setItem(4, 2, new ItemBuilder(Material.BARRIER).name(ChatColor.GREEN + "Return to the lobby").get(), (m, e) -> {
            Optional<Game> currentGame1 = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
            if (currentGame1.isPresent() && currentGame1.get().getPlayerTeam(player.getUniqueId()) != null) {
                player.sendMessage(ChatColor.RED + "You cannot use this command inside a game!");
            } else {
                currentGame1.get().removePlayer(player.getUniqueId());
            }
        });
    }
    menu.openForPlayer(player);
}
Also used : ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) GameHolder(com.ebicep.warlords.game.GameManager.GameHolder) Game(com.ebicep.warlords.game.Game) Menu(com.ebicep.warlords.menu.Menu)

Example 4 with ItemBuilder

use of com.ebicep.warlords.util.bukkit.ItemBuilder in project Warlords by ebicep.

the class DebugLocationMarker method getAsItem.

/**
 * Converts this debug marker into an item for the debug screen
 *
 * @return
 */
@Nonnull
default ItemStack getAsItem() {
    ItemBuilder item = new ItemBuilder(getMaterial(), 1, getMaterialData());
    String name = getName();
    String newName;
    if (name.indexOf(ChatColor.COLOR_CHAR) >= 0) {
        newName = name;
    } else {
        int index = name.indexOf(": ");
        if (index > 0) {
            newName = ChatColor.GOLD + name.substring(0, index + 1) + ChatColor.WHITE + name.substring(index + 1);
        } else {
            newName = ChatColor.GOLD + name;
        }
    }
    item.name(newName);
    Location loc = getLocation();
    List<String> lore = new ArrayList<>();
    lore.add(ChatColor.GRAY + "XYZ: " + ChatColor.WHITE + loc.getX() + ", " + loc.getY() + ", " + loc.getZ() + " Yaw/pitch: " + loc.getYaw() + "/" + loc.getPitch());
    lore.add(ChatColor.GRAY + "Source: " + ChatColor.WHITE + getCreator().getName());
    for (String extra : getExtra()) {
        String newString;
        if (extra.indexOf(ChatColor.COLOR_CHAR) >= 0) {
            newString = extra;
        } else {
            int index = extra.indexOf(": ");
            if (index > 0) {
                newString = ChatColor.GRAY + extra.substring(0, index + 1) + ChatColor.WHITE + extra.substring(index + 1);
            } else {
                newString = ChatColor.WHITE + extra;
            }
        }
        lore.add(newString);
    }
    item.lore(lore);
    return item.get();
}
Also used : ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) ArrayList(java.util.ArrayList) Location(org.bukkit.Location) Nonnull(javax.annotation.Nonnull)

Example 5 with ItemBuilder

use of com.ebicep.warlords.util.bukkit.ItemBuilder in project Warlords by ebicep.

the class GameMenu method openClassMenu.

public static void openClassMenu(Player player, ClassesGroup selectedGroup) {
    Classes selectedClass = getSelected(player);
    Menu menu = new Menu(selectedGroup.name, 9 * 4);
    List<Classes> values = selectedGroup.subclasses;
    for (int i = 0; i < values.size(); i++) {
        Classes subClass = values.get(i);
        ItemBuilder builder = new ItemBuilder(subClass.specType.itemStack).name(ChatColor.GREEN + "Specialization: " + subClass.name + " " + ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + "Lv" + ExperienceManager.getLevelString(ExperienceManager.getLevelForSpec(player.getUniqueId(), subClass)) + ChatColor.DARK_GRAY + "]").flags(ItemFlag.HIDE_ENCHANTS);
        List<String> lore = new ArrayList<>();
        lore.add(subClass.description);
        lore.add("");
        long experience = ExperienceManager.getExperienceForSpec(player.getUniqueId(), subClass);
        int level = (int) ExperienceManager.calculateLevelFromExp(experience);
        lore.add(ExperienceManager.getProgressString(experience, level + 1));
        lore.add("");
        if (subClass == selectedClass) {
            lore.add(ChatColor.GREEN + ">>> ACTIVE <<<");
            builder.enchant(Enchantment.OXYGEN, 1);
        } else {
            lore.add(ChatColor.YELLOW + "> Click to activate <");
        }
        builder.lore(lore);
        menu.setItem(9 / 2 - values.size() / 2 + i * 2 - 1, 1, builder.get(), (m, e) -> {
            player.sendMessage(ChatColor.WHITE + "Spec: §6" + subClass);
            player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 2);
            ArmorManager.resetArmor(player, subClass, Warlords.getPlayerSettings(player.getUniqueId()).getWantedTeam());
            PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
            playerSettings.setSelectedClass(subClass);
            AbstractPlayerClass apc = subClass.create.get();
            player.getInventory().setItem(1, new ItemBuilder(apc.getWeapon().getItem(playerSettings.getWeaponSkins().getOrDefault(subClass, Weapons.FELFLAME_BLADE).item)).name("§aWeapon Skin Preview").lore("").get());
            openClassMenu(player, selectedGroup);
            if (DatabaseManager.playerService == null)
                return;
            DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
            databasePlayer.setLastSpec(subClass);
            DatabaseManager.updatePlayerAsync(databasePlayer);
        });
    }
    menu.setItem(4, 3, MENU_BACK_PREGAME, (m, e) -> openMainMenu(player));
    menu.openForPlayer(player);
}
Also used : ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) AbstractPlayerClass(com.ebicep.warlords.classes.AbstractPlayerClass) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) Classes(com.ebicep.warlords.player.Classes)

Aggregations

ItemBuilder (com.ebicep.warlords.util.bukkit.ItemBuilder)49 Menu (com.ebicep.warlords.menu.Menu)31 ItemStack (org.bukkit.inventory.ItemStack)22 Warlords (com.ebicep.warlords.Warlords)12 Player (org.bukkit.entity.Player)12 Classes (com.ebicep.warlords.player.Classes)11 DatabasePlayer (com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)10 Collectors (java.util.stream.Collectors)10 DatabaseManager (com.ebicep.warlords.database.DatabaseManager)8 Team (com.ebicep.warlords.game.Team)8 ChatColor (org.bukkit.ChatColor)8 AbstractPlayerClass (com.ebicep.warlords.classes.AbstractPlayerClass)7 List (java.util.List)7 Material (org.bukkit.Material)7 Enchantment (org.bukkit.enchantments.Enchantment)7 ItemFlag (org.bukkit.inventory.ItemFlag)7 ArrayList (java.util.ArrayList)6 Arrays (java.util.Arrays)6 UUID (java.util.UUID)6 Game (com.ebicep.warlords.game.Game)5