Search in sources :

Example 1 with DataBlock

use of me.gameisntover.kbffa.arena.regions.DataBlock in project KnockbackFFA by GaMeIsNtOvEr.

the class GameEventsListener method onBlockPlace.

@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
    Player player = e.getPlayer();
    Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
    if (!knocker.isInGame())
        return;
    if (e.getBlockPlaced().getType() == Material.WHITE_WOOL) {
        Block block = e.getBlockPlaced();
        DataBlock db = KnockbackFFA.getInstance().getBlockDataManager().getBlockData(block);
        db.setBlockType("BuildingBlock");
        String arenaName = KnockbackFFA.getInstance().getArenaManager().getEnabledArena().getName();
        BukkitRunnable runnable = new BukkitRunnable() {

            @Override
            public void run() {
                if (KnockbackFFA.getInstance().getArenaManager().getEnabledArena().getName().equalsIgnoreCase(arenaName)) {
                    switch(block.getType()) {
                        case WHITE_WOOL:
                            block.setType(Material.YELLOW_WOOL);
                            break;
                        case YELLOW_WOOL:
                            block.setType(Material.ORANGE_WOOL);
                            break;
                        case ORANGE_WOOL:
                            block.setType(Material.RED_WOOL);
                            break;
                        case RED_WOOL:
                            block.setType(Material.AIR);
                            cancel();
                            break;
                    }
                } else {
                    block.setType(Material.AIR);
                    db.setBlockType("");
                }
            }
        };
        runnable.runTaskTimer(KnockbackFFA.getInstance(), 10L, 20L);
        BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
        scheduler.scheduleSyncDelayedTask(KnockbackFFA.getInstance(), () -> player.getInventory().addItem(Items.BUILDING_BLOCK.getItem()), 1);
    }
    if (e.getBlockPlaced().getType() == Material.LIGHT_WEIGHTED_PRESSURE_PLATE) {
        Block block = e.getBlockPlaced();
        block.getDrops().clear();
        BukkitScheduler blockTimer = Bukkit.getServer().getScheduler();
        blockTimer.scheduleSyncDelayedTask(KnockbackFFA.getInstance(), () -> e.getBlock().setType(Material.AIR), 100);
    }
}
Also used : Player(org.bukkit.entity.Player) Knocker(me.gameisntover.kbffa.api.Knocker) DataBlock(me.gameisntover.kbffa.arena.regions.DataBlock) Block(org.bukkit.block.Block) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) DataBlock(me.gameisntover.kbffa.arena.regions.DataBlock) EventHandler(org.bukkit.event.EventHandler)

Example 2 with DataBlock

use of me.gameisntover.kbffa.arena.regions.DataBlock 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)

Aggregations

Knocker (me.gameisntover.kbffa.api.Knocker)2 DataBlock (me.gameisntover.kbffa.arena.regions.DataBlock)2 Block (org.bukkit.block.Block)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 ArrayList (java.util.ArrayList)1 Arena (me.gameisntover.kbffa.arena.Arena)1 Kit (me.gameisntover.kbffa.kit.Kit)1 Material (org.bukkit.Material)1 ItemStack (org.bukkit.inventory.ItemStack)1 BukkitScheduler (org.bukkit.scheduler.BukkitScheduler)1