SHARE
TWEET

Untitled

a guest Dec 14th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.charmpvp.hcf.listener.fixes;
  2.  
  3. import org.bukkit.ChatColor;
  4. import org.bukkit.Location;
  5. import org.bukkit.Material;
  6. import org.bukkit.block.BlockFace;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.EventPriority;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.event.player.PlayerTeleportEvent;
  12.  
  13. import com.charmpvp.hcf.HCF;
  14. import com.google.common.collect.ImmutableSet;
  15. import com.google.common.collect.Sets;
  16.  
  17. public class PearlGlitchListener implements Listener {
  18.  
  19.     private final ImmutableSet<Material> blockedPearlTypes = Sets.immutableEnumSet(Material.IRON_FENCE, Material.FENCE,
  20.             Material.NETHER_FENCE, Material.FENCE_GATE, Material.ACACIA_STAIRS, Material.BIRCH_WOOD_STAIRS,
  21.             Material.BRICK_STAIRS, Material.COBBLESTONE_STAIRS, Material.DARK_OAK_STAIRS, Material.JUNGLE_WOOD_STAIRS,
  22.             Material.NETHER_BRICK_STAIRS, Material.QUARTZ_STAIRS, Material.SANDSTONE_STAIRS, Material.SMOOTH_STAIRS,
  23.             Material.SPRUCE_WOOD_STAIRS, Material.WOOD_STAIRS, Material.STEP, Material.THIN_GLASS, Material.WOOD_STEP,
  24.             Material.FENCE_GATE, Material.TRAP_DOOR);
  25.  
  26.     private final HCF plugin;
  27.     private BlockFace[] faces;
  28.  
  29.     public PearlGlitchListener(HCF plugin) {
  30.         this.plugin = plugin;
  31.     }
  32.  
  33.  
  34.     @SuppressWarnings("deprecation")
  35.     @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
  36.     public void onPearlClip(PlayerTeleportEvent event) {
  37.         if (event.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL) {
  38.             Location to = event.getTo();
  39.             if (blockedPearlTypes.contains(to.getBlock().getType())) {
  40.                 Player player = event.getPlayer();
  41.                 player.sendMessage(ChatColor.RED + "Pearl glitching detected, used Enderpearl has been refunded.");
  42.                 plugin.getTimerManager().getEnderPearlTimer().refund(player);
  43.                 event.setCancelled(true);
  44.                 return;
  45.             }
  46.             if (to.getBlock().getType().equals(Material.STEP) || to.getBlock().getType().equals(Material.WOOD_STEP)) {
  47.                 to.setX(to.getBlockX() + 0.5D);
  48.                 to.setZ(to.getBlockZ() + 0.5D);
  49.                 to.setY(to.getBlockY() + 0.5D);
  50.                 event.setTo(to);
  51.                 return;
  52.             }
  53.             to.setX(to.getBlockX() + 0.5D);
  54.             to.setZ(to.getBlockZ() + 0.5D);
  55.             event.setTo(to);
  56.         }
  57.     }
  58.  
  59.     public boolean isGlitch(Location localLocation2) {
  60.         final int radius = 1;
  61.         BlockFace[] faces2;
  62.         for (int length2 = (faces2 = this.faces).length, l = 0; l < length2; ++l) {
  63.             final BlockFace BlockFace2 = faces2[l];
  64.             final Location locationAhead = localLocation2.getBlock().getRelative(BlockFace2, 0).getLocation();
  65.             for (int x = -radius; x <= radius; ++x) {
  66.                 for (int y = -radius; y <= radius; ++y) {
  67.                     for (int z = -radius; z <= radius; ++z) {
  68.                         final Location loc = locationAhead.getBlock().getRelative(x, y, z).getLocation();
  69.                         if (loc.getBlock().getType().equals(Material.FENCE) || loc.getBlock().getType().equals(Material.FENCE_GATE) || loc.getBlock().getType().equals(Material.IRON_FENCE) || loc.getBlock().getType().equals(Material.NETHER_FENCE)) {
  70.                             return true;
  71.                         }
  72.                     }
  73.                 }
  74.             }
  75.         }
  76.         return false;
  77.     }
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top