Search in sources :

Example 6 with Knocker

use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.

the class Kit method giveKit.

public void giveKit(Player player) {
    if (getConfig().getList("KitContents") != null) {
        List<ItemStack> kitContents = Arrays.asList(getConfig().getList("KitContents").toArray(new ItemStack[0]));
        player.getInventory().setContents(kitContents.toArray(new ItemStack[0]));
        for (ItemStack item : kitContents) {
            if (item.getType().toString().contains("Helmet"))
                player.getInventory().setHelmet(item);
            if (item.getType().toString().contains("Chestplate"))
                player.getInventory().setChestplate(item);
            if (item.getType().toString().contains("Leggings"))
                player.getInventory().setLeggings(item);
            if (item.getType().toString().contains("Boots"))
                player.getInventory().setBoots(item);
        }
    } else {
        Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
        knocker.getConfig().set("owned-kits", knocker.getConfig().getStringList("owned-kits").stream().filter(s -> s.contains(kitName)).collect(Collectors.toList()));
        knocker.saveConfig();
    }
}
Also used : Knocker(me.gameisntover.kbffa.api.Knocker) ItemStack(org.bukkit.inventory.ItemStack)

Example 7 with Knocker

use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.

the class ArenaSettings method onItemDrop.

@EventHandler
public void onItemDrop(PlayerDropItemEvent e) {
    Player player = e.getPlayer();
    Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
    if (!knocker.isInGame())
        return;
    String[] arenaList = KnockbackFFA.getInstance().getArenaManager().getFolder().list();
    assert arenaList != null;
    for (String arenaName : arenaList) {
        Arena arena = KnockbackFFA.getInstance().getArenaManager().load(arenaName.replace(".yml", ""));
        e.setCancelled(knocker.isInArena() && !arena.getConfig().getBoolean("item-drop"));
    }
}
Also used : Player(org.bukkit.entity.Player) Knocker(me.gameisntover.kbffa.api.Knocker) Arena(me.gameisntover.kbffa.arena.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 8 with Knocker

use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.

the class ArenaSettings method onPlayerGoesToArena.

@EventHandler
public void onPlayerGoesToArena(PlayerMoveEvent e) {
    Player player = e.getPlayer();
    Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
    if (KnockbackFFA.getInstance().getArenaManager().getEnabledArena() != null) {
        Arena arena = KnockbackFFA.getInstance().getArenaManager().load(KnockbackFFA.getInstance().getArenaManager().getEnabledArena().getName());
        if (!arena.contains(player.getLocation()))
            return;
        if (!knocker.isInArena())
            knocker.setInArena(true);
        if (knocker.getConfig().getString("selected-kit") == null)
            knocker.getConfig().set("selected-kit", "Default");
        List<String> ownedKits = knocker.getConfig().getStringList("owned-kits");
        if (!ownedKits.contains("Default")) {
            ownedKits.add("Default");
            knocker.getConfig().set("owned-kits", ownedKits);
        }
        Kit kit = KnockbackFFA.getInstance().getKitManager().load(knocker.getConfig().getString("selected-kit"));
        for (ItemStack item : player.getInventory().getContents()) {
            if (item != null) {
                if (Items.COSMETIC_ITEM.getItem().equals(item) || Items.SHOP_ITEM.getItem().equals(item) || Items.KIT_ITEM.getItem().equals(item)) {
                    player.getInventory().clear();
                    kit.giveKit(player);
                    break;
                }
            }
        }
    } else
        knocker.setInArena(false);
    if (!knocker.isInGame())
        return;
    if (knocker.getConfig().getString("selected-trails") == null)
        return;
    String selectedTrails = knocker.getConfig().getString("selected-trails");
    Block block = player.getWorld().getBlockAt(e.getFrom().getBlockX(), e.getFrom().getBlockY() - 1, e.getFrom().getBlockZ());
    DataBlock db = KnockbackFFA.getInstance().getBlockDataManager().getBlockData(block);
    if (!db.getBlockType().equals("") || db.getBlockType() != null)
        return;
    if (KnockbackFFA.getInstance().getConfig().getStringList("no-trail-blocks").contains(block.getType().toString()))
        return;
    db.setPrevMaterial(block.getType());
    List<String> materialString = KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getStringList(selectedTrails + ".blocks");
    List<Material> materialList = new ArrayList<>();
    for (String material : materialString) materialList.add(Material.getMaterial(material));
    if (materialList.size() == 1) {
        block.setType(materialList.get(0));
        db.setBlockType("trail");
        new BukkitRunnable() {

            @Override
            public void run() {
                block.setType(db.getPrevMaterial());
                db.setBlockType("");
                cancel();
            }
        }.runTaskTimer(KnockbackFFA.getInstance(), KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getInt(selectedTrails + ".speed") * 20L, 1);
    } else {
        block.setType(materialList.get(0));
        db.setBlockType("trail");
        new BukkitRunnable() {

            int i = 0;

            @Override
            public void run() {
                if (i < materialList.size() - 1) {
                    i++;
                    String material = materialList.get(i).name();
                    block.setType(Material.getMaterial(material));
                } else {
                    block.setType(db.getPrevMaterial());
                    db.setBlockType("");
                    cancel();
                }
            }
        }.runTaskTimer(KnockbackFFA.getInstance(), KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getInt(selectedTrails + ".speed") * 20, KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getInt(selectedTrails + ".speed") * 20);
    }
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Material(org.bukkit.Material) Arena(me.gameisntover.kbffa.arena.Arena) DataBlock(me.gameisntover.kbffa.arena.regions.DataBlock) Knocker(me.gameisntover.kbffa.api.Knocker) Kit(me.gameisntover.kbffa.kit.Kit) DataBlock(me.gameisntover.kbffa.arena.regions.DataBlock) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Knocker

use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.

the class DeathListener method playerDeathByVoid.

@EventHandler
public void playerDeathByVoid(PlayerDeathEvent e) {
    Player player = e.getEntity();
    Entity damager = killer.get(player);
    if (KnockbackFFA.getInstance().getArenaManager() == null)
        return;
    Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
    Arena arena = KnockbackFFA.getInstance().getArenaManager().getEnabledArena();
    killer.remove(player);
    knocker.setInArena(false);
    if (!KnockbackFFA.getInstance().BungeeMode() && !knocker.isInGame())
        return;
    new BukkitRunnable() {

        @Override
        public void run() {
            player.spigot().respawn();
            knocker.giveLobbyItems();
            arena.teleportPlayer(player);
            cancel();
        }
    }.runTaskTimer(KnockbackFFA.getInstance(), 0, 1);
    World world = player.getWorld();
    List<Entity> entList = world.getEntities();
    for (Entity current : entList) if ((current instanceof Item))
        current.remove();
    knocker.setKillStreak(0);
    knocker.getConfig().set("deaths", knocker.getConfig().getInt("deaths") + 1);
    knocker.saveConfig();
    if (damager == null) {
        player.sendMessage(Message.DEATH_VOID.toString());
        e.setDeathMessage(Message.DEATH_VOID_GLOBAL.toString().replace("%player_name%", player.getName()));
    } else {
        if (damager != player && damager instanceof Player) {
            knocker.loadCosmetic(knocker.selectedCosmetic());
            Knocker damageKnocker = KnockbackFFA.getInstance().getKnocker((Player) damager);
            float prize = KnockbackFFA.getInstance().getConfig().getInt("kill-prize");
            damageKnocker.sendMessage(Message.PRIZE.toString().replace("%prize%", prize + "").replace("&", "ยง"));
            damageKnocker.addBalance(prize);
            damageKnocker.getConfig().set("kills", damageKnocker.getConfig().getInt("kills") + 1);
            damageKnocker.setKillStreak(damageKnocker.getKillStreak() + 1);
            if (damageKnocker.getKillStreak() > damageKnocker.getConfig().getInt("best-ks")) {
                String msg = Message.KILLSTREAK_RECORD.toString().replace("%killstreak%", damageKnocker.getConfig().getInt("best-ks") + "");
                damageKnocker.sendActionBar(msg);
                damageKnocker.getConfig().set("best-ks", damageKnocker.getKillStreak());
            }
            damageKnocker.saveConfig();
            e.setDeathMessage(PlaceholderAPI.setPlaceholders(e.getEntity(), Message.DEATH_KNOCKED_GOBAL.toString().replace("%killer%", damager.getName())));
        } else if (damager.hasMetadata("bot"))
            e.setDeathMessage(PlaceholderAPI.setPlaceholders(e.getEntity(), Message.DEATH_KNOCKED_GOBAL.toString().replace("%killer%", damager.getName())));
    }
}
Also used : Knocker(me.gameisntover.kbffa.api.Knocker) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) World(org.bukkit.World) Arena(me.gameisntover.kbffa.arena.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 10 with Knocker

use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.

the class ArenaManager method changeArena.

/**
 * Changes the arena to another arena
 */
public void changeArena(Arena arena) {
    String arenaName = arena.getName();
    setEnabledArena(arenaName);
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        Knocker knocker = KnockbackFFA.getInstance().getKnocker(p);
        if (!knocker.isInGame())
            return;
        p.getInventory().clear();
        knocker.giveLobbyItems();
        teleportPlayerToArena(p);
        p.playSound(p.getLocation(), Sounds.ARENA_CHANGE.toSound(), 1, 1);
        p.sendMessage(ChatColor.translateAlternateColorCodes('&', Message.ARENA_CHANGE.toString()).replace("%arena%", arenaName));
    }
    if (arena.getConfig().getBoolean("auto-reset"))
        arena.resetArena();
}
Also used : Player(org.bukkit.entity.Player) Knocker(me.gameisntover.kbffa.api.Knocker)

Aggregations

Knocker (me.gameisntover.kbffa.api.Knocker)18 Player (org.bukkit.entity.Player)14 EventHandler (org.bukkit.event.EventHandler)12 Arena (me.gameisntover.kbffa.arena.Arena)5 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5 DataBlock (me.gameisntover.kbffa.arena.regions.DataBlock)3 Block (org.bukkit.block.Block)3 ItemStack (org.bukkit.inventory.ItemStack)3 Kit (me.gameisntover.kbffa.kit.Kit)2 Material (org.bukkit.Material)2 World (org.bukkit.World)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 SneakyThrows (lombok.SneakyThrows)1 KnockbackFFA (me.gameisntover.kbffa.KnockbackFFA)1 ArenaManager (me.gameisntover.kbffa.arena.ArenaManager)1