Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. package com.byzarhq.hcfactions.handlers;
  2.  
  3. import com.byzarhq.hcfactions.utilties.*;
  4. import com.byzarhq.hcfactions.*;
  5. import com.google.common.collect.*;
  6. import org.bukkit.plugin.*;
  7. import org.bukkit.event.block.*;
  8. import org.bukkit.inventory.*;
  9. import org.bukkit.block.*;
  10. import org.bukkit.entity.*;
  11. import org.bukkit.event.*;
  12. import org.bukkit.event.player.*;
  13. import com.byzarhq.hcfactions.utilties.chat.*;
  14. import org.bukkit.*;
  15.  
  16. public class PearlGlitchHandler extends Handler implements Listener
  17. {
  18. private ImmutableSet<Material> blockedPearlTypes;
  19. private BlockFace[] faces;
  20.  
  21. public PearlGlitchHandler(final HCFactions plugin) {
  22. super(plugin);
  23. this.faces = new BlockFace[] { BlockFace.SELF, BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
  24. 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 });
  25. Bukkit.getPluginManager().registerEvents((Listener)this, (Plugin)plugin);
  26. }
  27.  
  28. @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
  29. public void onPlayerInteract(final PlayerInteractEvent event) {
  30. final Action action = event.getAction();
  31. if (action == Action.RIGHT_CLICK_BLOCK && event.hasItem() && event.getItem().getType() == Material.ENDER_PEARL) {
  32. final Block block = event.getClickedBlock();
  33. if (block.getType().isSolid() && !(block.getState() instanceof InventoryHolder)) {
  34. event.setCancelled(true);
  35. final Player player = event.getPlayer();
  36. player.setItemInHand(event.getItem());
  37. }
  38. }
  39. }
  40.  
  41. @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
  42. public void onPlayerTeleport(final PlayerTeleportEvent event) {
  43. if (event.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL) {
  44. final Location to = event.getTo();
  45. final Player player = event.getPlayer();
  46. if (this.blockedPearlTypes.contains((Object)to.getBlock().getType())) {
  47. player.sendMessage(Color.translate("&c&lInvalid Pearl!"));
  48. event.setCancelled(true);
  49. return;
  50. }
  51. if (this.isGlitch(to)) {
  52. player.sendMessage(Color.translate("&c&lInvalid Pearl!"));
  53. event.setCancelled(true);
  54. return;
  55. }
  56. if (to.getBlock().getType().equals((Object)Material.STEP) || to.getBlock().getType().equals((Object)Material.WOOD_STEP)) {
  57. to.setX(to.getBlockX() + 0.5);
  58. to.setZ(to.getBlockZ() + 0.5);
  59. to.setY(to.getBlockY() + 0.5);
  60. event.setTo(to);
  61. return;
  62. }
  63. final Block above = to.getBlock().getRelative(BlockFace.UP);
  64. final Material aboveType = above.getType();
  65. 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) {
  66. player.teleport(player.getLocation().add(0.0, player.getLocation().add(0.0, 1.0, 0.0).getBlockY() - player.getLocation().getY() + 0.05, 0.0));
  67. return;
  68. }
  69. to.setX(to.getBlockX() + 0.5);
  70. to.setZ(to.getBlockZ() + 0.5);
  71. event.setTo(to);
  72. }
  73. }
  74.  
  75. public boolean isGlitch(final Location location) {
  76. final int radius = 1;
  77. BlockFace[] faces2;
  78. for (int i = (faces2 = this.faces).length, l = 0; l < i; ++l) {
  79. final BlockFace face = faces2[l];
  80. final Location locationAhead = location.getBlock().getRelative(face, 0).getLocation();
  81. for (int x = -radius; x <= radius; ++x) {
  82. for (int y = -radius; y <= radius; ++y) {
  83. for (int z = -radius; z <= radius; ++z) {
  84. final Location loc = locationAhead.getBlock().getRelative(x, y, z).getLocation();
  85. 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)) {
  86. return true;
  87. }
  88. }
  89. }
  90. }
  91. }
  92. return false;
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement