Search in sources :

Example 1 with Cuboid

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

the class GameRules method onPlayerMove.

@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
    Player player = e.getPlayer();
    List<String> voids = KnockbackFFA.getInstance().getZoneConfiguration().getConfig.getStringList("registered-voids");
    for (String vd : voids) {
        if (KnockbackFFA.getInstance().getZoneConfiguration().getConfig.getLocation("voids." + vd + ".pos1") == null)
            return;
        Location pos1 = KnockbackFFA.getInstance().getZoneConfiguration().getConfig.getLocation("voids." + vd + ".pos1");
        Location pos2 = KnockbackFFA.getInstance().getZoneConfiguration().getConfig.getLocation("voids." + vd + ".pos2");
        Cuboid bb = new Cuboid(pos1, pos2);
        if (!bb.contains(player.getLocation()))
            return;
        Integer damage = KnockbackFFA.getInstance().getZoneConfiguration().getConfig.getInt("voids." + vd + ".damage");
        if (damage == null)
            return;
        new BukkitRunnable() {

            @Override
            public void run() {
                if (player.isDead() || !bb.contains(player.getLocation()))
                    cancel();
                else {
                    player.damage(damage);
                    player.setLastDamageCause(new EntityDamageEvent(player, EntityDamageEvent.DamageCause.VOID, damage));
                }
            }
        }.runTaskTimer(KnockbackFFA.getInstance(), 0, 20);
    }
}
Also used : Player(org.bukkit.entity.Player) Cuboid(me.gameisntover.kbffa.arena.regions.Cuboid) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Location(org.bukkit.Location) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Cuboid

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

the class GameRules method onPlayerDamages.

@EventHandler
public void onPlayerDamages(EntityDamageEvent e) {
    if (!(e.getEntity() instanceof Player))
        return;
    Player player = (Player) e.getEntity();
    for (String sz : KnockbackFFA.getInstance().getZoneConfiguration().getConfig.getStringList("registered-safezones")) {
        if (KnockbackFFA.getInstance().getZoneConfiguration().getConfig.getString("Safezones." + sz + ".world") != null) {
            Location loc1 = KnockbackFFA.getInstance().getZoneConfiguration().getConfig.getLocation("Safezones." + sz + ".pos1");
            Location loc2 = KnockbackFFA.getInstance().getZoneConfiguration().getConfig.getLocation("Safezones." + sz + ".pos2");
            Cuboid s1box = new Cuboid(loc1, loc2);
            Location location = player.getLocation();
            if (s1box.contains(location)) {
                e.setCancelled(true);
                break;
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Cuboid(me.gameisntover.kbffa.arena.regions.Cuboid) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Cuboid

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

the class EditArenaCommand method perform.

@Override
public void perform(Knocker knocker, String[] args) {
    Player p = knocker.getPlayer();
    if (args.length != 1) {
        p.sendMessage(ChatColor.RED + "Command Arguements missing or is invalid /editarena arenaname");
        return;
    }
    List<String> arenaList = Arrays.asList(KnockbackFFA.getInstance().getArenaManager().getFolder().list());
    if (!arenaList.contains(args[0] + ".yml")) {
        p.sendMessage(ChatColor.RED + "That arena name does not exist!");
        return;
    }
    p.sendMessage(ChatColor.GREEN + "You are now editing " + args[0]);
    Arena arena = KnockbackFFA.getInstance().getArenaManager().load(args[0]);
    GUI arenaGUI = new GUI("Arena Editor", (short) 5);
    List<String> blockbreaklore = new ArrayList<>();
    blockbreaklore.add(ChatColor.GRAY + "Toggle whether or not players can break blocks");
    blockbreaklore.add(ChatColor.GREEN + "Currently Block Breaking is " + arena.getConfig().getBoolean("block-break"));
    Button blockBreak = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.DIAMOND_PICKAXE, 1, ChatColor.GRAY + "Block Break", blockbreaklore).create(ItemFlag.HIDE_ATTRIBUTES), e -> {
        arena.getConfig().set("block-break", !arena.getConfig().getBoolean("block-break"));
        arena.save();
        ItemMeta im = e.getCurrentItem().getItemMeta();
        blockbreaklore.clear();
        blockbreaklore.add(ChatColor.GRAY + "Toggle whether or not players can break blocks");
        blockbreaklore.add(ChatColor.GREEN + "Currently Block Breaking is " + arena.getConfig().getBoolean("block-break"));
        im.setLore(blockbreaklore);
        e.getCurrentItem().setItemMeta(im);
    });
    List<String> itemDropLore = new ArrayList<>();
    itemDropLore.add(ChatColor.GRAY + "Toggle whether or not players can drop items");
    itemDropLore.add(ChatColor.GREEN + "Currently Item Dropping is " + arena.getConfig().getBoolean("item-drop"));
    Button itemDrop = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.DIAMOND, 1, ChatColor.GRAY + "Item Drop", itemDropLore).create(), e -> {
        arena.getConfig().set("item-drop", !arena.getConfig().getBoolean("item-drop"));
        arena.save();
        ItemMeta im = e.getCurrentItem().getItemMeta();
        itemDropLore.clear();
        itemDropLore.add(ChatColor.GRAY + "Toggle whether or not players can drop items");
        itemDropLore.add(ChatColor.GREEN + "Currently Item Dropping is " + arena.getConfig().getBoolean("item-drop"));
        im.setLore(itemDropLore);
        e.getCurrentItem().setItemMeta(im);
    });
    Button setSpawn = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.NETHER_STAR, 1, ChatColor.GRAY + "Set Spawn", Arrays.asList("sets the spawn point of players")).create(), e -> {
        Player player = (Player) e.getWhoClicked();
        arena.getConfig().set("arena.spawn", player.getLocation());
        arena.save();
        player.sendMessage(ChatColor.GREEN + "Arena Spawn Location Set!");
    });
    List<String> autoResetLore = new ArrayList<>();
    autoResetLore.add(ChatColor.GRAY + "Toggle whether or not the arena will reset blocks placed or broke automatically");
    autoResetLore.add(ChatColor.GREEN + "Currently Auto Reset is " + arena.getConfig().getBoolean("auto-reset"));
    Button autoReset = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.DISPENSER, 1, ChatColor.GRAY + "Auto Reset", autoResetLore).create(), e -> {
        arena.getConfig().set("auto-reset", !arena.getConfig().getBoolean("auto-reset"));
        arena.save();
        p.sendMessage("Auto Reset is now set to" + arena.getConfig().getBoolean("auto-reset"));
        if (arena.getConfig().getString("blocks") != null)
            return;
        Location loc1 = arena.getConfig().getLocation("arena.pos1");
        Location loc2 = arena.getConfig().getLocation("arena.pos2");
        List<String> blocks = new ArrayList<>();
        Cuboid region = new Cuboid(loc1, loc2);
        for (Block block : region.getBlocks()) {
            blocks.add(block.getType().name());
        }
        arena.getConfig().set("blocks", blocks);
        arena.save();
        autoResetLore.clear();
        autoResetLore.add(ChatColor.GRAY + "Toggle whether or not the arena will reset blocks placed or broke automatically");
        autoResetLore.add(ChatColor.GREEN + "Currently Auto Reset is " + arena.getConfig().getBoolean("auto-reset"));
        ItemStack item = e.getCurrentItem();
        ItemMeta meta = e.getCurrentItem().getItemMeta();
        meta.setLore(autoResetLore);
        item.setItemMeta(meta);
    });
    Button setpos = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.REDSTONE_BLOCK, 1, ChatColor.GRAY + "Set Position", Arrays.asList(ChatColor.GRAY + "set the new arena positions from here!")).create(), e -> {
        if (WandListener.pos1m.get(e.getWhoClicked()) != null && WandListener.pos2m.get(e.getWhoClicked()) != null) {
            Location loc1 = WandListener.pos1m.get(e.getWhoClicked());
            Location loc2 = WandListener.pos2m.get(e.getWhoClicked());
            BoundingBox box = new BoundingBox(loc1.getX(), loc1.getY(), loc1.getZ(), loc2.getX(), loc2.getY(), loc2.getZ());
            e.getWhoClicked().getWorld().getWorldBorder().setCenter(box.getCenterX(), box.getCenterZ());
            e.getWhoClicked().getWorld().getWorldBorder().setSize(box.getMaxX() - box.getMinX());
            arena.getConfig().set("arena.pos1", loc1);
            arena.getConfig().set("arena.pos2", loc2);
            String world = e.getWhoClicked().getWorld().getName();
            arena.getConfig().set("arena.spawn.world", world);
            List<String> blocks = new ArrayList<>();
            Cuboid region = new Cuboid(loc1, loc2);
            for (Block block : region.getBlocks()) {
                blocks.add(block.getType().name());
            }
            arena.getConfig().set("blocks", blocks);
            arena.save();
            e.getWhoClicked().sendMessage(ChatColor.GREEN + "Arena Positions Set!");
        }
    });
    List<String> worldBorderlore = new ArrayList<>();
    worldBorderlore.add(ChatColor.GRAY + "Toggle whether or not the world border is enabled.");
    worldBorderlore.add(ChatColor.GREEN + "Currently the world border is " + arena.getConfig().getBoolean("world-border"));
    Button worldBorder = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.BARRIER, 1, ChatColor.GRAY + "World Border", worldBorderlore).create(), e -> {
        arena.getConfig().set("world-border", !arena.getConfig().getBoolean("world-border"));
        arena.save();
        Location spawnLoc = arena.getConfig().getLocation("arena.spawn");
        boolean worldBorderBool = arena.getConfig().getBoolean("world-border");
        if (worldBorderBool) {
            Location loc1 = arena.getConfig().getLocation("arena.pos1");
            Location loc2 = arena.getConfig().getLocation("arena.pos2");
            BoundingBox box = new BoundingBox(loc1.getX(), loc1.getY(), loc1.getZ(), loc2.getX(), loc2.getY(), loc2.getZ());
            spawnLoc.getWorld().getWorldBorder().setCenter(box.getCenterX(), box.getCenterZ());
            spawnLoc.getWorld().getWorldBorder().setSize(box.getMaxX() - box.getMinX());
        } else {
            WorldBorder worldBorderr = spawnLoc.getWorld().getWorldBorder();
            worldBorderr.reset();
        }
        worldBorderlore.clear();
        ItemMeta im = e.getCurrentItem().getItemMeta();
        worldBorderlore.add(ChatColor.GRAY + "Toggle whether or not the world border is enabled.");
        worldBorderlore.add(ChatColor.GREEN + "Currently the world border is " + arena.getConfig().getBoolean("world-border"));
        im.setLore(worldBorderlore);
        e.getCurrentItem().setItemMeta(im);
    });
    arenaGUI.add(blockBreak, 10);
    arenaGUI.add(itemDrop, 11);
    arenaGUI.add(setSpawn, 12);
    arenaGUI.add(setpos, 13);
    arenaGUI.add(worldBorder, 14);
    arenaGUI.add(autoReset, 15);
    knocker.openGUI(arenaGUI);
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Cuboid(me.gameisntover.kbffa.arena.regions.Cuboid) Arena(me.gameisntover.kbffa.arena.Arena) ItemBuilder(me.gameisntover.kbffa.util.ItemBuilder) Button(me.gameisntover.kbffa.gui.Button) BoundingBox(org.bukkit.util.BoundingBox) WorldBorder(org.bukkit.WorldBorder) Block(org.bukkit.block.Block) GUI(me.gameisntover.kbffa.gui.GUI) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Location(org.bukkit.Location)

Aggregations

Cuboid (me.gameisntover.kbffa.arena.regions.Cuboid)3 Location (org.bukkit.Location)3 Player (org.bukkit.entity.Player)3 EventHandler (org.bukkit.event.EventHandler)2 ArrayList (java.util.ArrayList)1 Arena (me.gameisntover.kbffa.arena.Arena)1 Button (me.gameisntover.kbffa.gui.Button)1 GUI (me.gameisntover.kbffa.gui.GUI)1 ItemBuilder (me.gameisntover.kbffa.util.ItemBuilder)1 WorldBorder (org.bukkit.WorldBorder)1 Block (org.bukkit.block.Block)1 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)1 ItemStack (org.bukkit.inventory.ItemStack)1 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1 BoundingBox (org.bukkit.util.BoundingBox)1