Search in sources :

Example 1 with ShopCache

use of com.andrei1058.bedwars.shop.ShopCache in project BedWars1058 by andrei1058.

the class BedWarsTeam method respawnMember.

/**
 * Respawn a member
 */
public void respawnMember(@NotNull Player p) {
    if (reSpawnInvulnerability.containsKey(p.getUniqueId())) {
        reSpawnInvulnerability.replace(p.getUniqueId(), System.currentTimeMillis() + config.getInt(ConfigPath.GENERAL_CONFIGURATION_RE_SPAWN_INVULNERABILITY));
    } else {
        reSpawnInvulnerability.put(p.getUniqueId(), System.currentTimeMillis() + config.getInt(ConfigPath.GENERAL_CONFIGURATION_RE_SPAWN_INVULNERABILITY));
    }
    p.teleport(getSpawn(), PlayerTeleportEvent.TeleportCause.PLUGIN);
    p.setVelocity(new Vector(0, 0, 0));
    getArena().getRespawnSessions().remove(p);
    p.removePotionEffect(PotionEffectType.INVISIBILITY);
    nms.setCollide(p, arena, true);
    p.setAllowFlight(false);
    p.setFlying(false);
    p.setHealth(20);
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        for (Player inGame : arena.getPlayers()) {
            if (inGame.equals(p))
                continue;
            BedWars.nms.spigotShowPlayer(p, inGame);
            BedWars.nms.spigotShowPlayer(inGame, p);
        }
        for (Player spectator : arena.getSpectators()) {
            BedWars.nms.spigotShowPlayer(p, spectator);
        }
    }, 8L);
    nms.sendTitle(p, getMsg(p, Messages.PLAYER_DIE_RESPAWNED_TITLE), "", 0, 20, 0);
    sendDefaultInventory(p, false);
    ShopCache sc = ShopCache.getShopCache(p.getUniqueId());
    if (sc != null) {
        sc.managePermanentsAndDowngradables(getArena());
    }
    p.setHealth(20);
    if (!getBaseEffects().isEmpty()) {
        for (PotionEffect ef : getBaseEffects()) {
            p.addPotionEffect(ef, true);
        }
    }
    if (!getTeamEffects().isEmpty()) {
        for (PotionEffect ef : getTeamEffects()) {
            p.addPotionEffect(ef, true);
        }
    }
    if (!getBowsEnchantments().isEmpty()) {
        for (ItemStack i : p.getInventory().getContents()) {
            if (i == null)
                continue;
            if (i.getType() == Material.BOW) {
                ItemMeta im = i.getItemMeta();
                for (TeamEnchant e : getBowsEnchantments()) {
                    im.addEnchant(e.getEnchantment(), e.getAmplifier(), true);
                }
                i.setItemMeta(im);
            }
            p.updateInventory();
        }
    }
    if (!getSwordsEnchantments().isEmpty()) {
        for (ItemStack i : p.getInventory().getContents()) {
            if (i == null)
                continue;
            if (nms.isSword(i)) {
                ItemMeta im = i.getItemMeta();
                for (TeamEnchant e : getSwordsEnchantments()) {
                    im.addEnchant(e.getEnchantment(), e.getAmplifier(), true);
                }
                i.setItemMeta(im);
            }
            p.updateInventory();
        }
    }
    if (!getArmorsEnchantments().isEmpty()) {
        for (ItemStack i : p.getInventory().getArmorContents()) {
            if (i == null)
                continue;
            if (nms.isArmor(i)) {
                ItemMeta im = i.getItemMeta();
                for (TeamEnchant e : getArmorsEnchantments()) {
                    im.addEnchant(e.getEnchantment(), e.getAmplifier(), true);
                }
                i.setItemMeta(im);
            }
            p.updateInventory();
        }
    }
    Bukkit.getPluginManager().callEvent(new PlayerReSpawnEvent(p, getArena(), this));
    nms.sendPlayerSpawnPackets(p, getArena());
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        if (getArena() != null) {
            nms.sendPlayerSpawnPackets(p, getArena());
            // #274
            for (Player on : getArena().getShowTime().keySet()) {
                BedWars.nms.hideArmor(on, p);
            }
        }
    // 
    }, 10L);
    /*if (!config.getBoolean(ConfigPath.GENERAL_CONFIGURATION_PERFORMANCE_DISABLE_RESPAWN_PACKETS)) {
            Bukkit.getScheduler().runTaskLater(plugin, () -> nms.invisibilityFix(p, getArena()), 12L);
            Bukkit.getScheduler().runTaskLater(plugin, () -> nms.invisibilityFix(p, getArena()), 30L);
            Bukkit.getScheduler().runTaskLater(plugin, () -> arena.getPlayers().forEach(pl -> nms.showPlayer(pl, p)), 25L);
        }*/
    // un-vanish from respawn
    /*Bukkit.getScheduler().runTaskLater(plugin, () -> {
            arena.getPlayers().forEach(pl -> {
                nms.showPlayer(p, pl);
                nms.showArmor(p, pl);
                nms.showPlayer(pl, p);
                nms.showArmor(pl, p);
            });
            arena.getSpectators().forEach(pl -> {
                nms.showPlayer(p, pl);
                nms.showArmor(p, pl);
            });
        }, 20L);*/
    Sounds.playSound("player-re-spawn", p);
}
Also used : Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) TeamEnchant(com.andrei1058.bedwars.api.arena.team.TeamEnchant) ShopCache(com.andrei1058.bedwars.shop.ShopCache) PlayerReSpawnEvent(com.andrei1058.bedwars.api.events.player.PlayerReSpawnEvent) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 2 with ShopCache

use of com.andrei1058.bedwars.shop.ShopCache in project BedWars1058 by andrei1058.

the class ShopCacheListener method onArenaJoin.

@EventHandler(priority = EventPriority.LOWEST)
public void onArenaJoin(PlayerJoinArenaEvent e) {
    if (e.isSpectator())
        return;
    ShopCache sc = ShopCache.getShopCache(e.getPlayer().getUniqueId());
    if (sc != null) {
        sc.destroy();
    }
    new ShopCache(e.getPlayer().getUniqueId());
}
Also used : ShopCache(com.andrei1058.bedwars.shop.ShopCache) EventHandler(org.bukkit.event.EventHandler)

Example 3 with ShopCache

use of com.andrei1058.bedwars.shop.ShopCache in project BedWars1058 by andrei1058.

the class CategoryContent method execute.

public void execute(Player player, ShopCache shopCache, int slot) {
    IContentTier ct;
    // check weight
    if (shopCache.getCategoryWeight(father) > weight)
        return;
    if (shopCache.getContentTier(getIdentifier()) > contentTiers.size()) {
        Bukkit.getLogger().severe("Wrong tier order at: " + getIdentifier());
        return;
    }
    // check if can re-buy
    if (shopCache.getContentTier(getIdentifier()) == contentTiers.size()) {
        if (isPermanent() && shopCache.hasCachedItem(this)) {
            player.sendMessage(getMsg(player, Messages.SHOP_ALREADY_BOUGHT));
            Sounds.playSound(ConfigPath.SOUNDS_INSUFF_MONEY, player);
            return;
        }
        // current tier
        ct = contentTiers.get(shopCache.getContentTier(getIdentifier()) - 1);
    } else {
        if (!shopCache.hasCachedItem(this)) {
            ct = contentTiers.get(0);
        } else {
            ct = contentTiers.get(shopCache.getContentTier(getIdentifier()));
        }
    }
    // check money
    int money = calculateMoney(player, ct.getCurrency());
    if (money < ct.getPrice()) {
        player.sendMessage(getMsg(player, Messages.SHOP_INSUFFICIENT_MONEY).replace("{currency}", getMsg(player, getCurrencyMsgPath(ct))).replace("{amount}", String.valueOf(ct.getPrice() - money)));
        Sounds.playSound(ConfigPath.SOUNDS_INSUFF_MONEY, player);
        return;
    }
    ShopBuyEvent event;
    // call shop buy event
    Bukkit.getPluginManager().callEvent(event = new ShopBuyEvent(player, Arena.getArenaByPlayer(player), this));
    if (event.isCancelled()) {
        return;
    }
    // take money
    takeMoney(player, ct.getCurrency(), ct.getPrice());
    // upgrade if possible
    shopCache.upgradeCachedItem(this, slot);
    // give items
    giveItems(player, shopCache, Arena.getArenaByPlayer(player));
    // play sound
    Sounds.playSound(ConfigPath.SOUNDS_BOUGHT, player);
    // send purchase msg
    if (itemNamePath == null || Language.getPlayerLanguage(player).getYml().get(itemNamePath) == null) {
        ItemStack displayItem = ct.getItemStack();
        if (displayItem.getItemMeta() != null && displayItem.getItemMeta().hasDisplayName()) {
            player.sendMessage(getMsg(player, Messages.SHOP_NEW_PURCHASE).replace("{item}", displayItem.getItemMeta().getDisplayName()));
        }
    } else {
        player.sendMessage(getMsg(player, Messages.SHOP_NEW_PURCHASE).replace("{item}", ChatColor.stripColor(getMsg(player, itemNamePath))).replace("{color}", "").replace("{tier}", ""));
    }
    shopCache.setCategoryWeight(father, weight);
}
Also used : ShopBuyEvent(com.andrei1058.bedwars.api.events.shop.ShopBuyEvent) ItemStack(org.bukkit.inventory.ItemStack) IContentTier(com.andrei1058.bedwars.api.arena.shop.IContentTier)

Example 4 with ShopCache

use of com.andrei1058.bedwars.shop.ShopCache in project BedWars1058 by andrei1058.

the class InventoryListener method onUpgradableMove.

@EventHandler
public void onUpgradableMove(InventoryClickEvent e) {
    Player p = (Player) e.getWhoClicked();
    ShopCache sc = ShopCache.getShopCache(p.getUniqueId());
    if (sc == null)
        return;
    // block moving from hotbar
    if (e.getAction() == HOTBAR_SWAP && e.getClick() == ClickType.NUMBER_KEY) {
        if (e.getHotbarButton() > -1) {
            ItemStack i = e.getWhoClicked().getInventory().getItem(e.getHotbarButton());
            if (i != null) {
                if (e.getClickedInventory() != e.getWhoClicked().getInventory()) {
                    if (shouldCancelMovement(i, sc)) {
                        e.setCancelled(true);
                    }
                }
            }
        }
    }
    // block moving cursor item
    if (e.getCursor() != null) {
        if (e.getCursor().getType() != Material.AIR) {
            if (e.getClickedInventory() == null) {
                if (shouldCancelMovement(e.getCursor(), sc)) {
                    e.getWhoClicked().closeInventory();
                    e.setCancelled(true);
                }
            } else if (e.getClickedInventory().getType() != e.getWhoClicked().getInventory().getType()) {
                if (shouldCancelMovement(e.getCursor(), sc)) {
                    e.getWhoClicked().closeInventory();
                    e.setCancelled(true);
                }
            }
        }
    }
    // block moving current item
    if (e.getCurrentItem() != null) {
        if (e.getCurrentItem().getType() != Material.AIR) {
            if (e.getClickedInventory() == null) {
                if (shouldCancelMovement(e.getCursor(), sc)) {
                    e.getWhoClicked().closeInventory();
                    e.setCancelled(true);
                }
            } else if (e.getClickedInventory().getType() != e.getWhoClicked().getInventory().getType()) {
                if (shouldCancelMovement(e.getCurrentItem(), sc)) {
                    e.getWhoClicked().closeInventory();
                    e.setCancelled(true);
                }
            }
        }
    }
    // block moving with shift
    if (e.getAction() == MOVE_TO_OTHER_INVENTORY) {
        if (shouldCancelMovement(e.getCurrentItem(), sc)) {
            if (e.getView().getTopInventory().getHolder() != null && e.getInventory().getHolder() == e.getWhoClicked())
                return;
            e.setCancelled(true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ShopCache(com.andrei1058.bedwars.shop.ShopCache) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 5 with ShopCache

use of com.andrei1058.bedwars.shop.ShopCache in project BedWars1058 by andrei1058.

the class Arena method reJoin.

/**
 * Rejoin an arena
 */
public boolean reJoin(Player p) {
    ReJoin reJoin = ReJoin.getPlayer(p);
    if (reJoin == null)
        return false;
    if (reJoin.getArena() != this)
        return false;
    if (!reJoin.canReJoin())
        return false;
    if (reJoin.getTask() != null) {
        reJoin.getTask().destroy();
    }
    PlayerReJoinEvent ev = new PlayerReJoinEvent(p, this, BedWars.config.getInt(ConfigPath.GENERAL_CONFIGURATION_RE_SPAWN_COUNTDOWN));
    Bukkit.getPluginManager().callEvent(ev);
    if (ev.isCancelled())
        return false;
    for (Player on : Bukkit.getOnlinePlayers()) {
        if (on.equals(p))
            continue;
        if (!isInArena(on)) {
            BedWars.nms.spigotHidePlayer(on, p);
            BedWars.nms.spigotHidePlayer(p, on);
        }
    }
    p.closeInventory();
    players.add(p);
    for (Player on : players) {
        on.sendMessage(getMsg(on, Messages.COMMAND_REJOIN_PLAYER_RECONNECTED).replace("{playername}", p.getName()).replace("{player}", p.getDisplayName()).replace("{on}", String.valueOf(getPlayers().size())).replace("{max}", String.valueOf(getMaxPlayers())));
    }
    for (Player on : spectators) {
        on.sendMessage(getMsg(on, Messages.COMMAND_REJOIN_PLAYER_RECONNECTED).replace("{playername}", p.getName()).replace("{player}", p.getDisplayName()).replace("{on}", String.valueOf(getPlayers().size())).replace("{max}", String.valueOf(getMaxPlayers())));
    }
    setArenaByPlayer(p, this);
    /* save player inventory etc */
    if (BedWars.getServerType() != ServerType.BUNGEE) {
        // no need to backup inventory because it's empty
        // new PlayerGoods(p, true, true);
        playerLocation.put(p, p.getLocation());
    }
    p.teleport(getSpectatorLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
    p.getInventory().clear();
    // restore items before re-spawning in team
    ShopCache sc = ShopCache.getShopCache(p.getUniqueId());
    if (sc != null)
        sc.destroy();
    sc = new ShopCache(p.getUniqueId());
    for (ShopCache.CachedItem ci : reJoin.getPermanentsAndNonDowngradables()) {
        sc.getCachedItems().add(ci);
    }
    reJoin.getBwt().reJoin(p, ev.getRespawnTime());
    reJoin.destroy(false);
    BedWarsScoreboard.giveScoreboard(p, this, true);
    return true;
}
Also used : Player(org.bukkit.entity.Player) ShopCache(com.andrei1058.bedwars.shop.ShopCache) PlayerReJoinEvent(com.andrei1058.bedwars.api.events.player.PlayerReJoinEvent)

Aggregations

ShopCache (com.andrei1058.bedwars.shop.ShopCache)6 Player (org.bukkit.entity.Player)4 ItemStack (org.bukkit.inventory.ItemStack)4 EventHandler (org.bukkit.event.EventHandler)3 IContentTier (com.andrei1058.bedwars.api.arena.shop.IContentTier)2 PlayerQuickBuyCache (com.andrei1058.bedwars.shop.quickbuy.PlayerQuickBuyCache)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 IArena (com.andrei1058.bedwars.api.arena.IArena)1 TeamEnchant (com.andrei1058.bedwars.api.arena.team.TeamEnchant)1 PlayerReJoinEvent (com.andrei1058.bedwars.api.events.player.PlayerReJoinEvent)1 PlayerReSpawnEvent (com.andrei1058.bedwars.api.events.player.PlayerReSpawnEvent)1 ShopBuyEvent (com.andrei1058.bedwars.api.events.shop.ShopBuyEvent)1 CategoryContent (com.andrei1058.bedwars.shop.main.CategoryContent)1 ShopCategory (com.andrei1058.bedwars.shop.main.ShopCategory)1 QuickBuyAdd (com.andrei1058.bedwars.shop.quickbuy.QuickBuyAdd)1 QuickBuyElement (com.andrei1058.bedwars.shop.quickbuy.QuickBuyElement)1 ArrayList (java.util.ArrayList)1 ChatColor (org.bukkit.ChatColor)1 Inventory (org.bukkit.inventory.Inventory)1 PotionEffect (org.bukkit.potion.PotionEffect)1