/* * Copyright (c) 2018 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ package eu.univento.teamvento.listener; import eu.univento.core.api.events.MoveEventFilter; import eu.univento.core.api.player.CustomPlayer; import eu.univento.teamvento.TeamVento; import eu.univento.teamvento.plot.Plot; import eu.univento.teamvento.plot.PlotManager; import eu.univento.teamvento.plot.Time; import eu.univento.teamvento.plot.Weather; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.WeatherType; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.*; import org.bukkit.event.entity.*; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.*; import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; import java.util.HashMap; import java.util.Random; import java.util.Set; import java.util.UUID; /** * @author joethei * @version 1.0 */ public class Events implements Listener { public static int redstone = 0; private Random random = new Random(); private final HashMap lightningTasks = new HashMap<>(); @EventHandler public void onWeatherChange(WeatherChangeEvent e) { e.setCancelled(true); } @EventHandler public void onEntityExplode(EntityExplodeEvent e) { e.setCancelled(true); } @EventHandler public void onBlockBreak(BlockBreakEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if (!PlotManager.isAllowedToBuild(p, e.getBlock().getLocation())) e.setCancelled(true); } @EventHandler public void onBlockPlace(BlockPlaceEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if (!PlotManager.isAllowedToBuild(p, e.getBlock().getLocation())) e.setCancelled(true); } @EventHandler public void onHangingPlace(HangingPlaceEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if (!PlotManager.isAllowedToBuild(p, e.getEntity().getLocation())) e.setCancelled(true); } @EventHandler public void onHangingBreakByEntity(HangingBreakByEntityEvent e) { if (e.getRemover() instanceof Projectile) { if (((Projectile) e.getRemover()).getShooter() instanceof Player) { CustomPlayer p = CustomPlayer.getPlayer((Player) ((Projectile) e.getRemover()).getShooter()); if (!PlotManager.isAllowedToBuild(p, e.getEntity().getLocation())) e.setCancelled(true); } else { e.setCancelled(true); } } if (e.getRemover() instanceof Player) { CustomPlayer p = CustomPlayer.getPlayer((Player) e.getRemover()); if (!PlotManager.isAllowedToBuild(p, e.getEntity().getLocation())) e.setCancelled(true); } else { e.setCancelled(true); } } @EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent e) { if (e.getDamager() instanceof Player) { CustomPlayer p = CustomPlayer.getPlayer((Player) e.getDamager()); if (!PlotManager.isAllowedToBuild(p, e.getEntity().getLocation())) e.setCancelled(true); } if (e.getDamager() instanceof Projectile) { if (((Projectile) e.getDamager()).getShooter() instanceof Player) { CustomPlayer p = CustomPlayer.getPlayer((Player) ((Projectile) e.getDamager()).getShooter()); if (!PlotManager.isAllowedToBuild(p, e.getEntity().getLocation())) e.setCancelled(true); } else { e.setCancelled(true); } } } @EventHandler public void onBurn(BlockBurnEvent e) { e.setCancelled(true); } @EventHandler public void onBlockIgnite(BlockIgniteEvent e) { if (e.getCause() != BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && e.getCause() != BlockIgniteEvent.IgniteCause.FIREBALL) { e.setCancelled(true); return; } CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if (!PlotManager.isAllowedToBuild(p, e.getBlock().getLocation())) e.setCancelled(true); } @EventHandler public void onLeaveDecay(LeavesDecayEvent e) { e.setCancelled(true); } @EventHandler public void onBlockRedstone(BlockRedstoneEvent e) { if (e.getBlock().getWorld().getName().equalsIgnoreCase("world")) return; redstone++; if (redstone > 100) { e.getBlock().setType(Material.SIGN_POST); Sign sign = (Sign) e.getBlock().getState(); sign.setLine(0, "Redstone"); sign.setLine(1, "Clocks"); sign.setLine(2, "sind"); sign.setLine(3, "verboten"); sign.update(); redstone = 0; } } @EventHandler public void onCreatureSpawn(CreatureSpawnEvent e) { //if(e.getSpawnReason() != CreatureSpawnEvent.SpawnReason.CUSTOM) e.setCancelled(true); //if(e.getSpawnReason() != CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) e.setCancelled(true); e.getEntity().setAI(false); e.getEntity().setSilent(true); if (e.getEntity().getWorld().getName().equalsIgnoreCase("world")) return; Plot plot = PlotManager.getPlotByLocation(e.getEntity().getLocation()); assert plot != null; if (e.getEntity().getType() != EntityType.ITEM_FRAME && e.getEntity().getType() != EntityType.ARMOR_STAND && e.getEntity().getType() != EntityType.PAINTING) { e.setCancelled(true); } } @EventHandler public void onEntityDeath(EntityDeathEvent e) { e.getDrops().clear(); e.setDroppedExp(0); } @EventHandler public void onBlockFromTo(BlockFromToEvent e) { Material type = e.getBlock().getType(); if (type == Material.WATER || type == Material.STATIONARY_WATER || type == Material.LAVA || type == Material.STATIONARY_LAVA) e.setCancelled(true); } @EventHandler public void onPistonExtend(BlockPistonExtendEvent e) { if (e.getBlock().getWorld().getName().equalsIgnoreCase("world")) return; e.setCancelled(true); } @EventHandler public void onPistonRetract(BlockPistonRetractEvent e) { if (e.getBlock().getWorld().getName().equalsIgnoreCase("world")) return; e.setCancelled(true); } @EventHandler public void onInteract(PlayerInteractEvent e) { if (e.getAction() == Action.PHYSICAL && e.getClickedBlock().getType() == Material.SOIL) e.setCancelled(true); CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if (e.getAction() == Action.LEFT_CLICK_BLOCK) { Block block = e.getClickedBlock().getRelative(BlockFace.UP); if (!e.getPlayer().getWorld().getName().equalsIgnoreCase("plots")) return; if (block.getType() == Material.FIRE) { if (!PlotManager.isAllowedToBuild(p, e.getClickedBlock().getLocation())) e.setCancelled(true); } } if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (!PlotManager.isAllowedToBuild(p, e.getClickedBlock().getLocation())) e.setCancelled(true); } } @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if (e.getRightClicked().getType() == EntityType.ITEM_FRAME) { if (!PlotManager.isAllowedToBuild(p, e.getRightClicked().getLocation())) e.setCancelled(true); } } @EventHandler public void onArmorStandManipulate(PlayerArmorStandManipulateEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if (!PlotManager.isAllowedToBuild(p, e.getRightClicked().getLocation())) e.setCancelled(true); } @EventHandler public void onDrop(PlayerDropItemEvent e) { e.setCancelled(true); } @EventHandler public void onPickup(PlayerPickupItemEvent e) { e.setCancelled(true); } @EventHandler public void onArrowPickup(PlayerPickupArrowEvent e) { e.setCancelled(true); } @EventHandler public void onInventoryClick(InventoryClickEvent e) { if (e.getClickedInventory() instanceof PlayerInventory) { if (e.getSlot() == 8 || e.getHotbarButton() == 8) { e.setCancelled(true); } } } @EventHandler public void onSwapHands(PlayerSwapHandItemsEvent e) { if (e.getPlayer().getInventory().getHeldItemSlot() == 8) { e.setCancelled(true); } } @EventHandler public void onConsume(PlayerItemConsumeEvent e) { e.setCancelled(true); } @EventHandler public void onBucketEmpty(PlayerBucketEmptyEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if (!PlotManager.isAllowedToBuild(p, e.getBlockClicked().getLocation())) e.setCancelled(true); } @EventHandler public void onBucketFill(PlayerBucketFillEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if (!PlotManager.isAllowedToBuild(p, e.getBlockClicked().getLocation())) e.setCancelled(true); } @EventHandler public void onBlockMove(MoveEventFilter.PlayerBlockMoveEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); //plot enter if (!PlotManager.isPlot(e.getFrom()) && PlotManager.isPlot(e.getTo())) { Plot plot = PlotManager.getPlotByLocation(e.getTo()); assert plot != null; p.setPlayerTime(plot.getTime().getValue(), false); p.setPlayerWeather(plot.getWeatherType()); if (!plot.isOwner(p) && !plot.getOwner().equals(UUID.fromString("c35f6ece-c430-4fc0-b61e-18b55be19ee3"))) p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 999999, 2)); if (plot.getWeather() == Weather.THUNDER) { BukkitTask task = Bukkit.getScheduler().runTaskTimerAsynchronously(TeamVento.getInstance(), () -> { Random random = new Random(); int r = random.nextInt(100); if (r < 30) { p.strikeLightning(plot.getArea().getRandomLocation()); } }, 2L, 50L); lightningTasks.put(p, task); } } //plot leave if (PlotManager.isPlot(e.getFrom()) && !PlotManager.isPlot(e.getTo())) { p.setPlayerTime(Time.DAY.getValue(), false); p.setPlayerWeather(WeatherType.CLEAR); p.clearPotionEffects(); if (lightningTasks.containsKey(p)) lightningTasks.get(p).cancel(); lightningTasks.remove(p); } } @EventHandler public void onTeleport(PlayerTeleportEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); //plot enter if (!PlotManager.isPlot(e.getFrom()) && PlotManager.isPlot(e.getTo())) { Plot plot = PlotManager.getPlotByLocation(e.getTo()); assert plot != null; p.setPlayerTime(plot.getTime().getValue(), false); p.setPlayerWeather(plot.getWeatherType()); if (!plot.isOwner(p) && !plot.getOwner().equals(UUID.fromString("c35f6ece-c430-4fc0-b61e-18b55be19ee3"))) p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 999999, 2)); if (plot.getWeather() == Weather.THUNDER) { BukkitTask task = Bukkit.getScheduler().runTaskTimerAsynchronously(TeamVento.getInstance(), () -> { Random random = new Random(); int r = random.nextInt(100); if (r < 30) { p.strikeLightning(plot.getArea().getRandomLocation()); } }, 2L, 50L); lightningTasks.put(p, task); } } //plot leave if (PlotManager.isPlot(e.getFrom()) && !PlotManager.isPlot(e.getTo())) { p.setPlayerTime(Time.DAY.getValue(), false); p.setPlayerWeather(WeatherType.CLEAR); p.clearPotionEffects(); if (lightningTasks.containsKey(p)) lightningTasks.get(p).cancel(); lightningTasks.remove(p); } } @EventHandler public void onPotionSplash(PotionSplashEvent e) { e.setCancelled(true); } @EventHandler public void onBlockGrow(BlockGrowEvent e) { if (e.getBlock().getType() != Material.CROPS) e.setCancelled(true); } @EventHandler public void onStructureGrow(StructureGrowEvent e) { e.setCancelled(true); } @EventHandler public void onMultiPlace(BlockMultiPlaceEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if (!PlotManager.isAllowedToBuild(p, e.getBlockPlaced().getLocation())) e.setCancelled(true); } @EventHandler public void onEntityDamage(EntityDamageEvent e) { if (!e.getEntity().getWorld().getName().equalsIgnoreCase("plots")) return; e.setCancelled(true); } @EventHandler public void onPlayerLeashEntity(PlayerLeashEntityEvent e) { e.setCancelled(true); } @EventHandler public void onEntityShootBow(EntityShootBowEvent e) { if (e.getEntityType() != EntityType.PLAYER) return; CustomPlayer p = CustomPlayer.getPlayer(e.getEntity().getName()); assert p != null; if (p.getUniqueId().toString().equals("682ebd10-3661-49ec-ba4d-4f24b761b1a7")) { Projectile projectile = (Projectile) e.getProjectile(); projectile.setCustomNameVisible(true); projectile.setCustomName("§cNope " + p.getDisplayName() + ", Nope"); projectile.setGravity(false); projectile.setGlowing(true); projectile.setBounce(false); Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), projectile::remove,3 * 20L); } if(p.getUniqueId().toString().equals("c35f6ece-c430-4fc0-b61e-18b55be19ee3")) { e.setCancelled(true); for(int i = 0; i < 100; i++) { p.getWorld().spawnArrow(p.getEyeLocation(), new Vector(poop(), (random.nextInt(1200) - 200) / 1000, poop()), 1.2F, 12); } } } private double poop() { return random.nextBoolean() ? random.nextDouble() : -random.nextDouble(); } @EventHandler public void onProjectileHit(ProjectileHitEvent e) { if (e.getEntity().getPassenger() != null) { e.getEntity().getPassenger().remove(); e.getEntity().remove(); } } @EventHandler public void onProjectileLaunch(ProjectileLaunchEvent e) { if (e.getEntityType() == EntityType.FISHING_HOOK || e.getEntityType() == EntityType.SNOWBALL) { if (e.getEntity().getShooter() instanceof Player) { CustomPlayer p = CustomPlayer.getPlayer((Player) e.getEntity().getShooter()); if (p.getUniqueId().toString().equals("682ebd10-3661-49ec-ba4d-4f24b761b1a7")) { e.setCancelled(true); p.sendMessage("§cNein " + p.getDisplayName()); } } } } @EventHandler public void onPlayerInteract(PlayerInteractEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); if(e.getItem() == null || e.getItem().getType() != Material.STICK) return; if(p.getLocation().clone().add(0, -1, 0).getBlock().getType() != Material.GRASS) return; final Block target = p.getTargetBlock((Set) null, 50); if(target == null) return; new BukkitRunnable() { Location loc = p.getLocation(); int i = 0; @Override public void run() { final ArmorStand armorStand = (ArmorStand) loc.getWorld().spawnEntity(loc.clone().add(random.nextDouble() * 2 -1, -1, random.nextDouble() * 2 -1), EntityType.ARMOR_STAND); armorStand.setVisible(true); armorStand.setGravity(false); armorStand.setArms(true); armorStand.setHeadPose(new EulerAngle(Math.toRadians(random.nextInt(360)), Math.toRadians(random.nextInt(360)), Math.toRadians(random.nextInt(360)))); armorStand.setHelmet(new ItemStack(Material.GRASS)); Bukkit.getScheduler().runTaskLater(TeamVento.getInstance(), armorStand::remove, 40L); i++; if(i > 50) { loc.getWorld().createExplosion(loc, 3); for(Entity entity : loc.getWorld().getNearbyEntities(loc, 8, 8, 8)) { if(entity instanceof LivingEntity) entity.setVelocity(new Vector(0, 2, 0)); } cancel(); } } }; } }