Exemplo n.º 1
0
	@EventHandler(priority = EventPriority.HIGHEST)
	public void onPlayerInteract(PlayerInteractEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());
		Block block = e.getClickedBlock();

		if (player == null)
			return;
		if (block == null)
			return;
		if (!player.isActive())
			return;
		if (e.getAction() != Action.LEFT_CLICK_BLOCK)
			return;

		Game game = player.getGame();
		if (!game.canSpleef(player, block.getLocation()))
			return;

		if (game.getFlag(FlagType.BOWSPLEEF) || game.getFlag(FlagType.SPLEGG))
			return;

		if (game.getFlag(FlagType.BLOCKBREAKEFFECT)) {
			block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
		}

		block.setType(Material.AIR);
		player.addBrokenBlock(block);
	}
Exemplo n.º 2
0
	@EventHandler
	public void onBlockBreak(BlockBreakEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());
		Block block = e.getBlock();

		if (!player.isActive()) {
			for (Game game : GameManager.getGames()) {
				if (game.contains(block.getLocation())) {
					if (player.getBukkitPlayer().hasPermission(Permissions.BUILD_BYPASS.getPerm()))
						return;
					if (!HeavySpleef.getSystemConfig().getGeneralSection().isProtectArenas())
						return;

					e.setCancelled(true);
					fixBlockGlitch(player.getBukkitPlayer(), block);
					player.sendMessage(I18N._("notAllowedToBuild"));
					return;
				}
			}
			return;
		}

		Game game = player.getGame();

		if (!game.canSpleef(player, block.getLocation())) {
			e.setCancelled(true);
			fixBlockGlitch(player.getBukkitPlayer(), block);
			player.sendMessage(I18N._("notAllowedToBuild"));
			return;
		}

		if (game.getFlag(FlagType.BOWSPLEEF) || game.getFlag(FlagType.SPLEGG)) {
			e.setCancelled(true);
			return;
		}

		player.addBrokenBlock(block);
	}
Exemplo n.º 3
0
	@EventHandler
	public void onProjectileHit(ProjectileHitEvent e) {
		if (!(e.getEntity() instanceof Arrow) && !(e.getEntity() instanceof Egg))
			return;

		Projectile projectile = e.getEntity();

		if (!(projectile.getShooter() instanceof Player))
			return;

		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(projectile.getShooter());

		if (!player.isActive())
			return;

		Game game = player.getGame();

		if (projectile instanceof Arrow) {
			Arrow arrow = (Arrow) projectile;

			if (!game.getFlag(FlagType.BOWSPLEEF))
				return;

			// Use BlockIterator to detect the hit block
			BlockIterator iterator = new BlockIterator(arrow.getWorld(), arrow.getLocation().toVector(), arrow.getVelocity().normalize(), 0, 4);
			Block hitBlock = null;

			while (iterator.hasNext()) {
				hitBlock = iterator.next();

				if (hitBlock.getType() != Material.AIR)
					break;
			}

			if (!game.canSpleef(player, hitBlock.getLocation()))
				return;

			World world = arrow.getWorld();

			if (hitBlock.getType() == Material.TNT) {
				return;
			}

			arrow.remove();

			player.addBrokenBlock(hitBlock);
			FallingBlock block = world.spawnFallingBlock(hitBlock.getLocation(), hitBlock.getType(), hitBlock.getData());
			block.setMetadata("bowspleef", new FixedMetadataValue(HeavySpleef.getInstance(), true));

			if (game.getFlag(FlagType.BLOCKBREAKEFFECT)) {
				world.playEffect(hitBlock.getLocation(), Effect.STEP_SOUND, hitBlock.getType());
			}
			hitBlock.setType(Material.AIR);
		} else if (projectile instanceof Egg) {
			Egg egg = (Egg) projectile;

			if (!game.getFlag(FlagType.SPLEGG))
				return;

			// Use BlockIterator to detect the hit block
			World world = egg.getWorld();
			BlockIterator iterator = new BlockIterator(egg.getWorld(), egg.getLocation().toVector(), egg.getVelocity().normalize(), 0, 4);

			egg.remove();
			Block hitBlock = null;

			while (iterator.hasNext()) {
				hitBlock = iterator.next();

				if (hitBlock.getType() != Material.AIR)
					break;
			}

			if (!game.canSpleef(player, hitBlock.getLocation()))
				return;

			player.addBrokenBlock(hitBlock);
			world.playSound(hitBlock.getLocation(), Sound.CHICKEN_EGG_POP, 0.7F, 1.0F);
			FuzzyReflection.playMobSpellEffect(hitBlock.getLocation().clone().add(0.5, 0.8, 0.5), 100, 0);
			hitBlock.setType(Material.AIR);
		}
	}