Search in sources :

Example 11 with Knocker

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

the class GameRules method onBowUse.

@EventHandler
public void onBowUse(ProjectileLaunchEvent e) {
    if (!(e.getEntity().getShooter() instanceof Player))
        return;
    Player player = (Player) e.getEntity().getShooter();
    Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
    if (!KnockbackFFA.getInstance().BungeeMode() || !knocker.isInGame())
        return;
    if (!Items.BOW.getItem().equals(player.getInventory().getItemInMainHand()))
        return;
    new BukkitRunnable() {

        int timer = 10;

        @Override
        public void run() {
            timer--;
            if (timer == 10 || timer == 9 || timer == 8 || timer == 7 || timer == 6 || timer == 5 || timer == 4 || timer == 3 || timer == 2 || timer == 1) {
                if (player.getInventory().contains(Material.ARROW) || !player.getInventory().contains(Material.BOW)) {
                    cancel();
                    timer = 10;
                } else
                    player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(Message.BOW_COOLDOWN.toString().replace("%timer%", String.valueOf(timer)).replace("%player%", player.getName()).replace("&", "ยง")));
                if (timer == 0) {
                    if (!player.getInventory().contains(Material.ARROW) && player.getInventory().contains(Material.BOW))
                        player.getInventory().addItem(Items.ARROW.getItem());
                    cancel();
                    timer = 10;
                }
            }
        }
    }.runTaskTimer(KnockbackFFA.getInstance(), 0, 20);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) Knocker(me.gameisntover.kbffa.api.Knocker) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

Example 12 with Knocker

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

the class KnockbackFFA method getKnocker.

@NotNull
public Knocker getKnocker(@NotNull Player player) {
    if (knockerHandler.containsKey(player.getUniqueId()))
        return knockerHandler.get(player.getUniqueId());
    Knocker knocker = new Knocker(player.getUniqueId());
    knockerHandler.put(player.getUniqueId(), knocker);
    return knocker;
}
Also used : Knocker(me.gameisntover.kbffa.api.Knocker) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with Knocker

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

the class KnockbackFFA method onEnable.

@SneakyThrows
@Override
public void onEnable() {
    long time = System.currentTimeMillis();
    instance = this;
    getLogger().info("Loading config files...");
    if (!getDataFolder().exists())
        getDataFolder().mkdir();
    loadConfig();
    loadMessages();
    loadSounds();
    getLogger().info("Connecting to the database...");
    databaseManager = new DatabaseManager("SQLITE");
    arenaManager = new ArenaManager();
    kitManager = new KitManager();
    blockDataManager = new BlockDataManager();
    botManager = new BotManager();
    scoreboardManager = new BoardManager();
    buttonManager = new ButtonManager();
    Field f = getServer().getClass().getDeclaredField("commandMap");
    f.setAccessible(true);
    commandMap = (CommandMap) f.get(getServer());
    getLogger().info("Loading Commands");
    commandManager = new CommandManager();
    getLogger().info("Loading Listeners");
    loadListeners();
    getLogger().info("Loading Tasks");
    loadTasks();
    long takenTime = (System.currentTimeMillis() - time);
    getLogger().info("Plugin loaded successfully in " + takenTime + "ms");
    registerPlaceholders();
    if (!Bukkit.getOnlinePlayers().isEmpty()) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            Knocker knocker = getKnocker(player);
            knocker.setInGame(BungeeMode());
        }
    }
    for (Knocker p : getInGamePlayers()) {
        if (p.getPlayer().getInventory().contains(Material.BOW) && !p.getPlayer().getInventory().contains(Material.ARROW))
            p.getInventory().addItem(Items.ARROW.getItem());
    }
}
Also used : ArenaManager(me.gameisntover.kbffa.arena.ArenaManager) Field(java.lang.reflect.Field) Player(org.bukkit.entity.Player) Knocker(me.gameisntover.kbffa.api.Knocker) BotManager(me.gameisntover.kbffa.bots.BotManager) CommandManager(me.gameisntover.kbffa.command.CommandManager) DatabaseManager(me.gameisntover.kbffa.database.DatabaseManager) ButtonManager(me.gameisntover.kbffa.gui.ButtonManager) KitManager(me.gameisntover.kbffa.kit.KitManager) BlockDataManager(me.gameisntover.kbffa.arena.regions.BlockDataManager) BoardManager(me.gameisntover.kbffa.scoreboard.BoardManager) SneakyThrows(lombok.SneakyThrows)

Example 14 with Knocker

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

the class KnockbackFFA method loadTasks.

private void loadTasks() {
    if (arenaManager.getFolder().listFiles() == null || arenaManager.getFolder().listFiles().length == 0)
        return;
    List<Arena> arenaList = arenaManager.getArenaList();
    arenaManager.setEnabledArena(arenaList.get(0));
    timer = getConfig().getInt("arena-switch-timer");
    new BukkitRunnable() {

        @Override
        public void run() {
            if (arenaList.size() > 0) {
                String arenaName = arenaList.get(0).getName();
                arenaManager.setEnabledArena(arenaName);
                zoneConfiguration.save();
                for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                    Knocker knocker = getKnocker(p);
                    if (!knocker.isInGame())
                        return;
                    arenaManager.changeArena(arenaManager.load(arenaName.replace(".yml", "")));
                    cancel();
                }
                if (arenaList.size() > 1)
                    arenaID++;
            }
        }
    }.runTaskTimer(this, 0, 1);
    new BukkitRunnable() {

        @Override
        public void run() {
            timer--;
            if (timer == 0) {
                // what should happen when timer is up
                timer = getConfig().getInt("arena-switch-timer");
                if (!arenaList.isEmpty()) {
                    // checking if arenaList even has arenas
                    arenaID++;
                    if (!(arenaID <= arenaList.size()))
                        arenaID = 1;
                    arenaManager.changeArena(arenaList.get(arenaID - 1));
                }
            }
        }
    }.runTaskTimer(this, 0, 20);
    new BukkitRunnable() {

        @Override
        public void run() {
            for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                Knocker knocker = getKnocker(p);
                if (!knocker.isInGame())
                    return;
                World world = p.getWorld();
                List<Entity> entList = world.getEntities();
                for (Entity current : entList) if (current instanceof Item)
                    if (((Item) current).getItemStack().getType() == Material.LIGHT_WEIGHTED_PRESSURE_PLATE)
                        current.remove();
            }
        }
    }.runTaskTimer(this, 0, 5);
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    if (!getConfig().getBoolean("wipe-items.enabled"))
        return;
    scheduler.scheduleSyncRepeatingTask(this, () -> {
        Bukkit.broadcastMessage(Message.ITEM_CLEAR.toString());
        for (Player p : Bukkit.getServer().getOnlinePlayers()) {
            Knocker knocker = getKnocker(p);
            if (!knocker.isInGame())
                return;
            World world = p.getWorld();
            List<Entity> entList = world.getEntities();
            for (Entity current : entList) {
                if (!(current instanceof Item))
                    return;
                current.remove();
                p.playSound(p.getLocation(), Sounds.ITEM_REMOVED.toSound(), 1, 1);
            }
        }
    }, 10L, getConfig().getInt("wipe-items.period") * 20L);
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) World(org.bukkit.World) Arena(me.gameisntover.kbffa.arena.Arena) Item(org.bukkit.entity.Item) Knocker(me.gameisntover.kbffa.api.Knocker) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler)

Example 15 with Knocker

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

the class GameRules method onPlayerItemPickup.

@EventHandler
public void onPlayerItemPickup(EntityPickupItemEvent e) {
    if (!(e.getEntity() instanceof Player))
        return;
    Player player = (Player) e.getEntity();
    Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
    if (knocker.isInGame() || KnockbackFFA.getInstance().BungeeMode())
        e.setCancelled(true);
}
Also used : Player(org.bukkit.entity.Player) Knocker(me.gameisntover.kbffa.api.Knocker) EventHandler(org.bukkit.event.EventHandler)

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