Search in sources :

Example 36 with EventHandler

use of org.bukkit.event.EventHandler 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 EventHandler

use of org.bukkit.event.EventHandler in project GameCore by Warvale.

the class Preferences method onPlayerInteract.

@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Action a = event.getAction();
    ItemStack is = event.getItem();
    if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
        return;
    if (is.getType() == Material.REDSTONE_COMPARATOR)
        tsGUI(event.getPlayer());
    if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getPlayer().getName())) {
        event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
    }
}
Also used : Action(org.bukkit.event.block.Action) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 38 with EventHandler

use of org.bukkit.event.EventHandler in project GameCore by Warvale.

the class TeamSelect method onMove.

@EventHandler(priority = EventPriority.HIGHEST)
public void onMove(InventoryClickEvent event) {
    Player player = (Player) event.getWhoClicked();
    if (!event.getInventory().equals(inv)) {
        if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getWhoClicked().getName())) {
            event.setCancelled(true);
            return;
        }
    }
    switch(event.getSlot()) {
        case // Join red
        3:
            if (event.getInventory().equals(inv)) {
                Main.getTeams().getRedTeam().addEntry(event.getWhoClicked().getName());
                event.getWhoClicked().sendMessage(ChatColor.GRAY + "You joined team " + ChatColor.RED + "red");
                for (PotionEffect effect : event.getWhoClicked().getActivePotionEffects()) event.getWhoClicked().removePotionEffect(effect.getType());
                player.playSound(player.getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
                if (GameStart.initActive) {
                    player.sendMessage(org.bukkit.ChatColor.RED.toString() + org.bukkit.ChatColor.BOLD + "/vote #" + org.bukkit.ChatColor.BLUE.toString() + org.bukkit.ChatColor.BOLD + " to vote for a map!" + org.bukkit.ChatColor.DARK_BLUE + "\n1: Redwood Forest" + "\n2: Volcano Island" + "\n3: Pagoda Everglade" + "\n4: Extraterrestrial");
                }
                if (Main.getTeams().getRedTeam().getSize() >= 1 && Main.getTeams().getBlueTeam().getSize() >= 1 && !GameStart.initActive) {
                    GameStart.startCountdown();
                }
                event.setCancelled(true);
                player.closeInventory();
            }
            break;
        case // Close menu
        4:
            if (event.getInventory().equals(inv)) {
                event.setCancelled(true);
                player.playSound(player.getLocation(), Sound.BLOCK_ENDERCHEST_CLOSE, 1, 1);
                player.closeInventory();
            }
            break;
        case // Join blue
        5:
            if (event.getInventory().equals(inv)) {
                Main.getTeams().getBlueTeam().addEntry(event.getWhoClicked().getName());
                event.getWhoClicked().sendMessage(ChatColor.GRAY + "You joined team " + ChatColor.DARK_AQUA + "blue");
                for (PotionEffect effect : event.getWhoClicked().getActivePotionEffects()) event.getWhoClicked().removePotionEffect(effect.getType());
                player.playSound(player.getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
                if (GameStart.initActive) {
                    player.sendMessage(org.bukkit.ChatColor.RED.toString() + org.bukkit.ChatColor.BOLD + "/vote #" + org.bukkit.ChatColor.BLUE.toString() + org.bukkit.ChatColor.BOLD + " to vote for a map!" + org.bukkit.ChatColor.DARK_BLUE + "\n1: Redwood Forest" + "\n2: Volcano Island" + "\n3: Pagoda Everglade" + "\n4: Extraterrestrial");
                }
                if (Main.getTeams().getRedTeam().getSize() >= 1 && Main.getTeams().getBlueTeam().getSize() >= 1 && !GameStart.initActive) {
                    GameStart.startCountdown();
                }
                event.setCancelled(true);
                player.closeInventory();
            }
            break;
        default:
            if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getWhoClicked().getName())) {
                event.setCancelled(true);
                break;
            }
    }
}
Also used : Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) EventHandler(org.bukkit.event.EventHandler)

Example 39 with EventHandler

use of org.bukkit.event.EventHandler in project GameCore by Warvale.

the class TeamSelect method onPlayerInteract.

@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Action a = event.getAction();
    ItemStack is = event.getItem();
    if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
        return;
    if (is.getType() == Material.ENCHANTED_BOOK)
        tsGUI(event.getPlayer());
    if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getPlayer().getName())) {
        event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
    }
}
Also used : Action(org.bukkit.event.block.Action) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 40 with EventHandler

use of org.bukkit.event.EventHandler 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)

Aggregations

EventHandler (org.bukkit.event.EventHandler)532 Player (org.bukkit.entity.Player)185 Entity (org.bukkit.entity.Entity)70 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)67 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)62 Block (org.bukkit.block.Block)62 ItemStack (org.bukkit.inventory.ItemStack)55 Location (org.bukkit.Location)54 Island (com.wasteofplastic.acidisland.Island)42 Element (net.aufdemrand.denizencore.objects.Element)38 LivingEntity (org.bukkit.entity.LivingEntity)37 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)31 Minigame (au.com.mineauz.minigames.minigame.Minigame)29 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)29 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)28 Projectile (org.bukkit.entity.Projectile)26 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)23 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)22 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)18 ArrayList (java.util.ArrayList)18