Search in sources :

Example 36 with Location

use of org.bukkit.Location in project TotalFreedomMod by TotalFreedom.

the class RollbackManager method onPlayerInteract.

@EventHandler(ignoreCancelled = false)
public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    if (!event.hasItem() || event.getItem().getType() != Material.STICK || !plugin.al.isAdmin(player)) {
        return;
    }
    event.setCancelled(true);
    final Location location = DepreciationAggregator.getTargetBlock(player, null, 5).getLocation();
    final List<RollbackEntry> entries = plugin.rb.getEntriesAtLocation(location);
    if (entries.isEmpty()) {
        FUtil.playerMsg(player, "No block edits at that location.");
        return;
    }
    FUtil.playerMsg(player, "Block edits at (" + ChatColor.WHITE + "x" + location.getBlockX() + ", y" + location.getBlockY() + ", z" + location.getBlockZ() + ChatColor.BLUE + ")" + ChatColor.WHITE + ":", ChatColor.BLUE);
    for (RollbackEntry entry : entries) {
        FUtil.playerMsg(player, " - " + ChatColor.BLUE + entry.author + " " + entry.getType() + " " + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase()) + (entry.data == 0 ? "" : ":" + entry.data));
    }
}
Also used : Player(org.bukkit.entity.Player) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 37 with Location

use of org.bukkit.Location in project GameCore by Warvale.

the class GlobalEvent method onBlockBreak.

@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    if (event.getBlock().getType().equals(Material.IRON_ORE)) {
        event.getPlayer().giveExp(10);
        for (int i = 0; i < NumberUtils.random(3, 1); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.IRON_INGOT));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.IRON_NUGGET);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.forEach(Entity::remove);
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.IRON_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 5, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
    if (event.getBlock().getType().equals(Material.GOLD_ORE)) {
        event.getPlayer().giveExp(30);
        for (int i = 0; i < NumberUtils.random(2, 0); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.GOLD_INGOT));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.GOLD_NUGGET);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.stream().forEach(entity -> entity.remove());
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.GOLD_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 10, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
    if (event.getBlock().getType().equals(Material.DIAMOND_ORE)) {
        event.getPlayer().giveExp(50);
        for (int i = 0; i < NumberUtils.random(1, 0); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.DIAMOND));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.PRISMARINE_CRYSTALS);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.stream().forEach(entity -> entity.remove());
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.DIAMOND_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 25, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
    if (event.getBlock().getType().equals(Material.LAPIS_ORE)) {
        event.getPlayer().giveExp(50);
        for (int i = 0; i < NumberUtils.random(1, 0); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.LAPIS_BLOCK));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.EYE_OF_ENDER);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.stream().forEach(entity -> entity.remove());
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.LAPIS_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 15, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
}
Also used : Arrays(java.util.Arrays) Entity(org.bukkit.entity.Entity) Enchantment(org.bukkit.enchantments.Enchantment) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) NumberUtils(net.warvale.core.utils.NumberUtils) Sound(org.bukkit.Sound) Player(org.bukkit.entity.Player) PlayerPickupItemEvent(org.bukkit.event.player.PlayerPickupItemEvent) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) TeamManager(net.warvale.core.game.logic.TeamManager) EventHandler(org.bukkit.event.EventHandler) Vector(org.bukkit.util.Vector) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) List(java.util.List) ChatUtils(net.warvale.core.utils.chat.ChatUtils) Location(org.bukkit.Location) ChatColor(org.bukkit.ChatColor) Material(org.bukkit.Material) Listener(org.bukkit.event.Listener) Entity(org.bukkit.entity.Entity) ArrayList(java.util.ArrayList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 38 with Location

use of org.bukkit.Location in project GameCore by Warvale.

the class AbilityManager method onMove.

@EventHandler
public void onMove(PlayerMoveEvent e) {
    if (!freeze.contains(e.getPlayer()))
        return;
    if (!electroCooldown.contains(e.getPlayer()))
        return;
    Location from = e.getFrom();
    Location to = e.getTo();
    double x = Math.floor(from.getX());
    double z = Math.floor(from.getZ());
    if (Math.floor(to.getX()) != x || Math.floor(to.getZ()) != z) {
        x += .5;
        z += .5;
        e.getPlayer().teleport(new Location(from.getWorld(), x, from.getY(), z, from.getYaw(), from.getPitch()));
    }
}
Also used : Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 39 with Location

use of org.bukkit.Location in project Minigames by AddstarMC.

the class CTFFlag method spawnFlag.

public Location spawnFlag(Location location) {
    Location blockBelow = location.clone();
    Location newLocation = location.clone();
    blockBelow.setY(blockBelow.getBlockY() - 1);
    if (blockBelow.getBlock().getType() == Material.AIR) {
        while (blockBelow.getBlock().getType() == Material.AIR) {
            if (blockBelow.getY() > 1) {
                blockBelow.setY(blockBelow.getY() - 1);
            } else {
                return null;
            }
        }
    } else if (blockBelow.getBlock().getType() != Material.AIR) {
        while (blockBelow.getBlock().getType() != Material.AIR) {
            if (blockBelow.getY() < 255) {
                blockBelow.setY(blockBelow.getY() + 1);
            } else {
                return null;
            }
        }
        blockBelow.setY(blockBelow.getY() - 1);
    }
    if (blockBelow.getBlock().getType() == Material.FURNACE || blockBelow.getBlock().getType() == Material.DISPENSER || blockBelow.getBlock().getType() == Material.CHEST || blockBelow.getBlock().getType() == Material.BREWING_STAND || blockBelow.getBlock().getType() == Material.SIGN_POST || blockBelow.getBlock().getType() == Material.WALL_SIGN) {
        blockBelow.setY(blockBelow.getY() + 1);
    }
    newLocation = blockBelow.clone();
    newLocation.setY(newLocation.getY() + 1);
    newLocation.getBlock().setType(Material.SIGN_POST);
    Sign sign = (Sign) newLocation.getBlock().getState();
    sign.setData(data);
    originalBlock = blockBelow.getBlock().getState();
    blockBelow.getBlock().setType(Material.BEDROCK);
    if (newLocation != null) {
        atHome = false;
        for (int i = 0; i < 4; i++) {
            sign.setLine(i, signText[i]);
        }
        sign.update();
        currentLocation = newLocation.clone();
    }
    return newLocation;
}
Also used : Sign(org.bukkit.block.Sign) Location(org.bukkit.Location)

Example 40 with Location

use of org.bukkit.Location in project Minigames by AddstarMC.

the class RewardSign method signUse.

@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
    Location loc = sign.getLocation();
    if (!MinigameUtils.isMinigameTool(player.getPlayer().getInventory().getItemInMainHand())) {
        String label = sign.getLine(2).toLowerCase();
        if (player.isInMinigame()) {
            if (!player.hasTempClaimedReward(label)) {
                if (mdata.hasRewardSign(loc)) {
                    Rewards rew = mdata.getRewardSign(loc);
                    for (RewardType r : rew.getReward()) {
                        r.giveReward(player);
                    }
                }
                player.addTempClaimedReward(label);
            }
        } else {
            if (!player.hasClaimedReward(label)) {
                if (mdata.hasRewardSign(loc)) {
                    Rewards rew = mdata.getRewardSign(loc);
                    for (RewardType r : rew.getReward()) {
                        r.giveReward(player);
                    }
                    player.updateInventory();
                }
                player.addClaimedReward(label);
            }
        }
    } else if (player.getPlayer().hasPermission("minigame.tool")) {
        Rewards rew = null;
        if (!mdata.hasRewardSign(loc)) {
            mdata.addRewardSign(loc);
        }
        rew = mdata.getRewardSign(loc);
        Menu rewardMenu = new Menu(5, getName(), player);
        rewardMenu.addItem(new MenuItemRewardGroupAdd("Add Group", Material.ITEM_FRAME, rew), 42);
        rewardMenu.addItem(new MenuItemRewardAdd("Add Item", Material.ITEM_FRAME, rew), 43);
        final MenuItemCustom mic = new MenuItemCustom("Save Rewards", Material.REDSTONE_TORCH_ON);
        final Location floc = loc;
        mic.setClick(new InteractionInterface() {

            @Override
            public Object interact(Object object) {
                mdata.saveRewardSign(MinigameUtils.createLocationID(floc), true);
                mic.getContainer().getViewer().sendMessage("Saved rewards for this sign.", null);
                mic.getContainer().getViewer().getPlayer().closeInventory();
                return null;
            }
        });
        rewardMenu.addItem(mic, 44);
        List<String> list = new ArrayList<String>();
        for (RewardRarity r : RewardRarity.values()) {
            list.add(r.toString());
        }
        List<MenuItem> mi = new ArrayList<MenuItem>();
        for (RewardType item : rew.getRewards()) {
            mi.add(item.getMenuItem());
        }
        List<String> des = new ArrayList<String>();
        des.add("Double Click to edit");
        for (RewardGroup group : rew.getGroups()) {
            MenuItemRewardGroup rwg = new MenuItemRewardGroup(group.getName() + " Group", des, Material.CHEST, group, rew);
            mi.add(rwg);
        }
        rewardMenu.addItems(mi);
        rewardMenu.displayMenu(player);
    }
    return true;
}
Also used : MenuItemRewardAdd(au.com.mineauz.minigames.menu.MenuItemRewardAdd) MenuItem(au.com.mineauz.minigames.menu.MenuItem) MenuItemCustom(au.com.mineauz.minigames.menu.MenuItemCustom) InteractionInterface(au.com.mineauz.minigames.menu.InteractionInterface) MenuItemRewardGroup(au.com.mineauz.minigames.menu.MenuItemRewardGroup) RewardGroup(au.com.mineauz.minigames.minigame.reward.RewardGroup) RewardType(au.com.mineauz.minigames.minigame.reward.RewardType) MenuItemRewardGroupAdd(au.com.mineauz.minigames.menu.MenuItemRewardGroupAdd) Rewards(au.com.mineauz.minigames.minigame.reward.Rewards) ArrayList(java.util.ArrayList) List(java.util.List) Menu(au.com.mineauz.minigames.menu.Menu) RewardRarity(au.com.mineauz.minigames.minigame.reward.RewardRarity) MenuItemRewardGroup(au.com.mineauz.minigames.menu.MenuItemRewardGroup) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)470 Player (org.bukkit.entity.Player)120 World (org.bukkit.World)63 EventHandler (org.bukkit.event.EventHandler)54 Vector (org.bukkit.util.Vector)45 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)36 Block (org.bukkit.block.Block)31 Entity (org.bukkit.entity.Entity)28 UUID (java.util.UUID)27 ItemStack (org.bukkit.inventory.ItemStack)22 LivingEntity (org.bukkit.entity.LivingEntity)20 PotionEffect (org.bukkit.potion.PotionEffect)17 User (com.earth2me.essentials.User)16 List (java.util.List)16 IOException (java.io.IOException)15 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)14 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)14 Island (com.wasteofplastic.acidisland.Island)12