Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.byzarhq.hcfactions.handlers;
- import com.byzarhq.hcfactions.utilties.*;
- import com.byzarhq.hcfactions.*;
- import com.google.common.collect.*;
- import org.bukkit.plugin.*;
- import org.bukkit.event.block.*;
- import org.bukkit.inventory.*;
- import org.bukkit.block.*;
- import org.bukkit.entity.*;
- import org.bukkit.event.*;
- import org.bukkit.event.player.*;
- import com.byzarhq.hcfactions.utilties.chat.*;
- import org.bukkit.*;
- public class PearlGlitchHandler extends Handler implements Listener
- {
- private ImmutableSet<Material> blockedPearlTypes;
- private BlockFace[] faces;
- public PearlGlitchHandler(final HCFactions plugin) {
- super(plugin);
- this.faces = new BlockFace[] { BlockFace.SELF, BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
- this.blockedPearlTypes = (ImmutableSet<Material>)Sets.immutableEnumSet((Enum)Material.THIN_GLASS, (Enum[])new Material[] { Material.IRON_FENCE, Material.FENCE, Material.NETHER_FENCE, Material.FENCE_GATE, Material.ACACIA_STAIRS, Material.BIRCH_WOOD_STAIRS, Material.BRICK_STAIRS, Material.COBBLESTONE_STAIRS, Material.DARK_OAK_STAIRS, Material.JUNGLE_WOOD_STAIRS, Material.NETHER_BRICK_STAIRS, Material.QUARTZ_STAIRS, Material.SANDSTONE_STAIRS, Material.SMOOTH_STAIRS, Material.SPRUCE_WOOD_STAIRS, Material.WOOD_STAIRS });
- Bukkit.getPluginManager().registerEvents((Listener)this, (Plugin)plugin);
- }
- @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
- public void onPlayerInteract(final PlayerInteractEvent event) {
- final Action action = event.getAction();
- if (action == Action.RIGHT_CLICK_BLOCK && event.hasItem() && event.getItem().getType() == Material.ENDER_PEARL) {
- final Block block = event.getClickedBlock();
- if (block.getType().isSolid() && !(block.getState() instanceof InventoryHolder)) {
- event.setCancelled(true);
- final Player player = event.getPlayer();
- player.setItemInHand(event.getItem());
- }
- }
- }
- @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
- public void onPlayerTeleport(final PlayerTeleportEvent event) {
- if (event.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL) {
- final Location to = event.getTo();
- final Player player = event.getPlayer();
- if (this.blockedPearlTypes.contains((Object)to.getBlock().getType())) {
- player.sendMessage(Color.translate("&c&lInvalid Pearl!"));
- event.setCancelled(true);
- return;
- }
- if (this.isGlitch(to)) {
- player.sendMessage(Color.translate("&c&lInvalid Pearl!"));
- event.setCancelled(true);
- return;
- }
- if (to.getBlock().getType().equals((Object)Material.STEP) || to.getBlock().getType().equals((Object)Material.WOOD_STEP)) {
- to.setX(to.getBlockX() + 0.5);
- to.setZ(to.getBlockZ() + 0.5);
- to.setY(to.getBlockY() + 0.5);
- event.setTo(to);
- return;
- }
- final Block above = to.getBlock().getRelative(BlockFace.UP);
- final Material aboveType = above.getType();
- if ((this.blockedPearlTypes.contains((Object)aboveType) || aboveType.isSolid()) && to.subtract(0.0, 1.0, 0.0).getBlock().getType() == Material.AIR && to.subtract(0.0, 2.0, 0.0).getBlock().getType() == Material.AIR) {
- player.teleport(player.getLocation().add(0.0, player.getLocation().add(0.0, 1.0, 0.0).getBlockY() - player.getLocation().getY() + 0.05, 0.0));
- return;
- }
- to.setX(to.getBlockX() + 0.5);
- to.setZ(to.getBlockZ() + 0.5);
- event.setTo(to);
- }
- }
- public boolean isGlitch(final Location location) {
- final int radius = 1;
- BlockFace[] faces2;
- for (int i = (faces2 = this.faces).length, l = 0; l < i; ++l) {
- final BlockFace face = faces2[l];
- final Location locationAhead = location.getBlock().getRelative(face, 0).getLocation();
- for (int x = -radius; x <= radius; ++x) {
- for (int y = -radius; y <= radius; ++y) {
- for (int z = -radius; z <= radius; ++z) {
- final Location loc = locationAhead.getBlock().getRelative(x, y, z).getLocation();
- if (loc.getBlock().getType().equals((Object)Material.FENCE) || loc.getBlock().getType().equals((Object)Material.FENCE_GATE) || loc.getBlock().getType().equals((Object)Material.IRON_FENCE) || loc.getBlock().getType().equals((Object)Material.NETHER_FENCE)) {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement